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
+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")