The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
perf(release): stage candidates from metadata; verify package bytes at publish
ethernetfa6a127ed6cb
diff --git a/scripts/bundles/release_artifacts.py b/scripts/bundles/release_artifacts.pyindex 724df9c8a79..03a62aa676e 100644--- a/scripts/bundles/release_artifacts.py+++ b/scripts/bundles/release_artifacts.py@@ -196,18 +196,18 @@ def assemble(root: Path, tag: str, commit: str, public_base: str, out: Path,if prior is not None and prior != row:raise ValueError("Candidate handoffs disagree on file receipts")by_name[row["path"]] = row+ # Package bytes stay bound by their receipt digests; publish() downloads and+ # checks them, and the universal bundle's identity, before anything goes live.rows = []for name, receipt in sorted(by_name.items()):- if name.startswith("metadata-") or name.endswith(".msixbundle"):+ if name.startswith("metadata-"):file = root / nameif not file.is_file() or sha256_file(file) != receipt["sha256"]:raise ValueError(f"Candidate local digest mismatch: {name}")- if name.startswith("metadata-"):- rows.append(json.loads(file.read_text(encoding="utf-8-sig")))+ rows.append(json.loads(file.read_text(encoding="utf-8-sig")))universal_name = Noneif "windows" in lanes:universal_name = single(name for name in by_name if name.endswith(".msixbundle") and not name.startswith("Store-"))- validate_windows_bundle(root / universal_name, [r for r in rows if r["platform"] == "windows"])elif any(name.endswith(".msixbundle") and not name.startswith("Store-") for name in by_name):raise ValueError("Candidate carries a signed Windows bundle the claim did not build")stores = [name for name in by_name if name.endswith(".msixbundle") and name.startswith("Store-")]@@ -285,6 +285,11 @@ def publish(manifest: dict, root: Path, public_base: str) -> None:from scripts.releases.r2 import putmaterialize(manifest, root, public_base=public_base)+ windows = [row for row in manifest["packages"] if row["platform"] == "windows"]+ if windows:+ paths = {item["url"]: item["path"] for item in manifest["files"]}+ (universal,) = {paths[row["artifact"]["url"]] for row in windows}+ validate_windows_bundle(root / universal, windows)for file in (root / "apt").rglob("*"):rel = file.relative_to(root / "apt").as_posix()if file.is_file() and (rel.startswith("pool/") or "/by-hash/" in rel):diff --git a/scripts/releases/handoff.py b/scripts/releases/handoff.pyindex e09cf674950..30dcf3dd546 100644--- a/scripts/releases/handoff.py+++ b/scripts/releases/handoff.py@@ -225,9 +225,11 @@ def read_commit_receipt(commit: str, name: str, *, public_base: str | None = Nondef fetch(tag: str, commit: str, names: list[str], root: Path,- includes: list[str] | None = None, *, public_base: str | None = None) -> list[dict]:+ includes: list[str] | None = None, *, public_base: str | None = None,+ require_files: bool = True) -> list[dict]:receipts = [read_receipt(tag, commit, name, public_base=public_base) for name in names]- return _fetch_receipts(receipts, root, includes, public_base=public_base)+ return _fetch_receipts(receipts, root, includes, public_base=public_base,+ require_files=require_files)def fetch_commit_build(commit: str, names: list[str], root: Path,@@ -238,7 +240,8 @@ def fetch_commit_build(commit: str, names: list[str], root: Path,def _fetch_receipts(receipts: list[dict], root: Path,- includes: list[str] | None = None, *, public_base: str | None = None) -> list[dict]:+ includes: list[str] | None = None, *, public_base: str | None = None,+ require_files: bool = True) -> list[dict]:"""Download exact receipt-bound bytes before writing local receipt copies."""root = root.resolve()selected = {}@@ -255,7 +258,7 @@ def _fetch_receipts(receipts: list[dict], root: Path,if not target.resolve().is_relative_to(root):raise ValueError("Release artifact path escapes its download root")selected[row["path"].casefold()] = item- if not selected:+ if not selected and require_files:raise ValueError("No files selected from release handoff")root.mkdir(parents=True, exist_ok=True)credentials = r2.credentials() if public_base is None else Nonediff --git a/scripts/releases/stable.py b/scripts/releases/stable.pyindex bea0c755d6e..9b6570a87ba 100644--- a/scripts/releases/stable.py+++ b/scripts/releases/stable.py@@ -181,14 +181,16 @@ RECEIPT_TARGETS = {# The staged handoffs each receipt is assembled from. The Windows bundle# receipt reads the per-arch metadata handoffs plus the universal bundle-# handoff; fetch() re-verifies every staged byte against its receipt digest,-# and validate_receipt enforces the signing facts (teamId, publisher).+# handoff. Only the metadata is downloaded: package bytes are bound by their+# handoff receipt digests here and re-downloaded and digest-checked by+# release_artifacts.publish before anything goes live. validate_receipt+# enforces the signing facts (teamId, publisher).RECEIPT_HANDOFFS = {"darwin-arm64": ("darwin-arm64",),"darwin-x64": ("darwin-x64",),"win32-bundle": ("win32-x64", "win32-arm64", "windows-universal"),}-RECEIPT_INCLUDES = ("metadata-*.json", "*.zip", "*.msixbundle")+RECEIPT_INCLUDES = ("metadata-*.json",)def _validated_rows(manifest: dict, tag: str, commit: str, public_base: str,@@ -342,8 +344,6 @@ def _receipt_manifest(root: Path, receipt: str, tag: str, commit: str, archive:names = RECEIPT_HANDOFFS.get(receipt)if names is None:raise ValueError(f"Unknown receipt: {receipt}")- # Re-downloading the staged bytes proves the group's handoff is complete- # and matches its receipt before this receipt is published.fetch(tag=archive, commit=commit, names=list(names), root=root,includes=list(RECEIPT_INCLUDES))digests = {}@@ -354,14 +354,14 @@ def _receipt_manifest(root: Path, receipt: str, tag: str, commit: str, archive:for file in sorted(root.glob("metadata-*.json"))]universal = Noneif receipt == "win32-bundle":- bundles = [file.name for file in root.glob("*.msixbundle") if not file.name.startswith("Store-")]+ bundles = [name for name in digests if name.endswith(".msixbundle") and not name.startswith("Store-")]if len(bundles) != 1:raise ValueError(f"Expected one universal bundle, found {len(bundles)}")universal = bundles[0]packages = []for row in rows:filename = universal if row["platform"] == "windows" else row.get("filename")- if not filename or filename not in digests or not (root / filename).is_file():+ if not filename or filename not in digests:raise ValueError(f"Receipt {receipt} is missing staged bytes for "f"{row['platform']}/{row['arch']}")packages.append({@@ -373,11 +373,6 @@ def _receipt_manifest(root: Path, receipt: str, tag: str, commit: str, archive:})if row["platform"] != "windows" and not filename.endswith(".zip"):raise ValueError(f"Receipt {receipt} needs a signed app ZIP for {row['platform']}/{row['arch']}")- if receipt == "win32-bundle":- from scripts.bundles.release_artifacts import validate_windows_bundle-- validate_windows_bundle(root / universal,- [row for row in rows if row["platform"] == "windows"])return {"schema": 2, "tag": tag, "commit": commit, "releaseEpoch": release_epoch,"archive": archive, "packages": packages}@@ -797,7 +792,7 @@ SMOKE_CALLS = {}CANDIDATE_HANDOFFS = ("win32-x64", "win32-arm64", "darwin-x64", "darwin-arm64","termux", "windows-universal")-CANDIDATE_INCLUDES = ("metadata-*.json", "*.msixbundle")+CANDIDATE_INCLUDES = ("metadata-*.json",)def candidate_manifest(env: dict) -> None:@@ -831,8 +826,9 @@ def candidate_manifest(env: dict) -> None:archive = claim["claim_tag"]with tempfile.TemporaryDirectory() as directory:root = Path(directory)+ # A Store-only claim stages no metadata: its receipts alone bind the bytes.fetch(tag=archive, commit=commit, names=list(handoffs), root=root,- includes=list(CANDIDATE_INCLUDES))+ includes=list(CANDIDATE_INCLUDES), require_files=False)out = root / "release-candidates.json"assemble(root, tag, commit, base, out, smoke_results=smoke,release_epoch=claim["claim_epoch"], archive=archive, lanes=lanes)diff --git a/tests/scripts/test_release_artifacts.py b/tests/scripts/test_release_artifacts.pyindex d7a0514ce93..e13f36be3bc 100644--- a/tests/scripts/test_release_artifacts.py+++ b/tests/scripts/test_release_artifacts.py@@ -15,8 +15,8 @@ import hermes_yamlimport pytestfrom scripts.bundles.release_artifacts import materialize, record, stamp_matches-from tests.scripts.test_release_r2 import r2_server-from tests.scripts.test_stable_release import https_origin+from tests.scripts.test_release_r2 import r2_server as r2_server # noqa: PLC0414 -- the self-alias is load-bearing: it suppresses F811 for the pytest fixture parameter shadowing this import+from tests.scripts.test_stable_release import https_origin as https_origin # noqa: PLC0414 -- same self-alias, for the https_origin fixturefrom tests.scripts.test_release_darwin import _inputsfrom scripts.bundles import release_artifacts as artifactsfrom scripts.releases import lanes as lane_set@@ -184,6 +184,30 @@ def test_assemble_rejects_missing_and_changed_receipts(tmp_path, staged_candidatlanes=lane_set.NAMES)+def test_publish_rejects_a_universal_bundle_whose_identity_differs_from_its_packages(+ tmp_path, r2_server, staged_candidate):+ """Candidate staging binds the bundle by digest only; publish opens it before anything goes live."""+ manifest, _, base = staged_candidate+ key = f"releases/tag/{manifest['archive']}/Product-win.msixbundle"+ forged = tmp_path / 'forged.msixbundle'+ with zipfile.ZipFile(forged, 'w') as archive:+ archive.writestr('AppxMetadata/AppxBundleManifest.xml', f'<Bundle><Identity Name="Other" Publisher="CN=Test" Version="{WINDOWS_VERSION}"/><Packages><Package Type="application" Architecture="arm64"/><Package Type="application" Architecture="x64"/></Packages></Bundle>')+ body = forged.read_bytes()+ r2_server.store[key] = (body, *r2_server.store[key][1:])+ tampered = copy.deepcopy(manifest)+ digest = hashlib.sha256(body).hexdigest()+ for item in tampered['files']:+ if item['path'] == 'Product-win.msixbundle':+ item['sha256'], item['size'] = digest, len(body)+ for row in tampered['packages']:+ if row['platform'] == 'windows':+ row['artifact']['sha256'] = digest+ r2_server.requests.clear()+ with pytest.raises(ValueError, match='Universal bundle identity'):+ artifacts.publish(tampered, tmp_path / 'publish', base)+ assert not [path for method, path, _ in r2_server.requests if method == 'PUT']++def test_candidate_publication_and_store_selection(tmp_path, monkeypatch, r2_server, staged_candidate):manifest, _, base = staged_candidatetag, commit = manifest['tag'], manifest['commit']