Open History to see the last commit
1import { assert, describe, it } from "@effect/vitest";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import type { ManagedPolicyLimits } from "@t3tools/contracts";
4import { EDITORS, REMOTE_CAPABLE_EDITOR_IDS } from "@t3tools/contracts";
5import { resolveEditorCommand } from "@t3tools/shared/editor";
6import * as HostProcess from "@t3tools/shared/HostProcess";
7import { ManagedPolicyFileError } from "@t3tools/shared/managedPolicyFile";
8import * as FileSystem from "effect/FileSystem";
9import * as Path from "effect/Path";
10import * as Effect from "effect/Effect";
11import * as Layer from "effect/Layer";
12import * as Option from "effect/Option";
13import { vi } from "vite-plus/test";
14import type * as Electron from "electron";
15
16const { focusedWebContents, ownerWindow } = vi.hoisted(() => ({
17 focusedWebContents: vi.fn(),
18 ownerWindow: vi.fn(),
19}));
20vi.mock("electron", () => ({
21 webContents: { getFocusedWebContents: focusedWebContents },
22 BrowserWindow: { fromWebContents: ownerWindow },
23}));
24
25import * as DesktopBackendConfiguration from "../../backend/DesktopBackendConfiguration.ts";
26import * as DesktopBackendManager from "../../backend/DesktopBackendManager.ts";
27import * as DesktopBackendPool from "../../backend/DesktopBackendPool.ts";
28import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
29import * as DesktopManagedPolicy from "../../app/DesktopManagedPolicy.ts";
30import * as DesktopWslEnvironment from "../../wsl/DesktopWslEnvironment.ts";
31import * as ElectronDialog from "../../electron/ElectronDialog.ts";
32import * as ElectronWindow from "../../electron/ElectronWindow.ts";
33import * as IpcChannels from "../channels.ts";
34import * as DesktopIpc from "../DesktopIpc.ts";
35import {
36 getLocalEnvironmentBootstraps,
37 installRelayTelemetryEnabled,
38 pickProjectFavicon,
39 probeRemoteEditors,
40 readMedia,
41 syncHtmlFullscreen,
42 toLocalBackendPath,
43} from "./window.ts";
44
45const readyWslConfig: DesktopBackendManager.DesktopBackendStartConfig = {
46 executablePath: "wsl.exe",
47 args: ["-d", "Ubuntu", "--", "node", "/app/bin.mjs"],
48 entryPath: "/app/bin.mjs",
49 cwd: "/app",
50 env: {},
51 extendEnv: false,
52 bootstrap: {
53 mode: "desktop",
54 noBrowser: true,
55 port: 3774,
56 host: "0.0.0.0",
57 desktopBootstrapToken: "bootstrap-token",
58 tailscaleServeEnabled: false,
59 tailscaleServePort: 443,
60 },
61 bootstrapDelivery: "stdin",
62 httpBaseUrl: new URL("http://127.0.0.1:3774"),
63 captureOutput: true,
64 preflightFailure: Option.none(),
65 runningDistro: "Ubuntu",
66};
67
68const defaultWslInstance: DesktopBackendManager.DesktopBackendInstance = {
69 id: DesktopBackendManager.BackendInstanceId("wsl:default"),
70 label: Effect.succeed("WSL (default distro)"),
71 start: Effect.void,
72 stop: () => Effect.void,
73 currentConfig: Effect.succeedSome(readyWslConfig),
74 snapshot: Effect.succeed({
75 desiredRunning: true,
76 ready: true,
77 activePid: Option.some(123),
78 restartAttempt: 0,
79 restartScheduled: false,
80 }),
81 waitForReady: () => Effect.succeed(true),
82};
83
84const backendConfigurationLayer = Layer.succeed(
85 DesktopBackendConfiguration.DesktopBackendConfiguration,
86 {
87 resolvePrimary: Effect.die("unexpected resolvePrimary"),
88 resolvePrimaryLabel: Effect.succeed("Windows"),
89 resolveWsl: () => Effect.die("unexpected resolveWsl"),
90 currentBootstrapToken: Effect.succeed("current-window-token"),
91 } satisfies DesktopBackendConfiguration.DesktopBackendConfiguration["Service"],
92);
93
94const bootstrapsLayer = (instances: ReadonlyArray<DesktopBackendManager.DesktopBackendInstance>) =>
95 Layer.merge(DesktopBackendPool.layerTest([...instances]), backendConfigurationLayer);
96
97describe("getLocalEnvironmentBootstraps", () => {
98 it.effect("hands out the current window's token to a backend launched with the secret", () =>
99 Effect.gen(function* () {
100 const result = yield* getLocalEnvironmentBootstraps.handler();
101
102 assert.deepEqual(result, [
103 {
104 id: "wsl:default",
105 label: "WSL (Ubuntu)",
106 runningDistro: "Ubuntu",
107 httpBaseUrl: "http://127.0.0.1:3774/",
108 wsBaseUrl: "ws://127.0.0.1:3774/",
109 bootstrapToken: "current-window-token",
110 },
111 ]);
112 }).pipe(
113 Effect.provide(
114 bootstrapsLayer([
115 {
116 ...defaultWslInstance,
117 currentConfig: Effect.succeedSome({
118 ...readyWslConfig,
119 bootstrap: {
120 ...readyWslConfig.bootstrap,
121 desktopBootstrapSecret: "desktop-secret",
122 },
123 }),
124 },
125 ]),
126 ),
127 ),
128 );
129
130 it.effect("publishes a pending bootstrap only while a transient retry is scheduled", () => {
131 const retryingConfig: DesktopBackendManager.DesktopBackendStartConfig = {
132 ...readyWslConfig,
133 preflightFailure: Option.some({
134 reason: "WSL probe timed out",
135 fatal: false,
136 retryLimit: 12,
137 }),
138 };
139 const retryingInstance: DesktopBackendManager.DesktopBackendInstance = {
140 ...defaultWslInstance,
141 currentConfig: Effect.succeedSome(retryingConfig),
142 snapshot: Effect.succeed({
143 desiredRunning: true,
144 ready: false,
145 activePid: Option.none(),
146 restartAttempt: 2,
147 restartScheduled: true,
148 }),
149 };
150
151 return Effect.gen(function* () {
152 const result = yield* getLocalEnvironmentBootstraps.handler();
153 assert.deepEqual(result, [
154 {
155 id: "wsl:default",
156 label: "WSL (default distro)",
157 runningDistro: null,
158 httpBaseUrl: null,
159 wsBaseUrl: null,
160 },
161 ]);
162 }).pipe(Effect.provide(bootstrapsLayer([retryingInstance])));
163 });
164
165 it.effect("omits a bounded transient bootstrap after retries stop", () => {
166 const stoppedInstance: DesktopBackendManager.DesktopBackendInstance = {
167 ...defaultWslInstance,
168 currentConfig: Effect.succeedSome({
169 ...readyWslConfig,
170 preflightFailure: Option.some({
171 reason: "WSL probe timed out",
172 fatal: false,
173 retryLimit: 12,
174 }),
175 }),
176 snapshot: Effect.succeed({
177 desiredRunning: false,
178 ready: false,
179 activePid: Option.none(),
180 restartAttempt: 12,
181 restartScheduled: false,
182 }),
183 };
184
185 return Effect.gen(function* () {
186 const result = yield* getLocalEnvironmentBootstraps.handler();
187 assert.deepEqual(result, []);
188 }).pipe(Effect.provide(bootstrapsLayer([stoppedInstance])));
189 });
190});
191
192describe("toLocalBackendPath", () => {
193 const { runningDistro: _, ...windowsConfig } = readyWslConfig;
194 it.effect("converts paths through wslpath only for backends running in WSL", () =>
195 Effect.gen(function* () {
196 const convert = (backendId: string, path = "C:\\Users\\me\\project") =>
197 toLocalBackendPath.handler({ backendId, path });
198 assert.strictEqual(yield* convert("primary"), "C:\\Users\\me\\project");
199 assert.strictEqual(yield* convert("wsl:default"), "/drives/c/Users/me/project");
200 assert.strictEqual(yield* convert("wsl:missing"), null);
201 assert.strictEqual(
202 yield* convert("wsl:default", "\\\\wsl.localhost\\ubuntu\\home\\me\\repo"),
203 "/home/me/repo",
204 );
205 assert.strictEqual(yield* convert("wsl:default", "\\\\wsl$\\Debian\\home\\me\\repo"), null);
206 assert.strictEqual(
207 yield* convert("primary", "\\\\wsl$\\Debian\\home\\me\\repo"),
208 "\\\\wsl$\\Debian\\home\\me\\repo",
209 );
210 }).pipe(
211 Effect.provide(
212 Layer.mergeAll(
213 DesktopBackendPool.layerTest([
214 {
215 ...defaultWslInstance,
216 id: DesktopBackendManager.BackendInstanceId("primary"),
217 currentConfig: Effect.succeedSome(windowsConfig),
218 },
219 defaultWslInstance,
220 ]),
221 DesktopWslEnvironment.layerTest({
222 windowsToWslPath: (distro, windowsPath) =>
223 distro === "Ubuntu" && windowsPath === "C:\\Users\\me\\project"
224 ? Option.some("/drives/c/Users/me/project")
225 : Option.none(),
226 }),
227 ),
228 ),
229 ),
230 );
231});
232
233describe("installRelayTelemetryEnabled", () => {
234 // The renderer reads this over sync IPC, so the answer must not wait on the filesystem.
235 const relayTelemetryEnabled = (
236 env: NodeJS.ProcessEnv,
237 policy?: Parameters<typeof DesktopManagedPolicy.layerTest>[0],
238 ) =>
239 Effect.gen(function* () {
240 const listeners = new Map<string, DesktopIpc.DesktopIpcSyncListener>();
241 const ipcMain: DesktopIpc.DesktopIpcMain = {
242 removeHandler: () => undefined,
243 handle: () => undefined,
244 removeAllListeners: (channel) => void listeners.delete(channel),
245 on: (channel, listener) => void listeners.set(channel, listener),
246 };
247 yield* installRelayTelemetryEnabled().pipe(
248 Effect.provideService(HostProcess.Environment, env),
249 Effect.provide(
250 Layer.mergeAll(DesktopIpc.layerTest(ipcMain), DesktopManagedPolicy.layerTest(policy)),
251 ),
252 );
253 const event = { returnValue: undefined as unknown };
254 listeners.get(IpcChannels.GET_RELAY_TELEMETRY_ENABLED_CHANNEL)?.(event as never);
255 return event.returnValue;
256 }).pipe(Effect.scoped);
257
258 it.effect("reads the desktop host opt-out before returning the renderer policy", () =>
259 Effect.gen(function* () {
260 assert.isFalse(yield* relayTelemetryEnabled({ T3CODE_TELEMETRY_ENABLED: "false" }));
261 assert.isTrue(yield* relayTelemetryEnabled({}));
262 }),
263 );
264
265 it.effect("turns relay tracing off when the managed policy turns telemetry off", () =>
266 Effect.gen(function* () {
267 const policy = (limits: ManagedPolicyLimits) => ({
268 schemaVersion: 1 as const,
269 organization: "Example Corp",
270 limits,
271 });
272 assert.isFalse(yield* relayTelemetryEnabled({}, policy({ telemetry: false })));
273 assert.isTrue(yield* relayTelemetryEnabled({}, policy({ webhookTasks: false })));
274 // A policy that cannot be read fails closed.
275 assert.isFalse(
276 yield* relayTelemetryEnabled(
277 {},
278 new ManagedPolicyFileError({ path: "/test", reason: "bad JSON" }),
279 ),
280 );
281 }),
282 );
283});
284
285describe("readMedia", () => {
286 it.effect("reads http(s) media only for the main window", () =>
287 Effect.gen(function* () {
288 const mib = new Uint8Array(1024 * 1024);
289 const fetch = vi.fn(async (url: string) => {
290 if (url.endsWith("/missing.png")) return new Response("Not Found", { status: 404 });
291 if (url.endsWith("/small.png")) return new Response(new Uint8Array([1, 2]));
292 let sent = 0;
293 // 257 MiB from one reused chunk: over the cap without allocating it.
294 const huge = new ReadableStream<Uint8Array>({
295 pull: (controller) => (sent++ < 257 ? controller.enqueue(mib) : controller.close()),
296 });
297 return new Response(huge);
298 });
299 const main = {
300 webContents: { id: 1, session: { fetch } },
301 } as unknown as Electron.BrowserWindow;
302 const read = (url: string, senderId: number) =>
303 readMedia
304 .handler(url, { sender: { id: senderId } })
305 .pipe(
306 Effect.provide(
307 Layer.mock(ElectronWindow.ElectronWindow)({ main: Effect.succeedSome(main) }),
308 ),
309 );
310
311 assert.strictEqual(yield* read("https://example.com/a.png", 2), null);
312 assert.strictEqual(yield* read("file:///etc/passwd", 1), null);
313 assert.strictEqual(fetch.mock.calls.length, 0);
314 assert.deepEqual(yield* read("https://example.com/small.png", 1), {
315 status: 200,
316 mimeType: "",
317 data: Buffer.from([1, 2]),
318 });
319 assert.deepEqual(yield* read("https://example.com/missing.png", 1), {
320 status: 404,
321 mimeType: "text/plain;charset=UTF-8",
322 data: new Uint8Array(),
323 });
324 assert.deepEqual(yield* read("https://example.com/huge.mp4", 1), {
325 status: 413,
326 mimeType: "",
327 data: new Uint8Array(),
328 });
329 }),
330 );
331});
332
333describe("pickProjectFavicon", () => {
334 const pickerLayer = (
335 pickFiles: () => Effect.Effect<Array<string>>,
336 settings?: DesktopAppSettings.DesktopSettings,
337 ) =>
338 Layer.mergeAll(
339 Layer.mock(ElectronDialog.ElectronDialog)({ pickFiles }),
340 Layer.mock(ElectronWindow.ElectronWindow)({
341 focusedMainOrFirst: Effect.succeedNone,
342 }),
343 DesktopAppSettings.layerTest(settings),
344 );
345
346 it.effect("opens a single-image picker from the project directory", () =>
347 Effect.gen(function* () {
348 const pickFiles = vi.fn(() => Effect.succeed(["/pictures/icon.png"]));
349 const result = yield* pickProjectFavicon
350 .handler("/project")
351 .pipe(Effect.provide(pickerLayer(pickFiles)));
352
353 assert.strictEqual(result, "/pictures/icon.png");
354 assert.deepEqual(pickFiles.mock.calls, [
355 [
356 {
357 owner: Option.none(),
358 defaultPath: Option.some("/project"),
359 multiple: false,
360 filters: [
361 {
362 name: "Images",
363 extensions: [
364 "avif",
365 "bmp",
366 "gif",
367 "ico",
368 "heic",
369 "heif",
370 "jpeg",
371 "jpg",
372 "png",
373 "svg",
374 "tif",
375 "tiff",
376 "webp",
377 "icns",
378 ],
379 },
380 ],
381 },
382 ],
383 ]);
384 }),
385 );
386
387 it.effect("does not open a picker while the local environment is off", () =>
388 Effect.gen(function* () {
389 const pickFiles = vi.fn(() => Effect.succeed(["/pictures/icon.png"]));
390 const result = yield* pickProjectFavicon.handler("/project").pipe(
391 Effect.provide(
392 pickerLayer(pickFiles, {
393 ...DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,
394 localEnvironmentEnabled: false,
395 }),
396 ),
397 );
398
399 assert.strictEqual(result, null);
400 assert.strictEqual(pickFiles.mock.calls.length, 0);
401 }),
402 );
403});
404
405describe("syncHtmlFullscreen", () => {
406 const fullscreenWindow = (fullscreen: boolean, { animatedExit = false } = {}) => {
407 let current = fullscreen;
408 let exiting = false;
409 const queued: boolean[] = [];
410 const leaveListeners: Array<() => void> = [];
411 const leave = () => {
412 current = false;
413 for (const listener of leaveListeners) listener();
414 };
415 // Like macOS, an animated exit keeps reporting fullscreen and queues requests until it ends.
416 const setFullScreen = vi.fn((next: boolean) => {
417 if (exiting) queued.push(next);
418 else if (next) current = true;
419 else if (!current) return;
420 else if (animatedExit) exiting = true;
421 else leave();
422 });
423 const finishExit = () => {
424 exiting = false;
425 leave();
426 for (const next of queued.splice(0)) setFullScreen(next);
427 };
428 const window = {
429 webContents: { id: 1 },
430 isDestroyed: () => false,
431 isFullScreen: () => current,
432 setFullScreen,
433 on: (event: string, listener: () => void) => {
434 if (event === "leave-full-screen") leaveListeners.push(listener);
435 },
436 } as unknown as Electron.BrowserWindow;
437 const layer = Layer.mock(ElectronWindow.ElectronWindow)({ main: Effect.succeedSome(window) });
438 return { window, setFullScreen, finishExit, layer };
439 };
440 const fromMainRenderer = { sender: { id: 1 } };
441
442 it.effect("takes the screen for the app's own fullscreen element and gives it back", () => {
443 const { window, layer } = fullscreenWindow(false);
444 return Effect.gen(function* () {
445 yield* syncHtmlFullscreen.handler(true, fromMainRenderer);
446 assert.isTrue(window.isFullScreen());
447
448 yield* syncHtmlFullscreen.handler(false, fromMainRenderer);
449 assert.isFalse(window.isFullScreen());
450 }).pipe(Effect.provide(layer));
451 });
452
453 it.effect("keeps a window the user had already made fullscreen", () => {
454 const { window, setFullScreen, layer } = fullscreenWindow(true);
455 return Effect.gen(function* () {
456 yield* syncHtmlFullscreen.handler(true, fromMainRenderer);
457 yield* syncHtmlFullscreen.handler(false, fromMainRenderer);
458
459 assert.isTrue(window.isFullScreen());
460 assert.strictEqual(setFullScreen.mock.calls.length, 0);
461 }).pipe(Effect.provide(layer));
462 });
463
464 it.effect("hands the window back once the user leaves OS fullscreen during playback", () => {
465 const { window, layer } = fullscreenWindow(false);
466 return Effect.gen(function* () {
467 yield* syncHtmlFullscreen.handler(true, fromMainRenderer);
468 window.setFullScreen(false);
469 window.setFullScreen(true);
470 yield* syncHtmlFullscreen.handler(false, fromMainRenderer);
471
472 assert.isTrue(window.isFullScreen());
473 }).pipe(Effect.provide(layer));
474 });
475
476 it.effect("takes the screen again when the video returns during an animated exit", () => {
477 const { window, finishExit, layer } = fullscreenWindow(false, { animatedExit: true });
478 return Effect.gen(function* () {
479 yield* syncHtmlFullscreen.handler(true, fromMainRenderer);
480 yield* syncHtmlFullscreen.handler(false, fromMainRenderer);
481 yield* syncHtmlFullscreen.handler(true, fromMainRenderer);
482 finishExit();
483 assert.isTrue(window.isFullScreen());
484
485 yield* syncHtmlFullscreen.handler(false, fromMainRenderer);
486 finishExit();
487 assert.isFalse(window.isFullScreen());
488 }).pipe(Effect.provide(layer));
489 });
490});
491
492it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
493 "finds remote editors installed without PATH launchers",
494 () =>
495 Effect.gen(function* () {
496 const fs = yield* FileSystem.FileSystem;
497 const path = yield* Path.Path;
498 const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-remote-editors-" });
499 for (const app of ["Cursor", "Visual Studio Code", "WebStorm"]) {
500 const executable = path.join(
501 home,
502 "Applications",
503 `${app}.app`,
504 app === "WebStorm" ? "Contents/MacOS/webstorm" : "Contents/Resources/app/bin/code",
505 );
506 yield* fs.makeDirectory(path.dirname(executable), { recursive: true });
507 yield* fs.writeFileString(executable, "#!/bin/sh\n");
508 yield* fs.chmod(executable, 0o755);
509 }
510 const editors = yield* probeRemoteEditors.handler(undefined).pipe(
511 Effect.provideService(HostProcess.Environment, {
512 HOME: home,
513 PATH: path.join(home, "empty"),
514 }),
515 Effect.provideService(HostProcess.Platform, "darwin"),
516 );
517 assert.include(editors, "cursor");
518 assert.include(editors, "vscode");
519 assert.include(editors, "webstorm");
520 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
521);
522
523describe("probeRemoteEditors PATH scan", () => {
524 const platform = HostProcess.Platform.defaultValue();
525 const launcherName = (command: string) => (platform === "win32" ? `${command}.cmd` : command);
526
527 const makeFakePath = Effect.fnUntraced(function* () {
528 const fs = yield* FileSystem.FileSystem;
529 const path = yield* Path.Path;
530 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-probe-path-" });
531 const dirs = ["a", "b", "c", "d"].map((name) => path.join(root, name));
532 for (const dir of dirs) yield* fs.makeDirectory(dir, { recursive: true });
533 // Launchers in different PATH directories, deliberately not in REMOTE_CAPABLE_EDITOR_IDS order.
534 for (const [dir, command] of [
535 [dirs[2]!, "webstorm"],
536 [dirs[0]!, "cursor"],
537 [dirs[3]!, "code"],
538 [dirs[1]!, "zeditor"],
539 ] as const) {
540 const file = path.join(dir, launcherName(command));
541 yield* fs.writeFileString(file, "#!/bin/sh\n");
542 if (platform !== "win32") yield* fs.chmod(file, 0o755);
543 }
544 return {
545 root,
546 env: {
547 HOME: root,
548 USERPROFILE: root,
549 PATH: dirs.join(platform === "win32" ? ";" : ":"),
550 PATHEXT: ".COM;.EXE;.BAT;.CMD",
551 },
552 };
553 });
554
555 const countingFileSystem = (counter: { stat: number; reads: Map<string, number> }) =>
556 Layer.effect(
557 FileSystem.FileSystem,
558 Effect.gen(function* () {
559 const fs = yield* FileSystem.FileSystem;
560 return FileSystem.FileSystem.of({
561 ...fs,
562 stat: (target) => {
563 counter.stat += 1;
564 return fs.stat(target);
565 },
566 readDirectory: (target, options) => {
567 counter.reads.set(target, (counter.reads.get(target) ?? 0) + 1);
568 return fs.readDirectory(target, options);
569 },
570 });
571 }),
572 ).pipe(Layer.provideMerge(NodeServices.layer));
573
574 const serialReference = (env: Record<string, string>) =>
575 Effect.gen(function* () {
576 const available: Array<string> = [];
577 for (const editorId of REMOTE_CAPABLE_EDITOR_IDS) {
578 const editor = EDITORS.find((candidate) => candidate.id === editorId);
579 if (editor && Option.isSome(yield* resolveEditorCommand(editor, env))) {
580 available.push(editorId);
581 }
582 }
583 return available;
584 });
585
586 it.effect("reads each PATH directory once instead of stat-ing every candidate per editor", () =>
587 Effect.gen(function* () {
588 const { env: baseEnv } = yield* makeFakePath();
589 const delimiter = platform === "win32" ? ";" : ":";
590 const uncachedCounter = { stat: 0, reads: new Map<string, number>() };
591 const cachedCounter = { stat: 0, reads: new Map<string, number>() };
592 const uncachedEnv = { ...baseEnv, PATH: `${baseEnv.PATH}${delimiter}${baseEnv.HOME}x1` };
593 const cachedEnv = { ...baseEnv, PATH: `${baseEnv.PATH}${delimiter}${baseEnv.HOME}x2` };
594 const uncached = yield* serialReference(uncachedEnv).pipe(
595 Effect.provide(countingFileSystem(uncachedCounter)),
596 );
597 const cached = yield* probeRemoteEditors
598 .handler(undefined)
599 .pipe(
600 Effect.provideService(HostProcess.Environment, cachedEnv),
601 Effect.provideService(HostProcess.Platform, platform),
602 Effect.provide(countingFileSystem(cachedCounter)),
603 );
604 // The host can add editors from app folders the fixture can't redirect (e.g. /Applications).
605 const fixtureEditors = ["cursor", "vscode", "zed", "webstorm"];
606 assert.deepStrictEqual(
607 uncached.filter((id) => fixtureEditors.includes(id)),
608 fixtureEditors,
609 );
610 assert.deepStrictEqual(cached, uncached);
611 assert.isAbove(uncachedCounter.stat, 0);
612 // On every platform the probe lists each PATH directory at most once. Only PATH entries count:
613 // resolveEditorCommand also reads app folders such as /Applications on macOS.
614 const pathReads = cachedEnv.PATH.split(delimiter)
615 .filter((entry) => entry.length > 0)
616 .map((entry) => cachedCounter.reads.get(entry) ?? 0);
617 assert.isAbove(Math.max(...pathReads), 0);
618 assert.isAtMost(Math.max(...pathReads), 1);
619 // Without the listings, Windows stats every PATH entry x PATHEXT candidate for each editor;
620 // elsewhere there is no PATHEXT, so the stat count is about the same either way.
621 if (platform === "win32") {
622 assert.isBelow(cachedCounter.stat, uncachedCounter.stat / 2);
623 }
624 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
625 );
626});