Files
OmniRoute/tests/unit/synced-capability-warmup-8697.test.ts
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host.

Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean.

Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
2026-08-23 11:45:01 -03:00

66 lines
2.5 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it, mock } from "node:test";
import { getDbInstance } from "../../src/lib/db/core.ts";
import {
getSyncedCapabilities,
getSyncedCapability,
loadAllSyncedCapabilitiesUncached,
} from "../../src/lib/modelsDevSync.ts";
// #8697 guarded the cold /v1/models catalog build against one SQLite round-trip per
// distinct model lookup. #9199 deliberately moved that contract: getSyncedCapability()
// no longer self-warms the module cache — bulk callers (catalog builds) must pass a
// build-local snapshot (`bulk`, from loadAllSyncedCapabilitiesUncached()), and warm
// runtime lookups are served from the module cache. Both paths must stay off SQLite
// per model, otherwise the #8697 cold-catalog freeze regresses.
describe("getSyncedCapability bulk/warm lookups (#8697-adjacent, contract per #9199)", () => {
it("does not touch SQLite per model when a bulk snapshot is supplied (catalog build path)", () => {
const bulk = loadAllSyncedCapabilitiesUncached();
const db = getDbInstance();
const prepareSpy = mock.method(db, "prepare");
const callsBefore = prepareSpy.mock.calls.length;
const N = 200;
for (let i = 0; i < N; i++) {
getSyncedCapability("openai", `synthetic-model-${i}`, bulk);
}
const callsAfter = prepareSpy.mock.calls.length;
prepareSpy.mock.restore();
assert.equal(
callsAfter - callsBefore,
0,
`expected 0 db.prepare() calls across ${N} distinct model lookups with a bulk ` +
`snapshot, got ${callsAfter - callsBefore} — the catalog build path may have ` +
`regressed to a per-model SQLite round-trip (#8697)`
);
});
it("does not touch SQLite per model once the whole-table cache is warm", () => {
// Warm the module cache the way runtime callers do (one bulk read + table guard).
getSyncedCapabilities();
const db = getDbInstance();
const prepareSpy = mock.method(db, "prepare");
const callsBefore = prepareSpy.mock.calls.length;
const N = 200;
for (let i = 0; i < N; i++) {
getSyncedCapability("openai", `synthetic-model-${i}`);
}
const callsAfter = prepareSpy.mock.calls.length;
prepareSpy.mock.restore();
assert.equal(
callsAfter - callsBefore,
0,
`expected 0 db.prepare() calls across ${N} distinct model lookups on a warm ` +
`cache, got ${callsAfter - callsBefore} — warm-path lookups may have regressed ` +
`to a per-model SQLite round-trip (#8697)`
);
});
});