Skip to content

The agent that grows with you

fix(release): read a tag's record, not its signature

ethernet8023792ba0a2645a
diff --git a/scripts/releases/commit_build.py b/scripts/releases/commit_build.py
index 5f8791ce9b5..05db8f2de8d 100644
--- a/scripts/releases/commit_build.py
+++ b/scripts/releases/commit_build.py
@@ -96,10 +96,15 @@ def receipt_tag(kind: str, version: str, created_at: str, run_id: str) -> str:
def _verify_receipt(tag: str, commit: str, record: dict, *, run, repo: Path | None) -> None:
+ # Imported here, not at module level: this module's import surface stays
+ # stdlib-only so the isolated checkout-admission step can run it from a copy
+ # of scripts/releases alone, without the application package.
+ from scripts.releases.versioning import tag_record
+
tag_object = run(["git", "rev-parse", f"refs/tags/{tag}"], repo)
if (run(["git", "cat-file", "-t", tag_object], repo) != "tag"
or run(["git", "rev-parse", f"refs/tags/{tag}^{{commit}}"], repo) != commit
- or json.loads(run(["git", "tag", "-l", tag, "--format=%(contents)"], repo)) != record):
+ or tag_record(run(["git", "tag", "-l", tag, "--format=%(contents)"], repo)) != record):
raise ValueError("Build receipt tag differs from this run")
diff --git a/scripts/releases/sequencer.py b/scripts/releases/sequencer.py
index a4595971485..4aa6e130e50 100644
--- a/scripts/releases/sequencer.py
+++ b/scripts/releases/sequencer.py
@@ -17,7 +17,7 @@ from pathlib import Path
from scripts.releases.versioning import (
marker_ref, outstanding_attempts, parse_attempt_ref, parse_marker_ref,
- version_from_tag,
+ tag_record, version_from_tag,
)
MAX_ATTEMPTS = 3
@@ -201,7 +201,7 @@ def _tag_message(tag: str, expected_object: str, run=output) -> dict:
if local_object != expected_object or run(["git", "cat-file", "-t", local_object]) != "tag":
raise ValueError(f"{tag} differs from its remote annotated object")
try:
- message = json.loads(run(["git", "tag", "-l", tag, "--format=%(contents)"]))
+ message = tag_record(run(["git", "tag", "-l", tag, "--format=%(contents)"]))
except json.JSONDecodeError as error:
raise ValueError(f"{tag} metadata is invalid") from error
if not isinstance(message, dict):
diff --git a/scripts/releases/stable.py b/scripts/releases/stable.py
index 07737b70366..ae5c2847ad6 100644
--- a/scripts/releases/stable.py
+++ b/scripts/releases/stable.py
@@ -17,6 +17,7 @@ from urllib.parse import unquote, urlsplit
from hermes_cli.update_channel import STABLE_TAG_RE
from scripts.releases.draft_warning import strip_draft_warning
+from scripts.releases.versioning import tag_record
SHA = re.compile(r"[a-f0-9]{40}")
DIGEST = re.compile(r"[a-f0-9]{64}")
DESKTOP_TARGETS = ("windows/x64", "windows/arm64", "macos/x64", "macos/arm64")
@@ -400,8 +401,8 @@ def validate_claim(metadata: object, *, version: str, attempt: int, commit: str)
def _claim_metadata(raw: str, *, version: str, attempt: int, commit: str) -> dict:
try:
- metadata = json.loads(raw)
- except (TypeError, json.JSONDecodeError) as error:
+ metadata = tag_record(raw)
+ except (TypeError, AttributeError, json.JSONDecodeError) as error:
raise ValueError("Stable claim metadata is invalid") from error
return validate_claim(metadata, version=version, attempt=attempt, commit=commit)
@@ -538,7 +539,7 @@ def final_context(env: dict, run=output) -> tuple[str, str, dict]:
version=admitted["version"], attempt=admitted["attempt"], commit=commit,
)
final = validate_final(
- json.loads(run(["git", "tag", "-l", tag, "--format=%(contents)"])),
+ tag_record(run(["git", "tag", "-l", tag, "--format=%(contents)"])),
version=admitted["version"], commit=commit, claim_tag=claim_tag,
claim_object=claim_object, claim=claim,
)
@@ -777,7 +778,7 @@ def ensure_final_tag(tag: str, commit: str, claim: dict, *, candidate_manifest_s
else:
if (run(["git", "cat-file", "-t", local_object]) != "tag"
or run(["git", "rev-parse", f"{ref}^{{commit}}"]) != commit
- or json.loads(run(["git", "tag", "-l", tag, "--format=%(contents)"])) != expected):
+ or tag_record(run(["git", "tag", "-l", tag, "--format=%(contents)"])) != expected):
raise ValueError("Local final tag collision")
run(["git", "push", "origin", ref])
remote_raw = run(["git", "ls-remote", "origin", ref, f"{ref}^{{}}"])
@@ -792,7 +793,7 @@ def ensure_final_tag(tag: str, commit: str, claim: dict, *, candidate_manifest_s
local_object = run(["git", "rev-parse", ref])
if local_object != tag_object or run(["git", "cat-file", "-t", local_object]) != "tag":
raise ValueError("Final stable tag object differs from the verified remote")
- metadata = json.loads(run(["git", "tag", "-l", tag, "--format=%(contents)"]))
+ metadata = tag_record(run(["git", "tag", "-l", tag, "--format=%(contents)"]))
if metadata != expected:
raise ValueError("Final stable tag metadata differs from the accepted artifacts")
return tag_object
diff --git a/scripts/releases/versioning.py b/scripts/releases/versioning.py
index 6d52d74af3d..354127949b8 100644
--- a/scripts/releases/versioning.py
+++ b/scripts/releases/versioning.py
@@ -10,6 +10,7 @@ import json
import re
import subprocess
from functools import cmp_to_key
+from typing import Any
from hermes_cli.update_channel import STABLE_TAG_RE
from scripts.releases.semver import compare
@@ -106,6 +107,20 @@ def version_from_tag(ref: str) -> str | None:
return ref[1:]
+def tag_record(raw: str) -> Any:
+ """Decode the JSON record an annotated release tag carries.
+
+ ``git tag -l --format=%(contents)`` returns the whole message, and git keeps
+ a signature *inside* the message body: a signed tag reads as the record
+ followed by an armored signature block. The record is everything before the
+ armor, so every reader parses through here, never ``json.loads(raw)``.
+
+ Detached signatures (``git tag --detach-sign``) live outside the message and
+ leave this unchanged, as does an unsigned tag.
+ """
+ return json.loads(raw.split("\n-----BEGIN ", 1)[0])
+
+
# The ref grammar only anchors; ``version_from_tag`` owns the version shape.
_ATTEMPT_REF_RE = re.compile(r"rc\.(?P<attempt>[1-9][0-9]*)-(?P<tag>v[^/]+)")
_MARKER_PREFIX = "abandoned-"
diff --git a/tests/ci/test_channel_build_publication.py b/tests/ci/test_channel_build_publication.py
index 832b07e297c..73de6e8b7e6 100644
--- a/tests/ci/test_channel_build_publication.py
+++ b/tests/ci/test_channel_build_publication.py
@@ -18,6 +18,7 @@ import pytest
from hermes_cli.release_channels import canonical_json
from scripts.releases import channel_publish, handoff, r2
from scripts.releases.channels import preview_identity
+from scripts.releases.versioning import tag_record
from tests.ci.desktop_release_roles import (
DOWNLOADABLE_DISPATCHES, admitted, channel_publisher, commit_summary, gate, native_builds, needs_of, stage_step,
universal_assembler,
@@ -321,7 +322,7 @@ def test_real_publication_cas_and_manifest_summary(tmp_path, r2_server, staged_c
else:
tag = "v0.0.7+channel.20260922T012345Z.98765"
assert _git("tag", "--list", tag, cwd=tmp_path / "clone") == tag
- receipt = json.loads(_git("tag", "-l", tag, "--format=%(contents)", cwd=tmp_path / "clone"))
+ receipt = tag_record(_git("tag", "-l", tag, "--format=%(contents)", cwd=tmp_path / "clone"))
assert receipt == {
"schema": 1, "kind": "channel", "tag": tag, "version": request["version"],
"commit": request["commit"], "runId": "98765", "runCreatedAt": "2026-09-22T01:23:45Z",
diff --git a/tests/ci/test_desktop_release_commit_admission.py b/tests/ci/test_desktop_release_commit_admission.py
index 0fb40a66e6c..19f740f331e 100644
--- a/tests/ci/test_desktop_release_commit_admission.py
+++ b/tests/ci/test_desktop_release_commit_admission.py
@@ -8,6 +8,7 @@ import subprocess
import sys
from scripts.releases.commit_build import publish_receipt, receipt_tag
+from scripts.releases.versioning import tag_record
from tests.ci.test_desktop_release_tag_admission import _child_env, _git, _seed_repo, _workflow, _BASH
@@ -142,7 +143,7 @@ def test_post_build_receipts_bind_kind_commit_and_run_without_same_second_collis
'v0.0.0+commit.20260922T012345Z.123',
'v0.0.0+commit.20260922T012345Z.124',
]
- assert json.loads(_git('tag', '-l', first['tag'], '--format=%(contents)', cwd=clone)) == first
+ assert tag_record(_git('tag', '-l', first['tag'], '--format=%(contents)', cwd=clone)) == first
assert _git('rev-parse', f"{first['tag']}^{{commit}}", cwd=clone) == commit
assert publish_receipt(
'commit', base, version='0.0.0', commit=commit,
diff --git a/tests/scripts/test_release_entrypoint.py b/tests/scripts/test_release_entrypoint.py
index 2264408f331..24622b7c405 100644
--- a/tests/scripts/test_release_entrypoint.py
+++ b/tests/scripts/test_release_entrypoint.py
@@ -12,6 +12,8 @@ import threading
import pytest
+from scripts.releases.versioning import tag_record
+
def git(repo, *args):
return subprocess.check_output(["git", *args], cwd=repo, text=True, encoding="utf-8").strip()
@@ -98,7 +100,7 @@ def test_release_claims_the_first_attempt_creates_a_draft_and_dispatches(source)
assert result["url"] == "https://github.com/example/hermes-agent/releases/tag/untagged-0123abcd"
assert result["final_url"] == "https://github.com/example/hermes-agent/releases/tag/v0.21.5"
assert git(source, "rev-parse", "rc.1-v0.21.5^{commit}") == commit
- claim = json.loads(git(source, "tag", "-l", "rc.1-v0.21.5", "--format=%(contents)"))
+ claim = tag_record(git(source, "tag", "-l", "rc.1-v0.21.5", "--format=%(contents)"))
assert isinstance(claim.pop("claimEpoch"), int)
# The claim is the one record of the attempt's policy, flags included.
assert claim == {
@@ -160,7 +162,9 @@ def test_a_final_tag_for_the_next_version_refuses_the_cut(source):
from scripts.releases.entrypoint import ReleaseRefused
commit = git(source, "rev-parse", "HEAD")
- git(source, "tag", "v0.21.5", commit)
+ # A plain final tag on purpose. The fixture is about the cut, not about tag
+ # signing, and a host whose git signs tags by default cannot make this one.
+ git(source, "-c", "tag.gpgSign=false", "tag", "v0.21.5", commit)
git(source, "push", "-q", "origin", "refs/tags/v0.21.5")
with pytest.raises(ReleaseRefused, match="v0.21.5 already has a final tag"):
@@ -498,7 +502,7 @@ def test_abandon_of_a_draft_deletes_it_writes_the_marker_and_frees_the_version(s
remote = git(source, "ls-remote", "origin", "refs/tags/*")
assert "refs/tags/abandoned-rc.1-v0.21.5" in remote
assert "refs/tags/rc.1-v0.21.5" in remote
- marker = json.loads(git(source, "tag", "-l", "abandoned-rc.1-v0.21.5", "--format=%(contents)"))
+ marker = tag_record(git(source, "tag", "-l", "abandoned-rc.1-v0.21.5", "--format=%(contents)"))
assert marker == {"attempt": 1, "attemptRef": "rc.1-v0.21.5", "schema": 1, "version": "0.21.5"}
assert git(source, "rev-parse", "abandoned-rc.1-v0.21.5^{commit}") == git(
source, "rev-parse", "rc.1-v0.21.5^{commit}")
diff --git a/tests/scripts/test_release_version_from_ref.py b/tests/scripts/test_release_version_from_ref.py
index f0341473bfe..cd39b466f3d 100644
--- a/tests/scripts/test_release_version_from_ref.py
+++ b/tests/scripts/test_release_version_from_ref.py
@@ -7,7 +7,7 @@ import json
import pytest
-from scripts.releases.versioning import derive_next_version, next_attempt, version_from_tag
+from scripts.releases.versioning import derive_next_version, next_attempt, tag_record, version_from_tag
SEED = "0.21.4"
@@ -162,3 +162,21 @@ def test_outstanding_attempts_is_the_one_shared_predicate():
return version in published
assert outstanding_attempts(refs, is_published) == [("0.21.5", 2, "rc.2-v0.21.5")]
+
+
+def test_tag_record_reads_the_record_a_signature_is_appended_to():
+ """git keeps a tag signature inside the message body, so ``%(contents)`` is
+ the record followed by the armor. The record is what precedes it."""
+ record = {"attempt": 19, "autopublish": False, "claimEpoch": 1790701941,
+ "commit": "3" * 40, "schema": 1, "skipBundles": False, "skipTests": True,
+ "version": "0.21.5"}
+ record_text = json.dumps(record, sort_keys=True, separators=(",", ":"))
+
+ assert tag_record(record_text) == record
+ for armor in ("-----BEGIN SSH SIGNATURE-----", "-----BEGIN PGP SIGNATURE-----"):
+ assert tag_record(f"{record_text}\n{armor}\nAAAA\n") == record
+
+
+def test_tag_record_refuses_a_message_that_is_not_a_record():
+ with pytest.raises(json.JSONDecodeError):
+ tag_record("not a record\n-----BEGIN SSH SIGNATURE-----\nAAAA\n")
diff --git a/tests/scripts/test_stable_admission.py b/tests/scripts/test_stable_admission.py
index 1cbc753d7a6..02a5f84290b 100644
--- a/tests/scripts/test_stable_admission.py
+++ b/tests/scripts/test_stable_admission.py
@@ -5,9 +5,20 @@
``rc.<N>-vX.Y.Z`` names the version and the attempt, and the only question
about the commit is whether it is on ``main``.
"""
+import json
+import subprocess
+
import pytest
+SSH_SIGNATURE = """-----BEGIN SSH SIGNATURE-----
+U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAggv7kgN4gq9ilCWVWxT+yhG7bsr
+I9MDkVe9kzlnz6azsAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5
+AAAAQEpfHRbnoIdqp6f7VhHqY66Im8aoqVRR8z+VchVeNSWOVEOlM7jM7QzMcvNLeE+B3V
+yR4zgvmhXTUJgyPe+zMgM=
+-----END SSH SIGNATURE-----"""
+
+
def test_admission_reads_the_version_and_attempt_from_the_attempt_ref():
from scripts.releases.stable import admit_claim
@@ -33,3 +44,35 @@ def test_admission_refuses_a_tag_that_is_not_an_attempt_ref(tag):
with pytest.raises(ValueError, match="not a claim tag"):
admit_claim(tag, "a" * 40, on_main=lambda _sha: True)
+
+
+def test_a_signed_claim_tag_is_read_through_the_jobs_own_git_read(tmp_path, monkeypatch):
+ """The job reads a claim with ``git tag -l --format=%(contents)``, and a
+ signed tag appends its armor to that message. The reader has to parse the
+ record before the armor, or every signed claim fails admission."""
+ from scripts.releases.stable import _claim_metadata
+
+ monkeypatch.setenv("GIT_CONFIG_GLOBAL", str(tmp_path / "absent-config"))
+ monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
+ record = {"schema": 1, "version": "0.21.5", "attempt": 19, "commit": "3" * 40,
+ "autopublish": False, "skipBundles": False, "skipTests": True,
+ "claimEpoch": 1790701941}
+ repo = tmp_path / "repo"
+ repo.mkdir()
+
+ def git(*args: str) -> None:
+ subprocess.run(["git", *args], cwd=repo, check=True, capture_output=True, text=True)
+
+ git("init", "-q", "-b", "main")
+ git("config", "user.name", "Fixture")
+ git("config", "user.email", "[email protected]")
+ git("commit", "--allow-empty", "-qm", "fixture")
+ git("tag", "-a", "rc.19-v0.21.5", "-m",
+ json.dumps(record, sort_keys=True, separators=(",", ":")) + "\n" + SSH_SIGNATURE)
+
+ raw = subprocess.check_output(
+ ["git", "tag", "-l", "rc.19-v0.21.5", "--format=%(contents)"], cwd=repo, text=True).strip()
+ assert "-----BEGIN SSH SIGNATURE-----" in raw
+ with pytest.raises(json.JSONDecodeError): # the shape that failed admission
+ json.loads(raw)
+ assert _claim_metadata(raw, version="0.21.5", attempt=19, commit="3" * 40) == record
diff --git a/tests/scripts/test_stable_release.py b/tests/scripts/test_stable_release.py
index 5d96c244d57..46919667d6c 100644
--- a/tests/scripts/test_stable_release.py
+++ b/tests/scripts/test_stable_release.py
@@ -19,6 +19,7 @@ from scripts.releases.stable import (
check_claim, ensure_final_tag, plan_receipt_transitions, plan_transitions, read_manifest,
require_stable_identity, require_success, validate_candidates, validate_receipt,
)
+from scripts.releases.versioning import tag_record
BASE = "https://releases.example"
ROOT = Path(__file__).resolve().parents[2]
@@ -535,7 +536,7 @@ def test_publish_attempt_writes_the_receipt_retargets_and_copies_no_bytes(tmp_pa
commit, tag_object = _claim_fixture(tmp_path, tag="rc.2-v1.2.3", version="1.2.3")
monkeypatch.chdir(tmp_path / "repo")
- epoch = json.loads(subprocess.check_output(
+ epoch = tag_record(subprocess.check_output(
["git", "tag", "-l", "rc.2-v1.2.3", "--format=%(contents)"],
text=True, encoding="utf-8"))["claimEpoch"]
manifest_bytes = b'{"schema":2}\n'
@@ -585,7 +586,7 @@ def test_publish_attempt_writes_the_receipt_retargets_and_copies_no_bytes(tmp_pa
)
assert digest == docker_digest
- receipt = json.loads(subprocess.check_output(
+ receipt = tag_record(subprocess.check_output(
["git", "tag", "-l", "v1.2.3", "--format=%(contents)"],
text=True, encoding="utf-8"))
assert receipt["claimTag"] == "rc.2-v1.2.3"
@@ -616,7 +617,7 @@ def test_publish_attempt_refuses_a_release_that_is_no_longer_a_draft(tmp_path, m
commit, tag_object = _claim_fixture(tmp_path, tag="rc.2-v1.2.3", version="1.2.3")
monkeypatch.chdir(tmp_path / "repo")
- epoch = json.loads(subprocess.check_output(
+ epoch = tag_record(subprocess.check_output(
["git", "tag", "-l", "rc.2-v1.2.3", "--format=%(contents)"],
text=True, encoding="utf-8"))["claimEpoch"]
release = {"id": 42, "tag_name": "rc.2-v1.2.3", "draft": False, "prerelease": False,