Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(release): preserve candidate source across artifact transport
Xubin Ren91972b0e4f67
diff --git a/.github/workflows/release-candidate.yml b/.github/workflows/release-candidate.ymlindex fb7e37e9f..c1fae169f 100644--- a/.github/workflows/release-candidate.yml+++ b/.github/workflows/release-candidate.yml@@ -252,6 +252,31 @@ jobs:merge-multiple: truepath: ${{ 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 approvalif: inputs.retain_installableuses: actions/upload-artifact@v4diff --git a/scripts/release_candidate.py b/scripts/release_candidate.pyindex 38a1666ad..e89fd49fc 100644--- a/scripts/release_candidate.py+++ b/scripts/release_candidate.py@@ -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")diff --git a/tests/test_release_candidate.py b/tests/test_release_candidate.pyindex 5fee64bcf..17bae904d 100644--- a/tests/test_release_candidate.py+++ b/tests/test_release_candidate.py@@ -3,9 +3,12 @@import subprocessimport tomllibfrom types import SimpleNamespace+from zipfile import ZipFileimport pytest+from nanobot.releases import ReleaseArtifact, ReleaseManifest, release_filenames+from scripts import release_candidatefrom scripts.release_candidate import (_candidate_identity,_source_payload,@@ -151,3 +154,37 @@ def test_candidate_verifies_bundled_documentation_against_its_tracked_source(soufor 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()