Something went wrong. Try again.
Hardware-in-the-loop development platform for the Commodore 64.
Something went wrong. Try again.
8.2 kB · 156 lines
Python
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157"""Regressions for real hidden snapshot inputs and per-archive audit gating."""from __future__ import annotations
import jsonimport sysimport tempfileimport unittestfrom pathlib import Pathfrom unittest.mock import patch
ROOT = Path(__file__).resolve().parents[2]sys.path.insert(0, str(ROOT / "tools"))sys.path.insert(0, str(Path(__file__).resolve().parent))import package_release as packagingimport check_releasefrom test_release_package import SyntheticProject, build_tar
class SourceModuleSelectionTests(unittest.TestCase): def test_target_source_module_is_not_cargo_output(self): manifest = packaging.load_source_manifest(ROOT / "tools/release_source_manifest.json") files, _ = packaging.collect_source_files(ROOT, manifest) selected = {entry["path"] for entry in files} for module in (ROOT / "crates/ultimate-tool-core/src/target").glob("*.rs"): self.assertIn(module.relative_to(ROOT).as_posix(), selected) self.assertIn("crates/ultimate-tool-core/src/target/mod.rs", selected) self.assertFalse(any(path.startswith("target/") for path in selected)) self.assertTrue(packaging._is_always_excluded("fixtures/checkpoint-demo/target/release/file")) self.assertFalse(packaging._is_always_excluded("crates/ultimate-tool-core/src/target/ultimate.rs"))
def test_generated_targets_below_source_are_still_excluded(self): generated = [ "crates/ultimate-tool-core/src/build-check/target/release/file", "fixtures/checkpoint-demo/src/target/release/file", "crates/ultimate-tool-core/src/target/target/release/file", ] with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) source = "crates/ultimate-tool-core/src/target/mod.rs" for relative in generated + [source]: path = root / relative path.parent.mkdir(parents=True, exist_ok=True) path.write_bytes(b"harmless regular data") manifest = {"source_paths": {"include": [ {"path": "crates/", "kind": "crate-source"}, {"path": "fixtures/", "kind": "fixture-source"}, ], "deny": []}} files, _ = packaging.collect_source_files(root, manifest) paths = {entry["path"] for entry in files} self.assertEqual(paths, {source}) shipped = packaging.select_shipped_files(root, "crates", manifest) self.assertEqual(shipped, [source]) for relative in generated: self.assertTrue(packaging._is_always_excluded(relative), relative)
class SnapshotSelectionTests(unittest.TestCase): def test_real_example_selection_includes_every_snapshot_input(self): manifest = packaging.load_source_manifest(ROOT / "tools/release_source_manifest.json") selected = set(packaging.select_shipped_files(ROOT, "examples/first-run", manifest)) snapshot = json.loads((ROOT / "examples/first-run/snapshot.json").read_text()) paths = [] def visit(value): if isinstance(value, dict): if isinstance(value.get("path"), str): # The snapshot records every packaged file at its true path, # including the build outputs under outputs/. The archive # carries those exact paths; the materialized build/ tree is # a local product and is never shipped. paths.append(value["path"]) for child in value.values(): visit(child) elif isinstance(value, list): for child in value: visit(child) visit(snapshot) for relative in paths: candidate = ROOT / "examples/first-run" / relative if candidate.is_file(): self.assertIn("examples/first-run/" + relative, selected) self.assertIn("examples/first-run/sources/fixtures/rust-mos-smoke/.cargo/config.toml", selected) for name in ("elf", "map", "prg"): self.assertIn(f"examples/first-run/outputs/build/ultimate-tool-smoke.{name}", selected) self.assertFalse( any(path.startswith("examples/first-run/build/") for path in selected), "the materialized build/ destination must never be shipped", )
def test_explicit_hidden_child_does_not_admit_a_private_sibling(self): with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) hidden = root / "example/.cargo" hidden.mkdir(parents=True) (hidden / "config.toml").write_text("[build]\n") manifest = {"source_paths": {"include": [ {"path": "example/.cargo/config.toml", "hidden": True} ], "deny": []}} self.assertEqual(packaging.select_shipped_files(root, "example", manifest), ["example/.cargo/config.toml"]) (hidden / "private").write_text("not approved") with self.assertRaises(packaging.CheckFailure): packaging.select_shipped_files(root, "example", manifest)
class ArchiveAuditBoundaryTests(unittest.TestCase): def test_failed_binary_audit_has_no_binary_privacy_scan(self): with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) / "project" root.mkdir() project = SyntheticProject(root) project.write() project.development_package_with_evidence() manifest = json.loads((project.output / "release-manifest.json").read_text()) binary = project.output / manifest["archive"]["name"] build_tar(binary, [("duplicate/a", b"one"), ("duplicate/a", b"two")]) real = check_release.scan_archive scanned = [] def scan(path, prefix, limits=packaging.DEFAULT_LIMITS): scanned.append(Path(path).name) if Path(path) == binary: raise AssertionError("failed binary archive was reopened for content scanning") return real(path, prefix, limits) with patch.object(check_release, "scan_archive", scan): result = check_release.validate_release(project.output, source_root=root, require_ready=False, mode="development") self.assertNotIn(binary.name, scanned) self.assertIn(manifest["source_archive"]["name"], scanned) checks = {item["check"]: item for item in result["checks"]} self.assertEqual(checks["binary_archive_privacy"]["state"], "not_verified") self.assertIn("skipped", checks["binary_archive_privacy"]["detail"])
def test_failed_source_audit_has_no_source_content_scan(self): with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) / "project" root.mkdir() project = SyntheticProject(root) project.write() project.development_package_with_evidence() manifest = json.loads((project.output / "release-manifest.json").read_text()) source = project.output / manifest["source_archive"]["name"] build_tar(source, [("duplicate/a", b"one"), ("duplicate/a", b"two")]) real = check_release.scan_archive def scan(path, prefix, limits=packaging.DEFAULT_LIMITS): if Path(path) == source: raise AssertionError("failed source archive was reopened for content scanning") return real(path, prefix, limits) with patch.object(check_release, "scan_archive", scan): result = check_release.validate_release(project.output, source_root=root, require_ready=False, mode="development") checks = {item["check"]: item for item in result["checks"]} self.assertEqual(checks["source_archive_contents"]["state"], "not_verified") self.assertIn("skipped", checks["source_archive_contents"]["detail"])
if __name__ == "__main__": unittest.main()