1- import { describe , expect , it } from "@effect/vitest" ;
1+ import { describe , expect , it , vi } from "@effect/vitest" ;
22import {
33 EnvironmentId ,
44 ThreadId ,
@@ -17,6 +17,7 @@ import * as Option from "effect/Option";
1717import * as Stream from "effect/Stream" ;
1818import * as Schema from "effect/Schema" ;
1919import * as SubscriptionRef from "effect/SubscriptionRef" ;
20+ import * as TestClock from "effect/testing/TestClock" ;
2021import { Atom , AtomRegistry } from "effect/reactivity" ;
2122
2223import { AVAILABLE_CONNECTION_STATE } from "../connection/model.ts" ;
@@ -118,6 +119,42 @@ const makeHarness = Effect.fnUntraced(function* () {
118119} ) ;
119120
120121describe ( "file metadata" , ( ) => {
122+ it . effect ( "refreshes expired mounted misses while retaining known thread entries" , ( ) =>
123+ Effect . gen ( function * ( ) {
124+ vi . useFakeTimers ( { toFake : [ "setTimeout" , "clearTimeout" ] } ) ;
125+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => vi . useRealTimers ( ) ) ) ;
126+ const h = yield * makeHarness ( ) ;
127+ const threadId = ThreadId . make ( "new-directory-thread" ) ;
128+ h . registry . mount ( h . atoms . retainThread ( { environmentId : ENVIRONMENT_ID , threadId } ) ) ;
129+ const path = "/home/user/games/hl1" ;
130+ h . registry . mount ( h . atom ( path , ENVIRONMENT_ID , threadId ) ) ;
131+ h . values . set ( "/workspace/known" , { kind : "file" , byteLength : 5 } ) ;
132+ expect ( yield * h . read ( path , ENVIRONMENT_ID , threadId ) ) . toBeNull ( ) ;
133+ yield * h . read ( "/workspace/known" , ENVIRONMENT_ID , threadId ) ;
134+ h . values . set ( path , { kind : "directory" } ) ;
135+ h . registry . refresh ( h . atom ( path , ENVIRONMENT_ID , threadId ) ) ;
136+ expect ( yield * h . read ( path , ENVIRONMENT_ID , threadId ) ) . toBeNull ( ) ;
137+ h . failure . denied = true ;
138+ yield * TestClock . adjust ( 60_001 ) ;
139+ yield * Effect . promise ( ( ) => vi . advanceTimersByTimeAsync ( 60_000 ) ) ;
140+ expect ( yield * h . read ( path , ENVIRONMENT_ID , threadId ) . pipe ( Effect . flip ) ) . toBeInstanceOf (
141+ EnvironmentAuthorizationError ,
142+ ) ;
143+ h . failure . denied = false ;
144+ yield * TestClock . adjust ( 60_001 ) ;
145+ yield * Effect . promise ( ( ) => vi . advanceTimersByTimeAsync ( 60_000 ) ) ;
146+ expect ( yield * h . read ( path , ENVIRONMENT_ID , threadId ) ) . toEqual ( { kind : "directory" } ) ;
147+ h . registry . refresh ( h . atom ( "/workspace/known" , ENVIRONMENT_ID , threadId ) ) ;
148+ expect ( yield * h . read ( "/workspace/known" , ENVIRONMENT_ID , threadId ) ) . toEqual ( {
149+ kind : "file" ,
150+ byteLength : 5 ,
151+ } ) ;
152+ yield * TestClock . adjust ( 60_001 ) ;
153+ yield * Effect . promise ( ( ) => vi . advanceTimersByTimeAsync ( 60_000 ) ) ;
154+ expect ( h . batches ) . toEqual ( [ [ path ] , [ "/workspace/known" ] , [ path ] , [ path ] ] ) ;
155+ } ) . pipe ( Effect . scoped ) ,
156+ ) ;
157+
121158 it . effect ( "does not seed a different path from a literal name with a numeric suffix" , ( ) =>
122159 Effect . gen ( function * ( ) {
123160 const h = yield * makeHarness ( ) ;
0 commit comments