@@ -8,10 +8,12 @@ import * as NodePath from "node:path";
88import { ProviderDriverKind , ProviderInstanceId , type ServerProvider } from "@t3tools/contracts" ;
99import { HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
1010import * as Crypto from "effect/Crypto" ;
11+ import * as DateTime from "effect/DateTime" ;
1112import * as Effect from "effect/Effect" ;
1213import * as Sink from "effect/Sink" ;
1314import * as Stream from "effect/Stream" ;
14- import { HttpClient } from "effect/unstable/http" ;
15+ import * as TestClock from "effect/testing/TestClock" ;
16+ import { HttpClient , HttpClientRequest , HttpClientResponse } from "effect/unstable/http" ;
1517import { ChildProcessSpawner } from "effect/unstable/process" ;
1618import {
1719 createProviderVersionAdvisory ,
@@ -148,6 +150,44 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
148150 ) ,
149151 ) ;
150152
153+ it . effect (
154+ "retries a failed registry lookup on the next probe instead of caching it for an hour" ,
155+ ( ) =>
156+ Effect . gen ( function * ( ) {
157+ const cache = new Map < string , { expiresAt : number ; version : string | null } > ( ) ;
158+ const registry = ( status : number , body : string ) =>
159+ HttpClient . make ( ( ) =>
160+ Effect . succeed (
161+ HttpClientResponse . fromWeb (
162+ HttpClientRequest . get ( "https://registry.npmjs.org/" ) ,
163+ new Response ( body , { status } ) ,
164+ ) ,
165+ ) ,
166+ ) ;
167+ const failing = registry ( 503 , "" ) ;
168+ const serving = registry ( 200 , '{"version":"2.0.0"}' ) ;
169+ const resolve = ( client : HttpClient . HttpClient ) =>
170+ resolveLatestProviderVersion ( manualPackageTool ) . pipe (
171+ Effect . provideService ( ProviderVersionCache , cache ) ,
172+ Effect . provideService ( HttpClient . HttpClient , client ) ,
173+ ) ;
174+
175+ expect ( yield * resolve ( failing ) ) . toBeNull ( ) ;
176+ const failed = cache . get ( "@example/package-tool" ) ;
177+ expect ( failed ?. version ) . toBeNull ( ) ;
178+ expect ( failed ! . expiresAt - DateTime . toEpochMillis ( yield * DateTime . now ) ) . toBe ( 60_000 ) ;
179+
180+ // Still within the retry window: the failure is served from cache.
181+ expect ( yield * resolve ( serving ) ) . toBeNull ( ) ;
182+ yield * TestClock . adjust ( "61 seconds" ) ;
183+ expect ( yield * resolve ( serving ) ) . toBe ( "2.0.0" ) ;
184+ expect (
185+ cache . get ( "@example/package-tool" ) ! . expiresAt -
186+ DateTime . toEpochMillis ( yield * DateTime . now ) ,
187+ ) . toBe ( 60 * 60 * 1_000 ) ;
188+ } ) ,
189+ ) ;
190+
151191 it . effect ( "prefers the installer's own latest version over the npm registry" , ( ) =>
152192 resolveLatestProviderVersion ( { ...manualPackageTool , latestVersion : "1.2.0" } ) . pipe (
153193 Effect . provideService ( ProviderVersionCache , new Map ( ) ) ,
0 commit comments