Files
hermes-agent/tests/scripts/test_release_linux.py

799 lines
33 KiB
Python

"""Contract tests for Linux AppImage electron-updater feed publication and R2 prune protection.
Feed planning, admission, and validation are pure; R2 publication and pruning
run against the real loopback HTTP server fixture (http.server on 127.0.0.1).
"""
from __future__ import annotations
import base64
import hashlib
import json
import hermes_yaml as yaml
import pytest
from scripts.releases import linux, r2
from tests.scripts.test_release_r2 import r2_server
COMMIT = "d71a65744c569c1cd01a713692542a8d163e106b"
OTHER_COMMIT = "0123456789abcdef0123456789abcdef01234567"
def _sha512(data: bytes) -> str:
return base64.b64encode(hashlib.sha512(data).digest()).decode("ascii")
def _inputs(
tag: str = "canary.20261128T064458Z-v0.23.5",
*,
archive: str | None = None,
salt: str = "",
) -> tuple[dict[str, str], dict[str, bytes]]:
from hermes_cli.update_channel import release_version
version = release_version(tag)
assert version
archive_tag = archive or tag
feeds: dict[str, str] = {}
bytes_by_key: dict[str, bytes] = {}
for index, arch in enumerate(linux.ARCHES):
appimage_arch = linux.APPIMAGE_ARCH[arch]
name = f"HermesBundled-{version}-linux-{appimage_arch}.AppImage"
data = f"appimage-{arch}-{version}-{salt}".encode()
bytes_by_key[f"releases/tag/{archive_tag}/{name}"] = data
entry = {
"url": name,
"sha512": _sha512(data),
"size": len(data),
"blockMapSize": 1975431 + index,
}
feeds[arch] = yaml.safe_dump(
{
"version": version,
"files": [entry],
"path": name,
"sha512": entry["sha512"],
"releaseDate": f"2026-11-28T06:55:0{index}.000Z",
"releaseNotes": "line one\nline two",
},
sort_keys=False,
)
return feeds, bytes_by_key
def _good_evidence(claim_tag: str, commit: str = COMMIT) -> dict[str, linux.ArchEvidence]:
return {
arch: linux.ArchEvidence(
arch=arch,
claim_tag=claim_tag,
commit=commit,
staged=True,
smoke_passed=True,
)
for arch in linux.ARCHES
}
def _seed_artifacts(server, bytes_by_key: dict[str, bytes]) -> None:
for key, payload in bytes_by_key.items():
server.store[key] = (payload, '"artifact"')
def test_plan_linux_feeds_preserves_literal_plus_and_metadata():
tag = "canary.20261128T064458Z-v0.23.5"
feeds, _ = _inputs(tag)
plans = linux.plan_linux_feeds(feeds, tag)
assert plans["x64"]["key"] == "releases/linux/canary/canary-linux.yml"
assert plans["arm64"]["key"] == "releases/linux/canary/canary-linux-arm64.yml"
for arch in linux.ARCHES:
assert r2.cache_control_for(plans[arch]["key"]) == "no-store"
parsed = linux.parse_linux_feed(plans[arch]["text"])
assert parsed["version"] == "0.23.5+canary.20261128T064458Z"
assert "+canary.20261128T064458Z" in parsed["files"][0]["url"]
assert parsed["files"][0]["blockMapSize"] > 0
assert parsed["releaseNotes"] == "line one\nline two"
# AppImage embeds its blockmap, so references include only the .AppImage object.
refs = linux.linux_feed_references(plans[arch]["text"])
assert refs == [plans[arch]["artifact_key"]]
assert all(not ref.endswith(".blockmap") for ref in refs)
def _corrupt_feed_doc(doc: dict, kind: str) -> None:
def _set_url(url: str) -> None:
doc["files"][0]["url"] = url
doc["path"] = url
mutators = {
"version": lambda: doc.__setitem__("version", "0.27.0"),
"wrong-arch-name": lambda: _set_url(doc["files"][0]["url"].replace("linux-x86_64", "linux-x64")),
"traversal": lambda: _set_url("../escape.AppImage"),
"hash": lambda: (doc["files"][0].__setitem__("sha512", "not-base64"), doc.__setitem__("sha512", "not-base64")),
"top-sha512": lambda: doc.__setitem__("sha512", _sha512(b"other")),
"blockmap-size": lambda: doc["files"][0].__setitem__("blockMapSize", -5),
}
mutators[kind]()
@pytest.mark.parametrize(
"kind",
["missing-arch", "extra-arch", "version", "wrong-arch-name", "traversal", "hash", "top-sha512", "blockmap-size"],
)
def test_plan_linux_feeds_rejects_broken_or_partial_inputs(kind):
tag = "v0.28.0"
feeds, _ = _inputs(tag)
if kind == "missing-arch":
del feeds["arm64"]
elif kind == "extra-arch":
feeds["riscv64"] = feeds["x64"]
else:
doc = yaml.safe_load(feeds["x64"])
_corrupt_feed_doc(doc, kind)
feeds["x64"] = yaml.safe_dump(doc, sort_keys=False)
with pytest.raises(ValueError):
linux.plan_linux_feeds(feeds, tag)
def test_real_prune_protects_live_linux_appimages_and_fails_closed(r2_server, monkeypatch): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "canary.20200101T000000Z-v0.28.0"
feeds, _ = _inputs(tag)
plans = linux.plan_linux_feeds(feeds, tag)
stale = "releases/tag/canary.20200101T000000Z-v0.27.0/HermesBundled-0.27.0+canary.20200101T000000Z-linux-x86_64.AppImage"
protected_refs = []
for arch in linux.ARCHES:
r2_server.store[plans[arch]["key"]] = (plans[arch]["text"].encode(), '"feed"')
refs = linux.linux_feed_references(plans[arch]["text"])
protected_refs.extend(refs)
for ref in refs:
r2_server.store[ref] = (b"appimage", '"img"')
r2_server.store[stale] = (b"old-unreferenced", '"old"')
monkeypatch.setattr(r2.time, "time", lambda: 1788547200.0) # 2026-09-04
r2.prune(keep_days=14, dry_run=False)
assert stale not in r2_server.store
for ref in protected_refs:
assert ref in r2_server.store, ref
for arch in linux.ARCHES:
assert plans[arch]["key"] in r2_server.store
# Fail closed: an unparseable Linux feed aborts prune with zero deletions.
r2_server.store[stale] = (b"must survive corrupt feed", '"old"')
before = set(r2_server.store)
r2_server.store[plans["arm64"]["key"]] = (b"<html>503</html>", '"bad"')
with pytest.raises(ValueError):
r2.prune(keep_days=14, dry_run=False)
assert set(r2_server.store) == before
def test_publish_admitted_canary_preflights_both_arches_before_first_put(r2_server): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "canary.20261128T064458Z-v0.23.5"
feeds, bytes_by_key = _inputs(tag)
_seed_artifacts(r2_server, bytes_by_key)
authority = linux.ChannelAuthority(
channel="canary",
claim_tag=tag,
commit=COMMIT,
publish_canary_succeeded=True,
)
result = linux.publish_admitted(
tag=tag,
commit=COMMIT,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(tag),
authority=authority,
)
assert result["published"] is True
assert result["written"] == [
"releases/linux/canary/canary-linux.yml",
"releases/linux/canary/canary-linux-arm64.yml",
]
assert result["skipped"] == []
# Both live-feed GETs and both AppImage artifact verifications MUST precede the first PUT.
methods = [method for method, _, _ in r2_server.requests]
first_put = methods.index("PUT")
assert first_put == 4
assert all(method == "GET" for method in methods[:first_put])
put_headers = [headers for method, _, headers in r2_server.requests if method == "PUT"]
assert len(put_headers) == 2
for headers in put_headers:
assert headers["If-None-Match"] == "*"
assert headers["Cache-Control"] == "no-store"
assert headers["Content-Type"] == "application/yaml"
assert headers["authorization"].startswith("AWS4-HMAC-SHA256 ")
def test_preflight_failure_on_second_arch_writes_zero_puts(r2_server): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "canary.20261128T064458Z-v0.23.5"
feeds, bytes_by_key = _inputs(tag)
_seed_artifacts(r2_server, bytes_by_key)
# Corrupt only arm64 in R2: neither x64 nor arm64 feed may be written.
arm64_key = next(k for k in bytes_by_key if k.endswith("-linux-arm64.AppImage"))
r2_server.store[arm64_key] = (b"corrupt" + b"x" * (len(bytes_by_key[arm64_key]) - 7), '"bad"')
authority = linux.ChannelAuthority(
channel="canary",
claim_tag=tag,
commit=COMMIT,
publish_canary_succeeded=True,
)
with pytest.raises(ValueError, match="checksum mismatch"):
linux.publish_admitted(
tag=tag,
commit=COMMIT,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(tag),
authority=authority,
)
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
assert "releases/linux/canary/canary-linux.yml" not in r2_server.store
assert "releases/linux/canary/canary-linux-arm64.yml" not in r2_server.store
def test_partial_put_retry_is_idempotent_and_refuses_stale_retry(r2_server): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "canary.20261128T064458Z-v0.23.5"
feeds, bytes_by_key = _inputs(tag)
_seed_artifacts(r2_server, bytes_by_key)
authority = linux.ChannelAuthority(
channel="canary",
claim_tag=tag,
commit=COMMIT,
publish_canary_succeeded=True,
)
# Seed an older arm64 feed and inject a 412 race on arm64 so x64 PUT succeeds and arm64 fails.
old_tag = "canary.20261127T064458Z-v0.23.5"
old_plans = linux.plan_linux_feeds(_inputs(old_tag)[0], old_tag)
arm64_feed_key = "releases/linux/canary/canary-linux-arm64.yml"
r2_server.store[arm64_feed_key] = (old_plans["arm64"]["text"].encode(), '"old-arm64"')
r2_server.race_key = arm64_feed_key
with pytest.raises(r2.R2RequestError, match="412"):
linux.publish_admitted(
tag=tag,
commit=COMMIT,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(tag),
authority=authority,
)
assert "releases/linux/canary/canary-linux.yml" in r2_server.store
assert linux.parse_linux_feed(r2_server.store[arm64_feed_key][0].decode())["version"] == "0.23.5+canary.20261127T064458Z"
# Retry succeeds idempotently: x64 is skipped as identical (0 PUTs for x64) and arm64 finishes.
r2_server.race_key = None
r2_server.requests.clear()
retry = linux.publish_admitted(
tag=tag,
commit=COMMIT,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(tag),
authority=authority,
)
assert retry["published"] is True
assert retry["skipped"] == ["releases/linux/canary/canary-linux.yml"]
assert retry["written"] == [arm64_feed_key]
puts = [path for method, path, _ in r2_server.requests if method == "PUT"]
assert len(puts) == 1 and puts[0].endswith(arm64_feed_key)
# If a newer release supersedes x64 before a stale retry runs, the stale retry writes zero PUTs.
newer_tag = "canary.20261129T064458Z-v0.23.5"
newer_plans = linux.plan_linux_feeds(_inputs(newer_tag)[0], newer_tag)
r2_server.store["releases/linux/canary/canary-linux.yml"] = (newer_plans["x64"]["text"].encode(), '"newer"')
r2_server.requests.clear()
with pytest.raises(ValueError, match="backward"):
linux.publish_admitted(
tag=tag,
commit=COMMIT,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(tag),
authority=authority,
)
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
def test_retry_after_partial_publish_reverifies_the_already_live_arch_appimage(r2_server): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "canary.20261128T064458Z-v0.23.5"
feeds, bytes_by_key = _inputs(tag)
_seed_artifacts(r2_server, bytes_by_key)
plans = linux.plan_linux_feeds(feeds, tag)
# A first attempt wrote the x64 feed and failed on arm64; x64's AppImage has since gone bad.
r2_server.store[plans["x64"]["key"]] = (plans["x64"]["text"].encode(), '"x64-live"')
x64_appimage = plans["x64"]["artifact_key"]
r2_server.store[x64_appimage] = (b"x" * len(bytes_by_key[x64_appimage]), '"bad"')
r2_server.requests.clear()
with pytest.raises(ValueError, match="checksum mismatch"):
linux.publish_admitted(
tag=tag,
commit=COMMIT,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(tag),
authority=linux.ChannelAuthority("canary", tag, COMMIT, publish_canary_succeeded=True),
)
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
assert plans["arm64"]["key"] not in r2_server.store
def test_green_stable_rehearsal_without_sequencer_promotion_writes_zero_feeds(r2_server): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
# Exact counterexample: both Linux smokes pass, publish-bundles and publication succeed,
# even a no-op sequencer exits 0 with no abandonment marker, yet the sequencer did not
# promote this claim -> zero stable Linux feed writes.
tag = "v0.28.0"
archive = "rc.1-v0.28.0"
feeds, bytes_by_key = _inputs(tag, archive=archive)
_seed_artifacts(r2_server, bytes_by_key)
rehearsal_authority = linux.ChannelAuthority(
channel="stable",
claim_tag=archive,
commit=COMMIT,
sequencer_promoted=False,
abandoned=False,
)
result = linux.publish_admitted(
tag=tag,
commit=COMMIT,
archive=archive,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(archive),
authority=rehearsal_authority,
)
assert result["published"] is False
assert any("sequencer has not promoted" in reason for reason in result["reasons"])
assert r2_server.requests == []
assert "releases/linux/stable/stable-linux.yml" not in r2_server.store
assert "releases/linux/stable/stable-linux-arm64.yml" not in r2_server.store
@pytest.mark.parametrize(
"case",
["canary-unapproved", "canary-abandoned", "stable-abandoned", "authority-wrong-claim", "authority-wrong-commit"],
)
def test_abandoned_or_unapproved_candidate_writes_zero_feeds(r2_server, case): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
is_stable = case == "stable-abandoned"
tag = "v0.28.0" if is_stable else "canary.20261128T064458Z-v0.23.5"
archive = "rc.2-v0.28.0" if is_stable else tag
feeds, bytes_by_key = _inputs(tag, archive=archive)
_seed_artifacts(r2_server, bytes_by_key)
authority = linux.ChannelAuthority(
channel="stable" if is_stable else "canary",
claim_tag="canary.20261127T000000Z-v0.23.5" if case == "authority-wrong-claim" else archive,
commit=OTHER_COMMIT if case == "authority-wrong-commit" else COMMIT,
publish_canary_succeeded=(not is_stable and case != "canary-unapproved"),
sequencer_promoted=is_stable,
abandoned=case in {"canary-abandoned", "stable-abandoned"},
)
result = linux.publish_admitted(
tag=tag,
commit=COMMIT,
archive=archive,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(archive),
authority=authority,
)
assert result["published"] is False
assert result["reasons"]
assert r2_server.requests == []
@pytest.mark.parametrize(
"fault",
["missing-x64", "missing-arm64", "x64-unstaged", "arm64-smoke-failed", "x64-claim-mismatch", "arm64-commit-mismatch"],
)
def test_missing_skipped_or_failed_arch_smoke_writes_zero_feeds(r2_server, fault): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "canary.20261128T064458Z-v0.23.5"
feeds, bytes_by_key = _inputs(tag)
_seed_artifacts(r2_server, bytes_by_key)
evidence = _good_evidence(tag)
faults = {
"missing-x64": lambda: evidence.pop("x64"),
"missing-arm64": lambda: evidence.pop("arm64"),
"x64-unstaged": lambda: evidence.__setitem__("x64", linux.ArchEvidence("x64", tag, COMMIT, staged=False, smoke_passed=True)),
"arm64-smoke-failed": lambda: evidence.__setitem__("arm64", linux.ArchEvidence("arm64", tag, COMMIT, staged=True, smoke_passed=False)),
"x64-claim-mismatch": lambda: evidence.__setitem__("x64", linux.ArchEvidence("x64", "canary.20261127T064458Z-v0.23.5", COMMIT, staged=True, smoke_passed=True)),
"arm64-commit-mismatch": lambda: evidence.__setitem__("arm64", linux.ArchEvidence("arm64", tag, OTHER_COMMIT, staged=True, smoke_passed=True)),
}
faults[fault]()
authority = linux.ChannelAuthority(
channel="canary",
claim_tag=tag,
commit=COMMIT,
publish_canary_succeeded=True,
)
result = linux.publish_admitted(
tag=tag,
commit=COMMIT,
feeds_by_arch=feeds,
arch_evidence=evidence,
authority=authority,
)
assert result["published"] is False
assert result["reasons"]
assert r2_server.requests == []
def test_publish_admitted_stable_succeeds_with_verified_sequencer_promotion(r2_server): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "v0.28.0"
archive = "rc.2-v0.28.0"
feeds, bytes_by_key = _inputs(tag, archive=archive)
_seed_artifacts(r2_server, bytes_by_key)
authority = linux.ChannelAuthority(
channel="stable",
claim_tag=archive,
commit=COMMIT,
sequencer_promoted=True,
)
result = linux.publish_admitted(
tag=tag,
commit=COMMIT,
archive=archive,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(archive),
authority=authority,
)
assert result["published"] is True
assert result["written"] == [
"releases/linux/stable/stable-linux.yml",
"releases/linux/stable/stable-linux-arm64.yml",
]
for arch, key in zip(linux.ARCHES, result["written"]):
parsed = linux.parse_linux_feed(r2_server.store[key][0].decode())
assert parsed["version"] == "0.28.0"
assert parsed["files"][0]["url"].startswith(f"/releases/tag/{archive}/")
assert parsed["files"][0]["url"].endswith(f"-linux-{linux.APPIMAGE_ARCH[arch]}.AppImage")
def test_publish_admitted_rejects_downgrade_and_conflicting_same_version(r2_server): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
newer_tag = "v0.28.0"
newer_plans = linux.plan_linux_feeds(_inputs(newer_tag)[0], newer_tag)
for arch in linux.ARCHES:
r2_server.store[newer_plans[arch]["key"]] = (newer_plans[arch]["text"].encode(), '"live"')
# Semver downgrade rejected with zero PUTs.
older_tag = "v0.27.0"
older_feeds, older_bytes = _inputs(older_tag)
_seed_artifacts(r2_server, older_bytes)
with pytest.raises(ValueError, match="backward"):
linux.publish_admitted(
tag=older_tag,
commit=COMMIT,
feeds_by_arch=older_feeds,
arch_evidence=_good_evidence(older_tag),
authority=linux.ChannelAuthority("stable", older_tag, COMMIT, sequencer_promoted=True),
)
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
# Same version with different artifact bytes rejected with zero PUTs.
r2_server.requests.clear()
alt_feeds, alt_bytes = _inputs(newer_tag, salt="different-build")
_seed_artifacts(r2_server, alt_bytes)
with pytest.raises(ValueError, match="different artifacts"):
linux.publish_admitted(
tag=newer_tag,
commit=COMMIT,
feeds_by_arch=alt_feeds,
arch_evidence=_good_evidence(newer_tag),
authority=linux.ChannelAuthority("stable", newer_tag, COMMIT, sequencer_promoted=True),
)
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
def _stage_both_arches_via_handoff(tmp_path, tag: str, *, archive: str | None = None):
from scripts.releases import handoff
archive_tag = archive or tag
feeds, bytes_by_key = _inputs(tag, archive=archive_tag)
channel = "canary" if tag.startswith("canary.") else "stable"
for arch in linux.ARCHES:
stage_root = tmp_path / f"stage-{arch}"
stage_root.mkdir(parents=True)
feed_name = linux.linux_feed_spec(channel, arch)["fileName"]
(stage_root / feed_name).write_text(feeds[arch], encoding="utf-8")
appimage_key = next(k for k in bytes_by_key if f"-linux-{linux.APPIMAGE_ARCH[arch]}.AppImage" in k)
appimage_name = appimage_key.rsplit("/", 1)[-1]
(stage_root / appimage_name).write_bytes(bytes_by_key[appimage_key])
handoff.stage(archive_tag, COMMIT, f"linux-{arch}", stage_root, [appimage_name, feed_name])
return feeds, bytes_by_key
def test_publish_from_env_fetches_receipt_verified_feeds_and_publishes_both_arches(tmp_path, r2_server, monkeypatch, capsys): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "canary.20261129T064100Z-v0.23.5"
_stage_both_arches_via_handoff(tmp_path, tag)
capsys.readouterr()
r2_server.requests.clear()
env = {
"RELEASE_TAG": tag,
"RELEASE_ARCHIVE_TAG": tag,
"RELEASE_COMMIT": COMMIT,
"LINUX_X64_STAGED": "true",
"LINUX_X64_SMOKE_PASSED": "true",
"LINUX_ARM64_STAGED": "true",
"LINUX_ARM64_SMOKE_PASSED": "true",
"PUBLISH_CANARY_RESULT": "success",
}
for key, value in env.items():
monkeypatch.setenv(key, value)
rc = linux.main(["publish"])
assert rc == 0
out = json.loads(capsys.readouterr().out.strip().splitlines()[-1])
assert out["published"] is True
assert out["written"] == [
"releases/linux/canary/canary-linux.yml",
"releases/linux/canary/canary-linux-arm64.yml",
]
# Both published feeds exist with literal '+' preserved, no-store cache-control, and post-PUT GET readback ran.
for key in out["written"]:
body, _etag = r2_server.store[key]
parsed = linux.parse_linux_feed(body.decode("utf-8"))
assert parsed["version"] == "0.23.5+canary.20261129T064100Z"
assert "+canary.20261129T064100Z" in parsed["files"][0]["url"]
put_headers = [{k.lower(): v for k, v in headers.items()} for method, _, headers in r2_server.requests if method == "PUT"]
assert len(put_headers) == 2
assert all(h.get("cache-control") == "no-store" for h in put_headers)
# Verify post-PUT GET readback happened on both published keys.
for key in out["written"]:
methods_for_key = [m for m, p, _ in r2_server.requests if p.endswith(key)]
assert "PUT" in methods_for_key
assert methods_for_key[-1] == "GET"
@pytest.mark.parametrize(
"overrides",
[
{"LINUX_X64_SMOKE_PASSED": "false"},
{"LINUX_ARM64_SMOKE_PASSED": ""},
{"LINUX_ARM64_STAGED": "false"},
{"PUBLISH_CANARY_RESULT": "skipped"},
{"RELEASE_TAG": "v0.23.6", "RELEASE_ARCHIVE_TAG": "rc.2-v0.23.6", "SEQUENCER_PROMOTED": "false"},
{"CLAIM_ABANDONED": "true"},
],
)
def test_publish_from_env_writes_zero_requests_when_unadmitted(r2_server, monkeypatch, capsys, overrides): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
base_env = {
"RELEASE_TAG": "canary.20261129T064100Z-v0.23.5",
"RELEASE_ARCHIVE_TAG": "canary.20261129T064100Z-v0.23.5",
"RELEASE_COMMIT": COMMIT,
"LINUX_X64_STAGED": "true",
"LINUX_X64_SMOKE_PASSED": "true",
"LINUX_ARM64_STAGED": "true",
"LINUX_ARM64_SMOKE_PASSED": "true",
"PUBLISH_CANARY_RESULT": "success",
"SEQUENCER_PROMOTED": "false",
"CLAIM_ABANDONED": "false",
**overrides,
}
for key, value in base_env.items():
monkeypatch.setenv(key, value)
rc = linux.main(["publish"])
assert rc == 0
out = json.loads(capsys.readouterr().out)
assert out["published"] is False
assert out["written"] == []
assert out["reasons"]
assert r2_server.requests == []
def test_publish_from_env_rejects_tampered_staged_feed_before_any_put(tmp_path, r2_server, monkeypatch): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
monkeypatch.setattr(r2.time, "sleep", lambda _: None) # the shared download retries a mismatched transfer
tag = "canary.20261129T064100Z-v0.23.5"
_stage_both_arches_via_handoff(tmp_path, tag)
# Tamper the staged x64 feed after its handoff receipt was written.
tampered_key = f"releases/tag/{tag}/canary-linux.yml"
r2_server.store[tampered_key] = (b"version: 9.9.9\n", '"tampered"')
r2_server.requests.clear()
env = {
"RELEASE_TAG": tag,
"RELEASE_ARCHIVE_TAG": tag,
"RELEASE_COMMIT": COMMIT,
"LINUX_X64_STAGED": "true",
"LINUX_X64_SMOKE_PASSED": "true",
"LINUX_ARM64_STAGED": "true",
"LINUX_ARM64_SMOKE_PASSED": "true",
"PUBLISH_CANARY_RESULT": "success",
}
with pytest.raises(ValueError, match="checksum mismatch"):
linux.publish_from_env(env)
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
def test_publish_from_env_takes_each_feed_only_from_its_own_arch_receipt(tmp_path, r2_server): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "canary.20261129T064100Z-v0.23.5"
_stage_both_arches_via_handoff(tmp_path, tag)
# Move the x64 feed's receipt row from linux-x64's receipt to linux-arm64's: the bytes still match a
# receipt, but not the receipt of the arch whose smoke evidence admitted it.
receipts = {arch: f"releases/tag/{tag}/handoff-linux-{arch}.json" for arch in linux.ARCHES}
x64, arm64 = (json.loads(r2_server.store[receipts[arch]][0]) for arch in linux.ARCHES)
row = next(row for row in x64["files"] if row["path"] == "canary-linux.yml")
x64["files"].remove(row)
arm64["files"].append(row)
for arch, receipt in (("x64", x64), ("arm64", arm64)):
r2_server.store[receipts[arch]] = (json.dumps(receipt).encode(), f'"{arch}-moved"')
r2_server.requests.clear()
env = {
"RELEASE_TAG": tag,
"RELEASE_ARCHIVE_TAG": tag,
"RELEASE_COMMIT": COMMIT,
"LINUX_X64_STAGED": "true",
"LINUX_X64_SMOKE_PASSED": "true",
"LINUX_ARM64_STAGED": "true",
"LINUX_ARM64_SMOKE_PASSED": "true",
"PUBLISH_CANARY_RESULT": "success",
}
with pytest.raises(ValueError):
linux.publish_from_env(env)
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
assert "releases/linux/canary/canary-linux.yml" not in r2_server.store
def test_put_and_verify_feed_fails_on_readback_mismatch_in_production_mode(r2_server, monkeypatch): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "canary.20261129T064100Z-v0.23.5"
feeds, bytes_by_key = _inputs(tag)
_seed_artifacts(r2_server, bytes_by_key)
real_get = linux._get_live_feed
def corrupt_after_put(creds, base, bucket, key, now):
text, etag = real_get(creds, base, bucket, key, now)
if text is not None and key == "releases/linux/canary/canary-linux.yml":
return text + "# corrupted readback\n", etag
return text, etag
monkeypatch.setattr(linux, "_get_live_feed", corrupt_after_put)
with pytest.raises(ValueError, match="readback differs"):
linux.publish_admitted(
tag=tag,
commit=COMMIT,
feeds_by_arch=feeds,
arch_evidence=_good_evidence(tag),
authority=linux.ChannelAuthority("canary", tag, COMMIT, publish_canary_succeeded=True),
)
def test_record_evidence_and_publish_stable_record_round_trip(tmp_path, r2_server, monkeypatch, capsys): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "v0.23.6"
archive = "rc.2-v0.23.6"
_stage_both_arches_via_handoff(tmp_path, tag, archive=archive)
capsys.readouterr()
r2_server.requests.clear()
env = {
"RELEASE_TAG": tag,
"RELEASE_ARCHIVE_TAG": archive,
"RELEASE_COMMIT": COMMIT,
"LINUX_X64_STAGED": "true",
"LINUX_X64_SMOKE_PASSED": "true",
"LINUX_ARM64_STAGED": "true",
"LINUX_ARM64_SMOKE_PASSED": "true",
}
for key, value in env.items():
monkeypatch.setenv(key, value)
# Candidate run records immutable cross-run evidence under releases/tag/<archive>/ only.
assert linux.main(["record-evidence"]) == 0
rec = json.loads(capsys.readouterr().out.strip().splitlines()[-1])
assert rec == {
"key": f"releases/tag/{archive}/linux-evidence.json",
"recorded": True,
"reasons": [],
"skipped": False,
}
# Zero live Linux feeds touched during candidate / rehearsal phase.
assert not any(k.startswith("releases/linux/") for k in r2_server.store)
# Idempotent retry succeeds without an extra PUT.
r2_server.requests.clear()
again = linux.record_evidence_from_env(env)
assert again["recorded"] is True and again["skipped"] is True
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
# Held rehearsal / burned / non-linux records produce zero R2 requests.
for blocked in (
{"state": "green", "lanes": frozenset({"linux", "windows"}), "tag": tag, "claim_tag": archive, "commit": COMMIT},
{"state": "burned", "lanes": frozenset({"linux", "windows"}), "tag": tag, "claim_tag": archive, "commit": COMMIT},
{"state": "published", "lanes": frozenset({"windows", "macos-arm64"}), "tag": tag, "claim_tag": archive, "commit": COMMIT},
):
r2_server.requests.clear()
res = linux.publish_stable_record(blocked)
assert res["published"] is False and res["reasons"]
assert r2_server.requests == []
# Separate publication run promotes stable feeds once sequencer confirms state == 'published'.
r2_server.requests.clear()
promoted = linux.publish_stable_record({
"state": "published",
"lanes": frozenset({"windows", "macos-arm64", "linux"}),
"tag": tag,
"claim_tag": archive,
"commit": COMMIT,
})
assert promoted["published"] is True
assert promoted["written"] == [
"releases/linux/stable/stable-linux.yml",
"releases/linux/stable/stable-linux-arm64.yml",
]
for arch, key in zip(linux.ARCHES, promoted["written"]):
parsed = linux.parse_linux_feed(r2_server.store[key][0].decode("utf-8"))
assert parsed["version"] == "0.23.6"
assert parsed["files"][0]["url"] == f"/releases/tag/{archive}/HermesBundled-0.23.6-linux-{linux.APPIMAGE_ARCH[arch]}.AppImage"
# Subsequent sequencer pass is an idempotent no-op with zero PUTs.
r2_server.requests.clear()
noop = linux.publish_stable_record({
"state": "published",
"lanes": frozenset({"windows", "macos-arm64", "linux"}),
"tag": tag,
"claim_tag": archive,
"commit": COMMIT,
})
assert noop["published"] is True and noop["written"] == []
assert noop["skipped"] == promoted["written"]
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
@pytest.mark.parametrize(
"overrides",
[
{"LINUX_X64_SMOKE_PASSED": "false"},
{"LINUX_ARM64_SMOKE_PASSED": ""},
{"LINUX_X64_STAGED": "false"},
],
)
def test_record_evidence_writes_zero_requests_when_either_arch_incomplete(r2_server, overrides): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
env = {
"RELEASE_TAG": "v0.23.6",
"RELEASE_ARCHIVE_TAG": "rc.2-v0.23.6",
"RELEASE_COMMIT": COMMIT,
"LINUX_X64_STAGED": "true",
"LINUX_X64_SMOKE_PASSED": "true",
"LINUX_ARM64_STAGED": "true",
"LINUX_ARM64_SMOKE_PASSED": "true",
**overrides,
}
res = linux.record_evidence_from_env(env)
assert res["recorded"] is False and res["key"] is None and res["reasons"]
assert r2_server.requests == []
def test_publish_stable_record_rejects_missing_or_mismatched_evidence(tmp_path, r2_server): # health: allow F811 -- pytest injects the imported r2_server fixture by parameter name
tag = "v0.23.6"
archive = "rc.2-v0.23.6"
_stage_both_arches_via_handoff(tmp_path, tag, archive=archive)
r2_server.requests.clear()
# No linux-evidence.json staged -> clean refusal with zero PUTs.
record = {
"state": "published",
"lanes": frozenset({"windows", "linux"}),
"tag": tag,
"claim_tag": archive,
"commit": COMMIT,
}
missing = linux.publish_stable_record(record)
assert missing["published"] is False
assert "missing staged Linux smoke evidence receipt" in missing["reasons"][0]
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []
# Evidence bound to a different commit -> fail closed with zero PUTs.
r2_server.store[linux.evidence_key(archive)] = (
json.dumps({
"schema": 1, "tag": tag, "archive": archive, "commit": OTHER_COMMIT,
"arches": {"x64": {"staged": True, "smokePassed": True}, "arm64": {"staged": True, "smokePassed": True}},
}).encode("utf-8"),
'"wrong-commit"',
)
r2_server.requests.clear()
with pytest.raises(ValueError, match="commit"):
linux.publish_stable_record(record)
assert [m for m, _, _ in r2_server.requests if m == "PUT"] == []