"""인용한 코드가 그 리비전에 실재하는지 보는 검사기. `check_evidence.mjs --repo` 는 리비전이 **있는지**만 본다. 인용한 코드가 **그 리비전에서 왔는지**는 안 본다. 이 배치에서 실제로 그 결함이 났고 사람이 손으로 잡았다. """ import importlib.util import os import subprocess import unittest ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) TOOL = os.path.join(ROOT, "scripts", "check-code-anchors.py") _spec = importlib.util.spec_from_file_location("check_code_anchors", TOOL) ca = importlib.util.module_from_spec(_spec) _spec.loader.exec_module(ca) class UndecidableTest(unittest.TestCase): """판정할 수 있는 것만 판정한다. 못 보는 것은 세어서 낸다.""" def test_a_plain_repo_path_is_decidable(self): self.assertIsNone(ca._undecidable("scripts/audit-records.py")) def test_shapes_this_checker_cannot_decide(self): cases = { "FeedPersistenceIT.l2EagerToOneFires": "심볼", "`.../CaSkeletonApplication.java`": "축약 또는 백틱", "/etc/letsencrypt/renewal-hooks/": "저장소 밖 절대 경로", "tech-log-serving-contract.json": "폴더 없이 이름만", "renewal-hooks/deploy/": "폴더를 가리킨다", } for anchor, why in cases.items(): with self.subTest(why=why): self.assertIsNotNone(ca._undecidable(anchor), f"{anchor} 를 판정하려 든다") class SweepTest(unittest.TestCase): def _cli(self, *args): return subprocess.run(["python3", TOOL, *args], cwd=ROOT, capture_output=True, text=True) def test_every_project_in_this_repository_passes(self): """대조군. 지금 저장소의 앵커에 하나라도 걸리면 정책이 과하다. 축약 경로를 「없다」로 세면 있는 코드를 없다고 하는 것이고, 그것이 이 배치에서 채택된 편집 아홉 건을 막았던 실패와 같은 모양이다. """ p = self._cli("--samples", "1") self.assertEqual(0, p.returncode, p.stdout + p.stderr) def test_a_missing_project_is_not_reported_as_clean(self): self.assertEqual(2, self._cli("nosuchxyz").returncode) if __name__ == "__main__": unittest.main()