From d8a217511a0b0ffc7e2b61d2faf5cf27c2faed54 Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Wed, 14 Oct 2026 22:31:04 -0400 Subject: [PATCH 1/2] Pin the engine only in the source lock, and name new engines by date and content Engine/source-lock.json becomes the only place the engine is pinned, so two branches that change the engine conflict only in the lock, not in six files: - the app's pin is generated from the lock at build time (OmarchyEnginePinPlugin) instead of committed; - read-validation-engine.py (used by build-app.sh and prepare-engine.py), rebuild-python-overlay.py, assemble-candidate-v8.sh and cutover-wizard read the lock; - the pipeline config's engine block keeps only downstreamRevision, and catalog-inputs composes the rest from the lock (pipeline_engine); - the release-input templates drop engine_name and engine_version, and make-unsigned-catalog.py always takes them from the lock. New engines are named v0.9.2-omarchy.., where the id hashes the lock's build inputs, so branches never race for the next number. Engine/engine_pin.py writes the name; its check fails if a dated name no longer matches the inputs, so a merged engine must be renamed and rebuilt. Every catalog now requires app 2.1.0 or later instead of deciding from the engine's name, so nothing parses engine names. mac-catalog.yml's installer input and catalog_release.py prepare --installer become required. A test fails if any file outside the lock, docs and evidence repeats the engine digest. Co-Authored-By: Claude Opus 5.5 --- .github/mac-release-pipeline.json | 5 - .github/workflows/mac-catalog.yml | 14 +- .github/workflows/mac-release-pipeline.yml | 17 ++- Engine/engine_pin.py | 128 ++++++++++++++++++ Engine/rebuild-python-overlay.py | 4 +- Engine/source-lock.json | 2 +- Engine/tests/test_engine_pin.py | 89 ++++++++++++ Package.swift | 11 +- Packaging/build-app.sh | 1 + Packaging/read-validation-engine.py | 29 ++-- Plugins/OmarchyEnginePinPlugin/plugin.swift | 24 ++++ .../ValidationEngineArtifact.swift | 10 +- Sources/OmarchyEnginePinGenerator/main.swift | 87 ++++++++++++ .../ValidationEngineArtifactTests.swift | 39 +++--- docs/catalog-release.md | 2 +- docs/engine-versions.md | 33 +++++ docs/extraction.md | 4 +- docs/mac-release-pipeline.md | 4 +- scripts/assemble-candidate-v8.sh | 44 +++--- scripts/catalog_release.py | 44 ++++-- scripts/cutover-wizard | 6 +- scripts/make-unsigned-catalog.py | 19 +-- scripts/release-inputs-aurora.template.json | 2 - scripts/release-inputs.template.json | 2 - scripts/tests/test_catalog_release.py | 3 +- scripts/tests/test_mac_upload.py | 2 +- scripts/tests/test_make_unsigned_catalog.py | 25 +++- scripts/tests/test_release_pipeline.py | 20 ++- 28 files changed, 541 insertions(+), 129 deletions(-) create mode 100755 Engine/engine_pin.py create mode 100644 Engine/tests/test_engine_pin.py create mode 100644 Plugins/OmarchyEnginePinPlugin/plugin.swift create mode 100644 Sources/OmarchyEnginePinGenerator/main.swift create mode 100644 docs/engine-versions.md diff --git a/.github/mac-release-pipeline.json b/.github/mac-release-pipeline.json index 1dd6a2ec..cc01f1db 100644 --- a/.github/mac-release-pipeline.json +++ b/.github/mac-release-pipeline.json @@ -1,10 +1,5 @@ { "engine": { - "version": "v0.9.2-omarchy.50", - "url": "https://github.com/omacom/omarchy-mac-installer/releases/download/engine-v0.9.2-omarchy.50/installer-v0.9.2-omarchy.50.tar.gz", - "fileName": "installer-v0.9.2-omarchy.50.tar.gz", - "sizeBytes": 18037588, - "sha256": "313f91571422170094a8fa1ac65fb24002d708bba86f7a2dbfe4821f89b12e6e", "downstreamRevision": "6b644750fa3165d47838892cdbc46801cfe75018" }, "installer": { diff --git a/.github/workflows/mac-catalog.yml b/.github/workflows/mac-catalog.yml index ff47be6c..53e36217 100644 --- a/.github/workflows/mac-catalog.yml +++ b/.github/workflows/mac-catalog.yml @@ -40,9 +40,9 @@ on: type: string required: true installer: - description: App compatibility as JSON {minimumVersion, latestVersion, downloadURL}; required for engines from v0.9.2-omarchy.18 + description: App compatibility as JSON {minimumVersion, latestVersion, downloadURL}; minimumVersion at least 2.1.0 type: string - default: '' + required: true channel: description: Channel to publish (edge only until promotion is unparked) type: string @@ -84,9 +84,9 @@ on: type: string required: true installer: - description: App compatibility as JSON {minimumVersion, latestVersion, downloadURL}; required for engines from v0.9.2-omarchy.18 + description: App compatibility as JSON {minimumVersion, latestVersion, downloadURL}; minimumVersion at least 2.1.0 type: string - default: '' + required: true channel: description: Channel to publish type: choice @@ -140,7 +140,7 @@ jobs: printf '%s\n' "$ENGINE" >"$inputs/engine.json" printf '%s\n' "$INSTALLER_DATA" >"$inputs/installer-data.json" printf '%s\n' "$EVIDENCE" >"$inputs/evidence.json" - [[ -z $INSTALLER ]] || printf '%s\n' "$INSTALLER" >"$inputs/installer.json" + printf '%s\n' "$INSTALLER" >"$inputs/installer.json" { git rev-parse HEAD openssl version @@ -156,13 +156,11 @@ jobs: run: | set -euo pipefail inputs=$RUNNER_TEMP/catalog-inputs - installer=() - [[ ! -f $inputs/installer.json ]] || installer=(--installer "$inputs/installer.json") python3 scripts/catalog_release.py prepare \ --channel "$(<"$inputs/channel")" --image "$(<"$inputs/image")" \ --payload "$inputs/payload.json" --engine "$inputs/engine.json" \ --installer-data "$inputs/installer-data.json" --evidence "$inputs/evidence.json" \ - "${installer[@]}" --verify-remote --check-live --host github-release \ + --installer "$inputs/installer.json" --verify-remote --check-live --host github-release \ --out "$inputs" | tee "$inputs/prepare.log" echo "catalog-sha256=$(sed -n 's/^catalog_sha256=//p' "$inputs/prepare.log")" >>"$GITHUB_OUTPUT" { diff --git a/.github/workflows/mac-release-pipeline.yml b/.github/workflows/mac-release-pipeline.yml index b42bab6a..c8c6d1ed 100644 --- a/.github/workflows/mac-release-pipeline.yml +++ b/.github/workflows/mac-release-pipeline.yml @@ -11,7 +11,8 @@ name: Mac release pipeline # Namespace's Apple-backed Linux ARM64 runner). # Writes the evidence record, attests it when it passed, and # fails unless it passed. -# catalog-inputs the engine and app blocks from .github/mac-release-pipeline.json; +# catalog-inputs the engine pinned in Engine/source-lock.json and the app +# block from .github/mac-release-pipeline.json; # a real run without an app release stops here, before anything # is public # upload mac-upload.yml, only after passing evidence: in the publish @@ -147,21 +148,25 @@ jobs: echo "::error::$config names no app release (installer); set it to a published app release (mac-app-release.yml) before a catalog can be signed" exit 1 fi - # The catalog's own checks, so a malformed block stops here too. - python3 -I - "$config" <<'PY' + # The engine is the one Engine/source-lock.json pins; the config adds + # only its downstreamRevision. The catalog's own checks run on both + # blocks, so a malformed one stops here too. + engine=$(python3 -I - "$config" <<'PY' import importlib.util, json, sys spec = importlib.util.spec_from_file_location("catalog_release", "scripts/catalog_release.py") release = importlib.util.module_from_spec(spec) spec.loader.exec_module(release) config = json.load(open(sys.argv[1])) try: - release.check_engine(config["engine"]) + engine = release.pipeline_engine(config["engine"]) if config["installer"] is not None: - release.check_installer(config["installer"], config["engine"]["version"]) + release.check_installer(config["installer"]) except (release.Refusal, KeyError, TypeError) as error: sys.exit(f"::error::{sys.argv[1]}: {error}") + print(json.dumps(engine, separators=(",", ":"))) PY - echo "engine=$(jq -c .engine "$config")" | tee -a "$GITHUB_OUTPUT" + ) + echo "engine=$engine" | tee -a "$GITHUB_OUTPUT" echo "installer=$(jq -c .installer "$config")" | tee -a "$GITHUB_OUTPUT" upload: diff --git a/Engine/engine_pin.py b/Engine/engine_pin.py new file mode 100755 index 00000000..a4d725d0 --- /dev/null +++ b/Engine/engine_pin.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python3 +"""Name the installation engine the source lock pins, and check that name. + +Engine/source-lock.json is the only place the engine is pinned: downstream_overlay.version +names it and validation_artifact holds its file name, size and digest. Everything else +reads it there: the app (OmarchyEnginePinPlugin, at build time), Packaging/build-app.sh, +the release workflows and the catalog tools. See docs/engine-versions.md. + + engine_pin.py name [--date YYYYMMDD] [--write] + The name for the engine the lock describes: v0.9.2-omarchy... + The content id is a digest of the lock's build inputs, so two branches that change + the engine differently get different names, and the same inputs get the same id. + --write puts the name (and the matching archive file name) in the lock. + + engine_pin.py check + Fail if a dated name's content id does not match the lock's build inputs, or if + the archive name does not follow the name. + +After merging two branches that both changed the engine: resolve the lock's build inputs, +run `name --write`, rebuild the engine and record its size and digest. +""" + +import argparse +from datetime import datetime, timezone +import hashlib +import json +from pathlib import Path +import re +import sys + +ROOT = Path(__file__).resolve().parents[1] +LOCK = ROOT / "Engine" / "source-lock.json" + +BASE = "v0.9.2-omarchy" +DATED = re.compile(r"v0\.9\.2-omarchy\.(\d{8})\.([0-9a-f]{12})") + +# The lock's build inputs. Everything else in it either describes the result +# (the name and the artifact) or is prose. +INPUTS = ( + "upstream_installer", + "upstream_metadata", + "downstream_overlay", + "incremental_build", + "build_inputs", + "build_toolchain", + "build_recipe", +) + + +class PinError(Exception): + pass + + +def load_lock(path=LOCK): + return json.loads(Path(path).read_text()) + + +def content_id(lock): + inputs = {key: lock[key] for key in INPUTS if key in lock} + inputs["downstream_overlay"] = { + key: value for key, value in inputs["downstream_overlay"].items() if key != "version" + } + inputs["metadata_sha256"] = lock["validation_artifact"]["metadata_sha256"] + canonical = json.dumps(inputs, sort_keys=True, separators=(",", ":")).encode() + return hashlib.sha256(canonical).hexdigest()[:12] + + +def dated_name(lock, date): + if not re.fullmatch(r"\d{8}", date): + raise PinError(f"the date must be YYYYMMDD: {date}") + datetime.strptime(date, "%Y%m%d") + return f"{BASE}.{date}.{content_id(lock)}" + + +def archive_name(version): + return f"installer-{version}.tar.gz" + + +def dump_json(document): + return json.dumps(document, indent=2, ensure_ascii=False) + "\n" + + +def check(lock): + problems = [] + version = lock["downstream_overlay"]["version"] + # Engines named before dated names (v0.9.2-omarchy.50 and earlier) pass + # until the next engine change renames them. + if (match := DATED.fullmatch(version)) and match.group(2) != content_id(lock): + problems.append( + f"{version} names content {match.group(2)}, but the lock's build inputs are {content_id(lock)}; " + "run `engine_pin.py name --write`" + ) + filename = lock["validation_artifact"]["filename"] + if filename != archive_name(version): + problems.append(f"validation_artifact.filename is {filename}, expected {archive_name(version)}") + return problems + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) + commands = parser.add_subparsers(dest="command", required=True) + name = commands.add_parser("name", help="print (or --write) the dated engine name") + name.add_argument("--date", default=datetime.now(timezone.utc).strftime("%Y%m%d")) + name.add_argument("--write", action="store_true") + commands.add_parser("check", help="fail if the lock's engine name is inconsistent") + args = parser.parse_args(argv) + lock = load_lock() + try: + if args.command == "name": + version = dated_name(lock, args.date) + if args.write: + lock["downstream_overlay"]["version"] = version + lock["validation_artifact"]["filename"] = archive_name(version) + LOCK.write_text(dump_json(lock)) + print(version) + else: + problems = check(lock) + for problem in problems: + print(problem, file=sys.stderr) + return 1 if problems else 0 + except PinError as error: + print(error, file=sys.stderr) + return 1 + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/Engine/rebuild-python-overlay.py b/Engine/rebuild-python-overlay.py index 4d03c2e5..adbba14d 100644 --- a/Engine/rebuild-python-overlay.py +++ b/Engine/rebuild-python-overlay.py @@ -21,7 +21,6 @@ 'asahi_firmware/bluetooth.py': 'aa12e6cd684ed5b55d732db1f040d84570537bacc991d03ee6f854cbb232c369', } BASE_COMMIT = 'f0469cea0899f3efed8efead604174c7a53c4451' -VERSION = 'v0.9.2-omarchy.50' _SPEC = importlib.util.spec_from_file_location( 'verify_source_lock', Path(__file__).resolve().parent / 'verify-source-lock.py') @@ -137,7 +136,8 @@ def rebuild(checkout, base, output): if item['destination'] != 'bin/' + Path(item['path']).name: raise ValueError('bundled tool destination is invalid: ' + item['path']) overlay[item['destination']] = (root / item['path']).read_bytes() - overlay['version.tag'] = (VERSION + '\n').encode() + # The name is the lock's; Engine/engine_pin.py chooses it. + overlay['version.tag'] = (lock['downstream_overlay']['version'] + '\n').encode() with tarfile.open(fileobj=io.BytesIO(data), mode='r:gz') as archive: # The engine carries its own installer metadata; the per-payload copy in the repository is a different file. if sha256(archive.extractfile('./installer_data.json').read()) != lock['validation_artifact']['metadata_sha256']: diff --git a/Engine/source-lock.json b/Engine/source-lock.json index 1a5bac0e..9652666e 100644 --- a/Engine/source-lock.json +++ b/Engine/source-lock.json @@ -350,7 +350,7 @@ }, { "path": "rebuild-python-overlay.py", - "sha256": "2b9861e574228f69d81e136f93336e67488a889fc788ca6dbbb10c2d5779b7ac" + "sha256": "3ea07c0b9b7cb26b371c0bd970405d5ecb223a766c54dd6a31c3d2dcebea1139" }, { "path": "RestoreImage/LICENSE", diff --git a/Engine/tests/test_engine_pin.py b/Engine/tests/test_engine_pin.py new file mode 100644 index 00000000..b8a55ee8 --- /dev/null +++ b/Engine/tests/test_engine_pin.py @@ -0,0 +1,89 @@ +import copy +import importlib.util +from pathlib import Path +import subprocess +import unittest + + +MODULE_PATH = Path(__file__).resolve().parents[1] / "engine_pin.py" +SPEC = importlib.util.spec_from_file_location("engine_pin", MODULE_PATH) +PIN = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(PIN) + + +class EnginePinTests(unittest.TestCase): + def setUp(self): + self.lock = PIN.load_lock() + + def test_the_lock_names_its_engine_consistently(self): + self.assertEqual(PIN.check(self.lock), []) + + def test_nothing_else_repeats_the_pin(self): + # Every consumer reads the lock, so an engine change touches only the + # lock and two branches that change the engine conflict only there. + # Docs and evidence may record the history of past engines. + digest = self.lock["validation_artifact"]["sha256"] + result = subprocess.run(["git", "grep", "-l", "-F", digest, "--", ".", + ":!Engine/source-lock.json", ":!docs", ":!evidence", ":!*.md"], + cwd=PIN.ROOT, capture_output=True, text=True) + if result.returncode == 128: + self.skipTest(f"not a git checkout: {result.stderr.strip()}") + self.assertEqual(result.stdout.split(), [], "these files repeat the engine digest; read the lock instead") + + def test_the_content_id_ignores_the_name_and_the_built_artifact(self): + other = copy.deepcopy(self.lock) + other["downstream_overlay"]["version"] = "v0.9.2-omarchy.99" + other["validation_artifact"]["filename"] = "installer-v0.9.2-omarchy.99.tar.gz" + other["validation_artifact"]["sha256"] = "0" * 64 + other["validation_artifact"]["size_bytes"] = 1 + other["status"] = "prose changes do not rename the engine" + self.assertEqual(PIN.content_id(other), PIN.content_id(self.lock)) + + def test_any_build_input_change_gives_a_new_content_id(self): + cases = { + "an overlay source": lambda lock: lock["downstream_overlay"]["files"][0].update(sha256="1" * 64), + "the runtime patch": lambda lock: lock["downstream_overlay"]["patch"].update(sha256="2" * 64), + "the build recipe": lambda lock: lock["build_recipe"][0].update(sha256="3" * 64), + "the base engine": lambda lock: lock["incremental_build"].update(base_sha256="4" * 64), + "the engine metadata": lambda lock: lock["validation_artifact"].update(metadata_sha256="5" * 64), + } + for name, change in cases.items(): + with self.subTest(name): + other = copy.deepcopy(self.lock) + change(other) + self.assertNotEqual(PIN.content_id(other), PIN.content_id(self.lock)) + + def test_dated_names_carry_the_date_and_the_content_id(self): + name = PIN.dated_name(self.lock, "20261014") + self.assertEqual(name, f"v0.9.2-omarchy.20261014.{PIN.content_id(self.lock)}") + self.assertEqual(PIN.archive_name(name), f"installer-{name}.tar.gz") + + def test_impossible_dates_are_refused(self): + for date in ("2026101", "20261301", "2026-10-14"): + with self.subTest(date): + with self.assertRaises((PIN.PinError, ValueError)): + PIN.dated_name(self.lock, date) + + def test_a_dated_name_must_match_the_lock_inputs(self): + other = copy.deepcopy(self.lock) + stale = "v0.9.2-omarchy.20261014.000000000000" + other["downstream_overlay"]["version"] = stale + other["validation_artifact"]["filename"] = PIN.archive_name(stale) + problems = PIN.check(other) + self.assertTrue(any("names content 000000000000" in problem for problem in problems), problems) + + def test_the_archive_name_must_follow_the_version(self): + other = copy.deepcopy(self.lock) + other["validation_artifact"]["filename"] = "installer-something-else.tar.gz" + self.assertTrue(any("expected installer-" in problem for problem in PIN.check(other))) + + def test_name_write_renames_the_engine_and_its_archive(self): + other = copy.deepcopy(self.lock) + name = PIN.dated_name(other, "20261014") + other["downstream_overlay"]["version"] = name + other["validation_artifact"]["filename"] = PIN.archive_name(name) + self.assertEqual(PIN.check(other), []) + + +if __name__ == "__main__": + unittest.main() diff --git a/Package.swift b/Package.swift index 51522651..f2e70bb6 100644 --- a/Package.swift +++ b/Package.swift @@ -62,11 +62,20 @@ let package = Package( capability: .buildTool(), dependencies: ["OmarchyInstallerIdentityGenerator"] ), + .executableTarget( + name: "OmarchyEnginePinGenerator", + path: "Sources/OmarchyEnginePinGenerator" + ), + .plugin( + name: "OmarchyEnginePinPlugin", + capability: .buildTool(), + dependencies: ["OmarchyEnginePinGenerator"] + ), .target( name: "OmarchyAppleInstallerTrustCore", dependencies: ["OmarchyInstallerSystem", "RecoveryAccountCore"], path: "Sources/OmarchyAppleInstaller", - plugins: ["OmarchyInstallerIdentityPlugin"] + plugins: ["OmarchyInstallerIdentityPlugin", "OmarchyEnginePinPlugin"] ), .target( name: "OmarchyInstallerUXCore", diff --git a/Packaging/build-app.sh b/Packaging/build-app.sh index c7911ca9..d3435414 100755 --- a/Packaging/build-app.sh +++ b/Packaging/build-app.sh @@ -53,6 +53,7 @@ helper_identifier="$INSTALLER_HELPER_IDENTIFIER" app_name="$INSTALLER_APP_NAME.app" app_executable_name="OmarchyAppleInstallerApp" daemon_plist_name="$helper_identifier.plist" +# The engine is pinned only in the source lock (docs/engine-versions.md). read -r engine_file_name engine_digest engine_size < <( python3 "$script_directory/read-validation-engine.py" ) diff --git a/Packaging/read-validation-engine.py b/Packaging/read-validation-engine.py index e66d0eb4..f351c252 100644 --- a/Packaging/read-validation-engine.py +++ b/Packaging/read-validation-engine.py @@ -1,19 +1,22 @@ #!/usr/bin/env python3 -"""Print the inspection engine pin shared by app packaging and release CI.""" +"""Print the inspection engine pin shared by app packaging and release CI. + +The engine is pinned only in Engine/source-lock.json, and OmarchyEnginePinPlugin +compiles the same values into the app (docs/engine-versions.md). The checks are +the generator's. +""" import json from pathlib import Path import re -import sys root = Path(__file__).resolve().parents[1] -source = (root / "Sources/OmarchyAppleInstaller/ValidationEngineArtifact.swift").read_text() -name = re.search(r'public static let fileName = "(installer-[A-Za-z0-9.-]+\.tar\.gz)"', source) -digest = re.search(r'public static let expectedDigest\s*=\s*"sha256:([0-9a-f]{64})"', source) -size = re.search(r'public static let expectedSizeBytes: UInt64 = ([0-9_]+)', source) -if not all((name, digest, size)): - raise SystemExit("Cannot read the app inspection engine identity") -actual = (name[1], digest[1], int(size[1].replace("_", ""))) -lock = json.loads((root / "Engine/source-lock.json").read_text())["validation_artifact"] -if actual != (lock["filename"], lock["sha256"], lock["size_bytes"]): - raise SystemExit("App inspection engine differs from its source lock") -print(*actual) +lock = json.loads((root / "Engine/source-lock.json").read_text()) +version = lock["downstream_overlay"]["version"] +artifact = lock["validation_artifact"] +name, digest, size = artifact["filename"], artifact["sha256"], artifact["size_bytes"] +if (not isinstance(version, str) or re.fullmatch(r"v[0-9A-Za-z.+-]*", version) is None + or name != f"installer-{version}.tar.gz" + or not isinstance(digest, str) or re.fullmatch(r"[0-9a-f]{64}", digest) is None + or type(size) is not int or size <= 0): + raise SystemExit("Cannot read the inspection engine pin from the source lock") +print(name, digest, size) diff --git a/Plugins/OmarchyEnginePinPlugin/plugin.swift b/Plugins/OmarchyEnginePinPlugin/plugin.swift new file mode 100644 index 00000000..63fcc2a8 --- /dev/null +++ b/Plugins/OmarchyEnginePinPlugin/plugin.swift @@ -0,0 +1,24 @@ +import Foundation +import PackagePlugin + +@main +struct OmarchyEnginePinPlugin: BuildToolPlugin { + func createBuildCommands(context: PluginContext, target: any Target) throws -> [Command] { + let lock = context.package.directoryURL + .appending(components: "Engine", "source-lock.json") + let output = context.pluginWorkDirectoryURL + .appending(component: "ValidationEnginePin.swift") + return [ + .buildCommand( + displayName: "Generating the engine pin from Engine/source-lock.json", + executable: try context.tool(named: "OmarchyEnginePinGenerator").url, + arguments: [ + lock.path(percentEncoded: false), + output.path(percentEncoded: false), + ], + inputFiles: [lock], + outputFiles: [output] + ) + ] + } +} diff --git a/Sources/OmarchyAppleInstaller/ValidationEngineArtifact.swift b/Sources/OmarchyAppleInstaller/ValidationEngineArtifact.swift index 069b711b..e90419a4 100644 --- a/Sources/OmarchyAppleInstaller/ValidationEngineArtifact.swift +++ b/Sources/OmarchyAppleInstaller/ValidationEngineArtifact.swift @@ -17,13 +17,11 @@ /// recommendations separate from the safety limits used after staging. /// An installation engine fix ships in a catalog without rebuilding /// and re-notarizing the app. Nothing may require them to be equal. + /// + /// The pin itself (`version`, `fileName`, `expectedDigest`, + /// `expectedSizeBytes`) is generated from `Engine/source-lock.json` at + /// build time by OmarchyEnginePinPlugin. public struct ValidationEngineArtifactLocator: Sendable { - public static let version = "v0.9.2-omarchy.50" - public static let fileName = "installer-v0.9.2-omarchy.50.tar.gz" - public static let expectedDigest = - "sha256:313f91571422170094a8fa1ac65fb24002d708bba86f7a2dbfe4821f89b12e6e" - public static let expectedSizeBytes: UInt64 = 18_037_588 - public init() {} public func locate() throws -> PinnedAsahiEngineArchive { diff --git a/Sources/OmarchyEnginePinGenerator/main.swift b/Sources/OmarchyEnginePinGenerator/main.swift new file mode 100644 index 00000000..9db19750 --- /dev/null +++ b/Sources/OmarchyEnginePinGenerator/main.swift @@ -0,0 +1,87 @@ +import Foundation + +// Turns Engine/source-lock.json into the engine pin compiled into the app: +// the inspection engine's version, archive name, size and digest. The lock is +// the only place the engine is pinned (docs/engine-versions.md), so nothing +// generated from it is committed. + +func fail(_ message: String) -> Never { + FileHandle.standardError.write(Data("engine pin generator: \(message)\n".utf8)) + exit(1) +} + +func object(_ value: Any?, _ name: String) -> [String: Any] { + guard let object = value as? [String: Any] else { + fail("\(name) is not an object") + } + return object +} + +func string(_ object: [String: Any], _ key: String, _ name: String) -> String { + guard let value = object[key] as? String, !value.isEmpty else { + fail("\(name).\(key) is not a non-empty string") + } + return value +} + +func isHex(_ value: String, count: Int) -> Bool { + value.count == count + && value.allSatisfy { ("0"..."9").contains($0) || ("a"..."f").contains($0) } +} + +let versionCharacters = Set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.+-") + +let arguments = CommandLine.arguments +guard arguments.count == 3 else { + fail("usage: OmarchyEnginePinGenerator SOURCE_LOCK OUTPUT") +} +let lockURL = URL(fileURLWithPath: arguments[1]) +let output = URL(fileURLWithPath: arguments[2]) +let lock: [String: Any] +do { + lock = object( + try JSONSerialization.jsonObject(with: Data(contentsOf: lockURL)), "the source lock") +} catch { + fail("cannot read \(lockURL.path): \(error)") +} +let overlay = object(lock["downstream_overlay"], "downstream_overlay") +let artifact = object(lock["validation_artifact"], "validation_artifact") +let version = string(overlay, "version", "downstream_overlay") +let fileName = string(artifact, "filename", "validation_artifact") +let digest = string(artifact, "sha256", "validation_artifact") +guard version.hasPrefix("v"), version.allSatisfy(versionCharacters.contains) else { + fail("downstream_overlay.version is not an engine version: \(version)") +} +guard fileName == "installer-\(version).tar.gz" else { + fail("validation_artifact.filename is \(fileName), expected installer-\(version).tar.gz") +} +guard isHex(digest, count: 64) else { + fail("validation_artifact.sha256 is not a lowercase SHA-256") +} +guard let size = artifact["size_bytes"] as? NSNumber, + CFGetTypeID(size) != CFBooleanGetTypeID(), size.int64Value > 0, + size.stringValue == String(size.uint64Value) +else { + fail("validation_artifact.size_bytes is not a positive integer") +} + +let rendered = """ + // Generated from Engine/source-lock.json. Edit that file, not this one. + #if os(macOS) + extension ValidationEngineArtifactLocator { + public static let version = "\(version)" + public static let fileName = "\(fileName)" + public static let expectedDigest = "sha256:\(digest)" + public static let expectedSizeBytes: UInt64 = \(size.uint64Value) + } + #endif + + """ +let data = Data(rendered.utf8) +if (try? Data(contentsOf: output)) != data { + do { + try data.write(to: output, options: .atomic) + } catch { + fail("cannot write \(output.path): \(error)") + } +} diff --git a/Tests/OmarchyAppleInstallerTrustCoreTests/ValidationEngineArtifactTests.swift b/Tests/OmarchyAppleInstallerTrustCoreTests/ValidationEngineArtifactTests.swift index 765bd703..cdb8dbbb 100644 --- a/Tests/OmarchyAppleInstallerTrustCoreTests/ValidationEngineArtifactTests.swift +++ b/Tests/OmarchyAppleInstallerTrustCoreTests/ValidationEngineArtifactTests.swift @@ -5,23 +5,30 @@ @testable import OmarchyAppleInstallerTrustCore final class ValidationEngineArtifactTests: XCTestCase { - func testM3CapableInspectionIdentityIsPinnedExactly() { - XCTAssertEqual( - ValidationEngineArtifactLocator.version, - "v0.9.2-omarchy.50" - ) - XCTAssertEqual( - ValidationEngineArtifactLocator.fileName, - "installer-v0.9.2-omarchy.50.tar.gz" - ) - XCTAssertEqual( - ValidationEngineArtifactLocator.expectedDigest, - "sha256:313f91571422170094a8fa1ac65fb24002d708bba86f7a2dbfe4821f89b12e6e" - ) - XCTAssertEqual( - ValidationEngineArtifactLocator.expectedSizeBytes, - 18_037_588 + func testInspectionIdentityIsTheSourceLockEngine() throws { + // OmarchyEnginePinPlugin generates the pin from the lock at build + // time; this proves the compiled pin is the lock's. + let lockURL = URL(fileURLWithPath: #filePath) + .deletingLastPathComponent() + .deletingLastPathComponent() + .deletingLastPathComponent() + .appendingPathComponent("Engine/source-lock.json") + let lock = try XCTUnwrap( + JSONSerialization.jsonObject(with: Data(contentsOf: lockURL)) + as? [String: Any] ) + let overlay = try XCTUnwrap(lock["downstream_overlay"] as? [String: Any]) + let artifact = try XCTUnwrap(lock["validation_artifact"] as? [String: Any]) + let version = try XCTUnwrap(overlay["version"] as? String) + let fileName = try XCTUnwrap(artifact["filename"] as? String) + let digest = try XCTUnwrap(artifact["sha256"] as? String) + let size = try XCTUnwrap(artifact["size_bytes"] as? NSNumber) + + XCTAssertEqual(ValidationEngineArtifactLocator.version, version) + XCTAssertEqual(ValidationEngineArtifactLocator.fileName, fileName) + XCTAssertEqual(ValidationEngineArtifactLocator.fileName, "installer-\(version).tar.gz") + XCTAssertEqual(ValidationEngineArtifactLocator.expectedDigest, "sha256:\(digest)") + XCTAssertEqual(ValidationEngineArtifactLocator.expectedSizeBytes, size.uint64Value) } func testAppBundleLookupUsesThePinnedEngineFilename() throws { diff --git a/docs/catalog-release.md b/docs/catalog-release.md index 5e6b3f12..f0a2ca0a 100644 --- a/docs/catalog-release.md +++ b/docs/catalog-release.md @@ -34,7 +34,7 @@ All JSON inputs are strict: unknown keys are refused. Digests are 64 lowercase h - `payload` (ticket 07's upload output for the image zip): `{"url", "fileName", "sizeBytes", "sha256", "parts"?}`. `parts` (2 to 16, for a host with a file size limit) is a list of `{"url", "fileName", "sizeBytes", "sha256"}` in order; their sizes sum to `sizeBytes` and their bytes join into `sha256`. The whole-file `url` is informational when parts are given. - `installer-data`: the image's `installer_data.json` as `{"url", "fileName", "sizeBytes", "sha256"}`. - `engine`: `{"version", "url", "fileName", "sizeBytes", "sha256", "downstreamRevision"}`, optionally `asahiInstallerTag`, `asahiInstallerRevision` and `asahiInstallerDataRevision`, which default to `Engine/source-lock.json`. -- `installer`: `{"minimumVersion", "latestVersion", "downloadURL"}`, the app compatibility block. Required for engines from `v0.9.2-omarchy.18` (every current engine), whose `minimumVersion` must be 2.1.0 or later; `downloadURL` is under `.../v1/installer/` or a non-catalog release of this repository. +- `installer`: `{"minimumVersion", "latestVersion", "downloadURL"}`, the app compatibility block. Required: every engine since `.18` sends recommendation fields only app 2.1.0 and later decode, so `minimumVersion` must be 2.1.0 or later; `downloadURL` is under `.../v1/installer/` or a non-catalog release of this repository. - `evidence`: the VM evidence record below. - `dry-run`: defaults to true. diff --git a/docs/engine-versions.md b/docs/engine-versions.md new file mode 100644 index 00000000..747d467f --- /dev/null +++ b/docs/engine-versions.md @@ -0,0 +1,33 @@ +# Engine versions + +The installation engine is pinned in one place: `Engine/source-lock.json`. `downstream_overlay.version` names it, and `validation_artifact` holds its archive name, size and SHA-256. The engine's identity is its digest; the name is a label for people and release tags. + +## Names + +New engines are named `v0.9.2-omarchy..`, for example `v0.9.2-omarchy.20261014.3f9a1c2e07b4`. + +- The date is the day the name was chosen. It only helps people see which engine is newer. +- The content id is the first 12 hex characters of a SHA-256 over the lock's build inputs: the upstream installer and metadata, the downstream overlay (its files, patch, capability and modes, but not its name), the incremental base and upstream delta, the build inputs, toolchain and recipe, and the engine metadata digest. Two branches that change the engine differently get different names, so nobody has to coordinate the next number, and a rebase that changes no input keeps the id. + +Engines up to `v0.9.2-omarchy.50` keep their numeric names. Nothing compares or parses names: the catalog and the app pin the exact archive by digest, and every catalog requires app 2.1.0 or later whatever its engine is called. + +## Who reads the pin + +Nothing else in the repository carries a copy of the pin; everything reads the lock: + +- the app: `OmarchyEnginePinPlugin` generates `ValidationEngineArtifactLocator`'s version, file name, digest and size from the lock at build time; +- `Packaging/read-validation-engine.py`, which `Packaging/build-app.sh` and `Engine/prepare-engine.py` (and so `.github/workflows/mac-app-release.yml`) use; +- `Engine/rebuild-python-overlay.py`, `scripts/assemble-candidate-v8.sh` and `scripts/cutover-wizard`; +- `.github/workflows/mac-release-pipeline.yml`, whose config adds only the engine's `downstreamRevision`; +- `scripts/make-unsigned-catalog.py`. + +`Engine/tests/test_engine_pin.py`, run by `./test/all`, fails if any file outside the lock, docs and evidence repeats the engine's digest, or if a dated name's content id no longer matches the lock's build inputs. + +## Changing the engine + +1. Change the overlay and update its digests in the lock, as before. +2. `python3 Engine/engine_pin.py name --write` names the engine and its archive in the lock. +3. Rebuild the engine (`Engine/rebuild-python-overlay.py`) and record its `size_bytes` and `sha256` in `validation_artifact`. +4. `./test/all`. + +When two branches that both changed the engine meet, Git reports a conflict only in the lock (and in any overlay source both changed). Resolve the overlay sources and the lock's build inputs, then run steps 2 to 4 again: the merged engine gets a new content id, so it can never be mistaken for either branch's engine. diff --git a/docs/extraction.md b/docs/extraction.md index e008c293..265ed291 100644 --- a/docs/extraction.md +++ b/docs/extraction.md @@ -79,7 +79,7 @@ Engine `.27` stops probing stub containers. A stub carries the version of the ma Swift now withholds the resize drift margin before adopting the recommended (doubled) Omarchy size as the minimum. Adopting it first left a band of free-space states where the minimum equalled the maximum: the divider could not move and no margin remained for the engine's admission check. -The catalog's installation engine is `installer-v0.9.2-omarchy.28.tar.gz`, 17,843,348 bytes, SHA-256 `0cf1aa87760f90a545298b7cef737c9b497f2cad421d79ac59f557a81f2eb146`: the `.27` overlay with the Recovery step from #39 added. Two repacks with macOS `/usr/bin/python3` 3.9.6 produced identical bytes; compared with `.27`, only `omarchy_asahi.py`, `omarchy_runtime.py` and `version.tag` changed. The bundled inspection pins and packager select `.28` too, so the release scripts, which take the catalog engine from `Packaging/build-app.sh`, publish the engine the templates name. +The catalog's installation engine is `installer-v0.9.2-omarchy.28.tar.gz`, 17,843,348 bytes, SHA-256 `0cf1aa87760f90a545298b7cef737c9b497f2cad421d79ac59f557a81f2eb146`: the `.27` overlay with the Recovery step from #39 added. Two repacks with macOS `/usr/bin/python3` 3.9.6 produced identical bytes; compared with `.27`, only `omarchy_asahi.py`, `omarchy_runtime.py` and `version.tag` changed. The bundled inspection pins and packager select `.28` too. They now read it from `Engine/source-lock.json`, the only place the engine is pinned ([Engine versions](engine-versions.md)). ## macOS 26 firmware and MacBook Neo engine @@ -91,4 +91,4 @@ Engine `.31`, `installer-v0.9.2-omarchy.31.tar.gz`, 17,853,489 bytes, SHA-256 `d Engine `.32`, `installer-v0.9.2-omarchy.32.tar.gz`, 17,853,995 bytes, SHA-256 `12ba2f04ebdf01854cc791d89d5e577763d97453a88cc521f2092b42d30ea82c`, boots a 13-inch M3 MacBook Air (`j613ap`) on macOS 26.6.2 OS firmware through Aurora's J613 Stage 1. On 2026-10-10, a 26.6.2 restore-image stub from `.31` made iBoot panic before m1n1 ran (mBoot-18000.161.10) with asahi's Stage 1, and booted with Satya's `v1.6.1-m3next.stage1` (aurora-silicon/m1n1 `a7f0b4583150`). That image boots only a J613 with 26.6.2 and stays in proxy mode anywhere else. The J700-only Stage 1 code is now a per-board table: the Neo keeps `esp/aurora/stage1-j700.bin` with a 5000 ms proxy window, and a J613 whose chosen firmware is exactly 26.6.2 gets `esp/aurora/stage1-j613.bin` with a 0 ms window. Both are filled the same way, and the J613 fill reproduces Satya's two per-ESP filled images byte for byte. Every other Mac and firmware keeps asahi's Stage 1, including the 15-inch Air (`j615ap`) on 26.6.2. Preflight reads and test-fills the board image before any disk changes, so a 26.6.2 Air payload without `stage1-j613.bin`, or with one that can't be filled, is refused there; the Neo check moved there too. Two repacks with macOS `/usr/bin/python3` 3.9.6 produced identical bytes; compared with `.31`, only `omarchy_asahi.py` and `version.tag` changed. The packager, inspection pins and both release templates select `.32`. -Ship installer **2.1.0 or later** together with the new engine and a signed catalog whose `installer.minimumVersion` is at least **2.1.0**. Both release-input templates carry this gate, and the catalog generator refuses a lower minimum for `.18` or newer engines in this lineage. Older installers then show the update-required message before decoding recommendation fields. The bundled inspection pins now select `.31`; signed production catalogs and frozen private-test catalogs are not changed by this source update. Artifact publication, catalog signing and physical installation qualification remain separate release steps. +Ship installer **2.1.0 or later** together with the new engine and a signed catalog whose `installer.minimumVersion` is at least **2.1.0**. Both release-input templates carry this gate, and the catalog generator refuses a lower minimum for `.18` or newer engines in this lineage and for every dated engine. Older installers then show the update-required message before decoding recommendation fields. The bundled inspection pins now select `.31`; signed production catalogs and frozen private-test catalogs are not changed by this source update. Artifact publication, catalog signing and physical installation qualification remain separate release steps. diff --git a/docs/mac-release-pipeline.md b/docs/mac-release-pipeline.md index fc348053..e857c2f5 100644 --- a/docs/mac-release-pipeline.md +++ b/docs/mac-release-pipeline.md @@ -19,7 +19,7 @@ A dry run uploads to a `dryrun-` scratch release and deletes it, and signs no ca - The image never leaves Namespace: `build` (on Namespace's Apple-backed Linux ARM64 runner), `acceptance` and `upload` (on Namespace runners) pass it through Namespace's artifact storage (`namespace-actions/upload-artifact` and `download-artifact`), about 10 s for the 3.4 GB zip each way. No pull request reaches a Namespace runner: acceptance's VM job waits for its GitHub-hosted `guard`, and the build and upload jobs carry the same refusal in their own `if:` (the build also requires `main`). The small artifacts (evidence, logs) stay GitHub artifacts. - `acceptance` uploads the artifact `acceptance-evidence`, holding `acceptance-evidence.json` ([format](mac-acceptance-evidence.md)), and outputs `result`, `evidence-artifact` and `evidence-run-id` (this run). It also keeps the harness's logs as `acceptance-harness-logs`. The pipeline's `runner` input (empty by default) overrides the VM job's runner. - `upload` downloads the image and evidence artifacts from this run. After a real upload it outputs `payload` and `installer-data` (the catalog's inputs, built from the files it uploaded and verified) and `evidence` (the record it checked). -- `catalog-inputs` outputs the `engine` and `installer` blocks of `.github/mac-release-pipeline.json`. +- `catalog-inputs` outputs the catalog's `engine` block (the engine `Engine/source-lock.json` pins, with the config's `downstreamRevision`) and the `installer` block of `.github/mac-release-pipeline.json`. ## Where the jobs run @@ -35,5 +35,5 @@ The catalog takes the evidence record the upload checked, and the upload took it ## `.github/mac-release-pipeline.json` -- `engine`: the catalog's engine block ([format](catalog-release.md#inputs)). It is the engine `Packaging/build-app.sh` pins, published as the `engine-v0.9.2-omarchy.28` release. Ticket 13 moves it to `mac.omarchy.org/v1/engine/`. A test keeps this block in step with `build-app.sh` and `Engine/source-lock.json`. +- `engine`: only `{"downstreamRevision"}`. The run's engine is the one `Engine/source-lock.json` pins, the only place the engine is pinned ([Engine versions](engine-versions.md)); `catalog-inputs` adds its version, file name, size and digest, and its URL in the `engine-` release (`catalog_release.pipeline_engine`). Ticket 13 moves the archive to `mac.omarchy.org/v1/engine/`. - `installer`: the app compatibility block, `{"minimumVersion", "latestVersion", "downloadURL"}`. Until an app release from `mac-app-release.yml` is published, it is `null`, and on a real run `catalog-inputs` refuses with a message saying so, before the upload, so nothing is made public. Set it to that release's version and `.dmg` URL. diff --git a/scripts/assemble-candidate-v8.sh b/scripts/assemble-candidate-v8.sh index cf9af7c0..d5db53f6 100755 --- a/scripts/assemble-candidate-v8.sh +++ b/scripts/assemble-candidate-v8.sh @@ -121,22 +121,13 @@ verified_copy() { printf ' sha256 %s %s bytes\n' "$after" "$after_size" } -# Pull a shell assignment out of build-app.sh so the engine identity is read -# from the app package's own pin rather than restated here. -read_pinned_value() { - local file=$1 name=$2 value - value=$( - awk -v name="$name" ' - $0 ~ "^" name "=" { - line = $0 - sub("^" name "=", "", line) - gsub(/^"|"$/, "", line) - print line - exit - } - ' "$file" - ) - [[ -n $value ]] || die "cannot read $name from $file" +# Read the engine identity from the app package's own pin, Engine/source-lock.json, +# rather than restating it here. +read_lock_value() { + local file=$1 section=$2 key=$3 value + value=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))[sys.argv[2]][sys.argv[3]])' "$file" "$section" "$key" 2>/dev/null) || + die "could not read $section.$key from $file" + [[ -n $value ]] || die "empty $section.$key in $file" printf '%s\n' "$value" } @@ -251,10 +242,12 @@ main() { [[ $out != */ ]] || die "--out must not end with a slash" # ---- engine identity, read from the app package's own pin -------------- - step "Engine pin (from $build_app)" + local source_lock="$app_package/Engine/source-lock.json" + require_regular_file "$source_lock" + step "Engine pin (from $source_lock)" local engine_name engine_digest_pin engine_source engine_digest - engine_name=$(read_pinned_value "$build_app" engine_file_name) || exit 1 - engine_digest_pin=$(read_pinned_value "$build_app" engine_digest) || exit 1 + engine_name=$(read_lock_value "$source_lock" validation_artifact filename) || exit 1 + engine_digest_pin=$(read_lock_value "$source_lock" validation_artifact sha256) || exit 1 engine_source="$app_package/Engine/artifacts/$engine_name" require_regular_file "$engine_source" engine_digest=$(file_digest "$engine_source") @@ -262,7 +255,7 @@ main() { echo " pinned $engine_digest_pin" echo " actual $engine_digest" [[ $engine_digest == "$engine_digest_pin" ]] || - die "engine at $engine_source does not match the pin in build-app.sh" + die "engine at $engine_source does not match the pin in $source_lock" # ---- metadata agreement ------------------------------------------------- step "Installer metadata agreement" @@ -284,15 +277,12 @@ main() { # ---- generator name agreement ------------------------------------------ step "Catalog inputs name agreement" - local generator_payload generator_engine generator_metadata generator_evidence + local generator_payload generator_metadata generator_evidence generator_payload=$(read_release_input "$release_inputs" payload_name) || exit 1 - generator_engine=$(read_release_input "$release_inputs" engine_name) || exit 1 generator_metadata=$(read_release_input "$release_inputs" metadata_name) || exit 1 generator_evidence=$(read_release_input "$release_inputs" evidence_revision) || exit 1 [[ $generator_payload == "$payload_name" ]] || warn "release inputs pin payload_name=$generator_payload but this payload is $payload_name; update the inputs before generating the catalog" - [[ $generator_engine == "$engine_name" ]] || - warn "release inputs pin engine_name=$generator_engine but the app package pins $engine_name" [[ $generator_metadata == "installer_data.json" ]] || warn "release inputs pin metadata_name=$generator_metadata" case $generator_evidence in @@ -401,7 +391,7 @@ notarized, or connected to any device. | Installer metadata | \`installer_data.json\`, \`$metadata_size\` bytes | | — SHA-256 | \`$(file_digest "$out/engine/installer_data.json")\` | | Engine | \`$engine_name\`, \`$engine_size\` bytes | -| — SHA-256 | \`$engine_digest\` (matches the pin in \`Packaging/build-app.sh\`) | +| — SHA-256 | \`$engine_digest\` (matches the pin in \`Engine/source-lock.json\`) | ## Verification performed by the assembler @@ -409,8 +399,8 @@ notarized, or connected to any device. re-digested **after**; sizes were compared too. Any drift is a hard error. - Copies preferred an APFS clone (\`cp -c\`) and fell back to a plain \`cp\` where cloning is unavailable. Clones: $clone_copies. Plain copies: $plain_copies. -- The engine digest was checked against the pin hard-coded in - \`Packaging/build-app.sh\` before embedding. +- The engine digest was checked against the pin in + \`Engine/source-lock.json\` before embedding. - The payload's \`installer-data.json\` sidecar was compared byte-for-byte with the app package's \`Engine/installer_data.json\` (the bytes the catalog binds). - The catalog generator's pinned \`PAYLOAD_NAME\`/\`ENGINE_NAME\` constants were diff --git a/scripts/catalog_release.py b/scripts/catalog_release.py index 8a415ea5..91c68e70 100644 --- a/scripts/catalog_release.py +++ b/scripts/catalog_release.py @@ -235,20 +235,42 @@ def check_engine(document: object) -> dict: return resolved +def pipeline_engine(document: object) -> dict: + """The engine block for .github/mac-release-pipeline.json's run: the pin + from Engine/source-lock.json, the only place the engine is pinned, plus the + config's downstreamRevision. The archive is served from its engine- + release of this repository until mac.omarchy.org hosts it.""" + document = check_keys(document, "engine", {"downstreamRevision"}) + lock = json.loads(SOURCE_LOCK.read_text()) + version = lock["downstream_overlay"]["version"] + artifact = lock["validation_artifact"] + engine = { + "version": version, + "url": f"https://github.com/{stopgap_repo()}/releases/download/engine-{version}/{artifact['filename']}", + "fileName": artifact["filename"], + "sizeBytes": artifact["size_bytes"], + "sha256": artifact["sha256"], + "downstreamRevision": document["downstreamRevision"], + } + check_engine(engine) + return engine + + def version_tuple(value: str) -> tuple[int, ...]: return tuple(int(part) for part in value.split(".")) -def check_installer(document: object, engine_version: str) -> dict: +def check_installer(document: object) -> dict: document = check_keys(document, "installer", {"minimumVersion", "latestVersion", "downloadURL"}) for key in ("minimumVersion", "latestVersion"): if not isinstance(document[key], str) or not INSTALLER_VERSION.match(document[key]): raise Refusal(f"installer.{key} must look like X.Y.Z") if version_tuple(document["minimumVersion"]) > version_tuple(document["latestVersion"]): raise Refusal("installer.minimumVersion is newer than installer.latestVersion") - engine = re.fullmatch(r"v0\.9\.2-omarchy\.(\d+)", engine_version) - if engine and int(engine.group(1)) >= 18 and version_tuple(document["minimumVersion"]) < (2, 1, 0): - raise Refusal("this engine requires installer.minimumVersion >= 2.1.0") + # Every engine since .18 sends recommendation fields that only app 2.1.0 + # and later decode, so every catalog turns older apps away. + if version_tuple(document["minimumVersion"]) < (2, 1, 0): + raise Refusal("every catalog needs app 2.1.0 or later: installer.minimumVersion must be at least 2.1.0") check_url(document["downloadURL"], "installer.downloadURL", installer_bases()) return document @@ -348,7 +370,7 @@ def build_catalog( engine: dict, metadata: dict, evidence: object, - installer: dict | None, + installer: dict, now: datetime.datetime, ) -> dict: check_channel(channel) @@ -357,10 +379,7 @@ def build_catalog( metadata = check_artifact(metadata, "installer_data") engine = check_engine(engine) check_evidence(evidence, payload["sha256"]) - if installer is not None: - installer = check_installer(installer, engine["version"]) - elif re.fullmatch(r"v0\.9\.2-omarchy\.(1[89]|[2-9][0-9]|[1-9][0-9]{2,})", engine["version"]): - raise Refusal("this engine needs app 2.1.0 or later: pass installer with minimumVersion >= 2.1.0") + installer = check_installer(installer) def plain(artifact: dict) -> dict: return {"sourceURL": artifact["url"], "fileName": artifact["fileName"], "sizeBytes": artifact["sizeBytes"]} @@ -399,8 +418,7 @@ def plain(artifact: dict) -> dict: "sequence": int(now.timestamp()), "issuedAt": now.strftime("%Y-%m-%dT%H:%M:%SZ"), } - if installer is not None: - catalog["installer"] = installer + catalog["installer"] = installer catalog["models"] = models errors = supported_models.catalog_errors(catalog) if errors: @@ -874,7 +892,7 @@ def command_prepare(arguments) -> None: engine = load_json(arguments.engine, "engine") metadata = load_json(arguments.installer_data, "installer_data") evidence = load_json(arguments.evidence, "evidence") if arguments.evidence else None - installer = load_json(arguments.installer, "installer") if arguments.installer else None + installer = load_json(arguments.installer, "installer") catalog = build_catalog(channel, arguments.image, payload, engine, metadata, evidence, installer, now) if arguments.verify_remote: verify_remote_artifact(check_artifact(payload, "payload", True), "payload") @@ -1095,7 +1113,7 @@ def parse_arguments(argv: list[str]): prepare.add_argument("--engine", type=Path, required=True) prepare.add_argument("--installer-data", type=Path, required=True) prepare.add_argument("--evidence", type=Path) - prepare.add_argument("--installer", type=Path) + prepare.add_argument("--installer", type=Path, required=True) prepare.add_argument("--verify-remote", action="store_true") prepare.add_argument("--check-live", action="store_true") prepare.add_argument("--host", default="github-release") diff --git a/scripts/cutover-wizard b/scripts/cutover-wizard index 6c0a2051..c29d3ab6 100755 --- a/scripts/cutover-wizard +++ b/scripts/cutover-wizard @@ -204,11 +204,11 @@ OS_TAG="os-v4.0.2-mac.1.20260902" APP_VERSION="${OMARCHY_APP_VERSION:-2.1.0}" APP_BUILD="${OMARCHY_APP_BUILD_NUMBER:-28}" PAYLOAD="omarchy-2026.09.02-aarch64-apple-silicon-asahi-os-package.zip" -# The engine is whatever every build pins in Packaging/build-app.sh, read from +# The engine is whatever every build pins in Engine/source-lock.json, read from # there so a change to the pinned engine never has to be repeated here. -ENGINE=$(sed -n 's/^engine_file_name="\(.*\)"$/\1/p' "$APP_DIR/Packaging/build-app.sh") +ENGINE=$(plutil -extract validation_artifact.filename raw -o - "$APP_DIR/Engine/source-lock.json") [[ $ENGINE == installer-*.tar.gz ]] || { - echo "cutover-wizard: can't read the pinned engine from Packaging/build-app.sh" >&2 + echo "cutover-wizard: can't read the pinned engine from Engine/source-lock.json" >&2 exit 1 } ENGINE_SIZE=$(stat -f %z "$APP_DIR/Engine/artifacts/$ENGINE" 2>/dev/null) || { diff --git a/scripts/make-unsigned-catalog.py b/scripts/make-unsigned-catalog.py index c7656b4d..c0d1a683 100755 --- a/scripts/make-unsigned-catalog.py +++ b/scripts/make-unsigned-catalog.py @@ -8,7 +8,8 @@ Every per-release value comes from an inputs file (`--inputs`), so cutting a release never edits this script. `scripts/release-inputs.template.json` holds -the current values. The inputs must list exactly the Macs in +the current values. The engine is always the one `Engine/source-lock.json` +pins. The inputs must list exactly the Macs in `scripts/supported-models.json`: every M1, M2 and M3 Mac, none refused. The catalog pins whole-file digests. When the payload was split for release @@ -49,9 +50,7 @@ REQUIRED_INPUT_KEYS = frozenset( { "payload_name", - "engine_name", "metadata_name", - "engine_version", "evidence_revision", "asahi_installer_tag", "asahi_installer_revision", @@ -61,6 +60,8 @@ "installer", } ) +# The only place the engine is pinned (docs/engine-versions.md). +SOURCE_LOCK = Path(__file__).resolve().parents[1] / "Engine" / "source-lock.json" REQUIRED_INSTALLER_KEYS = frozenset( {"minimum_version", "latest_version", "download_url"} ) @@ -241,6 +242,9 @@ def load_inputs(path: Path, developer: bool = False) -> dict: unknown = keys - REQUIRED_INPUT_KEYS - ({"developer_models"} if developer else set()) if unknown: raise SystemExit(f"inputs file has unknown keys: {', '.join(sorted(unknown))}") + lock = json.loads(SOURCE_LOCK.read_text()) + document["engine_name"] = lock["validation_artifact"]["filename"] + document["engine_version"] = lock["downstream_overlay"]["version"] for key in ( "payload_name", @@ -313,11 +317,10 @@ def load_inputs(path: Path, developer: bool = False) -> dict: raise SystemExit( "inputs installer.minimum_version is newer than installer.latest_version" ) - # Engines with recommendation fields require the compatible decoder and - # reserve-policy UI. Refuse a catalog that sends older apps into decoding. - engine = re.fullmatch(r"v0\.9\.2-omarchy\.(\d+)", document["engine_version"]) - if engine and int(engine.group(1)) >= 18 and parse_version(installer["minimum_version"]) < (2, 1, 0): - raise SystemExit("this engine requires installer.minimum_version >= 2.1.0") + # Every engine since .18 sends recommendation fields that only app 2.1.0 + # and later decode, so every catalog turns older apps away. + if parse_version(installer["minimum_version"]) < (2, 1, 0): + raise SystemExit("every catalog needs installer.minimum_version >= 2.1.0") download_url = installer["download_url"] if not isinstance(download_url, str) or not download_url.startswith("https://"): raise SystemExit(f"inputs installer.download_url must be https: {download_url}") diff --git a/scripts/release-inputs-aurora.template.json b/scripts/release-inputs-aurora.template.json index 3f4399d6..16424144 100644 --- a/scripts/release-inputs-aurora.template.json +++ b/scripts/release-inputs-aurora.template.json @@ -1,8 +1,6 @@ { "payload_name": "omarchy-2026.09.13-aarch64-apple-silicon-aurora-os-package.zip", - "engine_name": "installer-v0.9.2-omarchy.50.tar.gz", "metadata_name": "installer_data.json", - "engine_version": "v0.9.2-omarchy.50", "evidence_revision": "4.0.3-mac.2.20260913-aurora", "asahi_installer_tag": "v0.9.2", "asahi_installer_revision": "dffbb38ef0c00c0431c609ecd8a00f42deb5b24c", diff --git a/scripts/release-inputs.template.json b/scripts/release-inputs.template.json index f6949956..17d8127f 100644 --- a/scripts/release-inputs.template.json +++ b/scripts/release-inputs.template.json @@ -1,8 +1,6 @@ { "payload_name": "omarchy-2026.09.13-aarch64-apple-silicon-asahi-os-package.zip", - "engine_name": "installer-v0.9.2-omarchy.50.tar.gz", "metadata_name": "installer_data.json", - "engine_version": "v0.9.2-omarchy.50", "evidence_revision": "4.0.3-mac.1.20260913", "asahi_installer_tag": "v0.9.2", "asahi_installer_revision": "dffbb38ef0c00c0431c609ecd8a00f42deb5b24c", diff --git a/scripts/tests/test_catalog_release.py b/scripts/tests/test_catalog_release.py index e7115323..88b3e000 100644 --- a/scripts/tests/test_catalog_release.py +++ b/scripts/tests/test_catalog_release.py @@ -318,7 +318,7 @@ def test_refuses_inconsistent_parts(self) -> None: def test_refuses_another_channel_or_image_name(self) -> None: result = self.run_tool("prepare", "--channel", "stable", "--image", IMAGE, "--payload", "x", - "--engine", "x", "--installer-data", "x", "--out", str(self.directory / "o")) + "--engine", "x", "--installer-data", "x", "--installer", "x", "--out", str(self.directory / "o")) self.assert_refused(result, "rc and stable come from promotion") with self.assertRaisesRegex(release.Refusal, "image must be"): release.check_image_name("omarchy-mac-edge-latest", "edge") @@ -807,5 +807,6 @@ def test_a_promotion_must_follow_the_published_target(self) -> None: self.assert_refused(self.promote("rc", "edge", LATER, "older"), "does not follow the published rc") + if __name__ == "__main__": unittest.main() diff --git a/scripts/tests/test_mac_upload.py b/scripts/tests/test_mac_upload.py index b17ad845..0e652d41 100644 --- a/scripts/tests/test_mac_upload.py +++ b/scripts/tests/test_mac_upload.py @@ -352,7 +352,7 @@ def test_a_split_image_becomes_a_payload_with_parts_the_catalog_accepts(self): self.assertEqual(part["url"], base + part["fileName"]) self.assertEqual(inputs["installer_data"]["url"], base + "installer_data.json") catalog = load("catalog_release", SCRIPTS / "catalog_release.py") - engine = json.loads((SCRIPTS.parent / ".github" / "mac-release-pipeline.json").read_text())["engine"] + engine = catalog.pipeline_engine(json.loads((SCRIPTS.parent / ".github" / "mac-release-pipeline.json").read_text())["engine"]) installer = {"minimumVersion": "2.1.0", "latestVersion": "2.1.0", "downloadURL": self.BASE.format("v2.1.0") + "app.dmg"} document = catalog.build_catalog("edge", self.image, payload, engine, inputs["installer_data"], fixture.evidence(self.sha256, RUN_URL), installer, diff --git a/scripts/tests/test_make_unsigned_catalog.py b/scripts/tests/test_make_unsigned_catalog.py index 5f81cecf..a9918fac 100644 --- a/scripts/tests/test_make_unsigned_catalog.py +++ b/scripts/tests/test_make_unsigned_catalog.py @@ -12,6 +12,7 @@ SCRIPT = Path(__file__).resolve().parents[1] / "make-unsigned-catalog.py" TEMPLATE = Path(__file__).resolve().parents[1] / "release-inputs.template.json" +LOCK = Path(__file__).resolve().parents[2] / "Engine" / "source-lock.json" MANIFEST = Path(__file__).resolve().parents[1] / "supported-models.json" M3_MACS = [ "apple,j433", "apple,j434", "apple,j504", "apple,j613", "apple,j615", @@ -30,7 +31,10 @@ def setUp(self) -> None: self.assets = self.directory / "assets" self.assets.mkdir() self.inputs = json.loads(TEMPLATE.read_text()) - for key in ("engine_name", "metadata_name", "payload_name"): + self.lock = json.loads(LOCK.read_text()) + self.engine_name = self.lock["validation_artifact"]["filename"] + (self.assets / self.engine_name).write_bytes(b"engine_name" * 64) + for key in ("metadata_name", "payload_name"): (self.assets / self.inputs[key]).write_bytes(key.encode() * 64) def write_inputs(self, document: dict | None = None) -> Path: @@ -85,9 +89,9 @@ def assertRejected(self, document: dict, fragment: str, developer: bool = False) self.assertNotEqual(result.returncode, 0, result.stdout) self.assertIn(fragment, result.stderr) - def test_recommendation_engine_rejects_old_installer_minimum(self): + def test_every_catalog_rejects_an_installer_minimum_before_2_1(self): self.inputs["installer"]["minimum_version"] = "2.0.10" - self.assertRejected(self.inputs, "requires installer.minimum_version >= 2.1.0") + self.assertRejected(self.inputs, "needs installer.minimum_version >= 2.1.0") def test_emits_schema_four_without_an_expiry(self) -> None: result = self.generate() @@ -162,9 +166,22 @@ def test_an_unknown_inputs_key_is_rejected(self) -> None: def test_a_missing_inputs_key_is_rejected(self) -> None: document = dict(self.inputs) - del document["engine_version"] + del document["metadata_name"] self.assertRejected(document, "missing keys") + def test_the_engine_is_the_source_locks(self) -> None: + self.assertNotIn("engine_name", self.inputs) + result = self.generate() + self.assertEqual(result.returncode, 0, result.stderr) + model = json.loads((self.directory / "catalog.json").read_text())["models"][0] + self.assertEqual(model["engineVersion"], self.lock["downstream_overlay"]["version"]) + self.assertEqual(model["engineArtifact"]["fileName"], self.engine_name) + + def test_inputs_cannot_name_another_engine(self) -> None: + for key in ("engine_name", "engine_version"): + with self.subTest(key): + self.assertRejected({**self.inputs, key: "v0.9.2-omarchy.27"}, "unknown keys") + def test_a_minimum_newer_than_the_latest_is_rejected(self) -> None: document = json.loads(json.dumps(self.inputs)) document["installer"]["minimum_version"] = "3.0.0" diff --git a/scripts/tests/test_release_pipeline.py b/scripts/tests/test_release_pipeline.py index 7b0ea458..3fe19ccc 100644 --- a/scripts/tests/test_release_pipeline.py +++ b/scripts/tests/test_release_pipeline.py @@ -660,7 +660,10 @@ def setUp(self) -> None: self.config = json.loads(CONFIG.read_text()) def test_the_engine_is_the_one_the_app_pins(self): - engine = self.config["engine"] + # The config names no engine: the run takes the one the source lock + # pins, which build-app.sh and the app also read. + self.assertEqual(set(self.config["engine"]), {"downstreamRevision"}) + engine = catalog.pipeline_engine(self.config["engine"]) build_app = (ROOT / "Packaging" / "build-app.sh").read_text() self.assertIn('python3 "$script_directory/read-validation-engine.py"', build_app) name, digest, size = subprocess.check_output( @@ -672,14 +675,19 @@ def test_the_engine_is_the_one_the_app_pins(self): self.assertEqual((lock["validation_artifact"]["filename"], lock["validation_artifact"]["size_bytes"], lock["validation_artifact"]["sha256"], lock["downstream_overlay"]["version"]), (engine["fileName"], engine["sizeBytes"], engine["sha256"], engine["version"])) + self.assertEqual(engine["url"], f"https://github.com/{catalog.stopgap_repo()}/releases/download/" + f"engine-{engine['version']}/{engine['fileName']}") template = json.loads((SCRIPTS / "release-inputs.template.json").read_text()) self.assertEqual(engine["downstreamRevision"], template["downstream_revision"]) - catalog.check_engine(engine) + + def test_the_config_cannot_pin_an_engine_of_its_own(self): + with self.assertRaises(catalog.Refusal): + catalog.pipeline_engine({**self.config["engine"], "version": "v0.9.2-omarchy.28"}) def test_the_app_block_is_unset_or_one_the_catalog_takes(self): self.assertEqual(set(self.config), {"engine", "installer"}) if self.config["installer"] is not None: - catalog.check_installer(self.config["installer"], self.config["engine"]["version"]) + catalog.check_installer(self.config["installer"]) @@ -692,6 +700,7 @@ def setUp(self) -> None: self.directory = Path(tempfile.mkdtemp(prefix="omarchy-release-pipeline-")) self.addCleanup(shutil.rmtree, self.directory) self.engine = json.loads(CONFIG.read_text())["engine"] + self.pinned = catalog.pipeline_engine(self.engine) def run_step(self, installer, dry_run: str, engine=None) -> tuple[int, str]: config = self.directory / "config.json" @@ -719,7 +728,8 @@ def test_a_dry_run_without_an_app_release_goes_on(self): def test_a_malformed_block_stops_a_real_run(self): for installer, engine in (({**self.installer(), "minimumVersion": "2.0.0"}, None), ({**self.installer(), "downloadURL": "https://example.invalid/app.dmg"}, None), - (self.installer(), {**self.engine, "sha256": "nope"})): + (self.installer(), {**self.engine, "downstreamRevision": "nope"}), + (self.installer(), {**self.engine, "sha256": "0" * 64})): with self.subTest(installer=installer, engine=engine): self.assertNotEqual(self.run_step(installer, "false", engine)[0], 0) @@ -727,7 +737,7 @@ def test_a_good_block_becomes_the_catalogs_inputs(self): status, output = self.run_step(self.installer(), "false") self.assertEqual(status, 0, output) lines = dict(line.split("=", 1) for line in output.splitlines() if "=" in line and not line.startswith("::")) - self.assertEqual(json.loads(lines["engine"]), self.engine) + self.assertEqual(json.loads(lines["engine"]), self.pinned) self.assertEqual(json.loads(lines["installer"]), self.installer()) if __name__ == "__main__": From d3e9c8d058c26f66f72080b08f0970f57ca63c9e Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Sun, 18 Oct 2026 22:22:11 -0500 Subject: [PATCH 2/2] Refuse undated engine names, and check the catalog's engine against the lock engine_pin.py check verified only dated names, so a hand-picked .51, a malformed dated name, or .50 with changed inputs passed. Now .50 passes only with the inputs it was built from (LEGACY freezes their content id, 2ede760866d5), a dated name needs a real date and a matching content id, and any other name is refused. make-unsigned-catalog.py took the engine's name from the lock but digested whatever archive had that name. It now refuses one whose size or sha256 isn't the lock's. docs/engine-versions.md: the legacy rule, and step 5, publishing the engine- release that pipeline_engine's URL names before a pipeline run. Co-Authored-By: Claude Opus 5.5 --- Engine/engine_pin.py | 36 +++++++++++++++------ Engine/tests/test_engine_pin.py | 26 +++++++++++++++ docs/engine-versions.md | 7 ++-- scripts/make-unsigned-catalog.py | 4 +++ scripts/tests/test_make_unsigned_catalog.py | 27 ++++++++++++++-- 5 files changed, 86 insertions(+), 14 deletions(-) diff --git a/Engine/engine_pin.py b/Engine/engine_pin.py index a4d725d0..3ff06b7d 100755 --- a/Engine/engine_pin.py +++ b/Engine/engine_pin.py @@ -13,8 +13,9 @@ --write puts the name (and the matching archive file name) in the lock. engine_pin.py check - Fail if a dated name's content id does not match the lock's build inputs, or if - the archive name does not follow the name. + Fail unless the name is a dated name whose date is real and whose content id matches + the lock's build inputs, or the one engine named before dated names (LEGACY) with the + inputs it was built from; and fail if the archive name does not follow the name. After merging two branches that both changed the engine: resolve the lock's build inputs, run `name --write`, rebuild the engine and record its size and digest. @@ -34,6 +35,11 @@ BASE = "v0.9.2-omarchy" DATED = re.compile(r"v0\.9\.2-omarchy\.(\d{8})\.([0-9a-f]{12})") +# The last engine named by number, frozen with the content id of the inputs it +# was built from (.50 rebuilds byte-identical from them). Any input change +# under this name, and any other name that isn't dated, fails `check`. +LEGACY = {"v0.9.2-omarchy.50": "2ede760866d5"} + # The lock's build inputs. Everything else in it either describes the result # (the name and the artifact) or is prose. INPUTS = ( @@ -83,13 +89,25 @@ def dump_json(document): def check(lock): problems = [] version = lock["downstream_overlay"]["version"] - # Engines named before dated names (v0.9.2-omarchy.50 and earlier) pass - # until the next engine change renames them. - if (match := DATED.fullmatch(version)) and match.group(2) != content_id(lock): - problems.append( - f"{version} names content {match.group(2)}, but the lock's build inputs are {content_id(lock)}; " - "run `engine_pin.py name --write`" - ) + actual = content_id(lock) + rename = "run `engine_pin.py name --write`" + if version in LEGACY: + if LEGACY[version] != actual: + problems.append( + f"{version} was built from inputs {LEGACY[version]}, but the lock's build inputs are {actual}; " + + rename + ) + elif match := DATED.fullmatch(version): + try: + datetime.strptime(match.group(1), "%Y%m%d") + except ValueError: + problems.append(f"{version} names an impossible date; " + rename) + if match.group(2) != actual: + problems.append( + f"{version} names content {match.group(2)}, but the lock's build inputs are {actual}; " + rename + ) + else: + problems.append(f"{version} is not a dated engine name ({BASE}..); " + rename) filename = lock["validation_artifact"]["filename"] if filename != archive_name(version): problems.append(f"validation_artifact.filename is {filename}, expected {archive_name(version)}") diff --git a/Engine/tests/test_engine_pin.py b/Engine/tests/test_engine_pin.py index b8a55ee8..6bb6bf38 100644 --- a/Engine/tests/test_engine_pin.py +++ b/Engine/tests/test_engine_pin.py @@ -72,6 +72,32 @@ def test_a_dated_name_must_match_the_lock_inputs(self): problems = PIN.check(other) self.assertTrue(any("names content 000000000000" in problem for problem in problems), problems) + def renamed(self, version): + other = copy.deepcopy(self.lock) + other["downstream_overlay"]["version"] = version + other["validation_artifact"]["filename"] = PIN.archive_name(version) + return other + + def test_the_legacy_engine_passes_only_with_the_inputs_it_was_built_from(self): + for version, built_from in PIN.LEGACY.items(): + with self.subTest(version): + other = self.renamed(version) + other["downstream_overlay"]["files"][0]["sha256"] = "1" * 64 + self.assertNotEqual(PIN.content_id(other), built_from) + problems = PIN.check(other) + self.assertTrue(any(f"built from inputs {built_from}" in problem for problem in problems), problems) + + def test_names_that_are_not_dated_are_refused(self): + for version in ("v0.9.2-omarchy.51", "v0.9.2-omarchy.20261019.bad", "v0.9.2-omarchy.20261019", + f"v0.9.2-omarchy.20261019.{PIN.content_id(self.lock).upper()}"): + with self.subTest(version): + problems = PIN.check(self.renamed(version)) + self.assertTrue(any("is not a dated engine name" in problem for problem in problems), problems) + + def test_a_dated_name_with_an_impossible_date_is_refused(self): + problems = PIN.check(self.renamed(f"v0.9.2-omarchy.20261399.{PIN.content_id(self.lock)}")) + self.assertTrue(any("impossible date" in problem for problem in problems), problems) + def test_the_archive_name_must_follow_the_version(self): other = copy.deepcopy(self.lock) other["validation_artifact"]["filename"] = "installer-something-else.tar.gz" diff --git a/docs/engine-versions.md b/docs/engine-versions.md index 747d467f..ade8ca4c 100644 --- a/docs/engine-versions.md +++ b/docs/engine-versions.md @@ -9,7 +9,7 @@ New engines are named `v0.9.2-omarchy..`, for example `v0. - The date is the day the name was chosen. It only helps people see which engine is newer. - The content id is the first 12 hex characters of a SHA-256 over the lock's build inputs: the upstream installer and metadata, the downstream overlay (its files, patch, capability and modes, but not its name), the incremental base and upstream delta, the build inputs, toolchain and recipe, and the engine metadata digest. Two branches that change the engine differently get different names, so nobody has to coordinate the next number, and a rebase that changes no input keeps the id. -Engines up to `v0.9.2-omarchy.50` keep their numeric names. Nothing compares or parses names: the catalog and the app pin the exact archive by digest, and every catalog requires app 2.1.0 or later whatever its engine is called. +`v0.9.2-omarchy.50`, the last engine named by number, keeps its name only while the lock holds the inputs it was built from: `Engine/engine_pin.py` freezes their content id in `LEGACY`. `check` refuses every other name that isn't a well-formed dated one, such as a hand-picked `.51`. So the next engine change must take a dated name. Nothing compares or parses names: the catalog and the app pin the exact archive by digest, and every catalog requires app 2.1.0 or later whatever its engine is called. ## Who reads the pin @@ -21,7 +21,7 @@ Nothing else in the repository carries a copy of the pin; everything reads the l - `.github/workflows/mac-release-pipeline.yml`, whose config adds only the engine's `downstreamRevision`; - `scripts/make-unsigned-catalog.py`. -`Engine/tests/test_engine_pin.py`, run by `./test/all`, fails if any file outside the lock, docs and evidence repeats the engine's digest, or if a dated name's content id no longer matches the lock's build inputs. +`Engine/tests/test_engine_pin.py`, run by `./test/all`, fails if any file outside the lock, docs and evidence repeats the engine's digest, or if `engine_pin.py check` finds a problem: a name that is neither dated nor `LEGACY`, an impossible date, or a content id that no longer matches the lock's build inputs. `scripts/make-unsigned-catalog.py` also refuses an engine archive whose size or SHA-256 isn't the lock's. ## Changing the engine @@ -29,5 +29,6 @@ Nothing else in the repository carries a copy of the pin; everything reads the l 2. `python3 Engine/engine_pin.py name --write` names the engine and its archive in the lock. 3. Rebuild the engine (`Engine/rebuild-python-overlay.py`) and record its `size_bytes` and `sha256` in `validation_artifact`. 4. `./test/all`. +5. Before the release pipeline runs on it, publish the archive as this repository's `engine-` release. `catalog_release.pipeline_engine` builds the engine URL from that release name, and `mac-catalog.yml`'s `--verify-remote` refuses a missing or different archive. When mac.omarchy.org hosts engines, that URL changes in `pipeline_engine`, not in the config. -When two branches that both changed the engine meet, Git reports a conflict only in the lock (and in any overlay source both changed). Resolve the overlay sources and the lock's build inputs, then run steps 2 to 4 again: the merged engine gets a new content id, so it can never be mistaken for either branch's engine. +When two branches that both changed the engine meet, Git reports a conflict only in the lock (and in any overlay source both changed). Resolve the overlay sources and the lock's build inputs, then run steps 2 to 5 again: the merged engine gets a new content id, so it can never be mistaken for either branch's engine. diff --git a/scripts/make-unsigned-catalog.py b/scripts/make-unsigned-catalog.py index c0d1a683..29419971 100755 --- a/scripts/make-unsigned-catalog.py +++ b/scripts/make-unsigned-catalog.py @@ -245,6 +245,7 @@ def load_inputs(path: Path, developer: bool = False) -> dict: lock = json.loads(SOURCE_LOCK.read_text()) document["engine_name"] = lock["validation_artifact"]["filename"] document["engine_version"] = lock["downstream_overlay"]["version"] + document["engine_identity"] = (lock["validation_artifact"]["size_bytes"], lock["validation_artifact"]["sha256"]) for key in ( "payload_name", @@ -391,6 +392,9 @@ def issue_time(override: str | None) -> datetime.datetime: def model_group(inputs: dict, group: dict, assets: Path, base_url: str) -> tuple[list[dict], int]: """The catalog models for one payload's boards, and its payload part count.""" engine = require_regular_file(assets / inputs["engine_name"]) + # The archive under the lock's name must be the lock's engine. + if (engine.stat().st_size, digest(engine)) != inputs["engine_identity"]: + raise SystemExit(f"{engine.name} is not the engine Engine/source-lock.json pins (size or sha256 differs)") metadata = require_regular_file(assets / group["metadata_name"]) payload = require_regular_file(assets / group["payload_name"]) diff --git a/scripts/tests/test_make_unsigned_catalog.py b/scripts/tests/test_make_unsigned_catalog.py index a9918fac..9316be79 100644 --- a/scripts/tests/test_make_unsigned_catalog.py +++ b/scripts/tests/test_make_unsigned_catalog.py @@ -4,6 +4,7 @@ import hashlib import json +import shutil import subprocess import sys import tempfile @@ -33,10 +34,25 @@ def setUp(self) -> None: self.inputs = json.loads(TEMPLATE.read_text()) self.lock = json.loads(LOCK.read_text()) self.engine_name = self.lock["validation_artifact"]["filename"] - (self.assets / self.engine_name).write_bytes(b"engine_name" * 64) + engine = b"engine_name" * 64 + (self.assets / self.engine_name).write_bytes(engine) + # The generator checks the engine against the lock beside it, so it + # runs from a copy whose lock pins this stand-in engine. + self.script = self.pinned_generator(len(engine), hashlib.sha256(engine).hexdigest()) for key in ("metadata_name", "payload_name"): (self.assets / self.inputs[key]).write_bytes(key.encode() * 64) + def pinned_generator(self, size: int, sha256: str) -> Path: + root = self.directory / "repository" + (root / "scripts").mkdir(parents=True, exist_ok=True) + (root / "Engine").mkdir(exist_ok=True) + for name in ("make-unsigned-catalog.py", "supported_models.py", "supported-models.json"): + shutil.copy2(SCRIPT.with_name(name), root / "scripts" / name) + lock = json.loads(LOCK.read_text()) + lock["validation_artifact"].update(size_bytes=size, sha256=sha256) + (root / "Engine" / "source-lock.json").write_text(json.dumps(lock, indent=2)) + return root / "scripts" / SCRIPT.name + def write_inputs(self, document: dict | None = None) -> Path: path = self.directory / "inputs.json" path.write_text(json.dumps(document or self.inputs, indent=2)) @@ -51,7 +67,7 @@ def generate( return subprocess.run( [ sys.executable, - str(SCRIPT), + str(self.script), "--base-url", BASE_URL, "--assets-dir", @@ -177,6 +193,13 @@ def test_the_engine_is_the_source_locks(self) -> None: self.assertEqual(model["engineVersion"], self.lock["downstream_overlay"]["version"]) self.assertEqual(model["engineArtifact"]["fileName"], self.engine_name) + def test_an_archive_that_is_not_the_locks_engine_is_refused(self) -> None: + engine = self.assets / self.engine_name + for name, contents in (("digest", b"Engine_name" * 64), ("size", b"engine_name" * 65)): + with self.subTest(name): + engine.write_bytes(contents) + self.assertRejected(self.inputs, "is not the engine Engine/source-lock.json pins") + def test_inputs_cannot_name_another_engine(self) -> None: for key in ("engine_name", "engine_version"): with self.subTest(key):