Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodeChildProcess from "node:child_process";
3import * as NodeFS from "node:fs";
4import * as NodeOS from "node:os";
5import * as NodePath from "node:path";
6import * as NodeURL from "node:url";
7
8import { expect, it } from "vite-plus/test";
9
10import { acpReplayAgentArgs } from "../src/orchestration-v2/Adapters/AcpAdapterV2.testkit.ts";
11
12const replayAgentPath = NodeURL.fileURLToPath(new URL("./acp-replay-agent.ts", import.meta.url));
13
14async function runRuntimeExit(status: "success" | "error" | "cancelled") {
15 const scratch = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-acp-replay-agent-"));
16 const statusPath = NodePath.join(scratch, "status.json");
17 const transcript = {
18 scenario: `${status}-runtime-exit`,
19 entries: [{ type: "runtime_exit", status }],
20 };
21 const args = acpReplayAgentArgs(replayAgentPath);
22 const child = NodeChildProcess.spawn(process.execPath, args, {
23 env: {
24 ...process.env,
25 T3_ACP_REPLAY_STATUS_PATH: statusPath,
26 T3_ACP_REPLAY_TRANSCRIPT: Buffer.from(JSON.stringify(transcript), "utf8").toString("base64"),
27 T3_ACP_REPLAY_WORKSPACE: scratch,
28 },
29 stdio: ["pipe", "pipe", "pipe"],
30 });
31 let stderr = "";
32 child.stderr.setEncoding("utf8");
33 child.stderr.on("data", (chunk: string) => {
34 stderr += chunk;
35 });
36 child.stdin.end();
37
38 try {
39 const code = await new Promise<number | null>((resolve, reject) => {
40 child.once("error", reject);
41 child.once("exit", resolve);
42 });
43 return {
44 code,
45 status: JSON.parse(NodeFS.readFileSync(statusPath, "utf8")) as unknown,
46 stderr,
47 transcript,
48 args,
49 };
50 } finally {
51 NodeFS.rmSync(scratch, { recursive: true, force: true });
52 }
53}
54
55it("accepts a recorded cancelled runtime exit", async () => {
56 const result = await runRuntimeExit("cancelled");
57 expect(result.code, result.stderr).toBe(0);
58 expect(result.args).toEqual(["--experimental-strip-types", replayAgentPath]);
59 expect(result.status).toEqual({
60 scenario: result.transcript.scenario,
61 cursor: 1,
62 total: 1,
63 });
64});
65
66it("still rejects a recorded error runtime exit", async () => {
67 const result = await runRuntimeExit("error");
68 expect(result.code).toBe(1);
69 expect(result.status).toMatchObject({
70 scenario: result.transcript.scenario,
71 cursor: 0,
72 total: 1,
73 failure: {
74 detail: "Recorded runtime exit was error",
75 cursor: 0,
76 },
77 });
78});