Open History to see the last commit
1import { assert, describe, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Option from "effect/Option";
4
5import * as DesktopBackendManager from "../../backend/DesktopBackendManager.ts";
6import * as DesktopBackendPool from "../../backend/DesktopBackendPool.ts";
7import { getLocalEnvironmentBootstraps } from "./window.ts";
8
9const readyWslConfig: DesktopBackendManager.DesktopBackendStartConfig = {
10 executablePath: "wsl.exe",
11 args: ["-d", "Ubuntu", "--", "node", "/app/bin.mjs"],
12 entryPath: "/app/bin.mjs",
13 cwd: "/app",
14 env: {},
15 extendEnv: false,
16 bootstrap: {
17 mode: "desktop",
18 noBrowser: true,
19 port: 3774,
20 host: "0.0.0.0",
21 desktopBootstrapToken: "bootstrap-token",
22 tailscaleServeEnabled: false,
23 tailscaleServePort: 443,
24 },
25 bootstrapDelivery: "stdin",
26 httpBaseUrl: new URL("http://127.0.0.1:3774"),
27 captureOutput: true,
28 preflightFailure: Option.none(),
29 runningDistro: "Ubuntu",
30};
31
32const defaultWslInstance: DesktopBackendManager.DesktopBackendInstance = {
33 id: DesktopBackendManager.BackendInstanceId("wsl:default"),
34 label: Effect.succeed("WSL (default distro)"),
35 start: Effect.void,
36 stop: () => Effect.void,
37 currentConfig: Effect.succeed(Option.some(readyWslConfig)),
38 snapshot: Effect.succeed({
39 desiredRunning: true,
40 ready: true,
41 activePid: Option.some(123),
42 restartAttempt: 0,
43 restartScheduled: false,
44 }),
45 waitForReady: () => Effect.succeed(true),
46};
47
48describe("getLocalEnvironmentBootstraps", () => {
49 it.effect("publishes the concrete running distro without replacing the stable instance id", () =>
50 Effect.gen(function* () {
51 const result = yield* getLocalEnvironmentBootstraps.handler();
52
53 assert.deepEqual(result, [
54 {
55 id: "wsl:default",
56 label: "WSL (Ubuntu)",
57 runningDistro: "Ubuntu",
58 httpBaseUrl: "http://127.0.0.1:3774/",
59 wsBaseUrl: "ws://127.0.0.1:3774/",
60 bootstrapToken: "bootstrap-token",
61 },
62 ]);
63 }).pipe(Effect.provide(DesktopBackendPool.layerTest([defaultWslInstance]))),
64 );
65
66 it.effect("publishes a pending bootstrap only while a transient retry is scheduled", () => {
67 const retryingConfig: DesktopBackendManager.DesktopBackendStartConfig = {
68 ...readyWslConfig,
69 preflightFailure: Option.some({
70 reason: "WSL probe timed out",
71 fatal: false,
72 retryLimit: 12,
73 }),
74 };
75 const retryingInstance: DesktopBackendManager.DesktopBackendInstance = {
76 ...defaultWslInstance,
77 currentConfig: Effect.succeed(Option.some(retryingConfig)),
78 snapshot: Effect.succeed({
79 desiredRunning: true,
80 ready: false,
81 activePid: Option.none(),
82 restartAttempt: 2,
83 restartScheduled: true,
84 }),
85 };
86
87 return Effect.gen(function* () {
88 const result = yield* getLocalEnvironmentBootstraps.handler();
89 assert.deepEqual(result, [
90 {
91 id: "wsl:default",
92 label: "WSL (default distro)",
93 runningDistro: null,
94 httpBaseUrl: null,
95 wsBaseUrl: null,
96 },
97 ]);
98 }).pipe(Effect.provide(DesktopBackendPool.layerTest([retryingInstance])));
99 });
100
101 it.effect("omits a bounded transient bootstrap after retries stop", () => {
102 const stoppedInstance: DesktopBackendManager.DesktopBackendInstance = {
103 ...defaultWslInstance,
104 currentConfig: Effect.succeed(
105 Option.some({
106 ...readyWslConfig,
107 preflightFailure: Option.some({
108 reason: "WSL probe timed out",
109 fatal: false,
110 retryLimit: 12,
111 }),
112 }),
113 ),
114 snapshot: Effect.succeed({
115 desiredRunning: false,
116 ready: false,
117 activePid: Option.none(),
118 restartAttempt: 12,
119 restartScheduled: false,
120 }),
121 };
122
123 return Effect.gen(function* () {
124 const result = yield* getLocalEnvironmentBootstraps.handler();
125 assert.deepEqual(result, []);
126 }).pipe(Effect.provide(DesktopBackendPool.layerTest([stoppedInstance])));
127 });
128});