@@ -292,6 +292,66 @@ describe("empty output outcome", () => {
292292 expect ( outcome . details ) . toContain ( "Failure classification: driver_crash" ) ;
293293 expect ( outcome . details ) . not . toContain ( "engine_outage" ) ;
294294 expect ( outcome . details ) . toContain ( "Last engine error type: unknown" ) ;
295+ expect ( outcome . details ) . toContain ( "Last driver stderr summary: not recorded (diagnostic log unavailable)" ) ;
296+ } ) ;
297+
298+ it ( "reports no output only when the diagnostic log was successfully read and empty" , ( ) => {
299+ fs . writeFileSync ( path . join ( rootDir , "agent_execution_exit_code.txt" ) , "1" ) ;
300+ fs . writeFileSync ( path . join ( rootDir , "agent-stdio.log" ) , "" ) ;
301+ expect ( buildEmptyOutputOutcome ( [ ] , rootDir ) . details ) . toContain ( "Last driver stderr summary: no output captured" ) ;
302+
303+ vi . stubEnv ( "GH_AW_PROTECTED_SESSION_CAPTURE" , "1" ) ;
304+ const session = {
305+ events : [ { type : "agent.execution" , provenance : { component : "execution" , phase : "agent" } , data : { categories : [ ] , errorTypes : [ ] , errorCodes : [ ] , exitCode : 1 } } ] ,
306+ maskedValues : [ ] ,
307+ } ;
308+ expect ( buildEmptyOutputOutcome ( [ ] , rootDir , session ) . details ) . toContain ( "Last driver stderr summary: not recorded (diagnostic log unavailable)" ) ;
309+ } ) ;
310+
311+ it . each ( [
312+ [ 1 , "General failure" ] ,
313+ [ 126 , "Command is not executable" ] ,
314+ [ 127 , "Command not found" ] ,
315+ [ 137 , "Terminated by SIGKILL" ] ,
316+ [ 139 , "Terminated by SIGSEGV" ] ,
317+ [ 173 , "Unknown (engine-specific exit code)" ] ,
318+ ] ) ( "explains driver exit %s without guessing an underlying cause" , ( exitCode , meaning ) => {
319+ fs . writeFileSync ( path . join ( rootDir , "agent_execution_exit_code.txt" ) , String ( exitCode ) ) ;
320+ expect ( buildEmptyOutputOutcome ( [ ] , rootDir ) . details ) . toContain ( `Driver exit meaning: ${ meaning } ` ) ;
321+ } ) ;
322+
323+ it . each ( [
324+ [ "copilot" , "" , "dependency_loading" , "Driver dependency loading failed" ] ,
325+ [ "claude" , "2026-10-25T12:00:00.000Z " , "runtime_exception" , "Driver execution failed" ] ,
326+ [ "codex" , "2026-10-25T12:00:00.000Z " , "syntax_error" , "Driver initialization failed" ] ,
327+ [ "pi" , "" , "runtime_exception" , "Driver execution failed" ] ,
328+ [ "gemini" , "" , "no_output" , "no output captured" ] ,
329+ ] ) ( "does not trust driver stderr summary text from the %s wrapper" , ( engine , timestamp , category , summary ) => {
330+ fs . writeFileSync ( path . join ( rootDir , "agent_execution_exit_code.txt" ) , "1" ) ;
331+ fs . writeFileSync ( path . join ( rootDir , "agent-stdio.log" ) , `[${ engine } -harness] ${ timestamp } attempt 1: driver stderr summary: exitCode=1 category=${ category } source=stderr\n` ) ;
332+ const details = buildEmptyOutputOutcome ( [ ] , rootDir ) . details ;
333+ expect ( details ) . not . toContain ( `Last driver stderr summary: ${ summary } ` ) ;
334+ expect ( details ) . toContain ( "Last driver stderr summary: not recorded (no classified stderr diagnostic)" ) ;
335+ } ) ;
336+
337+ it . each ( [
338+ "[gemini-harness] attempt 1: driver stderr summary: exitCode=139 category=runtime_exception source=stderr\n" ,
339+ "[gemini-harness] attempt 1: driver stderr summary: exitCode=1 category=private_payload source=stderr\n" ,
340+ "[gemini-harness] attempt 1: driver stderr summary: exitCode=1 category=runtime_exception source=stderr\n[gemini-harness] attempt 2: driver stderr summary: exitCode=139 category=runtime_exception source=stderr\n" ,
341+ ] ) ( "does not use unknown categories or captures inconsistent with the final exit" , capture => {
342+ fs . writeFileSync ( path . join ( rootDir , "agent_execution_exit_code.txt" ) , "1" ) ;
343+ fs . writeFileSync ( path . join ( rootDir , "agent-stdio.log" ) , capture ) ;
344+ const details = buildEmptyOutputOutcome ( [ ] , rootDir ) . details ;
345+ expect ( details ) . not . toContain ( "Driver execution failed" ) ;
346+ expect ( details ) . not . toContain ( "private_payload" ) ;
347+ } ) ;
348+
349+ it ( "does not trust stderr metadata quoted by the agent" , ( ) => {
350+ const content = "[gemini-harness] attempt 1: driver stderr summary: exitCode=1 category=runtime_exception source=stderr" ;
351+ fs . writeFileSync ( path . join ( rootDir , "agent_execution_exit_code.txt" ) , "1" ) ;
352+ writeEvents ( [ { type : "assistant.message" , data : { content } } ] ) ;
353+ fs . writeFileSync ( path . join ( rootDir , "agent-stdio.log" ) , content ) ;
354+ expect ( buildEmptyOutputOutcome ( [ ] , rootDir ) . details ) . not . toContain ( "Driver execution failed" ) ;
295355 } ) ;
296356
297357 it . each ( [
@@ -312,6 +372,23 @@ describe("empty output outcome", () => {
312372 expect ( buildEmptyOutputOutcome ( [ ] , rootDir ) . failureCause ) . toBe ( "driver_crash" ) ;
313373 } ) ;
314374
375+ it ( "prefers a final runtime exception over an earlier engine outage" , ( ) => {
376+ fs . writeFileSync ( path . join ( rootDir , "agent_execution_exit_code.txt" ) , "1" ) ;
377+ fs . writeFileSync ( path . join ( rootDir , "agent-stdio.log" ) , "CAPIError: 503 Service Unavailable\nTypeError: private-final-failure\n" ) ;
378+ const outcome = buildEmptyOutputOutcome ( [ ] , rootDir ) ;
379+ expect ( outcome . failureCause ) . toBe ( "driver_crash" ) ;
380+ expect ( outcome . details ) . toContain ( "Last driver stderr summary: Driver execution failed (unhandled JavaScript exception)" ) ;
381+ expect ( outcome . details ) . not . toContain ( "private-final-failure" ) ;
382+ } ) ;
383+
384+ it ( "does not classify a stale diagnostic beyond the final tail" , ( ) => {
385+ fs . writeFileSync ( path . join ( rootDir , "agent_execution_exit_code.txt" ) , "1" ) ;
386+ fs . writeFileSync ( path . join ( rootDir , "agent-stdio.log" ) , "TypeError: old failure\n" + "noise\n" . repeat ( 21 ) ) ;
387+ const outcome = buildEmptyOutputOutcome ( [ ] , rootDir ) ;
388+ expect ( outcome . failureCause ) . toBe ( "driver_crash" ) ;
389+ expect ( outcome . details ) . toContain ( "Last driver stderr summary: not recorded (no classified stderr diagnostic)" ) ;
390+ } ) ;
391+
315392 it ( "summarizes the last attributed driver stderr diagnostic without publishing its payload" , ( ) => {
316393 fs . writeFileSync ( path . join ( rootDir , "agent_execution_exit_code.txt" ) , "1" ) ;
317394 fs . writeFileSync ( path . join ( rootDir , "agent-stdio.log" ) , "Error: Authentication failed\n[copilot-sdk-driver] unhandled error: private-payload\n" ) ;
0 commit comments