Files
OmniRoute/tests/unit/replace-custom-models-preserve-hidden-5086.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

67 lines
2.6 KiB
TypeScript

/**
* #5086 / #4389 — model visibility reset after periodic sync.
*
* The EYE/visibility toggle hides a model by writing `isHidden:true` into the
* `modelCompatOverrides` namespace via `mergeModelCompatOverride`. Hidden flags
* for SYNCED models live there, not in the `customModels` store.
*
* Before the fix, `replaceCustomModels` pruned the compat-override list down to
* only the ids present in the new `customModels` array. The periodic model sync
* (and manual import) calls `replaceCustomModels` with a list that does NOT
* contain eye-hidden synced models, so their `isHidden` override was silently
* wiped — every hidden model turned back on after a sync.
*
* This guards that an eye-hidden override survives a `replaceCustomModels` call
* whose new model list omits that id.
*/
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 (see #3782 test): isolate DATA_DIR so override state never leaks
// into the shared dev/CI database between runs.
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-test-replace-custom-hide-"));
process.env.DATA_DIR = tmpDir;
const { replaceCustomModels, mergeModelCompatOverride, getModelIsHidden, getModelCompatOverrides } =
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 = "llama-cpp-5086";
test("an eye-hidden override survives replaceCustomModels when the new list omits it", async () => {
// Operator hides a SYNCED model "ghost" with the EYE toggle (visibility only).
mergeModelCompatOverride(PROVIDER, "ghost", { isHidden: true });
assert.equal(getModelIsHidden(PROVIDER, "ghost"), true, "ghost is eye-hidden before sync");
// A periodic sync / import replaces the CUSTOM models with a list that does
// NOT include "ghost" (it lives in the synced store, not customModels).
await replaceCustomModels(PROVIDER, [
{ id: "keep-1", name: "Keep One" },
{ id: "keep-2", name: "Keep Two" },
]);
// The compat override (and thus the hidden flag) must NOT be wiped.
assert.equal(
getModelIsHidden(PROVIDER, "ghost"),
true,
"ghost must stay hidden after replaceCustomModels omits it"
);
const overrides = getModelCompatOverrides(PROVIDER).map((o) => o.id);
assert.ok(
overrides.includes("ghost"),
"the compat override for ghost must still exist after the sync"
);
});