import assert from "node:assert/strict"; import path from "node:path"; import test from "node:test"; import { AcpWorker } from "../src/acp/worker.js"; import { parseConfig } from "../src/config.js"; import { BotProfileResolver } from "../src/roles/role-registry.js"; const fixture = path.resolve("test/fixtures/fake-acp-agent.mjs"); function makeWorker(promptTimeoutMs = 80) { const config = parseConfig({ configVersion: 3, bot: { id: "test-bot", workspace: path.resolve("."), persona: "", agent: { id: "fake", command: process.execPath, args: [fixture] }, permissions: { mode: "deny" } }, gateway: { platform: { type: "webhook", secret: "secret" } }, runtime: { acp: { promptTimeoutMs, cancelGraceMs: 30 } } }); let crashes = 0; const worker = new AcpWorker(new BotProfileResolver(config).bot, config.runtime.acp, () => { crashes++; }); return { worker, crashes: () => crashes }; } test("worker times out a hung prompt and can be terminated", async () => { const { worker } = makeWorker(); await worker.start(); await assert.rejects(worker.prompt("hang"), /timed out/); await worker.terminate(); }); test("worker reports an unexpected ACP subprocess exit", async () => { const current = makeWorker(500); await current.worker.start(); await assert.rejects(current.worker.prompt("crash")); await new Promise((resolve) => setTimeout(resolve, 20)); assert.equal(current.crashes(), 1); });