Files
OmniRoute/tests/unit/conductor-fleet-route.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

104 lines
4.2 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";
import { createServer, type Server } from "node:http";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-conductor-route-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const fleetRoute = await import("../../src/app/api/conductor/fleet/route.ts");
const detailRoute = await import("../../src/app/api/conductor/tasks/[id]/route.ts");
const cancelRoute = await import("../../src/app/api/conductor/tasks/[id]/cancel/route.ts");
const servers: Server[] = [];
function fakeHub(routes: Record<string, { status: number; body: unknown }>): Promise<string> {
const server = createServer((req, res) => {
const hit = Object.entries(routes).find(([p]) => (req.url ?? "").startsWith(p));
res.writeHead(hit ? hit[1].status : 404, { "content-type": "application/json" });
res.end(JSON.stringify(hit ? hit[1].body : { error: "hub: segredo interno que NÃO pode vazar" }));
});
servers.push(server);
return new Promise((resolve) => {
server.listen(0, "127.0.0.1", () => {
const addr = server.address();
resolve(`http://127.0.0.1:${typeof addr === "object" && addr ? addr.port : 0}`);
});
});
}
test.beforeEach(() => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
delete process.env.CONDUCTOR_HUB_URL;
delete process.env.CONDUCTOR_HUB_TOKEN;
});
test.after(async () => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
delete process.env.CONDUCTOR_HUB_URL;
while (servers.length > 0) {
const s = servers.pop();
await new Promise((resolve) => s?.close(resolve));
}
});
test("GET /api/conductor/fleet devolve snapshot whitelisted; sem hub → degradado 200", async () => {
process.env.CONDUCTOR_HUB_URL = await fakeHub({
"/v1/runners": {
status: 200,
body: [{ id: "r_1", token: "VAZOU?", online: true, capabilities: { name: "devbox", clis: [{ profile: "claude" }] } }],
},
"/v1/tasks": {
status: 200,
body: [{ id: "t_1", status: "working", mode: "solo", repo: { url: "https://x/r" }, assigned_runner: "r_1" }],
},
});
process.env.CONDUCTOR_HUB_TOKEN = "tok";
const res = await fleetRoute.GET(new Request("http://localhost/api/conductor/fleet"));
assert.equal(res.status, 200);
const body = await res.json();
assert.equal(body.offline, false);
assert.equal(body.runners[0].name, "devbox");
assert.equal(body.tasks[0].status, "working");
assert.ok(!JSON.stringify(body).includes("VAZOU?"), "token de runner não vaza pela rota");
delete process.env.CONDUCTOR_HUB_URL; // sem hub: degradado, nunca 500
const down = await fleetRoute.GET(new Request("http://localhost/api/conductor/fleet"));
assert.equal(down.status, 200);
assert.equal((await down.json()).offline, true);
});
test("GET /api/conductor/tasks/[id] → 404 sanitizado quando o hub não conhece a task", async () => {
process.env.CONDUCTOR_HUB_URL = await fakeHub({});
const res = await detailRoute.GET(new Request("http://localhost/api/conductor/tasks/t_x"), {
params: Promise.resolve({ id: "t_x" }),
});
assert.equal(res.status, 404);
const text = await res.text();
assert.ok(!text.includes("segredo interno"), "corpo do hub NUNCA repassado");
});
test("POST cancel repassa recusa do hub com status, sem corpo upstream", async () => {
process.env.CONDUCTOR_HUB_URL = await fakeHub({
"/v1/tasks/t_done/cancel": { status: 409, body: { error: "segredo interno que NÃO pode vazar" } },
"/v1/tasks/t_ok/cancel": { status: 200, body: { ok: true } },
});
const denied = await cancelRoute.POST(new Request("http://localhost/x", { method: "POST" }), {
params: Promise.resolve({ id: "t_done" }),
});
assert.equal(denied.status, 409);
assert.ok(!(await denied.text()).includes("segredo interno"));
const ok = await cancelRoute.POST(new Request("http://localhost/x", { method: "POST" }), {
params: Promise.resolve({ id: "t_ok" }),
});
assert.equal(ok.status, 200);
assert.deepEqual(await ok.json(), { ok: true });
});