import { describe, it } from "node:test"; import assert from "node:assert/strict"; import type { Api, Model } from "@earendil-works/pi-ai"; import { loadConfig } from "../../src/config.js"; import { MEMORY_LLM_MODEL } from "../../src/constants.js"; import { buildChildPiPromptArgs, execChildPrompt } from "../../src/handlers/pi-child-process.js"; import { resolveReviewModel } from "../../src/handlers/review-memory-ops.js"; const config = loadConfig("/nonexistent/memory-model-test.json"); const active = { provider: "other", id: "chat" } as Model; const pinned = { provider: "tokenin", id: "deepseek-v4.1-flash" } as Model; describe("fixed Selesai memory model", () => { it("selects the fixed model instead of the active chat model", () => { const registry = { getAll: () => [active, pinned] } as Parameters[0]; assert.equal(resolveReviewModel(registry), pinned); const args = buildChildPiPromptArgs("prompt", config); assert.equal(args[args.indexOf("--model") + 1], MEMORY_LLM_MODEL); assert.equal(args[args.indexOf("--thinking") + 1], "off"); }); it("does not use the chat model when the fixed model is missing", () => { const registry = { getAll: () => [active] } as Parameters[0]; assert.equal(resolveReviewModel(registry), undefined); }); it("never retries subprocess model failures without the fixed model", async () => { for (const throws of [false, true]) { let calls = 0; const pi = { exec: async () => { calls++; if (throws) throw new Error("model not found"); return { code: 1, stdout: "", stderr: "model not found" }; } }; const run = execChildPrompt(pi, "prompt", config, { timeoutMs: 30000, }); if (throws) await assert.rejects(run, /model not found/); else assert.equal((await run).code, 1); assert.equal(calls, 1); } }); });