import test from "node:test"; import assert from "node:assert/strict"; import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { GENERATION_PRESETS } from "../lib/generationSettings"; // `archilyzer gen` (release 27 S9). settings.json and the ledger are pinned to // a temp dir BEFORE anything reads getPaths() (it caches), so the offline // store writes there and nowhere else. const ROOT = mkdtempSync(path.join(os.tmpdir(), "gen-cli-")); Object.assign(process.env, { TRANSCRIPTS_DIR: path.join(ROOT, "transcripts"), SETTINGS_FILE: path.join(ROOT, "settings.json"), GENERATION_USAGE_FILE: path.join(ROOT, "usage.jsonl"), }); writeFileSync(path.join(ROOT, "settings.json"), JSON.stringify({ minFreeDiskGB: 0 })); test.after(() => rmSync(ROOT, { recursive: true, force: true })); const gen = await import("./gen"); type GenStore = import("./gen").GenStore; type GenPolicy = import("./gen").GenPolicy; function capture() { const lines: string[] = []; const errors: string[] = []; return { lines, errors, out: { log: (s: string) => lines.push(s), error: (s: string) => errors.push(s) } }; } const BALANCED: GenPolicy = { preset: "balanced", routes: { sweep: "code", "revise-report": "api", "revise-video": "local", narrate: "local", research: "api" }, models: { api: "claude-sonnet-5-5", local: "qwen3:8b", extractor: "claude-haiku-4-5" }, caps: { sweep: 5, revision: 2, narration: 1, daily: 20, max: 10 }, localSweep: { claimForm: "neutral", readAloud: "flag" }, }; // A store in memory, recording what it was asked to write. function memoryStore(policy: GenPolicy = BALANCED, offline = false) { const written: Record[] = []; const localSweeps: NonNullable[] = []; let p = structuredClone(policy); const store: GenStore = { where: offline ? "settings.json (test)" : "the editor at http://editor.test", offline, read: async () => p, usage: async () => ({ day: "2026-10-13", usd: 1.5, jobs: 2, daily: 20 }), writeRoutes: async (routes) => { written.push(routes); p = { ...p, routes, preset: "custom" }; return p; }, writeLocalSweep: async (ls) => { localSweeps.push(ls); p = { ...p, localSweep: ls }; return p; }, }; return { store, written, localSweeps }; } test("gen policy prints the routes, models, caps and today's spend", async () => { const c = capture(); const { store } = memoryStore(); assert.equal(await gen.policyMain({ json: false }, { store: async () => store, runOps: async () => 0, out: c.out }), 0); assert.equal(c.lines[0], "preset balanced · api model claude-sonnet-5-5 · local model qwen3:8b · extractor claude-haiku-4-5"); assert.ok(c.lines.includes(" sweep → code")); assert.ok(c.lines.includes(" revise-report → api")); assert.ok(c.lines.includes("caps: sweep $5.00 · revision $2.00 · narration $1.00 · max $10.00 · daily $20.00")); assert.ok(c.lines.includes("today 2026-10-13 (UTC): $1.50 on the Claude API in 2 job(s)")); const j = capture(); await gen.policyMain({ json: true }, { store: async () => store, runOps: async () => 0, out: j.out }); assert.equal(JSON.parse(j.lines[0]).routes.narrate, "local"); const refused = capture(); assert.equal(await gen.policyMain({ json: false }, { store: async () => ({ error: "the editor refused" }), runOps: async () => 0, out: refused.out }), 1); assert.match(refused.errors[0], /^gen policy: the editor refused/); }); test("gen preset writes the preset's routes; gen set writes one; nonsense is a usage error", async () => { const c = capture(); const m = memoryStore(); const deps = { store: async () => m.store, runOps: async () => 0, out: c.out }; assert.equal(await gen.setMain({ preset: "local" }, deps), 0); // Every task, the media drafts (release 28) included. assert.deepEqual(m.written[0], { ...GENERATION_PRESETS.local }); assert.equal(await gen.setMain({ task: "sweep", route: "api" }, deps), 0); assert.deepEqual(m.written[1], { ...GENERATION_PRESETS.local, sweep: "api" }); assert.ok(c.lines.includes("(written to the editor at http://editor.test)")); for (const o of [{ preset: "cheap" }, { task: "sweep", route: "cloud" }, { task: "sweep" }, { task: "nope", route: "api" }]) { assert.equal(await gen.setMain(o, deps), 2, JSON.stringify(o)); } assert.equal(m.written.length, 2); }); test("gen local-sweep shows the claim form and the read-aloud rule, writes one or both, and refuses a value it does not know", async () => { const c = capture(); const m = memoryStore(); const deps = { store: async () => m.store, runOps: async () => 0, out: c.out }; assert.equal(await gen.localSweepMain({}, deps), 0); assert.match(c.lines[0]!, /^local sweep: claim form neutral \(code writes each line/); assert.match(c.lines[1]!, /a quote that may be read aloud: flag \(kept, marked to check by ear\)/); assert.equal(m.localSweeps.length, 0, "a bare call writes nothing"); assert.equal(await gen.localSweepMain({ readAloud: "drop" }, deps), 0); assert.deepEqual(m.localSweeps[0], { claimForm: "neutral", readAloud: "drop" }); assert.equal(await gen.localSweepMain({ form: "sentence", readAloud: "off" }, deps), 0); assert.deepEqual(m.localSweeps[1], { claimForm: "sentence", readAloud: "off" }); assert.ok(c.lines.includes("(written to the editor at http://editor.test)")); for (const o of [{ form: "poem" }, { readAloud: "maybe" }]) assert.equal(await gen.localSweepMain(o, deps), 2, JSON.stringify(o)); assert.equal(m.localSweeps.length, 2); // The policy shows it too. const p = capture(); await gen.policyMain({ json: false }, { ...deps, out: p.out }); assert.ok(p.lines.some((l) => l.startsWith("local sweep: claim form sentence"))); }); test("gen run exits 3 and runs nothing when the task is routed to code", async () => { const c = capture(); const ran: string[][] = []; const deps = { store: async () => memoryStore().store, runOps: async (a: string[]) => (ran.push(a), 0), out: c.out }; const code = await gen.runMain({ task: "sweep", text: "What about the shop?", flags: { article: "synth-a", channels: "synth-kitchen" } }, deps); assert.equal(code, 3); assert.equal(ran.length, 0); assert.match(c.lines[0], /sweep is routed to Claude Code \(preset balanced\)/); assert.equal(await gen.runMain({ task: "revise-report", text: "Shorter.", flags: { article: "synth-a", iteration: "2", via: "code" } }, deps), 3); assert.equal(ran.length, 0); }); test("gen run enqueues through pnpm ops report-draft on the route's model; --via overrides; --wait follows", async () => { const c = capture(); const ran: string[][] = []; const deps = { store: async () => memoryStore().store, runOps: async (a: string[]) => (ran.push(a), 0), out: c.out }; assert.equal( await gen.runMain( { task: "sweep", text: "What about the shop?", flags: { article: "synth-a", channels: "synth-kitchen, synth-other", via: "api", "max-usd": "3", from: "2026-01-01", wait: true } }, deps, ), 0, ); assert.equal(ran[0][0], "report-draft"); assert.deepEqual(JSON.parse(ran[0][2]), { task: "sweep", article: "synth-a", question: "What about the shop?", channels: ["synth-kitchen", "synth-other"], from: "2026-01-01", maxUsd: 3, model: "claude-sonnet-5-5", }); assert.equal(ran[0][3], "--wait"); assert.equal(await gen.runMain({ task: "revise-video", text: "Shorter.", flags: { article: "synth-a", iteration: "2" } }, deps), 0); assert.deepEqual(JSON.parse(ran[1][2]), { task: "revise-video", article: "synth-a", iteration: 2, feedback: "Shorter.", model: "qwen3:8b" }); assert.equal(ran[1].length, 3); // --model names it outright: the policy is not asked. let asked = 0; const named = { ...deps, store: async () => (asked++, memoryStore().store) }; assert.equal(await gen.runMain({ task: "sweep", text: "q", flags: { article: "synth-a", channels: "x", model: "qwen3:8b" } }, named), 0); assert.equal(asked, 0); // Usage errors before anything is asked. for (const flags of []>[{}, { article: "a", iteration: "zero" }, { article: "a", "max-usd": "-1" }, { article: "a", via: "cloud" }, { article: "a", via: "api", model: "m" }]) { assert.equal(await gen.runMain({ task: "sweep", text: "q", flags }, named), 2, JSON.stringify(flags)); } assert.equal(asked, 0); // Offline: the route is known, but no editor runs the job. const offline = { ...deps, store: async () => memoryStore(BALANCED, true).store }; assert.equal(await gen.runMain({ task: "narrate", flags: { article: "a", iteration: "1" } }, offline), 1); assert.match(c.errors.at(-1)!, /no editor answers — generation runs in the editor/); }); test("the editor store: through the ops API with the token; refused → error; nothing listening → offline", async () => { const env = { WORKER_TOKEN: "tok", ARCHILYZER_EDITOR_URL: "http://editor.test/" }; const sent: { url: string; method: string; auth?: string; body?: unknown }[] = []; let policy: Record = { ...BALANCED }; const fetchImpl = (async (url: string, init: RequestInit) => { const headers = init.headers as Record; sent.push({ url, method: init.method ?? "GET", auth: headers.authorization, body: init.body ? JSON.parse(String(init.body)) : undefined }); const u = new URL(url); const json = (status: number, body: unknown) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } }); if (u.pathname === "/api/ops/settings" && init.method === "POST") { policy = { ...policy, routes: (sent.at(-1)!.body as { patch: { generation: { routes: unknown } } }).patch.generation.routes, preset: "api" }; return json(200, { ok: true, changed: ["generation"], value: { generation: policy } }); } if (u.pathname === "/api/ops/settings") return json(200, { ok: true, key: "generation", value: policy }); if (u.pathname === "/api/ops/generation-usage") return json(200, { ok: true, day: "2026-10-13", usd: 0.5, jobs: 1, daily: 20 }); return json(404, { ok: false, error: "no" }); }) as unknown as typeof fetch; const store = (await gen.editorStore({ ...env }, fetchImpl)) as GenStore; assert.equal(store.offline, false); assert.equal((await store.read()).preset, "balanced"); assert.deepEqual(await store.usage(), { day: "2026-10-13", usd: 0.5, jobs: 1, daily: 20 }); const saved = await store.writeRoutes({ sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api" }); assert.equal(saved.preset, "api"); assert.ok(sent.every((s) => s.auth === "Bearer tok" && s.url.startsWith("http://editor.test/api/ops/"))); assert.deepEqual(sent.find((s) => s.method === "POST")!.body, { patch: { generation: { routes: { sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api" } } }, }); const refusing = (async () => new Response(JSON.stringify({ ok: false, error: "unauthorized" }), { status: 401 })) as unknown as typeof fetch; const r = (await gen.editorStore({ ...env }, refusing)) as { error: string }; assert.match(r.error, /refused \(HTTP 401\): unauthorized \(hint: /); const refused = (async () => { throw Object.assign(new TypeError("fetch failed"), { cause: { code: "ECONNREFUSED" } }); }) as unknown as typeof fetch; assert.equal(await gen.editorStore({ ...env }, refused), null); const silent = (async () => { throw Object.assign(new Error("The operation was aborted due to timeout"), { name: "TimeoutError" }); }) as unknown as typeof fetch; const s = (await gen.editorStore({ ...env }, silent)) as { error: string }; assert.match(s.error, /did not answer \(no answer within 15 s\) — not writing settings\.json beside a running editor/); }); test("the offline store reads and writes settings.json through the settings writer", async () => { const store = await gen.offlineStore(); assert.equal(store.offline, true); const before = await store.read(); assert.equal(before.preset, "balanced"); const after = await store.writeRoutes({ ...before.routes, sweep: "local" }); assert.equal(after.routes.sweep, "local"); assert.equal(after.preset, "custom"); const file = JSON.parse(readFileSync(path.join(ROOT, "settings.json"), "utf8")); assert.equal(file.generation.routes.sweep, "local"); assert.equal(file.minFreeDiskGB, 0); assert.deepEqual(await store.usage(), { day: new Date().toISOString().slice(0, 10), usd: 0, jobs: 0, daily: 20 }); // A preset chosen offline is its routes, and reads back as the preset. const c = capture(); assert.equal(await gen.setMain({ preset: "api" }, { store: async () => store, runOps: async () => 0, out: c.out }), 0); assert.equal((await store.read()).preset, "api"); // The local sweep's two knobs: the defaults, then written through the same writer. assert.deepEqual((await store.read()).localSweep, { claimForm: "neutral", readAloud: "flag" }); assert.equal(await gen.localSweepMain({ form: "sentence", readAloud: "drop" }, { store: async () => store, runOps: async () => 0, out: c.out }), 0); assert.deepEqual(JSON.parse(readFileSync(path.join(ROOT, "settings.json"), "utf8")).generation.localSweep, { claimForm: "sentence", readAloud: "drop" }); }); test("gen run research takes --autonomy; nothing else does", async () => { assert.deepEqual(gen.runBody("research", "what is missing?", { article: "synth-a", channels: "synth-kitchen", autonomy: "limits" }), { task: "research", article: "synth-a", question: "what is missing?", channels: ["synth-kitchen"], autonomy: "limits", }); assert.deepEqual(gen.runBody("sweep", undefined, { article: "synth-a", autonomy: "auto" }), { error: "gen run: --autonomy is a research run's" }); // A continuation: a sweep naming the research run. assert.deepEqual(gen.runBody("sweep", undefined, { article: "synth-a", iteration: "4", force: true }), { task: "sweep", article: "synth-a", iteration: 4, force: true }); }); test("gen run a media draft: a step on --iteration, no words, --entries and --force (release 28)", () => { assert.deepEqual(gen.runBody("onscreen", undefined, { article: "synth-a", iteration: "2", entries: "c01, c02", force: true }), { task: "onscreen", article: "synth-a", iteration: 2, entries: ["c01", "c02"], force: true, }); assert.deepEqual(gen.runBody("youtube", undefined, { article: "synth-a", iteration: "2", model: "qwen3:8b" }), { task: "youtube", article: "synth-a", iteration: 2, model: "qwen3:8b" }); assert.deepEqual(gen.runBody("cut", undefined, { article: "synth-a" }), { error: "gen run: a cut draft names its iteration (--iteration )" }); assert.deepEqual(gen.runBody("teaser", "make it punchier", { article: "synth-a", iteration: "2" }), { error: "gen run: a teaser draft takes no question or feedback: it drafts from the iteration's report and cut", }); assert.deepEqual(gen.runBody("flips", undefined, { article: "synth-a", iteration: "2", "copy-of": "1" }), { error: "gen run: a flips draft is a step on its iteration: no --copy-of" }); assert.deepEqual(gen.runBody("sweep", "q", { article: "synth-a", entries: "c01" }), { error: "gen run: --entries is a media draft's" }); }); // ─── demo epic D5: gen model, gen local-check, the local-only refusal ─── const ALL_LOCAL: GenPolicy = { preset: "local", routes: { sweep: "local", "revise-report": "local", "revise-video": "local", narrate: "local", research: "local" }, models: { api: "claude-sonnet-5-5", local: "qwen2.5:7b", extractor: "qwen2.5:7b" }, }; function modelStore(policy: GenPolicy) { const { store } = memoryStore(policy); const writes: GenPolicy["models"][] = []; let p = structuredClone(policy); store.read = async () => p; store.writeModels = async (models) => { writes.push(models); p = { ...p, models }; return p; }; return { store, writes }; } test("gen model: shows the three; writes one slot keeping the others; an unchanged one is not written", async () => { const { store, writes } = modelStore(BALANCED); const c = capture(); assert.equal(await gen.modelMain({}, { store: async () => store, runOps: async () => 0, out: c.out }), 0); assert.match(c.lines[0]!, /^api claude-sonnet-5-5 · local qwen3:8b · extractor claude-haiku-4-5 {2}\(from the editor/); assert.equal(await gen.modelMain({ slot: "local", name: "qwen2.5:7b" }, { store: async () => store, runOps: async () => 0, out: c.out }), 0); assert.deepEqual(writes, [{ api: "claude-sonnet-5-5", local: "qwen2.5:7b", extractor: "claude-haiku-4-5" }]); assert.equal(await gen.modelMain({ slot: "local", name: "qwen2.5:7b" }, { store: async () => store, runOps: async () => 0, out: c.out }), 0); assert.equal(writes.length, 1, "already so: nothing written"); const e = capture(); assert.equal(await gen.modelMain({ slot: "vision", name: "x" }, { store: async () => store, runOps: async () => 0, out: e.out }), 2); assert.equal(await gen.modelMain({ slot: "local", name: "bad name!" }, { store: async () => store, runOps: async () => 0, out: e.out }), 2); assert.equal(await gen.modelMain({ slot: "local" }, { store: async () => store, runOps: async () => 0, out: e.out }), 2); }); test("gen model on a local-only instance: a Claude or cloud model refused for local and extractor", async () => { const { store, writes } = modelStore(ALL_LOCAL); const env = { ARCHILYZER_LOCAL_ONLY: "1" }; const c = capture(); assert.equal(await gen.modelMain({ slot: "extractor", name: "claude-haiku-4-5" }, { store: async () => store, runOps: async () => 0, out: c.out, env }), 1); assert.equal(await gen.modelMain({ slot: "local", name: "gpt-oss:120b-cloud" }, { store: async () => store, runOps: async () => 0, out: c.out, env }), 1); assert.match(c.errors.join("\n"), /local only \(ARCHILYZER_LOCAL_ONLY=1\): "claude-haiku-4-5" is not a local model/); assert.equal(writes.length, 0); }); test("gen preset/set on a local-only instance: a route other than local refused before any write", async () => { const { store, written } = memoryStore(ALL_LOCAL, true); const c = capture(); const deps = { store: async () => store, runOps: async () => 0, out: c.out, env: { ARCHILYZER_LOCAL_ONLY: "1" } }; assert.equal(await gen.setMain({ preset: "balanced" }, deps), 1); assert.equal(await gen.setMain({ task: "sweep", route: "code" }, deps), 1); assert.match(c.errors.join("\n"), /every generation route stays local — not saved: sweep → code/); assert.equal(written.length, 0); assert.equal(await gen.setMain({ preset: "local" }, deps), 0); assert.equal(written.length, 1); }); const row = (r: Partial) => ({ at: "2026-11-13T10:00:00Z", day: "2026-11-13", jobId: "j1", article: "a", iteration: 1, task: "sweep", model: "qwen2.5:7b", inputTokens: 10, outputTokens: 5, cacheReadTokens: 0, cacheWriteTokens: 0, usd: 0, route: "local" as const, calls: 12, ...r, }); const ON = { on: true, raw: "1", understood: true }; const base = (o: Partial[0]> = {}) => gen.localChecks({ policy: ALL_LOCAL, flagHere: ON, guardEditor: true, apiKey: null, endpoints: [{ what: "the local route (OLLAMA_URL)", url: "http://127.0.0.1:11434" }], rows: [], calls: [], imported: [], since: null, env: {}, ...o, }); const call = (route: string, at = "2026-11-13T10:00:00Z", model = "qwen2.5:7b") => ({ route, at, model }); test("gen local-check: PASS only with recorded calls, all local; each failing check named; --since narrows", () => { const pass = base({ rows: [row({}), row({ jobId: "j2", calls: 3 })], calls: [call("local"), call("local")] }); assert.equal(pass.verdict, "pass"); assert.deepEqual(pass.local, [{ model: "qwen2.5:7b", calls: 15, jobs: 2 }]); assert.deepEqual(pass.checks.map((c) => [c.name, c.status]), [["guard", "ok"], ["routes", "ok"], ["endpoints", "ok"], ["api key", "ok"], ["ledger", "ok"], ["model log", "ok"], ["imports", "ok"]]); assert.match(pass.checks[4]!.line, /all of it: 0 Claude API rows; local: qwen2\.5:7b 15 call\(s\) in 2 job\(s\)/); assert.match(pass.checks[5]!.line, /2 call\(s\), every one on the local route/); assert.match(pass.checks[2]!.line, /^the local route \(OLLAMA_URL\) → 127\.0\.0\.1$/); const apiRow = row({ day: "2026-11-01", model: "claude-sonnet-5-5", route: "api", usd: 0.4, jobId: "old" }); const fail = base({ policy: BALANCED, flagHere: { on: false, raw: "", understood: true }, guardEditor: false, apiKey: "file", endpoints: [{ what: "the local route (generation.ollamaUrl)", url: "https://ollama-proxy.cloud.example" }, { what: "LLM worker w1", url: "http://gpu-box.lan:11434" }], rows: [apiRow, row({})], calls: [call("api", "2026-11-01T00:00:00Z", "claude-sonnet-5-5"), call("local")], imported: [{ article: "a", n: 2, at: "2026-11-02T00:00:00Z", from: "claude-code" }], }); assert.equal(fail.verdict, "fail"); assert.equal(fail.ok, false); assert.deepEqual(fail.checks.map((c) => c.status), ["fail", "fail", "fail", "fail", "fail", "fail", "fail"]); assert.match(fail.checks[1]!.line, /3 of 5 not local: sweep → code, revise-report → api, research → api/); assert.match(fail.checks[2]!.line, /ollama-proxy\.cloud\.example \(NOT this machine\); LLM worker w1 → gpu-box\.lan \(NOT this machine\)/); assert.match(fail.checks[3]!.line, /the key file exists/); assert.match(fail.checks[4]!.line, /1 Claude API row\(s\) \(claude-sonnet-5-5\)/); assert.match(fail.checks[5]!.line, /2 call\(s\), 1 NOT local \(api claude-sonnet-5-5\)/); assert.match(fail.checks[6]!.line, /1 iteration\(s\) made elsewhere and imported: a i2 \(from claude-code\)/); // Before --since, the API rows, the call and the import do not count. const since = base({ guardEditor: null, rows: [apiRow, row({})], calls: [call("api", "2026-11-01T00:00:00Z"), call("local")], imported: [{ article: "a", n: 2, at: "2026-11-02T00:00:00Z", from: "x" }], since: "2026-11-13" }); assert.equal(since.verdict, "pass"); assert.match(since.checks[0]!.line, /this process; no editor answered/); // ARCHILYZER_LOCAL_MODEL_HOSTS names the compose service. const compose = base({ endpoints: [{ what: "w", url: "http://ollama:11434" }], env: { ARCHILYZER_LOCAL_MODEL_HOSTS: "ollama" } }); assert.equal(compose.checks[2]!.status, "ok"); assert.equal(base({ endpoints: [{ what: "w", url: "http://ollama:11434" }] }).checks[2]!.status, "fail"); }); test("gen local-check: an empty ledger and log is 'nothing to prove yet' (exit 0), never a pass; a flag not understood is named (S6, S7)", () => { const empty = base(); assert.equal(empty.verdict, "nothing-yet"); assert.equal(empty.ok, true); assert.deepEqual(empty.checks.filter((c) => c.status === "none").map((c) => [c.name, c.line]), [["ledger", "all of it: no calls recorded"], ["model log", "all of it: no calls recorded"]]); const typo = base({ flagHere: { on: false, raw: "enabled", understood: false }, guardEditor: null }); assert.equal(typo.checks[0]!.status, "fail"); assert.match(typo.checks[0]!.line, /ARCHILYZER_LOCAL_ONLY="enabled" is not understood here, so the guard is OFF/); }); test("gen local-check --since: a real calendar date, not in the future", () => { assert.equal(gen.sinceProblem("2026-11-13", "2026-11-13"), null); assert.match(gen.sinceProblem("2026-02-30", "2026-11-13")!, /not a calendar date/); assert.match(gen.sinceProblem("2099-01-01", "2026-11-13")!, /is after today \(2026-11-13, UTC\)/); assert.match(gen.sinceProblem("13 Nov", "2026-11-13")!, /YYYY-MM-DD/); }); test("gen local-check: the command's lines and exit; never a key, a key path or a home path", async () => { const { store } = memoryStore(ALL_LOCAL); store.editorLocalOnly = async () => true; store.where = `settings.json (${os.homedir()}/x/settings.json; no editor answering)`; const evidence = async () => ({ endpoints: [{ what: "the local route (OLLAMA_URL)", url: "http://ollama:11434" }], rows: [row({})], calls: [call("local")], imported: [] }); const c = capture(); const code = await gen.localCheckMain({ json: false }, { store: async () => store, runOps: async () => 0, out: c.out, env: { ARCHILYZER_LOCAL_MODEL_HOSTS: "ollama" }, evidence, apiKeyAtHand: async () => null }); assert.equal(code, 0, c.lines.join("\n")); assert.equal(c.lines[0], "local-check: PASS — the setup is local only, and every recorded call was local"); assert.ok(c.lines.some((l) => /^ {2}ok {3}guard {5}ARCHILYZER_LOCAL_ONLY is on \(the editor says so\)$/.test(l)), c.lines.join("\n")); assert.ok(c.lines.some((l) => /endpoints .*→ ollama$/.test(l)), c.lines.join("\n")); assert.equal(c.lines.at(-1), "(from settings.json (~/x/settings.json; no editor answering))"); assert.ok(!c.lines.join("\n").includes(os.homedir() + "/"), "no absolute home path"); const n = capture(); assert.equal(await gen.localCheckMain({ json: false }, { store: async () => store, runOps: async () => 0, out: n.out, env: {}, evidence: async () => ({ endpoints: [], rows: [], calls: [], imported: [] }), apiKeyAtHand: async () => null }), 0); assert.match(n.lines[0]!, /^local-check: NOTHING TO PROVE YET/); const j = capture(); assert.equal( await gen.localCheckMain({ json: true, since: "2026-11-01" }, { store: async () => store, runOps: async () => 0, out: j.out, env: {}, evidence: async () => ({ endpoints: [], rows: [], calls: [], imported: [] }), apiKeyAtHand: async () => "env" }), 1, ); const body = JSON.parse(j.lines[0]!); assert.equal(body.ok, false); assert.equal(body.verdict, "fail"); assert.ok(!/anthropic\.env|sk-|ANTHROPIC_API_KEY=/.test(j.lines[0]!), "no key file path or key"); const bad = capture(); assert.equal(await gen.localCheckMain({ json: false, since: "2099-01-01" }, { store: async () => store, runOps: async () => 0, out: bad.out }), 2); });