import importlib.util
from pathlib import Path
import tempfile, unittest
ROOT=Path(__file__).resolve().parents[1]
SPEC=importlib.util.spec_from_file_location("snapshot", ROOT/"ci/check_base_v3_source_snapshot.py")
MOD=importlib.util.module_from_spec(SPEC); SPEC.loader.exec_module(MOD)
class SnapshotScopeTests(unittest.TestCase):
 def test_official_snapshot_passes_without_overrides(self): self.assertEqual([], MOD.verify())
 def test_migration_and_operations_are_excluded(self):
  paths=[line.split("  ",1)[1] for line in MOD.MANIFEST.read_text().splitlines() if line]
  self.assertFalse(any(p.startswith(("v3-migration/","v3-operations/")) for p in paths))
 def test_downstream_rows_are_rejected(self):
  with tempfile.TemporaryDirectory() as d:
   root=Path(d); (root/"v3-migration").mkdir(); f=root/"v3-migration/ledger.json"; f.write_text("{}")
   import hashlib
   m=root/"manifest"; m.write_text(f"{hashlib.sha256(f.read_bytes()).hexdigest()}  v3-migration/ledger.json\n")
   self.assertTrue(any("forbidden" in e for e in MOD.verify(root,m)))
if __name__=="__main__": unittest.main()
