release: take the stdlib Bundle as one explicit, pinned input

package.py now requires --stdlib-dir and accepts --bundle-pin; it
verifies the manifest, required files, tree/alias digests and the pin
before staging, copies exactly that Bundle next to the binary, and
records stdlib.source{kind,repository,commit,path} in RELEASE_INFO.
Digest logic moves to tools/stdlib/bundle.py. GitHub/Woodpecker
release steps and docs/releasing.md pass the pinned input.
This commit is contained in:
cflmy committed 2026-11-26 15:07:29 +08:00
1 parent 1b9d9c4c26
commit 422b9de6d7
6 files changed
+138 -90

No files matched your search

+53 -8
View File
@@ -2,8 +2,8 @@
These tests are stdlib-only and do not build an archive; they pin the digest
helpers that package.py/smoke.py share with the runtime and check that the
release pipeline references a verified stdlib bundle instead of relying on the
compile-time source path.
release pipeline takes the stdlib Bundle as one explicit, verified input
instead of relying on the compile-time source path (ADR-0070).
"""
from __future__ import annotations
@@ -12,6 +12,8 @@ import contextlib
import importlib.util
import io
import json
import shutil
import tempfile
import unittest
from pathlib import Path
@@ -31,10 +33,11 @@ class ReleaseArchiveContractTest(unittest.TestCase):
self.package = load_module("release_package", ROOT / "tools/release/package.py")
self.smoke = load_module("release_smoke", ROOT / "tools/release/smoke.py")
self.manifest = json.loads((ROOT / "stdlib/stdlib.json").read_text(encoding="utf-8"))
self.pin = json.loads((ROOT / "tools/stdlib/bundle-pin.json").read_text(encoding="utf-8"))
def test_tree_digest_matches_manifest(self) -> None:
self.assertEqual(
self.package.stdlib_tree_digest(), self.manifest["digest"]
self.package.stdlib_tree_digest(ROOT / "stdlib"), self.manifest["digest"]
)
self.assertEqual(
self.smoke.stdlib_tree_digest(ROOT / "stdlib"), self.manifest["digest"]
@@ -51,7 +54,9 @@ class ReleaseArchiveContractTest(unittest.TestCase):
)
def test_verify_record_names_required_files_and_count(self) -> None:
record = self.package.verify_stdlib()
record = self.package.verify_stdlib(
ROOT / "stdlib", ROOT / "tools/stdlib/bundle-pin.json"
)
self.assertEqual(record["name"], self.manifest["name"])
self.assertEqual(record["version"], self.manifest["version"])
self.assertEqual(record["tree_digest"], self.manifest["digest"])
@@ -60,13 +65,53 @@ class ReleaseArchiveContractTest(unittest.TestCase):
self.assertIn("io.mq.md", record["files"])
self.assertIn("io/console.mq.md", record["files"])
self.assertEqual(record["file_count"], len(record["files"]))
self.assertEqual(record["source"]["commit"], self.pin["source"]["commit"])
self.assertEqual(record["source"]["kind"], "in-repo")
def test_package_stages_stdlib_next_to_the_binary_and_math_backend(self) -> None:
def test_verify_record_has_no_source_without_a_pin(self) -> None:
record = self.package.verify_stdlib(ROOT / "stdlib")
self.assertNotIn("source", record)
def test_missing_explicit_input_fails_closed(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
with self.assertRaises(SystemExit) as raised:
self.package.verify_stdlib(Path(tmp) / "missing")
self.assertEqual(raised.exception.code, 1)
self.assertIn("does not exist", stderr.getvalue())
def test_tampered_explicit_input_and_wrong_pin_fail_closed(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
copy = Path(tmp) / "stdlib"
shutil.copytree(ROOT / "stdlib", copy)
(copy / "io.mq.md").write_text("## @knowledge tampered\n", encoding="utf-8")
with contextlib.redirect_stderr(io.StringIO()):
with self.assertRaises(SystemExit) as raised:
self.package.verify_stdlib(copy)
self.assertEqual(raised.exception.code, 1)
shutil.rmtree(copy)
shutil.copytree(ROOT / "stdlib", copy)
restamped = json.loads((copy / "stdlib.json").read_text(encoding="utf-8"))
restamped["version"] = "9.9.9"
(copy / "stdlib.json").write_text(json.dumps(restamped), encoding="utf-8")
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
with self.assertRaises(SystemExit) as raised:
self.package.verify_stdlib(copy, ROOT / "tools/stdlib/bundle-pin.json")
self.assertEqual(raised.exception.code, 1)
self.assertIn("does not match the pin", stderr.getvalue())
def test_package_takes_one_explicit_stdlib_dir(self) -> None:
source = (ROOT / "tools/release/package.py").read_text(encoding="utf-8")
self.assertIn('copy_tree(STDLIB, stage_dir / "stdlib")', source)
self.assertIn('"math-backend"', source.replace("math_backend", "math-backend"))
self.assertIn('add_argument("--stdlib-dir", required=True)', source)
self.assertIn('add_argument("--bundle-pin"', source)
self.assertIn('copy_tree(stdlib_dir, stage_dir / "stdlib")', source)
self.assertIn('"stdlib": stdlib_info', source)
self.assertIn("verify_stdlib()", source)
self.assertIn("verify_stdlib(", source)
self.assertNotIn('STDLIB = ROOT / "stdlib"', source)
self.assertIn('"math-backend"', source.replace("math_backend", "math-backend"))
def test_archive_declares_only_current_analysis_revision(self) -> None:
self.smoke.verify_analysis_metadata({"analysis": 3})