@@ -17,6 +17,7 @@ import {
1717 cliArchivePlatformKey ,
1818 cliArchiveTarCommand ,
1919 cliReleaseDownloadBaseUrl ,
20+ type CliArchivePlatformKey ,
2021 parseChecksums ,
2122} from "@t3tools/shared/cliRelease" ;
2223
@@ -111,6 +112,8 @@ interface PinnedRuntimeInstallInput {
111112 readonly arch : string ;
112113 readonly httpClient : HttpClient . HttpClient ;
113114 readonly releaseBaseUrl ?: string | undefined ;
115+ /** Reuse a cached runtime only while the release source still lists it, as a policy mirror does. */
116+ readonly requirePublishedRelease ?: boolean ;
114117 readonly onProgress ?: ( progress : PinnedRuntimeProgress ) => void ;
115118}
116119
@@ -178,25 +181,8 @@ const installFromArchive = Effect.fn("cloud.pinned_runtime.install_archive")(fun
178181 } ) ;
179182 }
180183 const httpClient = input . httpClient ;
181- const baseUrl = cliReleaseDownloadBaseUrl ( input . version , input . releaseBaseUrl ) ;
182- const fileName = cliArchiveFileName ( input . version , platformKey ) ;
183-
184184 input . onProgress ?.( { stage : "download" , received : 0 , total : undefined } ) ;
185- const checksums = parseChecksums (
186- new TextDecoder ( ) . decode (
187- yield * fetchReleaseAsset (
188- httpClient ,
189- `${ baseUrl } /${ CLI_RELEASE_CHECKSUMS_FILE } ` ,
190- "downloading the t3 release checksums" ,
191- ) ,
192- ) ,
193- ) ;
194- const expected = checksums . get ( fileName ) ;
195- if ( expected === undefined ) {
196- return yield * new PinnedRuntimeInstallError ( {
197- step : `finding ${ fileName } in the t3 release checksums` ,
198- } ) ;
199- }
185+ const { baseUrl, fileName, expected } = yield * publishedArchive ( input , platformKey ) ;
200186 const archive = yield * fetchReleaseAsset (
201187 httpClient ,
202188 `${ baseUrl } /${ fileName } ` ,
@@ -248,6 +234,31 @@ const installFromArchive = Effect.fn("cloud.pinned_runtime.install_archive")(fun
248234 yield * fs . remove ( archivePath , { force : true } ) . pipe ( Effect . ignore ) ;
249235} ) ;
250236
237+ /** The release's archive for this machine and its checksum; fails when the release lists none. */
238+ const publishedArchive = Effect . fn ( "cloud.pinned_runtime.published_archive" ) ( function * (
239+ input : PinnedRuntimeInstallInput ,
240+ platformKey : CliArchivePlatformKey ,
241+ ) {
242+ const baseUrl = cliReleaseDownloadBaseUrl ( input . version , input . releaseBaseUrl ) ;
243+ const fileName = cliArchiveFileName ( input . version , platformKey ) ;
244+ const checksums = parseChecksums (
245+ new TextDecoder ( ) . decode (
246+ yield * fetchReleaseAsset (
247+ input . httpClient ,
248+ `${ baseUrl } /${ CLI_RELEASE_CHECKSUMS_FILE } ` ,
249+ "downloading the t3 release checksums" ,
250+ ) ,
251+ ) ,
252+ ) ;
253+ const expected = checksums . get ( fileName ) ;
254+ if ( expected === undefined ) {
255+ return yield * new PinnedRuntimeInstallError ( {
256+ step : `finding ${ fileName } in the t3 release checksums` ,
257+ } ) ;
258+ }
259+ return { baseUrl, fileName, expected } ;
260+ } ) ;
261+
251262const installPinnedRuntime = Effect . fn ( "cloud.pinned_runtime.ensure_installed" ) ( function * (
252263 input : PinnedRuntimeInstallInput ,
253264) {
@@ -265,6 +276,15 @@ const installPinnedRuntime = Effect.fn("cloud.pinned_runtime.ensure_installed")(
265276 const alreadyPinned =
266277 entryExists && Option . isSome ( sentinel ) && sentinel . value . trim ( ) === input . version ;
267278 if ( alreadyPinned ) {
279+ if ( input . requirePublishedRelease === true ) {
280+ const platformKey = cliArchivePlatformKey ( input . platform , input . arch ) ;
281+ if ( platformKey === undefined ) {
282+ return yield * new PinnedRuntimeInstallError ( {
283+ step : `selecting a t3 release archive for ${ input . platform } -${ input . arch } ` ,
284+ } ) ;
285+ }
286+ yield * publishedArchive ( input , platformKey ) ;
287+ }
268288 input . onProgress ?.( { stage : "cached" } ) ;
269289 yield * input . validate ( paths ) ;
270290 return paths ;
0 commit comments