Files
OmniRoute/tests/unit/combo-model-name-collision-8530.test.ts
Diego Rodrigues de Sa e Souza 3d4f3e4960 test(infra): retry recursive temp-dir removal instead of failing a shard on ENOTEMPTY (#11966) (#11968)
* test(infra): retry recursive temp-dir removal instead of failing a shard on ENOTEMPTY (#11966)

Two shards on release/v3.8.51 went red in one day with the same signature —
"ENOTEMPTY, Directory not empty: /tmp/omniroute-<test>-XXXXXX" — from
combo-same-provider-cascade (Unit Tests fast-path 4/4, on a PR that touches only
.github/) and auth-policy-embeddings-webfetch-7785 (the 20k-test TIA step). Both pass
alone and on re-run: the cleanup races something still writing into the directory
(SQLite WAL/-shm checkpoint, a worker, the backup) and under a loaded hosted runner
the window opens. 1154 test files do their own cleanup with
fs.rmSync(dir, { recursive: true, force: true }); 57 already asked for retries.

One-shot codemod (scripts/ad-hoc/codemod-rm-maxretries.mjs, kept for the record):
every rm / rmSync / rmdirSync option object with `recursive: true` and no
`maxRetries` gains `maxRetries: 5, retryDelay: 100` — Node itself then retries
ENOTEMPTY/EBUSY/EPERM for up to ~0.5 s before giving up. 2243 call sites in 1292
files under tests/, the shared tests/_setup/isolateDataDir.ts exit hook included.
Only the option object changes: no call site, assertion or import is touched.

Validation: prettier and ESLint (with the frozen suppressions) clean on all 1292
files; a random 20-file sample runs green (quota-redis-store hangs identically on
the untouched tree — it needs a Redis on localhost, an environment matter). The
four unit shards on this PR are the full run.

* fix(quality): let check-forgotten-sibling-tests read a 1,000-file diff

The gate shells out to `git diff` through execFileSync with Node's default 1 MB
maxBuffer; the 1,292-file codemod in this PR is the first diff large enough to
overflow it, and the gate died with `spawnSync git ENOBUFS` before comparing
anything. 64 MB is far above any real PR and costs nothing when unused.
2026-08-29 01:17:40 -03:00

191 lines
6.9 KiB
TypeScript

// #8530 — combo name / model id collision guard.
//
// #6940 (closed by the maintainer) documents a combo named identically to a
// bare model id (e.g. combo `gpt-5.5`) as THE supported mechanism for
// per-model provider fallback — see `tests/unit/responses-combo-resolution-3227.test.ts`
// and `tests/unit/combo-name-codex-responses-rewrite.test.ts` for the
// combo-before-rewrite precedence this relies on. So creation/rename must
// NEVER hard-reject a colliding name (that would regress #6940); it must
// only make the collision observable via a non-blocking `warning` field.
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-combo-collision-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const combosDb = await import("../../src/lib/db/combos.ts");
const createRoute = await import("../../src/app/api/combos/route.ts");
const comboRoute = await import("../../src/app/api/combos/[id]/route.ts");
const collision = await import("../../src/lib/combos/modelNameCollision.ts");
// A model id that really is registered by multiple providers (verified via
// PROVIDER_MODELS at write time — see open-sse/config/providers/*).
const REAL_MODEL_ID = "gpt-5.5";
// Not a registered bare model id anywhere in the provider registry.
const NON_COLLIDING_NAME = "not-a-real-model-8530-guard-probe";
interface ComboResponseBody {
name?: string;
warning?: { code: string; modelId: string; providerId: string };
}
async function resetStorage() {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
}
function makeCreateRequest(body: unknown) {
return new Request("http://localhost/api/combos", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
});
}
function makeUpdateRequest(body: unknown) {
return new Request("http://localhost/api/combos/combo-1", {
method: "PUT",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
});
}
test.beforeEach(async () => {
await resetStorage();
});
test.after(() => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
});
test("POST /api/combos: name colliding with a real model id is created (#6940 pattern), with a warning", async () => {
const response = await createRoute.POST(
makeCreateRequest({
name: REAL_MODEL_ID,
strategy: "priority",
models: [
{ providerId: "codex", model: REAL_MODEL_ID },
{ providerId: "openai", model: REAL_MODEL_ID },
],
})
);
const body = (await response.json()) as ComboResponseBody;
// Legitimate/sanctioned shape MUST still pass — never a 4xx (would regress #6940).
assert.equal(response.status, 201);
assert.equal(body.name, REAL_MODEL_ID);
const stored = await combosDb.getComboByName(REAL_MODEL_ID);
assert.equal(stored?.name, REAL_MODEL_ID);
// But it is now observable via a non-blocking warning.
assert.equal(body.warning?.code, "COMBO_NAME_SHADOWS_MODEL");
assert.equal(body.warning?.modelId, REAL_MODEL_ID);
assert.equal(typeof body.warning?.providerId, "string");
});
test("POST /api/combos: non-colliding name is created with no warning field at all", async () => {
const response = await createRoute.POST(
makeCreateRequest({
name: NON_COLLIDING_NAME,
strategy: "priority",
models: [{ providerId: "claude", model: "claude-sonnet-4-6" }],
})
);
const body = (await response.json()) as ComboResponseBody;
assert.equal(response.status, 201);
assert.equal(body.name, NON_COLLIDING_NAME);
assert.equal("warning" in body, false);
});
test("PUT /api/combos/[id]: renaming to a real model id is applied (#6940 pattern), with a warning", async () => {
const combo = await combosDb.createCombo({
name: "claude-plain",
models: [{ provider: "claude", model: "claude-sonnet-4-6" }],
});
const response = await comboRoute.PUT(makeUpdateRequest({ name: REAL_MODEL_ID }), {
params: Promise.resolve({ id: combo.id }),
});
const body = (await response.json()) as ComboResponseBody;
// Legitimate/sanctioned rename MUST still pass — never a 4xx.
assert.equal(response.status, 200);
assert.equal(body.name, REAL_MODEL_ID);
const stored = await combosDb.getComboByName(REAL_MODEL_ID);
assert.equal(stored?.id, combo.id);
assert.equal(body.warning?.code, "COMBO_NAME_SHADOWS_MODEL");
assert.equal(body.warning?.modelId, REAL_MODEL_ID);
});
test("PUT /api/combos/[id]: renaming to a non-colliding name has no warning field", async () => {
const combo = await combosDb.createCombo({
name: "claude-plain",
models: [{ provider: "claude", model: "claude-sonnet-4-6" }],
});
const response = await comboRoute.PUT(makeUpdateRequest({ name: NON_COLLIDING_NAME }), {
params: Promise.resolve({ id: combo.id }),
});
const body = (await response.json()) as ComboResponseBody;
assert.equal(response.status, 200);
assert.equal(body.name, NON_COLLIDING_NAME);
assert.equal("warning" in body, false);
});
test("scanCombosForModelCollisions: reports existing combos that shadow a real model id", () => {
const results = collision.scanCombosForModelCollisions([
{ name: REAL_MODEL_ID },
{ name: NON_COLLIDING_NAME },
{ name: "" },
]);
assert.equal(results.length, 1);
assert.equal(results[0].comboName, REAL_MODEL_ID);
assert.equal(results[0].modelId, REAL_MODEL_ID);
});
test("findCollidingModel: returns null for a name with no real-model-id collision", () => {
assert.equal(collision.findCollidingModel(NON_COLLIDING_NAME), null);
});
test("scanComboModelNameCollisionsAtBoot: logs a startup warning enumerating existing collisions", async () => {
await combosDb.createCombo({
name: REAL_MODEL_ID,
models: [{ provider: "codex", model: REAL_MODEL_ID }],
});
await combosDb.createCombo({
name: NON_COLLIDING_NAME,
models: [{ provider: "claude", model: "claude-sonnet-4-6" }],
});
const { scanComboModelNameCollisionsAtBoot } = await import("../../src/instrumentation-node.ts");
const originalWarn = console.warn;
const warnings: unknown[][] = [];
console.warn = (...args: unknown[]) => {
warnings.push(args);
};
try {
await scanComboModelNameCollisionsAtBoot();
} finally {
console.warn = originalWarn;
}
const collisionWarning = warnings.find((args) =>
String(args[0]).includes("share a name with a real model id (#8530)")
);
assert.ok(collisionWarning, "expected a startup warning about the model-name collision");
assert.ok(String(collisionWarning![0]).includes(REAL_MODEL_ID));
assert.ok(
!String(collisionWarning![0]).includes(NON_COLLIDING_NAME),
"non-colliding combo must not be reported"
);
});