Answer stability round 1: refuse an env-file only inside a config's folder or the clone folder, and split the tests
CI / tests (pull_request) Successful in 2m49s

This commit is contained in:
2026-11-18 12:40:04 +01:00
parent b93d3799c3
commit b5033abacc
2 changed files with 26 additions and 11 deletions
+4 -3
View File
@@ -9,7 +9,7 @@ One pair per machine, the same for every epic (docs/decisions.md → `do-epic: d
language = "Swedish"
- `jira-url` is the Jira site's address: https, a host, and no path.
- `env-file` is the file of Jira credentials: a path that starts with / or ~/, outside `~/.claude-projects` and the clone folder, which are git checkouts or hold them.
- `env-file` is the file of Jira credentials: a path that starts with / or ~/, outside every folder of `~/.claude-projects` and outside the clone folder, which hold git checkouts. `~/.claude-projects/<key>.env` is fine.
- `repoless-model` is the model that works an epic item with no repo: a model on the routing ladder, `model_routing/routing-ladder.json`.
- `clone-folder` is the folder a missing repo is cloned into: a path that starts with / or ~/. `~/code` where left out.
- `language` is the default language of Jira text, by its English name. English where left out.
@@ -45,7 +45,7 @@ class DoEpicConfig:
def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfig | Failure:
"""The settings and the repo rule under home; a Failure naming each missing or misspelt one it finds, so that do-epic refuses to start."""
"""The settings and the repo rule under home; a Failure naming the file it can't read, else each missing or misspelt setting it finds, so that do-epic refuses to start."""
folder = home / PROJECTS / DO_EPIC
values = parsed(folder / CONFIG)
if isinstance(values, Failure):
@@ -59,6 +59,7 @@ def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfi
unread = None
except (OSError, UnicodeDecodeError) as failure:
rule, unread = "", f"cannot read {folder / REPO_RULE}: {failure}"
config_folders = [path for path in (home / PROJECTS).iterdir() if path.is_dir()]
clone_folder = anywhere(values.get(CLONE_FOLDER, "~/code"), home)
env_file = anywhere(values.get(ENV_FILE), home)
language = values.get(LANGUAGE, "English")
@@ -69,7 +70,7 @@ def load(home: pathlib.Path, ladder_file: pathlib.Path = SHIPPED) -> DoEpicConfi
*([f"`{JIRA_URL}` is {url!r}, not a site's https address without a path, such as \"https://acme.atlassian.net\""] if JIRA_URL in values and not (isinstance(url, str) and re.fullmatch(SITE, url)) else []),
*([f"`{CLONE_FOLDER}` is {values[CLONE_FOLDER]!r}, not a path that starts with / or ~/"] if clone_folder is None else []),
*([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, not a path that starts with / or ~/"] if ENV_FILE in values and env_file is None else []),
*([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, inside ~/{PROJECTS} or the clone folder, which hold git checkouts"] if env_file and lies_in(env_file, home / PROJECTS, *([clone_folder] if clone_folder else [])) else []),
*([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, inside a folder of ~/{PROJECTS} or the clone folder, which hold git checkouts"] if env_file and lies_in(env_file, *config_folders, *([clone_folder] if clone_folder else [])) else []),
*([f"`{LANGUAGE}` is {language!r}, {fault}"] if LANGUAGE in values and (fault := language_fault(language)) else []),
*([f"`{REPOLESS_MODEL}` is {model!r}, not a model on the routing ladder: {', '.join(models)}"] if REPOLESS_MODEL in values and model not in models else []),
*([unread] if unread else [f"`{REPO_RULE}` is blank"] if not rule.strip() else []),
+22 -8
View File
@@ -43,19 +43,26 @@ class ConfigTest(unittest.TestCase):
assert isinstance(found, DoEpicConfig), found
self.assertEqual((found.clone_folder, found.language), (pathlib.Path("/srv/repos"), "Brazilian Portuguese"))
def test_refuses_while_the_config_is_missing_and_lists_the_settings(self) -> None:
def test_refuses_while_the_config_is_missing(self) -> None:
self.write(None)
self.assertIn(f"cannot read {self.folder / 'config.toml'}", self.failure())
def test_lists_the_settings_where_the_config_is_missing(self) -> None:
self.write(None)
self.assertIn("The settings are jira-url, env-file, repoless-model", self.failure())
def test_refuses_while_the_rule_is_missing_or_blank(self) -> None:
def test_refuses_while_the_rule_is_missing(self) -> None:
self.write(rule=None)
self.assertIn(f"cannot read {self.folder / 'repo-rule.md'}", self.failure())
self.write(SETTINGS.replace("claude-opus-5-5", "x"), rule=None)
self.assertIn("`repoless-model` is 'x'", self.failure(), "a missing rule doesn't hide the settings' faults")
def test_refuses_while_the_rule_is_blank(self) -> None:
self.write(rule=" \n")
self.assertIn("`repo-rule.md` is blank", self.failure())
def test_a_missing_rule_does_not_hide_the_settings_faults(self) -> None:
self.write(SETTINGS.replace("claude-opus-5-5", "x"), rule=None)
self.assertIn("`repoless-model` is 'x'", self.failure())
def test_names_each_missing_setting(self) -> None:
self.write("")
reason = self.failure()
@@ -80,16 +87,23 @@ class ConfigTest(unittest.TestCase):
self.write("\n".join([ln for ln in SETTINGS.splitlines() if not ln.startswith(name)] + [line]))
self.assertIn(f"`{name}` is", self.failure())
def test_keeps_the_credentials_outside_every_config_and_every_clone(self) -> None:
for env_file in ("~/.claude-projects/do-epic/jira.env", "~/.claude-projects/acme/jira.env"):
def test_keeps_the_credentials_outside_every_config_folder_and_the_clone_folder(self) -> None:
(self.home / ".claude-projects" / "acme").mkdir()
for env_file in ("~/.claude-projects/do-epic/jira.env", "~/.claude-projects/acme/jira.env", "~/code/acme/jira.env"):
with self.subTest(env_file):
self.write(SETTINGS.replace("~/jira.env", env_file))
self.assertIn("`env-file` is", self.failure())
self.write(SETTINGS.replace("~/jira.env", "~/code/acme/jira.env"))
self.assertIn("`env-file` is", self.failure())
def test_keeps_the_credentials_outside_a_clone_folder_the_config_sets(self) -> None:
self.write(SETTINGS.replace("~/jira.env", "~/clones/jira.env") + 'clone-folder = "~/clones"\n')
self.assertIn("`env-file` is", self.failure())
def test_accepts_credentials_beside_the_config_folders(self) -> None:
self.write(SETTINGS.replace("~/jira.env", "~/.claude-projects/do-epic.env"))
found = load(self.home)
assert isinstance(found, DoEpicConfig), found
self.assertEqual(found.env_file, self.home / ".claude-projects" / "do-epic.env")
def test_refuses_while_the_routing_ladder_cannot_be_read(self) -> None:
self.write()
found = load(self.home, self.home / "no-ladder.json")