From e4d41785e0f849fee6aad71b4e3881936abf1d5f Mon Sep 17 00:00:00 2001 From: San Dang Date: Wed, 22 Jul 2026 14:36:34 +0530 Subject: [PATCH 1/4] ci(installer): trust formula asset transition --- scripts/check-installer-hash.sh | 41 +++++++++++++++++---- scripts/checks/extract-installer-pins.mts | 39 +++++++++++++++----- test/installer-hash-check.test.ts | 45 +++++++++++++++++++++-- 3 files changed, 105 insertions(+), 20 deletions(-) diff --git a/scripts/check-installer-hash.sh b/scripts/check-installer-hash.sh index 2a34a3e5058..a4d1b07f4ff 100755 --- a/scripts/check-installer-hash.sh +++ b/scripts/check-installer-hash.sh @@ -6,7 +6,7 @@ # still match the immutable upstream checksum manifests. # # Checked artifacts: -# 1. OpenShell archives — scripts/install-openshell.sh release-asset table +# 1. OpenShell archives/formula — scripts/install-openshell.sh release-asset table # 2. Brev OpenShell CLI — scripts/brev-launchable-ci-cpu.sh release-asset table # # Usage: @@ -88,11 +88,11 @@ sha256_file() { check_openshell_release_assets() { local installer="${REPO_ROOT}/scripts/install-openshell.sh" local brev_installer="${REPO_ROOT}/scripts/brev-launchable-ci-cpu.sh" - local release_base workspace manifests spec manifest expected actual source asset pinned upstream + local release_base workspace manifests spec manifest expected actual source asset pinned upstream formula_asset local matches required_manifest required_matches local pin_records parser_error parser_errors parsed_version release_version="" record_extra local allowlist_entry allowlist_version allowlist_extra - local count=0 brev_count=0 published_count=0 failures=0 + local count=0 brev_count=0 published_count=0 expected_published_count=0 failures=0 local -a manifest_specs=() workspace=$(mktemp -d) manifests="${workspace}/published-sha256.txt" @@ -147,8 +147,11 @@ check_openshell_release_assets() { esac done <<<"$pin_records" - if [[ "$count" -ne 8 ]]; then - echo " STALE: expected 8 pinned OpenShell v${release_version:-unknown} assets, found ${count}." + # Transitional trust anchor: accept the current archive set and the same set + # plus openshell.rb. Tighten this to nine assets when the formula consumer + # lands. The base-trusted parser still rejects every other asset set. + if [[ "$count" -ne 8 && "$count" -ne 9 ]]; then + echo " STALE: expected 8 or 9 pinned OpenShell v${release_version:-unknown} assets, found ${count}." failures=$((failures + 1)) fi if [[ "$brev_count" -ne 2 ]]; then @@ -224,6 +227,29 @@ check_openshell_release_assets() { done while IFS=$'\t' read -r parsed_version source asset pinned record_extra; do + if [[ "$asset" == "openshell.rb" ]]; then + formula_asset="${workspace}/${asset}" + if ! fetch_file "${release_base}/${asset}" "$formula_asset"; then + echo " STALE: unable to download ${source} ${asset}." + failures=$((failures + 1)) + continue + fi + if ! actual=$(sha256_file "$formula_asset"); then + echo " STALE: unable to hash ${source} ${asset}." + failures=$((failures + 1)) + continue + fi + if [[ "$actual" == "$pinned" ]]; then + published_count=$((published_count + 1)) + echo " OK: ${source} ${asset} (${pinned})" + else + echo " STALE: ${source} ${asset} digest does not match the pinned v${release_version} release asset." + echo " pinned: ${pinned}" + echo " upstream: ${actual}" + failures=$((failures + 1)) + fi + continue + fi matches=$(awk -v asset="$asset" '$2 == asset { count++ } END { print count + 0 }' "$manifests") upstream=$(awk -v asset="$asset" '$2 == asset { print $1; exit }' "$manifests") if [[ "$matches" -eq 1 && "$pinned" == "$upstream" ]]; then @@ -238,8 +264,9 @@ check_openshell_release_assets() { fi done <<<"$pin_records" - if [[ "$published_count" -ne 10 ]]; then - echo " STALE: expected all 10 pinned asset references in the v${release_version} checksum manifests, matched ${published_count}." + expected_published_count=$((count + brev_count)) + if [[ "$published_count" -ne "$expected_published_count" ]]; then + echo " STALE: expected all ${expected_published_count} pinned asset references for v${release_version}, matched ${published_count}." failures=$((failures + 1)) fi return "$failures" diff --git a/scripts/checks/extract-installer-pins.mts b/scripts/checks/extract-installer-pins.mts index bddc0163d33..f137a94edc3 100644 --- a/scripts/checks/extract-installer-pins.mts +++ b/scripts/checks/extract-installer-pins.mts @@ -47,10 +47,17 @@ const MAX_INSTALLER_INPUT_BYTES = 1024 * 1024; // only in a prerequisite trust-anchor PR that keeps the currently selected // release; the later pin PR may then change release data without authorizing // any operational installer change. A mismatch reports the candidate hash. -const TRUSTED_INSTALLER_TEMPLATE_SHA256 = - "a101f002bd8e02aa7b38960ddcb76c9fca419bc3766f6870446f6a7e99e14d78"; -const TRUSTED_BREV_TEMPLATE_SHA256 = - "c0a4ddf25a02a9fe02b2df53a60942ea887610f04d4ce16a121b6e79a5aeff1a"; +// This transition accepts the current installer and the reviewed formula +// installer. Tighten this back to the formula installer hash when its consumer +// lands; accepting both is necessary because base-trusted CI validates both +// the prerequisite branch and the dependent pull request. +const TRUSTED_INSTALLER_TEMPLATE_SHA256_ALLOWLIST = [ + "a101f002bd8e02aa7b38960ddcb76c9fca419bc3766f6870446f6a7e99e14d78", + "2b6a6195241d6b946fe29503d8d2d99d5b864864458f510ca129e3396248ac58", +] as const; +const TRUSTED_BREV_TEMPLATE_SHA256_ALLOWLIST = [ + "c0a4ddf25a02a9fe02b2df53a60942ea887610f04d4ce16a121b6e79a5aeff1a", +] as const; const EXPECTED_INSTALLER_ASSETS = [ "openshell-x86_64-unknown-linux-musl.tar.gz", "openshell-aarch64-unknown-linux-musl.tar.gz", @@ -61,6 +68,7 @@ const EXPECTED_INSTALLER_ASSETS = [ "openshell-sandbox-x86_64-unknown-linux-gnu.tar.gz", "openshell-sandbox-aarch64-unknown-linux-gnu.tar.gz", ] as const; +const TRANSITIONAL_INSTALLER_ASSET = "openshell.rb"; const EXPECTED_BREV_ASSETS = [ "openshell-x86_64-unknown-linux-musl.tar.gz", "openshell-aarch64-unknown-linux-musl.tar.gz", @@ -164,6 +172,17 @@ function assertExactAssetSet( } } +function assertInstallerAssetSet(pins: InstallerPin[]): void { + const includesFormula = pins.some((pin) => pin.asset === TRANSITIONAL_INSTALLER_ASSET); + assertExactAssetSet( + pins, + includesFormula + ? [...EXPECTED_INSTALLER_ASSETS, TRANSITIONAL_INSTALLER_ASSET] + : EXPECTED_INSTALLER_ASSETS, + "installer pin table", + ); +} + // invalidState: the blueprint and stable runtime selectors request a newer // OpenShell release while both embedded hash tables still name an older, // independently valid release, so separate dependency and hash checks pass but @@ -655,7 +674,7 @@ function assertTrustedTemplate( source: string, functionNames: readonly string[], selectorPatterns: readonly RegExp[], - expectedSha256: string, + expectedSha256: readonly string[], label: string, ): void { const normalized = normalizeTrustedInstallerTemplate( @@ -665,10 +684,10 @@ function assertTrustedTemplate( label, ); const actualSha256 = createHash("sha256").update(normalized).digest("hex"); - if (actualSha256 !== expectedSha256) { + if (!expectedSha256.includes(actualSha256)) { fail( `${label} operational template is not base-trusted; ` + - `expected_sha256=${expectedSha256}, actual_sha256=${actualSha256}`, + `expected_sha256=[${expectedSha256.join(", ")}], actual_sha256=${actualSha256}`, ); } } @@ -931,7 +950,7 @@ function runCli(): void { functionName: "openshell_cli_pinned_sha256", sourceLabel: "Brev launchable", }); - assertExactAssetSet(installerPins, EXPECTED_INSTALLER_ASSETS, "installer pin table"); + assertInstallerAssetSet(installerPins); assertExactAssetSet(brevPins, EXPECTED_BREV_ASSETS, "Brev pin table"); const pins = [...installerPins, ...brevPins]; const releaseVersions = [...new Set(pins.map((pin) => pin.releaseVersion))].sort(); @@ -955,14 +974,14 @@ function runCli(): void { /^MAX_VERSION="([0-9]+\.[0-9]+\.[0-9]+)"$/gm, /^DEV_MIN_VERSION="([0-9]+\.[0-9]+\.[0-9]+)"$/gm, ], - TRUSTED_INSTALLER_TEMPLATE_SHA256, + TRUSTED_INSTALLER_TEMPLATE_SHA256_ALLOWLIST, "installer", ); assertTrustedTemplate( brevInstallerSource, ["openshell_cli_pinned_sha256"], [/^\s*stable\s*\|\s*auto\)\s*OPENSHELL_VERSION="v([0-9]+\.[0-9]+\.[0-9]+)"\s*;;\s*$/gm], - TRUSTED_BREV_TEMPLATE_SHA256, + TRUSTED_BREV_TEMPLATE_SHA256_ALLOWLIST, "Brev launchable", ); for (const [label, runtimeVersion] of [ diff --git a/test/installer-hash-check.test.ts b/test/installer-hash-check.test.ts index 194cf5d53c7..d235e0985d2 100644 --- a/test/installer-hash-check.test.ts +++ b/test/installer-hash-check.test.ts @@ -52,8 +52,11 @@ const ASSET_DIGESTS = new Map([ "openshell-sandbox-aarch64-unknown-linux-gnu.tar.gz", "2cf62cbd651e55d0f8750804e2b4025e0d6c8eea4564c87cda47a2c922941db0", ], + ["openshell.rb", "f53c62777fed23b42427822d231670451ee4358efeb2660c41a7a38919211b23"], ]); -const ASSETS = [...ASSET_DIGESTS.keys()]; +const FORMULA_ASSET = "openshell.rb"; +const FORMULA_DIGEST = ASSET_DIGESTS.get(FORMULA_ASSET)!; +const ASSETS = [...ASSET_DIGESTS.keys()].filter((asset) => asset !== FORMULA_ASSET); const UNPUBLISHED_ASSET = "openshell-sandbox-aarch64-unknown-linux-gnu-unpublished.tar.gz"; const OFFICIAL_UNEXPECTED_INSTALLER_ASSET = "openshell-driver-vm-x86_64-unknown-linux-gnu.tar.gz"; const OFFICIAL_UNEXPECTED_INSTALLER_DIGEST = @@ -532,6 +535,7 @@ function renderBrevTemplate(openshellVersion: string, pinFunction: string): stri function createFixture( openshellVersion = "0.0.72", formatting: PinFormatting = "canonical", + includeFormula = false, ): string { const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-installer-hash-")); const scriptsDir = path.join(fixtureRoot, "scripts"); @@ -561,7 +565,12 @@ function createFixture( path.join(scriptsDir, "install-openshell.sh"), renderInstallerTemplate( openshellVersion, - renderPinFunction("openshell_pinned_sha256", ASSETS, openshellVersion, formatting), + renderPinFunction( + "openshell_pinned_sha256", + includeFormula ? [...ASSETS, FORMULA_ASSET] : ASSETS, + openshellVersion, + formatting, + ), ), ); fs.writeFileSync( @@ -613,6 +622,9 @@ case "$url" in openshell-sandbox-checksums-sha256.txt) printf '%s' '${CHECKSUM_MANIFESTS.get("openshell-sandbox-checksums-sha256.txt")}' >"$output" ;; + openshell.rb) + printf '%s\n' 'class Openshell < Formula; end' >"$output" + ;; esac ;; *) exit 22 ;; @@ -620,6 +632,24 @@ esac `, ); fs.chmodSync(path.join(binDir, "curl"), 0o755); + fs.writeFileSync( + path.join(binDir, "sha256sum"), + `#!/usr/bin/env bash +set -euo pipefail +case "\${1:-}" in + */openshell.rb) + printf '%s %s\\n' '${FORMULA_DIGEST}' "$1" + ;; + *) + case "$(uname -s)" in + Darwin) /usr/bin/shasum -a 256 "$@" ;; + *) /usr/bin/sha256sum "$@" ;; + esac + ;; +esac +`, + ); + fs.chmodSync(path.join(binDir, "sha256sum"), 0o755); return fixtureRoot; } @@ -628,8 +658,9 @@ function runFixture( openshellVersion?: string, trustedChecker = false, formatting: PinFormatting = "canonical", + includeFormula = false, ) { - const fixtureRoot = createFixture(openshellVersion, formatting); + const fixtureRoot = createFixture(openshellVersion, formatting, includeFormula); const targetChecker = path.join(fixtureRoot, "scripts", "check-installer-hash.sh"); const trustedRoot = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-trusted-hash-check-")); const trustedCheckerPath = path.join(trustedRoot, "scripts", "check-installer-hash.sh"); @@ -695,6 +726,14 @@ describe("installer hash verification", () => { expect(result.stdout).toContain("All installer hashes are current"); }); + it("verifies the reviewed Homebrew formula during the trust-anchor transition", () => { + const result = runFixture("complete", undefined, true, "canonical", true); + + expect(result.status).toBe(0); + expect(result.stdout).toContain(`OK: installer ${FORMULA_ASSET} (${FORMULA_DIGEST})`); + expect(result.stdout).toContain("All installer hashes are current"); + }); + it("derives the release version from matching static installer pin tables", () => { const result = runFixture("complete", undefined, true); From 962f7aea3dfb8168c499b9f389e324f6378366ca Mon Sep 17 00:00:00 2001 From: San Dang Date: Wed, 22 Jul 2026 14:47:20 +0530 Subject: [PATCH 2/4] test(installer): cover formula trust failures --- scripts/checks/extract-installer-pins.mts | 1 + test/installer-hash-check.test.ts | 33 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/scripts/checks/extract-installer-pins.mts b/scripts/checks/extract-installer-pins.mts index f137a94edc3..3a0efe81f28 100644 --- a/scripts/checks/extract-installer-pins.mts +++ b/scripts/checks/extract-installer-pins.mts @@ -173,6 +173,7 @@ function assertExactAssetSet( } function assertInstallerAssetSet(pins: InstallerPin[]): void { + // extractInstallerPins rejects duplicate assets before this transition check. const includesFormula = pins.some((pin) => pin.asset === TRANSITIONAL_INSTALLER_ASSET); assertExactAssetSet( pins, diff --git a/test/installer-hash-check.test.ts b/test/installer-hash-check.test.ts index d235e0985d2..b59f8289179 100644 --- a/test/installer-hash-check.test.ts +++ b/test/installer-hash-check.test.ts @@ -83,7 +83,9 @@ type FixtureMode = | "brev-sha-command-bypass" | "complete" | "duplicate-brev-pin" + | "duplicate-installer-pin" | "failure" + | "formula-mismatch" | "incomplete-trusted-allowlist" | "installer-max-version-drift" | "installer-bypassed-comparison" @@ -221,6 +223,15 @@ const mutateSandboxBuildFunction = ( }; const INSTALLER_MUTATIONS: Partial string>> = { + "duplicate-installer-pin": (source) => { + const asset = ASSETS[0]; + const digest = ASSET_DIGESTS.get(asset ?? "") ?? "missing"; + const arm = ` v0.0.72:${asset}) + printf '%s\\n' "${digest}" + ;;`; + assert.ok(source.includes(arm), "installer duplicate-pin fixture arm must exist"); + return source.replace(arm, `${arm}\n${arm}`); + }, "installer-bypassed-comparison": (source) => source.replace('[ "$release_sha" = "$expected_sha" ]', "true"), "installer-changed-asset": (source) => @@ -638,7 +649,11 @@ esac set -euo pipefail case "\${1:-}" in */openshell.rb) - printf '%s %s\\n' '${FORMULA_DIGEST}' "$1" + case "\${NEMOCLAW_TEST_CURL_MODE:-}" in + formula-mismatch) digest='${"0".repeat(64)}' ;; + *) digest='${FORMULA_DIGEST}' ;; + esac + printf '%s %s\\n' "$digest" "$1" ;; *) case "$(uname -s)" in @@ -734,6 +749,16 @@ describe("installer hash verification", () => { expect(result.stdout).toContain("All installer hashes are current"); }); + it("fails closed when the Homebrew formula digest does not match", () => { + const result = runFixture("formula-mismatch", undefined, true, "canonical", true); + + expect(result.status).toBe(1); + expect(result.stdout).toContain( + "STALE: installer openshell.rb digest does not match the pinned v0.0.72 release asset", + ); + expect(result.stdout).not.toContain("All installer hashes are current"); + }); + it("derives the release version from matching static installer pin tables", () => { const result = runFixture("complete", undefined, true); @@ -965,11 +990,17 @@ describe("installer hash verification", () => { it.each([ "missing-brev-pin", "duplicate-brev-pin", + "duplicate-installer-pin", ] as const)("fails closed when the pull-request tree has a %s", (mode) => { const result = runFixture(mode, undefined, true); expect(result.status).toBe(1); expect(result.stdout).toContain("unable to extract the OpenShell installer pin tables"); + if (mode === "duplicate-installer-pin") { + expect(result.stdout).toContain( + `openshell_pinned_sha256 contains duplicate assets: ${ASSETS[0]}`, + ); + } expect(result.stdout).not.toContain("All installer hashes are current"); }); From 72e4b38b1004b5ebcc0f219ce5bf951d11030daa Mon Sep 17 00:00:00 2001 From: San Dang Date: Wed, 22 Jul 2026 14:51:47 +0530 Subject: [PATCH 3/4] test(installer): keep trust checks linear --- test/installer-hash-check.test.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/installer-hash-check.test.ts b/test/installer-hash-check.test.ts index b59f8289179..f1d98b6536e 100644 --- a/test/installer-hash-check.test.ts +++ b/test/installer-hash-check.test.ts @@ -990,17 +990,22 @@ describe("installer hash verification", () => { it.each([ "missing-brev-pin", "duplicate-brev-pin", - "duplicate-installer-pin", ] as const)("fails closed when the pull-request tree has a %s", (mode) => { const result = runFixture(mode, undefined, true); expect(result.status).toBe(1); expect(result.stdout).toContain("unable to extract the OpenShell installer pin tables"); - if (mode === "duplicate-installer-pin") { - expect(result.stdout).toContain( - `openshell_pinned_sha256 contains duplicate assets: ${ASSETS[0]}`, - ); - } + expect(result.stdout).not.toContain("All installer hashes are current"); + }); + + it("fails closed when the installer pin table contains a duplicate asset", () => { + const result = runFixture("duplicate-installer-pin", undefined, true); + + expect(result.status).toBe(1); + expect(result.stdout).toContain("unable to extract the OpenShell installer pin tables"); + expect(result.stdout).toContain( + `openshell_pinned_sha256 contains duplicate assets: ${ASSETS[0]}`, + ); expect(result.stdout).not.toContain("All installer hashes are current"); }); From febfda3e1d3f1756f1066569bb5754eefa2f81f7 Mon Sep 17 00:00:00 2001 From: San Dang Date: Wed, 22 Jul 2026 16:51:04 +0530 Subject: [PATCH 4/4] fix(installer): bind asset contracts to templates --- scripts/checks/extract-installer-pins.mts | 39 +++++++++++------- test/installer-hash-check.test.ts | 48 +++++++++++++++++++++-- 2 files changed, 69 insertions(+), 18 deletions(-) diff --git a/scripts/checks/extract-installer-pins.mts b/scripts/checks/extract-installer-pins.mts index 3a0efe81f28..f5a0626ee1a 100644 --- a/scripts/checks/extract-installer-pins.mts +++ b/scripts/checks/extract-installer-pins.mts @@ -50,10 +50,15 @@ const MAX_INSTALLER_INPUT_BYTES = 1024 * 1024; // This transition accepts the current installer and the reviewed formula // installer. Tighten this back to the formula installer hash when its consumer // lands; accepting both is necessary because base-trusted CI validates both -// the prerequisite branch and the dependent pull request. +// the prerequisite branch and the dependent pull request. Each trusted hash is +// coupled below to the exact asset set consumed by that template. +const TRUSTED_ARCHIVE_INSTALLER_TEMPLATE_SHA256 = + "a101f002bd8e02aa7b38960ddcb76c9fca419bc3766f6870446f6a7e99e14d78"; +const TRUSTED_FORMULA_INSTALLER_TEMPLATE_SHA256 = + "2b6a6195241d6b946fe29503d8d2d99d5b864864458f510ca129e3396248ac58"; const TRUSTED_INSTALLER_TEMPLATE_SHA256_ALLOWLIST = [ - "a101f002bd8e02aa7b38960ddcb76c9fca419bc3766f6870446f6a7e99e14d78", - "2b6a6195241d6b946fe29503d8d2d99d5b864864458f510ca129e3396248ac58", + TRUSTED_ARCHIVE_INSTALLER_TEMPLATE_SHA256, + TRUSTED_FORMULA_INSTALLER_TEMPLATE_SHA256, ] as const; const TRUSTED_BREV_TEMPLATE_SHA256_ALLOWLIST = [ "c0a4ddf25a02a9fe02b2df53a60942ea887610f04d4ce16a121b6e79a5aeff1a", @@ -69,6 +74,13 @@ const EXPECTED_INSTALLER_ASSETS = [ "openshell-sandbox-aarch64-unknown-linux-gnu.tar.gz", ] as const; const TRANSITIONAL_INSTALLER_ASSET = "openshell.rb"; +const EXPECTED_INSTALLER_ASSETS_BY_TEMPLATE_SHA256 = new Map([ + [TRUSTED_ARCHIVE_INSTALLER_TEMPLATE_SHA256, EXPECTED_INSTALLER_ASSETS], + [ + TRUSTED_FORMULA_INSTALLER_TEMPLATE_SHA256, + [...EXPECTED_INSTALLER_ASSETS, TRANSITIONAL_INSTALLER_ASSET], + ], +]); const EXPECTED_BREV_ASSETS = [ "openshell-x86_64-unknown-linux-musl.tar.gz", "openshell-aarch64-unknown-linux-musl.tar.gz", @@ -172,16 +184,12 @@ function assertExactAssetSet( } } -function assertInstallerAssetSet(pins: InstallerPin[]): void { +function assertInstallerAssetSet(pins: InstallerPin[], templateSha256: string): void { // extractInstallerPins rejects duplicate assets before this transition check. - const includesFormula = pins.some((pin) => pin.asset === TRANSITIONAL_INSTALLER_ASSET); - assertExactAssetSet( - pins, - includesFormula - ? [...EXPECTED_INSTALLER_ASSETS, TRANSITIONAL_INSTALLER_ASSET] - : EXPECTED_INSTALLER_ASSETS, - "installer pin table", - ); + const expectedAssets = + EXPECTED_INSTALLER_ASSETS_BY_TEMPLATE_SHA256.get(templateSha256) ?? + fail(`installer template ${templateSha256} has no trusted asset contract`); + assertExactAssetSet(pins, expectedAssets, "installer pin table"); } // invalidState: the blueprint and stable runtime selectors request a newer @@ -677,7 +685,7 @@ function assertTrustedTemplate( selectorPatterns: readonly RegExp[], expectedSha256: readonly string[], label: string, -): void { +): string { const normalized = normalizeTrustedInstallerTemplate( source, functionNames, @@ -691,6 +699,7 @@ function assertTrustedTemplate( `expected_sha256=[${expectedSha256.join(", ")}], actual_sha256=${actualSha256}`, ); } + return actualSha256; } function skipSeparators(tokens: Token[], start: number): number { @@ -951,7 +960,6 @@ function runCli(): void { functionName: "openshell_cli_pinned_sha256", sourceLabel: "Brev launchable", }); - assertInstallerAssetSet(installerPins); assertExactAssetSet(brevPins, EXPECTED_BREV_ASSETS, "Brev pin table"); const pins = [...installerPins, ...brevPins]; const releaseVersions = [...new Set(pins.map((pin) => pin.releaseVersion))].sort(); @@ -967,7 +975,7 @@ function runCli(): void { `pinned_sandbox_build_version must contain at least one digest for release ${releaseVersion}`, ); } - assertTrustedTemplate( + const installerTemplateSha256 = assertTrustedTemplate( installerSource, ["openshell_pinned_sha256", "pinned_sandbox_build_version"], [ @@ -978,6 +986,7 @@ function runCli(): void { TRUSTED_INSTALLER_TEMPLATE_SHA256_ALLOWLIST, "installer", ); + assertInstallerAssetSet(installerPins, installerTemplateSha256); assertTrustedTemplate( brevInstallerSource, ["openshell_cli_pinned_sha256"], diff --git a/test/installer-hash-check.test.ts b/test/installer-hash-check.test.ts index f1d98b6536e..603e934e436 100644 --- a/test/installer-hash-check.test.ts +++ b/test/installer-hash-check.test.ts @@ -57,6 +57,10 @@ const ASSET_DIGESTS = new Map([ const FORMULA_ASSET = "openshell.rb"; const FORMULA_DIGEST = ASSET_DIGESTS.get(FORMULA_ASSET)!; const ASSETS = [...ASSET_DIGESTS.keys()].filter((asset) => asset !== FORMULA_ASSET); +const ARCHIVE_INSTALLER_TEMPLATE_SHA256 = + "a101f002bd8e02aa7b38960ddcb76c9fca419bc3766f6870446f6a7e99e14d78"; +const FORMULA_INSTALLER_TEMPLATE_SHA256 = + "2b6a6195241d6b946fe29503d8d2d99d5b864864458f510ca129e3396248ac58"; const UNPUBLISHED_ASSET = "openshell-sandbox-aarch64-unknown-linux-gnu-unpublished.tar.gz"; const OFFICIAL_UNEXPECTED_INSTALLER_ASSET = "openshell-driver-vm-x86_64-unknown-linux-gnu.tar.gz"; const OFFICIAL_UNEXPECTED_INSTALLER_DIGEST = @@ -543,6 +547,19 @@ function renderBrevTemplate(openshellVersion: string, pinFunction: string): stri ); } +function mapFixtureTemplateToFormulaContract(source: string): string { + // The fixture renders the current archive-only installer. Rebind the hashes + // in the copied parser so this test exercises the formula contract without + // copying the dependent PR's installer implementation into this branch. + const withoutArchiveContract = source.replace(ARCHIVE_INSTALLER_TEMPLATE_SHA256, "0".repeat(64)); + const formulaContract = withoutArchiveContract.replace( + FORMULA_INSTALLER_TEMPLATE_SHA256, + ARCHIVE_INSTALLER_TEMPLATE_SHA256, + ); + assert.notEqual(formulaContract, source, "trusted parser formula contract fixture must change"); + return formulaContract; +} + function createFixture( openshellVersion = "0.0.72", formatting: PinFormatting = "canonical", @@ -674,6 +691,7 @@ function runFixture( trustedChecker = false, formatting: PinFormatting = "canonical", includeFormula = false, + formulaTemplate = false, ) { const fixtureRoot = createFixture(openshellVersion, formatting, includeFormula); const targetChecker = path.join(fixtureRoot, "scripts", "check-installer-hash.sh"); @@ -688,9 +706,15 @@ function runFixture( tempDirs.push(trustedRoot); fs.mkdirSync(path.dirname(trustedParserPath), { recursive: true }); fs.copyFileSync(path.join(REPO_ROOT, "scripts", "check-installer-hash.sh"), trustedCheckerPath); - fs.copyFileSync( + const trustedParserSource = fs.readFileSync( path.join(REPO_ROOT, "scripts", "checks", "extract-installer-pins.mts"), + "utf8", + ); + fs.writeFileSync( trustedParserPath, + formulaTemplate + ? mapFixtureTemplateToFormulaContract(trustedParserSource) + : trustedParserSource, ); fs.writeFileSync( targetChecker, @@ -742,7 +766,7 @@ describe("installer hash verification", () => { }); it("verifies the reviewed Homebrew formula during the trust-anchor transition", () => { - const result = runFixture("complete", undefined, true, "canonical", true); + const result = runFixture("complete", undefined, true, "canonical", true, true); expect(result.status).toBe(0); expect(result.stdout).toContain(`OK: installer ${FORMULA_ASSET} (${FORMULA_DIGEST})`); @@ -750,7 +774,7 @@ describe("installer hash verification", () => { }); it("fails closed when the Homebrew formula digest does not match", () => { - const result = runFixture("formula-mismatch", undefined, true, "canonical", true); + const result = runFixture("formula-mismatch", undefined, true, "canonical", true, true); expect(result.status).toBe(1); expect(result.stdout).toContain( @@ -759,6 +783,24 @@ describe("installer hash verification", () => { expect(result.stdout).not.toContain("All installer hashes are current"); }); + it("rejects a formula pin when the installer keeps the archive-only template", () => { + const result = runFixture("complete", undefined, true, "canonical", true); + + expect(result.status).toBe(1); + expect(result.stdout).toContain("unable to extract the OpenShell installer pin tables"); + expect(result.stdout).toContain("unexpected=[openshell.rb]"); + expect(result.stdout).not.toContain("All installer hashes are current"); + }); + + it("rejects the formula installer template when its formula pin is missing", () => { + const result = runFixture("complete", undefined, true, "canonical", false, true); + + expect(result.status).toBe(1); + expect(result.stdout).toContain("unable to extract the OpenShell installer pin tables"); + expect(result.stdout).toContain("missing=[openshell.rb]"); + expect(result.stdout).not.toContain("All installer hashes are current"); + }); + it("derives the release version from matching static installer pin tables", () => { const result = runFixture("complete", undefined, true);