mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 00:52:18 +03:00
Drain the unit-shard reds the 2026-08-23 merge wave left on release/v3.8.50, each discriminated as stale-test (contract moved intentionally, test aligned) vs real bug (fixed in code/messages): 1. check-deps 6A.8 allowlist — #11224 added @testing-library/dom and @testing-library/user-event to package.json without the gate allowlist. Both are legitimate: @testing-library/dom is a required peer of @testing-library/react v16, and user-event is the official companion for UI tests. Fix: allowlist entries with a justification note referencing #11224/#9985. 2. search-route 400-vs-fallback — #11097 intentionally changed the zero-credential /v1/search contract: instead of returning 400 it promotes the fallback-only duckduckgo-free provider so out-of-the-box search works. The test pinned the OLD 400 contract. Fix (contract alignment): the test now pins the new fallback contract — 200, provider duckduckgo-free, DuckDuckGo lite endpoint called, results parsed from lite HTML. 3. codex catalog token limits (4 named reds + 2 sibling sweeps) — #11179 raised GPT_5_6_CODEX_CAPABILITIES from the 272K pricing tier to the real usable 872K window (live evidence: 390K served past 272K with HTTP 200) and updated codex-gpt56-catalog.test.ts but missed the sibling pins. Stale tests aligned: models-catalog-combo- metadata (max_input_tokens now clamps to min(872000, 500000 override) = 500000), vscode-token-routes x3 (872000), and two more found in the sibling sweep: vscode-token-routes-gpt56 and provider-models-route- codex (conservative merge semantics unchanged: pinned 872000 < live 999999 still wins). 4. CLI catalog counts (3 reds) — #11166 added prime-agent (agent category) without the cardinality pins: EXPECTED_AGENT_COUNT 8->9, total 34->35, D15 agent list + prime-agent, cli-tools-schema id list. Also added the missing English/Vietnamese cliTools descriptions for prime-agent (cli-catalog-display-contract) and corrected the stale CLI-TOOLS.md agent count (8->9). 5. setup-qwen container guard — since #10057 the container guard exits 2 on ephemeral runtimes; the two tests exercising the merge/write path were environment-sensitive (red on container devboxes). Fix: pass allowContainerWrite so the tests are hermetic everywhere; the guard keeps its own dedicated coverage. 6. i18n health verdict namespace (real bug, fixed in messages) — #11224 added the verdict/diagnostics strings to the `sidebar` namespace but health/page.tsx reads them via useTranslations("health"), so the page rendered raw keys in every locale and the "direct translation calls have English messages" gate went red. Fix: keys moved sidebar->health in en.json + vi.json (the only locales that had them), plus health.healthSubtitle added. The sidebar never referenced them (verified: no usage), and sidebar.healthSubtitle (its real sidebar key) is untouched. 7. i18n pt-BR drift (22 keys) — the 08-23 wave (#11224/#11228/#11215/ #11204/#11195) added English keys never translated: common.batch*, endpoint.*, cliCommon.concept.acp.warning, resilienceConnections.*, plus the moved health.* keys and the prime-agent cliTools description. Fix: pt-BR translations added — 0 missing keys vs en; vi strict parity re-verified (0 missing, 0 extra). Validation: every touched test file RED->GREEN individually (node --import tsx/esm --test), typecheck:core clean, docs-counts-sync soft-pass, cli-i18n gate PASS, 8/8 unit shards re-run on the branch. Refs #9985
431 lines
15 KiB
TypeScript
431 lines
15 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(
|
|
path.join(os.tmpdir(), "omniroute-provider-model-routes-codex-")
|
|
);
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const providersDb = await import("../../src/lib/db/providers.ts");
|
|
const modelsDb = await import("../../src/lib/db/models.ts");
|
|
const providerModelsRoute = await import("../../src/app/api/providers/[id]/models/route.ts");
|
|
const codexDiscovery = await import("../../src/app/api/providers/[id]/models/discovery/codex.ts");
|
|
|
|
type RouteModel = {
|
|
id: string;
|
|
name?: string;
|
|
apiFormat?: string;
|
|
supportedEndpoints?: string[];
|
|
inputTokenLimit?: number;
|
|
outputTokenLimit?: number;
|
|
[key: string]: unknown;
|
|
};
|
|
|
|
type RouteBody = {
|
|
provider?: string;
|
|
models?: RouteModel[];
|
|
source?: string;
|
|
warning?: string;
|
|
intentional?: boolean;
|
|
discoveredCandidateCount?: number;
|
|
};
|
|
|
|
type ProviderOverrides = {
|
|
authType?: string;
|
|
apiKey?: string | null;
|
|
accessToken?: string | null;
|
|
providerSpecificData?: Record<string, unknown>;
|
|
};
|
|
|
|
const originalFetch = globalThis.fetch;
|
|
|
|
async function resetStorage() {
|
|
globalThis.fetch = originalFetch;
|
|
codexDiscovery.clearCodexGithubCatalogCacheForTests();
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
}
|
|
|
|
async function seedCodexConnection(overrides: ProviderOverrides = {}) {
|
|
return providersDb.createProviderConnection({
|
|
provider: "codex",
|
|
authType: overrides.authType || "oauth",
|
|
name: `codex-${Math.random().toString(16).slice(2, 8)}`,
|
|
apiKey: overrides.apiKey,
|
|
accessToken: overrides.accessToken,
|
|
isActive: true,
|
|
testStatus: "active",
|
|
providerSpecificData: overrides.providerSpecificData || {},
|
|
});
|
|
}
|
|
|
|
async function callRoute(connectionId: string, search = "") {
|
|
return providerModelsRoute.GET(
|
|
new Request(`http://localhost/api/providers/${connectionId}/models${search}`),
|
|
{ params: { id: connectionId } }
|
|
);
|
|
}
|
|
|
|
test.beforeEach(async () => {
|
|
await resetStorage();
|
|
});
|
|
|
|
test.after(async () => {
|
|
globalThis.fetch = originalFetch;
|
|
codexDiscovery.clearCodexGithubCatalogCacheForTests();
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
});
|
|
|
|
test("provider models route merges live Codex models with the local catalog then filters denylist", async () => {
|
|
const connection = await seedCodexConnection({
|
|
accessToken: "codex-access-token",
|
|
providerSpecificData: { chatgptAccountId: "account-123" },
|
|
});
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection("codex", connection.id, [
|
|
{ id: "stale-codex-model", name: "Stale Codex Model", source: "imported" },
|
|
]);
|
|
const seenRequests: Array<Record<string, string | null>> = [];
|
|
|
|
globalThis.fetch = async (url, init) => {
|
|
const requestUrl = String(url);
|
|
const headers = new Headers(init?.headers as HeadersInit | undefined);
|
|
seenRequests.push({
|
|
url: requestUrl,
|
|
authorization: headers.get("authorization"),
|
|
workspaceId: headers.get("chatgpt-account-id"),
|
|
originator: headers.get("originator"),
|
|
userAgent: headers.get("user-agent"),
|
|
});
|
|
if (requestUrl.includes("raw.githubusercontent.com/openai/codex")) {
|
|
return Response.json({
|
|
models: [
|
|
{
|
|
slug: "gpt-5.6-sol",
|
|
display_name: "GPT 5.6 Sol GitHub",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
minimal_client_version: "0.144.0",
|
|
context_window: 372000,
|
|
input_modalities: ["text", "image"],
|
|
supported_reasoning_levels: [{ effort: "low" }, { effort: "high" }],
|
|
},
|
|
{
|
|
slug: "gpt-5.4",
|
|
display_name: "Retired GPT 5.4 GitHub",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
},
|
|
],
|
|
});
|
|
}
|
|
return Response.json({
|
|
models: [
|
|
{ slug: "codex-auto-review", visibility: "hide", supported_in_api: true },
|
|
{
|
|
slug: "gpt-5.6-sol",
|
|
display_name: "GPT 5.6 Sol Live",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
max_input_tokens: 999999,
|
|
max_output_tokens: 999999,
|
|
},
|
|
{
|
|
slug: "gpt-5.4",
|
|
display_name: "Retired GPT 5.4 Live",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
},
|
|
{ id: "", name: "missing-id" },
|
|
],
|
|
});
|
|
};
|
|
|
|
const response = await callRoute(connection.id, "?refresh=true");
|
|
const body = (await response.json()) as RouteBody;
|
|
const modelIds = new Set(body.models?.map((model) => model.id));
|
|
const liveModel = body.models?.find((model) => model.id === "gpt-5.6-sol");
|
|
const syncedModels = await modelsDb.getSyncedAvailableModelsForConnection("codex", connection.id);
|
|
const syncedIds = new Set(syncedModels.map((model) => model.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(body.provider, "codex");
|
|
assert.equal(body.source, "api");
|
|
assert.equal(body.discoveredCandidateCount, undefined);
|
|
assert.deepEqual(seenRequests, [
|
|
{
|
|
url: "https://chatgpt.com/backend-api/codex/models?client_version=0.149.0",
|
|
authorization: "Bearer codex-access-token",
|
|
workspaceId: "account-123",
|
|
originator: "codex_cli_rs",
|
|
userAgent: "codex-cli/0.149.0 (Windows 10.0.26200; x64)",
|
|
},
|
|
{
|
|
url: "https://raw.githubusercontent.com/openai/codex/refs/heads/main/codex-rs/models-manager/models.json",
|
|
authorization: null,
|
|
workspaceId: null,
|
|
originator: null,
|
|
userAgent: null,
|
|
},
|
|
]);
|
|
assert.ok(modelIds.has("gpt-5.6-sol"));
|
|
assert.ok(modelIds.has("gpt-5.6-sol-ultra"));
|
|
assert.ok(modelIds.has("gpt-5.6-sol-max"));
|
|
// Live payload wins on overlapping fields; local catalog supplies local-only
|
|
// variants. EXCEPTION: capacity limits (inputTokenLimit/outputTokenLimit)
|
|
// merge conservatively — the smaller of live vs. pinned wins, never the
|
|
// larger, so a stale/inflated live number can never make OmniRoute promise
|
|
// more context than the account can actually serve (#7012). Here the pinned
|
|
// GPT-5.6 Codex contract (872000/128000, see GPT_5_6_CODEX_CAPABILITIES — raised
|
|
// from the old 272K pricing tier to the real usable window by #11179)
|
|
// is smaller than the live payload's 999999/999999, so the pinned value wins.
|
|
assert.equal(liveModel?.name, "GPT 5.6 Sol Live");
|
|
assert.equal(liveModel?.inputTokenLimit, 872000);
|
|
assert.equal(liveModel?.outputTokenLimit, 128000);
|
|
assert.equal(liveModel?.apiFormat, "responses");
|
|
assert.deepEqual(liveModel?.supportedEndpoints, ["responses"]);
|
|
assert.equal(liveModel?.supportsThinking, true);
|
|
assert.equal(liveModel?.supportsVision, true);
|
|
assert.ok(modelIds.has("gpt-5.5-low"));
|
|
assert.equal(
|
|
[...modelIds].some((id) => String(id).startsWith("gpt-5.4")),
|
|
false
|
|
);
|
|
assert.ok(syncedIds.has("gpt-5.6-sol"));
|
|
assert.ok(syncedIds.has("gpt-5.5-low"));
|
|
assert.equal(
|
|
[...syncedIds].some((id) => String(id).startsWith("gpt-5.4")),
|
|
false
|
|
);
|
|
// Stale cache-only ids are replaced when a fresh discovery response is persisted.
|
|
assert.equal(modelIds.has("stale-codex-model"), false);
|
|
assert.equal(syncedIds.has("stale-codex-model"), false);
|
|
});
|
|
|
|
test("provider models route: live token limit wins when it is SMALLER than the pinned local catalog value", async () => {
|
|
const connection = await seedCodexConnection({
|
|
accessToken: "codex-access-token",
|
|
providerSpecificData: { chatgptAccountId: "account-123" },
|
|
});
|
|
|
|
globalThis.fetch = async (url) => {
|
|
const requestUrl = String(url);
|
|
if (requestUrl.includes("raw.githubusercontent.com/openai/codex")) {
|
|
return Response.json({ models: [] });
|
|
}
|
|
// Live reports a SMALLER budget than the pinned GPT-5.6 Codex contract
|
|
// (272000/128000, GPT_5_6_CODEX_CAPABILITIES) — e.g. a temporary
|
|
// account-level cap. The conservative merge must take the smaller live
|
|
// value here, not the larger pinned one (#7012).
|
|
return Response.json({
|
|
models: [
|
|
{
|
|
slug: "gpt-5.6-sol",
|
|
display_name: "GPT 5.6 Sol Live",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
max_input_tokens: 100000,
|
|
max_output_tokens: 50000,
|
|
},
|
|
],
|
|
});
|
|
};
|
|
|
|
const response = await callRoute(connection.id, "?refresh=true");
|
|
const body = (await response.json()) as RouteBody;
|
|
const liveModel = body.models?.find((model) => model.id === "gpt-5.6-sol");
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(liveModel?.inputTokenLimit, 100000);
|
|
assert.equal(liveModel?.outputTokenLimit, 50000);
|
|
});
|
|
|
|
test("provider models route uses the GitHub Codex catalog when live discovery fails", async () => {
|
|
const connection = await seedCodexConnection({ accessToken: "codex-access-token" });
|
|
const seenUrls: string[] = [];
|
|
|
|
globalThis.fetch = async (url) => {
|
|
const requestUrl = String(url);
|
|
seenUrls.push(requestUrl);
|
|
if (requestUrl.includes("raw.githubusercontent.com/openai/codex")) {
|
|
return Response.json({
|
|
models: [
|
|
{
|
|
slug: "gpt-5.6-sol",
|
|
display_name: "GPT-5.6-Sol",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
minimal_client_version: "0.144.0",
|
|
context_window: 372000,
|
|
},
|
|
{
|
|
slug: "gpt-5.4",
|
|
display_name: "Retired GPT-5.4",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
},
|
|
],
|
|
});
|
|
}
|
|
return new Response("upstream unavailable", { status: 503 });
|
|
};
|
|
|
|
const response = await callRoute(connection.id, "?refresh=true");
|
|
const body = (await response.json()) as RouteBody;
|
|
const modelIds = new Set((body.models || []).map((model) => model.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(body.provider, "codex");
|
|
assert.equal(body.source, "api");
|
|
assert.equal(body.intentional, undefined);
|
|
assert.equal(body.warning, "Codex live catalog unavailable — using GitHub model catalog");
|
|
assert.equal(body.discoveredCandidateCount, undefined);
|
|
assert.ok(seenUrls.some((url) => url.includes("backend-api/codex/models")));
|
|
assert.ok(seenUrls.some((url) => url.includes("raw.githubusercontent.com/openai/codex")));
|
|
assert.ok(modelIds.has("gpt-5.6-sol"));
|
|
assert.ok(modelIds.has("gpt-5.5-low"));
|
|
assert.equal(
|
|
[...modelIds].some((id) => String(id).startsWith("gpt-5.4")),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("provider models route returns cached Codex models when refresh discovery fails", async () => {
|
|
const connection = await seedCodexConnection({ accessToken: "codex-access-token" });
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection("codex", connection.id, [
|
|
{
|
|
id: "gpt-5.4",
|
|
name: "Retired Cached GPT 5.4",
|
|
source: "imported",
|
|
apiFormat: "responses",
|
|
supportedEndpoints: ["responses"],
|
|
},
|
|
{
|
|
id: "gpt-5.6-sol",
|
|
name: "Cached GPT 5.6 Sol",
|
|
source: "imported",
|
|
apiFormat: "responses",
|
|
supportedEndpoints: ["responses"],
|
|
},
|
|
]);
|
|
|
|
globalThis.fetch = async () => new Response("upstream unavailable", { status: 503 });
|
|
|
|
const response = await callRoute(connection.id, "?refresh=true");
|
|
const body = (await response.json()) as RouteBody;
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(body.provider, "codex");
|
|
assert.equal(body.source, "cache");
|
|
assert.equal(body.warning, "Codex live catalog unavailable — using cached catalog");
|
|
assert.equal(body.discoveredCandidateCount, undefined);
|
|
const modelIds = new Set((body.models || []).map((model) => model.id));
|
|
assert.ok(modelIds.has("gpt-5.6-sol"));
|
|
assert.ok(modelIds.has("gpt-5.6-sol-ultra"));
|
|
assert.equal(
|
|
[...modelIds].some((id) => String(id).startsWith("gpt-5.4")),
|
|
false
|
|
);
|
|
const syncedModels = await modelsDb.getSyncedAvailableModelsForConnection("codex", connection.id);
|
|
const syncedIds = new Set(syncedModels.map((model) => model.id));
|
|
assert.ok(syncedIds.has("gpt-5.6-sol-ultra"));
|
|
assert.equal(syncedIds.has("gpt-5.4"), false);
|
|
});
|
|
|
|
test("provider models route auto-includes remote-only Codex models after merge", async () => {
|
|
const connection = await seedCodexConnection({ accessToken: "codex-access-token" });
|
|
|
|
globalThis.fetch = async (url) => {
|
|
const requestUrl = String(url);
|
|
if (requestUrl.includes("raw.githubusercontent.com/openai/codex")) {
|
|
return Response.json({ models: [] });
|
|
}
|
|
return Response.json({
|
|
models: [
|
|
{
|
|
slug: "future-codex-experimental",
|
|
display_name: "Future Codex Experimental",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
},
|
|
{
|
|
slug: "gpt-5.6-sol",
|
|
display_name: "GPT 5.6 Sol Live",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
},
|
|
{
|
|
slug: "gpt-5.4",
|
|
display_name: "Retired GPT 5.4 Live",
|
|
visibility: "list",
|
|
supported_in_api: true,
|
|
},
|
|
],
|
|
});
|
|
};
|
|
|
|
const response = await callRoute(connection.id, "?refresh=true");
|
|
const body = (await response.json()) as RouteBody;
|
|
const modelIds = new Set((body.models || []).map((model) => model.id));
|
|
const syncedModels = await modelsDb.getSyncedAvailableModelsForConnection("codex", connection.id);
|
|
const syncedIds = new Set(syncedModels.map((model) => model.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(body.source, "api");
|
|
assert.ok(modelIds.has("future-codex-experimental"));
|
|
assert.ok(modelIds.has("gpt-5.6-sol"));
|
|
assert.equal(modelIds.has("gpt-5.4"), false);
|
|
assert.ok(syncedIds.has("future-codex-experimental"));
|
|
assert.equal(syncedIds.has("gpt-5.4"), false);
|
|
});
|
|
|
|
test("provider models route falls back to local Codex catalog when live and GitHub fail", async () => {
|
|
const connection = await seedCodexConnection({ accessToken: "codex-access-token" });
|
|
|
|
globalThis.fetch = async () => new Response("upstream unavailable", { status: 503 });
|
|
|
|
const response = await callRoute(connection.id, "?refresh=true");
|
|
const body = (await response.json()) as RouteBody;
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(body.provider, "codex");
|
|
assert.equal(body.source, "local_catalog");
|
|
assert.equal(body.intentional, true);
|
|
assert.equal(body.warning, "Codex live and GitHub catalogs unavailable — using local catalog");
|
|
assert.ok(body.models?.some((model) => model.id === "gpt-5.6-sol"));
|
|
assert.ok(body.models?.some((model) => model.id === "gpt-5.5"));
|
|
assert.equal(
|
|
body.models?.some((model) => model.id.startsWith("gpt-5.4")),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("provider models route returns curated GPT-5.6 variants when auto-fetch is disabled", async () => {
|
|
const connection = await seedCodexConnection({
|
|
apiKey: null,
|
|
accessToken: "codex-access",
|
|
providerSpecificData: { autoFetchModels: false },
|
|
});
|
|
|
|
const response = await callRoute(connection.id);
|
|
const body = (await response.json()) as RouteBody;
|
|
const modelIds = new Set((body.models || []).map((model) => model.id));
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(body.provider, "codex");
|
|
assert.equal(body.source, "local_catalog");
|
|
assert.ok(modelIds.has("gpt-5.6-sol-ultra"));
|
|
assert.ok(modelIds.has("gpt-5.6-sol-max"));
|
|
assert.ok(modelIds.has("gpt-5.6-terra-ultra"));
|
|
assert.ok(modelIds.has("gpt-5.6-luna-max"));
|
|
assert.equal(
|
|
[...modelIds].some((id) => String(id).startsWith("gpt-5.4")),
|
|
false
|
|
);
|
|
});
|