import assert from "node:assert/strict"; import test from "node:test"; import { formatFailure, startCraftos, startSandbox } from "./harness.js"; const SECRET = "s3cr3t-canary"; test("hello with the wrong secret is rejected in-band (unauthorized)", async () => { const sandbox = await startSandbox({ sandboxPassword: SECRET }); const craftos = startCraftos("gateway-client.lua", { computerId: 7, computerLabel: "auth-bad", shellArgs: [sandbox.baseUrl, "wrong-secret", "auth"], }); try { const result = await craftos.done; assert.match( result.output, /__SANDBOX_HELLO__ ok=false code=unauthorized/, formatFailure("expected hello ok=false code=unauthorized", result.output), ); } finally { craftos.abort(); await craftos.done.catch(() => undefined); await sandbox.close(); } }); test("hello with the correct secret succeeds", async () => { const sandbox = await startSandbox({ sandboxPassword: SECRET }); const craftos = startCraftos("gateway-client.lua", { computerId: 7, computerLabel: "auth-ok", shellArgs: [sandbox.baseUrl, SECRET, "auth"], }); try { const result = await craftos.done; assert.match( result.output, /__SANDBOX_HELLO__ ok=true/, formatFailure("expected hello ok=true", result.output), ); } finally { craftos.abort(); await craftos.done.catch(() => undefined); await sandbox.close(); } });