fix(opencode): fallback to sh for curl upgrade (#30499)

Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com>
This commit is contained in:
Ulises Jeremias
2026-06-03 12:27:20 +05:30
committed by GitHub
co-authored by Shoubhit Dash
parent a444410cd4
commit 01cc475923
2 changed files with 27 additions and 3 deletions
+8 -1
View File
@@ -149,13 +149,20 @@ export const layer: Layer.Layer<Service, never, HttpClient.HttpClient | AppProce
return `Upgrade failed for ${method}.` return `Upgrade failed for ${method}.`
} }
const upgradeScriptShell = Effect.fnUntraced(function* () {
const bashVersion = yield* text(["bash", "--version"])
if (bashVersion) return "bash"
return "sh"
})
const upgradeCurl = Effect.fnUntraced( const upgradeCurl = Effect.fnUntraced(
function* (target: string) { function* (target: string) {
const response = yield* httpOk.execute(HttpClientRequest.get("https://opencode.ai/install")) const response = yield* httpOk.execute(HttpClientRequest.get("https://opencode.ai/install"))
const body = yield* response.text const body = yield* response.text
const bodyBytes = new TextEncoder().encode(body) const bodyBytes = new TextEncoder().encode(body)
const shell = yield* upgradeScriptShell()
const result = yield* appProcess.run( const result = yield* appProcess.run(
ChildProcess.make("bash", [], { ChildProcess.make(shell, [], {
stdin: Stream.make(bodyBytes), stdin: Stream.make(bodyBytes),
env: { VERSION: target }, env: { VERSION: target },
extendEnv: true, extendEnv: true,
@@ -194,8 +194,9 @@ describe("installation", () => {
testEffect( testEffect(
testLayer( testLayer(
() => new Response("install script with token=secret", { status: 200 }), () => new Response("install script with token=secret", { status: 200 }),
(cmd) => { (cmd, args) => {
if (cmd === "bash") return { code: 1, stderr: "script output with token=secret" } if (cmd === "bash" && args[0] === "--version") return "GNU bash"
if (cmd === "bash" || cmd === "sh") return { code: 1, stderr: "script output with token=secret" }
return "" return ""
}, },
), ),
@@ -209,5 +210,21 @@ describe("installation", () => {
expect(error.stderr).not.toContain("script output") expect(error.stderr).not.toContain("script output")
}), }),
) )
testEffect(
testLayer(
() => new Response("install script", { status: 200 }),
(cmd, args) => {
if (cmd === "bash" && args[0] === "--version") return { code: 1, stderr: "missing" }
if (cmd === "bash") return { code: 1, stderr: "should not execute installer with bash" }
if (cmd === "sh") return "ok"
return ""
},
),
).effect("falls back to sh when bash is unavailable during curl upgrade", () =>
Effect.gen(function* () {
yield* Installation.use.upgrade("curl", "9.9.9")
}),
)
}) })
}) })