@@ -25,6 +25,7 @@ vi.mock("../lib/logger.js", () => ({
2525 logger : {
2626 info : vi . fn ( ) ,
2727 warn : vi . fn ( ) ,
28+ error : vi . fn ( ) ,
2829 } ,
2930} ) ) ;
3031
@@ -386,11 +387,88 @@ describe("runPrePrChecksWithFixes", () => {
386387 expect ( result . fixCycles ) . toBe ( 1 ) ;
387388 expect ( result . agentFailure ) . toMatchObject ( {
388389 category : "provider" ,
389- diagnostic : { failureKind : "cli_exit" , exitCode : 7 } ,
390+ diagnostic : {
391+ failureKind : "cli_exit" ,
392+ exitCode : 7 ,
393+ detail : "The CLI exited with code 7." ,
394+ } ,
390395 } ) ;
391396 expect ( checkRuns ) . toBe ( 1 ) ;
392397 } ) ;
393398
399+ it ( "names the cause when the repair process cannot be launched at all" , async ( ) => {
400+ // Production runs died here with a failure that named only the boundary:
401+ // no exit code, no captured bytes, and the thrown error destroyed at the
402+ // catch. Every distinct launch cause has to reach the run record instead.
403+ const launchWith = ( thrown : unknown ) => {
404+ mockRunCommand . mockImplementation ( ( cmd , args ) => {
405+ if ( isWrapperLaunch ( cmd ) ) throw thrown ;
406+ if ( cmd === "cat" && args [ 0 ] === WORKSPACE_MANIFEST_PATH ) {
407+ return commandResult ( 0 , JSON . stringify ( manifest ) ) ;
408+ }
409+ if ( cmd === "git" && args [ 0 ] === "-C" && args [ 2 ] === "rev-parse" ) {
410+ return commandResult ( 0 , "web-head" ) ;
411+ }
412+ if ( isConfiguredCheck ( cmd ) ) return commandResult ( 1 , "" , "still failing" ) ;
413+ return commandResult ( 0 , "" ) ;
414+ } ) ;
415+ return runPrePrChecksWithFixes (
416+ "sbx-test-123" ,
417+ { repositories : [ config . repositories [ 0 ] ! ] } ,
418+ "codex" ,
419+ "gpt-5" ,
420+ ) ;
421+ } ;
422+
423+ const reset = await launchWith ( new Error ( "sandbox connection reset" ) ) ;
424+ expect ( reset . agentFailure ) . toMatchObject ( {
425+ diagnostic : {
426+ failureKind : "setup_failed" ,
427+ detail : expect . stringContaining ( "sandbox connection reset" ) ,
428+ } ,
429+ } ) ;
430+
431+ const refused = await launchWith (
432+ Object . assign ( new Error ( "connect ECONNREFUSED 10.0.0.1:443" ) , {
433+ code : "ECONNREFUSED" ,
434+ } ) ,
435+ ) ;
436+ expect ( refused . agentFailure ?. diagnostic . detail ) . toContain (
437+ "ECONNREFUSED: connect ECONNREFUSED 10.0.0.1:443" ,
438+ ) ;
439+ } ) ;
440+
441+ it ( "bounds a very long launch failure cause instead of embedding it whole" , async ( ) => {
442+ const thrownMessage = "sandbox refused the launch. " . repeat ( 200 ) ;
443+ mockRunCommand . mockImplementation ( ( cmd , args ) => {
444+ if ( isWrapperLaunch ( cmd ) ) throw new Error ( thrownMessage ) ;
445+ if ( cmd === "cat" && args [ 0 ] === WORKSPACE_MANIFEST_PATH ) {
446+ return commandResult ( 0 , JSON . stringify ( manifest ) ) ;
447+ }
448+ if ( cmd === "git" && args [ 0 ] === "-C" && args [ 2 ] === "rev-parse" ) {
449+ return commandResult ( 0 , "web-head" ) ;
450+ }
451+ if ( isConfiguredCheck ( cmd ) ) return commandResult ( 1 , "" , "still failing" ) ;
452+ return commandResult ( 0 , "" ) ;
453+ } ) ;
454+
455+ const result = await runPrePrChecksWithFixes (
456+ "sbx-test-123" ,
457+ { repositories : [ config . repositories [ 0 ] ! ] } ,
458+ "codex" ,
459+ "gpt-5" ,
460+ ) ;
461+
462+ const detail = result . agentFailure ?. diagnostic . detail ?? "" ;
463+ expect ( detail ) . toContain ( "The Pre-PR repair process could not be launched:" ) ;
464+ expect ( detail ) . not . toContain ( thrownMessage ) ;
465+ // Sentence plus the bound the repair cause is clamped to, and nothing more,
466+ // so a runaway error text cannot become the run status.
467+ expect ( detail . length ) . toBeLessThanOrEqual (
468+ "The Pre-PR repair process could not be launched: " . length + 200 ,
469+ ) ;
470+ } ) ;
471+
394472 it ( "keeps valid repair usage when malformed protocol output becomes an execution failure" , async ( ) => {
395473 let checkRuns = 0 ;
396474 const malformedWithUsage = [
@@ -666,6 +744,18 @@ function isConfiguredCheck(cmd: unknown): boolean {
666744 ) ;
667745}
668746
747+ function isWrapperLaunch ( cmd : unknown ) : boolean {
748+ const objectCommand = cmd as { cmd ?: unknown ; args ?: unknown } ;
749+ return (
750+ typeof cmd === "object" &&
751+ cmd !== null &&
752+ objectCommand . cmd === "bash" &&
753+ Array . isArray ( objectCommand . args ) &&
754+ typeof objectCommand . args [ 0 ] === "string" &&
755+ objectCommand . args [ 0 ] . endsWith ( "-wrapper.sh" )
756+ ) ;
757+ }
758+
669759function isHeadInspection ( cmd : unknown ) : boolean {
670760 const objectCommand = cmd as { cmd ?: unknown ; args ?: unknown } ;
671761 return (
0 commit comments