Files
OmniRoute/tests/unit/auto-combo-hidden-models-4558.test.ts
Webman 50bc8ab8aa fix(barrel): delete the @/lib/localDb barrel — every consumer migrated (#11795 Phase 5) (#12055)
Resynced onto the release tip after #12051/#12052/#12053 landed. Same LKGP-clear conflict as #12053 (kept the current clearStaleLKGP() helper at both call sites). One additional issue this final phase's combined-worktree validation surfaced: clearStaleLKGP() itself (added by #12013, which none of the 4 phase PRs could have seen since it landed after they were authored) still had a dynamic `await import("@/lib/localDb")` — a real break once this PR deletes the barrel. Fixed to `await import("@/lib/db/settings")`, matching the direct-import pattern used at every other call site. typecheck:core, check-db-rules, check:cycles, and the eslint-import-boundaries regression test (3/3, including "G14 rejects localDb barrel imports") all green after resync — zero barrel-importing production files remain. Nice clean 5-phase migration, and thanks for taking on the full #11795 cleanup.
2026-08-30 02:36:26 -03:00

96 lines
3.8 KiB
TypeScript

/**
* #4558 — Auto-combo must respect model visibility (isHidden).
*
* When an operator hides a model with the EYE/visibility toggle
* (`mergeModelCompatOverride(provider, model, { isHidden: true })`, written to
* the `modelCompatOverrides` key_value namespace), that model must be excluded
* from the AUTO-combo candidate pool. Both auto paths consume the same seam:
* - `open-sse/services/combo.ts::buildAutoCandidates` (combo.ts:322,520-521)
* - `open-sse/services/autoCombo/virtualFactory.ts` (virtualFactory.ts:239,256-257)
* via the new bulk `getHiddenModelsByProvider()` map (single query, not N+1).
*
* This guards that seam: a hidden model is present in the map's per-provider set
* while a visible sibling is not, and that toggling visibility back off
* (`isHidden: null`) removes it from the map again. Without the fix the map is
* empty and the auto pool would keep serving hidden models.
*/
import test, { before, after } from "node:test";
import assert from "node:assert/strict";
import os from "node:os";
import path from "node:path";
import fs from "node:fs";
// Hermetic DB: this test writes overrides into the `modelCompatOverrides`
// key_value namespace. Without an isolated DATA_DIR it would leak that state
// into the shared dev/CI database. Point DATA_DIR at a throwaway dir before any
// import that opens the SQLite handle (CLAUDE.md "Database Handles in Tests").
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-test-hidden-4558-"));
process.env.DATA_DIR = tmpDir;
const {
addCustomModel,
getHiddenModelsByProvider,
getModelIsHidden,
mergeModelCompatOverride,
updateCustomModel,
} = await import("@/lib/db/models");
const { resetDbInstance } = await import("../../src/lib/db/core.ts");
before(() => {
resetDbInstance();
});
after(() => {
resetDbInstance();
fs.rmSync(tmpDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
});
const PROVIDER = "openai";
const HIDDEN_MODEL = "gpt-hidden-preview";
const VISIBLE_MODEL = "gpt-visible-4o";
test("getHiddenModelsByProvider: empty before any model is hidden", () => {
const map = getHiddenModelsByProvider();
assert.equal(map.get(PROVIDER)?.has(HIDDEN_MODEL) ?? false, false);
});
test("a hidden model lands in the provider's hidden set; a visible sibling does not", () => {
// Hide one model, leave a sibling visible (overridden for an unrelated reason).
mergeModelCompatOverride(PROVIDER, HIDDEN_MODEL, { isHidden: true });
mergeModelCompatOverride(PROVIDER, VISIBLE_MODEL, { normalizeToolCallId: true });
// Sanity: the per-model read agrees.
assert.equal(getModelIsHidden(PROVIDER, HIDDEN_MODEL), true);
assert.equal(getModelIsHidden(PROVIDER, VISIBLE_MODEL), false);
const map = getHiddenModelsByProvider();
const hiddenForProvider = map.get(PROVIDER);
assert.ok(hiddenForProvider, "expected an entry for the provider");
assert.equal(hiddenForProvider.has(HIDDEN_MODEL), true, "hidden model must be in the set");
assert.equal(
hiddenForProvider.has(VISIBLE_MODEL),
false,
"visible model must NOT be in the hidden set"
);
});
test("un-hiding a model (isHidden: null) removes it from the map", () => {
mergeModelCompatOverride(PROVIDER, HIDDEN_MODEL, { isHidden: null });
const map = getHiddenModelsByProvider();
assert.equal(
map.get(PROVIDER)?.has(HIDDEN_MODEL) ?? false,
false,
"un-hidden model must drop out of the hidden set"
);
});
test("an explicit visible custom-model setting overrides a hidden compat fallback", async () => {
const modelId = "gpt-custom-visible-override";
mergeModelCompatOverride(PROVIDER, modelId, { isHidden: true });
await addCustomModel(PROVIDER, modelId);
await updateCustomModel(PROVIDER, modelId, { isHidden: false });
assert.equal(getModelIsHidden(PROVIDER, modelId), false);
assert.equal(getHiddenModelsByProvider().get(PROVIDER)?.has(modelId) ?? false, false);
});