@@ -92,6 +92,44 @@ process.stdout.write(JSON.stringify({ protocolVersion: "0.1", type: "completed",
9292 assert . deepEqual ( events . map ( ( event ) => event . type ) , [ "started" , "artifact" , "completed" ] ) ;
9393} ) ;
9494
95+ test ( "DevAgentAdapter waits for close before reading result" , async ( ) => {
96+ const { root, artifactDir, workspacePath } = await createWorkspace ( ) ;
97+ const stubPath = join ( root , "devagent-close-stub.js" ) ;
98+ await createStub ( stubPath , `#!/usr/bin/env node
99+ const fs = require("fs");
100+ const path = require("path");
101+ const args = process.argv.slice(2);
102+ const requestPath = args[args.indexOf("--request") + 1];
103+ const artifactDir = args[args.indexOf("--artifact-dir") + 1];
104+ const request = JSON.parse(fs.readFileSync(requestPath, "utf8"));
105+ const artifactPath = path.join(artifactDir, "triage-report.md");
106+ const resultPath = path.join(artifactDir, "result.json");
107+ process.on("beforeExit", () => {
108+ fs.writeFileSync(artifactPath, "# Triage\\n\\nLate output\\n");
109+ fs.writeFileSync(resultPath, JSON.stringify({
110+ protocolVersion: "0.1",
111+ taskId: request.taskId,
112+ status: "success",
113+ artifacts: [{ kind: "triage-report", path: artifactPath, createdAt: new Date().toISOString() }],
114+ metrics: { startedAt: new Date().toISOString(), finishedAt: new Date().toISOString(), durationMs: 1 }
115+ }, null, 2));
116+ process.stdout.write(JSON.stringify({ protocolVersion: "0.1", type: "started", at: new Date().toISOString(), taskId: request.taskId }) + "\\n");
117+ process.stdout.write(JSON.stringify({ protocolVersion: "0.1", type: "artifact", at: new Date().toISOString(), taskId: request.taskId, artifact: { kind: "triage-report", path: artifactPath, createdAt: new Date().toISOString() } }) + "\\n");
118+ process.stdout.write(JSON.stringify({ protocolVersion: "0.1", type: "completed", at: new Date().toISOString(), taskId: request.taskId, status: "success" }) + "\\n");
119+ });
120+ ` ) ;
121+
122+ const { events, result } = await collectEvents (
123+ new DevAgentAdapter ( `${ process . execPath } ${ stubPath } ` ) ,
124+ createRequest ( "devagent" ) ,
125+ workspacePath ,
126+ artifactDir ,
127+ ) ;
128+
129+ assert . equal ( result . status , "success" ) ;
130+ assert . deepEqual ( events . map ( ( event ) => event . type ) , [ "started" , "artifact" , "completed" ] ) ;
131+ } ) ;
132+
95133test ( "DevAgentAdapter reports cancelled runs as cancelled" , async ( ) => {
96134 const { root, artifactDir, workspacePath } = await createWorkspace ( ) ;
97135 const stubPath = join ( root , "devagent-cancel-stub.js" ) ;
0 commit comments