The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(release): key the stable APT pool by the attempt ref
ethernet40747f50042a
diff --git a/.github/workflows/desktop-bundled-release.yml b/.github/workflows/desktop-bundled-release.ymlindex 679806110de..3b920f8369f 100644--- a/.github/workflows/desktop-bundled-release.yml+++ b/.github/workflows/desktop-bundled-release.yml@@ -1780,6 +1780,7 @@ jobs:CHANNEL: ${{ steps.channel.outputs.channel }}PREVIOUS_TAG: ${{ inputs.termux_upgrade_from_tag }}RELEASE_PHASE: ${{ inputs.release-phase }}+ RELEASE_CLAIM_TAG: ${{ inputs.claim-tag }}RELEASE_COMMIT: ${{ needs.validate.outputs.sha }}# Passphrase-protected signing keys only; unset for bare keys.TERMUX_APT_GPG_PASSPHRASE: ${{ secrets.TERMUX_APT_GPG_PASSPHRASE }}@@ -1787,10 +1788,14 @@ jobs:# stage_apt_repo.py builds dists/<suite>/ + pool/ under --out and# signs Release/InRelease with the key file. Exit 3 (unsigned# Release) must fail the run.- python3 scripts/termux/stage_apt_repo.py \- --pool termux-build/deb \- --out termux-build/apt \- --suite "hermes-$CHANNEL" \+ # The candidate phase keys the pool by the attempt ref: the pool+ # upload is immutable with a one-year cache header, so a recut of+ # the same version must never reuse a pool key.+ stage_args=(--pool termux-build/deb --out termux-build/apt --suite "hermes-$CHANNEL")+ if [ "$RELEASE_PHASE" = candidate ]; then+ stage_args+=(--pool-subdir "$RELEASE_CLAIM_TAG")+ fi+ python3 scripts/termux/stage_apt_repo.py "${stage_args[@]}" \--gpg-key-file "$RUNNER_TEMP/termux-apt-gpg.asc"debs=(termux-build/deb/*.deb)diff --git a/scripts/termux/stage_apt_repo.py b/scripts/termux/stage_apt_repo.pyindex 71774e41caf..0478aed312f 100644--- a/scripts/termux/stage_apt_repo.py+++ b/scripts/termux/stage_apt_repo.py@@ -32,6 +32,8 @@ import timefrom pathlib import Pathfrom typing import NoReturn+from scripts.releases.versioning import parse_attempt_ref+ARCH = "aarch64"COMPONENT = "main"@@ -217,7 +219,19 @@ def existing_published(out_dir: Path, suite: str) -> set:return published-def stage(pool_dir: Path, out_dir: Path, suite: str, gpg_key_file: Path | None) -> int:+def stage(+ pool_dir: Path,+ out_dir: Path,+ suite: str,+ gpg_key_file: Path | None,+ pool_subdir: str = "",+) -> int:+ # The pool upload is immutable with a one-year cache header, so a recut+ # of the same version must not reuse a pool key; only an attempt ref+ # (which names the build, not the version) may prefix the pool, and it+ # doubles as the guard against path escapes.+ if pool_subdir and parse_attempt_ref(pool_subdir) is None:+ die(f"--pool-subdir must be an attempt ref (rc.<N>-vX.Y.Z), got {pool_subdir!r}")debs = sorted(pool_dir.glob("*.deb"))if not debs:die(f"no .deb files found in pool {pool_dir}")@@ -238,12 +252,13 @@ def stage(pool_dir: Path, out_dir: Path, suite: str, gpg_key_file: Path | None)"(published apt assets are immutable)")arch = fields["Architecture"]- target = out_dir / "pool" / deb.name[0].lower() / deb.name+ prefix = f"{pool_subdir}/" if pool_subdir else ""+ target = out_dir / "pool" / pool_subdir / deb.name[0].lower() / deb.nametarget.parent.mkdir(parents=True, exist_ok=True)# Unconditional write: the pool file must always equal the source so# the stanza hashes below can never describe a stale/different file.target.write_bytes(raw)- filename = f"pool/{deb.name[0].lower()}/{deb.name}"+ filename = f"pool/{prefix}{deb.name[0].lower()}/{deb.name}"size = len(raw)sha256 = hashlib.sha256(raw).hexdigest()stanzas.append(@@ -508,13 +523,14 @@ def main(argv: list | None = None) -> int:choices=["hermes-stable", "hermes-canary", "hermes-nightly"],)ap.add_argument("--gpg-key-file", type=Path, default=None)+ ap.add_argument("--pool-subdir", default="")args = ap.parse_args(argv)if not args.pool.is_dir():die(f"pool dir not found: {args.pool}")args.out.mkdir(parents=True, exist_ok=True)try:- return stage(args.pool, args.out, args.suite, args.gpg_key_file)+ return stage(args.pool, args.out, args.suite, args.gpg_key_file, args.pool_subdir)except StageError as e:die(str(e))diff --git a/tests/scripts/test_stage_apt_repo.py b/tests/scripts/test_stage_apt_repo.pyindex a7cce91651d..05639f333b5 100644--- a/tests/scripts/test_stage_apt_repo.py+++ b/tests/scripts/test_stage_apt_repo.py@@ -37,6 +37,67 @@ def no_gpg(monkeypatch):monkeypatch.setattr(stage_apt_repo.shutil, "which", lambda _: None)+def _stage(pool: Path, out: Path, suite: str, pool_subdir: str = "") -> int:+ args = ["--pool", str(pool), "--out", str(out), "--suite", suite]+ if pool_subdir:+ args += ["--pool-subdir", pool_subdir]+ return stage_apt_repo.main(args)+++def _pool_keys(out: Path, suite: str) -> set:+ text = (out / "dists" / suite / "main" / "binary-aarch64" / "Packages").read_text(encoding="utf-8")+ return {+ dict(line.split(": ", 1) for line in stanza.splitlines())["Filename"]+ for stanza in text.strip().split("\n\n")+ }+++def test_pool_subdir_is_in_the_path_and_the_index(tmp_path):+ pool = tmp_path / "pool-in"+ pool.mkdir()+ make_deb(pool / "hermes-agent_0.21.5_aarch64.deb", "hermes-agent", "0.21.5-1")+ out = tmp_path / "repo"+ assert _stage(pool, out, "hermes-stable", pool_subdir="rc.2-v0.21.5") == 3+ deb = out / "pool" / "rc.2-v0.21.5" / "h" / "hermes-agent_0.21.5_aarch64.deb"+ assert deb.is_file()+ assert _pool_keys(out, "hermes-stable") == {"pool/rc.2-v0.21.5/h/hermes-agent_0.21.5_aarch64.deb"}+++def test_no_pool_subdir_keeps_the_plain_layout(tmp_path):+ pool = tmp_path / "pool-in"+ pool.mkdir()+ make_deb(pool / "hermes-agent_1.2.3_aarch64.deb", "hermes-agent", "1.2.3-1")+ out = tmp_path / "repo"+ assert _stage(pool, out, "hermes-canary") == 3+ assert (out / "pool" / "h" / "hermes-agent_1.2.3_aarch64.deb").is_file()+ assert _pool_keys(out, "hermes-canary") == {"pool/h/hermes-agent_1.2.3_aarch64.deb"}+++def test_two_attempts_of_one_version_use_different_pool_keys(tmp_path):+ keys = set()+ for attempt in ("rc.1-v0.21.5", "rc.2-v0.21.5"):+ root = tmp_path / attempt+ pool = root / "pool-in"+ pool.mkdir(parents=True)+ make_deb(pool / "hermes-agent_0.21.5_aarch64.deb", "hermes-agent", "0.21.5-1")+ out = root / "repo"+ assert _stage(pool, out, "hermes-stable", pool_subdir=attempt) == 3+ keys |= {attempt} & {k.split("/")[1] for k in _pool_keys(out, "hermes-stable")}+ assert keys == {"rc.1-v0.21.5", "rc.2-v0.21.5"}++[email protected]("subdir", ["../x", "v0.21.5", "rc.1-v0.21.5/x", ""])+def test_pool_subdir_rejects_non_attempt_refs(tmp_path, subdir):+ pool = tmp_path / "pool-in"+ pool.mkdir()+ make_deb(pool / "hermes-agent_1.2.3_aarch64.deb", "hermes-agent", "1.2.3-1")+ if subdir:+ with pytest.raises(SystemExit):+ _stage(pool, tmp_path / "repo", "hermes-stable", pool_subdir=subdir)+ else:+ assert _stage(pool, tmp_path / "repo", "hermes-stable", pool_subdir=subdir) == 3++def test_canary_versions_below_stable():versions = ["1.2.3-1", "1.2.3~canary.20260831120000-1", "1.2.4~canary.1-1", "1.2.4-1"]ordered = sorted(versions, key=stage_apt_repo.deb_version_key)