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

32 lines
1.5 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>"}
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 == "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()