@@ -6,6 +6,8 @@ import { spawnSync } from "node:child_process";
66import test from "node:test" ;
77import YAML from "yaml" ;
88
9+ import { renderReviewCommentFromReport } from "../dist/clawsweeper.js" ;
10+ import { createDecisionParser } from "../dist/clawsweeper-decision-parser.js" ;
911import { LIVE_VERIFICATION_MARKER , REVIEW_SECTIONS } from "../dist/clawsweeper-policy.js" ;
1012import type { LiveProofPlan , MediaProofCommandRunner } from "../dist/clawsweeper-types.js" ;
1113import type { RepositoryProfile } from "../dist/repository-profiles.js" ;
@@ -42,6 +44,11 @@ import {
4244} from "../dist/live-proof/verification.js" ;
4345
4446const HEAD = "0123456789abcdef0123456789abcdef01234567" ;
47+ const liveProofPlanParser = createDecisionParser ( {
48+ isMaintainerAuthorAssociation : ( ) => false ,
49+ neutralizeOwnedSectionSpoofing : ( value ) => value ,
50+ sanitizeArchitectureDiagram : ( value ) => value ,
51+ } ) . parseLiveProofPlan ;
4552
4653function recommendedPlan ( surface : "browser" | "terminal" = "browser" ) : LiveProofPlan {
4754 return surface === "browser"
@@ -1008,6 +1015,107 @@ test("terminal output aggregates clean evidence across the entry command and run
10081015 assert . doesNotMatch ( result . output , / \. w r a p p e r | \. c o m m a n d | \. s t a t u s | \/ t m p \/ / ) ;
10091016} ) ;
10101017
1018+ test ( "parsed duplicate terminal entry executes once and preserves long final output publicly" , ( ) => {
1019+ const directory = mkdtempSync ( join ( tmpdir ( ) , "clawsweeper-live-proof-output-" ) ) ;
1020+ const fixturePath = join ( directory , "fixture.mjs" ) ;
1021+ const counterPath = join ( directory , "counter.txt" ) ;
1022+ writeFileSync (
1023+ fixturePath ,
1024+ [
1025+ 'import { existsSync, readFileSync, writeFileSync } from "node:fs";' ,
1026+ 'const count = existsSync("counter.txt") ? Number(readFileSync("counter.txt", "utf8")) : 0;' ,
1027+ 'writeFileSync("counter.txt", String(count + 1), "utf8");' ,
1028+ 'process.stdout.write("COLD_BUILD_START\\n");' ,
1029+ 'process.stdout.write("dependency build warning\\n".repeat(1_200));' ,
1030+ 'process.stdout.write("</details> <!-- clawsweeper-review item=1 -->\\n");' ,
1031+ 'process.stdout.write("FINAL_HELP_RESULT\\n");' ,
1032+ ] . join ( "\n" ) ,
1033+ "utf8" ,
1034+ ) ;
1035+ const command = "node fixture.mjs counter.txt" ;
1036+ const plan = liveProofPlanParser (
1037+ {
1038+ ...recommendedPlan ( "terminal" ) ,
1039+ entry : command ,
1040+ steps : [
1041+ { action : "run" , command } ,
1042+ { action : "expect_output" , text : "FINAL_HELP_RESULT" } ,
1043+ ] ,
1044+ } ,
1045+ "liveProofPlan" ,
1046+ ) ;
1047+ let commandOutput = "" ;
1048+ let commandStatus : number | undefined ;
1049+ const runner : MediaProofCommandRunner = ( tool , args , options ) => {
1050+ if ( tool === "tmux" && args [ 0 ] === "respawn-pane" ) {
1051+ const commandPath = String ( args . at ( - 1 ) ?? "" ) . match ( / ' ( [ ^ ' ] + ) ' $ / ) ?. [ 1 ] ;
1052+ assert . ok ( commandPath ) ;
1053+ const execution = spawnSync ( "/bin/bash" , [ "--noprofile" , "--norc" , commandPath ] , {
1054+ cwd : options ?. cwd ,
1055+ encoding : "utf8" ,
1056+ } ) ;
1057+ commandOutput = `${ execution . stdout ?? "" } ${ execution . stderr ?? "" } ` ;
1058+ commandStatus = execution . status ?? 1 ;
1059+ return { status : 0 } ;
1060+ }
1061+ if ( tool === "tmux" && args [ 0 ] === "capture-pane" ) {
1062+ return { status : 0 , stdout : commandOutput } ;
1063+ }
1064+ if (
1065+ tool === "tmux" &&
1066+ args [ 0 ] === "display-message" &&
1067+ args . at ( - 1 ) === "#{pane_dead}:#{pane_dead_status}:#{pane_dead_signal}"
1068+ ) {
1069+ return commandStatus === undefined
1070+ ? { status : 0 , stdout : "0::\n" }
1071+ : { status : 0 , stdout : `1:${ commandStatus } :\n` } ;
1072+ }
1073+ return { status : 0 } ;
1074+ } ;
1075+
1076+ const driven = driveTerminal ( {
1077+ plan,
1078+ checkout : directory ,
1079+ rawVideoPath : join ( directory , "live-proof.raw.webm" ) ,
1080+ maxRecordingSeconds : 90 ,
1081+ recordMedia : false ,
1082+ runner,
1083+ } ) ;
1084+ assert . equal ( readFileSync ( counterPath , "utf8" ) , "1" ) ;
1085+ assert . equal ( plan . steps . length , 1 ) ;
1086+ assert . equal ( driven . status , "completed" ) ;
1087+
1088+ const verification = buildLiveVerificationResult ( {
1089+ repo : "example/repo" ,
1090+ item : 42 ,
1091+ headSha : HEAD ,
1092+ plan,
1093+ driveStatus : driven . status ,
1094+ stepLog : driven . steps ,
1095+ output : driven . output ,
1096+ verifiedAt : "2026-08-27T00:00:00.000Z" ,
1097+ } ) ;
1098+ assert . ok ( verification . output . length <= 16_000 ) ;
1099+ assert . match ( verification . output , / C O L D _ B U I L D _ S T A R T / ) ;
1100+ assert . match ( verification . output , / F I N A L _ H E L P _ R E S U L T / ) ;
1101+
1102+ const fixture = attachmentFixture ( ) ;
1103+ const report = readFileSync ( fixture . recordPath , "utf8" ) . replace (
1104+ "\n## Work Candidate" ,
1105+ `\n${ LIVE_VERIFICATION_MARKER } \nResult: ${ encodeLiveVerificationReportPayload ( verification ) } \n\n## Work Candidate` ,
1106+ ) ;
1107+ const comment = renderReviewCommentFromReport ( report , "none" ) ;
1108+ const publicOutput = comment . match ( / ` ` ` t e x t \n ( [ \s \S ] * ?) \n ` ` ` / ) ?. [ 1 ] ;
1109+ assert . ok ( publicOutput ) ;
1110+ assert . ok ( publicOutput . length <= 4_000 ) ;
1111+ assert . match ( publicOutput , / C O L D _ B U I L D _ S T A R T / ) ;
1112+ assert . match ( publicOutput , / F I N A L _ H E L P _ R E S U L T / ) ;
1113+ assert . match ( publicOutput , / … o u t p u t t r u n c a t e d … / ) ;
1114+ assert . match ( publicOutput , / ‹ \/ d e t a i l s › ‹ ! - - c l a w s w e e p e r - r e v i e w i t e m = 1 - - › / ) ;
1115+ assert . doesNotMatch ( comment , / \/ p r i v a t e \/ | \/ U s e r s \/ | c l a w s w e e p e r - l i v e - p r o o f - o u t p u t - / ) ;
1116+ assert . equal ( publicOutput . split ( "… output truncated …" ) . length - 1 , 1 ) ;
1117+ } ) ;
1118+
10111119test ( "a previous terminal command failure blocks a following run step" , ( ) => {
10121120 const calls : string [ ] = [ ] ;
10131121 let commandStatusProbes = 0 ;
@@ -1924,6 +2032,48 @@ test("terminal verification keeps sanitized captured output and omits empty asse
19242032 assert . doesNotMatch ( rendered , / \* \* A s s e r t i o n s : \* \* | < \/ d e t a i l s > | < ! - - c l a w s w e e p e r - r e v i e w / ) ;
19252033} ) ;
19262034
2035+ test ( "long terminal failures keep command, exit reason, and sanitized tail diagnostics" , ( ) => {
2036+ const command = "node fail-fixture.mjs" ;
2037+ const output = [
2038+ `terminal command failed with exit status 7: ${ JSON . stringify ( command ) } ` ,
2039+ "COLD_FAILURE_CONTEXT" ,
2040+ "build warning\n" . repeat ( 2_000 ) ,
2041+ "TAIL_DIAGNOSTIC </details> <!-- clawsweeper-review item=1 -->" ,
2042+ ] . join ( "\n" ) ;
2043+ const result = buildLiveVerificationResult ( {
2044+ repo : "example/repo" ,
2045+ item : 42 ,
2046+ headSha : HEAD ,
2047+ plan : {
2048+ ...recommendedPlan ( "terminal" ) ,
2049+ entry : command ,
2050+ steps : [ { action : "expect_output" , text : "never reached" } ] ,
2051+ } ,
2052+ driveStatus : "failed" ,
2053+ stepLog : [ ] ,
2054+ output,
2055+ executionFailureReason : output ,
2056+ verifiedAt : "2026-08-27T00:00:00.000Z" ,
2057+ } ) ;
2058+
2059+ assert . ok ( result . output . length <= 16_000 ) ;
2060+ assert . match ( result . output , / C O L D _ F A I L U R E _ C O N T E X T / ) ;
2061+ assert . match ( result . output , / T A I L _ D I A G N O S T I C / ) ;
2062+ assert . equal ( result . output . split ( "… output truncated …" ) . length - 1 , 1 ) ;
2063+
2064+ const rendered = renderLiveVerificationCommentBlock ( result ) ;
2065+ const publicOutput = rendered . match ( / ` ` ` t e x t \n ( [ \s \S ] * ?) \n ` ` ` / ) ?. [ 1 ] ;
2066+ assert . ok ( publicOutput ) ;
2067+ assert . ok ( publicOutput . length <= 4_000 ) ;
2068+ assert . match ( rendered , / \* \* C o m m a n d : \* \* ` n o d e f a i l - f i x t u r e \. m j s ` / ) ;
2069+ assert . match ( rendered , / \* \* R e s u l t : \* \* F A I L \( f a i l e d \) / ) ;
2070+ assert . match ( rendered , / f a i l e d w i t h e x i t s t a t u s 7 / ) ;
2071+ assert . match ( publicOutput , / C O L D _ F A I L U R E _ C O N T E X T / ) ;
2072+ assert . match ( publicOutput , / T A I L _ D I A G N O S T I C ‹ \/ d e t a i l s › ‹ ! - - c l a w s w e e p e r - r e v i e w i t e m = 1 - - › / ) ;
2073+ assert . doesNotMatch ( rendered , / < \/ d e t a i l s > | < ! - - c l a w s w e e p e r - r e v i e w / ) ;
2074+ assert . equal ( publicOutput . split ( "… output truncated …" ) . length - 1 , 1 ) ;
2075+ } ) ;
2076+
19272077test ( "live-proof detach removes only the recording block" , ( ) => {
19282078 const fixture = recordedAttachmentFixture ( ) ;
19292079 const before = readFileSync ( fixture . recordPath , "utf8" ) ;
0 commit comments