Resolve every cited CLAUDE.md heading in a test
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
CITATION = re.compile(r'CLAUDE\.md`?[ ,→]+"([^"]+)"')
|
||||
HEADING = re.compile(r"^#+ (.+?)(?: \(.*\))?$", re.MULTILINE)
|
||||
|
||||
|
||||
class Citations(unittest.TestCase):
|
||||
def test_every_cited_heading_is_in_claude_md(self):
|
||||
headings = set(HEADING.findall((ROOT / "CLAUDE.md").read_text()))
|
||||
tracked = subprocess.run(["git", "ls-files", "-z"], capture_output=True, check=True, cwd=ROOT, text=True).stdout.split("\0")
|
||||
cited = [(path, heading) for path in filter(None, tracked) for heading in CITATION.findall((ROOT / path).read_text())]
|
||||
self.assertTrue(cited)
|
||||
self.assertEqual([f"{path}: {heading}" for path, heading in cited if heading not in headings], [])
|
||||
Reference in New Issue
Block a user