mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +03:00
Rebased onto the current release/v3.8.51 tip as part of a combined provider-retirement/provenance merge batch (Designer Web, Felo Web, Runtime, GPL-derived removal all landed together already). Conflicts resolved: - `src/shared/constants/providerRetirement.ts`: add/add conflict — combined `felo-web`/`felo` (already-merged) with `qwen-web`/`qw` into one `RUNTIME_RETIRED_PROVIDER_IDS` set, kept both `assertRuntimeProviderAvailable`/`assertRuntimeModelProviderAvailable` helpers. - `open-sse/config/providers/registry/minimax/web/index.ts`: modify/delete — kept deleted (file is hailuo-web's registry entry, already retired by #11691; this PR's own change to it was just a comment reword on a since-removed target). - `open-sse/executors/index.ts`, `executorProxy.ts`, `virtualFactory.ts`, `autoStrategy.ts`, `model.ts`, `chat.ts`, `chatHelpers.ts`, `auth.ts`, `src/lib/db/providers.ts`, `reservedProviderPrefixes.ts`: combined the Designer + Runtime (Felo + Qwen) retirement guard calls at each shared chokepoint — compute-once-then-OR pattern, consistent with the prior Designer+Felo combination. - `src/shared/constants/providers/web-cookie.ts`, `tests/snapshots/provider/translate-path.json`, `tests/snapshots/executors/executor-map.json`: both sides had inserted a different retired provider (qwen-web vs. already-retired raycast/hailuo-web) at the same dict position — resolved by dropping both. `executor-map.json`'s `keyCount` recomputed to 135 (matches actual merged `entries`). - `tests/unit/chatcore-executor-proxy.test.ts`, `tests/unit/provider-node-reserved-prefix.test.ts`: split into independent Felo/Qwen test blocks (established pattern for coexisting retirement-mechanism tests); recomputed `RESERVED_PREFIX_COUNT` to 398 (Designer+Felo+Qwen tombstones on top of the post-#11691 REGISTRY, verified via direct module evaluation, not hand-derived). - `config/quality/test-masking-allowlist.json`: additive merge of Qwen's `_deletedWithReplacement` entries alongside Designer's. - `README.md` + all `docs/i18n/*/README.md` mirrors, `docs/getting-started/FREE-TIERS-GUIDE.md`, `docs/reference/FREE_TIERS.md`, `docs/diagrams/free-tier-budget.svg`, `docs/screenshots/free-tier-budget-card.svg`: recomputed the free-tier catalog counts (447 entries / 440 active / 7 discontinued) from the actual merged `freeModelCatalog.data.ts`, regenerated the budget-card SVG via its real generator (`scripts/research/gen-budget-card-svg.mjs`), and dropped the retired Qwen quick-start row / QWEN MODELS section from every i18n README (identical unlocalized block across all 34 locales). - Also fixed a duplicate-import merge artifact in `src/lib/db/providers.ts` (`isRuntimeRetiredProviderId` imported twice) caught by `typecheck:core`, and rebaselined `file-size-baseline.json` for the combined retirement-guard growth (`virtualFactory.ts` +3, with justification). Focused suite green (345/345 across executor-proxy, reserved-prefix, migration-167, qwen-web-retirement, virtual-auto-combo, web-cookie/session, executor-map-golden and siblings), plus `typecheck:core` and `check-file-size`/`check-changelog-integrity` clean. Thanks for the provenance-hold retirement work — appreciated.
123 lines
5.2 KiB
TypeScript
123 lines
5.2 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const webCookieAuth = await import("../../src/lib/providers/webCookieAuth.ts");
|
|
|
|
const {
|
|
extractCookieValue,
|
|
normalizeSessionCookieHeader,
|
|
stripCookieInputPrefix,
|
|
buildGrokCookieHeader,
|
|
} = webCookieAuth;
|
|
|
|
test("Qwen Web cookie helpers are absent while supported cookie helpers remain", () => {
|
|
assert.equal("buildQwenCookieHeader" in webCookieAuth, false);
|
|
assert.equal("extractQwenToken" in webCookieAuth, false);
|
|
assert.equal(typeof webCookieAuth.stripCookieInputPrefix, "function");
|
|
assert.equal(typeof webCookieAuth.parseJsonCookiesToHeader, "function");
|
|
assert.equal(typeof webCookieAuth.normalizeSessionCookieHeader, "function");
|
|
assert.equal(typeof webCookieAuth.extractCookieValue, "function");
|
|
assert.equal(typeof webCookieAuth.buildGrokCookieHeader, "function");
|
|
});
|
|
|
|
test("stripCookieInputPrefix removes 'cookie:' and 'bearer ' prefixes", () => {
|
|
assert.equal(stripCookieInputPrefix("Cookie: sso=abc"), "sso=abc");
|
|
assert.equal(stripCookieInputPrefix("bearer xyz"), "xyz");
|
|
assert.equal(stripCookieInputPrefix(" plain "), "plain");
|
|
assert.equal(stripCookieInputPrefix(""), "");
|
|
});
|
|
|
|
test("normalizeSessionCookieHeader returns input as-is when it already has '='", () => {
|
|
assert.equal(
|
|
normalizeSessionCookieHeader(
|
|
"__Secure-authjs.session-token=abc",
|
|
"__Secure-authjs.session-token"
|
|
),
|
|
"__Secure-authjs.session-token=abc"
|
|
);
|
|
assert.equal(
|
|
normalizeSessionCookieHeader("bare-value", "__Secure-authjs.session-token"),
|
|
"__Secure-authjs.session-token=bare-value"
|
|
);
|
|
});
|
|
|
|
test("extractCookieValue: bare value returns unchanged", () => {
|
|
assert.equal(extractCookieValue("eyJ0eXAi.abc.def", "sso"), "eyJ0eXAi.abc.def");
|
|
});
|
|
|
|
test("extractCookieValue: single name=value pair returns the value", () => {
|
|
assert.equal(extractCookieValue("sso=eyJ0eXAi.abc.def", "sso"), "eyJ0eXAi.abc.def");
|
|
assert.equal(extractCookieValue("Cookie: sso=eyJ0eXAi.abc.def", "sso"), "eyJ0eXAi.abc.def");
|
|
});
|
|
|
|
test("extractCookieValue: full DevTools cookie blob picks the named cookie", () => {
|
|
const blob =
|
|
"i18nextLng=en; stblid=aaaaaaaa; __cf_bm=foo; sso-rw=eyJOTHER; sso=eyJTARGET.abc.def; cf_clearance=baz;";
|
|
assert.equal(extractCookieValue(blob, "sso"), "eyJTARGET.abc.def");
|
|
assert.equal(extractCookieValue(blob, "sso-rw"), "eyJOTHER");
|
|
assert.equal(extractCookieValue(blob, "cf_clearance"), "baz");
|
|
});
|
|
|
|
test("extractCookieValue: blob without target cookie returns empty string", () => {
|
|
assert.equal(extractCookieValue("foo=1; bar=2;", "sso"), "");
|
|
});
|
|
|
|
test("extractCookieValue: empty input returns empty string", () => {
|
|
assert.equal(extractCookieValue("", "sso"), "");
|
|
assert.equal(extractCookieValue(" ", "sso"), "");
|
|
});
|
|
|
|
test("extractCookieValue: cookie name with regex metacharacters is escaped", () => {
|
|
const blob = "foo=1; my.cookie+name=hello; bar=2;";
|
|
assert.equal(extractCookieValue(blob, "my.cookie+name"), "hello");
|
|
});
|
|
|
|
// #3063 — Grok now requires the paired `sso-rw` write cookie alongside `sso`.
|
|
test("buildGrokCookieHeader: bare sso value emits only sso (no phantom sso-rw)", () => {
|
|
assert.equal(buildGrokCookieHeader("eyJ0eXAi.abc.def"), "sso=eyJ0eXAi.abc.def");
|
|
});
|
|
|
|
test("buildGrokCookieHeader: single sso= pair emits only sso", () => {
|
|
assert.equal(buildGrokCookieHeader("sso=eyJ0eXAi.abc"), "sso=eyJ0eXAi.abc");
|
|
});
|
|
|
|
test("buildGrokCookieHeader: full cookie blob forwards sso, sso-rw and cf_clearance", () => {
|
|
const blob = "cf_clearance=zzz; sso=AAA.bbb; sso-rw=CCC.ddd; other=1";
|
|
assert.equal(buildGrokCookieHeader(blob), "sso=AAA.bbb; sso-rw=CCC.ddd; cf_clearance=zzz");
|
|
});
|
|
|
|
// #5350 — forward the Cloudflare cookies (cf_clearance + __cf_bm) when the pasted
|
|
// blob carries them, matching the real browser request (parity with AIClient2API).
|
|
test("buildGrokCookieHeader: forwards sso, sso-rw, cf_clearance and __cf_bm (order-independent)", () => {
|
|
const blob = "i18nextLng=en; __cf_bm=BM; sso=SSO; sso-rw=RW; cf_clearance=CF; x-userid=U";
|
|
const header = buildGrokCookieHeader(blob);
|
|
assert.match(header, /(?:^|;\s*)sso=SSO(?:;|$)/);
|
|
assert.match(header, /(?:^|;\s*)sso-rw=RW(?:;|$)/);
|
|
assert.match(header, /(?:^|;\s*)cf_clearance=CF(?:;|$)/);
|
|
assert.match(header, /(?:^|;\s*)__cf_bm=BM(?:;|$)/);
|
|
});
|
|
|
|
test("buildGrokCookieHeader: bare sso emits no phantom cf_clearance/__cf_bm keys", () => {
|
|
assert.equal(buildGrokCookieHeader("sso=SSO"), "sso=SSO");
|
|
assert.doesNotMatch(buildGrokCookieHeader("sso=SSO"), /cf_clearance|__cf_bm/);
|
|
});
|
|
|
|
test("buildGrokCookieHeader: forwards __cf_bm even when cf_clearance is absent", () => {
|
|
const blob = "foo=1; __cf_bm=BM; sso=AAA.bbb";
|
|
assert.equal(buildGrokCookieHeader(blob), "sso=AAA.bbb; __cf_bm=BM");
|
|
});
|
|
|
|
test("buildGrokCookieHeader: order-independent — sso-rw before sso in the blob", () => {
|
|
const blob = "sso-rw=CCC.ddd; sso=AAA.bbb";
|
|
assert.equal(buildGrokCookieHeader(blob), "sso=AAA.bbb; sso-rw=CCC.ddd");
|
|
});
|
|
|
|
test("buildGrokCookieHeader: blob with sso but no sso-rw emits only sso", () => {
|
|
assert.equal(buildGrokCookieHeader("foo=1; sso=AAA.bbb; bar=2"), "sso=AAA.bbb");
|
|
});
|
|
|
|
test("buildGrokCookieHeader: blob without sso returns empty string", () => {
|
|
assert.equal(buildGrokCookieHeader("foo=1; sso-rw=CCC.ddd; bar=2"), "");
|
|
assert.equal(buildGrokCookieHeader(""), "");
|
|
});
|