Skip to content

Commit 8a21daf

Browse files
authored
Merge pull request #40 from hack-dance/dimitri/fix-lifecycle-non-login-shell
fix(cli): avoid login shells for lifecycle commands
2 parents 679b7e6 + 2963d46 commit 8a21daf

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/commands/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,9 +2141,9 @@ export function wrapLifecyclePersistentCommand(opts: {
21412141
' done < "$fifo" ) &',
21422142
"reader_pid=$!",
21432143
"if command -v python3 >/dev/null 2>&1; then",
2144-
' python3 -c \'import os, sys; os.setsid(); os.execvp("sh", ["sh", "-lc", sys.argv[1]])\' "$HACK_LIFECYCLE_COMMAND" >"$fifo" 2>&1 &',
2144+
' python3 -c \'import os, sys; os.setsid(); os.execvp("sh", ["sh", "-c", sys.argv[1]])\' "$HACK_LIFECYCLE_COMMAND" >"$fifo" 2>&1 &',
21452145
"else",
2146-
' sh -lc "$HACK_LIFECYCLE_COMMAND" >"$fifo" 2>&1 &',
2146+
' sh -c "$HACK_LIFECYCLE_COMMAND" >"$fifo" 2>&1 &',
21472147
"fi",
21482148
"cmd_pid=$!",
21492149
'wait "$cmd_pid"',

tests/project-lifecycle-processes.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ test("wrapLifecyclePersistentCommand uses external kill for process-group cleanu
137137
);
138138
});
139139

140+
test("wrapLifecyclePersistentCommand avoids login-shell execution", () => {
141+
const script = wrapLifecyclePersistentCommand({
142+
command: "bun run proxy",
143+
logPath: "/tmp/event-agent.log",
144+
serviceName: "proxy",
145+
});
146+
147+
expect(script).toContain('os.execvp("sh", ["sh", "-c", sys.argv[1]])');
148+
expect(script).toContain('sh -c "$HACK_LIFECYCLE_COMMAND" >"$fifo" 2>&1 &');
149+
expect(script).not.toContain('os.execvp("sh", ["sh", "-lc", sys.argv[1]])');
150+
expect(script).not.toContain(
151+
'sh -lc "$HACK_LIFECYCLE_COMMAND" >"$fifo" 2>&1 &'
152+
);
153+
});
154+
140155
async function createLifecycleProjectDir(): Promise<string> {
141156
const root = await mkdtemp(join(tmpdir(), "hack-lifecycle-processes-"));
142157
tempDirs.add(root);

0 commit comments

Comments
 (0)