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