mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-15 11:22:15 +03:00
* test(infra): retry recursive temp-dir removal on main (main twin of #11968)
`main` has been red since b342c1a361 on the vitest and integration gates:
✖ tests/unit/autoCombo/provider-family-combos.test.ts > auto/<family>
✖ chat pipeline applies Codex OAuth fingerprint and priority tier inside combos
Both call resetStorage() from beforeEach, which does an fs.rmSync(TEST_DATA_DIR,
{recursive: true, force: true}) with no retry, and intermittently loses the race
with a not-yet-released SQLite handle (ENOTEMPTY).
release/v3.8.51 fixed this in #11968 with a mechanical codemod adding
maxRetries/retryDelay to every recursive rm/rmSync/rmdirSync under tests/, but
that PR landed only on the release branch. Because main only receives work at
the release squash, it stayed broken for the whole cycle — and repo-wide gates
then turn every open PR into main red on checks unrelated to their diff.
This is the --base main twin: re-runs the same codemod that already shipped on
the release branch (scripts/ad-hoc/codemod-rm-maxretries.mjs), so the two
branches converge on identical test-teardown semantics. Test-only; no product
logic is touched.
The remaining three failures reported on #12133 (unit full suite exceeding its
4800s ceiling, package-artifact exceeding 1200s, and the boot-smoke that is
skipped as a consequence) are runner-contention timeouts, not code defects —
validate-release-green.mjs runs those heavy gates concurrently on one shared
hosted runner. There is no fix to port for those.
* chore(scripts): carry the rm-maxretries codemod onto main alongside its output
The codemod that generated the previous commit lives in the repo on
release/v3.8.51 (added by #11968) but was never on main. Bringing it over keeps
the tool next to the change it produced, so the transformation stays
reproducible and auditable from either branch.
162 lines
5.9 KiB
TypeScript
162 lines
5.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-codex-synced-routing-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const modelsDb = await import("../../src/lib/db/models.ts");
|
|
const providersDb = await import("../../src/lib/db/providers.ts");
|
|
const { getModelInfoCore } = await import("../../open-sse/services/model.ts");
|
|
|
|
type TestProvider = "anthropic" | "codex" | "openai";
|
|
|
|
const GPT_56_CODEX_MODEL = "gpt-5.6-sol";
|
|
const FUTURE_CODEX_MODEL = "codex-next-preview";
|
|
const FUTURE_NON_GPT_MODEL = "orion-preview-2027";
|
|
|
|
async function seedConnection(provider: TestProvider, isActive = true) {
|
|
return providersDb.createProviderConnection({
|
|
provider,
|
|
authType: provider === "codex" ? "oauth" : "apikey",
|
|
name: `${provider}-routing-test`,
|
|
email: provider === "codex" ? `${provider}@example.com` : undefined,
|
|
apiKey: provider !== "codex" ? `sk-${provider}-routing-test` : undefined,
|
|
isActive,
|
|
providerSpecificData: provider === "codex" ? { workspaceId: "ws-routing-test" } : undefined,
|
|
});
|
|
}
|
|
|
|
async function seedSyncedModel(provider: TestProvider, modelId: string, isActive = true) {
|
|
const connection = await seedConnection(provider, isActive);
|
|
assert.ok(connection?.id, `${provider} connection must be created`);
|
|
await modelsDb.replaceSyncedAvailableModelsForConnection(provider, String(connection.id), [
|
|
{
|
|
id: modelId,
|
|
name: modelId,
|
|
apiFormat: "openai-responses",
|
|
supportedEndpoints: ["chat"],
|
|
},
|
|
]);
|
|
return connection;
|
|
}
|
|
|
|
test.beforeEach(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
});
|
|
|
|
test.after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
test("bare GPT-5.6 model routes through Codex when it is the only active provider", async () => {
|
|
await seedSyncedModel("codex", GPT_56_CODEX_MODEL);
|
|
|
|
const info = await getModelInfoCore(GPT_56_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "codex");
|
|
assert.equal(info.model, GPT_56_CODEX_MODEL);
|
|
});
|
|
|
|
// #9275 put the whole gpt-5.6-sol tier set into CODEX_NATIVE_UNPREFIXED_MODELS, so an
|
|
// active Codex connection now claims the bare id ahead of OpenAI. Before, OpenAI won the
|
|
// overlap; the escape hatch is the explicit prefix, covered by the last test in this file.
|
|
test("Codex claims the bare model when both providers advertise it", async () => {
|
|
await seedSyncedModel("codex", GPT_56_CODEX_MODEL);
|
|
await seedSyncedModel("openai", GPT_56_CODEX_MODEL);
|
|
|
|
const info = await getModelInfoCore(GPT_56_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "codex");
|
|
assert.equal(info.model, GPT_56_CODEX_MODEL);
|
|
});
|
|
|
|
test("Codex is inferred when only its active catalog advertises the model", async () => {
|
|
await seedSyncedModel("codex", FUTURE_CODEX_MODEL);
|
|
await seedConnection("openai");
|
|
|
|
const info = await getModelInfoCore(FUTURE_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "codex");
|
|
assert.equal(info.model, FUTURE_CODEX_MODEL);
|
|
});
|
|
|
|
test("non-GPT models use the same active synchronized-catalog inference", async () => {
|
|
await seedSyncedModel("anthropic", FUTURE_NON_GPT_MODEL);
|
|
|
|
const info = await getModelInfoCore(FUTURE_NON_GPT_MODEL, null);
|
|
|
|
assert.equal(info.provider, "anthropic");
|
|
assert.equal(info.model, FUTURE_NON_GPT_MODEL);
|
|
});
|
|
|
|
test("OpenAI remains selected when it is the only active provider advertising the model", async () => {
|
|
await seedSyncedModel("openai", GPT_56_CODEX_MODEL);
|
|
|
|
const info = await getModelInfoCore(GPT_56_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "openai");
|
|
assert.equal(info.model, GPT_56_CODEX_MODEL);
|
|
});
|
|
|
|
test("inactive Codex synchronized models do not influence bare-model routing", async () => {
|
|
await seedSyncedModel("codex", GPT_56_CODEX_MODEL, false);
|
|
await seedSyncedModel("openai", GPT_56_CODEX_MODEL);
|
|
|
|
const info = await getModelInfoCore(GPT_56_CODEX_MODEL, null);
|
|
|
|
assert.equal(info.provider, "openai");
|
|
assert.equal(info.model, GPT_56_CODEX_MODEL);
|
|
});
|
|
|
|
test("Codex claims an overlapping static model when both connections are active", async () => {
|
|
await seedConnection("codex");
|
|
await seedConnection("openai");
|
|
|
|
const info = await getModelInfoCore("gpt-5.5", null);
|
|
|
|
assert.equal(info.provider, "codex");
|
|
assert.equal(info.model, "gpt-5.5");
|
|
});
|
|
|
|
// The regression #9275 introduced and this file now guards: the Codex-native set must
|
|
// never claim a bare id when no codex connection is active — an OpenAI-only install
|
|
// would get "no active credentials for provider: codex" for a model OpenAI serves.
|
|
test("a Codex-native bare id stays on OpenAI when no codex connection exists", async () => {
|
|
await seedConnection("openai");
|
|
|
|
const info = await getModelInfoCore("gpt-5.5", null);
|
|
|
|
assert.equal(info.provider, "openai");
|
|
assert.equal(info.model, "gpt-5.5");
|
|
});
|
|
|
|
test("OpenAI remains selected for an overlapping static model when Codex is inactive", async () => {
|
|
await seedConnection("codex", false);
|
|
await seedConnection("openai");
|
|
|
|
const info = await getModelInfoCore("gpt-5.5", null);
|
|
|
|
assert.equal(info.provider, "openai");
|
|
assert.equal(info.model, "gpt-5.5");
|
|
});
|
|
|
|
test("explicit Codex and OpenAI prefixes remain authoritative", async () => {
|
|
await seedSyncedModel("codex", GPT_56_CODEX_MODEL);
|
|
await seedSyncedModel("openai", GPT_56_CODEX_MODEL);
|
|
|
|
const codexAlias = await getModelInfoCore(`cx/${GPT_56_CODEX_MODEL}`, null);
|
|
const codexCanonical = await getModelInfoCore(`codex/${GPT_56_CODEX_MODEL}`, null);
|
|
const openai = await getModelInfoCore(`openai/${GPT_56_CODEX_MODEL}`, null);
|
|
|
|
assert.equal(codexAlias.provider, "codex");
|
|
assert.equal(codexCanonical.provider, "codex");
|
|
assert.equal(openai.provider, "openai");
|
|
});
|