From 3a3631609c5c12b695c16bc3ca08ee6b631ee797 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 13 Nov 2026 20:38:53 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(1=20misread);=20refuse=20an?= =?UTF-8?q?=20env-file=20in=20the=20main=20checkout=20from=20a=20worktree,?= =?UTF-8?q?=20test=20the=20DM=20wiring=20in-process,=20and=20record=20why?= =?UTF-8?q?=20an=20unreadable=20config=20skips=20the=20DM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/loop_effects/test_effects.py | 8 ++++++++ bin/project_config/settings.py | 16 ++++++++-------- bin/project_config/test_project_config.py | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/bin/loop_effects/test_effects.py b/bin/loop_effects/test_effects.py index 72eb6602..1593e29c 100644 --- a/bin/loop_effects/test_effects.py +++ b/bin/loop_effects/test_effects.py @@ -13,6 +13,7 @@ import unittest.mock sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) +from mattermost_dm.dm import http_json from loop_effects.effects import run_python, say, system_effects NOW = 1790000000 @@ -59,6 +60,13 @@ class Said(unittest.TestCase): +class Dm(unittest.TestCase): + def test_sends_the_text_for_the_project_holding_the_current_directory_with_the_real_http(self): + with unittest.mock.patch("loop_effects.effects.dm", return_value=None) as sent: + self.assertIsNone(system_effects().dm("Which one?")) + sent.assert_called_once_with("Which one?", None, pathlib.Path.home(), http_json) + + class LocalTime(unittest.TestCase): def test_renders_seconds_in_the_machines_zone(self): # A POSIX zone two hours ahead of UTC, so a time in UTC would read 14:13:20. Cleanups run last in, first out: the zone is restored before time.tzset makes the clock read it again. diff --git a/bin/project_config/settings.py b/bin/project_config/settings.py index 2882112f..43009c4a 100644 --- a/bin/project_config/settings.py +++ b/bin/project_config/settings.py @@ -11,11 +11,11 @@ PROJECTS = ".claude-projects" CONFIG = "config.toml" # 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") -# The one setting a project may leave out: the file holding the credentials its tools read. It has no default either, so that a project without it asks for none, and never reads another project's. -ENV_FILE = "env-file" # 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. -OUTSIDE = "a path that starts with / or ~/ and lies outside the checkout and the config's folder, so that no git remote receives the credentials" SPELLING = '"checkout:" for a path in the checkout, "folder:" for one in the config\'s folder, or a path that starts with / or ~/' +# The one setting a project may leave out: the file of KEY=value credentials its tools read. It has no default either: a project without it asks for no credentials, and never reads another project's. +ENV_FILE = "env-file" +OUTSIDE = "a path that starts with / or ~/ and lies outside the checkout and the config's folder, so that no git remote receives the credentials" # Where a project keeps a file, for a tool that reads it at a commit: a path from the checkout's top, as git names it; or, outside the checkout, the file itself, which the tool reads as it stands, since the checkout's commits hold no version of it. Place = str | pathlib.Path @@ -28,7 +28,7 @@ class ProjectConfig: folder: pathlib.Path top: pathlib.Path paths: dict[str, pathlib.Path] - # The file of KEY=value credentials the project's tools read, or None where the config sets none. It lies outside the checkout and the config's folder, whose git repos can reach a remote. + # The config's `env-file`, or None where it sets none. env_file: pathlib.Path | None = None def tracked(self, setting: str) -> str | None: @@ -60,7 +60,7 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo file, values = named[0] paths = {name: placed(values[name], top, file.parent, home) for name in SETTINGS if name in values} env_file = anywhere(values.get(ENV_FILE), home) - misplaced = ENV_FILE in values and (env_file is None or inside(env_file, top, file.parent)) + misplaced = ENV_FILE in values and (env_file is None or lies_in(env_file, top, main, file.parent)) faults = [ *(f"`{name}` is missing" for name in SETTINGS if name not in values), *(f"`{name}` is not a setting" for name in values if name not in (*SETTINGS, ENV_FILE)), @@ -72,9 +72,9 @@ 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}, env_file) -def inside(path: pathlib.Path, top: pathlib.Path, folder: pathlib.Path) -> bool: - """Whether path lies in the checkout or in the config's folder.""" - return any(path.resolve().is_relative_to(place.resolve()) for place in (top, folder)) +def lies_in(path: pathlib.Path, *places: pathlib.Path) -> bool: + """Whether path lies in one of places. Both sides are resolved, so a symlink can't lead a path out of the place it names.""" + return any(path.resolve().is_relative_to(place.resolve()) for place in places) def held(folder: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure | None: diff --git a/bin/project_config/test_project_config.py b/bin/project_config/test_project_config.py index 36b9b99b..ff9bcd0c 100644 --- a/bin/project_config/test_project_config.py +++ b/bin/project_config/test_project_config.py @@ -179,6 +179,16 @@ class LoadTest(ConfigCase): self.assertIn("`env-file`", reason) self.assertNotIn("is not a setting", reason) + def test_a_worktree_refuses_an_env_file_in_the_main_checkout_as_well_as_one_in_its_own_files(self) -> None: + for case, folder in {"the main checkout": "acme-billing", "the worktree": "acme-billing-item-3"}.items(): + with self.subTest(case=case), tempfile.TemporaryDirectory() as made: + 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) + assert isinstance(found, Failure), found + self.assertIn("`env-file`", found.reason) + 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') self.assertEqual(self.failure(), f"{folder / 'config.toml'}: `plan` is missing; `env-file` is 'checkout:.env', not {OUTSIDE}. The settings are {', '.join(SETTINGS)}, and optionally env-file.") @@ -246,6 +256,16 @@ class ToolTest(ConfigCase): one = self.run_tool("changelog", cwd=self.checkout / "src") self.assertEqual((one.returncode, one.stdout), (0, f"{self.checkout}/CHANGELOG.md\n")) + def test_prints_the_env_file_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("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') + 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") + def test_fails_on_stderr(self) -> None: cases = {"no config": ((), "no config names the checkout"), "an unknown setting": (("readme",), "usage:"), "two arguments": (("plan", "changelog"), "usage:")} for case, (args, said) in cases.items():