-
Notifications
You must be signed in to change notification settings - Fork 91
feat(install): verify release archive checksums in both installers #942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bb09151
feat(install): verify release archive checksums (both installers)
mdesmet cecfe06
fix(install): address checksum-verification review
ralphstodomingo d9fe5be
fix(install.ps1): ASCII-only so it parses on Windows PowerShell 5.1
ralphstodomingo ab14d6b
fix(install): guard the verify_checksum cleanup against a pathologica…
ralphstodomingo 1ecf6ae
test: update #930 release-validation for the checksum URL refactor
ralphstodomingo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/opencode/test/install/checksum-verification.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /** | ||
| * Release-archive integrity verification across the install surface. | ||
| * | ||
| * The release publishes a checksums.txt asset; both installers fetch it and | ||
| * verify the downloaded archive (sha256) before extracting — hard-fail on | ||
| * mismatch, soft-skip when the file is absent (older pinned releases). | ||
| */ | ||
| import { describe, test, expect } from "bun:test" | ||
| import { readFileSync } from "node:fs" | ||
| import { join } from "node:path" | ||
|
|
||
| const REPO_ROOT = join(import.meta.dir, "../../../..") | ||
| const BASH_INSTALL = readFileSync(join(REPO_ROOT, "install"), "utf-8") | ||
| const PS1 = readFileSync(join(REPO_ROOT, "install.ps1"), "utf-8") | ||
| const RELEASE_YML = readFileSync(join(REPO_ROOT, ".github/workflows/release.yml"), "utf-8") | ||
|
|
||
| describe("release publishes checksums", () => { | ||
| test("release.yml generates checksums.txt and uploads it", () => { | ||
| expect(RELEASE_YML).toContain("sha256sum *.tar.gz *.zip > checksums.txt") | ||
| expect(RELEASE_YML).toContain("packages/opencode/dist/checksums.txt") | ||
| }) | ||
| }) | ||
|
|
||
| describe("bash installer verifies checksums", () => { | ||
| test("fetches checksums.txt and compares sha256", () => { | ||
| expect(BASH_INSTALL).toContain("checksums.txt") | ||
| expect(BASH_INSTALL).toMatch(/sha256sum|shasum -a 256/) | ||
| }) | ||
|
|
||
| test("hard-fails on mismatch", () => { | ||
| expect(BASH_INSTALL).toContain("Checksum mismatch") | ||
| expect(BASH_INSTALL).toContain("verify_checksum") | ||
| }) | ||
| }) | ||
|
|
||
| describe("PowerShell installer verifies checksums", () => { | ||
| test("fetches checksums.txt and compares sha256", () => { | ||
| expect(PS1).toContain("checksums.txt") | ||
| expect(PS1).toContain("Get-FileHash") | ||
| expect(PS1).toContain("Test-Checksum") | ||
| }) | ||
|
|
||
| test("hard-fails on mismatch before extracting", () => { | ||
| expect(PS1).toContain("Checksum mismatch") | ||
| // The verify call must precede the actual extraction call (not the | ||
| // Expand-Archive mention in the top-of-file ProgressPreference comment). | ||
| expect(PS1.indexOf("Test-Checksum -Path")).toBeLessThan(PS1.indexOf("Expand-Archive -Path")) | ||
| }) | ||
|
|
||
| test("decodes a Byte[] checksums.txt body (Windows PowerShell 5.1)", () => { | ||
| // GitHub serves release assets as octet-stream, so PS 5.1 returns .Content | ||
| // as Byte[]; without an explicit decode it coerces to decimal text and the | ||
| // check silently soft-skips. See test/windows/install.Tests.ps1 for the | ||
| // behavioral guard. | ||
| expect(PS1).toContain("-is [byte[]]") | ||
| expect(PS1).toContain("[System.Text.Encoding]::UTF8.GetString") | ||
| }) | ||
| }) | ||
|
|
||
| describe("archive and checksums come from the same release (no latest/ race)", () => { | ||
| test("bash derives the checksums URL from the same base as the archive", () => { | ||
| // verify_checksum builds checksums_url from the archive's own URL (${url%/*}), | ||
| // so the two are always fetched from the same release path. | ||
| expect(BASH_INSTALL).toContain('checksums_url="${url%/*}/checksums.txt"') | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| test("PowerShell pins both URLs to the resolved release tag (cubic P2)", () => { | ||
| // The archive and checksums.txt share one $base; that base is the resolved | ||
| // tag, so a release published mid-install can't hand back mismatched assets. | ||
| // Falls back to latest/ only when the version couldn't be resolved. | ||
| expect(PS1).toContain('$url = "$base/$filename"') | ||
| expect(PS1).toContain('$checksumsUrl = "$base/checksums.txt"') | ||
| expect(PS1).toContain('$base = "https://github.com/AltimateAI/altimate-code/releases/download/v$specificVersion"') | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.