refactor: accept the ecosystem stdlib Bundle and remove the in-repo sources
Phase B of ADR-0070 (issue #11): the CLI no longer owns standard-library sources. The pin names the accepted ecosystem Bundle (marqdo-stdlib@0.2.0, root commit + tree/alias digests); tools/ci/fetch_ecosystem_bundle.py materializes it from the pinned root commit and stdlib gitlinks and verifies the digests. bundle.py and the test harness require an explicit verified Bundle for the accepted identity, and runtime discovery has no compile-time source fallback in any profile. Delete stdlib/ (modules, self-tests, aliases manifest). Module and domain tests stay with their component owners; the CLI product lane now verifies the external Bundle's public surface, std: resolution and official print/打印 alias routing (tests/product-stdlib). Composition assertions whose owner is the ecosystem (Table split, print-format equivalence) moved to the root Bundle acceptance; the generic TCP round-trip stays a CLI test. Spawned-CLI tests name the verified Bundle explicitly. CI (Woodpecker + GitHub) materializes the pinned Bundle before product tests, packaging and performance lanes; packaging and release take --stdlib-dir from that artifact. Docs, STATUS, ADR-0070 and a Phase B evidence record updated. Refs cflmy/marqdo#9, cflmy/marqdo-cli#11
This commit is contained in:
1 parent
f8b82d4143
commit
72f57beee0
85 files changed
+796
-5939
No files matched your search
@@ -12,12 +12,33 @@ import contextlib
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
BUNDLE_ENV = "MARQDO_TEST_STDLIB_BUNDLE"
|
||||
|
||||
|
||||
def product_bundle() -> Path:
|
||||
"""The explicit verified Bundle for product-level unit tests.
|
||||
|
||||
Phase B no longer ships a Bundle in this repository; CI and maintainers pass
|
||||
one produced from the pinned ecosystem commit. Missing input is an explicit
|
||||
skip here (this is a unit-test fixture, not release acceptance), while the
|
||||
product lane itself fails closed.
|
||||
"""
|
||||
value = os.environ.get(BUNDLE_ENV)
|
||||
if not value:
|
||||
raise unittest.SkipTest(
|
||||
f"set {BUNDLE_ENV} to a verified Bundle (tools/ci/fetch_ecosystem_bundle.py)"
|
||||
)
|
||||
root = Path(value)
|
||||
if not (root / "stdlib.json").is_file():
|
||||
raise AssertionError(f"{BUNDLE_ENV} does not name a Bundle: {root}")
|
||||
return root
|
||||
|
||||
|
||||
def load_module(name: str, path: Path):
|
||||
@@ -32,15 +53,20 @@ class ReleaseArchiveContractTest(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
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"))
|
||||
self.bundle = product_bundle()
|
||||
self.manifest = json.loads(
|
||||
(self.bundle / "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(ROOT / "stdlib"), self.manifest["digest"]
|
||||
self.package.stdlib_tree_digest(self.bundle), self.manifest["digest"]
|
||||
)
|
||||
self.assertEqual(
|
||||
self.smoke.stdlib_tree_digest(ROOT / "stdlib"), self.manifest["digest"]
|
||||
self.smoke.stdlib_tree_digest(self.bundle), self.manifest["digest"]
|
||||
)
|
||||
|
||||
def test_alias_digest_matches_manifest(self) -> None:
|
||||
@@ -55,7 +81,7 @@ class ReleaseArchiveContractTest(unittest.TestCase):
|
||||
|
||||
def test_verify_record_names_required_files_and_count(self) -> None:
|
||||
record = self.package.verify_stdlib(
|
||||
ROOT / "stdlib", ROOT / "tools/stdlib/bundle-pin.json"
|
||||
self.bundle, ROOT / "tools/stdlib/bundle-pin.json"
|
||||
)
|
||||
self.assertEqual(record["name"], self.manifest["name"])
|
||||
self.assertEqual(record["version"], self.manifest["version"])
|
||||
@@ -66,10 +92,10 @@ class ReleaseArchiveContractTest(unittest.TestCase):
|
||||
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")
|
||||
self.assertEqual(record["source"]["kind"], "ecosystem")
|
||||
|
||||
def test_verify_record_has_no_source_without_a_pin(self) -> None:
|
||||
record = self.package.verify_stdlib(ROOT / "stdlib")
|
||||
record = self.package.verify_stdlib(self.bundle)
|
||||
self.assertNotIn("source", record)
|
||||
|
||||
def test_missing_explicit_input_fails_closed(self) -> None:
|
||||
@@ -84,7 +110,7 @@ class ReleaseArchiveContractTest(unittest.TestCase):
|
||||
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)
|
||||
shutil.copytree(self.bundle, 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:
|
||||
@@ -92,7 +118,7 @@ class ReleaseArchiveContractTest(unittest.TestCase):
|
||||
self.assertEqual(raised.exception.code, 1)
|
||||
|
||||
shutil.rmtree(copy)
|
||||
shutil.copytree(ROOT / "stdlib", copy)
|
||||
shutil.copytree(self.bundle, 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")
|
||||
@@ -110,7 +136,7 @@ class ReleaseArchiveContractTest(unittest.TestCase):
|
||||
self.assertIn('copy_tree(stdlib_dir, stage_dir / "stdlib")', source)
|
||||
self.assertIn('"stdlib": stdlib_info', source)
|
||||
self.assertIn("verify_stdlib(", source)
|
||||
self.assertNotIn('STDLIB = ROOT / "stdlib"', source)
|
||||
self.assertNotIn('ROOT / "stdlib"', source)
|
||||
self.assertIn('"math-backend"', source.replace("math_backend", "math-backend"))
|
||||
|
||||
def test_archive_declares_only_current_analysis_revision(self) -> None:
|
||||
@@ -120,14 +146,14 @@ class ReleaseArchiveContractTest(unittest.TestCase):
|
||||
with self.assertRaises(SystemExit):
|
||||
self.smoke.verify_analysis_metadata(malformed)
|
||||
|
||||
def test_release_discovery_does_not_fall_back_to_the_source_tree(self) -> None:
|
||||
def test_release_discovery_has_no_source_tree_fallback(self) -> None:
|
||||
source = (ROOT / "crates/cli/src/stdlib.rs").read_text(encoding="utf-8")
|
||||
fallback = source.index("CARGO_MANIFEST_DIR")
|
||||
self.assertIn("#[cfg(debug_assertions)]", source[:fallback])
|
||||
# The compile-time path must be inside the debug-only block: a release
|
||||
# build cannot reach it.
|
||||
debug_block = source[fallback - 200 : fallback + 400]
|
||||
self.assertIn("#[cfg(debug_assertions)]", debug_block)
|
||||
# Phase B: no build profile may reach a compile-time source tree; only the
|
||||
# explicit override and the installed sibling Bundle remain.
|
||||
self.assertNotIn("CARGO_MANIFEST_DIR", source)
|
||||
self.assertNotIn("debug_assertions", source)
|
||||
self.assertIn("STDLIB_DIR_ENV", source)
|
||||
self.assertIn("parent.join(\"stdlib\")", source)
|
||||
|
||||
def test_smoke_verifies_and_fails_closed_without_stdlib(self) -> None:
|
||||
source = (ROOT / "tools/release/smoke.py").read_text(encoding="utf-8")
|
||||
|
||||
Reference in new issue
Block a user