Commit a chunk's changes to the config's folder in its own repo
CI / tests (pull_request) Failing after 2m33s

This commit is contained in:
2026-11-13 01:58:50 +01:00
parent 1272894aea
commit cfb5e50904
9 changed files with 65 additions and 12 deletions
+9
View File
@@ -64,6 +64,15 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
return ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path})
def held(folder: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure | None:
"""The config folder holds, as its project's main checkout reads it; None where folder is not a config's folder under home."""
file = folder / CONFIG
if folder.resolve().parent != (home / PROJECTS).resolve() or not file.is_file():
return None
config = read(file, home)
return config if isinstance(config, Failure) else load(config[0], config[0], home)
def read(file: pathlib.Path, home: pathlib.Path) -> tuple[pathlib.Path, dict[str, object]] | Failure:
"""The checkout a config names, as an absolute path, and its other values."""
try:
+1 -1
View File
@@ -81,7 +81,7 @@ RULES: dict[RuleName, Rule] = {
),
"todo-rank-check": Rule(
"while todo.md has changes, staged or not, a git commit waits until rank_todo.py --check passes on it: the checkout's own bin/rank_todo.py where the checkout is of this setup's repo, else ~/.claude/bin/rank_todo.py",
"a git commit in a checkout whose todo.md has changes, and every git commit where the project's config puts todo.md outside the checkout, where no commit says whether it changed",
"a git commit in a checkout whose todo.md has changes, and every git commit where the project's config puts todo.md outside the checkout, where no commit says whether it changed; also a git commit in the config's folder, `~/.claude-projects/<key>/`, whose todo.md has changes there",
),
}
# The lookahead ends each reason at the next marker on its line, or at the line's end. The reason is lazy, so it stops at the next marker instead of running on and swallowing the markers after it.
+15
View File
@@ -927,6 +927,21 @@ class TodoRankCheck(unittest.TestCase):
(self.config.parent / "todo.md").write_text("# todo\n")
self.assertEqual(self.details(checkout), [f"own script checked {self.config.parent}/todo.md"])
def test_a_commit_in_the_configs_folder_checks_the_plan_it_keeps_there_once_it_changes(self):
checkout = self.changed_plan(f"{self.folder}/clone", self.STUB)
folder = str(self.config.parent)
git(folder, "init", "-q", "-b", "main")
self.assertEqual(self.details(folder), [], "the plan is the checkout's todo.md, which a commit here doesn't hold")
self.config.write_text(self.config.read_text().replace('"checkout:todo.md"', '"folder:todo.md"'))
(self.config.parent / "todo.md").write_text("# todo\n")
self.assertEqual(self.details(folder), [f"own script checked {folder}/todo.md"], "checked with the checkout's own rank_todo.py, as a commit there would be")
git(folder, "add", "-A")
git(folder, "commit", "-q", "-m", "plan")
self.assertEqual(self.details(folder), [], "committed, so unchanged")
self.config.write_text("checkout = 3\n")
(self.config.parent / "todo.md").write_text("# changed\n")
self.assertEqual(self.details(folder), [], "a config to fix doesn't block the commit that fixes it")
def test_a_plan_in_a_folder_of_the_checkout_is_checked_once_it_changes(self):
checkout = self.changed_plan(f"{self.folder}/clone", self.STUB)
self.config.write_text(self.config.read_text().replace('"checkout:todo.md"', '"checkout:plan/todo.md"'))
+17 -2
View File
@@ -10,7 +10,7 @@ from git_cli.git_repo import git
from rule_hook.git import guarded_git
from project_config.main import located
from release_plan import plan_file
from project_config.settings import ProjectConfig
from project_config.settings import held, ProjectConfig
# The checkout this hook runs from: bin/rule_hook/ sits two folders below it.
@@ -20,10 +20,13 @@ OWN_CHECK_SECONDS = 20
def todo_breaches(directory: str, own: pathlib.Path = OWN) -> list[Breach]:
"""Why the plan of directory's project is not ranked, where the plan has changed; the plan is the todo.md its config names."""
"""Why the plan of directory's project is not ranked, where the plan has changed; the plan is the todo.md its config names. directory may also be a config's folder, which commits its own files."""
top = guarded_git(directory, "rev-parse", "--show-toplevel")
if isinstance(top, Failure):
return []
held_here = held(pathlib.Path(top), pathlib.Path.home())
if held_here is not None:
return folder_breaches(top, held_here, own)
config = located(top, pathlib.Path.home(), functools.partial(git, guarded=True))
if isinstance(config, Failure):
# A checkout whose todo.md changes with no config is one whose config is still to write. An unchanged todo.md may be a third party's, whose clone needs no config.
@@ -36,6 +39,18 @@ def todo_breaches(directory: str, own: pathlib.Path = OWN) -> list[Breach]:
return [Breach("todo-rank-check", line, top) for line in check_failures(top, todo, config, own)]
def folder_breaches(top: str, config: ProjectConfig | Failure, own: pathlib.Path) -> list[Breach]:
"""Why the plan in top, a config's folder and a git repo of its own, is not ranked, where the plan has changed there; checked as a commit in the project's checkout would check it.
A config that cannot be read doesn't block anything here, so that the commit fixing it goes through."""
if isinstance(config, Failure) or not config.paths["plan"].is_relative_to(config.folder):
return []
todo = config.paths["plan"]
if not todo.is_file() or not changed(str(config.folder), todo, todo.relative_to(config.folder).as_posix()):
return []
return [Breach("todo-rank-check", line, top) for line in check_failures(str(config.top), todo, config, own)]
def check_failures(top: str, todo: pathlib.Path, config: ProjectConfig, own: pathlib.Path) -> list[str]:
"""Why rank_todo.py --check fails on todo. A checkout of the repo the hook runs from checks with its own bin/rank_todo.py, so a branch that changes the table's shape is held to its own rules. Any other checkout checks with the hook's ranking: running its script would run its code before every commit."""
script = pathlib.Path(top) / "bin" / "rank_todo.py"