The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 09:30 UTC
fix(desktop): keep noisy shell probes from blocking PATH capture (#21913)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Simone committed
Nov 1, 2026 at 03:04 UTC
0b75a852d8fe529774daf6ccc37916336aa3e0b2
2 files changed
+39
-1
apps/desktop/src/shell/DesktopShellEnvironment.test.ts
+38
@@ -1,6 +1,7 @@
1
// @effect-diagnostics nodeBuiltinImport:off -- The process fixture runs real shell commands with isolated config files.
2
import * as NodeServices from "@effect/platform-node/NodeServices";
3
import { assert, describe, it } from "@effect/vitest";
4
+import * as HostProcess from "@t3tools/shared/HostProcess";
5
import * as Effect from "effect/Effect";
6
import * as Layer from "effect/Layer";
7
import * as Logger from "effect/Logger";
@@ -72,6 +73,7 @@ function runShellEnvironment(input: {
73
command: ChildProcess.Command,
74
) => string | { output: string; exitCode: number };
75
readonly failure?: PlatformError.PlatformError;
76
+ readonly processSpawner?: ChildProcessSpawner.ChildProcessSpawner["Service"];
77
}) {
78
const layerEnvironment = Layer.succeed(
79
DesktopEnvironment.DesktopEnvironment,
@@ -82,6 +84,7 @@ function runShellEnvironment(input: {
84
const layerSpawner = Layer.succeed(
85
ChildProcessSpawner.ChildProcessSpawner,
86
ChildProcessSpawner.make((command) => {
87
+ if (input.processSpawner) return input.processSpawner.spawn(command);
88
if (input.failure !== undefined) return Effect.fail(input.failure);
89
const result = input.handler(command);
90
return Effect.succeed(
@@ -118,6 +121,41 @@ function runShellEnvironment(input: {
121
}
122
123
describe("DesktopShellEnvironment", () => {
124
+ it.effect(
125
+ "captures the login-shell PATH when startup writes more than a pipe buffer to stderr",
126
+ () =>
127
+ Effect.gen(function* () {
128
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner.pipe(
129
+ Effect.provide(NodeServices.layer),
130
+ );
131
+ const executable = yield* HostProcess.ExecutablePath;
132
+ const env: NodeJS.ProcessEnv = { SHELL: "/test-shell", PATH: "/usr/bin" };
133
+ const commands: string[] = [];
134
+ const source = [
135
+ "setTimeout(() => process.exit(99), 3000).unref();",
136
+ "process.stderr.write(Buffer.alloc(2 * 1024 * 1024, 120), () => {",
137
+ `process.stdout.write(${JSON.stringify(envOutput({ PATH: "/shell-only/bin:/usr/bin" }))});`,
138
+ "});",
139
+ ].join("\n");
140
+
141
+ yield* runShellEnvironment({
142
+ env,
143
+ platform: "linux",
144
+ handler: () => "",
145
+ processSpawner: ChildProcessSpawner.make((command) => {
146
+ if (command._tag !== "StandardCommand") return Effect.succeed(makeProcess(""));
147
+ commands.push(command.command);
148
+ return command.command === "/test-shell"
149
+ ? spawner.spawn(ChildProcess.make(executable, ["-e", source], command.options))
150
+ : Effect.succeed(makeProcess(""));
151
+ }),
152
+ }).pipe(Effect.provide(Logger.layer([])));
153
+
154
+ assert.equal(env.PATH, "/shell-only/bin:/usr/bin");
155
+ assert.deepEqual(commands, ["/test-shell"]);
156
+ }),
157
+ );
158
+
159
it.effect("rejects PATH output from a failed shell and tries the next candidate", () =>
160
Effect.gen(function* () {
161
const env: NodeJS.ProcessEnv = { SHELL: "/bin/failing", PATH: "/usr/bin" };
apps/desktop/src/shell/DesktopShellEnvironment.ts
+1
-1
@@ -255,7 +255,7 @@ const runCommandOutput = Effect.fn("desktop.shellEnvironment.runCommandOutput")(
255
shell: input.shell ?? false,
256
stdin: "ignore",
257
stdout: "pipe",
258
- stderr: "pipe",
258
+ stderr: "ignore",
259
killSignal: "SIGTERM",
260
forceKillAfter: PROCESS_TERMINATE_GRACE,
261
}),