@@ -3,6 +3,7 @@ import { expect, it } from "@effect/vitest";
33import type { ManagedPolicyDocument } from "@t3tools/contracts" ;
44import * as HostProcess from "@t3tools/shared/HostProcess" ;
55import * as Deferred from "effect/Deferred" ;
6+ import * as Duration from "effect/Duration" ;
67import * as Effect from "effect/Effect" ;
78import * as FileSystem from "effect/FileSystem" ;
89import * as Fiber from "effect/Fiber" ;
@@ -26,6 +27,8 @@ interface HarnessOptions {
2627 readonly mode ?: "web" | "desktop" ;
2728 readonly managed ?: boolean ;
2829 readonly preflight ?: "ready" | "blocked" ;
30+ readonly preflightDuration ?: Duration . Input ;
31+ readonly preflightStarted ?: Deferred . Deferred < void > ;
2932 readonly beforeDownload ?: Effect . Effect < void > ;
3033 readonly requestUpdate ?: ServiceLauncherClient . ServiceLauncherClient [ "Service" ] [ "requestUpdate" ] ;
3134 readonly desktopAppUpdate ?: DesktopAppUpdate . DesktopAppUpdate [ "Service" ] ;
@@ -78,6 +81,21 @@ const makeHarness = Effect.fn("test.make_self_update_harness")(function* (
7881 stderrInvalidUtf8 : false ,
7982 } ;
8083 }
84+ if ( options . preflightStarted ) yield * Deferred . succeed ( options . preflightStarted , undefined ) ;
85+ if ( options . preflightDuration !== undefined ) {
86+ // Like the real runner, fail once the caller's timeout elapses.
87+ const timeout = Duration . fromInputUnsafe ( input . timeout ?? "60 seconds" ) ;
88+ const finished = yield * Effect . sleep ( options . preflightDuration ) . pipe (
89+ Effect . timeoutOption ( timeout ) ,
90+ ) ;
91+ if ( finished . _tag === "None" ) {
92+ return yield * new ProcessRunner . ProcessTimeoutError ( {
93+ command : input . command ,
94+ argumentCount : input . args . length ,
95+ timeoutMs : Duration . toMillis ( timeout ) ,
96+ } ) ;
97+ }
98+ }
8199 order . push ( "preflight" ) ;
82100 const result =
83101 options . preflight === "blocked"
@@ -240,6 +258,27 @@ it.layer(NodeServices.layer)("server self update", (it) => {
240258 } ) ,
241259 ) ;
242260
261+ // regression: #28198 a slow staged preflight on a loaded host no longer fails the update
262+ it . effect ( "waits for a staged preflight that takes a minute on a loaded host" , ( ) =>
263+ Effect . gen ( function * ( ) {
264+ const preflightStarted = yield * Deferred . make < void > ( ) ;
265+ const { selfUpdate, order } = yield * makeHarness ( {
266+ preflightDuration : "60 seconds" ,
267+ preflightStarted,
268+ } ) ;
269+ const update = yield * Effect . forkChild ( selfUpdate . update ( { targetVersion : "1.1.0" } ) , {
270+ startImmediately : true ,
271+ } ) ;
272+ yield * Deferred . await ( preflightStarted ) ;
273+ yield * TestClock . adjust ( "60 seconds" ) ;
274+ const exit = yield * Fiber . await ( update ) ;
275+ expect ( exit . _tag === "Failure" ? String ( exit . cause ) : "launcher handoff" ) . toBe (
276+ "launcher handoff" ,
277+ ) ;
278+ expect ( order ) . toEqual ( [ "download" , "extract" , "preflight" , "accept" ] ) ;
279+ } ) ,
280+ ) ;
281+
243282 it . effect ( "keeps preparing after the progress stream closes" , ( ) =>
244283 Effect . gen ( function * ( ) {
245284 const releaseDownload = yield * Deferred . make < void > ( ) ;
0 commit comments