Skip to content

The agent that grows with you

fix(release): stable advance checks native metadata against the payload tag

ethernet576012d3295d
diff --git a/scripts/releases/channel_releases.py b/scripts/releases/channel_releases.py
index 38716428438..539245b8e6e 100644
--- a/scripts/releases/channel_releases.py
+++ b/scripts/releases/channel_releases.py
@@ -79,7 +79,14 @@ def _leg_targets(legs: tuple[str, ...]) -> list[tuple[str, str]]:
def read_native_receipts(root: Path, tag: str, commit: str,
- legs: tuple[str, ...] = NATIVE_LEGS) -> dict:
+ legs: tuple[str, ...] = NATIVE_LEGS, *,
+ payload_tag: str | None = None) -> dict:
+ """Receipts bind the archive tag; metadata rows bind the payload tag.
+
+ For stable those differ: the handoffs are staged under the attempt ref
+ (``rc.N-vX.Y.Z``) while record() stamps each package with ``vX.Y.Z``.
+ """
+ payload_tag = payload_tag or tag
files = {}
for name in legs:
receipt = json.loads((root / handoff.receipt_name(name)).read_text(encoding="utf-8-sig"))
@@ -97,7 +104,7 @@ def read_native_receipts(root: Path, tag: str, commit: str,
if name not in files or not (root / name).is_file():
raise ChannelError(f"Missing receipt-bound native metadata: {name}")
row = json.loads((root / name).read_text(encoding="utf-8-sig"))
- if any(row.get(k) != v for k, v in {"platform": platform, "arch": arch, "tag": tag, "commit": commit}.items()):
+ if any(row.get(k) != v for k, v in {"platform": platform, "arch": arch, "tag": payload_tag, "commit": commit}.items()):
raise ChannelError("Native metadata release identity mismatch")
rows.append(row)
return {"packages": rows, "files": files}
@@ -389,7 +396,7 @@ def publish_release(policy: str, env: dict, root: Path) -> dict:
legs = native_legs(accepted)
handoff.fetch(tag, commit, list(legs), root,
["metadata-*.json", "*.zip", "*.dmg", "*.blockmap", "*.msixbundle"], public_base=publisher.public_base)
- native = read_native_receipts(root, tag, commit, legs)
+ native = read_native_receipts(root, tag, commit, legs, payload_tag=payload_tag)
windows = next(row for row in native["packages"] if row["platform"] == "windows")
if policy == "canary-release":
expected_windows = canary_windows_version(tag)
@@ -430,7 +437,7 @@ def publish_release(policy: str, env: dict, root: Path) -> dict:
def qualified(pinned: dict, actual: dict) -> bool:
# Rehash local receipt-bound bytes rather than trusting caller-supplied claims.
- expected, _ = assemble(pinned, read_native_receipts(root, tag, commit, legs), root,
+ expected, _ = assemble(pinned, read_native_receipts(root, tag, commit, legs, payload_tag=payload_tag), root,
artifact_prefix=f"releases/tag/{tag}/", targets=_leg_targets(legs))
if accepted is not None:
match_accepted_packages(expected, accepted)
diff --git a/tests/scripts/test_release_channels.py b/tests/scripts/test_release_channels.py
index c5e1d88b541..ce0ff0c0e92 100644
--- a/tests/scripts/test_release_channels.py
+++ b/tests/scripts/test_release_channels.py
@@ -694,3 +694,34 @@ def test_stable_requests_name_the_attempt_archive_only_when_given():
assert pub.request(bare["buildId"]) == bare
with pytest.raises(ChannelError, match="(?i)archive ref"):
allocate("c" * 40, "2.2.0", "rc.2-v2.9.9")
+
+
+def test_stable_receipts_bind_the_attempt_ref_while_metadata_binds_the_payload_tag(tmp_path):
+ """Stable stages handoffs under rc.N-vX.Y.Z but record() stamps vX.Y.Z."""
+ from scripts.releases import channel_releases
+ from scripts.releases.handoff import receipt_name
+ from hermes_cli.release_channels import ChannelError, canonical_json
+ attempt, payload, commit = "rc.15-v2.0.0", "v2.0.0", "e" * 40
+ legs = ("darwin-arm64", "win32-arm64", "win32-x64")
+
+ def stage(metadata_tag):
+ for leg in legs:
+ platform, arch = leg.split("-")
+ native = "macos" if platform == "darwin" else "windows"
+ name = f"metadata-{native}-{arch}.json"
+ body = canonical_json({"platform": native, "arch": arch, "tag": metadata_tag, "commit": commit})
+ (tmp_path / name).write_bytes(body)
+ rows = [{"path": name, "size": len(body), "sha256": hashlib.sha256(body).hexdigest()}]
+ receipt = {"schema": 1, "tag": attempt, "commit": commit, "name": leg, "files": rows}
+ (tmp_path / receipt_name(leg)).write_bytes(canonical_json(receipt))
+
+ stage(payload)
+ native = channel_releases.read_native_receipts(tmp_path, attempt, commit, legs, payload_tag=payload)
+ assert {row["tag"] for row in native["packages"]} == {payload}
+ # Without the payload tag the rows are held to the attempt ref and refused.
+ with pytest.raises(ChannelError, match="identity mismatch"):
+ channel_releases.read_native_receipts(tmp_path, attempt, commit, legs)
+ # A row stamped with the attempt ref is not the published payload.
+ stage(attempt)
+ with pytest.raises(ChannelError, match="identity mismatch"):
+ channel_releases.read_native_receipts(tmp_path, attempt, commit, legs, payload_tag=payload)