Files
OmniRoute/tests/unit/active-catalog-display-snapshot.test.ts
Jan Leon a928ea8762 fix(models): reconcile provider dashboards with active live catalogs (#13434)
Merged. The NVIDIA 116-vs-82 discrepancy is the visible symptom; the fix is the right one — reuse the existing `liveCatalogAuthoritative` policy on the dashboard listing instead of a provider-specific filter, refresh after a removals-only import, keep the last confirmed snapshot on a failed refresh, and apply the same membership rule to the OpenRouter/compatible/passthrough row builders so static fallbacks cannot resurrect retired rows. Operator custom models and overrides preserved.

Validated as a combined board first (this PR merged with the 4 siblings of the JxnLexn wave on the release tip): eslint with the frozen suppressions, typecheck:core, check:open-sse-typecheck, complexity, cognitive-complexity, changelog-integrity, docs-sync, migration-numbering, provider-consistency and a duplicate-identifier audit all green, plus 77 passing / 0 failing focused node:test cases across the test files the wave touches. The wave's i18n fill (new keys carried to all 66 locales), free-tier doc counts and file-size rebaseline land in one follow-up PR right after the wave, as with #13904.

Thank you — checking the projection against 14 production catalog snapshots is the kind of evidence that makes a listing change safe to land.
2026-09-16 16:56:28 -03:00

56 lines
2.1 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-display-catalog-"));
process.env.DATA_DIR = directory;
process.env.API_KEY_SECRET = "display-catalog-test-secret";
const core = await import("../../src/lib/db/core.ts");
const { replaceSyncedAvailableModelsForConnection } = await import("../../src/lib/db/models.ts");
const { getActiveSyncedCatalog } = await import("../../src/lib/db/models/activeSyncedCatalog.ts");
test.after(() => {
core.resetDbInstance();
fs.rmSync(directory, { recursive: true, force: true });
});
test("display snapshot unions active connections, excludes inactive catalogs and custom/import overlays", async () => {
const db = core.getDbInstance();
const now = new Date().toISOString();
for (const [id, active] of [
["active-a", 1],
["active-b", 1],
["inactive", 0],
] as const) {
db.prepare(
"INSERT INTO provider_connections (id,provider,is_active,created_at,updated_at) VALUES (?,?,?,?,?)"
).run(id, "nvidia", active, now, now);
await replaceSyncedAvailableModelsForConnection("nvidia", id, [
{ id: `${id}-model`, name: id },
]);
}
db.prepare("INSERT OR REPLACE INTO key_value (namespace,key,value) VALUES (?,?,?)").run(
"customModels",
"nvidia",
JSON.stringify([
{ id: "manual", source: "custom" },
{ id: "old-import", source: "imported" },
])
);
const catalog = await getActiveSyncedCatalog("nvidia", false);
assert.equal(catalog.authoritative, true);
assert.deepEqual(catalog.models.map((m) => m.id).sort(), ["active-a-model", "active-b-model"]);
});
test("custom rows alone cannot establish an authoritative discovery snapshot", async () => {
core
.getDbInstance()
.prepare("INSERT OR REPLACE INTO key_value (namespace,key,value) VALUES (?,?,?)")
.run("customModels", "openai", JSON.stringify([{ id: "manual", source: "custom" }]));
const catalog = await getActiveSyncedCatalog("openai", false);
assert.equal(catalog.authoritative, false);
assert.equal(catalog.models.length, 0);
});