Files
OmniRoute/tests/unit/zcode-executor.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

87 lines
2.9 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
const fixture = join(process.cwd(), "tests/fixtures/fake-zcode-app-server.mjs");
const TEST_DATA_DIR = mkdtempSync(join(tmpdir(), "omniroute-zcode-"));
process.env.DATA_DIR = TEST_DATA_DIR;
test.after(() => rmSync(TEST_DATA_DIR, { recursive: true, force: true }));
async function loadZcodeExecutor() {
return import("../../open-sse/executors/zcode.ts");
}
function requestBody() {
return {
messages: [
{ role: "system", content: "You are a coding assistant." },
{ role: "user", content: "Reply with a short status." },
],
};
}
test("ZCode accepts GLM Coding Plan models and rejects unsafe/unknown ids", async () => {
const { resolveZcodeModel } = await loadZcodeExecutor();
assert.deepEqual(resolveZcodeModel("glm-5.2"), { ok: true, model: "glm-5.2" });
assert.equal(resolveZcodeModel("glm-5.2-high").ok, false);
assert.equal(resolveZcodeModel("glm-5.3-low").ok, false);
assert.equal(resolveZcodeModel("-unexpected").ok, false);
assert.equal(resolveZcodeModel("unknown-model").ok, false);
});
test("ZCode runs a local app-server turn and returns an OpenAI chat completion", async () => {
const { ZcodeExecutor } = await loadZcodeExecutor();
const executor = new ZcodeExecutor({
command: process.execPath,
args: [fixture],
cwd: process.cwd(),
requestTimeoutMs: 3000,
turnTimeoutMs: 3000,
pollIntervalMs: 1,
});
const result = await executor.execute({
model: "glm-5.2",
body: requestBody(),
stream: false,
credentials: {},
});
const response = "response" in result ? result.response : result;
assert.equal(response.status, 200);
assert.match(response.headers.get("content-type") || "", /application\/json/);
const body = await response.json();
assert.equal(body.object, "chat.completion");
assert.equal(body.model, "glm-5.2");
assert.equal(body.choices?.[0]?.message?.role, "assistant");
assert.equal(body.choices?.[0]?.message?.content, "fake zcode response");
assert.equal(body.choices?.[0]?.finish_reason, "stop");
});
test("ZCode buffers the completed turn into OpenAI SSE when stream=true", async () => {
const { ZcodeExecutor } = await loadZcodeExecutor();
const executor = new ZcodeExecutor({
command: process.execPath,
args: [fixture],
cwd: process.cwd(),
requestTimeoutMs: 3000,
turnTimeoutMs: 3000,
pollIntervalMs: 1,
});
const result = await executor.execute({
model: "glm-5.2",
body: requestBody(),
stream: true,
credentials: {},
});
const response = "response" in result ? result.response : result;
const text = await response.text();
assert.equal(response.status, 200);
assert.match(response.headers.get("content-type") || "", /text\/event-stream/);
assert.match(text, /fake zcode response/);
assert.match(text, /data: \[DONE\]/);
});