Files
OmniRoute/tests/unit/cli-backup-command.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

110 lines
4.3 KiB
TypeScript

// ENVIRONMENT NOTE (sandbox better-sqlite3 / glibc limitation, not a code defect):
// This test constructs or exercises a real better-sqlite3-backed SQLite database.
// better-sqlite3 is a native addon; production and CI load it normally, but some
// sandboxes/dev boxes ship a system glibc older than the prebuilt binary requires
// ("GLIBC_2.29 not found"), so the native module fails to dlopen and any test that
// reaches better-sqlite3 directly (or asserts stdout that the load-failure warning
// would pollute) fails HERE while passing in CI. This is a known environment
// limitation, not a defect in the code under test: the OmniRoute runtime itself
// cascades to node:sqlite/sql.js when better-sqlite3 is unavailable. See
// tests/unit/_helpers/betterSqlite3Availability.ts for a guard helper.
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;
function createTempDataDir() {
return fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-cli-backup-"));
}
async function withBackupEnv(fn: (dataDir: string) => Promise<void>) {
const dataDir = createTempDataDir();
process.env.DATA_DIR = dataDir;
const originalLog = console.log;
console.log = () => {};
try {
await fn(dataDir);
} finally {
console.log = originalLog;
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("backup returns 0 with no files (empty data dir)", async () => {
await withBackupEnv(async () => {
const { runBackupCommand } = await import("../../bin/cli/commands/backup.mjs");
const result = await runBackupCommand({});
assert.equal(result, 0);
});
});
test("backup creates backup-info.json when storage.sqlite exists", async () => {
await withBackupEnv(async (dataDir) => {
const dbPath = path.join(dataDir, "storage.sqlite");
const Database = (await import("better-sqlite3")).default;
new Database(dbPath).close();
const { runBackupCommand } = await import("../../bin/cli/commands/backup.mjs");
const result = await runBackupCommand({});
assert.equal(result, 0);
const backupDir = path.join(dataDir, "backups");
assert.ok(fs.existsSync(backupDir));
const entries = fs.readdirSync(backupDir).filter((d) => d.startsWith("omniroute-backup-"));
assert.ok(entries.length > 0);
const infoPath = path.join(backupDir, entries[0], "backup-info.json");
assert.ok(fs.existsSync(infoPath));
const info = JSON.parse(fs.readFileSync(infoPath, "utf8"));
assert.ok(info.timestamp);
assert.ok(Array.isArray(info.files));
});
});
test("encrypted backup removes temporary ciphertext files", async () => {
await withBackupEnv(async (dataDir) => {
fs.writeFileSync(path.join(dataDir, "settings.json"), JSON.stringify({ ok: true }), "utf8");
const keyFile = path.join(dataDir, "backup.key");
fs.writeFileSync(keyFile, "test-passphrase", "utf8");
const { runBackupCommand } = await import("../../bin/cli/commands/backup.mjs");
const result = await runBackupCommand({ encrypt: true, keyFile });
assert.equal(result, 0);
const backupDir = path.join(dataDir, "backups");
const entries = fs.readdirSync(backupDir).filter((d) => d.startsWith("omniroute-backup-"));
assert.ok(entries.length > 0);
const backupPath = path.join(backupDir, entries[0]);
assert.deepEqual(
fs.readdirSync(backupPath).filter((name) => name.endsWith(".ciphertext")),
[]
);
assert.ok(fs.existsSync(path.join(backupPath, "settings.json.enc")));
});
});
test("restore --list returns 0 with no backups", async () => {
await withBackupEnv(async () => {
const { runRestoreCommand } = await import("../../bin/cli/commands/backup.mjs");
const result = await runRestoreCommand(undefined, { list: true });
assert.equal(result, 0);
});
});
test("restore returns 1 when backup id not found", async () => {
await withBackupEnv(async () => {
const { runRestoreCommand } = await import("../../bin/cli/commands/backup.mjs");
const originalError = console.error;
console.error = () => {};
const result = await runRestoreCommand("nonexistent-id", { yes: true });
console.error = originalError;
assert.equal(result, 1);
});
});