@@ -5,23 +5,19 @@ import * as NodeChildProcess from "node:child_process";
55import * as Duration from "effect/Duration" ;
66import * as Effect from "effect/Effect" ;
77import * as Fiber from "effect/Fiber" ;
8- import * as FileSystem from "effect/FileSystem" ;
98import * as Layer from "effect/Layer" ;
109import * as Sink from "effect/Sink" ;
1110import * as Stream from "effect/Stream" ;
1211import * as TestClock from "effect/testing/TestClock" ;
1312import { ChildProcessSpawner } from "effect/process" ;
1413
15- import * as DesktopEnvironment from "../app/DesktopEnvironment.ts" ;
1614import {
1715 buildWslRuntimeInstallScript ,
1816 buildWslRuntimeInvalidateScript ,
1917 buildWslRuntimePruneScript ,
2018 buildWslRuntimeProbeScript ,
2119 DesktopWslDistroListError ,
22- DesktopWslEnvironment ,
2320 formatMissingToolsReason ,
24- layer as desktopWslEnvironmentLayer ,
2521 parseNodePath ,
2622 parseNodeVersion ,
2723 parseResolvedPath ,
@@ -162,104 +158,6 @@ describe("probeWslDistros", () => {
162158 } ) ;
163159} ) ;
164160
165- // Stands in for wsl.exe against a stopped distro: the process exits with
166- // `exitCode` once `exitAfter` passes on the test clock, or never. `released`
167- // records the operation's scope closing, which is what kills wsl.exe for real.
168- const makeColdDistroWsl = ( options : {
169- readonly exitCode : number ;
170- readonly exitAfter ?: Duration . Duration ;
171- } ) => {
172- const child = { exited : false , released : false } ;
173- const spawner = ChildProcessSpawner . make ( ( ) =>
174- Effect . gen ( function * ( ) {
175- yield * Effect . addFinalizer ( ( ) =>
176- Effect . sync ( ( ) => {
177- child . released = true ;
178- } ) ,
179- ) ;
180- return ChildProcessSpawner . makeHandle ( {
181- pid : ChildProcessSpawner . ProcessId ( 1 ) ,
182- exitCode :
183- options . exitAfter === undefined
184- ? Effect . never
185- : Effect . sleep ( options . exitAfter ) . pipe (
186- Effect . as ( ChildProcessSpawner . ExitCode ( options . exitCode ) ) ,
187- Effect . tap ( ( ) =>
188- Effect . sync ( ( ) => {
189- child . exited = true ;
190- } ) ,
191- ) ,
192- ) ,
193- isRunning : Effect . sync ( ( ) => ! child . exited ) ,
194- kill : ( ) => Effect . void ,
195- unref : Effect . succeed ( Effect . void ) ,
196- stdin : Sink . drain ,
197- stdout : Stream . empty ,
198- stderr : Stream . empty ,
199- all : Stream . empty ,
200- getInputFd : ( ) => Sink . drain ,
201- getOutputFd : ( ) => Stream . empty ,
202- } ) ;
203- } ) ,
204- ) ;
205- const layer = Layer . merge (
206- TestClock . layer ( ) ,
207- desktopWslEnvironmentLayer . pipe (
208- Layer . provide (
209- Layer . mergeAll (
210- Layer . succeed ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
211- // Off Windows the layer reads only the platform from the environment.
212- Layer . succeed (
213- DesktopEnvironment . DesktopEnvironment ,
214- DesktopEnvironment . DesktopEnvironment . of ( {
215- platform : "linux" ,
216- } as DesktopEnvironment . DesktopEnvironment [ "Service" ] ) ,
217- ) ,
218- FileSystem . layerNoop ( { } ) ,
219- ) ,
220- ) ,
221- ) ,
222- ) ;
223- return { child, layer } ;
224- } ;
225-
226- // The first wsl.exe call after a distro stops waits for it to boot, which can
227- // pass 10 seconds (#14348).
228- describe ( "preWarm against a stopped distro" , ( ) => {
229- it . effect ( "waits for a boot that takes longer than 10 seconds" , ( ) => {
230- const wsl = makeColdDistroWsl ( { exitCode : 0 , exitAfter : Duration . seconds ( 12 ) } ) ;
231- return Effect . gen ( function * ( ) {
232- const fiber = yield * ( yield * DesktopWslEnvironment ) . preWarm ( "Ubuntu" ) . pipe ( Effect . forkScoped ) ;
233- yield * Effect . yieldNow ;
234- yield * TestClock . adjust ( Duration . seconds ( 12 ) ) ;
235- yield * Fiber . join ( fiber ) ;
236- expect ( wsl . child . exited ) . toBe ( true ) ;
237- } ) . pipe ( Effect . provide ( wsl . layer ) ) ;
238- } ) ;
239-
240- it . effect ( "releases wsl.exe at 30 seconds" , ( ) => {
241- const wsl = makeColdDistroWsl ( { exitCode : 0 } ) ;
242- return Effect . gen ( function * ( ) {
243- const fiber = yield * ( yield * DesktopWslEnvironment ) . preWarm ( "Ubuntu" ) . pipe ( Effect . forkScoped ) ;
244- yield * Effect . yieldNow ;
245- yield * TestClock . adjust ( Duration . seconds ( 29 ) ) ;
246- expect ( wsl . child . released ) . toBe ( false ) ;
247- yield * TestClock . adjust ( Duration . seconds ( 1 ) ) ;
248- yield * Fiber . join ( fiber ) ;
249- expect ( wsl . child . released ) . toBe ( true ) ;
250- } ) . pipe ( Effect . provide ( wsl . layer ) ) ;
251- } ) ;
252-
253- it . effect ( "returns a non-zero exit without waiting for the deadline" , ( ) => {
254- // The clock never moves, so this only finishes if nothing waits on it.
255- const wsl = makeColdDistroWsl ( { exitCode : 1 , exitAfter : Duration . zero } ) ;
256- return Effect . gen ( function * ( ) {
257- yield * ( yield * DesktopWslEnvironment ) . preWarm ( "Ubuntu" ) ;
258- expect ( wsl . child . released ) . toBe ( true ) ;
259- } ) . pipe ( Effect . provide ( wsl . layer ) ) ;
260- } ) ;
261- } ) ;
262-
263161describe ( "WSL runtime cache" , ( ) => {
264162 it . each ( [
265163 [
0 commit comments