@@ -17,9 +17,11 @@ import * as FileSystem from "effect/FileSystem";
1717import * as Layer from "effect/Layer" ;
1818import * as Option from "effect/Option" ;
1919import * as PlatformError from "effect/PlatformError" ;
20+ import * as Queue from "effect/Queue" ;
2021import * as Schema from "effect/Schema" ;
2122import * as Sink from "effect/Sink" ;
2223import * as Stream from "effect/Stream" ;
24+ import * as TestClock from "effect/testing/TestClock" ;
2325import { HttpClient , HttpClientResponse } from "effect/http" ;
2426import * as ChildProcess from "effect/process/ChildProcess" ;
2527import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner" ;
@@ -725,4 +727,54 @@ it.layer(layerTest)("CodexDriver", (it) => {
725727 } ) . pipe ( Effect . scoped ) ,
726728 { skip : windowsHost } ,
727729 ) ;
730+
731+ it . effect ( "probes again when auth.json in the Codex home changes" , ( ) =>
732+ Effect . gen ( function * ( ) {
733+ const fs = yield * FileSystem . FileSystem ;
734+ const codexHome = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-codex-auth-watch-" } ) ;
735+ const watchedPath = yield * Deferred . make < string > ( ) ;
736+ const homeEvents = yield * Queue . unbounded < FileSystem . WatchEvent > ( ) ;
737+ const probes = yield * Queue . unbounded < void > ( ) ;
738+ yield * CodexDriver . create ( {
739+ instanceId : ProviderInstanceId . make ( "codex-auth-watch" ) ,
740+ displayName : "Codex auth watch" ,
741+ enabled : true ,
742+ environment : [ ] ,
743+ config : { ...CodexDriver . defaultConfig ( ) , homePath : codexHome } ,
744+ } ) . pipe (
745+ // OS watchers can miss events written right after they start, so the test supplies them.
746+ Effect . provideService ( FileSystem . FileSystem , {
747+ ...fs ,
748+ watch : ( path ) =>
749+ Stream . unwrap (
750+ Deferred . succeed ( watchedPath , path ) . pipe ( Effect . as ( Stream . fromQueue ( homeEvents ) ) ) ,
751+ ) ,
752+ } ) ,
753+ Effect . provideService (
754+ ChildProcessSpawner . ChildProcessSpawner ,
755+ ChildProcessSpawner . make ( ( command ) =>
756+ ( ChildProcess . isStandardCommand ( command ) && command . args . includes ( "app-server" )
757+ ? Queue . offer ( probes , undefined )
758+ : Effect . void
759+ ) . pipe (
760+ Effect . andThen (
761+ PlatformError . badArgument ( {
762+ module : "ChildProcessSpawner" ,
763+ method : "spawn" ,
764+ description : "The fixture has no Codex executable" ,
765+ } ) ,
766+ ) ,
767+ ) ,
768+ ) ,
769+ ) ,
770+ ) ;
771+ expect ( yield * Deferred . await ( watchedPath ) ) . toBe ( codexHome ) ;
772+ yield * Queue . take ( probes ) ;
773+
774+ yield * Queue . offer ( homeEvents , { _tag : "Update" , path : "auth.json" } ) ;
775+ yield * TestClock . adjust ( "250 millis" ) ;
776+
777+ yield * Queue . take ( probes ) ;
778+ } ) . pipe ( Effect . scoped ) ,
779+ ) ;
728780} ) ;
0 commit comments