@@ -199,6 +199,63 @@ describe("provider workspace snapshot refresh atom", () => {
199199 unmount ( ) ;
200200 } ) ;
201201
202+ it . each ( [ "already expired" , "expires during discovery" ] ) (
203+ "retries an unchanged catalog that %s after the short cooldown" ,
204+ async ( expiry ) => {
205+ const start = Date . parse ( "2026-01-01T00:05:00.000Z" ) ;
206+ vi . useFakeTimers ( { now : expiry === "expires during discovery" ? start - 1 : start } ) ;
207+ const stale = withSnapshot ( "2026-01-01T00:00:00.000Z" ) ;
208+ const { registry, atom, responses, run, unmount } = setup (
209+ expiry === "expires during discovery"
210+ ? withSnapshot ( "2026-01-01T00:00:00.000Z" , true )
211+ : stale ,
212+ [
213+ ( ) => {
214+ if ( expiry === "expires during discovery" ) vi . setSystemTime ( start + 1 ) ;
215+ return stale ;
216+ } ,
217+ ] ,
218+ ) ;
219+ await vi . advanceTimersByTimeAsync ( 0 ) ;
220+ await vi . advanceTimersByTimeAsync ( 9_999 ) ;
221+ registry . refresh ( atom ) ;
222+ expect ( run ) . toHaveBeenCalledTimes ( 1 ) ;
223+ responses . push ( ( ) => withSnapshot ( "2026-01-01T00:05:10.000Z" ) ) ;
224+ await vi . advanceTimersByTimeAsync ( 1 ) ;
225+ registry . refresh ( atom ) ;
226+ expect ( run ) . toHaveBeenCalledTimes ( 2 ) ;
227+ unmount ( ) ;
228+ } ,
229+ ) ;
230+
231+ it ( "keeps the TTL guard for a newly scanned catalog when the client clock is ahead" , async ( ) => {
232+ vi . useFakeTimers ( { now : Date . parse ( "2026-01-01T01:00:00.000Z" ) } ) ;
233+ const { registry, atom, run, unmount } = setup ( withSnapshot ( "2026-01-01T00:00:00.000Z" ) , [
234+ ( ) => withSnapshot ( "2026-01-01T00:01:00.000Z" ) ,
235+ ] ) ;
236+ await vi . advanceTimersByTimeAsync ( 10_000 ) ;
237+ registry . refresh ( atom ) ;
238+ expect ( run ) . toHaveBeenCalledTimes ( 1 ) ;
239+ unmount ( ) ;
240+ } ) ;
241+
242+ it ( "bounds retries when discovery repeatedly returns the same expired catalog" , async ( ) => {
243+ vi . useFakeTimers ( { now : Date . parse ( "2026-01-01T00:05:00.000Z" ) } ) ;
244+ const stale = withSnapshot ( "2026-01-01T00:00:00.000Z" ) ;
245+ const { registry, atom, run, unmount } = setup ( stale , [ ( ) => stale , ( ) => stale , ( ) => stale ] ) ;
246+ await vi . advanceTimersByTimeAsync ( 0 ) ;
247+ await vi . advanceTimersByTimeAsync ( 10_000 ) ;
248+ registry . refresh ( atom ) ;
249+ await vi . advanceTimersByTimeAsync ( 0 ) ;
250+ await vi . advanceTimersByTimeAsync ( 10_000 ) ;
251+ registry . refresh ( atom ) ;
252+ await vi . advanceTimersByTimeAsync ( 0 ) ;
253+ await vi . advanceTimersByTimeAsync ( 10_000 ) ;
254+ registry . refresh ( atom ) ;
255+ expect ( run ) . toHaveBeenCalledTimes ( 3 ) ;
256+ unmount ( ) ;
257+ } ) ;
258+
202259 it ( "does not rescan a current snapshot, and rescans once it ages past the TTL" , ( ) => {
203260 vi . useFakeTimers ( { now : Date . parse ( "2026-01-01T00:01:00.000Z" ) } ) ;
204261 const { registry, atom, run, unmount } = setup ( withSnapshot ( "2026-01-01T00:00:00.000Z" ) ) ;
0 commit comments