@@ -9,12 +9,15 @@ import * as Effect from "effect/Effect";
99import * as Hex from "effect/encoding/Hex" ;
1010import * as FileSystem from "effect/FileSystem" ;
1111import * as Option from "effect/Option" ;
12+ import * as Path from "effect/Path" ;
1213import * as PlatformError from "effect/PlatformError" ;
1314import * as Exit from "effect/Exit" ;
15+ import * as Queue from "effect/Queue" ;
1416import * as Scope from "effect/Scope" ;
1517import * as Sink from "effect/Sink" ;
1618import * as Stream from "effect/Stream" ;
1719import { HttpClient , HttpClientResponse } from "effect/http" ;
20+ import * as TestClock from "effect/testing/TestClock" ;
1821import { ChildProcessSpawner } from "effect/process" ;
1922import * as CodexInstallation from "./CodexInstallation.ts" ;
2023
@@ -59,19 +62,24 @@ const makeHarness = Effect.fn("test.makeCodexInstallation")(function* (
5962 const crypto = yield * Crypto . Crypto ;
6063 const sha256 = Hex . encode ( yield * crypto . digest ( "SHA-256" , archive ) . pipe ( Effect . orDie ) ) ;
6164 let runtimeRenameFailures = input . runtimeRenameFailures ?? 0 ;
65+ const failedRenames = yield * Queue . unbounded < void > ( ) ;
6266 const lockingFs : FileSystem . FileSystem = {
6367 ...fs ,
6468 // Suspended so each retry of the same effect is a fresh attempt, like the real rename.
6569 rename : ( from , to ) =>
6670 Effect . suspend ( ( ) =>
6771 / [ / \\ ] r u n t i m e $ / u. test ( from ) && runtimeRenameFailures -- > 0
68- ? Effect . fail (
69- PlatformError . systemError ( {
70- _tag : "PermissionDenied" ,
71- module : "FileSystem" ,
72- method : "rename" ,
73- pathOrDescriptor : from ,
74- } ) ,
72+ ? Queue . offer ( failedRenames , undefined ) . pipe (
73+ Effect . andThen (
74+ Effect . fail (
75+ PlatformError . systemError ( {
76+ _tag : "PermissionDenied" ,
77+ module : "FileSystem" ,
78+ method : "rename" ,
79+ pathOrDescriptor : from ,
80+ } ) ,
81+ ) ,
82+ ) ,
7583 )
7684 : fs . rename ( from , to ) ,
7785 ) ,
@@ -113,7 +121,15 @@ const makeHarness = Effect.fn("test.makeCodexInstallation")(function* (
113121 ) ,
114122 ) ,
115123 ) ;
116- return { installation, fs, baseDir, localBinaryPath, probeLog, downloads : ( ) => downloads } ;
124+ return {
125+ installation,
126+ fs,
127+ baseDir,
128+ localBinaryPath,
129+ probeLog,
130+ failedRenames,
131+ downloads : ( ) => downloads ,
132+ } ;
117133} ) ;
118134const terminalState = ( installation : CodexInstallation . CodexInstallation [ "Service" ] ) =>
119135 installation . changes . pipe (
@@ -465,8 +481,7 @@ const makeWindowsTar = (fs: FileSystem.FileSystem, commands: Array<string>) =>
465481 } ) . pipe ( Effect . orDie ) ,
466482 ) ;
467483
468- // Live clock: the Windows rename retry waits between attempts.
469- it . live ( "installs on Windows via System32 tar with CRLF output and a locked runtime" , ( ) =>
484+ it . effect ( "installs on Windows via System32 tar with CRLF output and a locked runtime" , ( ) =>
470485 Effect . gen ( function * ( ) {
471486 const fs = yield * FileSystem . FileSystem ;
472487 const commands : Array < string > = [ ] ;
@@ -476,14 +491,20 @@ it.live("installs on Windows via System32 tar with CRLF output and a locked runt
476491 runtimeRenameFailures : 3 ,
477492 } ) ;
478493 yield * h . installation . start ;
494+ // Each failed attempt has scheduled its retry before the test fiber resumes.
495+ for ( let attempt = 0 ; attempt < 3 ; attempt ++ ) {
496+ yield * Queue . take ( h . failedRenames ) ;
497+ yield * TestClock . adjust ( "100 millis" ) ;
498+ }
479499 expect ( yield * terminalState ( h . installation ) ) . toMatchObject ( { phase : "succeeded" } ) ;
480500 expect ( commands ) . toEqual ( [
481501 "C:\\Windows\\System32\\tar.exe" ,
482502 "C:\\Windows\\System32\\tar.exe" ,
483503 "C:\\Windows\\System32\\tar.exe" ,
484504 ] ) ;
505+ const path = yield * Path . Path ;
485506 expect ( ( yield * h . installation . resolve ( ) ) . executablePath ) . toBe (
486- ` ${ h . baseDir } / tools/ codex/ 0.156.1/ bin/ codex.exe` ,
507+ path . join ( h . baseDir , " tools" , " codex" , " 0.156.1" , " bin" , " codex.exe" ) ,
487508 ) ;
488509 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
489510) ;
0 commit comments