import assert from "node:assert/strict"; import test from "node:test"; import { formatFailure, startCraftos, startFakeOpencode, startSandbox } from "./harness.js"; test("probe_gateway reports opencodeOk=true when opencode is healthy", async () => { const opencode = await startFakeOpencode({ status: 200 }); const sandbox = await startSandbox({ opencodeUrl: opencode.url }); const craftos = startCraftos("gateway-client.lua", { computerId: 7, computerLabel: "health-ok", shellArgs: [sandbox.baseUrl, "-", "health"], }); try { const result = await craftos.done; assert.match( result.output, /__SANDBOX_HEALTH__ sandboxOk=true opencodeOk=true/, formatFailure("expected sandboxOk=true opencodeOk=true", result.output), ); } finally { craftos.abort(); await craftos.done.catch(() => undefined); await sandbox.close(); await opencode.close(); } }); test("probe_gateway reports opencodeOk=false when opencode is unhealthy", async () => { const opencode = await startFakeOpencode({ status: 500 }); const sandbox = await startSandbox({ opencodeUrl: opencode.url }); const craftos = startCraftos("gateway-client.lua", { computerId: 7, computerLabel: "health-bad", shellArgs: [sandbox.baseUrl, "-", "health"], }); try { const result = await craftos.done; assert.match( result.output, /__SANDBOX_HEALTH__ sandboxOk=true opencodeOk=false/, formatFailure("expected sandboxOk=true opencodeOk=false", result.output), ); } finally { craftos.abort(); await craftos.done.catch(() => undefined); await sandbox.close(); await opencode.close(); } });