Skip to content

Commit beb753e

Browse files
fix: propagate curl failures in install pipeline (#1241)
installClaudeCode() pipes `curl -fsSL | bash -s --`. Bash exits with the status of the last command, so when curl fails (429 rate limit, 403, or connection error) `bash -s` still exits 0 on empty stdin and the action logs "Claude Code installed successfully". The 3-attempt retry loop never triggers because the first attempt looks successful, and the run later dies with "Executable not found in $PATH: claude". Prefix the pipeline with `set -o pipefail;` so curl's non-zero exit propagates through the pipe and the retry loop can actually kick in. Extracted into buildInstallCommand() with regression tests covering both the old buggy shape and the fixed one.
1 parent 235b39b commit beb753e

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

‎src/entrypoints/run.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ import { runClaude } from "../../base-action/src/run-claude";
4444
import type { ClaudeRunResult } from "../../base-action/src/run-claude-sdk";
4545
import { setExecutionFileOutputIfPresent } from "../../base-action/src/execution-file";
4646

47+
// Exported for unit testing. `set -o pipefail` makes curl's non-zero exit
48+
// propagate through the pipe so the install retry logic actually triggers
49+
// on 429/403 instead of silently succeeding (see #1136).
50+
export function buildInstallCommand(version: string): string {
51+
return `set -o pipefail; curl -fsSL https://claude.ai/install.sh | bash -s -- ${version}`;
52+
}
53+
4754
/**
4855
* Install Claude Code CLI, handling retry logic and custom executable paths.
4956
* Returns the absolute path to the claude executable.
@@ -77,10 +84,7 @@ async function installClaudeCode(): Promise<string> {
7784
await new Promise<void>((resolve, reject) => {
7885
const child = spawn(
7986
"bash",
80-
[
81-
"-c",
82-
`curl -fsSL https://claude.ai/install.sh | bash -s -- ${claudeCodeVersion}`,
83-
],
87+
["-c", buildInstallCommand(claudeCodeVersion)],
8488
{ stdio: "inherit" },
8589
);
8690
child.on("close", (code) => {

‎test/install-pipefail.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { describe, it, expect } from "bun:test";
2+
import { spawnSync } from "child_process";
3+
import { buildInstallCommand } from "../src/entrypoints/run";
4+
5+
describe("buildInstallCommand (regression for #1136)", () => {
6+
it("includes the pinned claude version in the bash -s args", () => {
7+
const cmd = buildInstallCommand("2.1.114");
8+
expect(cmd).toContain("bash -s -- 2.1.114");
9+
});
10+
11+
it("prefixes the pipeline with `set -o pipefail`", () => {
12+
const cmd = buildInstallCommand("2.1.114");
13+
expect(cmd.startsWith("set -o pipefail;")).toBe(true);
14+
});
15+
16+
it("keeps the curl -fsSL flags so the script is fetched, not inlined", () => {
17+
const cmd = buildInstallCommand("2.1.114");
18+
expect(cmd).toContain(
19+
"curl -fsSL https://claude.ai/install.sh | bash -s --",
20+
);
21+
});
22+
});
23+
24+
describe("pipefail semantics (proves the bug shape and the fix)", () => {
25+
// Mirrors the real install invocation: a curl that returns non-zero
26+
// feeding into `bash -s --`. Without pipefail, the pipeline exits 0
27+
// because bash -s receives an empty stdin and does nothing. With
28+
// pipefail, curl's exit code wins and the retry loop in run.ts triggers.
29+
//
30+
// Uses port 1 (reserved/unused) so curl fails deterministically with no
31+
// network access. No shell-escaping traps here: the version argument is
32+
// a numeric literal.
33+
const unreachable = "http://127.0.0.1:1/nope";
34+
const version = "2.1.114";
35+
36+
it("BEFORE FIX: pipeline without pipefail swallows curl failure (exit 0)", () => {
37+
const buggy = `curl -fsSL ${unreachable} | bash -s -- ${version}`;
38+
const result = spawnSync("bash", ["-c", buggy], { stdio: "pipe" });
39+
expect(result.status).toBe(0);
40+
});
41+
42+
it("AFTER FIX: buildInstallCommand (against unreachable host) exits non-zero", () => {
43+
const fixed = buildInstallCommand(version).replace(
44+
"https://claude.ai/install.sh",
45+
unreachable,
46+
);
47+
const result = spawnSync("bash", ["-c", fixed], { stdio: "pipe" });
48+
expect(result.status).not.toBe(0);
49+
});
50+
});

0 commit comments

Comments
 (0)