@@ -56,6 +56,19 @@ function ignoreWindowsTempCleanupRace(error: unknown): void {
5656 if ( ! [ 'EBUSY' , 'ENOTEMPTY' , 'EPERM' ] . includes ( code ?? '' ) ) throw error ;
5757}
5858
59+ function cleanupSessionRoot ( sessionRoot : string ) : void {
60+ try {
61+ rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
62+ recursive : true ,
63+ force : true ,
64+ maxRetries : 10 ,
65+ retryDelay : 200
66+ } ) ;
67+ } catch ( error ) {
68+ ignoreWindowsTempCleanupRace ( error ) ;
69+ }
70+ }
71+
5972function tempSessionRoot ( phase : 'phase40' | 'phase41' = 'phase40' ) : string {
6073 return path . join (
6174 mkdtempSync ( path . join ( tmpdir ( ) , `contextbench-${ phase } -runner-` ) ) ,
@@ -156,12 +169,7 @@ describe('ContextBench Phase 40 baseline runner', () => {
156169 expect ( rows . every ( ( row ) => row . scoring . officialEvaluatorInvoked === false ) ) . toBe ( true ) ;
157170 expect ( rows . every ( ( row ) => ! ( 'taskWallTimeMs' in row . setupIndex ) ) ) . toBe ( true ) ;
158171 } finally {
159- rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
160- recursive : true ,
161- force : true ,
162- maxRetries : 10 ,
163- retryDelay : 200
164- } ) ;
172+ cleanupSessionRoot ( sessionRoot ) ;
165173 }
166174 } ) ;
167175
@@ -226,10 +234,7 @@ describe('ContextBench Phase 40 baseline runner', () => {
226234 expect ( rawTrace . scriptedAgentDecisions ) . toBe ( false ) ;
227235 expect ( rawTrace . antiScriptingBoundary ) . toEqual ( expect . arrayContaining ( [ 'file_selection' ] ) ) ;
228236 } finally {
229- rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
230- recursive : true ,
231- force : true
232- } ) ;
237+ cleanupSessionRoot ( sessionRoot ) ;
233238 }
234239 } ) ;
235240
@@ -553,10 +558,7 @@ describe('ContextBench Phase 40 baseline runner', () => {
553558 ) as { phase : number } ;
554559 expect ( session . phase ) . toBe ( 41 ) ;
555560 } finally {
556- rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
557- recursive : true ,
558- force : true
559- } ) ;
561+ cleanupSessionRoot ( sessionRoot ) ;
560562 }
561563 } ) ;
562564
@@ -617,10 +619,7 @@ describe('ContextBench Phase 40 baseline runner', () => {
617619 setupLogPath : measurement . setupLogPath
618620 } ) ;
619621 } finally {
620- rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
621- recursive : true ,
622- force : true
623- } ) ;
622+ cleanupSessionRoot ( sessionRoot ) ;
624623 }
625624 } ) ;
626625
@@ -656,10 +655,7 @@ describe('ContextBench Phase 40 baseline runner', () => {
656655 expect ( attempt ?. scoring . fallbackReason ) . toContain ( 'missing_setup_index_measurement' ) ;
657656 expect ( attempt ?. setupIndex . setupStatus ) . toBe ( 'setup_failed' ) ;
658657 } finally {
659- rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
660- recursive : true ,
661- force : true
662- } ) ;
658+ cleanupSessionRoot ( sessionRoot ) ;
663659 }
664660 } ) ;
665661
@@ -740,10 +736,7 @@ describe('ContextBench Phase 40 baseline runner', () => {
740736 indexLogPath
741737 } ) ;
742738 } finally {
743- rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
744- recursive : true ,
745- force : true
746- } ) ;
739+ cleanupSessionRoot ( sessionRoot ) ;
747740 }
748741 } ) ;
749742
@@ -883,10 +876,7 @@ describe('ContextBench Phase 40 baseline runner', () => {
883876 expect ( attempt ?. status ) . toBe ( 'setup_failed' ) ;
884877 expect ( attempt ?. scoring . fallbackReason ) . toContain ( 'missing_setup_index_measurement' ) ;
885878 } finally {
886- rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
887- recursive : true ,
888- force : true
889- } ) ;
879+ cleanupSessionRoot ( sessionRoot ) ;
890880 }
891881 } ) ;
892882
@@ -936,10 +926,7 @@ describe('ContextBench Phase 40 baseline runner', () => {
936926 ) as { reservations : unknown [ ] } ;
937927 expect ( reservations . reservations ) . toHaveLength ( 20 * 6 * 3 ) ;
938928 } finally {
939- rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
940- recursive : true ,
941- force : true
942- } ) ;
929+ cleanupSessionRoot ( sessionRoot ) ;
943930 }
944931 } ) ;
945932
@@ -1102,16 +1089,7 @@ describe('ContextBench Phase 40 baseline runner', () => {
11021089 expect ( result . stdout ) . toContain ( 'phase42 verification failed' ) ;
11031090 expect ( result . stderr ) . toContain ( 'baseline seal blocked by Phase 42 evidence gate' ) ;
11041091 } finally {
1105- try {
1106- rmSync ( path . dirname ( path . dirname ( path . dirname ( path . dirname ( sessionRoot ) ) ) ) , {
1107- recursive : true ,
1108- force : true ,
1109- maxRetries : 10 ,
1110- retryDelay : 200
1111- } ) ;
1112- } catch ( error ) {
1113- ignoreWindowsTempCleanupRace ( error ) ;
1114- }
1092+ cleanupSessionRoot ( sessionRoot ) ;
11151093 }
11161094 } ) ;
11171095} ) ;
0 commit comments