mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +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.
98 lines
3.5 KiB
TypeScript
98 lines
3.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
|
|
function makeResponse(data: unknown, status = 200): Response {
|
|
return {
|
|
ok: status >= 200 && status < 300,
|
|
status,
|
|
headers: new Headers(),
|
|
json: async () => data,
|
|
text: async () => JSON.stringify(data),
|
|
} as Response;
|
|
}
|
|
|
|
async function captureStdout(fn: () => Promise<number>): Promise<{ output: string; code: number }> {
|
|
const chunks: string[] = [];
|
|
const original = process.stdout.write.bind(process.stdout);
|
|
process.stdout.write = ((chunk: string | Uint8Array) => {
|
|
if (typeof chunk === "string") chunks.push(chunk);
|
|
return true;
|
|
}) as typeof process.stdout.write;
|
|
try {
|
|
const code = await fn();
|
|
return { output: chunks.join(""), code };
|
|
} finally {
|
|
process.stdout.write = original;
|
|
}
|
|
}
|
|
|
|
test("radar status is GET-only, read-only, and prints no secret", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
let method = "GET";
|
|
let url = "";
|
|
globalThis.fetch = (async (input, init) => {
|
|
url = String(input);
|
|
method = init?.method ?? "GET";
|
|
return makeResponse({
|
|
settings: { optIn: true, hasSupporterKey: true },
|
|
feeds: { catalog: { available: true, version: "2026.08.09.1", tier: "live" } },
|
|
});
|
|
}) as typeof fetch;
|
|
try {
|
|
const { runRadarStatusCommand } = await import("../../bin/cli/commands/radar.mjs");
|
|
const result = await captureStdout(() => runRadarStatusCommand({ output: "json" }));
|
|
assert.equal(result.code, 0);
|
|
assert.match(url, /\/api\/radar\/status$/);
|
|
assert.equal(method, "GET");
|
|
assert.ok(!result.output.includes("omr_"));
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|
|
|
|
test("radar sync posts only to the local aggregate route and prints per-feed results", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
let method = "";
|
|
let url = "";
|
|
globalThis.fetch = (async (input, init) => {
|
|
url = String(input);
|
|
method = init?.method ?? "GET";
|
|
return makeResponse({
|
|
catalog: { status: "updated", version: "2026.08.09.1" },
|
|
referrals: { status: "stale" },
|
|
offers: { status: "no_key" },
|
|
intel: { status: "no_key" },
|
|
});
|
|
}) as typeof fetch;
|
|
try {
|
|
const { runRadarSyncCommand } = await import("../../bin/cli/commands/radar.mjs");
|
|
const result = await captureStdout(() => runRadarSyncCommand({ output: "json" }));
|
|
assert.equal(result.code, 0);
|
|
assert.match(url, /\/api\/radar\/sync-all$/);
|
|
assert.equal(method, "POST");
|
|
const parsed = JSON.parse(result.output) as Record<string, unknown>;
|
|
assert.deepEqual(Object.keys(parsed).sort(), ["catalog", "intel", "offers", "referrals"]);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|
|
|
|
test("CLI registry exposes nested radar status and sync commands with EN/PT strings", async () => {
|
|
const { createProgram } = await import("../../bin/cli/program.mjs");
|
|
const program = createProgram();
|
|
const radar = program.commands.find((command) => command.name() === "radar");
|
|
assert.ok(radar);
|
|
assert.deepEqual(radar.commands.map((command) => command.name()).sort(), ["status", "sync"]);
|
|
|
|
for (const locale of ["en", "pt-BR"]) {
|
|
const messages = JSON.parse(
|
|
fs.readFileSync(path.resolve(process.cwd(), `bin/cli/locales/${locale}.json`), "utf8")
|
|
) as { radar?: Record<string, unknown> };
|
|
assert.equal(typeof messages.radar?.description, "string");
|
|
assert.equal(typeof messages.radar?.status, "string");
|
|
assert.equal(typeof messages.radar?.sync, "string");
|
|
}
|
|
});
|