Skip to content
TypeScript

fix(desktop): keep noisy shell probes from blocking PATH capture (#21913)

Simone0b75a852d8fe
diff --git a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts
index 48048230690..33325d9de99 100644
--- a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts
+++ b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts
@@ -1,6 +1,7 @@
// @effect-diagnostics nodeBuiltinImport:off -- The process fixture runs real shell commands with isolated config files.
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, describe, it } from "@effect/vitest";
+import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Logger from "effect/Logger";
@@ -72,6 +73,7 @@ function runShellEnvironment(input: {
command: ChildProcess.Command,
) => string | { output: string; exitCode: number };
readonly failure?: PlatformError.PlatformError;
+ readonly processSpawner?: ChildProcessSpawner.ChildProcessSpawner["Service"];
}) {
const layerEnvironment = Layer.succeed(
DesktopEnvironment.DesktopEnvironment,
@@ -82,6 +84,7 @@ function runShellEnvironment(input: {
const layerSpawner = Layer.succeed(
ChildProcessSpawner.ChildProcessSpawner,
ChildProcessSpawner.make((command) => {
+ if (input.processSpawner) return input.processSpawner.spawn(command);
if (input.failure !== undefined) return Effect.fail(input.failure);
const result = input.handler(command);
return Effect.succeed(
@@ -118,6 +121,41 @@ function runShellEnvironment(input: {
}
describe("DesktopShellEnvironment", () => {
+ it.effect(
+ "captures the login-shell PATH when startup writes more than a pipe buffer to stderr",
+ () =>
+ Effect.gen(function* () {
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner.pipe(
+ Effect.provide(NodeServices.layer),
+ );
+ const executable = yield* HostProcess.ExecutablePath;
+ const env: NodeJS.ProcessEnv = { SHELL: "/test-shell", PATH: "/usr/bin" };
+ const commands: string[] = [];
+ const source = [
+ "setTimeout(() => process.exit(99), 3000).unref();",
+ "process.stderr.write(Buffer.alloc(2 * 1024 * 1024, 120), () => {",
+ `process.stdout.write(${JSON.stringify(envOutput({ PATH: "/shell-only/bin:/usr/bin" }))});`,
+ "});",
+ ].join("\n");
+
+ yield* runShellEnvironment({
+ env,
+ platform: "linux",
+ handler: () => "",
+ processSpawner: ChildProcessSpawner.make((command) => {
+ if (command._tag !== "StandardCommand") return Effect.succeed(makeProcess(""));
+ commands.push(command.command);
+ return command.command === "/test-shell"
+ ? spawner.spawn(ChildProcess.make(executable, ["-e", source], command.options))
+ : Effect.succeed(makeProcess(""));
+ }),
+ }).pipe(Effect.provide(Logger.layer([])));
+
+ assert.equal(env.PATH, "/shell-only/bin:/usr/bin");
+ assert.deepEqual(commands, ["/test-shell"]);
+ }),
+ );
+
it.effect("rejects PATH output from a failed shell and tries the next candidate", () =>
Effect.gen(function* () {
const env: NodeJS.ProcessEnv = { SHELL: "/bin/failing", PATH: "/usr/bin" };
diff --git a/apps/desktop/src/shell/DesktopShellEnvironment.ts b/apps/desktop/src/shell/DesktopShellEnvironment.ts
index 6e0fdbd3805..255eb202df6 100644
--- a/apps/desktop/src/shell/DesktopShellEnvironment.ts
+++ b/apps/desktop/src/shell/DesktopShellEnvironment.ts
@@ -255,7 +255,7 @@ const runCommandOutput = Effect.fn("desktop.shellEnvironment.runCommandOutput")(
shell: input.shell ?? false,
stdin: "ignore",
stdout: "pipe",
- stderr: "pipe",
+ stderr: "ignore",
killSignal: "SIGTERM",
forceKillAfter: PROCESS_TERMINATE_GRACE,
}),