This commit is contained in:
@@ -8,7 +8,7 @@ import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from project_config.settings import env_files, held, load, OUTSIDE, ProjectConfig, SETTINGS, Unnamed
|
||||
from project_config.settings import env_files, Epic, held, load, OUTSIDE, ProjectConfig, SETTINGS, Unnamed
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
from project_config.main import title_templates
|
||||
@@ -28,6 +28,9 @@ goals-and-audience = "folder:goals.md"
|
||||
principles = "~/.claude/principles"
|
||||
"""
|
||||
|
||||
JIRA_PLAN = "jira:https://acme.atlassian.net/browse/ABC-12"
|
||||
JIRA_CLIENT = CLIENT.replace("folder:todo.md", JIRA_PLAN) + 'env-file = "~/acme.env"\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."""
|
||||
@@ -83,6 +86,36 @@ class LoadTest(ConfigCase):
|
||||
self.assertEqual(found.paths["principles"], self.home / ".claude" / "principles")
|
||||
self.assertEqual(tuple(found.paths), SETTINGS)
|
||||
|
||||
def test_a_plan_spelt_as_a_jira_epic_is_no_path(self) -> None:
|
||||
self.write("acme", JIRA_CLIENT)
|
||||
found = load(self.checkout, self.checkout, self.home)
|
||||
assert isinstance(found, ProjectConfig), found
|
||||
self.assertEqual(found.epic, Epic("https://acme.atlassian.net", "ABC-12"))
|
||||
self.assertEqual((found.plan_file, found.tracked("plan"), found.plan_label), (None, None, JIRA_PLAN))
|
||||
self.assertEqual(tuple(found.places), SETTINGS)
|
||||
self.assertEqual(found.places["plan"], JIRA_PLAN)
|
||||
self.assertEqual(tuple(found.paths), SETTINGS[1:])
|
||||
|
||||
def test_a_plan_kept_as_a_file_has_no_epic(self) -> None:
|
||||
folder = self.write("acme", CLIENT)
|
||||
found = load(self.checkout, self.checkout, self.home)
|
||||
assert isinstance(found, ProjectConfig), found
|
||||
self.assertEqual((found.epic, found.plan_file, found.plan_label, found.places["plan"]), (None, folder / "todo.md", str(folder / "todo.md"), str(folder / "todo.md")))
|
||||
|
||||
def test_a_jira_plan_needs_an_env_file(self) -> None:
|
||||
self.write("acme", JIRA_CLIENT.replace('env-file = "~/acme.env"\n', ""))
|
||||
self.assertIn("`plan` names a Jira epic, so `env-file` must name the file that holds its credentials", self.failure())
|
||||
|
||||
def test_a_plan_that_spells_no_path_and_no_epic_names_both_spellings(self) -> None:
|
||||
for spelled in ("jira:http://acme.atlassian.net/browse/ABC-12", "jira:https://acme.atlassian.net/browse/abc-12", "jira:https://acme.atlassian.net/browse/ABC-12/x", "jira:https://acme.atlassian.net@evil.example/browse/ABC-12", "jira:ABC-12", "https://acme.atlassian.net/browse/ABC-12"):
|
||||
with self.subTest(spelled):
|
||||
self.write(f"acme-{len(spelled)}-{hash(spelled) % 1000}", CLIENT.replace("folder:todo.md", spelled) + 'env-file = "~/acme.env"\n')
|
||||
reason = self.failure()
|
||||
self.assertIn(f"`plan` is {spelled!r}, not ", reason)
|
||||
self.assertIn("jira:https://<site>/browse/<epic's key>", reason)
|
||||
for config in (self.home / ".claude-projects").glob("*/config.toml"):
|
||||
config.unlink()
|
||||
|
||||
def test_a_worktree_finds_the_main_checkouts_config_and_reads_its_own_files(self) -> None:
|
||||
self.write("acme", CLIENT)
|
||||
worktree = self.home / "code" / "acme-billing-item-3"
|
||||
@@ -325,6 +358,11 @@ class EnvFilesTest(ConfigCase):
|
||||
|
||||
|
||||
class ToolTest(ConfigCase):
|
||||
def test_prints_a_jira_plan_as_the_config_spells_it(self) -> None:
|
||||
self.write("acme", JIRA_CLIENT)
|
||||
self.assertEqual(self.run_tool("plan").stdout, JIRA_PLAN + "\n")
|
||||
self.assertEqual(self.run_tool().stdout.splitlines()[0], f"plan: {JIRA_PLAN}")
|
||||
|
||||
def run_tool(self, *args: str, cwd: pathlib.Path | None = None) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.run([sys.executable, str(TOOL), *args], cwd=cwd or self.checkout, env={**isolated_env(), "HOME": str(self.home)}, capture_output=True, text=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user