sots-re/verify/config/test_source_check.py

31 lines
1.2 KiB
Python

"""The no-Git snapshot used by the gate must be inspected, not silently passed."""
import importlib.util
import os
from pathlib import Path
import tempfile
import unittest
ENGINE = Path(os.environ.get("SOTS_ENGINE", "/home/alex/sots-engine"))
spec = importlib.util.spec_from_file_location("clean_room", ENGINE / "tools/clean_room_check.py")
scanner = importlib.util.module_from_spec(spec)
spec.loader.exec_module(scanner)
class SnapshotTests(unittest.TestCase):
def test_plain_snapshot_and_forbidden_contents(self):
with tempfile.TemporaryDirectory() as td:
root = Path(td)
(root / "safe.cpp").write_text("int main() { return 0; }\n")
self.assertEqual(scanner.scan(root)[1], [])
(root / "copied.sav").write_text("handwritten forbidden fixture")
self.assertIn("forbidden artifact: copied.sav", scanner.scan(root)[1])
(root / "unsafe.cpp").write_text("void FUN_12345678();")
self.assertIn("decompiler-style identifier: unsafe.cpp", scanner.scan(root)[1])
def test_empty_snapshot_fails(self):
with tempfile.TemporaryDirectory() as td:
self.assertIn("no source files inspected", scanner.scan(Path(td))[1])
if __name__ == "__main__":
unittest.main()