mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 17:12:27 +03:00
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.
110 lines
3.8 KiB
TypeScript
110 lines
3.8 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
const ORIGINAL_DATA_DIR = process.env.DATA_DIR;
|
|
const ORIGINAL_FETCH = globalThis.fetch;
|
|
|
|
function createTempDataDir() {
|
|
return fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-cli-combo-"));
|
|
}
|
|
|
|
async function withComboEnv(fn: (dataDir: string) => Promise<void>) {
|
|
const dataDir = createTempDataDir();
|
|
process.env.DATA_DIR = dataDir;
|
|
// Mock fetch → simulates server offline so withRuntime falls back to DB
|
|
globalThis.fetch = (async () => {
|
|
throw new Error("server offline");
|
|
}) as typeof fetch;
|
|
|
|
const originalLog = console.log;
|
|
console.log = () => {};
|
|
|
|
try {
|
|
await fn(dataDir);
|
|
} finally {
|
|
console.log = originalLog;
|
|
globalThis.fetch = ORIGINAL_FETCH;
|
|
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
|
|
if (ORIGINAL_DATA_DIR === undefined) delete process.env.DATA_DIR;
|
|
else process.env.DATA_DIR = ORIGINAL_DATA_DIR;
|
|
}
|
|
}
|
|
|
|
test("combo create inserts a new combo via db module", async () => {
|
|
await withComboEnv(async () => {
|
|
const { runComboCreateCommand } = await import("../../bin/cli/commands/combo.mjs");
|
|
// #11162: combo create refuses combos without any model — pass a model
|
|
// like the sibling tests updated in that commit.
|
|
const result = await runComboCreateCommand("my-combo", "priority", {
|
|
models: ["openai/gpt-4o-mini"],
|
|
});
|
|
assert.equal(result, 0);
|
|
|
|
// Verify via the same db module
|
|
const { getComboByName } = await import("../../src/lib/db/combos.ts");
|
|
const combo = await getComboByName("my-combo");
|
|
assert.ok(combo);
|
|
assert.equal(combo.name, "my-combo");
|
|
assert.equal(combo.strategy, "priority");
|
|
});
|
|
});
|
|
|
|
test("combo create fails if combo already exists", async () => {
|
|
await withComboEnv(async () => {
|
|
const { runComboCreateCommand } = await import("../../bin/cli/commands/combo.mjs");
|
|
|
|
await runComboCreateCommand("dup-combo", "auto", { models: ["openai/gpt-4o-mini"] });
|
|
const originalError = console.error;
|
|
console.error = () => {};
|
|
const result = await runComboCreateCommand("dup-combo", "auto", {
|
|
models: ["openai/gpt-4o-mini"],
|
|
});
|
|
console.error = originalError;
|
|
|
|
assert.equal(result, 1);
|
|
});
|
|
});
|
|
|
|
test("combo delete removes the combo", async () => {
|
|
await withComboEnv(async () => {
|
|
const { runComboCreateCommand, runComboDeleteCommand } =
|
|
await import("../../bin/cli/commands/combo.mjs");
|
|
|
|
await runComboCreateCommand("to-delete", "weighted", { models: ["openai/gpt-4o-mini"] });
|
|
const result = await runComboDeleteCommand("to-delete", { yes: true });
|
|
assert.equal(result, 0);
|
|
|
|
const { getComboByName } = await import("../../src/lib/db/combos.ts");
|
|
const combo = await getComboByName("to-delete");
|
|
assert.equal(combo, null);
|
|
});
|
|
});
|
|
|
|
test("combo list returns 0 with empty combos table", async () => {
|
|
await withComboEnv(async () => {
|
|
const { runComboListCommand } = await import("../../bin/cli/commands/combo.mjs");
|
|
const result = await runComboListCommand({});
|
|
assert.equal(result, 0);
|
|
});
|
|
});
|
|
|
|
test("combo switch updates active combo when server is offline", async () => {
|
|
await withComboEnv(async () => {
|
|
const { runComboCreateCommand, runComboSwitchCommand } =
|
|
await import("../../bin/cli/commands/combo.mjs");
|
|
|
|
await runComboCreateCommand("my-switch", "round-robin", { models: ["openai/gpt-4o-mini"] });
|
|
const result = await runComboSwitchCommand("my-switch", {});
|
|
assert.equal(result, 0);
|
|
|
|
// Verify active combo written to key_value settings
|
|
const { getSettings } = await import("../../src/lib/db/settings.ts");
|
|
const settings = await getSettings();
|
|
assert.equal((settings as Record<string, unknown>).activeCombo, "my-switch");
|
|
});
|
|
});
|