Answer stability round 1: 0 🔴, 5 🟡 (0 misread); match a checkout through symlinks, test a linked worktree and -h, hold tests to facts
This commit is contained in:
@@ -9,9 +9,9 @@ from failure import Failure
|
|||||||
|
|
||||||
PROJECTS = ".claude-projects"
|
PROJECTS = ".claude-projects"
|
||||||
CONFIG = "config.toml"
|
CONFIG = "config.toml"
|
||||||
# Every path a project sets, by its role. The syntax panel picked role names over file names, which a client's project doesn't share.
|
# Every path a project sets, by its role. Three readers, seated as the human who writes the config, picked the spelling from four candidates. They picked role names over file names, which a client's project doesn't share.
|
||||||
SETTINGS = ("plan", "working-rules", "decisions", "score-anchors", "comprehension-history", "reading-cost", "changelog", "goals-and-audience", "principles")
|
SETTINGS = ("plan", "working-rules", "decisions", "score-anchors", "comprehension-history", "reading-cost", "changelog", "goals-and-audience", "principles")
|
||||||
# The panel also picked a prefix on every path over bare relative paths: each line says its own place, and a path with no prefix fails instead of landing somewhere by default.
|
# They also picked a prefix over bare relative paths: each line says its own place, and a relative path with no prefix fails instead of landing somewhere by default.
|
||||||
SPELLING = '"checkout:<path>" for a path in the checkout, "folder:<path>" for one in the config\'s folder, or a path that starts with / or ~/'
|
SPELLING = '"checkout:<path>" for a path in the checkout, "folder:<path>" for one in the config\'s folder, or a path that starts with / or ~/'
|
||||||
|
|
||||||
|
|
||||||
@@ -24,20 +24,22 @@ class ProjectConfig:
|
|||||||
|
|
||||||
|
|
||||||
def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure:
|
def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure:
|
||||||
"""The config that names main, the project's main checkout. A `checkout:` path lands in top, the worktree that asks, which is main itself outside a worktree.
|
"""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."""
|
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]]] = []
|
named: list[tuple[pathlib.Path, dict[str, object]]] = []
|
||||||
for file in sorted((home / PROJECTS).glob(f"*/{CONFIG}")):
|
for file in sorted((home / PROJECTS).glob(f"*/{CONFIG}")):
|
||||||
values = read(file, home)
|
config = read(file, home)
|
||||||
if isinstance(values, Failure):
|
if isinstance(config, Failure):
|
||||||
return values
|
return config
|
||||||
if values.pop("checkout") == main:
|
# Resolved on both sides, so a checkout reached through a symlink, or spelt with `..`, still finds its config.
|
||||||
named.append((file, values))
|
if config[0].resolve() == main.resolve():
|
||||||
|
named.append((file, config[1]))
|
||||||
if not named:
|
if not named:
|
||||||
return Failure(f"no config names the checkout {main}: write ~/{PROJECTS}/<key>/{CONFIG}, as README.md → Install shows")
|
return Failure(f"no config names the checkout {main}: write ~/{PROJECTS}/<key>/{CONFIG}, as `project-config --help` shows")
|
||||||
if len(named) > 1:
|
if len(named) > 1:
|
||||||
return Failure(f"{' and '.join(str(file) for file, _ in named)} both name the checkout {main}; one config may")
|
return Failure(f"{' and '.join(str(file) for file, _ in named)} each name the checkout {main}; only one config may")
|
||||||
file, values = named[0]
|
file, values = named[0]
|
||||||
paths = {name: placed(values[name], top, file.parent, home) for name in SETTINGS if name in values}
|
paths = {name: placed(values[name], top, file.parent, home) for name in SETTINGS if name in values}
|
||||||
faults = [
|
faults = [
|
||||||
@@ -50,16 +52,17 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
|||||||
return ProjectConfig(file.parent.name, file.parent, {name: path for name, path in paths.items() if path})
|
return ProjectConfig(file.parent.name, file.parent, {name: path for name, path in paths.items() if path})
|
||||||
|
|
||||||
|
|
||||||
def read(file: pathlib.Path, home: pathlib.Path) -> dict[str, object] | Failure:
|
def read(file: pathlib.Path, home: pathlib.Path) -> tuple[pathlib.Path, dict[str, object]] | Failure:
|
||||||
"""The config's values, its checkout as an absolute path."""
|
"""The checkout a config names, as an absolute path, and its other values."""
|
||||||
try:
|
try:
|
||||||
values = tomllib.loads(file.read_text(encoding="utf-8"))
|
values = tomllib.loads(file.read_text(encoding="utf-8"))
|
||||||
except (OSError, UnicodeDecodeError, tomllib.TOMLDecodeError) as failure:
|
except (OSError, UnicodeDecodeError, tomllib.TOMLDecodeError) as failure:
|
||||||
return Failure(f"cannot read {file}: {failure}")
|
return Failure(f"cannot read {file}: {failure}")
|
||||||
checkout = anywhere(values.get("checkout"), home)
|
checkout = anywhere(values.get("checkout"), home)
|
||||||
if checkout is None:
|
if checkout is None:
|
||||||
return Failure(f'{file}: `checkout` names the project\'s main checkout as a path that starts with / or ~/, such as "~/code/acme-billing", not {values.get("checkout")!r}')
|
found = f"not {values['checkout']!r}" if "checkout" in values else "and is missing"
|
||||||
return {**values, "checkout": checkout}
|
return Failure(f'{file}: `checkout` names the project\'s main checkout as a path that starts with / or ~/, such as "~/code/acme-billing", {found}')
|
||||||
|
return checkout, {name: value for name, value in values.items() if name != "checkout"}
|
||||||
|
|
||||||
|
|
||||||
def placed(value: object, top: pathlib.Path, folder: pathlib.Path, home: pathlib.Path) -> pathlib.Path | None:
|
def placed(value: object, top: pathlib.Path, folder: pathlib.Path, home: pathlib.Path) -> pathlib.Path | None:
|
||||||
|
|||||||
@@ -71,6 +71,13 @@ class LoadTest(ConfigCase):
|
|||||||
assert isinstance(found, ProjectConfig), found
|
assert isinstance(found, ProjectConfig), found
|
||||||
self.assertEqual(found.paths["principles"], pathlib.Path("/srv/principles"))
|
self.assertEqual(found.paths["principles"], pathlib.Path("/srv/principles"))
|
||||||
|
|
||||||
|
def test_a_checkout_reached_through_a_symlink_or_dots_finds_its_config(self) -> None:
|
||||||
|
self.write("acme", CLIENT)
|
||||||
|
(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)
|
||||||
|
|
||||||
def test_no_config_fails_naming_the_checkout_and_the_file_to_write(self) -> None:
|
def test_no_config_fails_naming_the_checkout_and_the_file_to_write(self) -> None:
|
||||||
for write_other in (False, True):
|
for write_other in (False, True):
|
||||||
with self.subTest(write_other=write_other):
|
with self.subTest(write_other=write_other):
|
||||||
@@ -85,10 +92,10 @@ class LoadTest(ConfigCase):
|
|||||||
self.write("acme", kept)
|
self.write("acme", kept)
|
||||||
reason = self.failure()
|
reason = self.failure()
|
||||||
for name in ("plan", "changelog", "principles"):
|
for name in ("plan", "changelog", "principles"):
|
||||||
self.assertIn(f"`{name}`", reason)
|
with self.subTest(name=name):
|
||||||
file = self.home / ".claude-projects" / "acme" / "config.toml"
|
self.assertIn(f"`{name}` is missing", reason)
|
||||||
settings = "plan, working-rules, decisions, score-anchors, comprehension-history, reading-cost, changelog, goals-and-audience, principles"
|
self.assertNotIn("`decisions` is", reason)
|
||||||
self.assertEqual(reason, f"{file}: `plan` is missing; `changelog` is missing; `principles` is missing. The settings are {settings}.")
|
self.assertIn("acme/config.toml", reason)
|
||||||
|
|
||||||
def test_every_fault_in_one_config_is_named_together(self) -> None:
|
def test_every_fault_in_one_config_is_named_together(self) -> None:
|
||||||
cases = {
|
cases = {
|
||||||
@@ -113,8 +120,9 @@ class LoadTest(ConfigCase):
|
|||||||
def test_two_configs_naming_one_checkout_fail_naming_both(self) -> None:
|
def test_two_configs_naming_one_checkout_fail_naming_both(self) -> None:
|
||||||
self.write("acme", CLIENT)
|
self.write("acme", CLIENT)
|
||||||
self.write("acme-copy", CLIENT)
|
self.write("acme-copy", CLIENT)
|
||||||
projects = self.home / ".claude-projects"
|
reason = self.failure()
|
||||||
self.assertEqual(self.failure(), f"{projects}/acme/config.toml and {projects}/acme-copy/config.toml both name the checkout {self.checkout}; one config may")
|
self.assertIn("acme/config.toml", reason)
|
||||||
|
self.assertIn("acme-copy/config.toml", reason)
|
||||||
|
|
||||||
def test_a_config_that_cannot_be_read_fails_whichever_checkout_asks(self) -> None:
|
def test_a_config_that_cannot_be_read_fails_whichever_checkout_asks(self) -> None:
|
||||||
cases = {"not TOML": "checkout = ", "no checkout": 'plan = "folder:todo.md"\n', "a checkout that is not text": "checkout = 3\n", "a relative checkout": 'checkout = "code/acme"\n'}
|
cases = {"not TOML": "checkout = ", "no checkout": 'plan = "folder:todo.md"\n', "a checkout that is not text": "checkout = 3\n", "a relative checkout": 'checkout = "code/acme"\n'}
|
||||||
@@ -123,10 +131,7 @@ class LoadTest(ConfigCase):
|
|||||||
self.home = pathlib.Path(made).resolve()
|
self.home = pathlib.Path(made).resolve()
|
||||||
self.write("acme", CLIENT)
|
self.write("acme", CLIENT)
|
||||||
self.write("broken", text)
|
self.write("broken", text)
|
||||||
reason = self.failure()
|
self.assertIn("broken/config.toml", self.failure())
|
||||||
self.assertIn("broken/config.toml", reason)
|
|
||||||
if case == "a relative checkout":
|
|
||||||
self.assertTrue(reason.endswith(", not 'code/acme'"), reason)
|
|
||||||
|
|
||||||
def test_a_folder_with_no_config_is_skipped(self) -> None:
|
def test_a_folder_with_no_config_is_skipped(self) -> None:
|
||||||
self.write("acme", CLIENT)
|
self.write("acme", CLIENT)
|
||||||
@@ -161,9 +166,20 @@ class ToolTest(ConfigCase):
|
|||||||
self.assertIn(said, ran.stderr)
|
self.assertIn(said, ran.stderr)
|
||||||
|
|
||||||
def test_help_shows_a_config(self) -> None:
|
def test_help_shows_a_config(self) -> None:
|
||||||
ran = self.run_tool("--help")
|
for flag in ("-h", "--help"):
|
||||||
self.assertEqual(ran.returncode, 0)
|
with self.subTest(flag=flag):
|
||||||
self.assertIn('plan = "folder:todo.md"', ran.stdout)
|
ran = self.run_tool(flag)
|
||||||
|
self.assertEqual(ran.returncode, 0)
|
||||||
|
self.assertIn('plan = "folder:todo.md"', ran.stdout)
|
||||||
|
|
||||||
|
def test_a_linked_worktree_finds_the_config_and_prints_its_own_files(self) -> None:
|
||||||
|
self.write("acme", CLIENT)
|
||||||
|
worktree = self.home / "code" / "acme-billing-item-3"
|
||||||
|
git = ["git", "-C", str(self.checkout), "-c", "user.name=t", "-c", "user.email=t@example.com"]
|
||||||
|
subprocess.run([*git, "commit", "-q", "--allow-empty", "-m", "first"], check=True, env=isolated_env())
|
||||||
|
subprocess.run([*git, "worktree", "add", "-q", str(worktree)], check=True, env=isolated_env())
|
||||||
|
ran = self.run_tool("changelog", cwd=worktree)
|
||||||
|
self.assertEqual((ran.returncode, ran.stdout), (0, f"{worktree}/CHANGELOG.md\n"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user