Files
claude-config/bin/repo_checks/test_tools_named_bare.py
T

34 lines
1.9 KiB
Python

import re
import unittest
from git_cli.git_repo import git
from repo_checks import ROOT
# A tool spelled by its place in an install folder, as opposed to a source file under bin/, which a reader opens by its path. A session the loop starts has the release's tools on PATH, so prose names a tool bare, and works wherever the release is installed.
BY_ITS_FOLDER = re.compile(r"(?:~|\$HOME)/\.claude/bin/[\w.<>-]+(?![\w.<>/-])")
# The files that record what was once so, which nobody runs a command from.
HISTORY = ("CHANGELOG.md", "todo.md", "docs/")
# README.md → Install links loop-claude and compress-archives from a shell and a crontab, which lack the tools, and says how to run any other tool there.
INSTALL = {"~/.claude/bin/loop-claude", "$HOME/.claude/bin/compress-archives", "~/.claude/bin/<tool>"}
# settings.json names its hooks and its status line by their folder, and the test of the reviewer hook quotes it. Claude Code reads the file in every session, also one the human starts without the tools on PATH. A hook it cannot find doesn't refuse anything, so a bare name there would switch rule-hook off in that session.
SETTINGS = ("settings.json", "bin/review_rules/test_reviewer_context.py")
class ToolsNamedBare(unittest.TestCase):
def test_no_tracked_file_names_a_tool_by_its_install_folder(self) -> None:
tracked = git("ls-files", cwd=str(ROOT))
self.assertIsInstance(tracked, str, tracked)
found = []
for name in str(tracked).splitlines():
path = ROOT / name
if name.startswith(HISTORY) or name in SETTINGS or name == "bin/repo_checks/test_tools_named_bare.py" or not path.is_file():
continue
for number, line in enumerate(path.read_text(encoding="utf-8", errors="replace").splitlines(), 1):
found += [f"{name}:{number}: {spelled}" for spelled in BY_ITS_FOLDER.findall(line) if not (name == "README.md" and spelled in INSTALL)]
self.assertEqual(found, [], "name each tool bare, as in `todo-item`")
if __name__ == "__main__":
unittest.main()