Files
OmniRoute/tests/unit/synced-model-delete-resync.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

56 lines
2.2 KiB
TypeScript

/**
* A synced model delete removes the current discovery row only. If the upstream
* provider advertises that model again, the next sync restores it. Persistent
* exclusion is represented by isHidden, not a separate deletion tombstone.
*/
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 mutates the syncedAvailableModels key_value namespace.
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-test-synced-del-"));
process.env.DATA_DIR = tmpDir;
const { replaceSyncedAvailableModelsForConnection, getSyncedAvailableModels } =
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 });
});
test("a deleted synced model is restored when upstream advertises it again", async () => {
const provider = "llama-cpp";
const connectionId = "conn-3199";
// Initial sync brings in two models.
await replaceSyncedAvailableModelsForConnection(provider, connectionId, [
{ id: "model-keep", name: "Keep" },
{ id: "model-del", name: "Delete me" },
]);
let synced = (await getSyncedAvailableModels(provider)).map((m) => m.id);
assert.ok(synced.includes("model-del"), "both models present after first sync");
const { removeSyncedAvailableModel } = await import("@/lib/db/models");
assert.equal(await removeSyncedAvailableModel(provider, "model-del"), true);
synced = (await getSyncedAvailableModels(provider)).map((m) => m.id);
assert.ok(!synced.includes("model-del"), "delete removes the current synced row");
// Auto-fetch re-imports the SAME upstream list (still advertising model-del).
await replaceSyncedAvailableModelsForConnection(provider, connectionId, [
{ id: "model-keep", name: "Keep" },
{ id: "model-del", name: "Delete me" },
]);
synced = (await getSyncedAvailableModels(provider)).map((m) => m.id);
assert.ok(synced.includes("model-keep"), "unrelated model stays");
assert.ok(synced.includes("model-del"), "upstream re-sync restores the deleted model");
});