| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #!/usr/bin/env python3
- """Regression: review-compact source/ is exact DELIVERY tracked subset."""
- from __future__ import annotations
- import json
- import tempfile
- import unittest
- import zipfile
- from pathlib import Path
- ROOT = Path(__file__).resolve().parents[2]
- import sys
- sys.path.insert(0, str(ROOT))
- sys.path.insert(0, str(ROOT / "tools"))
- import package_for_agent_analysis as analyzer # noqa: E402
- import compact_package_selftest as selftest # noqa: E402
- class ExactCommitSourceSnapshotTests(unittest.TestCase):
- maxDiff = None
- def test_collect_exact_commit_keeps_formal_excludes_sby_workdir(self) -> None:
- with tempfile.TemporaryDirectory(prefix="prod2u-exact-") as tmp:
- temp_root = Path(tmp)
- # Plant untracked SBY junk in live tree — must NOT enter exact snapshot.
- junk_dir = ROOT / "tests" / "formal" / "alt_config_limit_normalize_bmc" / "src"
- junk_dir.mkdir(parents=True, exist_ok=True)
- junk = junk_dir / "alt_config_limit_normalize_formal.v"
- planted = False
- if not junk.is_file():
- junk.write_text("// planted untracked junk\n", encoding="utf-8")
- planted = True
- try:
- commit = analyzer._resolve_delivery_commit(ROOT, None)
- items, _excl, manifest = analyzer._collect_exact_commit_unified_items(
- root=ROOT,
- commit=commit,
- source_id="workspace-current",
- temp_root=temp_root,
- extra_exclusions=(),
- profile="review-compact",
- )
- finally:
- if planted and junk.is_file():
- junk.unlink()
- self.assertEqual(manifest["source_snapshot_mode"], "exact_commit_tracked_subset")
- source_paths = {
- item.candidate.relative
- for item in items
- if item.candidate.relative.startswith("source/")
- }
- self.assertIn(
- "source/tests/formal/alt_config_limit_normalize_formal.v",
- source_paths,
- )
- self.assertFalse(
- any("alt_config_limit_normalize_bmc" in p for p in source_paths)
- )
- self.assertFalse(
- any("alt_config_limit_normalize_cover" in p for p in source_paths)
- )
- included = {
- str(row["path"])
- for row in manifest["included_source_files"]
- if isinstance(row, dict)
- }
- self.assertIn("tests/formal/alt_config_limit_normalize_formal.v", included)
- def test_content_dedup_never_drops_source_software(self) -> None:
- with tempfile.TemporaryDirectory(prefix="prod2u-dedup-") as tmp:
- root = Path(tmp)
- a = root / "formal.v"
- b = root / "copy.v"
- payload = b"module x; endmodule\n"
- a.write_bytes(payload)
- b.write_bytes(payload)
- items = (
- analyzer.make_package_item(
- a,
- relative="source/tests/formal/alt_config_limit_normalize_formal.v",
- category="source",
- source_id="t",
- ),
- analyzer.make_package_item(
- b,
- relative="source/tests/formal/alt_config_limit_normalize_bmc/src/alt_config_limit_normalize_formal.v",
- category="source",
- source_id="t",
- ),
- )
- inventory = [
- {
- "path": item.candidate.relative,
- "sha256": __import__("hashlib").sha256(payload).hexdigest(),
- "size": len(payload),
- }
- for item in items
- ]
- kept, _records, _excl = analyzer.apply_content_dedup(items, inventory)
- kept_paths = {item.candidate.relative for item in kept}
- self.assertIn(
- "source/tests/formal/alt_config_limit_normalize_formal.v",
- kept_paths,
- )
- if __name__ == "__main__":
- unittest.main()
|