Files
OmniRoute/tests/unit/model-hidden-modality-scope-12172.test.ts
Diego Rodrigues de Sa e Souza c79caa913a fix(db): scope model-hidden overrides by modality (#12172) (#13258)
Merged as part of the 39-PR owner batch of 2026-09-11, validated as a unit.

Boarded into one consolidated worktree cut from `release/v3.8.51` with the other 38 — zero conflicts between them.

- ESLint over every changed file: no errors (the only finding was one suppression entry the batch emptied, pruned on #13243)
- `typecheck:core` clean; `check:dashboard-typecheck` OK (206 pre-existing, within baseline); `check:changelog-integrity` OK
- complexity 2821 / baseline 3218 and cognitive-complexity 1272 / baseline 1437 — both under baseline
- 256 assertions green: 246 under node:test and 10 under vitest, which is where `tests/unit/**/*.test.tsx` actually runs
- `check-file-size`: `chatCore.ts` rebaselined 6144 → 6146 for #13278 and #13276, annotated and landed on #13243

⚠️ base-red inherited: #12732 — the provider count (356 in the docs vs the 358 the modules define) and `open-sse/utils/stream.ts` at 3115 > frozen 3098 both reproduce on the pure tip with zero contribution from this batch.
2026-09-11 22:04:31 -03:00

83 lines
3.5 KiB
TypeScript

/**
* Regression test for #12172 — a model ID collision between the Chat registry and a
* specialty modality registry (Image) prevented independent visibility toggling,
* because `modelCompatOverrides` was keyed only by (providerId, modelId) with no
* modality/endpoint field: hiding the chat model also hid the identically-ID'd
* image model, and vice versa.
*/
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-12172-modality-"));
process.env.DATA_DIR = TEST_DATA_DIR;
process.env.API_KEY_SECRET = process.env.API_KEY_SECRET || "modality-collision-test-secret";
const { setModelIsHidden, getModelIsHidden, getHiddenModelsByProvider } = await import(
"../../src/lib/db/models.ts"
);
const { resetDbInstance } = await import("../../src/lib/db/core.ts");
const { codexProvider } = await import(
"../../open-sse/config/providers/registry/codex/index.ts"
);
const { IMAGE_PROVIDERS } = await import("../../open-sse/config/imageRegistry.ts");
test.after(() => {
resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
test("#12172: codex chat and image registries collide on the same model id (premise)", () => {
const chatModel = codexProvider.models.find((m) => m.id === "gpt-5.6-sol");
const imageModel = IMAGE_PROVIDERS.codex.models.find((m) => m.id === "gpt-5.6-sol");
assert.ok(chatModel, "codex chat registry must define gpt-5.6-sol (premise check)");
assert.ok(imageModel, "codex image registry must define gpt-5.6-sol (premise check)");
});
test("#12172: hiding the codex CHAT model gpt-5.6-sol must not suppress the codex IMAGE model", () => {
setModelIsHidden("codex", "gpt-5.6-sol", true, "chat");
const chatHidden = getHiddenModelsByProvider("chat").get("codex");
const imageHidden = getHiddenModelsByProvider("images").get("codex");
assert.equal(chatHidden?.has("gpt-5.6-sol"), true, "chat model must be hidden after the toggle");
assert.equal(
imageHidden?.has("gpt-5.6-sol") ?? false,
false,
"BUG #12172: hiding the chat model must not also hide the identically-ID'd image model"
);
assert.equal(getModelIsHidden("codex", "gpt-5.6-sol", "chat"), true);
assert.equal(getModelIsHidden("codex", "gpt-5.6-sol", "images"), false);
});
test("#12172: unhiding one modality does not affect the other", () => {
setModelIsHidden("codex", "gpt-5.6-terra", true, "chat");
setModelIsHidden("codex", "gpt-5.6-terra", true, "images");
assert.equal(getModelIsHidden("codex", "gpt-5.6-terra", "chat"), true);
assert.equal(getModelIsHidden("codex", "gpt-5.6-terra", "images"), true);
setModelIsHidden("codex", "gpt-5.6-terra", false, "chat");
assert.equal(
getModelIsHidden("codex", "gpt-5.6-terra", "chat"),
false,
"chat toggle must not be affected by the images toggle"
);
assert.equal(
getModelIsHidden("codex", "gpt-5.6-terra", "images"),
true,
"images toggle must remain hidden after unhiding chat only"
);
});
test("#12172: a legacy (no-modality) hide keeps suppressing every modality — backward compatible", () => {
setModelIsHidden("codex", "gpt-5.6-luna", true);
assert.equal(getModelIsHidden("codex", "gpt-5.6-luna", "chat"), true);
assert.equal(getModelIsHidden("codex", "gpt-5.6-luna", "images"), true);
assert.equal(getHiddenModelsByProvider("chat").get("codex")?.has("gpt-5.6-luna"), true);
assert.equal(getHiddenModelsByProvider("images").get("codex")?.has("gpt-5.6-luna"), true);
});