mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-20 22:02:19 +03:00
- validateWebCookieProvider's /models probe against lmarena's registered baseUrl (a POST-only streaming endpoint from #6280) triggers a 307 REDIRECT_BLOCKED from safeOutboundFetch, which was surfaced as a raw "Redirect blocked" error (unsupported:false) instead of the honest "unsupported" signal — the dashboard rendered a hard Invalid state for a perfectly valid cookie. - Add toWebCookieValidationErrorResult() in validation/transport.ts: for providers whose /models probe is known-unreliable (lmarena for now), REDIRECT_BLOCKED now degrades to {valid:false, unsupported:true}, mirroring the same REDIRECT_BLOCKED degrade already applied on the discovery path by #6267. Deliberately scoped to lmarena only (see code comment) — other web-cookie providers with a similarly-shaped baseUrl need their own proven repro before joining the allowlist. - Remove the now-stale comment at validation.ts claiming lmarena has no providerRegistry entry (false since #6280 registered one). - Regression test: tests/unit/arena-cookie-validation-redirect-7542.test.ts (RED confirmed against unfixed code, GREEN after the fix).
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
// Import BEFORE mocking global.fetch — open-sse/utils/proxyFetch.ts overwrites
|
|
// globalThis.fetch as a module-load side effect, so a mock installed before the
|
|
// import gets clobbered (same pattern as tests/unit/provider-models-qwen-web-redirect-6267.test.ts).
|
|
const { validateWebCookieProvider } = await import("../../src/lib/providers/validation.ts");
|
|
|
|
const originalFetch = globalThis.fetch;
|
|
test.after(() => {
|
|
globalThis.fetch = originalFetch;
|
|
});
|
|
|
|
test("should_not_report_Invalid_when_lmarena_models_probe_307_redirects", async () => {
|
|
const fetchCalls: string[] = [];
|
|
globalThis.fetch = (async (input: RequestInfo | URL) => {
|
|
const url = typeof input === "string" ? input : input.toString();
|
|
fetchCalls.push(url);
|
|
return new Response(null, { status: 307, headers: { location: "https://arena.ai/" } });
|
|
}) as typeof fetch;
|
|
|
|
const result = await validateWebCookieProvider({
|
|
provider: "lmarena",
|
|
apiKey: "arena_session=abc123",
|
|
providerSpecificData: {},
|
|
});
|
|
|
|
assert.equal(fetchCalls.length, 1);
|
|
assert.equal(fetchCalls[0], "https://arena.ai/nextjs-api/stream/create-evaluation/models");
|
|
assert.equal(result.valid, false);
|
|
assert.equal(
|
|
result.unsupported,
|
|
true,
|
|
"BUG #7542: current code returns unsupported:false — dashboard renders hard Invalid"
|
|
);
|
|
});
|
|
|
|
test("should_still_report_SESSION_EXPIRED_for_lmarena_401", async () => {
|
|
globalThis.fetch = (async () => {
|
|
return new Response(null, { status: 401 });
|
|
}) as typeof fetch;
|
|
|
|
const result = await validateWebCookieProvider({
|
|
provider: "lmarena",
|
|
apiKey: "arena_session=abc123",
|
|
providerSpecificData: {},
|
|
});
|
|
|
|
assert.equal(result.valid, false);
|
|
assert.equal(result.unsupported, false);
|
|
assert.equal((result as { error?: string }).error, "SESSION_EXPIRED");
|
|
});
|