Read the routing ladder from routing-ladder.json, which a project replaces with a file of its own in its config's folder
CI / tests (pull_request) Successful in 2m37s

This commit is contained in:
2026-11-15 18:51:59 +01:00
parent 9d0e2ad853
commit 0a20b6d4f6
42 changed files with 848 additions and 453 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ import sys
from failure import Failure
from git_cli.git_repo import git, Git
from project_config.settings import load, ProjectConfig, SETTINGS
from project_config.settings import load, ProjectConfig, SETTINGS, Unnamed
def main(argv: list[str]) -> int:
@@ -51,7 +51,7 @@ def located(directory: str | None, home: pathlib.Path, run: Git = git) -> Projec
"""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):
return found
return Unnamed(found.reason)
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.
+6 -1
View File
@@ -18,6 +18,11 @@ SPELLING = '"checkout:<path>" for a path in the checkout, "folder:<path>" for on
Place = str | pathlib.Path
@dataclasses.dataclass(frozen=True)
class Unnamed(Failure):
"""No config names a checkout here: none names the one asked for, or git finds no checkout. A reader of the routing ladder takes the shipped one there, as in a third party's clone; a config that is faulty or cannot be read is a plain 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."""
@@ -49,7 +54,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 Failure(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 ~/{PROJECTS}/<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]
+9 -1
View File
@@ -9,8 +9,9 @@ import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from failure import Failure
from project_config.settings import held, load, ProjectConfig, SETTINGS
from project_config.settings import held, load, ProjectConfig, SETTINGS, Unnamed
from test_env import isolated_env
from project_config.main import located
TOOL = pathlib.Path(__file__).resolve().parents[1] / "project-config"
@@ -119,6 +120,13 @@ class LoadTest(ConfigCase):
self.assertIn(str(self.checkout), reason)
self.assertIn("~/.claude-projects/<key>/config.toml", reason)
def test_tells_a_checkout_no_config_names_from_one_whose_config_is_faulty(self) -> None:
self.assertIsInstance(load(self.checkout, self.checkout, self.home), Unnamed)
self.assertIsInstance(located(str(self.checkout), self.home), Unnamed, "a folder that is no checkout has no config either")
self.write("acme", CLIENT.replace('plan = "folder:todo.md"\n', ""))
self.assertNotIsInstance(load(self.checkout, self.checkout, self.home), Unnamed)
self.assertIn("`plan` is missing", self.failure())
def test_every_missing_setting_is_named(self) -> None:
kept = "".join(line + "\n" for line in CLIENT.splitlines() if not line.startswith(("plan", "changelog", "principles")))
self.write("acme", kept)