Answer the architecture pass's second round

This commit is contained in:
2026-10-02 09:11:11 +02:00
parent 56a2985a6f
commit 6bd150c820
4 changed files with 34 additions and 42 deletions
+28 -29
View File
@@ -370,52 +370,51 @@ class ExitContract(unittest.TestCase):
def test_every_exit_1_stop_has_its_clause_in_help(self):
read, git, premises_ = "a transcript cannot be read or archived", "git cannot start or finds no checkout", "README.md holds no premises"
models_ = "the models file cannot be read or written"
# Each Stop with an exit code other than 0, 2 or 130, in source order, by the start of its reason, with its --help clause.
# Each Stop with an exit code other than 0, 2 or 130, in source order, by its code and the start of its reason, with its --help clause.
clauses = [
("cycle/interrupt.py", "interrupt", "entries.reason", read),
("cycle/interrupt.py", "interrupt", "f'could not start claude for the interrupt:", "claude cannot start for an interrupt"),
("cycle/interrupt.py", "interrupt", "f'could not tell whether you typed anything:", read),
("cycle/retry.py", "retried", "f'the {who} failed three times running:", "the worker or the judge fails three times running"),
("cycle/run.py", "work", "f'claude left no transcript for session", "claude leaves no transcript"),
("cycle/run.py", "rule", "entries.reason", read),
("cycle/run.py", "ask", "failure.reason", read),
("cycle/run.py", "close", "failure.reason", read),
("cycle/run.py", "close", "failure.reason", "a finished chunk's session cannot be deleted"),
("loop/main.py", "loop_run_from", "__doc__.strip()", "no task is given"),
("loop/main.py", "loop_run_from", "f'the reload cannot read the cycle number,", "a reload cannot read the cycle number, checkout root and task"),
("loop/reload.py", "exec_if_edited", "f'could not reload loop-claude:", "python cannot start for a reload"),
("project/checkout.py", "checkout_root", "f'could not start git:", git),
("project/checkout.py", "checkout_root", "found.stderr.strip()", git),
("project/model_choice.py", "get_or_ask_model", "f'could not save the model in", models_),
("project/model_choice.py", "read_models_file", 'f"could not read {saved}: {getattr(', models_),
("project/model_choice.py", "read_models_file", "f'could not read {saved}: not an object", models_),
("project/premises.py", "read_premises", "f'README.md in {root}:", premises_),
("project/premises.py", "read_premises", "f'README.md is not UTF-8", premises_),
("project/premises.py", "read_premises", "f'README.md has no ##", premises_),
("project/premises.py", "read_premises", "f'README.md has ## {name} more than once", premises_),
("project/premises.py", "read_premises", "f'README.md has nothing under", premises_),
("cycle/interrupt.py", "interrupt", "1", "entries.reason", read),
("cycle/interrupt.py", "interrupt", "1", "f'could not start claude for the interrupt:", "claude cannot start for an interrupt"),
("cycle/interrupt.py", "interrupt", "1", "f'could not tell whether you typed anything:", read),
("cycle/retry.py", "retried", "1", "f'the {who} failed three times running:", "the worker or the judge fails three times running"),
("cycle/run.py", "work", "1", "f'claude left no transcript for session", "claude leaves no transcript"),
("cycle/run.py", "rule", "1", "entries.reason", read),
("cycle/run.py", "ask", "1", "failure.reason", read),
("cycle/run.py", "close", "1", "failure.reason", read),
("cycle/run.py", "close", "1", "failure.reason", "a finished chunk's session cannot be deleted"),
("loop/main.py", "loop_run_from", "0 if task else 1", "__doc__.strip()", "no task is given"),
("loop/main.py", "loop_run_from", "1", "f'the reload cannot read the cycle number,", "a reload cannot read the cycle number, checkout root and task"),
("loop/reload.py", "exec_if_edited", "1", "f'could not reload loop-claude:", "python cannot start for a reload"),
("project/checkout.py", "checkout_root", "1", "f'could not start git:", git),
("project/checkout.py", "checkout_root", "1", "found.stderr.strip()", git),
("project/model_choice.py", "get_or_ask_model", "1", "f'could not save the model in", models_),
("project/model_choice.py", "read_models_file", "1", 'f"could not read {saved}: {getattr(', models_),
("project/model_choice.py", "read_models_file", "1", "f'could not read {saved}: not an object", models_),
("project/premises.py", "read_premises", "1", "f'README.md in {root}:", premises_),
("project/premises.py", "read_premises", "1", "f'README.md is not UTF-8", premises_),
("project/premises.py", "read_premises", "1", "f'README.md has no ##", premises_),
("project/premises.py", "read_premises", "1", "f'README.md has ## {name} more than once", premises_),
("project/premises.py", "read_premises", "1", "f'README.md has nothing under", premises_),
]
root = pathlib.Path(main.__file__).parents[1]
found = []
for path in sorted(root.rglob("*.py")):
functions = [node for node in ast.walk(ast.parse(path.read_text())) if isinstance(node, ast.FunctionDef)]
stops = [(call.lineno, function.name, ast.unparse(call.args[1])) for function in functions for call in ast.walk(function) if isinstance(call, ast.Call) and getattr(call.func, "id", None) == "Stop" and not (isinstance(call.args[0], ast.Constant) and call.args[0].value in (0, 2, 130))]
found += [(str(path.relative_to(root)), function, reason) for _, function, reason in sorted(stops)]
stops = [(call.lineno, function.name, ast.unparse(call.args[0]), ast.unparse(call.args[1])) for function in functions for call in ast.walk(function) if isinstance(call, ast.Call) and getattr(call.func, "id", None) == "Stop" and not (isinstance(call.args[0], ast.Constant) and call.args[0].value in (0, 2, 130))]
found += [(str(path.relative_to(root)), function, code, reason) for _, function, code, reason in sorted(stops)]
self.assertEqual(len(found), len(clauses), found)
for (path, function, reason), (want_path, want_function, reason_start, _) in zip(found, clauses):
self.assertEqual((path, function), (want_path, want_function))
for (path, function, code, reason), (want_path, want_function, want_code, reason_start, _) in zip(found, clauses):
self.assertEqual((path, function, code), (want_path, want_function, want_code))
self.assertTrue(reason.startswith(reason_start), f"{path} {function}: {reason}")
help_exit_1 = main.__doc__[main.__doc__.index("Exit 1"):main.__doc__.index("Exit 2")]
self.assertEqual([clause for *_, clause in clauses if f"- {clause}" not in help_exit_1], [])
class Checkouts(unittest.TestCase):
class Worktrees(unittest.TestCase):
def test_lists_the_root_alone_when_git_cannot_start(self):
fake = FakeEffects(git=[FileNotFoundError(2, "No such file or directory")])
self.assertEqual(checkout.worktrees("/r", fake.effects()), ["/r"])
class ReplaceFile(unittest.TestCase):
def test_removes_what_it_staged_when_the_replace_fails(self):
with tempfile.TemporaryDirectory() as root: