// A stand-in harness turn for the runner tests. MOSAIC_REQUEST's body // (after the blank line) picks the behaviour: // TOOL call a typed tool through the tool socket, print the result or refusal // SLEEP hang until killed // FAIL exit 3 // NOMARKER answer without writing the turn marker // anything else answer "echo: " // Every turn appends its pid to $FAKE_PIDS when set. import { appendFileSync, writeFileSync } from "node:fs"; import { callTool } from "../../src/tools.mjs"; const request = process.env.MOSAIC_REQUEST ?? ""; const body = request.split("\n\n").slice(1).join("\n\n"); if (process.env.FAKE_PIDS) appendFileSync(process.env.FAKE_PIDS, `${process.pid}\n`); process.stderr.write(`fake adapter: ${process.env.MOSAIC_MODEL}\n`); const done = () => writeFileSync(process.env.MOSAIC_TURN_MARKER, "done\n"); if (body.startsWith("TOOL ")) { const [, name, ...rest] = body.split(" "); try { process.stdout.write(JSON.stringify(await callTool(process.env.MOSAIC_TOOL_SOCKET, name, JSON.parse(rest.join(" ") || "{}")))); } catch (e) { process.stdout.write(e.message); } done(); } else if (body === "SLEEP") { setInterval(() => {}, 1000); } else if (body === "FAIL") { process.exit(3); } else if (body === "NOMARKER") { process.stdout.write("half an answer"); } else { process.stdout.write(`echo: ${request}\n`); done(); }