import assert from "node:assert/strict"; import { randomUUID } from "node:crypto"; import { SubstrateClient } from "../src/client.js"; const endpoint = process.env.SUBSTRATE_GUEST_ENDPOINT; if (!endpoint) throw new Error("Set SUBSTRATE_GUEST_ENDPOINT to an isolated, real ate-env-guest endpoint. This smoke executes remote shell commands and writes disposable files."); const client = new SubstrateClient({ endpoint, atespace: "ate-env", timeoutMs: 10_000, maxBytes: 4096 }); const id = "guest-smoke"; // The standalone upstream guest ignores routing metadata. const name = `substrate-smoke-${randomUUID()}`; const receipt: Record = { scenario: "upstream-guest-gRPC", upstream: "ab40c7bfb2049af1a7aade9e7bf9c6cac925b5ca", suspensionVerified: false }; try { const bytes = Buffer.from("hello remote λ漢\n"); assert.equal(await client.write(id, name, bytes), bytes.length); assert.deepEqual(await client.read(id, name), bytes); await client.write(id, name, Buffer.alloc(0)); assert.equal((await client.read(id, name)).length, 0); receipt.fileRoundTripAndEmptyOverwrite = true; const proc = await client.start(id, { command: ["sh", "-c", "printf 'remote-output'; printf 'remote-error' >&2; exit 7"] }); const output = await client.outputs(id, proc, { follow: true }); assert.equal(output.stdout, "remote-output"); assert.equal(output.stderr, "remote-error"); assert.equal((await client.process(id, proc)).exitCode, 7); receipt.processOutputAndExit = true; const paged = await client.outputs(id, proc, { stdoutOffset: 7, stderrOffset: 7 }); assert.equal(paged.stdout, "output"); assert.equal(paged.stderr, "error"); receipt.outputOffsets = true; const long = await client.start(id, { command: ["sh", "-c", "sleep 60"] }); const abort = new AbortController(); const stream = client.outputs(id, long, { follow: true }, { signal: abort.signal }); abort.abort(); await assert.rejects(stream); await client.kill(id, long); assert.notEqual((await client.process(id, long)).status, "PROCESS_STATUS_RUNNING"); receipt.cancelAndRemoteTermination = true; const oversized = await client.start(id, { command: ["sh", "-c", "yes x | head -c 8192"] }); const limited = await client.outputs(id, oversized, { follow: true }); assert.equal(limited.truncated, true); assert.ok(Buffer.byteLength(limited.stdout) <= 4096); receipt.boundedOutput = true; await assert.rejects(client.write(id, name, Buffer.alloc(4097)), /limit|bytes|exceed/i); receipt.boundedWrite = true; const cleanup = await client.start(id, { command: ["rm", "--", name] }); await client.outputs(id, cleanup, { follow: true }); console.log(JSON.stringify(receipt, null, 2)); } finally { client.close(); }