mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
* fix(lmarena): modernize Arena web provider + static Direct-chat catalog Update the lmarena provider for arena.ai (product rebranded from LMArena): - Route chat via arena.ai create-evaluation with Chrome TLS impersonation (tls-client-node) and optional browser-minted recaptchaV3Token. - Seed Text+Search (48) into the chat registry; seed Image (27) only into IMAGE_PROVIDERS. Disable live HTML model discovery; resolve public names to Arena UUIDs from the static TypeScript allowlist (no scrape JSON in-repo). - Soft-exclude 404/502 model ids; slow/stop bulk test-all probes for this provider. - Do not fold IMAGE_PROVIDERS/video specialty into the chat provider catalog when a chat registry already exists (lmarena/openai/xai). - Display name Arena (Free); keep wire id `lmarena` / alias `lma` for back-compat. - Theme-aware provider icons: arena-light.svg / arena-dark.svg. - Preserve split Supabase SSR cookie reconstruction for arena-auth-prod-v1.*. * fix(providers): align provider-models-route test fixture + regen provider reference Fold the topaz image-only catalog entry's apiFormat/supportedEndpoints into the local-catalog test fixture (route now tags media-only providers per the lmarena PR's staticModels.ts change), regenerate PROVIDER_REFERENCE.md against the merged release providers.ts, and add the changelog fragment for #6280. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * test: align web-cookie fallback suite — lmarena now has a registry entry (probe path) Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
114 lines
4.9 KiB
TypeScript
114 lines
4.9 KiB
TypeScript
// Tests for validateWebCookieProvider fallback when no registry entry exists.
|
|
// Covers providers like lmarena, gemini-business, poe-web, venice-web and v0-vercel-web
|
|
// that are listed in WEB_COOKIE_PROVIDERS but have no entry in providerRegistry.ts.
|
|
//
|
|
// These providers only expose a marketing website URL (WEB_COOKIE_PROVIDERS[id].website),
|
|
// not a real API host. Probing `${website}/models` does not reliably signal session
|
|
// validity — live verification showed most of these hosts return redirects or SPA 200s
|
|
// regardless of cookie validity, which would silently report an expired/garbage cookie as
|
|
// "OK". Until each provider has a verified, side-effect-free auth probe against its real
|
|
// API host, validateWebCookieProvider reports `unsupported: true` for this fallback case
|
|
// instead of a false "valid" — and does so WITHOUT making any network probe.
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { validateProviderApiKey } = await import("../../src/lib/providers/validation.ts");
|
|
|
|
const originalFetch = globalThis.fetch;
|
|
|
|
const fetchCalls: Array<{ url: string; headers: Record<string, string> }> = [];
|
|
|
|
test.beforeEach(() => {
|
|
fetchCalls.length = 0;
|
|
globalThis.fetch = (async (url: string | URL, init?: RequestInit) => {
|
|
const headers: Record<string, string> = {};
|
|
if (init?.headers) {
|
|
if (init.headers instanceof Headers) {
|
|
init.headers.forEach((v, k) => {
|
|
headers[k] = v;
|
|
});
|
|
} else if (Array.isArray(init.headers)) {
|
|
for (const [k, v] of init.headers) headers[k] = v;
|
|
} else {
|
|
Object.assign(headers, init.headers);
|
|
}
|
|
}
|
|
fetchCalls.push({ url: String(url), headers });
|
|
// If this mock is ever hit for a no-registry-entry provider, the test will fail on
|
|
// the `fetchCalls.length` assertion below — this response is never meant to be read.
|
|
return new Response("", { status: 404 });
|
|
}) as typeof fetch;
|
|
});
|
|
|
|
test.afterEach(() => {
|
|
globalThis.fetch = originalFetch;
|
|
});
|
|
|
|
// ── lmarena (#6280: gained a REAL providerRegistry entry — left the fallback class) ──
|
|
// Before #6280 lmarena had no registry entry, so this suite asserted the unsupported
|
|
// fallback. The Arena modernization added a real registry entry (registry/lmarena/),
|
|
// so validateWebCookieProvider now takes the probe path (directHttpsRequest against the
|
|
// registry baseUrl — which deliberately bypasses this suite's fetch mock, so the probe
|
|
// itself cannot be unit-asserted here). What this suite still guards for lmarena: its
|
|
// classification out of the no-registry fallback.
|
|
|
|
test("lmarena has a registry entry — no longer the no-registry unsupported fallback", async () => {
|
|
const { getRegistryEntry } = await import("@omniroute/open-sse/config/providerRegistry.ts");
|
|
const entry = getRegistryEntry("lmarena");
|
|
assert.ok(entry, "lmarena must have a providerRegistry entry (#6280 Arena modernization)");
|
|
assert.ok(entry.baseUrl, "the probe path requires a real baseUrl on the registry entry");
|
|
});
|
|
|
|
test("lmarena validation rejects empty cookie before checking support", async () => {
|
|
const result = await validateProviderApiKey({
|
|
provider: "lmarena",
|
|
apiKey: "",
|
|
});
|
|
assert.strictEqual(result.valid, false);
|
|
assert.match(result.error, /api key required|cookie/i);
|
|
assert.equal(fetchCalls.length, 0);
|
|
});
|
|
|
|
// ── gemini-business (no registry entry, falls back to WEB_COOKIE_PROVIDERS) ──
|
|
|
|
test("gemini-business validation is unsupported and makes no network call", async () => {
|
|
const result = await validateProviderApiKey({
|
|
provider: "gemini-business",
|
|
apiKey: "test-gemini-cookie",
|
|
});
|
|
assert.strictEqual(result.valid, false);
|
|
assert.equal(result.unsupported, true);
|
|
assert.equal(fetchCalls.length, 0);
|
|
});
|
|
|
|
// ── remaining WEB_COOKIE_PROVIDERS-only providers (no registry entry) ──
|
|
// NOTE: doubao-web and zenmux-free are intentionally NOT covered here — unlike when this
|
|
// fix was proposed, both now carry a providerRegistry.ts entry (added independently of
|
|
// this PR), so they no longer exercise the no-registry-entry fallback branch this test
|
|
// file targets; they go through the pre-existing entry-based probe instead, which is out
|
|
// of scope for this fix.
|
|
|
|
for (const provider of ["poe-web", "venice-web", "v0-vercel-web"]) {
|
|
test(`${provider} validation is unsupported and makes no network call`, async () => {
|
|
const result = await validateProviderApiKey({
|
|
provider,
|
|
apiKey: "some-cookie-value",
|
|
});
|
|
assert.strictEqual(result.valid, false);
|
|
assert.equal(result.unsupported, true);
|
|
assert.equal(fetchCalls.length, 0);
|
|
});
|
|
}
|
|
|
|
// ── generic fallback guard ──
|
|
|
|
test("unknown web-cookie provider without registry returns unsupported", async () => {
|
|
const result = await validateProviderApiKey({
|
|
provider: "fake-web",
|
|
apiKey: "some-key",
|
|
});
|
|
assert.strictEqual(result.valid, false);
|
|
assert.equal(result.unsupported, true);
|
|
});
|