From 118dbf0be6cd6a09736c74485664cc33595b28ae Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Sat, 14 Feb 2026 13:16:23 +0000 Subject: [PATCH] fix(upgrade): remove v prefix from release URLs and work around Bun.write streaming bug Download URLs used a `v` prefix (e.g. `/download/v0.10.1/...`) but this repo's GitHub tags are un-prefixed. Additionally, `Bun.write(path, Response)` with a large streaming body silently exits the process before the download completes (Bun event-loop bug). Materialise the body via `arrayBuffer()` first so the await keeps the process alive. Fixes CLI-5F --- src/lib/binary.ts | 2 +- src/lib/upgrade.ts | 10 +++++++--- test/commands/cli/upgrade.test.ts | 10 +++++----- test/lib/binary.test.ts | 4 ++-- test/lib/upgrade.test.ts | 6 +++--- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/lib/binary.ts b/src/lib/binary.ts index 8f03be9a88..4a899491e7 100644 --- a/src/lib/binary.ts +++ b/src/lib/binary.ts @@ -39,7 +39,7 @@ export function getBinaryDownloadUrl(version: string): string { const arch = process.arch === "arm64" ? "arm64" : "x64"; const suffix = process.platform === "win32" ? ".exe" : ""; - return `https://github.com/getsentry/cli/releases/download/v${version}/sentry-${os}-${arch}${suffix}`; + return `https://github.com/getsentry/cli/releases/download/${version}/sentry-${os}-${arch}${suffix}`; } /** diff --git a/src/lib/upgrade.ts b/src/lib/upgrade.ts index 705f3f0a23..abc1c80436 100644 --- a/src/lib/upgrade.ts +++ b/src/lib/upgrade.ts @@ -316,7 +316,7 @@ export async function versionExists( ): Promise { if (method === "curl") { const response = await fetchWithUpgradeError( - `${GITHUB_RELEASES_URL}/tags/v${version}`, + `${GITHUB_RELEASES_URL}/tags/${version}`, { method: "HEAD", headers: getGitHubHeaders() }, "GitHub" ); @@ -388,8 +388,12 @@ export async function downloadBinaryToTemp( ); } - // Write to temp file - await Bun.write(tempPath, response); + // Fully consume the response body before writing to disk. + // Bun.write(path, Response) with a large streaming body can exit the + // process before the download completes (Bun event-loop bug). + // Materialising the body first ensures the await keeps the process alive. + const body = await response.arrayBuffer(); + await Bun.write(tempPath, body); // Set executable permission (Unix only) if (process.platform !== "win32") { diff --git a/test/commands/cli/upgrade.test.ts b/test/commands/cli/upgrade.test.ts index dfd561152b..fd30415ea9 100644 --- a/test/commands/cli/upgrade.test.ts +++ b/test/commands/cli/upgrade.test.ts @@ -101,17 +101,17 @@ function mockGitHubVersion(version: string): void { // GitHub latest release endpoint — returns JSON with tag_name if (urlStr.includes("releases/latest")) { - return new Response(JSON.stringify({ tag_name: `v${version}` }), { + return new Response(JSON.stringify({ tag_name: version }), { status: 200, headers: { "content-type": "application/json" }, }); } - // GitHub tag check (for versionExists) - if (urlStr.includes("/releases/tag/")) { - const requested = urlStr.split("/releases/tag/v")[1]; + // GitHub tag check (for versionExists) — this repo uses un-prefixed tags + if (urlStr.includes("/releases/tags/")) { + const requested = urlStr.split("/releases/tags/")[1]; if (requested === version) { - return new Response(JSON.stringify({ tag_name: `v${version}` }), { + return new Response(JSON.stringify({ tag_name: version }), { status: 200, headers: { "content-type": "application/json" }, }); diff --git a/test/lib/binary.test.ts b/test/lib/binary.test.ts index 63871b415f..8d884d3ec5 100644 --- a/test/lib/binary.test.ts +++ b/test/lib/binary.test.ts @@ -31,9 +31,9 @@ describe("getBinaryDownloadUrl", () => { test("builds correct URL for current platform", () => { const url = getBinaryDownloadUrl("1.0.0"); - expect(url).toContain("/v1.0.0/"); + expect(url).toContain("/1.0.0/"); expect(url).toStartWith( - "https://github.com/getsentry/cli/releases/download/v" + "https://github.com/getsentry/cli/releases/download/" ); expect(url).toContain("sentry-"); diff --git a/test/lib/upgrade.test.ts b/test/lib/upgrade.test.ts index cef4594506..7f3d7f9fc9 100644 --- a/test/lib/upgrade.test.ts +++ b/test/lib/upgrade.test.ts @@ -437,10 +437,10 @@ describe("getBinaryDownloadUrl", () => { test("builds correct URL for current platform", () => { const url = getBinaryDownloadUrl("1.0.0"); - // URL should contain the version with 'v' prefix (GitHub tag format) - expect(url).toContain("/v1.0.0/"); + // URL should contain the version without 'v' prefix (this repo's tag format) + expect(url).toContain("/1.0.0/"); expect(url).toStartWith( - "https://github.com/getsentry/cli/releases/download/v" + "https://github.com/getsentry/cli/releases/download/" ); expect(url).toContain("sentry-");