Skip to content

Commit f1ace2d

Browse files
fix(shell): avoid interactive job control in environment probes
Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 05d4042 commit f1ace2d

4 files changed

Lines changed: 44 additions & 4 deletions

File tree

‎apps/desktop/src/shell/DesktopShellEnvironment.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,36 @@ describe("DesktopShellEnvironment", () => {
129129
}),
130130
);
131131

132+
it.effect("runs the login-shell probe without interactive job control", () =>
133+
Effect.gen(function* () {
134+
const env: NodeJS.ProcessEnv = {
135+
SHELL: "/bin/zsh",
136+
PATH: "/usr/bin",
137+
};
138+
const commands: ChildProcess.Command[] = [];
139+
140+
yield* runShellEnvironment({
141+
env,
142+
platform: "darwin",
143+
handler: (command) => {
144+
commands.push(command);
145+
return envOutput({ PATH: "/opt/homebrew/bin:/usr/bin" });
146+
},
147+
});
148+
149+
const probe = commands[0];
150+
assert.equal(probe?._tag, "StandardCommand");
151+
if (probe?._tag === "StandardCommand") {
152+
// `-l` without `-i`: interactive job control stops the probe on
153+
// SIGTTOU when the session inherits a controlling TTY owned by
154+
// another process group.
155+
assert.equal(probe.args[0], "-lc");
156+
assert.notInclude(probe.args, "-i");
157+
}
158+
assert.equal(env.PATH, "/opt/homebrew/bin:/usr/bin");
159+
}),
160+
);
161+
132162
it.effect("preserves inherited POSIX values when present", () =>
133163
Effect.gen(function* () {
134164
const env: NodeJS.ProcessEnv = {

‎apps/desktop/src/shell/DesktopShellEnvironment.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,10 @@ const readLoginShellEnvironment = (
340340
: runCommandOutput({
341341
probe: "login-shell",
342342
command: shell,
343-
args: ["-ilc", capturePosixEnvironmentCommand(names)],
343+
// Login shell only, no `-i`: interactive job control stops the probe
344+
// on SIGTTOU when the session inherits a controlling TTY owned by
345+
// another process group. Environment capture needs only login files.
346+
args: ["-lc", capturePosixEnvironmentCommand(names)],
344347
timeout: LOGIN_SHELL_TIMEOUT,
345348
}).pipe(Effect.map((output) => extractEnvironment(output, names)));
346349

‎packages/shared/src/shell.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const withWindowsEnvironmentMocks = <A, E, R>(
3939
);
4040

4141
describe("readPathFromLoginShell", () => {
42-
it("uses a shell-agnostic printenv PATH probe", () => {
42+
it("probes PATH through a login shell without interactive job control", () => {
4343
const execFile = vi.fn<
4444
(
4545
file: string,
@@ -62,7 +62,10 @@ describe("readPathFromLoginShell", () => {
6262
const [shell, args, options] = firstCall;
6363
expect(shell).toBe("/opt/homebrew/bin/fish");
6464
expect(args).toHaveLength(2);
65-
expect(args?.[0]).toBe("-ilc");
65+
// `-l` without `-i`: interactive job control stops the probe on SIGTTOU
66+
// when the session inherits a controlling TTY owned by another pgrp.
67+
expect(args?.[0]).toBe("-lc");
68+
expect(args?.[0]).not.toContain("i");
6669
expect(args?.[1]).toContain("printenv PATH || true");
6770
expect(args?.[1]).toContain("__T3CODE_ENV_PATH_START__");
6871
expect(args?.[1]).toContain("__T3CODE_ENV_PATH_END__");

‎packages/shared/src/shell.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ export const readEnvironmentFromLoginShell: ShellEnvironmentReader = (
298298
return {};
299299
}
300300

301-
const output = execFile(shell, ["-ilc", buildEnvironmentCaptureCommand(names)], {
301+
// Login shell only, no `-i`: interactive shells initialize job control, and
302+
// tcsetpgrp on a controlling TTY owned by another process group stops the
303+
// probe on SIGTTOU (SSH daemons started from a terminal hand sessions exactly
304+
// that). Environment capture only needs the login startup files.
305+
const output = execFile(shell, ["-lc", buildEnvironmentCaptureCommand(names)], {
302306
encoding: "utf8",
303307
timeout: 5000,
304308
});

0 commit comments

Comments
 (0)