cc-libs/tools/trap-sandbox/test-integration/reverse-ping.test.ts

29 lines
1.1 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { formatFailure, startCraftos, startSandbox, waitFor } from "./harness.js";
// Exercises the gateway -> computer direction: the gateway sends a `ping`
// gateway_request and the real libsandbox client answers with a computer_response.
test("gateway->computer reverse ping is answered by the client", async () => {
const sandbox = await startSandbox();
const craftos = startCraftos("gateway-client.lua", {
computerId: 7,
computerLabel: "ping",
shellArgs: [sandbox.baseUrl, "-", "idle"],
});
try {
await waitFor(() => sandbox.registry.has("local", "7:ping"), 12_000, "computer registered");
const payload = await sandbox.registry.request("local", "7:ping", "ping");
assert.deepEqual(payload, { traposId: "7:ping" });
} catch (error) {
throw new Error(
formatFailure(error instanceof Error ? error.message : String(error), craftos.snapshot()),
{ cause: error },
);
} finally {
craftos.abort();
await craftos.done.catch(() => undefined);
await sandbox.close();
}
});