Keep configs in ~/.config/build-release/ and tool state in ~/.local/state/build-release/, under XDG_* where set
CI / tests (pull_request) Successful in 6m34s

This commit is contained in:
2026-12-03 18:56:28 +01:00
parent 20c83f861f
commit 1ca2c8efe0
142 changed files with 1095 additions and 933 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ import subprocess
import tempfile
import unittest
from loop_state.paths import CONFIG_FOLDER
from loop_state.paths import config_folder
from test_env import isolated_env
CLIENT = """checkout = "~/code/acme-billing"
@@ -26,7 +26,7 @@ JIRA_SCORING = 'jira-score-formula = "100 * V / (2**S + 8)"\njira-score-bar = 1\
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 / CONFIG_FOLDER / checkout.name
folder = config_folder({}, home) / 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
+12 -9
View File
@@ -3,10 +3,11 @@
usage: project-config [<setting>]
Run inside a checkout, or a worktree of one. It finds the config that names the checkout,
~/.claude-projects/<key>/config.toml, and prints each setting and its absolute path, as in
~/.config/build-release/<key>/config.toml, and prints each setting and its absolute path, as in
`plan: /home/me/code/acme/todo.md`. Given a setting, it prints only that setting's path.
Where XDG_CONFIG_HOME is set, the configs are in $XDG_CONFIG_HOME/build-release/ instead.
`~/.claude-projects/do-epic/` holds do-epic's machine-wide settings, not a project's. It needs no `checkout`,
`~/.config/build-release/do-epic/` holds do-epic's machine-wide settings, not a project's. It needs no `checkout`,
and project-config doesn't read anything from it, so no project may use `do-epic` as its key.
The config is TOML. `checkout` names the project's main checkout, and every setting in the example below is a path:
@@ -74,7 +75,7 @@ rule-hook ranks a plan kept as a file before tool calls, and a read from Conflue
`env-file` is an optional setting: the file of KEY=value credentials the project's tools read,
a path that starts with / or ~/ and lies outside the checkout and the config's folder, such as
"~/.claude-projects/acme-billing.env". Where it is left out, the project has no credentials file, and
"~/.config/build-release/acme-billing.env". Where it is left out, the project has no credentials file, and
a tool that needs one fails naming the setting. It is printed with the others only where it is set.
`touch-predictions` is an optional setting, a path spelt as the others are, never a page: the record
@@ -179,6 +180,8 @@ one of those two without a `plan` in Jira, sets the formula to one that doesn't
but a number, sets `readability-floor` to anything but a number
from 1 to 10, sets `parallel-chunks` to anything but a whole number of 1 or more, or sets `jira-finding-type` to anything but a name or without a `plan` in Jira, and where `bench-tasks`, `coding-conventions`, `env-file`, `epic-branch`, `jira-finish-transition`, `jira-finish-status`, `notifier`, `review-request-comment` or `touch-predictions` is asked for and not set. No path setting has a default.
"""
from collections.abc import Mapping
import os
import pathlib
import sys
@@ -195,7 +198,7 @@ def main(argv: list[str]) -> int:
if len(argv) > 1 or (argv and argv[0] not in (*SETTINGS, *OPTIONAL)):
print(f"usage: project-config [<setting>], where <setting> is one of {', '.join((*SETTINGS, *OPTIONAL))}", file=sys.stderr)
return 1
config = located(None, pathlib.Path.home())
config = located(None, pathlib.Path.home(), os.environ)
if isinstance(config, Failure):
print(config.reason, file=sys.stderr)
return 1
@@ -216,7 +219,7 @@ def main(argv: list[str]) -> int:
return 0
def located(directory: str | None, home: pathlib.Path, run: Git = git) -> ProjectConfig | Failure:
def located(directory: str | None, home: pathlib.Path, env: Mapping[str, str], run: Git = git) -> ProjectConfig | Failure:
"""The config under home of the checkout that holds directory, else the current directory."""
found = run("rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", cwd=directory)
if isinstance(found, Failure):
@@ -224,12 +227,12 @@ def located(directory: str | None, home: pathlib.Path, run: Git = git) -> Projec
if len(lines := found.splitlines()) != 2:
return Failure(f"git rev-parse printed {found!r}, not a checkout's top folder and git directory on two lines")
# The common dir is the main checkout's .git, whichever worktree runs this.
return load(pathlib.Path(lines[0]), pathlib.Path(lines[1]).parent, home)
return load(pathlib.Path(lines[0]), pathlib.Path(lines[1]).parent, home, env)
def title_templates(directory: str | None, home: pathlib.Path, run: Git = git) -> templates.Titles | Failure:
def title_templates(directory: str | None, home: pathlib.Path, env: Mapping[str, str], run: Git = git) -> templates.Titles | Failure:
"""The title templates of the project whose checkout holds directory, else the current directory. Bare summaries where no config names a checkout there, as in a third party's clone, so every title is read as it stands. A Failure where a config is faulty or cannot be read: read bare, a templated project's round titles would count for nothing."""
config = located(directory, home, run)
config = located(directory, home, env, run)
if isinstance(config, Unnamed):
return templates.BARE
return config if isinstance(config, Failure) else config.titles
@@ -237,5 +240,5 @@ def title_templates(directory: str | None, home: pathlib.Path, run: Git = git) -
def project() -> ProjectConfig | Failure:
"""The config of the project whose checkout holds the current directory, under the user's home."""
return located(None, pathlib.Path.home())
return located(None, pathlib.Path.home(), os.environ)
+18 -18
View File
@@ -1,22 +1,22 @@
"""A project's settings, read from the one config that names its checkout: `~/.claude-projects/<key>/config.toml`.
"""A project's settings, read from the one config that names its checkout: `<key>/config.toml` in the config folder, `~/.config/build-release/` unless `XDG_CONFIG_HOME` is set.
No path setting has a default, so that a client's project never runs on another project's files: a missing config or setting is a Failure that names it."""
import dataclasses
import decimal
from collections.abc import Mapping
import math
import pathlib
import re
import tomllib
import typing
from loop_state.paths import CONFIG_FOLDER
from loop_state.paths import config_folder
from failure import Failure
from plan.formula import parse_formula
from plan.todo_table import SHAPE
from project_config import templates
from plan.ranking import variables
PROJECTS = CONFIG_FOLDER
CONFIG = "config.toml"
# The key of do-epic's machine-wide settings: the folder's config.toml has no `checkout`, so no project may use the key.
DO_EPIC = "do-epic"
@@ -133,7 +133,7 @@ class Unnamed(Failure):
@dataclasses.dataclass(frozen=True)
class ProjectConfig:
"""folder is `~/.claude-projects/<key>`, top is the worktree that asked, and paths holds each of SETTINGS as an absolute path, except three kinds that pages or epics hold instead: `plan` and `goals-and-audience` where they are kept in Jira, and a record kept on a Confluence page."""
"""folder is `<key>` in the config folder, top is the worktree that asked, and paths holds each of SETTINGS as an absolute path, except three kinds that pages or epics hold instead: `plan` and `goals-and-audience` where they are kept in Jira, and a record kept on a Confluence page."""
key: str
folder: pathlib.Path
top: pathlib.Path
@@ -203,13 +203,13 @@ class ProjectConfig:
return path.relative_to(self.top).as_posix() if path.is_relative_to(self.top) else None
def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure:
def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path, env: Mapping[str, str]) -> ProjectConfig | Failure:
"""The config that names main, the project's main checkout.
top is the worktree that asks, and main itself outside a worktree. A `checkout:` path lands in top.
A config that cannot be read fails every project, since it may be the one that names main."""
named: list[tuple[pathlib.Path, dict[str, object]]] = []
for file in configs(home):
for file in configs(home, env):
config = read(file, home)
if isinstance(config, Failure):
return config
@@ -217,7 +217,7 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
if config[0].resolve() == main.resolve():
named.append((file, config[1]))
if not named:
return Unnamed(f"no config names the checkout {main}: write ~/{PROJECTS}/<key>/{CONFIG}, as `project-config --help` shows")
return Unnamed(f"no config names the checkout {main}: write {config_folder(env, home)}/<key>/{CONFIG}, as `project-config --help` shows")
if len(named) > 1:
return Failure(f"{' and '.join(str(file) for file, _ in named)} each name the checkout {main}; only one config may")
file, values = named[0]
@@ -413,20 +413,20 @@ def lies_in(path: pathlib.Path, *places: pathlib.Path) -> bool:
return any(path.resolve().is_relative_to(place.resolve()) for place in places)
def held(folder: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure | None:
def held(folder: pathlib.Path, home: pathlib.Path, env: Mapping[str, str]) -> ProjectConfig | Failure | None:
"""The config in folder, read as its project's main checkout reads it; None where folder is not a config's folder under home."""
# Matched on resolved paths, as git names a folder, so a config's folder reached through a symlink is still found.
file = next((file for file in configs(home) if file.parent.resolve() == folder.resolve()), None)
file = next((file for file in configs(home, env) if file.parent.resolve() == folder.resolve()), None)
if file is None:
return None
config = read(file, home)
return config if isinstance(config, Failure) else load(config[0], config[0], home)
return config if isinstance(config, Failure) else load(config[0], config[0], home, env)
def by_name(name: str, home: pathlib.Path) -> ProjectConfig | Failure | None:
def by_name(name: str, home: pathlib.Path, env: Mapping[str, str]) -> ProjectConfig | Failure | None:
"""The config of the project whose main checkout is a folder called name, though that folder may not exist yet, loaded as `held` does; None where no config names one. A config that cannot be read fails every name, since it may be the one asked for."""
files = []
for file in configs(home):
for file in configs(home, env):
config = read(file, home)
if isinstance(config, Failure):
return config
@@ -434,17 +434,17 @@ def by_name(name: str, home: pathlib.Path) -> ProjectConfig | Failure | None:
files.append(file)
if len(files) > 1:
return Failure(f"{' and '.join(str(file) for file in files)} each name a checkout called {name}; only one config may")
return held(files[0].parent, home) if files else None
return held(files[0].parent, home, env) if files else None
def configs(home: pathlib.Path) -> list[pathlib.Path]:
"""Every project's config file under home, in key order. do-epic's machine-wide config is not a project's."""
return sorted(file for file in (home / PROJECTS).glob(f"*/{CONFIG}") if file.parent.name != DO_EPIC)
def configs(home: pathlib.Path, env: Mapping[str, str]) -> list[pathlib.Path]:
"""Every project's config file in the config folder, in key order. do-epic's machine-wide config is not a project's."""
return sorted(file for file in config_folder(env, home).glob(f"*/{CONFIG}") if file.parent.name != DO_EPIC)
def env_files(home: pathlib.Path) -> list[pathlib.Path]:
def env_files(home: pathlib.Path, env: Mapping[str, str]) -> list[pathlib.Path]:
"""Every config's env-file, do-epic's included. Each is read without the checks load makes, so a config that fails them still keeps its credentials guarded. A config that can't be read doesn't name one."""
values = [parsed(file) for file in (*configs(home), home / PROJECTS / DO_EPIC / CONFIG)]
values = [parsed(file) for file in (*configs(home, env), config_folder(env, home) / DO_EPIC / CONFIG)]
return [path for found in values if not isinstance(found, Failure) and (path := anywhere(found.get(ENV_FILE), home))]
+100 -100
View File
@@ -29,7 +29,7 @@ class ConfigCase(unittest.TestCase):
self.checkout.mkdir(parents=True)
def write(self, key: str, text: str) -> pathlib.Path:
folder = self.home / ".claude-projects" / key
folder = self.home / ".config/build-release" / key
folder.mkdir(parents=True)
(folder / "config.toml").write_text(text, encoding="utf-8")
return folder
@@ -37,14 +37,14 @@ class ConfigCase(unittest.TestCase):
class LoadTest(ConfigCase):
def failure(self, top: pathlib.Path | None = None) -> str:
found = load(top or self.checkout, self.checkout, self.home)
found = load(top or self.checkout, self.checkout, self.home, {})
assert isinstance(found, Failure), found
return found.reason
def test_resolves_each_setting_by_its_prefix(self) -> None:
folder = self.write("acme", CLIENT)
self.write("other", CLIENT.replace("acme-billing", "other"))
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual((found.key, found.folder), ("acme", folder))
self.assertEqual(found.paths["plan"], folder / "todo.md")
@@ -57,13 +57,13 @@ class LoadTest(ConfigCase):
def test_the_do_epic_folder_is_no_projects_config_so_it_needs_no_checkout(self) -> None:
self.write("do-epic", 'jira-url = "https://acme.atlassian.net"\n')
self.write("acme", CLIENT)
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.key, "acme")
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)
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))
@@ -73,7 +73,7 @@ class LoadTest(ConfigCase):
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)
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")))
@@ -88,12 +88,12 @@ class LoadTest(ConfigCase):
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"):
for config in (self.home / ".config/build-release").glob("*/config.toml"):
config.unlink()
def test_goals_and_audience_spelt_as_a_jira_epic_is_no_path(self) -> None:
self.write("acme", JIRA_CLIENT.replace("folder:goals.md", "jira:https://acme.atlassian.net/browse/ABC-7"))
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.goals_epic, Epic("https://acme.atlassian.net", "ABC-7"))
self.assertEqual(found.places["goals-and-audience"], "jira:https://acme.atlassian.net/browse/ABC-7")
@@ -102,7 +102,7 @@ class LoadTest(ConfigCase):
def test_goals_and_the_plan_may_name_the_same_epic(self) -> None:
self.write("acme", JIRA_CLIENT.replace("folder:goals.md", JIRA_PLAN))
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.goals_epic, found.epic)
@@ -112,7 +112,7 @@ class LoadTest(ConfigCase):
def test_goals_kept_as_a_file_have_no_epic(self) -> None:
folder = self.write("acme", CLIENT)
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual((found.goals_epic, found.places["goals-and-audience"]), (None, str(folder / "goals.md")))
@@ -129,7 +129,7 @@ class LoadTest(ConfigCase):
def test_a_record_spelt_as_a_confluence_page_is_no_path_and_prints_as_written(self) -> None:
self.write("acme", JIRA_CLIENT.replace("folder:docs/decisions.md", DECISIONS_PAGE))
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.pages, {"decisions": Page("https://acme.atlassian.net", "2293761", DECISIONS_PAGE)})
self.assertEqual(found.places["decisions"], DECISIONS_PAGE)
@@ -140,11 +140,11 @@ class LoadTest(ConfigCase):
def test_a_confluence_page_may_leave_out_its_title(self) -> None:
for spelled in ("confluence:https://acme.atlassian.net/wiki/spaces/ENG/pages/2293761", "confluence:https://acme.atlassian.net/wiki/spaces/~5b1e/pages/2293761/R%C3%A5d+och+beslut"):
with self.subTest(spelled):
for config in (self.home / ".claude-projects").glob("*/config.toml"):
for config in (self.home / ".config/build-release").glob("*/config.toml"):
config.unlink()
config.parent.rmdir()
self.write("acme", CLIENT.replace("checkout:CHANGELOG.md", spelled) + 'env-file = "~/acme.env"\n')
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.pages["changelog"].page_id, "2293761")
@@ -165,7 +165,7 @@ class LoadTest(ConfigCase):
reason = self.failure()
self.assertIn(f"`decisions` is {spelled!r}, not ", reason)
self.assertIn("confluence:https://<site>/wiki/spaces/<space>/pages/<page ID>", reason)
for config in (self.home / ".claude-projects").glob("*/config.toml"):
for config in (self.home / ".config/build-release").glob("*/config.toml"):
config.unlink()
def test_only_a_record_may_name_a_confluence_page(self) -> None:
@@ -177,14 +177,14 @@ class LoadTest(ConfigCase):
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"
found = load(worktree, self.checkout, self.home)
found = load(worktree, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.paths["changelog"], worktree / "CHANGELOG.md")
def test_names_a_file_in_the_checkout_as_git_does_and_none_outside_it(self) -> None:
self.write("acme", CLIENT.replace("folder:docs/decisions.md", "checkout:project/decisions.md"))
worktree = self.home / "code" / "acme-billing-item-3"
found = load(worktree, self.checkout, self.home)
found = load(worktree, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.tracked("changelog"), "CHANGELOG.md")
self.assertEqual(found.tracked("decisions"), "project/decisions.md")
@@ -192,7 +192,7 @@ class LoadTest(ConfigCase):
def test_an_absolute_checkout_and_path_are_taken_as_written(self) -> None:
self.write("acme", CLIENT.replace("~/code/acme-billing", str(self.checkout)).replace("~/.claude/principles", "/srv/principles"))
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.paths["principles"], pathlib.Path("/srv/principles"))
@@ -201,7 +201,7 @@ class LoadTest(ConfigCase):
(self.home / "work").symlink_to(self.home / "code")
for case, main in {"a symlink": self.home / "work" / "acme-billing", "dots": self.home / "code" / "other" / ".." / "acme-billing"}.items():
with self.subTest(case=case):
self.assertIsInstance(load(main, main, self.home), ProjectConfig)
self.assertIsInstance(load(main, main, self.home, {}), ProjectConfig)
def test_no_config_fails_naming_the_checkout_and_the_file_to_write(self) -> None:
for write_other in (False, True):
@@ -210,10 +210,10 @@ class LoadTest(ConfigCase):
self.write("other", CLIENT.replace("acme-billing", "other"))
reason = self.failure()
self.assertIn(str(self.checkout), reason)
self.assertIn("~/.claude-projects/<key>/config.toml", reason)
self.assertIn(f"{self.home}/.config/build-release/<key>/config.toml", reason)
def test_a_folder_that_is_no_checkout_fails_as_unnamed_with_gits_reason(self) -> None:
outside = located(str(self.checkout), self.home)
outside = located(str(self.checkout), self.home, {})
self.assertIsInstance(outside, Unnamed)
self.assertIn("not a git repository", outside.reason)
@@ -249,77 +249,77 @@ class LoadTest(ConfigCase):
def test_env_file_is_the_one_optional_setting_and_names_a_file_outside_the_checkout_and_the_configs_folder(self) -> None:
self.write("acme", CLIENT)
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertIsNone(found.env_file, "a project that sets none has asked for no credentials, and never falls back to another project's")
for case, spelled in {"~/": '"~/.claude-projects/acme.env"', "absolute": f'"{self.home}/.claude-projects/acme.env"'}.items():
for case, spelled in {"~/": '"~/.config/build-release/acme.env"', "absolute": f'"{self.home}/.config/build-release/acme.env"'}.items():
with self.subTest(case=case):
self.write(f"acme-{case[0]}", CLIENT.replace("acme-billing", f"acme-{case[0]}") + f"env-file = {spelled}\n")
named = load(self.home / "code" / f"acme-{case[0]}", self.home / "code" / f"acme-{case[0]}", self.home)
named = load(self.home / "code" / f"acme-{case[0]}", self.home / "code" / f"acme-{case[0]}", self.home, {})
assert isinstance(named, ProjectConfig), named
self.assertEqual(named.env_file, self.home / ".claude-projects" / "acme.env")
self.assertEqual(named.env_file, self.home / ".config/build-release" / "acme.env")
def test_the_notifier_is_optional_and_names_mattermost_or_slack_beside_an_env_file(self) -> None:
self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertIsNone(left_out.notifier, "a project that names none has asked for no notices")
for index, name in enumerate(NOTIFIERS):
with self.subTest(name):
self.write(f"acme-{index}", CLIENT.replace("acme-billing", f"acme-{index}") + f'env-file = "~/acme.env"\nnotifier = "{name}"\n')
named = load(self.home / "code" / f"acme-{index}", self.home / "code" / f"acme-{index}", self.home)
named = load(self.home / "code" / f"acme-{index}", self.home / "code" / f"acme-{index}", self.home, {})
assert isinstance(named, ProjectConfig), named
self.assertEqual(named.notifier, name)
def test_the_epic_branch_and_its_review_request_comment_are_optional(self) -> None:
self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertEqual((left_out.epic_branch, left_out.review_request_comment), (None, None))
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "epic/{epic}"\nreview-request-comment = "@coderabbitai review"\n')
named = load(self.checkout, self.checkout, self.home)
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "epic/{epic}"\nreview-request-comment = "@coderabbitai review"\n')
named = load(self.checkout, self.checkout, self.home, {})
assert isinstance(named, ProjectConfig), named
self.assertEqual((named.epic_branch, named.review_request_comment), ("epic/{epic}", "@coderabbitai review"))
def test_an_epic_branch_without_the_epic_or_a_comment_without_an_epic_branch_fails_naming_it(self) -> None:
self.write("acme", CLIENT + 'epic-branch = "develop"\n')
self.assertIn("`epic-branch` is 'develop', not text with exactly one {epic}", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'review-request-comment = "@coderabbitai review"\n')
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(CLIENT + 'review-request-comment = "@coderabbitai review"\n')
self.assertIn("`review-request-comment` is set, so `epic-branch` must be set", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "{epic}"\nreview-request-comment = " "\n')
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "{epic}"\nreview-request-comment = " "\n')
self.assertIn("`review-request-comment` is ' ', not one line of text", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "{epic}"\nreview-request-comment = "--help"\n')
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "{epic}"\nreview-request-comment = "--help"\n')
self.assertIn("`review-request-comment` is '--help', not one line of text that doesn't start with `-`", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "{epic}"\nreview-request-comment = "@coderabbitai\\nreview"\n')
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "{epic}"\nreview-request-comment = "@coderabbitai\\nreview"\n')
self.assertIn("`review-request-comment` is '@coderabbitai\\nreview', not one line of text", self.failure())
def test_a_jira_plan_may_name_the_transition_and_status_that_finish_an_item(self) -> None:
self.write("acme", JIRA_CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertIsNone(left_out.jira_finish)
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(JIRA_CLIENT + 'jira-finish-transition = "Mark as done"\njira-finish-status = "Done"\n')
named = load(self.checkout, self.checkout, self.home)
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(JIRA_CLIENT + 'jira-finish-transition = "Mark as done"\njira-finish-status = "Done"\n')
named = load(self.checkout, self.checkout, self.home, {})
assert isinstance(named, ProjectConfig), named
self.assertEqual(named.jira_finish, Finish("Mark as done", "Done"))
def test_a_finish_setting_alone_misspelt_or_beside_a_plan_in_a_file_fails_naming_it(self) -> None:
self.write("acme", JIRA_CLIENT + 'jira-finish-status = "Done"\n')
self.assertIn("`jira-finish-status` is set, so `jira-finish-transition` must be too", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(JIRA_CLIENT + 'jira-finish-transition = "Mark as done"\n')
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(JIRA_CLIENT + 'jira-finish-transition = "Mark as done"\n')
self.assertIn("`jira-finish-transition` is set, so `jira-finish-status` must be too", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(JIRA_CLIENT + 'jira-finish-transition = 31\njira-finish-status = " "\n')
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(JIRA_CLIENT + 'jira-finish-transition = 31\njira-finish-status = " "\n')
self.assertIn("`jira-finish-transition` is 31, not the name Jira shows, such as \"Mark as done\"; `jira-finish-status` is ' ', not the name Jira shows, such as \"Done\"", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'jira-finish-transition = "Mark as done"\njira-finish-status = "Done"\n')
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(CLIENT + 'jira-finish-transition = "Mark as done"\njira-finish-status = "Done"\n')
self.assertIn("`jira-finish-transition` is set, so `plan` must name a Jira epic; `jira-finish-status` is set, so `plan` must name a Jira epic", self.failure())
def test_a_jira_plan_may_name_the_issue_type_it_files_items_as_which_is_task_where_left_out(self) -> None:
folder = self.write("acme", JIRA_CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertEqual(left_out.jira_finding_type, "Task")
(folder / "config.toml").write_text(JIRA_CLIENT + 'jira-finding-type = "Feature"\n')
named = load(self.checkout, self.checkout, self.home)
named = load(self.checkout, self.checkout, self.home, {})
assert isinstance(named, ProjectConfig), named
self.assertEqual(named.jira_finding_type, "Feature")
@@ -333,13 +333,13 @@ class LoadTest(ConfigCase):
def test_a_jira_plan_holds_the_formula_and_bar_it_scores_by(self) -> None:
self.write("acme", JIRA_CLIENT.replace("jira-score-bar = 1", "jira-score-bar = 0.5"))
named = load(self.checkout, self.checkout, self.home)
named = load(self.checkout, self.checkout, self.home, {})
assert isinstance(named, ProjectConfig), named
self.assertEqual(named.jira_scoring, JiraScoring("100 * V / (2**S + 8)", 0.5))
def test_a_plan_in_a_file_holds_no_formula_or_bar_of_the_configs(self) -> None:
self.write("acme", CLIENT)
named = load(self.checkout, self.checkout, self.home)
named = load(self.checkout, self.checkout, self.home, {})
assert isinstance(named, ProjectConfig), named
self.assertIsNone(named.jira_scoring)
@@ -368,7 +368,7 @@ class LoadTest(ConfigCase):
def test_a_notifier_that_is_unknown_or_has_no_env_file_fails_naming_it(self) -> None:
self.write("acme", CLIENT + 'env-file = "~/acme.env"\nnotifier = "teams"\n')
self.assertIn("`notifier` is 'teams', not mattermost or slack", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'notifier = "slack"\n')
(self.home / ".config/build-release" / "acme" / "config.toml").write_text(CLIENT + 'notifier = "slack"\n')
self.assertIn("`notifier` names a notifier, so `env-file` must name the file that holds its credentials", self.failure())
def test_an_env_file_in_the_checkout_or_the_configs_folder_or_spelt_loosely_fails_naming_it(self) -> None:
@@ -377,7 +377,7 @@ class LoadTest(ConfigCase):
"a folder: path": lambda home: '"folder:acme.env"',
"no prefix": lambda home: '".env"',
"a path in the checkout": lambda home: f'"{home}/code/acme-billing/.env"',
"a path in the config's folder": lambda home: f'"{home}/.claude-projects/acme/acme.env"',
"a path in the config's folder": lambda home: f'"{home}/.config/build-release/acme/acme.env"',
"not text": lambda home: "3",
}
for case, spelled in cases.items():
@@ -395,17 +395,17 @@ class LoadTest(ConfigCase):
self.home = pathlib.Path(made).resolve()
self.checkout = self.home / "code" / "acme-billing"
self.write("acme", CLIENT + f'env-file = "{self.home}/code/{folder}/.env"\n')
found = load(self.home / "code" / "acme-billing-item-3", self.checkout, self.home)
found = load(self.home / "code" / "acme-billing-item-3", self.checkout, self.home, {})
assert isinstance(found, Failure), found
self.assertIn("`env-file`", found.reason)
def test_bench_tasks_is_an_optional_path_listed_last_only_where_set(self) -> None:
folder = self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig)
self.assertNotIn("bench-tasks", left_out.places)
(folder / "config.toml").write_text(CLIENT + 'bench-tasks = "checkout:bench-tasks"\ntouch-predictions = "folder:docs/touch-predictions.md"\n', encoding="utf-8")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig)
self.assertEqual(list(found.places)[-3:], ["standards", "touch-predictions", "bench-tasks"])
self.assertEqual(found.paths["bench-tasks"], self.checkout / "bench-tasks")
@@ -414,11 +414,11 @@ class LoadTest(ConfigCase):
def test_touch_predictions_is_an_optional_path_listed_after_the_others_only_where_set(self) -> None:
folder = self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig)
self.assertNotIn("touch-predictions", left_out.places)
(folder / "config.toml").write_text(CLIENT + 'touch-predictions = "folder:docs/touch-predictions.md"\n', encoding="utf-8")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig)
self.assertEqual(list(found.places)[-2:], ["standards", "touch-predictions"])
self.assertEqual(found.paths["touch-predictions"], folder / "docs/touch-predictions.md")
@@ -428,11 +428,11 @@ class LoadTest(ConfigCase):
def test_coding_conventions_is_an_optional_list_of_paths_spelt_as_the_others_are(self) -> None:
folder = self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig)
self.assertEqual(left_out.coding_conventions, ())
(folder / "config.toml").write_text(CLIENT + 'coding-conventions = ["checkout:CONVENTIONS.md", "folder:style.md", "~/shared/php.md"]\n', encoding="utf-8")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig)
self.assertEqual(found.coding_conventions, (self.checkout / "CONVENTIONS.md", folder / "style.md", self.home / "shared/php.md"))
@@ -445,13 +445,13 @@ class LoadTest(ConfigCase):
def test_merge_is_chunk_where_left_out_and_takes_human(self) -> None:
folder = self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertEqual(left_out.merge, "chunk")
for spelled in ("chunk", "human"):
with self.subTest(spelled):
(folder / "config.toml").write_text(CLIENT + f'merge = "{spelled}"\n')
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.merge, spelled)
@@ -460,19 +460,19 @@ class LoadTest(ConfigCase):
for spelled, named in (('"person"', "'person'"), ("true", "True")):
with self.subTest(spelled):
(folder / "config.toml").write_text(CLIENT + f"merge = {spelled}\n")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, Failure), found
self.assertIn(f'`merge` is {named}, not "chunk" or "human"', found.reason)
def test_wait_for_approval_is_an_optional_boolean_that_is_false_where_left_out(self) -> None:
folder = self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertFalse(left_out.wait_for_approval)
for spelled, expected in (("true", True), ("false", False)):
with self.subTest(spelled):
(folder / "config.toml").write_text(CLIENT + f"wait-for-approval = {spelled}\n")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.wait_for_approval, expected)
@@ -481,35 +481,35 @@ class LoadTest(ConfigCase):
for spelled in ('"yes"', "1", '"true"'):
with self.subTest(spelled):
(folder / "config.toml").write_text(CLIENT + f"wait-for-approval = {spelled}\n")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, Failure), found
self.assertIn(f"`wait-for-approval` is {eval(spelled)!r}, not true or false", found.reason)
def test_tooling_on_host_is_an_optional_boolean_that_is_false_where_left_out(self) -> None:
folder = self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertFalse(left_out.tooling_on_host)
for spelled, expected in (("true", True), ("false", False)):
with self.subTest(spelled):
(folder / "config.toml").write_text(CLIENT + f"tooling-on-host = {spelled}\n")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.tooling_on_host, expected)
(folder / "config.toml").write_text(CLIENT + 'tooling-on-host = "yes"\n')
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, Failure), found
self.assertIn("`tooling-on-host` is 'yes', not true or false", found.reason)
def test_the_readability_floor_is_an_optional_number_from_1_to_10_that_is_7_where_left_out(self) -> None:
folder = self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertEqual(left_out.readability_floor, decimal.Decimal("7.0"))
for spelled, expected in (("5", "5"), ("6.5", "6.5"), ("1", "1"), ("10.0", "10.0")):
with self.subTest(spelled):
(folder / "config.toml").write_text(CLIENT + f"readability-floor = {spelled}\n")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.readability_floor, decimal.Decimal(expected))
@@ -518,20 +518,20 @@ class LoadTest(ConfigCase):
for spelled in ('"7.0"', "0.5", "11", "true", "nan", "inf", "1" + "0" * 400):
with self.subTest(spelled):
(folder / "config.toml").write_text(CLIENT + f"readability-floor = {spelled}\n")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, Failure), found
self.assertIn("`readability-floor` is ", found.reason)
self.assertIn(", not a number from 1 to 10; write a bare number, such as `readability-floor = 7.0`", found.reason)
def test_parallel_chunks_is_an_optional_whole_number_from_1_that_is_1_where_left_out(self) -> None:
folder = self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertEqual(left_out.parallel_chunks, 1)
for spelled in (1, 3, 12):
with self.subTest(spelled):
(folder / "config.toml").write_text(CLIENT + f"parallel-chunks = {spelled}\n")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual(found.parallel_chunks, spelled)
@@ -540,18 +540,18 @@ class LoadTest(ConfigCase):
for spelled in ('"2"', "0", "-1", "2.0", "true", "inf"):
with self.subTest(spelled):
(folder / "config.toml").write_text(CLIENT + f"parallel-chunks = {spelled}\n")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, Failure), found
self.assertIn("`parallel-chunks` is ", found.reason)
self.assertIn(", not a whole number of 1 or more, such as `parallel-chunks = 2`", found.reason)
def test_the_language_and_the_templates_are_optional_and_default_to_english_bare_summaries_and_item_branches(self) -> None:
folder = self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
left_out = load(self.checkout, self.checkout, self.home, {})
assert isinstance(left_out, ProjectConfig), left_out
self.assertEqual((left_out.language, left_out.commit_title, left_out.pull_request_title, left_out.branch), ("English", "{summary}", "{summary}", "item-{id}"))
(folder / "config.toml").write_text(CLIENT + 'language = "Swedish"\ncommit-title = "PAY-{id} - {summary}"\npull-request-title = "fix: {summary} (#{id})"\nbranch = "feature/PAY-{id}"\n')
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual((found.language, found.commit_title, found.pull_request_title, found.branch), ("Swedish", "PAY-{id} - {summary}", "fix: {summary} (#{id})", "feature/PAY-{id}"))
@@ -561,22 +561,22 @@ class LoadTest(ConfigCase):
for line, named in cases.items():
with self.subTest(line):
(folder / "config.toml").write_text(CLIENT + line + "\n")
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, Failure), found
self.assertIn(named, found.reason)
def test_a_language_of_more_than_words_fails_saying_what_is_accepted(self) -> None:
folder = self.write("acme", CLIENT + 'language = "Chinese (Simplified)"\n')
found = load(self.checkout, self.checkout, self.home)
found = load(self.checkout, self.checkout, self.home, {})
assert isinstance(found, Failure), found
self.assertIn("`language` is 'Chinese (Simplified)', not a language's English name in words of letters, such as \"Swedish\" or \"Brazilian Portuguese\"", found.reason)
(folder / "config.toml").write_text(CLIENT + 'language = "Brazilian Portuguese"\n')
self.assertIsInstance(load(self.checkout, self.checkout, self.home), ProjectConfig)
self.assertIsInstance(load(self.checkout, self.checkout, self.home, {}), ProjectConfig)
def test_a_checkout_no_config_names_fails_as_unnamed_and_a_faulty_config_does_not(self) -> None:
self.assertIsInstance(load(self.checkout, self.checkout, self.home), Unnamed)
self.assertIsInstance(load(self.checkout, self.checkout, self.home, {}), Unnamed)
self.write("acme", CLIENT + "language = 3\n")
self.assertNotIsInstance(load(self.checkout, self.checkout, self.home), Unnamed)
self.assertNotIsInstance(load(self.checkout, self.checkout, self.home, {}), Unnamed)
def test_the_failure_for_a_misplaced_env_file_and_a_missing_setting_names_both_and_lists_every_setting(self) -> None:
folder = self.write("acme", "".join(line + "\n" for line in CLIENT.splitlines() if not line.startswith("plan")) + 'env-file = "checkout:.env"\n')
@@ -600,27 +600,27 @@ class LoadTest(ConfigCase):
def test_a_folder_with_no_config_is_skipped(self) -> None:
self.write("acme", CLIENT)
(self.home / ".claude-projects" / "notes").mkdir()
self.assertIsInstance(load(self.checkout, self.checkout, self.home), ProjectConfig)
(self.home / ".config/build-release" / "notes").mkdir()
self.assertIsInstance(load(self.checkout, self.checkout, self.home, {}), ProjectConfig)
class TitleTemplatesTest(ConfigCase):
def test_names_the_configs_templates_and_bare_summaries_where_no_config_names_the_checkout_or_git_finds_none(self) -> None:
subprocess.run(["git", "init", "--quiet", str(self.checkout)], check=True, env=isolated_env())
self.assertEqual(title_templates(str(self.checkout), self.home), Titles("{summary}", "{summary}"))
self.assertEqual(title_templates(str(self.checkout), self.home, {}), Titles("{summary}", "{summary}"))
self.write("acme", CLIENT + 'commit-title = "PAY-{id} - {summary}"\npull-request-title = "fix: {summary} (#{id})"\n')
self.assertEqual(title_templates(str(self.checkout), self.home), Titles("PAY-{id} - {summary}", "fix: {summary} (#{id})"))
self.assertEqual(title_templates(str(self.home), self.home), Titles("{summary}", "{summary}"))
self.assertEqual(title_templates(str(self.checkout), self.home, {}), Titles("PAY-{id} - {summary}", "fix: {summary} (#{id})"))
self.assertEqual(title_templates(str(self.home), self.home, {}), Titles("{summary}", "{summary}"))
def test_fails_where_the_checkouts_config_or_any_other_cannot_be_read(self) -> None:
subprocess.run(["git", "init", "--quiet", str(self.checkout)], check=True, env=isolated_env())
folder = self.write("acme", CLIENT + 'commit-title = "PAY-{id}"\n')
faulty = title_templates(str(self.checkout), self.home)
faulty = title_templates(str(self.checkout), self.home, {})
assert isinstance(faulty, Failure), faulty
self.assertIn("`commit-title` is 'PAY-{id}'", faulty.reason)
(folder / "config.toml").write_text(CLIENT)
other = self.write("other", "checkout = [")
unread = title_templates(str(self.checkout), self.home)
unread = title_templates(str(self.checkout), self.home, {})
assert isinstance(unread, Failure), unread
self.assertIn(f"cannot read {other / 'config.toml'}", unread.reason)
@@ -628,54 +628,54 @@ class TitleTemplatesTest(ConfigCase):
class HeldTest(ConfigCase):
def test_a_configs_folder_holds_its_config_as_the_main_checkout_reads_it(self) -> None:
folder = self.write("acme", CLIENT)
found = held(folder, self.home)
found = held(folder, self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual((found.folder, found.top, found.paths["plan"]), (folder, self.checkout, folder / "todo.md"), "the config's ~/ checkout read under home")
def test_a_folder_holds_no_config_unless_it_is_under_the_projects_folder_and_has_one(self) -> None:
self.assertIsNone(held(self.home / ".claude-projects" / "empty", self.home), "no config.toml")
self.assertIsNone(held(self.home / ".config/build-release" / "empty", self.home, {}), "no config.toml")
elsewhere = self.home / "code" / "acme"
elsewhere.mkdir()
(elsewhere / "config.toml").write_text(CLIENT, encoding="utf-8")
self.assertIsNone(held(elsewhere, self.home), "a config.toml outside ~/.claude-projects/")
self.assertIsNone(held(elsewhere, self.home, {}), "a config.toml outside ~/.config/build-release/")
def test_the_do_epic_folder_holds_no_projects_config(self) -> None:
folder = self.write("do-epic", CLIENT)
self.assertIsNone(held(folder, self.home))
self.assertIsNone(held(folder, self.home, {}))
def test_a_configs_folder_reached_through_a_symlink_holds_its_config(self) -> None:
target = self.home / "kept" / "acme"
target.mkdir(parents=True)
(target / "config.toml").write_text(CLIENT, encoding="utf-8")
(self.home / ".claude-projects").mkdir()
(self.home / ".claude-projects" / "acme").symlink_to(target)
self.assertIsInstance(held(target, self.home), ProjectConfig, "git names the folder by its resolved path")
(self.home / ".config/build-release").mkdir(parents=True)
(self.home / ".config/build-release" / "acme").symlink_to(target)
self.assertIsInstance(held(target, self.home, {}), ProjectConfig, "git names the folder by its resolved path")
class ByNameTest(ConfigCase):
def test_finds_the_config_of_the_project_whose_main_checkout_has_the_name_though_the_checkout_is_missing(self) -> None:
folder = self.write("acme", CLIENT)
found = by_name("acme-billing", self.home)
found = by_name("acme-billing", self.home, {})
assert isinstance(found, ProjectConfig), found
self.assertEqual((found.folder, found.top), (folder, self.checkout))
def test_finds_none_where_no_config_names_a_checkout_of_that_name(self) -> None:
self.write("acme", CLIENT)
self.assertIsNone(by_name("billing", self.home), "a part of a name is not the name")
self.assertIsNone(by_name("acme", self.home), "a config's key is not a repo's name")
self.assertIsNone(by_name("do-epic", self.home))
self.assertIsNone(by_name("billing", self.home, {}), "a part of a name is not the name")
self.assertIsNone(by_name("acme", self.home, {}), "a config's key is not a repo's name")
self.assertIsNone(by_name("do-epic", self.home, {}))
def test_fails_where_two_configs_name_a_checkout_of_that_name(self) -> None:
self.write("acme", CLIENT)
self.write("acme-two", CLIENT.replace("~/code/acme-billing", "~/other/acme-billing"))
found = by_name("acme-billing", self.home)
found = by_name("acme-billing", self.home, {})
assert isinstance(found, Failure), found
self.assertIn("acme/config.toml and ", found.reason)
self.assertIn("acme-two/config.toml each name a checkout called acme-billing", found.reason)
def test_fails_where_a_config_cannot_be_read_since_it_may_be_the_one_asked_for(self) -> None:
self.write("acme", "this is not toml")
self.assertIsInstance(by_name("acme-billing", self.home), Failure)
self.assertIsInstance(by_name("acme-billing", self.home, {}), Failure)
class EnvFilesTest(ConfigCase):
@@ -684,11 +684,11 @@ class EnvFilesTest(ConfigCase):
self.write("misplaced", 'checkout = "~/code/other"\nenv-file = "/srv/other.env"\n')
self.write("broken", "checkout = ")
self.write("none", CLIENT)
self.assertEqual(env_files(self.home), [self.home / "acme.env", pathlib.Path("/srv/other.env")])
self.assertEqual(env_files(self.home, {}), [self.home / "acme.env", pathlib.Path("/srv/other.env")])
def test_lists_do_epics_env_file_though_its_config_names_no_checkout(self) -> None:
self.write("do-epic", 'env-file = "~/jira.env"\n')
self.assertEqual(env_files(self.home), [self.home / "jira.env"])
self.assertEqual(env_files(self.home, {}), [self.home / "jira.env"])
class ToolTest(ConfigCase):
@@ -729,17 +729,17 @@ class ToolTest(ConfigCase):
unset = self.run_tool("env-file")
self.assertEqual((unset.returncode, unset.stdout, unset.stderr), (1, "", f"{folder / 'config.toml'} sets no `env-file`\n"))
self.assertNotIn("env-file", self.run_tool().stdout)
(folder / "config.toml").write_text(CLIENT + 'env-file = "~/.claude-projects/acme.env"\n')
(folder / "config.toml").write_text(CLIENT + 'env-file = "~/.config/build-release/acme.env"\n')
one = self.run_tool("env-file")
self.assertEqual((one.returncode, one.stdout), (0, f"{self.home}/.claude-projects/acme.env\n"))
self.assertEqual(self.run_tool().stdout.splitlines()[-1], f"env-file: {self.home}/.claude-projects/acme.env")
self.assertEqual((one.returncode, one.stdout), (0, f"{self.home}/.config/build-release/acme.env\n"))
self.assertEqual(self.run_tool().stdout.splitlines()[-1], f"env-file: {self.home}/.config/build-release/acme.env")
def test_prints_the_notifier_where_the_config_sets_one_and_fails_asking_for_it_where_it_does_not(self) -> None:
folder = self.write("acme", CLIENT)
unset = self.run_tool("notifier")
self.assertEqual((unset.returncode, unset.stdout, unset.stderr), (1, "", f"{folder / 'config.toml'} sets no `notifier`\n"))
self.assertNotIn("notifier", self.run_tool().stdout)
(folder / "config.toml").write_text(CLIENT + 'env-file = "~/.claude-projects/acme.env"\nnotifier = "slack"\n')
(folder / "config.toml").write_text(CLIENT + 'env-file = "~/.config/build-release/acme.env"\nnotifier = "slack"\n')
self.assertEqual(self.run_tool("notifier").stdout, "slack\n")
self.assertEqual(self.run_tool().stdout.splitlines()[-1], "notifier: slack")