@@ -472,6 +472,66 @@ describe("makeManagedServerProvider", () => {
472472 ) . pipe ( Effect . provide ( layerAlwaysRunTest ) ) ,
473473 ) ;
474474
475+ it . effect (
476+ "rechecks an auth failure when settings are applied, even if this provider's did not change" ,
477+ ( ) =>
478+ Effect . scoped (
479+ Effect . gen ( function * ( ) {
480+ const settingsChanges = yield * PubSub . unbounded <
481+ TestSettings & { readonly revision : number }
482+ > ( ) ;
483+ const checkCalls = yield * Ref . make ( 0 ) ;
484+ const seenRevisions : Array < number > = [ ] ;
485+ const releaseInitialCheck = yield * Deferred . make < void > ( ) ;
486+ const markerApplied = yield * Deferred . make < void > ( ) ;
487+ const unauthenticatedSnapshot : ServerProvider = {
488+ ...refreshedSnapshot ,
489+ status : "error" ,
490+ auth : { status : "unauthenticated" } ,
491+ message : "Codex CLI is not authenticated. Run `codex login` and try again." ,
492+ } ;
493+ const provider = yield * makeManagedServerProvider <
494+ TestSettings & { readonly revision : number }
495+ > ( {
496+ resolveMaintenance : ( ) => Effect . succeed ( maintenanceCapabilities ) ,
497+ getSettings : Effect . succeed ( { enabled : true , revision : 0 } ) ,
498+ streamSettings : Stream . fromPubSub ( settingsChanges ) ,
499+ haveSettingsChanged : ( previous , next ) => {
500+ seenRevisions . push ( next . revision ) ;
501+ if ( next . revision === 2 ) Deferred . doneUnsafe ( markerApplied , Effect . void ) ;
502+ return previous . enabled !== next . enabled ;
503+ } ,
504+ initialSnapshot : ( ) => Effect . succeed ( initialSnapshot ) ,
505+ // The credential is fixed (e.g. `codex login`) after the first, failed probe.
506+ checkProvider : Deferred . await ( releaseInitialCheck ) . pipe (
507+ Effect . andThen ( Ref . updateAndGet ( checkCalls , ( count ) => count + 1 ) ) ,
508+ Effect . map ( ( count ) => ( count === 1 ? unauthenticatedSnapshot : refreshedSnapshot ) ) ,
509+ ) ,
510+ refreshInterval : "1 hour" ,
511+ } ) ;
512+ const initialProbe = yield * provider . streamChanges . pipe (
513+ Stream . take ( 1 ) ,
514+ Stream . runDrain ,
515+ Effect . forkChild ,
516+ ) ;
517+ yield * Effect . yieldNow ;
518+ yield * Deferred . succeed ( releaseInitialCheck , undefined ) ;
519+ yield * Fiber . join ( initialProbe ) ;
520+ assert . deepStrictEqual ( yield * provider . getSnapshot , unauthenticatedSnapshot ) ;
521+
522+ // A settings apply that does not touch this provider's settings, then a marker:
523+ // the consumer is sequential, so the first apply has finished once the marker is seen.
524+ yield * PubSub . publish ( settingsChanges , { enabled : true , revision : 1 } ) ;
525+ yield * PubSub . publish ( settingsChanges , { enabled : true , revision : 2 } ) ;
526+ yield * Deferred . await ( markerApplied ) ;
527+
528+ assert . deepStrictEqual ( seenRevisions , [ 1 , 2 ] ) ;
529+ assert . isAtLeast ( yield * Ref . get ( checkCalls ) , 2 ) ;
530+ assert . deepStrictEqual ( ( yield * provider . getSnapshot ) . auth , refreshedSnapshot . auth ) ;
531+ } ) ,
532+ ) . pipe ( Effect . provide ( layerAlwaysRunTest ) ) ,
533+ ) ;
534+
475535 it . effect ( "streams supplemental snapshot updates after the base provider check completes" , ( ) =>
476536 Effect . scoped (
477537 Effect . gen ( function * ( ) {
0 commit comments