Files
claude-config/bin/project_config/doubles.py
T

42 lines
1.9 KiB
Python

"""Test doubles for the tools that read a project's config: a client's config text, and a checkout that a config names."""
import pathlib
import subprocess
import tempfile
import unittest
from test_env import isolated_env
CLIENT = """checkout = "~/code/acme-billing"
plan = "folder:todo.md"
working-rules = "folder:AGENTS.md"
decisions = "folder:docs/decisions.md"
score-anchors = "folder:docs/score-anchors.md"
comprehension-history = "folder:docs/comprehension-history.md"
reading-cost = "folder:docs/reading-cost.md"
changelog = "checkout:CHANGELOG.md"
goals-and-audience = "folder:goals.md"
principles = "~/.claude/principles"
standards = "~/.claude/skills/larv-review/standards"
"""
JIRA_PLAN = "jira:https://acme.atlassian.net/browse/ABC-12"
JIRA_SCORING = 'jira-score-formula = "100 * V / (2**S + 8)"\njira-score-bar = 1\n'
def write_config(home: pathlib.Path, checkout: pathlib.Path, goals: str = "checkout:README.md") -> pathlib.Path:
"""A config under home that names checkout, every setting inside it but goals-and-audience; for the tests of each tool that reads the config."""
folder = home / ".claude-projects" / checkout.name
folder.mkdir(parents=True, exist_ok=True)
(folder / "config.toml").write_text(CLIENT.replace('"~/code/acme-billing"', f'"{checkout}"').replace('"folder:', '"checkout:').replace('"checkout:goals.md"', f'"{goals}"'), encoding="utf-8")
return folder
def configured(test: unittest.TestCase, checkout: pathlib.Path, goals: str = "checkout:README.md", home: pathlib.Path | None = None) -> pathlib.Path:
"""Makes checkout a git checkout that a config names, under home, else under a folder of its own for the rest of the test; the config's folder, two levels under that home."""
subprocess.run(["git", "init", "--quiet", str(checkout)], check=True, env=isolated_env())
if home is None:
made = tempfile.TemporaryDirectory()
test.addCleanup(made.cleanup)
home = pathlib.Path(made.name)
return write_config(home, checkout, goals)