fix(release): preserve candidate source across artifact transport

This commit is contained in:
Xubin Ren committed 2026-10-28 16:54:41 +08:00
1 parent 89d35863d9
commit 91972b0e4f
3 files changed
+65

No files matched your search

+25
View File
@@ -252,6 +252,31 @@ jobs:
merge-multiple: true
path: ${{ runner.temp }}/retained-candidate
- name: Verify the downloaded handoff before retaining accepted bytes
if: inputs.retain_installable
env:
HANDOFF: ${{ runner.temp }}/retained-candidate
CANDIDATE_COMMIT: ${{ needs.candidate.outputs.candidate_commit }}
MANIFEST_SHA256: ${{ needs.candidate.outputs.manifest_sha256 }}
run: |
git --git-dir="$HANDOFF/source.git" fsck --full
test "$(git --git-dir="$HANDOFF/source.git" rev-parse HEAD)" = "$CANDIDATE_COMMIT"
python - <<'PY'
import hashlib, json, os
from pathlib import Path
root = Path(os.environ["HANDOFF"])
manifest = (root / "artifacts/release-manifest.json").read_bytes()
assert hashlib.sha256(manifest).hexdigest() == os.environ["MANIFEST_SHA256"]
handoff = json.loads((root / "handoff.json").read_text())
assert handoff["candidate_commit"] == os.environ["CANDIDATE_COMMIT"]
assert handoff["manifest_sha256"] == os.environ["MANIFEST_SHA256"]
for artifact in json.loads(manifest)["artifacts"]:
payload = (root / "artifacts" / artifact["filename"]).read_bytes()
assert len(payload) == artifact["size"]
assert hashlib.sha256(payload).hexdigest() == artifact["sha256"]
PY
- name: Retain accepted installable candidate for separate approval
if: inputs.retain_installable
uses: actions/upload-artifact@v4
+3
View File
@@ -326,6 +326,9 @@ def retain_candidate(root: Path, artifacts: Path, output: Path, *, source_commit
_git(root, "-c", f"init.templateDir={template}", "clone", "--bare", "--depth", "2",
"--single-branch", "--no-tags", root.as_uri(), str(source))
(source / "config").write_text("[core]\nrepositoryformatversion = 0\nbare = true\n", encoding="utf-8")
# Artifact transport keeps files, not empty directories. A bare clone can
# have only packed refs; retain a loose ref so the downloaded Git tree works.
_git(source, "update-ref", "refs/retained/candidate", manifest.candidate_commit)
_git(source, "fsck", "--full")
if _git(source, "rev-parse", "HEAD") != manifest.candidate_commit:
raise ValueError("Retained source differs from the candidate")
+37
View File
@@ -3,9 +3,12 @@
import subprocess
import tomllib
from types import SimpleNamespace
from zipfile import ZipFile
import pytest
from nanobot.releases import ReleaseArtifact, ReleaseManifest, release_filenames
from scripts import release_candidate
from scripts.release_candidate import (
_candidate_identity,
_source_payload,
@@ -151,3 +154,37 @@ def test_candidate_verifies_bundled_documentation_against_its_tracked_source(sou
for name in (reference, "docs/README.md"):
with pytest.raises(ValueError, match="differs from the candidate"):
_source_payload(root, {**packaged, prefix + name: b"Unchecked instructions"}, prefix)
def test_retained_source_survives_file_only_artifact_transport(tmp_path, source, monkeypatch):
root, commit = source
manifest = ReleaseManifest(
version="0.3.5", source_commit=commit, candidate_commit=commit,
requires_python=">=3.11",
artifacts=[ReleaseArtifact(filename=name, size=123, sha256="c" * 64)
for name in sorted(release_filenames("0.3.5"))],
)
artifacts = tmp_path / "artifacts"
artifacts.mkdir()
for artifact in manifest.artifacts:
(artifacts / artifact.filename).write_bytes(b"structurally verified elsewhere")
(artifacts / "release-manifest.json").write_text(manifest.model_dump_json(), encoding="utf-8")
# Exercise actual Git retention and ZIP transport; packaging has independent
# real-archive coverage and is not the contract under test here.
monkeypatch.setattr(release_candidate, "verify_candidate", lambda *args, **kwargs: manifest)
monkeypatch.setattr(release_candidate, "write_install_guide", lambda *args, **kwargs: None)
retained = tmp_path / "retained"
release_candidate.retain_candidate(root, artifacts, retained, source_commit=commit)
with ZipFile(tmp_path / "handoff.zip", "w") as archive:
for path in retained.rglob("*"):
if path.is_file():
archive.write(path, path.relative_to(retained))
downloaded = tmp_path / "downloaded"
with ZipFile(tmp_path / "handoff.zip") as archive:
archive.extractall(downloaded)
restored = downloaded / "source.git"
git(restored, "fsck", "--full")
assert git(restored, "rev-parse", "HEAD") == commit
checkout = tmp_path / "checkout"
git(tmp_path, "clone", str(restored), str(checkout))
assert (checkout / "pyproject.toml").read_bytes() == (root / "pyproject.toml").read_bytes()