Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, describe, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import * as Logger from "effect/Logger";
6import * as PlatformError from "effect/PlatformError";
7import * as Schema from "effect/Schema";
8import * as Sink from "effect/Sink";
9import * as Stream from "effect/Stream";
10import * as ChildProcess from "effect/process/ChildProcess";
11import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
12import * as NodeOS from "node:os";
13import { vi } from "vite-plus/test";
14
15import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
16import * as DesktopPreReadyPlatform from "../app/DesktopPreReadyPlatform.ts";
17import * as DesktopShellEnvironment from "./DesktopShellEnvironment.ts";
18
19vi.mock("node:os", { spy: true });
20const { appendSwitch, removeSwitch } = vi.hoisted(() => ({
21 appendSwitch: vi.fn(),
22 removeSwitch: vi.fn(),
23}));
24vi.mock("electron", () => ({
25 app: { commandLine: { appendSwitch, removeSwitch } },
26}));
27
28const textEncoder = new TextEncoder();
29
30const isDesktopShellEnvironmentCommandError = Schema.is(
31 DesktopShellEnvironment.DesktopShellEnvironmentCommandError,
32);
33
34function envOutput(values: Readonly<Record<string, string>>): string {
35 return Object.entries(values)
36 .flatMap(([name, value]) => [
37 `__T3CODE_ENV_${name}_START__`,
38 value,
39 `__T3CODE_ENV_${name}_END__`,
40 ])
41 .join("\n");
42}
43
44function makeProcess(output: string, exitCode = 0): ChildProcessSpawner.ChildProcessHandle {
45 const stdout = output.length === 0 ? Stream.empty : Stream.make(textEncoder.encode(output));
46 return ChildProcessSpawner.makeHandle({
47 pid: ChildProcessSpawner.ProcessId(123),
48 stdout,
49 stderr: Stream.empty,
50 all: stdout,
51 exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)),
52 isRunning: Effect.succeed(false),
53 kill: () => Effect.void,
54 stdin: Sink.drain,
55 getInputFd: () => Sink.drain,
56 getOutputFd: () => Stream.empty,
57 unref: Effect.succeed(Effect.void),
58 });
59}
60
61function withProcessEnv<A, E, R>(
62 env: NodeJS.ProcessEnv,
63 effect: Effect.Effect<A, E, R>,
64): Effect.Effect<A, E, R> {
65 return Effect.acquireUseRelease(
66 Effect.sync(() => {
67 const previous = process.env;
68 process.env = env;
69 return previous;
70 }),
71 () => effect,
72 (previous) =>
73 Effect.sync(() => {
74 process.env = previous;
75 }),
76 );
77}
78
79function runShellEnvironment(input: {
80 readonly env: NodeJS.ProcessEnv;
81 readonly platform: NodeJS.Platform;
82 readonly userShell?: string;
83 readonly handler: (
84 command: ChildProcess.Command,
85 ) => string | { output: string; exitCode: number };
86 readonly failure?: PlatformError.PlatformError;
87 readonly secretStorage?: boolean;
88 readonly passwordStoreCommandLine?: string;
89}) {
90 const layerEnvironment = Layer.succeed(
91 DesktopEnvironment.DesktopEnvironment,
92 DesktopEnvironment.DesktopEnvironment.of({
93 platform: input.platform,
94 } as DesktopEnvironment.DesktopEnvironment["Service"]),
95 );
96 const layerSpawner = Layer.succeed(
97 ChildProcessSpawner.ChildProcessSpawner,
98 ChildProcessSpawner.make((command) => {
99 if (input.failure !== undefined) return Effect.fail(input.failure);
100 const result = input.handler(command);
101 return Effect.succeed(
102 typeof result === "string"
103 ? makeProcess(result)
104 : makeProcess(result.output, result.exitCode),
105 );
106 }),
107 );
108
109 const program = Effect.gen(function* () {
110 const shellEnvironment = yield* DesktopShellEnvironment.DesktopShellEnvironment;
111 if (input.secretStorage) {
112 yield* shellEnvironment.secretStorageReady;
113 yield* shellEnvironment.secretStorageReady;
114 }
115 const prepared = yield* shellEnvironment.installIntoProcess;
116 assert.equal(yield* shellEnvironment.installIntoProcess, prepared);
117 return prepared;
118 }).pipe(
119 Effect.provide(
120 DesktopShellEnvironment.layer.pipe(
121 Layer.provide(
122 Layer.mergeAll(
123 layerEnvironment,
124 NodeServices.layer,
125 layerSpawner,
126 Layer.succeed(DesktopPreReadyPlatform.DesktopPreReadyElectronOptions, {
127 linux: null,
128 linuxPasswordStoreCommandLine: input.passwordStoreCommandLine ?? null,
129 }),
130 ),
131 ),
132 ),
133 ),
134 );
135
136 return Effect.acquireUseRelease(
137 Effect.sync(() =>
138 vi.spyOn(NodeOS, "userInfo").mockReturnValue({
139 ...NodeOS.userInfo(),
140 shell: input.userShell ?? null,
141 }),
142 ),
143 () => withProcessEnv(input.env, program),
144 (spy) => Effect.sync(() => spy.mockRestore()),
145 );
146}
147
148describe("DesktopShellEnvironment", () => {
149 it.effect.each([
150 { bus: undefined, label: "missing" },
151 { bus: "unix:path=/tmp/stale-bus", label: "stale" },
152 ])("selects secret storage after shell hydration with a $label bus", ({ bus }) => {
153 appendSwitch.mockClear();
154 removeSwitch.mockClear();
155 const env = {
156 PATH: "/usr/bin",
157 DBUS_SESSION_BUS_ADDRESS: bus,
158 XDG_CURRENT_DESKTOP: "GNOME",
159 };
160 return runShellEnvironment({
161 env,
162 platform: "linux",
163 secretStorage: true,
164 handler: () =>
165 envOutput({
166 PATH: "/usr/bin",
167 DBUS_SESSION_BUS_ADDRESS: "unix:path=/tmp/hydrated-bus",
168 XDG_CURRENT_DESKTOP: "LXQt",
169 }),
170 }).pipe(
171 Effect.map(() => {
172 assert.equal(env.DBUS_SESSION_BUS_ADDRESS, "unix:path=/tmp/hydrated-bus");
173 assert.deepEqual(removeSwitch.mock.calls, [["password-store"]]);
174 assert.deepEqual(appendSwitch.mock.calls, [["password-store", "gnome-libsecret"]]);
175 }),
176 );
177 });
178
179 it.effect("preserves an explicit password-store after shell hydration", () => {
180 appendSwitch.mockClear();
181 removeSwitch.mockClear();
182 return runShellEnvironment({
183 env: { PATH: "/usr/bin", DBUS_SESSION_BUS_ADDRESS: "unix:path=/tmp/stale-bus" },
184 platform: "linux",
185 secretStorage: true,
186 passwordStoreCommandLine: "basic",
187 handler: () => envOutput({ PATH: "/usr/bin", XDG_CURRENT_DESKTOP: "LXQt" }),
188 }).pipe(
189 Effect.map(() => {
190 assert.deepEqual(removeSwitch.mock.calls, []);
191 assert.deepEqual(appendSwitch.mock.calls, []);
192 }),
193 );
194 });
195
196 it.effect("rejects PATH output from a failed shell and tries the next candidate", () =>
197 Effect.gen(function* () {
198 const env: NodeJS.ProcessEnv = { SHELL: "/bin/failing", PATH: "/usr/bin" };
199 const commands: string[] = [];
200
201 yield* runShellEnvironment({
202 env,
203 platform: "linux",
204 userShell: "/usr/local/bin/fish",
205 handler: (command) => {
206 if (command._tag !== "StandardCommand") return "";
207 commands.push(command.command);
208 return command.command === "/bin/failing"
209 ? { output: envOutput({ PATH: "/failed/bin" }), exitCode: 7 }
210 : envOutput({ PATH: "/home/test/.local/bin:/usr/bin" });
211 },
212 }).pipe(Effect.provide(Logger.layer([])));
213
214 assert.deepEqual(commands, ["/bin/failing", "/usr/local/bin/fish"]);
215 assert.equal(env.PATH, "/home/test/.local/bin:/usr/bin");
216 }),
217 );
218
219 it.effect.each(["darwin", "linux"] as const)(
220 "uses the account shell when SHELL is missing on %s",
221 (platform) =>
222 Effect.gen(function* () {
223 const env: NodeJS.ProcessEnv = { PATH: "/usr/bin" };
224 const commands: string[] = [];
225
226 yield* runShellEnvironment({
227 env,
228 platform,
229 userShell: "/usr/local/bin/fish",
230 handler: (command) => {
231 if (command._tag !== "StandardCommand") return "";
232 commands.push(command.command);
233 return envOutput({ PATH: "/home/test/.local/bin:/usr/bin" });
234 },
235 });
236
237 assert.deepEqual(commands, ["/usr/local/bin/fish"]);
238 assert.equal(env.PATH, "/home/test/.local/bin:/usr/bin");
239 }),
240 );
241
242 it.effect("tries the account shell before the platform fallback when SHELL has no PATH", () =>
243 Effect.gen(function* () {
244 const env: NodeJS.ProcessEnv = { SHELL: "/bin/missing", PATH: "/usr/bin" };
245 const commands: string[] = [];
246
247 yield* runShellEnvironment({
248 env,
249 platform: "linux",
250 userShell: "/usr/local/bin/fish",
251 handler: (command) => {
252 if (command._tag !== "StandardCommand") return "";
253 commands.push(command.command);
254 return command.command === "/usr/local/bin/fish"
255 ? envOutput({ PATH: "/home/test/.local/bin:/usr/bin" })
256 : "";
257 },
258 });
259
260 assert.deepEqual(commands, ["/bin/missing", "/usr/local/bin/fish"]);
261 assert.equal(env.PATH, "/home/test/.local/bin:/usr/bin");
262 }),
263 );
264
265 it.effect("hydrates PATH and missing SSH_AUTH_SOCK from the login shell on macOS", () =>
266 Effect.gen(function* () {
267 const env: NodeJS.ProcessEnv = {
268 SHELL: "/bin/zsh",
269 PATH: "/Users/test/.local/bin:/usr/bin",
270 };
271 const commands: ChildProcess.Command[] = [];
272
273 yield* runShellEnvironment({
274 env,
275 platform: "darwin",
276 handler: (command) => {
277 commands.push(command);
278 return envOutput({
279 PATH: "/opt/homebrew/bin:/usr/bin",
280 SSH_AUTH_SOCK: "/tmp/secretive.sock",
281 HOMEBREW_PREFIX: "/opt/homebrew",
282 });
283 },
284 });
285
286 assert.equal(commands.length, 1);
287 assert.equal(commands[0]?._tag === "StandardCommand" ? commands[0].command : "", "/bin/zsh");
288 assert.equal(env.PATH, "/opt/homebrew/bin:/usr/bin:/Users/test/.local/bin");
289 assert.equal(env.SSH_AUTH_SOCK, "/tmp/secretive.sock");
290 assert.equal(env.HOMEBREW_PREFIX, "/opt/homebrew");
291 }),
292 );
293
294 it.effect("preserves inherited POSIX values when present", () =>
295 Effect.gen(function* () {
296 const env: NodeJS.ProcessEnv = {
297 SHELL: "/bin/zsh",
298 PATH: "/usr/bin",
299 SSH_AUTH_SOCK: "/tmp/inherited.sock",
300 };
301
302 yield* runShellEnvironment({
303 env,
304 platform: "darwin",
305 handler: () =>
306 envOutput({
307 PATH: "/opt/homebrew/bin:/usr/bin",
308 SSH_AUTH_SOCK: "/tmp/login-shell.sock",
309 }),
310 });
311
312 assert.equal(env.PATH, "/opt/homebrew/bin:/usr/bin");
313 assert.equal(env.SSH_AUTH_SOCK, "/tmp/inherited.sock");
314 }),
315 );
316
317 it.effect("hydrates the locale from the login shell on macOS", () =>
318 Effect.gen(function* () {
319 const env: NodeJS.ProcessEnv = {
320 SHELL: "/bin/zsh",
321 PATH: "/usr/bin",
322 };
323
324 yield* runShellEnvironment({
325 env,
326 platform: "darwin",
327 handler: () =>
328 envOutput({
329 PATH: "/opt/homebrew/bin:/usr/bin",
330 LANG: "de_DE.UTF-8",
331 }),
332 });
333
334 assert.equal(env.LANG, "de_DE.UTF-8");
335 }),
336 );
337
338 it.effect("preserves an inherited locale over the login shell on macOS", () =>
339 Effect.gen(function* () {
340 const env: NodeJS.ProcessEnv = {
341 SHELL: "/bin/zsh",
342 PATH: "/usr/bin",
343 LANG: "en_US.UTF-8",
344 };
345
346 yield* runShellEnvironment({
347 env,
348 platform: "darwin",
349 handler: () =>
350 envOutput({
351 PATH: "/opt/homebrew/bin:/usr/bin",
352 LANG: "de_DE.UTF-8",
353 }),
354 });
355
356 assert.equal(env.LANG, "en_US.UTF-8");
357 }),
358 );
359
360 it.effect("does not mix login-shell locale categories into an inherited locale", () =>
361 Effect.gen(function* () {
362 const env: NodeJS.ProcessEnv = {
363 SHELL: "/bin/zsh",
364 PATH: "/usr/bin",
365 LANG: "en_US.UTF-8",
366 };
367
368 yield* runShellEnvironment({
369 env,
370 platform: "darwin",
371 handler: () =>
372 envOutput({
373 PATH: "/opt/homebrew/bin:/usr/bin",
374 LC_ALL: "de_DE.UTF-8",
375 }),
376 });
377
378 assert.equal(env.LANG, "en_US.UTF-8");
379 assert.equal(env.LC_ALL, undefined);
380 }),
381 );
382
383 it.effect("falls back to a UTF-8 LC_CTYPE when no locale is available on macOS", () =>
384 Effect.gen(function* () {
385 const env: NodeJS.ProcessEnv = {
386 SHELL: "/bin/zsh",
387 PATH: "/usr/bin",
388 };
389
390 yield* runShellEnvironment({
391 env,
392 platform: "darwin",
393 handler: () => envOutput({ PATH: "/opt/homebrew/bin:/usr/bin" }),
394 });
395
396 assert.equal(env.LANG, undefined);
397 assert.equal(env.LC_ALL, undefined);
398 assert.equal(env.LC_CTYPE, "en_US.UTF-8");
399 }),
400 );
401
402 it.effect("does not apply the locale fallback on linux", () =>
403 Effect.gen(function* () {
404 const env: NodeJS.ProcessEnv = {
405 SHELL: "/bin/zsh",
406 PATH: "/usr/bin",
407 };
408
409 yield* runShellEnvironment({
410 env,
411 platform: "linux",
412 handler: () => envOutput({ PATH: "/home/linuxbrew/.linuxbrew/bin:/usr/bin" }),
413 });
414
415 assert.equal(env.LANG, undefined);
416 }),
417 );
418
419 it.effect("hydrates PATH and missing SSH_AUTH_SOCK from the login shell on linux", () =>
420 Effect.gen(function* () {
421 const env: NodeJS.ProcessEnv = {
422 SHELL: "/bin/zsh",
423 PATH: "/usr/bin",
424 };
425
426 yield* runShellEnvironment({
427 env,
428 platform: "linux",
429 handler: () =>
430 envOutput({
431 PATH: "/home/linuxbrew/.linuxbrew/bin:/usr/bin",
432 SSH_AUTH_SOCK: "/tmp/secretive.sock",
433 T3CODE_TELEMETRY_ENABLED: "false",
434 }),
435 });
436
437 assert.equal(env.PATH, "/home/linuxbrew/.linuxbrew/bin:/usr/bin");
438 assert.equal(env.SSH_AUTH_SOCK, "/tmp/secretive.sock");
439 assert.equal(env.T3CODE_TELEMETRY_ENABLED, "false");
440 }),
441 );
442
443 it.effect("hydrates missing CA trust variables from the login shell", () =>
444 Effect.gen(function* () {
445 const env: NodeJS.ProcessEnv = {
446 SHELL: "/bin/zsh",
447 PATH: "/usr/bin",
448 SSL_CERT_DIR: "/etc/ssl/certs",
449 };
450
451 yield* runShellEnvironment({
452 env,
453 platform: "darwin",
454 handler: () =>
455 envOutput({
456 PATH: "/opt/zerobrew/bin:/usr/bin",
457 SSL_CERT_FILE: "/opt/zerobrew/etc/ca-certificates/cacert.pem",
458 SSL_CERT_DIR: "/opt/zerobrew/etc/ca-certificates",
459 NODE_EXTRA_CA_CERTS: "/Users/me/corp-root.pem",
460 }),
461 });
462
463 assert.equal(env.SSL_CERT_FILE, "/opt/zerobrew/etc/ca-certificates/cacert.pem");
464 assert.equal(env.SSL_CERT_DIR, "/etc/ssl/certs");
465 assert.equal(env.NODE_EXTRA_CA_CERTS, "/Users/me/corp-root.pem");
466 }),
467 );
468
469 it.effect("keeps mise's PATH record with the login shell PATH", () =>
470 Effect.gen(function* () {
471 const env: NodeJS.ProcessEnv = {
472 SHELL: "/bin/bash",
473 PATH: "/usr/bin",
474 };
475
476 yield* runShellEnvironment({
477 env,
478 platform: "linux",
479 handler: () =>
480 envOutput({
481 PATH: "/home/me/.local/bin:/mise/installs/claude/latest:/mise/shims",
482 __MISE_DIFF: "mise-diff",
483 }),
484 });
485
486 assert.equal(env.__MISE_DIFF, "mise-diff");
487 }),
488 );
489
490 it.effect("falls back to launchctl PATH on macOS when shell probing does not return one", () =>
491 Effect.gen(function* () {
492 const env: NodeJS.ProcessEnv = {
493 SHELL: "/opt/homebrew/bin/nu",
494 PATH: "/usr/bin",
495 };
496 const commands: string[] = [];
497
498 yield* runShellEnvironment({
499 env,
500 platform: "darwin",
501 handler: (command) => {
502 if (command._tag !== "StandardCommand") return "";
503 commands.push(command.command);
504 return command.command === "/bin/launchctl" ? "/opt/homebrew/bin:/usr/bin" : "";
505 },
506 });
507
508 assert.deepEqual(commands, ["/opt/homebrew/bin/nu", "/bin/zsh", "/bin/launchctl"]);
509 assert.equal(env.PATH, "/opt/homebrew/bin:/usr/bin");
510 }),
511 );
512
513 it.effect("loads PowerShell profile environment on Windows", () =>
514 Effect.gen(function* () {
515 const env: NodeJS.ProcessEnv = {
516 PATH: "C:\\Windows\\System32",
517 APPDATA: "C:\\Users\\testuser\\AppData\\Roaming",
518 LOCALAPPDATA: "C:\\Users\\testuser\\AppData\\Local",
519 USERPROFILE: "C:\\Users\\testuser",
520 };
521
522 const prepared = yield* runShellEnvironment({
523 env,
524 platform: "win32",
525 handler: (command) => {
526 if (command._tag !== "StandardCommand") return "";
527 const loadProfile = !command.args.includes("-NoProfile");
528 return loadProfile
529 ? envOutput({
530 PATH: "C:\\Profile\\Node;C:\\Windows\\System32",
531 FNM_DIR: "C:\\Users\\testuser\\AppData\\Roaming\\fnm",
532 FNM_MULTISHELL_PATH: "C:\\Users\\testuser\\AppData\\Local\\fnm_multishells\\123",
533 })
534 : envOutput({ PATH: 'C:\\Custom\\Bin;C:";C:\\Windows\\System32' });
535 },
536 });
537
538 assert.isTrue(prepared);
539 assert.equal(
540 env.PATH,
541 [
542 "C:\\Profile\\Node",
543 "C:\\Windows\\System32",
544 "C:\\Users\\testuser\\AppData\\Roaming\\npm",
545 "C:\\Users\\testuser\\AppData\\Local\\Programs\\nodejs",
546 "C:\\Users\\testuser\\AppData\\Local\\Volta\\bin",
547 "C:\\Users\\testuser\\AppData\\Local\\pnpm",
548 "C:\\Users\\testuser\\.local\\bin",
549 "C:\\Users\\testuser\\.bun\\bin",
550 "C:\\Users\\testuser\\scoop\\shims",
551 "C:\\Custom\\Bin",
552 "C:",
553 ].join(";"),
554 );
555 assert.equal(env.FNM_DIR, "C:\\Users\\testuser\\AppData\\Roaming\\fnm");
556 assert.equal(
557 env.FNM_MULTISHELL_PATH,
558 "C:\\Users\\testuser\\AppData\\Local\\fnm_multishells\\123",
559 );
560 }),
561 );
562
563 it.effect.each([false, true])(
564 "leaves Windows preparation incomplete when loadProfile=%s fails",
565 (loadProfile) =>
566 Effect.gen(function* () {
567 const env: NodeJS.ProcessEnv = { PATH: "C:\\Windows\\System32" };
568 let calls = 0;
569 const prepared = yield* runShellEnvironment({
570 env,
571 platform: "win32",
572 handler: (command) => {
573 calls++;
574 if (command._tag !== "StandardCommand") return "";
575 return !command.args.includes("-NoProfile") === loadProfile
576 ? { output: "", exitCode: 1 }
577 : envOutput({ PATH: "C:\\Working" });
578 },
579 }).pipe(Effect.provide(Logger.layer([])));
580 assert.isFalse(prepared);
581 assert.equal(calls, 3);
582 assert.include(env.PATH, "C:\\Working");
583 assert.include(env.PATH, "C:\\Windows\\System32");
584 }),
585 );
586
587 it.effect("replaces a Path-spelled Windows PATH instead of adding a second key", () =>
588 Effect.gen(function* () {
589 const env: NodeJS.ProcessEnv = { Path: "C:\\Windows\\System32" };
590
591 yield* runShellEnvironment({
592 env,
593 platform: "win32",
594 handler: (command) =>
595 command._tag === "StandardCommand" && command.args.includes("-NoProfile")
596 ? envOutput({ PATH: "C:\\Shell\\Bin" })
597 : "",
598 });
599
600 assert.deepEqual(env, { PATH: "C:\\Shell\\Bin;C:\\Windows\\System32" });
601 }),
602 );
603
604 it.effect("prefers login-shell desktop session hints over inherited values on linux", () =>
605 Effect.gen(function* () {
606 const env: NodeJS.ProcessEnv = {
607 SHELL: "/bin/zsh",
608 PATH: "/usr/bin",
609 XDG_CURRENT_DESKTOP: "wrong-launcher",
610 XDG_SESSION_DESKTOP: "wrong-launcher",
611 };
612
613 yield* runShellEnvironment({
614 env,
615 platform: "linux",
616 handler: () =>
617 envOutput({
618 PATH: "/home/linuxbrew/.linuxbrew/bin:/usr/bin",
619 XDG_CURRENT_DESKTOP: "KDE",
620 XDG_SESSION_DESKTOP: "KDE",
621 XDG_SESSION_TYPE: "wayland",
622 }),
623 });
624
625 assert.equal(env.XDG_CURRENT_DESKTOP, "KDE");
626 assert.equal(env.XDG_SESSION_DESKTOP, "KDE");
627 assert.equal(env.XDG_SESSION_TYPE, "wayland");
628 }),
629 );
630
631 it.effect("overrides stale dbus session addresses from the login shell", () =>
632 Effect.gen(function* () {
633 const env: NodeJS.ProcessEnv = {
634 SHELL: "/bin/zsh",
635 PATH: "/usr/bin",
636 DBUS_SESSION_BUS_ADDRESS: "unix:path=/tmp/stale-bus",
637 };
638
639 yield* runShellEnvironment({
640 env,
641 platform: "linux",
642 handler: () =>
643 envOutput({
644 PATH: "/usr/bin",
645 DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/1000/bus",
646 }),
647 });
648
649 assert.equal(env.DBUS_SESSION_BUS_ADDRESS, "unix:path=/run/user/1000/bus");
650 }),
651 );
652
653 it.effect("logs command failures with safe probe context and the exact cause", () => {
654 const env: NodeJS.ProcessEnv = {
655 SHELL: "/bin/bash",
656 PATH: "/usr/bin",
657 };
658 const cause = PlatformError.systemError({
659 _tag: "PermissionDenied",
660 module: "ChildProcess",
661 method: "spawn",
662 pathOrDescriptor: "/bin/bash",
663 });
664 const messages: Array<unknown> = [];
665 const logger = Logger.make(({ message }) => {
666 messages.push(message);
667 });
668
669 return runShellEnvironment({
670 env,
671 platform: "linux",
672 handler: () => "",
673 failure: cause,
674 }).pipe(
675 Effect.andThen(
676 Effect.sync(() => {
677 const errors = messages
678 .flatMap((message) => (Array.isArray(message) ? message : [message]))
679 .filter(isDesktopShellEnvironmentCommandError);
680 assert.lengthOf(errors, 1);
681 assert.equal(errors[0]?.probe, "login-shell");
682 assert.equal(errors[0]?.executable, "bash");
683 assert.equal(errors[0]?.argumentCount, 2);
684 assert.notProperty(errors[0] ?? {}, "args");
685 assert.equal(errors[0]?.cause, cause);
686 assert.notInclude(errors[0]?.message ?? "", cause.message);
687 }),
688 ),
689 Effect.provide(Logger.layer([logger], { mergeWithExisting: false })),
690 );
691 });
692});