From 32aee19da2fe772ac842f95fc150a03e5bd8b00b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:07:35 +0100 Subject: [PATCH 01/45] Treat a recorded base that is origin's default branch as the default branch, and wait for the forge to show a pushed head before push asks for a review --- bin/chunk_pr/main.py | 50 +++++++++++++++++++++++++---------- bin/chunk_pr/test_chunk_pr.py | 38 ++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index 2ececd93..cd1909a8 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -43,7 +43,9 @@ ready marks the pull request ready for review. On Gitea a draft is a pull req as the pull request's title first; where that fails, the pull request stays a draft. push pushes the branch, setting its upstream. Where its pull request is open and goes into an epic's working branch, it then asks for a review as ready does. Use it for each push - after ready there, and wait for that review as for any other. + after ready there, and wait for that review as for any other. Where the pull request + was open at the branch's old head, it waits up to a minute for the forge to show the + new head on it, and fails, naming the pull request, where the forge never does. merge merges the pull request in its turn: the chunks of one project on this machine take turns, one at a time. Run it in the background. In its turn it: 1. fetches origin and merges its default branch into the branch, as sync does; @@ -139,6 +141,9 @@ QUEUE = "chunk-pr-merge-queue" # A turn lasts as long as its checks, which chunk-pr waits half an hour for on Gitea, so a queue still held after that is reported, not waited out. QUEUE_SECONDS = 30 * 60 QUEUE_POLL_SECONDS = 10 +# How long push waits for the forge to show the pushed commit as the head of the branch's open pull request, polling every PUSH_POLL_SECONDS: GitHub may list the old head for a while after a push. +PUSH_SECONDS = 60 +PUSH_POLL_SECONDS = 5 # The line record-ruling writes into the comprehension history, as git's -G reads it. RULING = "^Ruling: " # The project's config, loaded once per step, on the first call that needs it. @@ -164,8 +169,8 @@ def main(argv: list[str]) -> int: return 0 -def step(argv: list[str], run: Run, config: Config, parks: bool = False) -> str | Failure: - """Run the step argv names: the line to print, or a Failure. A malformed argv doesn't run anything. parks is whether a merge fails at once where it would wait for an approval (`merged`).""" +def step(argv: list[str], run: Run, config: Config, parks: bool = False, sleep: typing.Callable[[float], None] = time.sleep) -> str | Failure: + """Run the step argv names: the line to print, or a Failure. A malformed argv doesn't run anything. parks is whether a merge fails at once where it would wait for an approval (`merged`). sleep is how push and merge wait.""" match argv: case ["open", title, *body] if len(body) <= 1 and not title.startswith("-"): return Failure("give a title of one line") if not one_line(title) else misfit(title, run, config) or opened(title, body[0] if body else "", run) @@ -175,12 +180,12 @@ def step(argv: list[str], run: Run, config: Config, parks: bool = False) -> str return Failure("give a title of one line") if title and not one_line(title[0]) else (misfit(title[0], run, config) if title else None) or readied(run, title[0] if title else None, config) # Three readers, seated as those who run `chunk-pr`, picked the spellings `push`, 3-0, and `open-epic`, 2-1. case ["push"]: - return pushed(run, config) + return pushed(run, config, sleep) case ["open-epic", epic, title, *body] if len(body) <= 1 and not any(given.startswith("-") for given in (epic, title)): return Failure("give a title of one line") if not one_line(title) else epic_opened(epic, title, body[0] if body else "", run, config) case ["merge", *given]: finishes = finishes_of(given) - return Failure(USAGE) if finishes is None else merged(run, config, time.sleep, finishes=finishes, parks=parks) + return Failure(USAGE) if finishes is None else merged(run, config, sleep, finishes=finishes, parks=parks) case ["clean"]: return cleaned(run) return Failure(USAGE) @@ -235,12 +240,13 @@ class Base: def base_of(branch: str, run: Run) -> Base | Failure: - """The Base of the pull request from branch: the epic's working branch the checkout records for it (`git_repo.record_chunk_base`), else origin's default branch.""" - recorded = run(["git", "config", "--get", f"branch.{branch}.{CHUNK_BASE}"]) - if not isinstance(recorded, Failure) and recorded.strip(): - return Base(recorded.strip(), True) + """The Base of the pull request from branch: the epic's working branch the checkout records for it (`git_repo.record_chunk_base`), else origin's default branch. A recorded base that is origin's default branch is no epic's: the pull request merges into the default branch, where a person may have to merge it.""" default = default_branch(run) - return default if isinstance(default, Failure) else Base(default, False) + if isinstance(default, Failure): + return default + recorded = run(["git", "config", "--get", f"branch.{branch}.{CHUNK_BASE}"]) + recorded = "" if isinstance(recorded, Failure) else recorded.strip() + return Base(recorded, True) if recorded and recorded != default else Base(default, False) def pull(run: Run) -> tuple[Forge, str, str] | Failure: @@ -363,14 +369,15 @@ def marked_ready(run: Run, title: str | None) -> str | Failure: return f"Marked pull request #{number} ready, titled “{title}”." if title is not None else f"Marked pull request #{number} ready." -def pushed(run: Run, config: Config) -> str | Failure: - """Push the branch checked out, and ask for a review of its open pull request as `review_asked` does.""" +def pushed(run: Run, config: Config, sleep: typing.Callable[[float], None]) -> str | Failure: + """Push the branch checked out, and ask for a review of its open pull request as `review_asked` does, once the forge shows the pushed commit as that pull request's head.""" found = checkout(run) if isinstance(found, Failure): return found forge, branch, head = found - sent = run(["git", "push", "--quiet", "--set-upstream", "origin", branch]) - number = sent if isinstance(sent, Failure) else open_pull(forge, branch, head, run) + old = run(["git", "ls-remote", "origin", f"refs/heads/{branch}"]) + sent = old if isinstance(old, Failure) else run(["git", "push", "--quiet", "--set-upstream", "origin", branch]) + number = sent if isinstance(sent, Failure) else shown_pull(forge, branch, head, old.split()[0] if old.strip() else "", run, sleep) if isinstance(number, Failure): return number asked = review_asked(forge, number, run, config) if number is not None else None @@ -379,6 +386,21 @@ def pushed(run: Run, config: Config) -> str | Failure: return f"Pushed {branch}, and asked for a review of pull request #{number} with “{asked}”." if asked else f"Pushed {branch}." +def shown_pull(forge: Forge, branch: str, head: str, old: str, run: Run, sleep: typing.Callable[[float], None]) -> str | None | Failure: + """The number of branch's open pull request at head, just pushed over old, the head origin had before. The forge may keep showing old for up to PUSH_SECONDS, so while it does, this polls; a Failure naming the pull request where it still does. None where no pull request is open at head or at old: `push` before `open` is normal.""" + stale = None + for waited in range(0, PUSH_SECONDS + 1, PUSH_POLL_SECONDS): + number = open_pull(forge, branch, head, run) + if number is not None or not old or old == head: + return number + stale = open_pull(forge, branch, old, run) + if not isinstance(stale, str): + return stale + if waited < PUSH_SECONDS: + sleep(PUSH_POLL_SECONDS) + return Failure(f"pushed {branch}, but the forge still shows pull request #{stale} at {old[:12]}, not at {head[:12]}, after {PUSH_SECONDS} seconds, so no review was asked for; run chunk-pr push again") + + def review_asked(forge: Forge, number: str, run: Run, config: Config) -> str | None | Failure: """Comment on the pull request numbered number with the config's `review-request-comment`, where the pull request goes into an epic's working branch: a forge's auto-reviewer may review only pull requests into the default branch unless asked. The comment made; None where the config names none or the pull request goes into the default branch.""" branch = answers(run, ["symbolic-ref", "--short", "HEAD"]) diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index 46727ddc..4132ad47 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -24,6 +24,8 @@ GITHUB = "git@github.com:me/project.git" GITEA = "ssh://git@gitea.example.org:22/me/project.git" HEAD = "c0ffee" PUSH = ["git", "push", "--quiet", "--set-upstream", "origin", "item-7"] +OLD = "badc0de" +OLD_HEAD = ["git", "ls-remote", "origin", "refs/heads/item-7"] GH_LIST = ["gh", "pr", "list", "--head", "item-7", "--json", "number,headRefOid,isCrossRepository", "--template", "{{range .}}{{.number}}\t{{.headRefOid}}\t{{.isCrossRepository}}\n{{end}}"] TEA_LIST = ["tea", "api", "repos/{owner}/{repo}/pulls?state=open&limit=50"] GH_SETTINGS = ["gh", "repo", "view", "--json", "mergeCommitAllowed,rebaseMergeAllowed,squashMergeAllowed"] @@ -61,6 +63,8 @@ class Checkout: self.chunk_base = "" # The branch the forge merges the pull request into on each read; the last one repeats. Empty where the forge has the checkout's: chunk_base, else main. self.bases: list[str] = [] + # The heads GitHub lists pull request #12 at on each read; the last one repeats. Empty where it lists HEAD. + self.listed_heads: list[str] = [] # What GitHub reports as the pull request's review decision on each read; the last one repeats. self.decisions = ["APPROVED"] # Set, what GitHub prints instead of a decision's JSON. @@ -101,7 +105,7 @@ class Checkout: if command[2:3] == ["create"]: self.open = True if command == GH_LIST: - return f"12\t{HEAD}\tfalse\n" if self.open else "" + return f"12\t{self.listed_heads.pop(0) if len(self.listed_heads) > 1 else self.listed_heads[0] if self.listed_heads else HEAD}\tfalse\n" if self.open else "" if command == TEA_LIST: return json.dumps([{"number": 12, "head": {"ref": "item-7", "label": "item-7", "sha": HEAD, "repo": {"full_name": "me/project"}}, "base": {"repo": {"full_name": "me/project"}}}] if self.open else []) if command == TEA_STATUS: @@ -123,7 +127,7 @@ class Checkout: def acted(self) -> list[list[str]]: """What it ran beyond reading the checkout, the pull requests and the repository's settings.""" - reads = [GH_LIST, GH_DECISION, GH_BASE, TEA_LIST, TEA_PULL, GH_SETTINGS, TEA_SETTINGS, OWED, GH_CHECKS, TEA_BRANCH, TEA_STATUS, GH_THREADS] + reads = [OLD_HEAD, GH_LIST, GH_DECISION, GH_BASE, TEA_LIST, TEA_PULL, GH_SETTINGS, TEA_SETTINGS, OWED, GH_CHECKS, TEA_BRANCH, TEA_STATUS, GH_THREADS] return [command for command in self.ran if tuple(command) not in self.answers and command not in reads] @@ -1078,6 +1082,14 @@ class EpicBranch(unittest.TestCase): self.assertEqual(step(["merge"], checkout, checkout.config, parks=True), "Merged pull request #12 (merge).") self.assertNotIn(GH_DECISION, checkout.ran) + def test_a_recorded_base_that_is_origins_default_branch_leaves_the_pull_request_to_a_person(self): + checkout = self.checkout() + checkout.chunk_base = "main\n" + checkout.answers[(PROJECT_CONFIG, "merge")] = "human\n" + done = step(["merge"], checkout, checkout.config) + self.assertIn("awaits a person's merge", str(done)) + self.assertFalse(any("merge" in command[1:4] for command in checkout.acted() if command[0] != "git"), checkout.acted()) + def test_merge_fails_naming_both_branches_where_the_forge_merges_the_pull_request_into_another_branch_than_the_checkout_records(self): for origin in (GITHUB, GITEA): with self.subTest(origin): @@ -1185,6 +1197,28 @@ class EpicBranch(unittest.TestCase): self.assertEqual(step(["push"], checkout, checkout.config), "Pushed item-7.") self.assertEqual(checkout.acted(), [PUSH]) + def test_push_waits_for_the_forge_to_show_the_new_head_before_it_asks_for_a_review(self): + checkout, slept = self.checkout(), [] + checkout.answers[tuple(OLD_HEAD)] = f"{OLD}\trefs/heads/item-7\n" + checkout.listed_heads = [OLD, OLD, OLD, OLD, HEAD] + self.assertEqual(step(["push"], checkout, checkout.config, sleep=slept.append), "Pushed item-7, and asked for a review of pull request #12 with “@reviewer review”.") + self.assertEqual(slept, [5, 5]) + + def test_push_fails_naming_the_pull_request_where_the_forge_never_shows_the_new_head(self): + checkout, slept = self.checkout(), [] + checkout.answers[tuple(OLD_HEAD)] = f"{OLD}\trefs/heads/item-7\n" + checkout.listed_heads = [OLD] + done = step(["push"], checkout, checkout.config, sleep=slept.append) + self.assertEqual(done, Failure(f"pushed item-7, but the forge still shows pull request #12 at {OLD[:12]}, not at {HEAD[:12]}, after 60 seconds, so no review was asked for; run chunk-pr push again")) + self.assertEqual(sum(slept), 60) + self.assertNotIn(self.COMMENT_GH, checkout.ran) + + def test_push_waits_for_no_pull_request_that_was_not_open_at_the_old_head(self): + checkout, slept = self.checkout(open=False), [] + checkout.answers[tuple(OLD_HEAD)] = f"{OLD}\trefs/heads/item-7\n" + self.assertEqual(step(["push"], checkout, checkout.config, sleep=slept.append), "Pushed item-7.") + self.assertEqual(slept, []) + def test_a_failed_push_asks_for_no_review(self): checkout = self.checkout() checkout.answers[tuple(PUSH)] = Failure("git push: rejected") From 83298bed3d7ef2ad5c9d2466232145782ead5f2a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:08:14 +0100 Subject: [PATCH 02/45] Make chunk-preflight report space-indented code with no setting that says so, and narrow the tabs principle's override --- bin/chunk_preflight/facts.py | 12 +++- bin/chunk_preflight/gathered.py | 3 + bin/chunk_preflight/indentation.py | 56 ++++++++++++++++ bin/chunk_preflight/main.py | 8 ++- bin/chunk_preflight/test_chunk_preflight.py | 30 +++++++++ bin/chunk_preflight/test_indentation.py | 72 +++++++++++++++++++++ principles/technical-principles.md | 3 +- 7 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 bin/chunk_preflight/indentation.py create mode 100644 bin/chunk_preflight/test_indentation.py diff --git a/bin/chunk_preflight/facts.py b/bin/chunk_preflight/facts.py index 806b0029..d7121a4e 100644 --- a/bin/chunk_preflight/facts.py +++ b/bin/chunk_preflight/facts.py @@ -5,6 +5,7 @@ from release_plan.next_chunk import cut_name, NextChunk, NoItem from release_plan.release_standing import dated_cut, LastCut, unreleased_entries, UNSEEN_RELEASES from failure import Failure from forge.commands import Forge +from chunk_preflight.indentation import SpaceIndented from chunk_preflight.gathered import Gathered, ItemFacts, NamedPath, Ran from text_files.markdown_text import listed, quoted from chunk_preflight.choices import PULLS_LIST @@ -19,7 +20,7 @@ def render(found: Gathered) -> list[str]: """One `- ` line per fact, then the item's tagline and detail, the detail of each item that may join its chunk, and what each tool printed.""" note = [f"- {found.note}"] if found.note else [] unseen = [f"- {UNSEEN_RELEASES}"] if found.plan_outside else [] - head = [*note, f"- {last_release(found.default, found.cut)}", *unseen, *merge_lines(found)] + head = [*note, f"- {last_release(found.default, found.cut)}", *unseen, *merge_lines(found), *indentation_lines(found.indentation)] paths = f"- The project's config puts its files and plan at: {'; '.join(f'{setting} {path}' for setting, path in found.places.items())}." texts = f"- The project's config sets: {'; '.join(f'{setting} {text}' for setting, text in found.texts.items())}." if isinstance(found.item, NoItem): @@ -38,6 +39,15 @@ def merge_lines(found: Gathered) -> list[str]: return [*left, *over, *unread] +def indentation_lines(found: SpaceIndented | Failure | None) -> list[str]: + """The one fact about indentation: the project's code is space-indented with no setting that says so. It only reports: a client's repo belongs to its team.""" + if isinstance(found, Failure): + return [f"- Whether the project's code is space-indented cannot be read: {found.reason}"] + if found is None: + return [] + return [f"- The project's code is space-indented ({found.spaced} lines against {found.tabbed} with tabs), and no `.editorconfig` with `indent_style` nor formatter setting (`rustfmt.toml` `hard_tabs`, Prettier `useTabs`, Biome `indentStyle`) says so. The technical principles indent with hard tabs unless a setting a tool reads, plus a decision in `docs/decisions.md` that names the reason, overrides that. Either convert the code to tabs, or record the override in `.editorconfig` and a decision."] + + def last_release(default: str, release: LastCut) -> str: if isinstance(release.tag, Failure): return f"Last version cut: cannot be read: {release.tag.reason}" diff --git a/bin/chunk_preflight/gathered.py b/bin/chunk_preflight/gathered.py index 00f81899..b7de48b8 100644 --- a/bin/chunk_preflight/gathered.py +++ b/bin/chunk_preflight/gathered.py @@ -6,6 +6,7 @@ from failure import Failure from forge.commands import Forge from release_plan.release_standing import LastCut from release_plan.next_chunk import NextChunk, NoItem +from chunk_preflight.indentation import SpaceIndented @dataclasses.dataclass(frozen=True) @@ -75,3 +76,5 @@ class Gathered: merges_unread: Failure | None = None # The worktrees `chunk-pr clean` is still to remove. left: tuple[LeftWorktree, ...] = () + # The line counts of the project's code where it is space-indented with no setting that says so, or why they cannot be read; None where it is not. + indentation: SpaceIndented | Failure | None = None diff --git a/bin/chunk_preflight/indentation.py b/bin/chunk_preflight/indentation.py new file mode 100644 index 00000000..4a73e4c0 --- /dev/null +++ b/bin/chunk_preflight/indentation.py @@ -0,0 +1,56 @@ +"""Whether a project's code is space-indented with no tool setting that says so. + +The technical principles indent with hard tabs by default, and let a setting a tool reads override that. Code that is mostly space-indented, with no such setting, reads as a first session's habit that later sessions followed, not as a choice.""" +import dataclasses +import os +import pathlib +import re + +from failure import Failure +from git_cli.git_repo import git + +# The files the project's language tooling covers. Markdown, JSON and YAML are not code: their indentation is a format's. +CODE = re.compile(r".*\.(py|js|mjs|cjs|jsx|ts|tsx|rs|go|php|java|kt|kts|scala|rb|c|h|cc|cpp|hpp|cs|swift|sh|bash|lua|ex|exs|dart|vue|svelte)", re.IGNORECASE) +# Committed copies of other people's code follow their authors' style. +VENDORED = re.compile(r"(^|/)(vendor|node_modules|third_party)/") +# The files whose key says how to indent: an `.editorconfig` with `indent_style`, rustfmt's `hard_tabs`, Prettier's `useTabs` in its own files or a `package.json`, Biome's `indentStyle`. +SETTINGS = ( + (re.compile(r"\.editorconfig"), "indent_style"), + (re.compile(r"\.?rustfmt\.toml"), "hard_tabs"), + (re.compile(r"\.prettierrc(\.\w+)?|prettier\.config\.\w+|package\.json"), "useTabs"), + (re.compile(r"biome\.jsonc?"), "indentStyle"), +) +# Two spaces is the narrowest space indent; a lone leading space aligns a comment's continuation. +SPACED_LINE = re.compile(r"^ {2,}\S", re.MULTILINE) +TABBED_LINE = re.compile(r"^\t+\S", re.MULTILINE) + + +@dataclasses.dataclass(frozen=True) +class SpaceIndented: + """Lines of tracked code that start with spaces, and lines that start with tabs.""" + spaced: int + tabbed: int + + +def space_indented(base: pathlib.Path, timeout: float | None = None) -> SpaceIndented | Failure | None: + """The line counts of the tracked code under base where it has more space-indented lines than tab-indented ones and no tracked file sets the indent; None where it doesn't, or has no code; a Failure where a file cannot be read.""" + tracked = git("ls-files", "-z", cwd=str(base), timeout=timeout) + if isinstance(tracked, Failure): + return tracked + spaced = tabbed = 0 + for name in filter(None, tracked.split("\0")): + code = CODE.fullmatch(name) and not VENDORED.search(name) + key = next((key for pattern, key in SETTINGS if pattern.fullmatch(name.rsplit("/", 1)[-1])), None) + path = base / name + if not (code or key) or not os.path.isfile(path): + continue + try: + text = path.read_text(encoding="utf-8", errors="replace") + except OSError as failure: + return Failure(f"cannot read {name}: {failure}") + if key and key in text: + return None + if code: + spaced += len(SPACED_LINE.findall(text)) + tabbed += len(TABBED_LINE.findall(text)) + return SpaceIndented(spaced, tabbed) if spaced > tabbed else None diff --git a/bin/chunk_preflight/main.py b/bin/chunk_preflight/main.py index 9487ea08..30bc9ce5 100644 --- a/bin/chunk_preflight/main.py +++ b/bin/chunk_preflight/main.py @@ -21,6 +21,11 @@ and prints that the release reviews and the cuts are the human's to call. It pri finished on the branch of an open pull request that is not a draft, where the checkout holds the plan. Where no item of the release can start and one awaits such a merge, it names those pull requests and says the working loop stops there; +- where the project's tracked code (the files its language tooling covers, not Markdown, JSON or + YAML) has more space-indented than tab-indented lines, and neither an `.editorconfig` with + `indent_style` nor a formatter setting (`rustfmt.toml` `hard_tabs`, Prettier `useTabs`, Biome + `indentStyle`) says so, one line naming the technical principles' hard-tabs default and the two + ways out. It only reports; - the next release and its first item that does not wait, the item loop-claude routes on, with its L and E + I; with --item , the plan item of that ID instead, which loop-claude names in a window named for an item. An item waits while it is marked question, while an item still in todo.md @@ -93,6 +98,7 @@ from git_cli import epic_branch from failure import Failure from forge.commands import Forge, forge_of, Run, runner from chunk_preflight.gathered import Gathered, ItemFacts, LeftWorktree, NamedPath, Ran, Worktree +from chunk_preflight.indentation import space_indented from chunk_preflight.facts import JOINING_DETAILS, render from project_config.main import located from forge.pulls import merged_pull @@ -165,7 +171,7 @@ def preflight(root: pathlib.Path, timeout: float, make: bool, item_id: int | Non item = plan if isinstance(plan, NoItem) else item_facts(root, ref, plan, timeout, make, epic_branch_of(config)) # A `checkout:` path lands in the worktree the chunk works in. made = located(str(item.worktree.path), pathlib.Path.home()) if isinstance(item, ItemFacts) and isinstance(item.worktree, Worktree) else config - return render(Gathered(ref, note, held.cut, item, plan_name(ref, outside), (config if isinstance(made, Failure) else made).places, outside is not None, config.texts, merges_unread=held.merges_unread, left=left_worktrees(root, forge_run) if config.merge == "human" else ())) + return render(Gathered(ref, note, held.cut, item, plan_name(ref, outside), (config if isinstance(made, Failure) else made).places, outside is not None, config.texts, merges_unread=held.merges_unread, left=left_worktrees(root, forge_run) if config.merge == "human" else (), indentation=space_indented(item.worktree.path if isinstance(item, ItemFacts) and isinstance(item.worktree, Worktree) else root, timeout))) def epic_branch_of(config: ProjectConfig) -> str | None | Failure: diff --git a/bin/chunk_preflight/test_chunk_preflight.py b/bin/chunk_preflight/test_chunk_preflight.py index ed6a98bb..01ec521f 100644 --- a/bin/chunk_preflight/test_chunk_preflight.py +++ b/bin/chunk_preflight/test_chunk_preflight.py @@ -22,6 +22,7 @@ from release_plan.release_standing import LastCut, UNSEEN_RELEASES from release_plan.awaiting_merge import marked from release_plan import next_chunk from chunk_preflight.facts import open_pulls, render +from chunk_preflight.indentation import SpaceIndented from plan_store.todo_md import plan_of from chunk_preflight.choices import worktree_add, worktree_on, worktrees from project_config.doubles import write_config @@ -801,6 +802,35 @@ class Running(unittest.TestCase): self.assertIsNone(line_count(folder)) +class IndentationFact(unittest.TestCase): + def said(self, indentation): + found = dataclasses.replace(gathered(item_facts()), indentation=indentation) + return [line for line in render(found) if "indent" in line] + + def test_names_the_counts_the_principle_and_the_two_ways_out(self): + (line,) = self.said(SpaceIndented(spaced=120, tabbed=3)) + self.assertIn("space-indented (120 lines against 3 with tabs)", line) + self.assertIn("The technical principles indent with hard tabs", line) + self.assertIn("convert the code to tabs, or record the override in `.editorconfig` and a decision", line) + + def test_says_nothing_where_the_code_is_not_space_indented_and_why_where_it_cannot_be_read(self): + self.assertEqual(self.said(None), []) + self.assertEqual(self.said(Failure("cannot read a.py: denied")), ["- Whether the project's code is space-indented cannot be read: cannot read a.py: denied"]) + + def test_prints_it_from_a_checkout_of_spaced_code_and_only_then(self): + tabbed = Repo(self) + self.assertNotIn("space-indented", tabbed.preflight().stdout) + spaced = Repo(self) + spaced.write(spaced.root, "src/app.py", "def run():\n if True:\n return 1\n") + spaced.commit(spaced.root, "spaces") + done = spaced.preflight() + self.assertEqual(done.returncode, 0, done.stderr) + self.assertIn("- The project's code is space-indented (2 lines against 0 with tabs)", done.stdout) + spaced.write(spaced.root, ".editorconfig", "[*]\nindent_style = space\n") + spaced.commit(spaced.root, "setting") + self.assertNotIn("space-indented", spaced.preflight().stdout) + + class BesideTest(unittest.TestCase): """The fact that names the items that may start chunks beside the next one.""" # Items 3 and 4 touch other parts of one file, and item 6 touches what item 3 does. diff --git a/bin/chunk_preflight/test_indentation.py b/bin/chunk_preflight/test_indentation.py new file mode 100644 index 00000000..018db070 --- /dev/null +++ b/bin/chunk_preflight/test_indentation.py @@ -0,0 +1,72 @@ +import os +import pathlib +import subprocess +import sys +import tempfile +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) + +from chunk_preflight.indentation import space_indented, SpaceIndented +from failure import Failure +from test_env import isolated_env + +TABBED = "def run():\n\tif True:\n\t\treturn 1\n" +SPACED = "def run():\n if True:\n return 1\n" + + +class SpaceIndentation(unittest.TestCase): + """Each case is a fake checkout whose tracked files are those given.""" + + def checkout(self, **files): + temp = tempfile.TemporaryDirectory() + self.addCleanup(temp.cleanup) + root = pathlib.Path(os.path.realpath(temp.name)) + for name, text in files.items(): + path = root / name.replace("__", "/") + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(text) + subprocess.run(["git", "init", "--quiet"], cwd=root, check=True, env=isolated_env()) + subprocess.run(["git", "add", "-A"], cwd=root, check=True, env=isolated_env()) + return root + + def test_stays_silent_for_code_indented_with_tabs(self): + self.assertIsNone(space_indented(self.checkout(**{"app.py": TABBED}))) + + def test_counts_the_lines_of_code_indented_with_spaces_where_no_tool_setting_says_so(self): + root = self.checkout(**{"app.py": SPACED, "lib__more.rs": SPACED, "web__page.ts": TABBED, "README.md": SPACED}) + self.assertEqual(space_indented(root), SpaceIndented(spaced=4, tabbed=2)) + + def test_stays_silent_where_a_tool_reads_a_setting_that_says_so(self): + settings = { + "editorconfig": (".editorconfig", "[*]\nindent_style = space\n"), + "rustfmt": ("rustfmt.toml", "hard_tabs = false\n"), + "prettier": (".prettierrc.json", '{"useTabs": false}\n'), + "prettier in package.json": ("package.json", '{"prettier": {"useTabs": false}}\n'), + "biome": ("biome.jsonc", '{"formatter": {"indentStyle": "space"}}\n'), + "a nested editorconfig": ("src__.editorconfig", "indent_style = space\n"), + } + for label, (name, text) in settings.items(): + with self.subTest(label): + self.assertIsNone(space_indented(self.checkout(**{"app.py": SPACED, name: text}))) + + def test_reports_a_file_that_names_no_such_setting(self): + for name, text in ((".editorconfig", "[*]\nend_of_line = lf\n"), ("package.json", '{"name": "x"}\n'), ("notes.txt", "indent_style = space\n")): + with self.subTest(name): + self.assertIsInstance(space_indented(self.checkout(**{"app.py": SPACED, name: text})), SpaceIndented) + + def test_stays_silent_for_a_repo_without_code(self): + self.assertIsNone(space_indented(self.checkout(**{"README.md": SPACED, "data.json": SPACED, "ci.yml": SPACED}))) + + def test_leaves_out_vendored_code(self): + self.assertIsNone(space_indented(self.checkout(**{"vendor__lib.py": SPACED, "web__node_modules__x__index.js": SPACED}))) + + def test_stays_silent_where_tabs_are_as_many_as_spaces(self): + self.assertIsNone(space_indented(self.checkout(**{"a.py": SPACED, "b.py": TABBED}))) + + def test_says_why_it_cannot_read_a_checkout(self): + self.assertIsInstance(space_indented(pathlib.Path("/nonexistent-checkout")), Failure) + + +if __name__ == "__main__": + unittest.main() diff --git a/principles/technical-principles.md b/principles/technical-principles.md index bde9eb8c..aa8b2f4f 100644 --- a/principles/technical-principles.md +++ b/principles/technical-principles.md @@ -70,6 +70,7 @@ - Enumerate the cases that can go wrong and return them as explicit results (e.g. a result DTO with an optional error), so failure is part of the signature instead of a hidden second channel. - try/catch lives only at the edges, wrapped tightly around the call that can actually throw (DB, HTTP, filesystem), converting the exception into an explicit result right there. Pure functions and core logic never throw or catch for control flow. - A function that both returns a result and throws for some inputs has two error channels; collapse to one. Throw only for a truly unrecoverable state. + - Where code branches on why a call failed, it reads a status code, an exit code the tool documents, or a typed error. It reads message text only where the tool documents that text as unique to one cause, and treats every other failure as unknown, which stops the run rather than guessing. Older versions of a CLI often print one message for a missing image, a refused credential and a failed request. * Commands and Queries Separation (CQS)-ish - Queries must never modify data, commands may only return data that is the result of their change. * Copy important contextual information on buisness transactions and equal data, instead of referencing it. @@ -117,4 +118,4 @@ - A Python script with a `#!/usr/bin/env python3` shebang runs identically across systems where shell dialects and builtins differ. - Read config (credentials, hosts, paths) from CLI params or env vars, never hardcoded. * Indent with hard tabs by default. - - A project's own settings win: `.editorconfig`, linter/formatter config (Prettier, `rustfmt.toml`, …), or the surrounding file's existing indentation. + - Only a setting a tool reads overrides it: `.editorconfig` or a formatter's config (Prettier, `rustfmt.toml`, Biome, …), plus a decision in `docs/decisions.md` that names the reason. A prose rule in `AGENTS.md`, or the existing files' habit, doesn't. Output formats a spec fixes, such as a spelling's JSON, are outside the rule. `chunk-preflight` reports space-indented code that has no such setting. From e785ce8f6be474002a34b28da86fefc8fff06d77 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:16:10 +0100 Subject: [PATCH 03/45] Sort the new imports by first binding --- bin/chunk_preflight/facts.py | 2 +- bin/chunk_preflight/main.py | 2 +- bin/chunk_preflight/test_chunk_preflight.py | 2 +- bin/chunk_preflight/test_indentation.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/chunk_preflight/facts.py b/bin/chunk_preflight/facts.py index d7121a4e..38541271 100644 --- a/bin/chunk_preflight/facts.py +++ b/bin/chunk_preflight/facts.py @@ -5,10 +5,10 @@ from release_plan.next_chunk import cut_name, NextChunk, NoItem from release_plan.release_standing import dated_cut, LastCut, unreleased_entries, UNSEEN_RELEASES from failure import Failure from forge.commands import Forge -from chunk_preflight.indentation import SpaceIndented from chunk_preflight.gathered import Gathered, ItemFacts, NamedPath, Ran from text_files.markdown_text import listed, quoted from chunk_preflight.choices import PULLS_LIST +from chunk_preflight.indentation import SpaceIndented from plan.release import version diff --git a/bin/chunk_preflight/main.py b/bin/chunk_preflight/main.py index 30bc9ce5..a58f166a 100644 --- a/bin/chunk_preflight/main.py +++ b/bin/chunk_preflight/main.py @@ -98,7 +98,6 @@ from git_cli import epic_branch from failure import Failure from forge.commands import Forge, forge_of, Run, runner from chunk_preflight.gathered import Gathered, ItemFacts, LeftWorktree, NamedPath, Ran, Worktree -from chunk_preflight.indentation import space_indented from chunk_preflight.facts import JOINING_DETAILS, render from project_config.main import located from forge.pulls import merged_pull @@ -107,6 +106,7 @@ from release_plan.next_chunk import NextChunk, NoItem, plan_name, planned from release_plan.release_standing import project_plan from project_config.settings import ProjectConfig from chunk_preflight.choices import pulls_command, worktree_add, worktree_on, worktrees +from chunk_preflight.indentation import space_indented from project_config import templates BIN = pathlib.Path(__file__).resolve().parents[1] diff --git a/bin/chunk_preflight/test_chunk_preflight.py b/bin/chunk_preflight/test_chunk_preflight.py index 01ec521f..f23f23ac 100644 --- a/bin/chunk_preflight/test_chunk_preflight.py +++ b/bin/chunk_preflight/test_chunk_preflight.py @@ -22,8 +22,8 @@ from release_plan.release_standing import LastCut, UNSEEN_RELEASES from release_plan.awaiting_merge import marked from release_plan import next_chunk from chunk_preflight.facts import open_pulls, render -from chunk_preflight.indentation import SpaceIndented from plan_store.todo_md import plan_of +from chunk_preflight.indentation import SpaceIndented from chunk_preflight.choices import worktree_add, worktree_on, worktrees from project_config.doubles import write_config diff --git a/bin/chunk_preflight/test_indentation.py b/bin/chunk_preflight/test_indentation.py index 018db070..f2c5bba2 100644 --- a/bin/chunk_preflight/test_indentation.py +++ b/bin/chunk_preflight/test_indentation.py @@ -7,9 +7,9 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from chunk_preflight.indentation import space_indented, SpaceIndented from failure import Failure from test_env import isolated_env +from chunk_preflight.indentation import space_indented, SpaceIndented TABBED = "def run():\n\tif True:\n\t\treturn 1\n" SPACED = "def run():\n if True:\n return 1\n" From ccc5e8a830162312ad3234242efa407d06fce255 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:16:51 +0100 Subject: [PATCH 04/45] Narrow the old head's type in chunk-pr push --- bin/chunk_pr/main.py | 4 +++- docs/reading-cost.md | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index cd1909a8..3dce17fb 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -376,7 +376,9 @@ def pushed(run: Run, config: Config, sleep: typing.Callable[[float], None]) -> s return found forge, branch, head = found old = run(["git", "ls-remote", "origin", f"refs/heads/{branch}"]) - sent = old if isinstance(old, Failure) else run(["git", "push", "--quiet", "--set-upstream", "origin", branch]) + if isinstance(old, Failure): + return old + sent = run(["git", "push", "--quiet", "--set-upstream", "origin", branch]) number = sent if isinstance(sent, Failure) else shown_pull(forge, branch, head, old.split()[0] if old.strip() else "", run, sleep) if isinstance(number, Failure): return number diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 6dfa2b13..eb2266a4 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -3700,3 +3700,14 @@ Read most (opens and searches): - `bin/task_bench/feature_tasks.py` 1 - `bin/task_bench/tasks.py` 1 - `todo.md` 1 + +## Reading cost, chunk f344ce83433c, finished 2026-11-27T14:05:18Z + +108886 new input tokens before the first commit. + +Read most (opens and searches): + +- `README.md` 3 +- `bin/release_plan/release_standing.py` 3 +- `CHANGELOG.md` 1 +- `bin/deploy_release/cut.py` 1 From ae2c0a58eeb8aed30b74820631cf5fb4890a908e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:24:27 +0100 Subject: [PATCH 05/45] Test base_of and a failed ls-remote of chunk-pr push --- bin/chunk_pr/test_chunk_pr.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index 4132ad47..6eced099 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -12,7 +12,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from chunk_pr.approval import awaited -from chunk_pr.main import cleaned, merged, QUEUE, step, turn, USAGE +from chunk_pr.main import base_of, Base, cleaned, merged, QUEUE, step, turn, USAGE from failure import Failure from test_env import isolated_env from project_config.settings import ProjectConfig @@ -22,9 +22,9 @@ from forge.reviews import THREADS TOOL = pathlib.Path(__file__).resolve().parents[1] / "chunk-pr" GITHUB = "git@github.com:me/project.git" GITEA = "ssh://git@gitea.example.org:22/me/project.git" -HEAD = "c0ffee" +HEAD = "c0ffee" * 7 PUSH = ["git", "push", "--quiet", "--set-upstream", "origin", "item-7"] -OLD = "badc0de" +OLD = "badc0de" * 6 OLD_HEAD = ["git", "ls-remote", "origin", "refs/heads/item-7"] GH_LIST = ["gh", "pr", "list", "--head", "item-7", "--json", "number,headRefOid,isCrossRepository", "--template", "{{range .}}{{.number}}\t{{.headRefOid}}\t{{.isCrossRepository}}\n{{end}}"] TEA_LIST = ["tea", "api", "repos/{owner}/{repo}/pulls?state=open&limit=50"] @@ -1090,6 +1090,17 @@ class EpicBranch(unittest.TestCase): self.assertIn("awaits a person's merge", str(done)) self.assertFalse(any("merge" in command[1:4] for command in checkout.acted() if command[0] != "git"), checkout.acted()) + def test_a_branch_whose_base_git_does_not_record_merges_into_the_default_branch(self): + self.assertEqual(base_of("item-7", self.unrecorded), Base("main", False)) + self.assertEqual(base_of("item-7", self.recorded("main")), Base("main", False)) + self.assertEqual(base_of("item-7", self.recorded("ABC-1")), Base("ABC-1", True)) + + def unrecorded(self, command: list[str]) -> str | Failure: + return Failure("git config: exit 1") if command[:3] == ["git", "config", "--get"] else "origin/main\n" + + def recorded(self, base: str) -> Run: + return lambda command: f"{base}\n" if command[:3] == ["git", "config", "--get"] else "origin/main\n" + def test_merge_fails_naming_both_branches_where_the_forge_merges_the_pull_request_into_another_branch_than_the_checkout_records(self): for origin in (GITHUB, GITEA): with self.subTest(origin): @@ -1219,6 +1230,12 @@ class EpicBranch(unittest.TestCase): self.assertEqual(step(["push"], checkout, checkout.config, sleep=slept.append), "Pushed item-7.") self.assertEqual(slept, []) + def test_a_push_whose_old_head_cannot_be_read_pushes_nothing(self): + checkout = self.checkout() + checkout.answers[tuple(OLD_HEAD)] = Failure("git ls-remote: no network") + self.assertEqual(step(["push"], checkout, checkout.config), Failure("git ls-remote: no network")) + self.assertNotIn(PUSH, checkout.ran) + def test_a_failed_push_asks_for_no_review(self): checkout = self.checkout() checkout.answers[tuple(PUSH)] = Failure("git push: rejected") From 3b125bbcbdb90c90751891494f495c5d01be8a14 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:30:00 +0100 Subject: [PATCH 06/45] Sort the test's imports --- bin/chunk_pr/test_chunk_pr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index 6eced099..78449368 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -12,7 +12,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from chunk_pr.approval import awaited -from chunk_pr.main import base_of, Base, cleaned, merged, QUEUE, step, turn, USAGE +from chunk_pr.main import Base, base_of, cleaned, merged, QUEUE, step, turn, USAGE from failure import Failure from test_env import isolated_env from project_config.settings import ProjectConfig From 8ce06dd983a641f63e3f467b8c18ce3b59641713 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:31:04 +0100 Subject: [PATCH 07/45] Kill the surviving mutants of the indentation check --- bin/chunk_preflight/test_indentation.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bin/chunk_preflight/test_indentation.py b/bin/chunk_preflight/test_indentation.py index f2c5bba2..e6902346 100644 --- a/bin/chunk_preflight/test_indentation.py +++ b/bin/chunk_preflight/test_indentation.py @@ -45,6 +45,7 @@ class SpaceIndentation(unittest.TestCase): "prettier in package.json": ("package.json", '{"prettier": {"useTabs": false}}\n'), "biome": ("biome.jsonc", '{"formatter": {"indentStyle": "space"}}\n'), "a nested editorconfig": ("src__.editorconfig", "indent_style = space\n"), + "an editorconfig two folders down": ("src__web__.editorconfig", "indent_style = space\n"), } for label, (name, text) in settings.items(): with self.subTest(label): @@ -64,6 +65,26 @@ class SpaceIndentation(unittest.TestCase): def test_stays_silent_where_tabs_are_as_many_as_spaces(self): self.assertIsNone(space_indented(self.checkout(**{"a.py": SPACED, "b.py": TABBED}))) + def test_sums_the_tabbed_lines_of_every_file(self): + self.assertIsNone(space_indented(self.checkout(**{"a.py": SPACED, "b.py": SPACED, "c.py": TABBED, "d.py": TABBED, "e.py": TABBED}))) + + def test_skips_a_tracked_file_that_is_gone_from_the_disk(self): + root = self.checkout(**{"a.py": SPACED, "gone.py": SPACED}) + (root / "gone.py").unlink() + self.assertEqual(space_indented(root), SpaceIndented(spaced=2, tabbed=0)) + + def test_reads_a_file_that_is_not_utf8(self): + root = self.checkout(**{"a.py": ""}) + (root / "a.py").write_bytes(b"\xff\xfe\n x\n y\n") + self.assertEqual(space_indented(root), SpaceIndented(spaced=2, tabbed=0)) + + @unittest.skipIf(os.geteuid() == 0, "root reads any file") + def test_names_a_file_it_cannot_read(self): + root = self.checkout(**{"a.py": SPACED}) + (root / "a.py").chmod(0) + self.addCleanup((root / "a.py").chmod, 0o644) + self.assertEqual(space_indented(root), Failure(f"cannot read a.py: [Errno 13] Permission denied: '{root}/a.py'")) + def test_says_why_it_cannot_read_a_checkout(self): self.assertIsInstance(space_indented(pathlib.Path("/nonexistent-checkout")), Failure) From d107ae0bb7cc5a6ed3d9fa365651f147a20721f8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:31:52 +0100 Subject: [PATCH 08/45] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20the=20pass?= =?UTF-8?q?=20found=20nothing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 60ac3a8116fbf05340abc52194463f7b9b4a207d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:32:00 +0100 Subject: [PATCH 09/45] Run each claimed output from a fresh checkout's state, and check claims about what a command writes --- agents/product-owner-reviewer.md | 2 +- agents/prose-reviewer.md | 2 +- skills/larv-review/SKILL.md | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/agents/product-owner-reviewer.md b/agents/product-owner-reviewer.md index 5333a415..f8ae26dc 100644 --- a/agents/product-owner-reviewer.md +++ b/agents/product-owner-reviewer.md @@ -45,7 +45,7 @@ Before anything else, **read the technical principles** in the folder your promp 6. **Assess reasonableness of usage paths**: Are there paths that exist but no real persona would use? -7. **Check each claim about output against its run.** A changed doc line that says what a command, flag or error prints is true only if the real output says so. Where your prompt has a `Claimed output:` line, that file holds each such claim's command and real output. Report a claim the output doesn't bear out, such as an error said to name the fix that doesn't, and name the missing words. Never settle one by reading code. A claim marked `not run`, or one you find that the prompt doesn't hand you a run of, is a ❓ naming the command that would run it. +7. **Check each claim about output against its run.** A changed doc line that says what a command, flag or error prints, or what a command writes, is true only if the real output or the written file says so. Where your prompt has a `Claimed output:` line, that file holds each such claim's command and real output, or the file it wrote. Report a claim the output doesn't bear out, such as an error said to name the fix that doesn't, and name the missing words. Never settle one by reading code. A claim marked `not run`, or one you find that the prompt doesn't hand you a run of, is a ❓ naming the command that would run it. ## Your Output Format diff --git a/agents/prose-reviewer.md b/agents/prose-reviewer.md index 0da6bcb9..7bf689b2 100644 --- a/agents/prose-reviewer.md +++ b/agents/prose-reviewer.md @@ -30,7 +30,7 @@ Also report a list whose order carries no meaning and is not sorted (the technic Where your prompt hands you claims a fix rewrote, judge each claim afresh, not only the finding it answered. Look for a counter-example: one input or case where it is false. Then check it against every term of the source it names, such as each credit and notice a licence file lists. Report a claim you can't check as a ❓ naming what would check it. -Where your prompt has a `Claimed output:` line, that file holds the command and real output of each changed line that says what a command prints. Report a claim its output doesn't bear out, and name the missing words. A claim marked `not run` is a ❓ naming the command that would run it. +Where your prompt has a `Claimed output:` line, that file holds the command and real output of each changed line that says what a command prints or writes. Report a claim its output doesn't bear out, and name the missing words. A claim marked `not run` is a ❓ naming the command that would run it. ## Growth diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 4a0e4bff..73e75404 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -74,10 +74,11 @@ Give a reviewer without Bash `git ls-files`'s output in its prompt, since some h **Reports.** Run `~/.claude/bin/larv-review reviewer-header ` in the chunk's worktree, and open each prompt to an agent under `~/.claude/agents/` with what it prints; then say in a few lines what the change does and which files it touches. The command makes the chunk's review folder and writes the branch diff and the plan's listing into it. The header names that diff, the reviewer's full report, `-round-.md`, in the folder, the folders of technical principles and review standards the project's config sets, the files of coding conventions where it lists any, the listing, and for architecture and stability the places too. For a reviewer whose definition starts it without `CLAUDE.md`, the header's last line names the file that holds the project principles and decision titles, which the reviewer reads first. For a relaunch one rung up, add `--rerun`: the report becomes `-round--rerun.md`, and the header names the report that asked. Before you answer a 🔴 or 🟡, read its entry: Grep the report for the finding's place, with the lines after it, rather than Read the whole report. rule-hook refuses a reviewer's Edit and MultiEdit, and any Write outside `~/.local/state/larv-review/`. Keep the folder after the merge: `review-replay` replays a round from the reports its prompt names, and `compress-archives` gzips each file 30 days after it last changed. -**Claimed output.** Before the Product-owner or Prose pass launches in a round, find the lines the diff adds or changes that say what a command, flag or error prints, such as "the error names the fix". In round 2, take only the lines the round's fixes changed. Those reviewers have no shell, and reading code can't show that an output holds the words a line claims. +**Claimed output.** Before the Product-owner or Prose pass launches in a round, find the lines the diff adds or changes that say what a command, flag or error prints, such as "the error names the fix", or what it writes, such as "the diff of the regenerated file holds only X". In round 2, take only the lines the round's fixes changed. Those reviewers have no shell, and reading code can't show that an output holds the words a line claims. -- **Run.** Run each claim's command in the chunk's worktree, the way the project runs its tools (its container setup, unless its config sets `tooling-on-host`), with the input that triggers the output the line describes, such as the input that raises the error. Run only a command that leaves every file as it was, in the worktree and outside it, and sends no data out. List any other claim as `not run: `. -- **Hand over.** Write each claim into `claimed-output-round-.md` in the chunk's review folder, `` the round's number: its file and line, the command, the exit code and the real output, or `not run: `. Add `Claimed output: ` to the prompts of the Product-owner and Prose reviewers. With no claim, write no file and add no line. +- **Run.** Run each claim's command in a scratch copy of the chunk's worktree, made in the review folder from what `git ls-files --cached --others --exclude-standard` lists. The copy lacks the ignored build and cache files that earlier runs wrote, as a fresh checkout does, so a command that needs one fails here as it would for a reader. Run it the way the project runs its tools (its container setup, unless its config sets `tooling-on-host`), with the input that triggers the output the line describes, such as the input that raises the error. Remove the copy afterwards. +- **Writes.** Run a claim about what a command writes like one about what it prints, and check the written file against the claim, such as its diff against the worktree's copy of it. The command may write in the scratch copy only; run no command that changes another file, in the worktree or outside it, or that sends data out. List any other claim as `not run: `. +- **Hand over.** Write each claim into `claimed-output-round-.md` in the chunk's review folder, `` the round's number: its file and line, the command, the exit code and the real output, or the file it wrote, or `not run: `. Add `Claimed output: ` to the prompts of the Product-owner and Prose reviewers. With no claim, write no file and add no line. **Precedent, then ask** — for the full scan: From 6ca674ccb5485937d8c87d837043ffb7d315fb33 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:32:34 +0100 Subject: [PATCH 10/45] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20no=20findin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From c13f4cc154bf20ff9cfeb0b4e835e2d6b2ee947f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:39:03 +0100 Subject: [PATCH 11/45] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20wait=20for?= =?UTF-8?q?=20a=20pull=20request=20at=20another=20head,=20and=20only=20whe?= =?UTF-8?q?re=20a=20review=20is=20owed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_pr/main.py | 67 ++++++++++++++++++++--------------- bin/chunk_pr/test_chunk_pr.py | 27 +++++++------- bin/forge/pulls.py | 11 ++++-- bin/forge/test_forge.py | 10 +++++- 4 files changed, 69 insertions(+), 46 deletions(-) diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index 3dce17fb..b07eaf52 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -43,9 +43,9 @@ ready marks the pull request ready for review. On Gitea a draft is a pull req as the pull request's title first; where that fails, the pull request stays a draft. push pushes the branch, setting its upstream. Where its pull request is open and goes into an epic's working branch, it then asks for a review as ready does. Use it for each push - after ready there, and wait for that review as for any other. Where the pull request - was open at the branch's old head, it waits up to a minute for the forge to show the - new head on it, and fails, naming the pull request, where the forge never does. + after ready there, and wait for that review as for any other. Before it asks, it waits up + to a minute for the forge to show the pushed commit as the head of the branch's open + pull request, and fails, naming the pull request, where the forge never does. merge merges the pull request in its turn: the chunks of one project on this machine take turns, one at a time. Run it in the background. In its turn it: 1. fetches origin and merges its default branch into the branch, as sync does; @@ -122,7 +122,7 @@ import time import typing from chunk_pr.approval import approval, approved, awaited, left_to_a_person, left_to_park, PARKS, unanswered -from forge.pulls import checks_passed, merged_pull, open_pull, other_base, required_checks +from forge.pulls import checks_passed, merged_pull, open_pull, other_base, pull_from, required_checks from git_cli.git_repo import CHUNK_BASE, Git from git_cli import epic_branch from failure import Failure @@ -240,7 +240,7 @@ class Base: def base_of(branch: str, run: Run) -> Base | Failure: - """The Base of the pull request from branch: the epic's working branch the checkout records for it (`git_repo.record_chunk_base`), else origin's default branch. A recorded base that is origin's default branch is no epic's: the pull request merges into the default branch, where a person may have to merge it.""" + """The Base of the pull request from branch: the epic's working branch the checkout records for it (`git_repo.record_chunk_base`), else origin's default branch. A recorded base equal to origin's default branch isn't an epic's working branch: the pull request merges into the default branch, so `merge = "human"` and `wait-for-approval` apply to it.""" default = default_branch(run) if isinstance(default, Failure): return default @@ -375,36 +375,49 @@ def pushed(run: Run, config: Config, sleep: typing.Callable[[float], None]) -> s if isinstance(found, Failure): return found forge, branch, head = found - old = run(["git", "ls-remote", "origin", f"refs/heads/{branch}"]) - if isinstance(old, Failure): - return old sent = run(["git", "push", "--quiet", "--set-upstream", "origin", branch]) - number = sent if isinstance(sent, Failure) else shown_pull(forge, branch, head, old.split()[0] if old.strip() else "", run, sleep) - if isinstance(number, Failure): - return number - asked = review_asked(forge, number, run, config) if number is not None else None - if isinstance(asked, Failure): - return Failure(f"pushed {branch}, but could not ask for a review: {asked.reason}") - return f"Pushed {branch}, and asked for a review of pull request #{number} with “{asked}”." if asked else f"Pushed {branch}." + if isinstance(sent, Failure): + return sent + comment = review_comment(run, config) + number = None if comment is None or isinstance(comment, Failure) else shown_pull(forge, branch, head, run, sleep) + if isinstance(comment, Failure): + return Failure(f"pushed {branch}, but could not ask for a review: {comment.reason}") + if isinstance(number, Failure) or number is None or comment is None: + return number if isinstance(number, Failure) else f"Pushed {branch}." + made = comment_on(forge, number, comment, run) + return Failure(f"pushed {branch}, but could not ask for a review: {made.reason}") if isinstance(made, Failure) else f"Pushed {branch}, and asked for a review of pull request #{number} with “{comment}”." -def shown_pull(forge: Forge, branch: str, head: str, old: str, run: Run, sleep: typing.Callable[[float], None]) -> str | None | Failure: - """The number of branch's open pull request at head, just pushed over old, the head origin had before. The forge may keep showing old for up to PUSH_SECONDS, so while it does, this polls; a Failure naming the pull request where it still does. None where no pull request is open at head or at old: `push` before `open` is normal.""" - stale = None +def shown_pull(forge: Forge, branch: str, head: str, run: Run, sleep: typing.Callable[[float], None]) -> str | None | Failure: + """The number of branch's open pull request at head, just pushed. Right after a push the forge may still list the pull request at an older head, so this polls up to PUSH_SECONDS while it lists one at another head, and then fails naming it. None where no pull request from branch is open: `push` before `open` is normal.""" + other = None for waited in range(0, PUSH_SECONDS + 1, PUSH_POLL_SECONDS): number = open_pull(forge, branch, head, run) - if number is not None or not old or old == head: + if number is not None: return number - stale = open_pull(forge, branch, old, run) - if not isinstance(stale, str): - return stale + other = pull_from(forge, branch, run) + if not isinstance(other, str): + return other if waited < PUSH_SECONDS: sleep(PUSH_POLL_SECONDS) - return Failure(f"pushed {branch}, but the forge still shows pull request #{stale} at {old[:12]}, not at {head[:12]}, after {PUSH_SECONDS} seconds, so no review was asked for; run chunk-pr push again") + return Failure(f"pushed {branch}, but pull request #{other} still doesn't show {head[:12]} as its head after {PUSH_SECONDS} seconds, so no review was asked for; once it does, run chunk-pr push again") def review_asked(forge: Forge, number: str, run: Run, config: Config) -> str | None | Failure: - """Comment on the pull request numbered number with the config's `review-request-comment`, where the pull request goes into an epic's working branch: a forge's auto-reviewer may review only pull requests into the default branch unless asked. The comment made; None where the config names none or the pull request goes into the default branch.""" + """Comment on the pull request numbered number as `review_comment` says. The comment made; None where it says none.""" + comment = review_comment(run, config) + if comment is None or isinstance(comment, Failure): + return comment + made = comment_on(forge, number, comment, run) + return made if isinstance(made, Failure) else comment + + +def comment_on(forge: Forge, number: str, comment: str, run: Run) -> str | Failure: + return run(["gh", "pr", "comment", number, "--body", comment] if forge == "gh" else ["tea", "comment", number, comment]) + + +def review_comment(run: Run, config: Config) -> str | None | Failure: + """The config's `review-request-comment` that a pull request from the branch checked out is owed, where it goes into an epic's working branch: a forge's auto-reviewer may review only pull requests into the default branch unless asked. None where the config names none or the pull request goes into the default branch.""" branch = answers(run, ["symbolic-ref", "--short", "HEAD"]) base = branch if isinstance(branch, Failure) else base_of(branch[0], run) if isinstance(base, Failure): @@ -412,11 +425,7 @@ def review_asked(forge: Forge, number: str, run: Run, config: Config) -> str | N if not base.to_epic: return None loaded = config() - if isinstance(loaded, Failure) or loaded.review_request_comment is None: - return loaded if isinstance(loaded, Failure) else None - comment = loaded.review_request_comment - made = run(["gh", "pr", "comment", number, "--body", comment] if forge == "gh" else ["tea", "comment", number, comment]) - return made if isinstance(made, Failure) else comment + return loaded if isinstance(loaded, Failure) else loaded.review_request_comment def epic_opened(epic: str, title: str, body: str, run: Run, config: Config) -> str | Failure: diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index 78449368..b351b853 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -25,7 +25,6 @@ GITEA = "ssh://git@gitea.example.org:22/me/project.git" HEAD = "c0ffee" * 7 PUSH = ["git", "push", "--quiet", "--set-upstream", "origin", "item-7"] OLD = "badc0de" * 6 -OLD_HEAD = ["git", "ls-remote", "origin", "refs/heads/item-7"] GH_LIST = ["gh", "pr", "list", "--head", "item-7", "--json", "number,headRefOid,isCrossRepository", "--template", "{{range .}}{{.number}}\t{{.headRefOid}}\t{{.isCrossRepository}}\n{{end}}"] TEA_LIST = ["tea", "api", "repos/{owner}/{repo}/pulls?state=open&limit=50"] GH_SETTINGS = ["gh", "repo", "view", "--json", "mergeCommitAllowed,rebaseMergeAllowed,squashMergeAllowed"] @@ -127,7 +126,7 @@ class Checkout: def acted(self) -> list[list[str]]: """What it ran beyond reading the checkout, the pull requests and the repository's settings.""" - reads = [OLD_HEAD, GH_LIST, GH_DECISION, GH_BASE, TEA_LIST, TEA_PULL, GH_SETTINGS, TEA_SETTINGS, OWED, GH_CHECKS, TEA_BRANCH, TEA_STATUS, GH_THREADS] + reads = [GH_LIST, GH_DECISION, GH_BASE, TEA_LIST, TEA_PULL, GH_SETTINGS, TEA_SETTINGS, OWED, GH_CHECKS, TEA_BRANCH, TEA_STATUS, GH_THREADS] return [command for command in self.ran if tuple(command) not in self.answers and command not in reads] @@ -1092,6 +1091,8 @@ class EpicBranch(unittest.TestCase): def test_a_branch_whose_base_git_does_not_record_merges_into_the_default_branch(self): self.assertEqual(base_of("item-7", self.unrecorded), Base("main", False)) + + def test_a_recorded_base_is_an_epics_working_branch_unless_it_is_the_default_branch(self): self.assertEqual(base_of("item-7", self.recorded("main")), Base("main", False)) self.assertEqual(base_of("item-7", self.recorded("ABC-1")), Base("ABC-1", True)) @@ -1210,31 +1211,31 @@ class EpicBranch(unittest.TestCase): def test_push_waits_for_the_forge_to_show_the_new_head_before_it_asks_for_a_review(self): checkout, slept = self.checkout(), [] - checkout.answers[tuple(OLD_HEAD)] = f"{OLD}\trefs/heads/item-7\n" checkout.listed_heads = [OLD, OLD, OLD, OLD, HEAD] self.assertEqual(step(["push"], checkout, checkout.config, sleep=slept.append), "Pushed item-7, and asked for a review of pull request #12 with “@reviewer review”.") self.assertEqual(slept, [5, 5]) def test_push_fails_naming_the_pull_request_where_the_forge_never_shows_the_new_head(self): checkout, slept = self.checkout(), [] - checkout.answers[tuple(OLD_HEAD)] = f"{OLD}\trefs/heads/item-7\n" checkout.listed_heads = [OLD] done = step(["push"], checkout, checkout.config, sleep=slept.append) - self.assertEqual(done, Failure(f"pushed item-7, but the forge still shows pull request #12 at {OLD[:12]}, not at {HEAD[:12]}, after 60 seconds, so no review was asked for; run chunk-pr push again")) + self.assertIsInstance(done, Failure) + for fact in ("pushed item-7", "pull request #12", HEAD[:12], "60 seconds"): + self.assertIn(fact, done.reason) self.assertEqual(sum(slept), 60) self.assertNotIn(self.COMMENT_GH, checkout.ran) - def test_push_waits_for_no_pull_request_that_was_not_open_at_the_old_head(self): - checkout, slept = self.checkout(open=False), [] - checkout.answers[tuple(OLD_HEAD)] = f"{OLD}\trefs/heads/item-7\n" + def test_push_does_not_wait_where_the_pull_request_goes_into_the_default_branch(self): + checkout, slept = self.checkout(), [] + checkout.chunk_base = "" + checkout.listed_heads = [OLD] self.assertEqual(step(["push"], checkout, checkout.config, sleep=slept.append), "Pushed item-7.") self.assertEqual(slept, []) - def test_a_push_whose_old_head_cannot_be_read_pushes_nothing(self): - checkout = self.checkout() - checkout.answers[tuple(OLD_HEAD)] = Failure("git ls-remote: no network") - self.assertEqual(step(["push"], checkout, checkout.config), Failure("git ls-remote: no network")) - self.assertNotIn(PUSH, checkout.ran) + def test_push_does_not_wait_where_no_pull_request_is_open(self): + checkout, slept = self.checkout(open=False), [] + self.assertEqual(step(["push"], checkout, checkout.config, sleep=slept.append), "Pushed item-7.") + self.assertEqual(slept, []) def test_a_failed_push_asks_for_no_review(self): checkout = self.checkout() diff --git a/bin/forge/pulls.py b/bin/forge/pulls.py index d93479bc..151dbec1 100644 --- a/bin/forge/pulls.py +++ b/bin/forge/pulls.py @@ -22,26 +22,31 @@ def open_pull(forge: Forge, branch: str, head: str, run: Run) -> str | None | Fa return pull_at(forge, branch, head, "open", run) +def pull_from(forge: Forge, branch: str, run: Run) -> str | None | Failure: + """The number of the open pull request from origin's own branch, whatever its head is; None where there is none.""" + return pull_at(forge, branch, None, "open", run) + + def merged_pull(forge: Forge, branch: str, head: str, run: Run) -> str | None | Failure: """The number of the merged pull request from origin's own branch whose head was head; None where there is none. A rebase or a squash merge counts: the pull request keeps the head it had.""" return pull_at(forge, branch, head, "merged", run) -def pull_at(forge: Forge, branch: str, head: str, state: typing.Literal["open", "merged"], run: Run) -> str | None | Failure: +def pull_at(forge: Forge, branch: str, head: str | None, state: typing.Literal["open", "merged"], run: Run) -> str | None | Failure: if forge == "gh": # gh lists the open pull requests unless told another state. listed = run(["gh", "pr", "list", "--head", branch, *(["--state", "merged"] if state == "merged" else []), "--json", "number,headRefOid,isCrossRepository", "--template", "{{range .}}{{.number}}\t{{.headRefOid}}\t{{.isCrossRepository}}\n{{end}}"]) if isinstance(listed, Failure): return listed rows = [line.split("\t") for line in listed.splitlines()] - return next((row[0] for row in rows if row[1:] == [head, "false"]), None) + return next((row[0] for row in rows if row[1:] == ([head, "false"] if head is not None else row[1:2] + ["false"])), None) # Gitea lists at most 50 a page; the pull request sought is among the newest. Gitea has no merged state: a merged pull request is a closed one marked merged. pulls = gitea(run, f"repos/{{owner}}/{{repo}}/pulls?state={'open' if state == 'open' else 'closed'}&limit=50") if isinstance(pulls, Failure): return pulls try: # Match the label, not the ref: once origin deletes a merged branch, Gitea reports its ref as refs/pull//head. - return next((str(pull["number"]) for pull in pulls if pull["head"]["label"] == branch and pull["head"]["sha"] == head and pull["head"]["repo"]["full_name"] == pull["base"]["repo"]["full_name"] and (state == "open" or pull["merged"] is True)), None) + return next((str(pull["number"]) for pull in pulls if pull["head"]["label"] == branch and (head is None or pull["head"]["sha"] == head) and pull["head"]["repo"]["full_name"] == pull["base"]["repo"]["full_name"] and (state == "open" or pull["merged"] is True)), None) except (KeyError, TypeError): return Failure(f"tea api listed pull requests in a shape that can't be read: {str(pulls)[:200]}") diff --git a/bin/forge/test_forge.py b/bin/forge/test_forge.py index e59fffc0..5915a79a 100644 --- a/bin/forge/test_forge.py +++ b/bin/forge/test_forge.py @@ -9,7 +9,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from forge.pulls import BEHIND, CheckFailed, checks_now, checks_passed, CONFLICTS, open_pull, other_base, Pending, POLL_SECONDS, ready_pulls, ReadyPull, required_checks, unmergeable, WAIT_SECONDS +from forge.pulls import BEHIND, CheckFailed, checks_now, checks_passed, CONFLICTS, open_pull, other_base, Pending, POLL_SECONDS, pull_from, ready_pulls, ReadyPull, required_checks, unmergeable, WAIT_SECONDS from failure import Failure from forge.commands import forge_of, gitea, runner, url_beside @@ -46,6 +46,14 @@ class Gitea(unittest.TestCase): class OpenPull(unittest.TestCase): + def test_finds_the_open_pull_request_from_a_branch_whatever_its_head_is(self): + gh = "12\told\tfalse\n13\tfork\ttrue\n" + tea = json.dumps([{"number": 14, "head": {"label": "item-3", "sha": "old", "repo": {"full_name": "o/r"}}, "base": {"repo": {"full_name": "o/r"}}}, {"number": 15, "head": {"label": "item-3", "sha": "fork", "repo": {"full_name": "f/r"}}, "base": {"repo": {"full_name": "o/r"}}}]) + self.assertEqual(pull_from("gh", "item-3", lambda command: gh), "12") + self.assertEqual(pull_from("tea", "item-3", lambda command: tea), "14") + self.assertEqual(open_pull("gh", "item-3", "new", lambda command: gh), None) + self.assertIsNone(pull_from("gh", "item-3", lambda command: "13\tfork\ttrue\n")) + def test_fails_quoting_the_first_200_characters_where_tea_lists_pull_requests_in_another_shape(self): self.assertEqual(open_pull("tea", "item-3", "abc", lambda command: LONG).reason, f"tea api listed pull requests in a shape that can't be read: {LONG[:200]}") From d94b5c522681d2d7272240f38f36c68d06ff9afe Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:39:03 +0100 Subject: [PATCH 12/45] =?UTF-8?q?Answer=20product-owner=20round=201:=201?= =?UTF-8?q?=20=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20fixed=20?= =?UTF-8?q?with=20stability's:=20a=20rerun=20finds=20the=20pull=20request?= =?UTF-8?q?=20at=20another=20head=20and=20fails?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From e2c29e1b392c4fa30f2046fc8eff81af26bcc5d7 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:39:03 +0100 Subject: [PATCH 13/45] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(0=20misread);=20fixed=20wit?= =?UTF-8?q?h=20stability's:=20the=20base=5Fof=20docstring,=20the=20help=20?= =?UTF-8?q?text,=20the=20failure=20text,=20the=20test=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 7ea4b415d4b8600388b99a673d103f03ae1775ed Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:39:52 +0100 Subject: [PATCH 14/45] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20run=20claim?= =?UTF-8?q?s=20in=20a=20fresh=20clone,=20as=20a=20fresh=20checkout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agents/product-owner-reviewer.md | 2 +- skills/larv-review/SKILL.md | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/agents/product-owner-reviewer.md b/agents/product-owner-reviewer.md index f8ae26dc..ff2455ab 100644 --- a/agents/product-owner-reviewer.md +++ b/agents/product-owner-reviewer.md @@ -45,7 +45,7 @@ Before anything else, **read the technical principles** in the folder your promp 6. **Assess reasonableness of usage paths**: Are there paths that exist but no real persona would use? -7. **Check each claim about output against its run.** A changed doc line that says what a command, flag or error prints, or what a command writes, is true only if the real output or the written file says so. Where your prompt has a `Claimed output:` line, that file holds each such claim's command and real output, or the file it wrote. Report a claim the output doesn't bear out, such as an error said to name the fix that doesn't, and name the missing words. Never settle one by reading code. A claim marked `not run`, or one you find that the prompt doesn't hand you a run of, is a ❓ naming the command that would run it. +7. **Check each claim about output against its run.** A changed doc line that says what a command, flag or error prints, or what a command writes, is true only if the real output or the written file says so. Where your prompt has a `Claimed output:` line, that file holds each such claim's command and real output, or the lines it wrote. Report a claim the output or the written lines don't bear out, such as an error said to name the fix that doesn't, and name the missing words. Never settle one by reading code. A claim marked `not run`, or one you find that the prompt doesn't hand you a run of, is a ❓ naming the command that would run it. ## Your Output Format diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 73e75404..33a64fd9 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -74,11 +74,12 @@ Give a reviewer without Bash `git ls-files`'s output in its prompt, since some h **Reports.** Run `~/.claude/bin/larv-review reviewer-header ` in the chunk's worktree, and open each prompt to an agent under `~/.claude/agents/` with what it prints; then say in a few lines what the change does and which files it touches. The command makes the chunk's review folder and writes the branch diff and the plan's listing into it. The header names that diff, the reviewer's full report, `-round-.md`, in the folder, the folders of technical principles and review standards the project's config sets, the files of coding conventions where it lists any, the listing, and for architecture and stability the places too. For a reviewer whose definition starts it without `CLAUDE.md`, the header's last line names the file that holds the project principles and decision titles, which the reviewer reads first. For a relaunch one rung up, add `--rerun`: the report becomes `-round--rerun.md`, and the header names the report that asked. Before you answer a 🔴 or 🟡, read its entry: Grep the report for the finding's place, with the lines after it, rather than Read the whole report. rule-hook refuses a reviewer's Edit and MultiEdit, and any Write outside `~/.local/state/larv-review/`. Keep the folder after the merge: `review-replay` replays a round from the reports its prompt names, and `compress-archives` gzips each file 30 days after it last changed. -**Claimed output.** Before the Product-owner or Prose pass launches in a round, find the lines the diff adds or changes that say what a command, flag or error prints, such as "the error names the fix", or what it writes, such as "the diff of the regenerated file holds only X". In round 2, take only the lines the round's fixes changed. Those reviewers have no shell, and reading code can't show that an output holds the words a line claims. +**Claimed output.** Before the Product-owner or Prose pass launches in a round, find the lines the diff adds or changes that say what a command, flag or error prints, such as "the error names the fix", or what a command writes, such as "the diff of the regenerated file holds only X". In round 2, take only the lines the round's fixes changed. Those reviewers have no shell, and reading code can't show that an output holds the words a line claims. -- **Run.** Run each claim's command in a scratch copy of the chunk's worktree, made in the review folder from what `git ls-files --cached --others --exclude-standard` lists. The copy lacks the ignored build and cache files that earlier runs wrote, as a fresh checkout does, so a command that needs one fails here as it would for a reader. Run it the way the project runs its tools (its container setup, unless its config sets `tooling-on-host`), with the input that triggers the output the line describes, such as the input that raises the error. Remove the copy afterwards. -- **Writes.** Run a claim about what a command writes like one about what it prints, and check the written file against the claim, such as its diff against the worktree's copy of it. The command may write in the scratch copy only; run no command that changes another file, in the worktree or outside it, or that sends data out. List any other claim as `not run: `. -- **Hand over.** Write each claim into `claimed-output-round-.md` in the chunk's review folder, `` the round's number: its file and line, the command, the exit code and the real output, or the file it wrote, or `not run: `. Add `Claimed output: ` to the prompts of the Product-owner and Prose reviewers. With no claim, write no file and add no line. +- **Run.** Run each claim's command in a fresh clone of the chunk's worktree at its head, with every change committed: `git clone `, the folder in the chunk's review folder. The clone lacks the ignored build and cache files that earlier runs wrote, so a command that needs one fails there, as it does in a fresh checkout. Run the command the way the project runs its tools (its container setup, unless its config sets `tooling-on-host`), with the input that triggers the output the line describes, such as the input that raises the error. +- **Limits.** A command may change files in the clone only. Run none that changes a file elsewhere, or sends data out; list such a claim as `not run: `. +- **Writes.** Run a claim about what a command writes like one about what it prints, and compare the file it writes with the claim, such as `git diff` in the clone against the claim about the diff. Hand over the file's relevant lines or the diff. +- **Hand over.** Write each claim into `claimed-output-round-.md` in the chunk's review folder, `` the round's number: its file and line, the command, the exit code and the real output (for a claim about what a command writes, the written lines or the diff), or `not run: `. Add `Claimed output: ` to the prompts of the Product-owner and Prose reviewers. With no claim, write no file and add no line. Then remove the clone. **Precedent, then ask** — for the full scan: From d24782eb8d036dd0d67754884442a9cdc278cf32 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:39:52 +0100 Subject: [PATCH 15/45] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20clone=20fix?= =?UTF-8?q?=20above=20answers=20all=20three,=20=F0=9F=9F=A2s=20taken=20in?= =?UTF-8?q?=20the=20same=20rewrite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 49d93e8dab6c6285d06ec68728a0fbcd01899680 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:40:35 +0100 Subject: [PATCH 16/45] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20approved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 4a4a8526af4b0ad64899035c668b0009926c4954 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:46:58 +0100 Subject: [PATCH 17/45] Finish item 549 in the plan --- CHANGELOG.md | 1 + todo.md | 15 --------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 866e82e2..a374e59a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- larv-review's claimed-output step runs each claim in a fresh clone, without the ignored files earlier runs wrote, and checks claims about what a command writes. - stability-reviewer now flags a regex that validates a whole input with `$`, which also matches before a final newline. - stability-reviewer checks that a guard on whether a file, row or record exists looks at every place the thing passes through. - stability-reviewer checks that a validation rule holds for the value the code uses after it trims, strips or converts the input. diff --git a/todo.md b/todo.md index afb9d9ae..86b5356a 100644 --- a/todo.md +++ b/todo.md @@ -19,7 +19,6 @@ | 542 | 0.17.0 | | | **Make chunk-preflight report a project whose code is space-indented with no `.editorconfig` or formatter setting that says so, and narrow the tabs principle to explicit overrides.** | 2 | 2 | 3 | 5 | 4 | 1.1 by 4 | 1.2 | | 523 | 0.17.0 | | | **Make the security pass and stability-reviewer check that a new secret's docs name its scope and its reach, such as the other repositories its account can use.** | 1 | 1 | 2 | 2 | 1 | 1.1 by 2 | 0.9 | | 547 | 0.17.0 | | | **Add a technical principle: tell a failure's cause from a status code or a typed error, never from a tool's message text unless the tool documents that text as unique to the cause.** | 1 | 2 | 2 | 3 | 1 | 1.1 by 2 | 0.9 | -| 549 | 0.17.0 | | | **Run each claimed output from the state a fresh checkout leaves, without the ignored files earlier runs wrote, and check each claim about what a command writes.** | 1 | 1 | 2 | 2 | 1 | 1.1 by 2 | 0.9 | | 541 | 0.17.0 | | | **Find a Gitea pull request by its branch and head however many pull requests are newer, so `chunk-pr clean`, `chunk-pr merge` and `chunk-preflight` see an older one.** | 2 | 2 | 3 | 5 | 2 | 1 by 2 | 0.8 | | 545 | 0.17.0 | | | **Have chunk-preflight name each next-release item with no `Touches:` list while others wait, and have loop-claude launch a subagent that writes the lists before it starts the next chunk.** | 3 | 2 | 3 | 6 | 6 | 1.1 by 4 | 0.6 | | 539 | 0.17.0 | | | **Leave out of a `task-bench` fix a change Haiku makes to a Rust test kept in a file of its own.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 1 | 0.4 | @@ -177,20 +176,6 @@ Touches: - `principles/technical-principles.md`: `Handle errors explicitly, as values — avoid the exception path.` (small) -### 549. Run each claimed output from the state a fresh checkout leaves, without the ignored files earlier runs wrote, and check each claim about what a command writes. - -Found when an outside reviewer raised two findings that our review had missed: - -- A documented local command failed on a fresh checkout. It needed a cache file that earlier writable runs had left in an ignored folder. The implementer's claimed-output runs reused that file, so the claimed-output step showed the command working. -- A README sentence said what a regenerated file's diff holds. The claim was about the file the command writes, not what it prints, so the step never ran it, and the sentence was wrong. - -Change `larv-review` §3 → "Claimed output" so that: -- each claim runs from a state like a fresh checkout's, with the ignored build and cache files that earlier runs wrote moved aside; -- a claim about what a command writes, such as a file or a diff, is run like a claim about what it prints. - -Touches: -- `skills/larv-review/SKILL.md`: `**Claimed output.**` (small) - ### 541. Find a Gitea pull request by its branch and head however many pull requests are newer, so `chunk-pr clean`, `chunk-pr merge` and `chunk-preflight` see an older one. Today `pull_at` in `bin/forge/pulls.py` reads only Gitea's first page of 50 pull requests, open or closed, and looks for the branch among them. A pull request with 50 newer ones in that state is missed. PR #652 here merged after 50+ newer PRs had closed, and `chunk-pr clean` then said "no merged pull request from filing-prose-reentry", leaving the worktree and branch to remove by hand. The same lookup serves `open_pull`, so `ready` and `merge` miss an old open one too, and `chunk-preflight` misses a merged chunk's worktree. From 75b36ed34cde29e954c04695f28dfa64c8d80982 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:48:45 +0100 Subject: [PATCH 18/45] =?UTF-8?q?Answer=20prose=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20the=20shown?= =?UTF-8?q?=5Fpull=20docstring,=20the=20help's=20last=20clause,=20the=20re?= =?UTF-8?q?view=5Fcomment=20docstring=20and=20a=20test=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_pr/main.py | 6 +++--- bin/chunk_pr/test_chunk_pr.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index b07eaf52..569471a0 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -45,7 +45,7 @@ push pushes the branch, setting its upstream. Where its pull request is open epic's working branch, it then asks for a review as ready does. Use it for each push after ready there, and wait for that review as for any other. Before it asks, it waits up to a minute for the forge to show the pushed commit as the head of the branch's open - pull request, and fails, naming the pull request, where the forge never does. + pull request, and fails, naming the pull request, where the forge still doesn't after that. merge merges the pull request in its turn: the chunks of one project on this machine take turns, one at a time. Run it in the background. In its turn it: 1. fetches origin and merges its default branch into the branch, as sync does; @@ -389,7 +389,7 @@ def pushed(run: Run, config: Config, sleep: typing.Callable[[float], None]) -> s def shown_pull(forge: Forge, branch: str, head: str, run: Run, sleep: typing.Callable[[float], None]) -> str | None | Failure: - """The number of branch's open pull request at head, just pushed. Right after a push the forge may still list the pull request at an older head, so this polls up to PUSH_SECONDS while it lists one at another head, and then fails naming it. None where no pull request from branch is open: `push` before `open` is normal.""" + """The number of branch's open pull request at head, just pushed. Right after a push the forge may still list that pull request at an older head. While it does, this polls for up to PUSH_SECONDS, then returns a Failure naming the pull request. None where no pull request from branch is open: `push` before `open` is normal.""" other = None for waited in range(0, PUSH_SECONDS + 1, PUSH_POLL_SECONDS): number = open_pull(forge, branch, head, run) @@ -417,7 +417,7 @@ def comment_on(forge: Forge, number: str, comment: str, run: Run) -> str | Failu def review_comment(run: Run, config: Config) -> str | None | Failure: - """The config's `review-request-comment` that a pull request from the branch checked out is owed, where it goes into an epic's working branch: a forge's auto-reviewer may review only pull requests into the default branch unless asked. None where the config names none or the pull request goes into the default branch.""" + """The config's `review-request-comment`, where the pull request from the branch checked out goes into an epic's working branch: a forge's auto-reviewer may review only pull requests into the default branch unless asked. None where the config names none or the pull request goes into the default branch.""" branch = answers(run, ["symbolic-ref", "--short", "HEAD"]) base = branch if isinstance(branch, Failure) else base_of(branch[0], run) if isinstance(base, Failure): diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index b351b853..4bac9b5b 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -1215,7 +1215,7 @@ class EpicBranch(unittest.TestCase): self.assertEqual(step(["push"], checkout, checkout.config, sleep=slept.append), "Pushed item-7, and asked for a review of pull request #12 with “@reviewer review”.") self.assertEqual(slept, [5, 5]) - def test_push_fails_naming_the_pull_request_where_the_forge_never_shows_the_new_head(self): + def test_push_fails_naming_the_pull_request_where_the_forge_still_shows_the_old_head_after_a_minute(self): checkout, slept = self.checkout(), [] checkout.listed_heads = [OLD] done = step(["push"], checkout, checkout.config, sleep=slept.append) From a52ac1f78a2666f9a09febade716e3ff7aa28e27 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:48:45 +0100 Subject: [PATCH 19/45] =?UTF-8?q?Answer=20product-owner=20round=202:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20approved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From bbaa56d0eca207352b77151247c25100da9a934a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:51:44 +0100 Subject: [PATCH 20/45] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20skip=20vend?= =?UTF-8?q?ored=20settings=20files,=20test=20the=20worktree=20read,=20use?= =?UTF-8?q?=20assert=5Fnot=5Froot,=20read=20a=20file=20name=20that=20is=20?= =?UTF-8?q?not=20UTF-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_preflight/indentation.py | 8 +++++--- bin/chunk_preflight/test_chunk_preflight.py | 9 +++++++++ bin/chunk_preflight/test_indentation.py | 18 ++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/bin/chunk_preflight/indentation.py b/bin/chunk_preflight/indentation.py index 4a73e4c0..86ac098b 100644 --- a/bin/chunk_preflight/indentation.py +++ b/bin/chunk_preflight/indentation.py @@ -34,12 +34,14 @@ class SpaceIndented: def space_indented(base: pathlib.Path, timeout: float | None = None) -> SpaceIndented | Failure | None: """The line counts of the tracked code under base where it has more space-indented lines than tab-indented ones and no tracked file sets the indent; None where it doesn't, or has no code; a Failure where a file cannot be read.""" - tracked = git("ls-files", "-z", cwd=str(base), timeout=timeout) + tracked = git("ls-files", "-z", cwd=str(base), timeout=timeout, errors="replace") if isinstance(tracked, Failure): return tracked spaced = tabbed = 0 for name in filter(None, tracked.split("\0")): - code = CODE.fullmatch(name) and not VENDORED.search(name) + if VENDORED.search(name): + continue + code = CODE.fullmatch(name) key = next((key for pattern, key in SETTINGS if pattern.fullmatch(name.rsplit("/", 1)[-1])), None) path = base / name if not (code or key) or not os.path.isfile(path): @@ -47,7 +49,7 @@ def space_indented(base: pathlib.Path, timeout: float | None = None) -> SpaceInd try: text = path.read_text(encoding="utf-8", errors="replace") except OSError as failure: - return Failure(f"cannot read {name}: {failure}") + return Failure(f"{name}: {failure}") if key and key in text: return None if code: diff --git a/bin/chunk_preflight/test_chunk_preflight.py b/bin/chunk_preflight/test_chunk_preflight.py index f23f23ac..2afb7443 100644 --- a/bin/chunk_preflight/test_chunk_preflight.py +++ b/bin/chunk_preflight/test_chunk_preflight.py @@ -830,6 +830,15 @@ class IndentationFact(unittest.TestCase): spaced.commit(spaced.root, "setting") self.assertNotIn("space-indented", spaced.preflight().stdout) + def test_reads_the_item_worktree_made_off_origins_default_branch_not_the_checkout(self): + repo = Repo(self) + repo.write(repo.root, "src/app.py", "def run():\n if True:\n return 1\n") + repo.commit(repo.root, "spaces, not pushed") + self.assertIn("space-indented", repo.preflight().stdout) + done = repo.preflight("--worktree") + self.assertEqual(done.returncode, 0, done.stderr) + self.assertNotIn("space-indented", done.stdout, "the worktree holds origin/main, whose code is indented with tabs") + class BesideTest(unittest.TestCase): """The fact that names the items that may start chunks beside the next one.""" diff --git a/bin/chunk_preflight/test_indentation.py b/bin/chunk_preflight/test_indentation.py index e6902346..9b8e1015 100644 --- a/bin/chunk_preflight/test_indentation.py +++ b/bin/chunk_preflight/test_indentation.py @@ -8,7 +8,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from failure import Failure -from test_env import isolated_env +from test_env import assert_not_root, isolated_env from chunk_preflight.indentation import space_indented, SpaceIndented TABBED = "def run():\n\tif True:\n\t\treturn 1\n" @@ -59,8 +59,16 @@ class SpaceIndentation(unittest.TestCase): def test_stays_silent_for_a_repo_without_code(self): self.assertIsNone(space_indented(self.checkout(**{"README.md": SPACED, "data.json": SPACED, "ci.yml": SPACED}))) - def test_leaves_out_vendored_code(self): + def test_leaves_out_vendored_code_and_the_settings_files_it_holds(self): self.assertIsNone(space_indented(self.checkout(**{"vendor__lib.py": SPACED, "web__node_modules__x__index.js": SPACED}))) + vendored = self.checkout(**{"a.py": SPACED, "vendor__lib__.editorconfig": "indent_style = space\n", "third_party__x__package.json": '{"useTabs": false}'}) + self.assertEqual(space_indented(vendored), SpaceIndented(spaced=2, tabbed=0)) + + def test_reads_a_checkout_with_a_file_name_that_is_not_utf8(self): + root = self.checkout(**{"a.py": SPACED}) + (root / os.fsdecode(b"caf\xe9.py")).write_text(SPACED) + subprocess.run(["git", "add", "-A"], cwd=root, check=True, env=isolated_env()) + self.assertEqual(space_indented(root), SpaceIndented(spaced=2, tabbed=0)) def test_stays_silent_where_tabs_are_as_many_as_spaces(self): self.assertIsNone(space_indented(self.checkout(**{"a.py": SPACED, "b.py": TABBED}))) @@ -78,12 +86,14 @@ class SpaceIndentation(unittest.TestCase): (root / "a.py").write_bytes(b"\xff\xfe\n x\n y\n") self.assertEqual(space_indented(root), SpaceIndented(spaced=2, tabbed=0)) - @unittest.skipIf(os.geteuid() == 0, "root reads any file") def test_names_a_file_it_cannot_read(self): + assert_not_root(self) root = self.checkout(**{"a.py": SPACED}) (root / "a.py").chmod(0) self.addCleanup((root / "a.py").chmod, 0o644) - self.assertEqual(space_indented(root), Failure(f"cannot read a.py: [Errno 13] Permission denied: '{root}/a.py'")) + failed = space_indented(root) + self.assertIsInstance(failed, Failure) + self.assertTrue(failed.reason.startswith("a.py: "), failed.reason) def test_says_why_it_cannot_read_a_checkout(self): self.assertIsInstance(space_indented(pathlib.Path("/nonexistent-checkout")), Failure) From 86f67899f62f6767e32843ba7e8ef330420ea041 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:52:03 +0100 Subject: [PATCH 21/45] =?UTF-8?q?Answer=20product-owner=20round=201:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20tell=20t?= =?UTF-8?q?he=20worker=20what=20to=20do=20with=20the=20fact,=20name=20the?= =?UTF-8?q?=20decision=20log,=20say=20what=20a=20space-indented=20file=20k?= =?UTF-8?q?eeps=20meanwhile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_preflight/facts.py | 4 ++-- bin/chunk_preflight/test_chunk_preflight.py | 2 +- principles/technical-principles.md | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/chunk_preflight/facts.py b/bin/chunk_preflight/facts.py index 38541271..a8fc9ce0 100644 --- a/bin/chunk_preflight/facts.py +++ b/bin/chunk_preflight/facts.py @@ -40,12 +40,12 @@ def merge_lines(found: Gathered) -> list[str]: def indentation_lines(found: SpaceIndented | Failure | None) -> list[str]: - """The one fact about indentation: the project's code is space-indented with no setting that says so. It only reports: a client's repo belongs to its team.""" + """The fact about indentation, where the project's code is space-indented and no setting sets the indent, else why that cannot be read. It reports only and never fails the run, since a client's repo belongs to its team.""" if isinstance(found, Failure): return [f"- Whether the project's code is space-indented cannot be read: {found.reason}"] if found is None: return [] - return [f"- The project's code is space-indented ({found.spaced} lines against {found.tabbed} with tabs), and no `.editorconfig` with `indent_style` nor formatter setting (`rustfmt.toml` `hard_tabs`, Prettier `useTabs`, Biome `indentStyle`) says so. The technical principles indent with hard tabs unless a setting a tool reads, plus a decision in `docs/decisions.md` that names the reason, overrides that. Either convert the code to tabs, or record the override in `.editorconfig` and a decision."] + return [f"- The project's code is space-indented ({found.spaced} lines against {found.tabbed} with tabs), and neither an `.editorconfig` with `indent_style` nor a formatter setting (`rustfmt.toml` `hard_tabs`, Prettier `useTabs`, Biome `indentStyle`) sets the indent. The technical principles indent with hard tabs unless a setting a tool reads, plus a decision in the project's decision log that names the reason, overrides that. Don't reindent in a chunk with another purpose. Where the plan holds no item for either way out, file one: convert the code to tabs, or record the override in `.editorconfig` and a decision."] def last_release(default: str, release: LastCut) -> str: diff --git a/bin/chunk_preflight/test_chunk_preflight.py b/bin/chunk_preflight/test_chunk_preflight.py index 2afb7443..44a76492 100644 --- a/bin/chunk_preflight/test_chunk_preflight.py +++ b/bin/chunk_preflight/test_chunk_preflight.py @@ -811,7 +811,7 @@ class IndentationFact(unittest.TestCase): (line,) = self.said(SpaceIndented(spaced=120, tabbed=3)) self.assertIn("space-indented (120 lines against 3 with tabs)", line) self.assertIn("The technical principles indent with hard tabs", line) - self.assertIn("convert the code to tabs, or record the override in `.editorconfig` and a decision", line) + self.assertIn("file one: convert the code to tabs, or record the override in `.editorconfig` and a decision", line) def test_says_nothing_where_the_code_is_not_space_indented_and_why_where_it_cannot_be_read(self): self.assertEqual(self.said(None), []) diff --git a/principles/technical-principles.md b/principles/technical-principles.md index aa8b2f4f..3157a948 100644 --- a/principles/technical-principles.md +++ b/principles/technical-principles.md @@ -70,7 +70,7 @@ - Enumerate the cases that can go wrong and return them as explicit results (e.g. a result DTO with an optional error), so failure is part of the signature instead of a hidden second channel. - try/catch lives only at the edges, wrapped tightly around the call that can actually throw (DB, HTTP, filesystem), converting the exception into an explicit result right there. Pure functions and core logic never throw or catch for control flow. - A function that both returns a result and throws for some inputs has two error channels; collapse to one. Throw only for a truly unrecoverable state. - - Where code branches on why a call failed, it reads a status code, an exit code the tool documents, or a typed error. It reads message text only where the tool documents that text as unique to one cause, and treats every other failure as unknown, which stops the run rather than guessing. Older versions of a CLI often print one message for a missing image, a refused credential and a failed request. + - Where code branches on why a call failed, it reads a status code, an exit code the tool documents, or a typed error. It reads message text only where the tool documents that text as unique to one cause, and treats every other failure as unknown, which stops the run. * Commands and Queries Separation (CQS)-ish - Queries must never modify data, commands may only return data that is the result of their change. * Copy important contextual information on buisness transactions and equal data, instead of referencing it. @@ -118,4 +118,6 @@ - A Python script with a `#!/usr/bin/env python3` shebang runs identically across systems where shell dialects and builtins differ. - Read config (credentials, hosts, paths) from CLI params or env vars, never hardcoded. * Indent with hard tabs by default. - - Only a setting a tool reads overrides it: `.editorconfig` or a formatter's config (Prettier, `rustfmt.toml`, Biome, …), plus a decision in `docs/decisions.md` that names the reason. A prose rule in `AGENTS.md`, or the existing files' habit, doesn't. Output formats a spec fixes, such as a spelling's JSON, are outside the rule. `chunk-preflight` reports space-indented code that has no such setting. + - Overriding it takes two things: a setting a tool reads (`.editorconfig` or a formatter's config, such as Prettier, `rustfmt.toml` or Biome) and a decision in the decision log that names the reason. A prose rule in `AGENTS.md`, or the existing files' habit, doesn't override it. + - Files whose format fixes their indentation, such as YAML (no tabs) or a spelling's JSON, are outside the rule. + - A file already indented with spaces keeps them until the project converts it or records the override, so no file mixes the two. `chunk-preflight` reports a project in that state where `.editorconfig`, `rustfmt.toml`, Prettier and Biome set nothing about it. From 42c5ff83256e5c86cf62ebbe62852a569a248414 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:52:45 +0100 Subject: [PATCH 22/45] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(0=20misread);=20say=20what?= =?UTF-8?q?=20the=20check=20counts=20and=20what=20a=20setting=20does,=20an?= =?UTF-8?q?d=20tighten=20the=20docstrings=20and=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_preflight/gathered.py | 2 +- bin/chunk_preflight/indentation.py | 8 ++++---- bin/chunk_preflight/main.py | 11 ++++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bin/chunk_preflight/gathered.py b/bin/chunk_preflight/gathered.py index b7de48b8..051d3fda 100644 --- a/bin/chunk_preflight/gathered.py +++ b/bin/chunk_preflight/gathered.py @@ -76,5 +76,5 @@ class Gathered: merges_unread: Failure | None = None # The worktrees `chunk-pr clean` is still to remove. left: tuple[LeftWorktree, ...] = () - # The line counts of the project's code where it is space-indented with no setting that says so, or why they cannot be read; None where it is not. + # The line counts of the project's code where it is space-indented and no setting sets the indent, or why they cannot be read; None where it is not. indentation: SpaceIndented | Failure | None = None diff --git a/bin/chunk_preflight/indentation.py b/bin/chunk_preflight/indentation.py index 86ac098b..6f445152 100644 --- a/bin/chunk_preflight/indentation.py +++ b/bin/chunk_preflight/indentation.py @@ -1,4 +1,4 @@ -"""Whether a project's code is space-indented with no tool setting that says so. +"""Whether a project's code is space-indented where no tool setting sets the indent. The technical principles indent with hard tabs by default, and let a setting a tool reads override that. Code that is mostly space-indented, with no such setting, reads as a first session's habit that later sessions followed, not as a choice.""" import dataclasses @@ -9,11 +9,11 @@ import re from failure import Failure from git_cli.git_repo import git -# The files the project's language tooling covers. Markdown, JSON and YAML are not code: their indentation is a format's. +# Files of common programming languages, by extension. Markdown, JSON and YAML aren't code: a format fixes their indentation. CODE = re.compile(r".*\.(py|js|mjs|cjs|jsx|ts|tsx|rs|go|php|java|kt|kts|scala|rb|c|h|cc|cpp|hpp|cs|swift|sh|bash|lua|ex|exs|dart|vue|svelte)", re.IGNORECASE) # Committed copies of other people's code follow their authors' style. VENDORED = re.compile(r"(^|/)(vendor|node_modules|third_party)/") -# The files whose key says how to indent: an `.editorconfig` with `indent_style`, rustfmt's `hard_tabs`, Prettier's `useTabs` in its own files or a `package.json`, Biome's `indentStyle`. +# The key that, present in a file of that name, means the project sets its indent, whatever the key's value. Prettier also reads `package.json`. SETTINGS = ( (re.compile(r"\.editorconfig"), "indent_style"), (re.compile(r"\.?rustfmt\.toml"), "hard_tabs"), @@ -33,7 +33,7 @@ class SpaceIndented: def space_indented(base: pathlib.Path, timeout: float | None = None) -> SpaceIndented | Failure | None: - """The line counts of the tracked code under base where it has more space-indented lines than tab-indented ones and no tracked file sets the indent; None where it doesn't, or has no code; a Failure where a file cannot be read.""" + """The line counts of the tracked code under base, where it has more space-indented than tab-indented lines and no tracked file holds an indent key; else None. A Failure where git cannot list the files or a file cannot be read.""" tracked = git("ls-files", "-z", cwd=str(base), timeout=timeout, errors="replace") if isinstance(tracked, Failure): return tracked diff --git a/bin/chunk_preflight/main.py b/bin/chunk_preflight/main.py index a58f166a..607dc661 100644 --- a/bin/chunk_preflight/main.py +++ b/bin/chunk_preflight/main.py @@ -21,11 +21,12 @@ and prints that the release reviews and the cuts are the human's to call. It pri finished on the branch of an open pull request that is not a draft, where the checkout holds the plan. Where no item of the release can start and one awaits such a merge, it names those pull requests and says the working loop stops there; -- where the project's tracked code (the files its language tooling covers, not Markdown, JSON or - YAML) has more space-indented than tab-indented lines, and neither an `.editorconfig` with - `indent_style` nor a formatter setting (`rustfmt.toml` `hard_tabs`, Prettier `useTabs`, Biome - `indentStyle`) says so, one line naming the technical principles' hard-tabs default and the two - ways out. It only reports; +- where the project's tracked code (files of common programming languages, by extension; not + Markdown, JSON or YAML, nor anything under vendor/, node_modules/ or third_party/) has more + space-indented than tab-indented lines, and neither an `.editorconfig` with `indent_style` nor a + formatter setting (`rustfmt.toml` `hard_tabs`, Prettier `useTabs`, Biome `indentStyle`) sets the + indent, one line naming the technical principles' hard-tabs default and the two ways out. It + reports only, and never fails the run; - the next release and its first item that does not wait, the item loop-claude routes on, with its L and E + I; with --item , the plan item of that ID instead, which loop-claude names in a window named for an item. An item waits while it is marked question, while an item still in todo.md From c4c2508488186e99cd8c1e108db19b571ae5e170 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:55:32 +0100 Subject: [PATCH 23/45] Sort test_indentation's imports by first binding --- bin/chunk_preflight/test_indentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/chunk_preflight/test_indentation.py b/bin/chunk_preflight/test_indentation.py index 9b8e1015..549420fe 100644 --- a/bin/chunk_preflight/test_indentation.py +++ b/bin/chunk_preflight/test_indentation.py @@ -7,8 +7,8 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from failure import Failure from test_env import assert_not_root, isolated_env +from failure import Failure from chunk_preflight.indentation import space_indented, SpaceIndented TABBED = "def run():\n\tif True:\n\t\treturn 1\n" From f46946f6dee0303319874bfd1c84f4a547dffca1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 15:56:13 +0100 Subject: [PATCH 24/45] Test that the merge step waits with the sleep it is given --- bin/chunk_pr/test_chunk_pr.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index 4bac9b5b..cc719e33 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -368,6 +368,13 @@ class Merge(unittest.TestCase): self.assertEqual(merged(checkout, checkout.config, slept.append), "Merged pull request #12 (merge).") self.assertEqual(sum(slept), 60) + def test_the_merge_step_waits_with_the_sleep_it_is_given(self): + checkout = Checkout(GITEA, open=True) + checkout.statuses = [json.dumps({"total_count": 0, "state": "pending", "statuses": []})] * 7 + slept: list[float] = [] + self.assertEqual(step(["merge"], checkout, checkout.config, sleep=slept.append), "Merged pull request #12 (merge).") + self.assertEqual(sum(slept), 60) + def requiring_approval(self, origin: str = GITHUB, *decisions: str) -> Checkout: """A Checkout whose project config sets wait-for-approval, and which reports each of decisions in turn as the review decision.""" checkout = Checkout(origin, open=True) @@ -1220,7 +1227,7 @@ class EpicBranch(unittest.TestCase): checkout.listed_heads = [OLD] done = step(["push"], checkout, checkout.config, sleep=slept.append) self.assertIsInstance(done, Failure) - for fact in ("pushed item-7", "pull request #12", HEAD[:12], "60 seconds"): + for fact in ("pushed item-7", "pull request #12", f"{HEAD[:12]} as", "60 seconds"): self.assertIn(fact, done.reason) self.assertEqual(sum(slept), 60) self.assertNotIn(self.COMMENT_GH, checkout.ran) From 1703f0d47b1b37b2a1e1d9fd19170aa7996e41fc Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:02:59 +0100 Subject: [PATCH 25/45] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20a=20test=20?= =?UTF-8?q?of=20the=20last=20poll,=20early=20returns=20in=20pushed,=20a=20?= =?UTF-8?q?plainer=20gh=20row=20match?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_pr/main.py | 10 +++++++--- bin/chunk_pr/test_chunk_pr.py | 6 ++++++ bin/forge/pulls.py | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index 569471a0..a9e22ba1 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -379,11 +379,15 @@ def pushed(run: Run, config: Config, sleep: typing.Callable[[float], None]) -> s if isinstance(sent, Failure): return sent comment = review_comment(run, config) - number = None if comment is None or isinstance(comment, Failure) else shown_pull(forge, branch, head, run, sleep) if isinstance(comment, Failure): return Failure(f"pushed {branch}, but could not ask for a review: {comment.reason}") - if isinstance(number, Failure) or number is None or comment is None: - return number if isinstance(number, Failure) else f"Pushed {branch}." + if comment is None: + return f"Pushed {branch}." + number = shown_pull(forge, branch, head, run, sleep) + if number is None: + return f"Pushed {branch}." + if isinstance(number, Failure): + return number made = comment_on(forge, number, comment, run) return Failure(f"pushed {branch}, but could not ask for a review: {made.reason}") if isinstance(made, Failure) else f"Pushed {branch}, and asked for a review of pull request #{number} with “{comment}”." diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index cc719e33..12c45b43 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -1232,6 +1232,12 @@ class EpicBranch(unittest.TestCase): self.assertEqual(sum(slept), 60) self.assertNotIn(self.COMMENT_GH, checkout.ran) + def test_push_asks_for_a_review_where_the_forge_shows_the_new_head_at_the_last_poll(self): + checkout, slept = self.checkout(), [] + checkout.listed_heads = [OLD] * 24 + [HEAD] + self.assertIn("asked for a review of pull request #12", str(step(["push"], checkout, checkout.config, sleep=slept.append))) + self.assertEqual(sum(slept), 60) + def test_push_does_not_wait_where_the_pull_request_goes_into_the_default_branch(self): checkout, slept = self.checkout(), [] checkout.chunk_base = "" diff --git a/bin/forge/pulls.py b/bin/forge/pulls.py index 151dbec1..f024e297 100644 --- a/bin/forge/pulls.py +++ b/bin/forge/pulls.py @@ -39,7 +39,7 @@ def pull_at(forge: Forge, branch: str, head: str | None, state: typing.Literal[" if isinstance(listed, Failure): return listed rows = [line.split("\t") for line in listed.splitlines()] - return next((row[0] for row in rows if row[1:] == ([head, "false"] if head is not None else row[1:2] + ["false"])), None) + return next((row[0] for row in rows if len(row) == 3 and row[2] == "false" and head in (None, row[1])), None) # Gitea lists at most 50 a page; the pull request sought is among the newest. Gitea has no merged state: a merged pull request is a closed one marked merged. pulls = gitea(run, f"repos/{{owner}}/{{repo}}/pulls?state={'open' if state == 'open' else 'closed'}&limit=50") if isinstance(pulls, Failure): From 86edf81d288c509750e09c108546400b4fbab00f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:05:56 +0100 Subject: [PATCH 26/45] Keep a Rust test in a file of its own as planted in a task-bench fix --- bin/task_bench/main.py | 15 ++++- bin/task_bench/runs.py | 36 +++++++++-- bin/task_bench/rust_test_modules.py | 64 +++++++++++++++---- bin/task_bench/test_rust_test_modules.py | 24 +++++++ bin/task_bench/test_task_bench.py | 79 +++++++++++++++++++++++- 5 files changed, 195 insertions(+), 23 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index e7d9971b..826997c2 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -42,8 +42,10 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. Where the planted file has such modules and Haiku's file lacks one of them, or its modules cannot be told apart, the planted file stands whole; where the planted file has none, or its modules cannot be told apart, Haiku's stands. A Rust mutant whose file's modules cannot be told apart, as where two share a name or a brace, string or comment - is never closed, is passed over. A Rust test in a file of its own, as `#[cfg(test)] mod tests;` names, counts, since the bench - tells no such file from code. + is never closed, is passed over. A Rust file that a `#[cfg(test)] mod name;` in another file of the planted tree names, as + `src/name.rs` or `src/name/mod.rs` beside a `lib.rs`, `main.rs` or `mod.rs`, or in the folder of any other file's name, is a + test: it stands as the planted tree has it, and no mutant is planted in it. A Rust mutant in a tree where such a declaration + names no file there, as one that `#[path]` moves does, is passed over. --image is the project's development image, such as golang:1.27.4. The bench adds Claude Code to it, as its installer installs it, so the image needs curl and bash; the result names the version. Haiku works in that image. So does --test: sh runs that text at @@ -200,7 +202,7 @@ from task_bench.tasks import Asked, Bench, BUG, check_made, committed, DATA_SOUR from task_bench.bugs.planted_mutant import bug_at_sides, Mutant from claude_code.reply import Claude from task_bench.bench_folder import clear_left, held -from task_bench.runs import closed, Containers, docker_cli, fix_attempted, MEMORY_MIB, opened, ran_tests, TimedOut, TOKEN, WORK +from task_bench.runs import closed, Containers, docker_cli, fix_attempted, MEMORY_MIB, opened, ran_tests, rust_test_files, TimedOut, TOKEN, WORK from task_bench.figures.digest import counted, digest, Run, TaskRuns from machine_load.slots import CPUS_PER_SLOT from git_cli.git_repo import default_ref, Git, top @@ -588,6 +590,13 @@ def planted(bench: Bench, number: int, mutant: Mutant) -> Task | Failure | None: # The check keeps a Rust file's test modules as planted, which it can only do where it tells them apart. if bugs is None or not all(tells_apart(mutant.path, source) for source in bugs.values()): return None + # ... and a Rust test in a file of its own, which it can only keep where it finds each such file. + if mutant.path.endswith(".rs"): + standing = on_disk(f"find the Rust test files beside {mutant.path}", lambda: [rust_test_files(tree) for tree in bench.trees.values()]) + if isinstance(standing, Failure): + return standing + if any(tests is None or mutant.path in tests for tests in standing): + return None trees: dict[Side, str] = {} messages: dict[Side, str] = {} for side, changed in bugs.items(): diff --git a/bin/task_bench/runs.py b/bin/task_bench/runs.py index 28337af8..ed327f16 100644 --- a/bin/task_bench/runs.py +++ b/bin/task_bench/runs.py @@ -12,7 +12,7 @@ from mutate_changes.tool_process import failed, Ran from failure import Failure from mutate_changes.changed_lines import is_test from task_bench.api_proxy import PORT -from task_bench.rust_test_modules import with_tests_of +from task_bench.rust_test_modules import declared, homes, with_tests_of MODEL = "claude-haiku-5-5" # Where each run's container mounts its copy of the code, and its home folder: the paths in a run's stream start there. @@ -168,19 +168,21 @@ def checked_tree(planted: str, copy: str, into: str, rust_tests_planted: bool = """Makes at `into` the tree the tests check a fix in: `planted`, the code with the bug as Haiku got it, with each file that is no test as `copy` holds it after the fix. So a test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder, where Go's tests keep the output they expect. Where rust_tests_planted, a Rust file's inline `#[cfg(test)]` - modules stand as the planted file has them too, as `with_tests_of` says. + modules stand as the planted file has them too, as `with_tests_of` says, and so does each Rust file that `rust_test_files` finds. Raises OSError where a file cannot be copied.""" shutil.copytree(planted, into, symlinks=True) + # `rust_test_files` is None for a tree whose declarations it cannot resolve, which the bench passes over where it plants the bug. + rust_tests = (rust_test_files(planted) or set()) if rust_tests_planted else set() before, after = set(entries(planted)), set(entries(copy)) for path in before - after: - if not of_tests(path): + if not of_tests(path, rust_tests): with contextlib.suppress(FileNotFoundError): os.unlink(os.path.join(into, path)) for path in sorted(after): target = os.path.join(into, path) # A link is copied as a link, never followed; and one that would stand in for a folder of the planted tree is left out. - if of_tests(path) or (os.path.isdir(target) and not os.path.islink(target)): + if of_tests(path, rust_tests) or (os.path.isdir(target) and not os.path.islink(target)): continue os.makedirs(os.path.dirname(target), exist_ok=True) with contextlib.suppress(FileNotFoundError): @@ -201,8 +203,30 @@ def keep_rust_tests(planted_file: str, target: str) -> None: pathlib.Path(target).write_bytes(with_tests_of(planted, pathlib.Path(target).read_bytes())) -def of_tests(path: str) -> bool: - return is_test(path) or "testdata" in pathlib.PurePath(path).parts +def of_tests(path: str, rust_tests: typing.AbstractSet[str] = frozenset()) -> bool: + """Whether path is a test by its path alone, or one of rust_tests.""" + return is_test(path) or "testdata" in pathlib.PurePath(path).parts or path in rust_tests + + +def rust_test_files(tree: str) -> set[str] | None: + """The Rust files under tree that a `#[cfg(test)] mod name;` declaration names, by their paths from tree. None where a + declaration names no file there, or `declared` cannot tell a file's declarations. + + Raises OSError where a file cannot be read.""" + files = set(entries(tree)) + found = set() + for path in sorted(files): + if not path.endswith(".rs") or os.path.islink(os.path.join(tree, path)): + continue + names = declared(pathlib.Path(tree, path).read_bytes()) + if names is None: + return None + for name in names: + standing = [home for home in homes(path, name) if home in files] + if not standing: + return None + found.add(standing[0]) + return found def entries(top: str) -> list[str]: diff --git a/bin/task_bench/rust_test_modules.py b/bin/task_bench/rust_test_modules.py index aa2b13d2..2ebed22c 100644 --- a/bin/task_bench/rust_test_modules.py +++ b/bin/task_bench/rust_test_modules.py @@ -1,5 +1,7 @@ -"""The `#[cfg(test)]` modules of a Rust file, which stand in the file of the code they test. Here are where each is, and a file with -the modules of another file put in place of its own. A file is bytes: a Rust file is UTF-8, and a module is found by ASCII text alone.""" +"""The `#[cfg(test)]` modules of a Rust file, which stand in the file of the code they test or, as `mod name;` declares, in a file of +their own. Here are where each inline one is, which files hold the others, and a file with the modules of another file put in place +of its own. A file is bytes: a Rust file is UTF-8, and a module is found by ASCII text alone.""" +import pathlib import re # What the scan steps over or stops at. A string, a char and a comment may hold a brace. @@ -17,6 +19,10 @@ STRING_BODY = re.compile(rb'(?:[^"\\]|\\.)*"', re.DOTALL) COMMENT_EDGE = re.compile(rb"/\*|\*/") # What follows the attribute that starts an inline module: any other attributes, an optional visibility, then `mod name {`. MODULE = re.compile(rb"\s*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*\{") +# What follows the attribute that starts a module kept in a file of its own: any other attributes, an optional visibility, then `mod name;`. +DECLARATION = re.compile(rb"\s*(?P(?:#\[[^\]]*\]\s*)*)(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*;") +PATH_ATTRIBUTE = re.compile(rb"#\[\s*path\b") +KEEP_BESIDE = ("lib.rs", "main.rs", "mod.rs") def tells_apart(path: str, source: bytes) -> bool: @@ -32,16 +38,13 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: depth = 0 # The module being read: its name, the offset of its attribute and the depth outside it. inside: tuple[bytes, int, int] | None = None - position: int | None = 0 - while position is not None and (match := SCAN.search(source, position)): - token, position = match.group(), match.end() - if token == b"/*": - position = after_comment(source, position) - elif token == b'"': - position = after_string(source, position) - elif match.group("hashes") is not None: - position = after_raw_string(source, position, match.group("hashes")) - elif token == b"{": + position = 0 + while match := SCAN.search(source, position): + token = match.group() + if (after := after_token(source, match)) is None: + return None + position = after + if token == b"{": depth += 1 elif token == b"}": depth -= 1 @@ -52,7 +55,42 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: elif token.startswith(b"#[") and inside is None and (module := MODULE.match(source, position)): inside, position = (module.group("name"), match.start(), depth), module.end() depth += 1 - return found if position is not None and depth == 0 and inside is None else None + return found if depth == 0 and inside is None else None + + +def declared(source: bytes) -> list[str] | None: + """The name of each `#[cfg(test)] mod name;` of source, a test module kept in a file of its own, in the order they stand. + None where a `#[path]` attribute moves such a file, or a string or comment is never closed.""" + names = [] + position = 0 + while match := SCAN.search(source, position): + if (after := after_token(source, match)) is None: + return None + position = after + if match.group() == b"#[cfg(test)]" and (declaration := DECLARATION.match(source, position)): + if PATH_ATTRIBUTE.search(declaration.group("attributes")): + return None + names.append(declaration.group("name").decode()) + return names + + +def homes(path: str, name: str) -> list[str]: + """Where the file of the module `name`, declared in the Rust file at path, may stand, by its path from the same top. A crate root + (`lib.rs`, `main.rs`) and a `mod.rs` keep their modules beside them; any other file keeps them in a folder of its own name.""" + declaring = pathlib.PurePosixPath(path) + folder = declaring.parent if declaring.name in KEEP_BESIDE else declaring.parent / declaring.stem + return [str(folder / f"{name}.rs"), str(folder / name / "mod.rs")] + + +def after_token(source: bytes, match: re.Match[bytes]) -> int | None: + """The offset after match, or after the comment, string or raw string that match opens; None where that is never closed.""" + if match.group() == b"/*": + return after_comment(source, match.end()) + if match.group() == b'"': + return after_string(source, match.end()) + if match.group("hashes") is not None: + return after_raw_string(source, match.end(), match.group("hashes")) + return match.end() def after_comment(source: bytes, position: int) -> int | None: diff --git a/bin/task_bench/test_rust_test_modules.py b/bin/task_bench/test_rust_test_modules.py index 6db68697..cfd977c5 100644 --- a/bin/task_bench/test_rust_test_modules.py +++ b/bin/task_bench/test_rust_test_modules.py @@ -103,6 +103,30 @@ class ModulesTest(unittest.TestCase): self.assertIsNone(modules(source)) +def declared(source: str) -> list[str] | None: + return rust_test_modules.declared(source.encode()) + + +class DeclaredTest(unittest.TestCase): + def test_lists_each_test_module_the_file_declares_without_a_body(self): + self.assertEqual(declared("#[cfg(test)]\nmod tests;\n#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks;\n"), ["tests", "checks"]) + + def test_leaves_out_an_inline_module_and_a_declaration_that_is_no_test_module(self): + self.assertEqual(declared(LIB + "mod util;\n#[cfg(feature = \"x\")]\nmod extra;\n"), []) + + def test_leaves_out_a_declaration_in_a_comment_or_a_string(self): + source = '// #[cfg(test)]\n// mod a;\n/* #[cfg(test)] mod b; */\nconst C: &str = "#[cfg(test)] mod c;";\nconst D: &str = r#"#[cfg(test)] mod d;"#;\n' + self.assertEqual(declared(source), []) + + def test_cannot_tell_where_a_declaration_moves_its_file_with_a_path_attribute(self): + self.assertIsNone(declared('#[cfg(test)]\n#[path = "elsewhere.rs"]\nmod tests;\n')) + + def test_cannot_tell_where_a_string_or_comment_is_never_closed(self): + for source in ("#[cfg(test)]\nmod tests;\nconst A: &str = \"\n", "/* open\n#[cfg(test)]\nmod tests;\n"): + with self.subTest(source=source): + self.assertIsNone(declared(source)) + + class TellsApartTest(unittest.TestCase): def test_tells_the_modules_of_a_rust_file_apart_where_they_can_be(self): self.assertEqual([tells_apart("lib.rs", b"fn a() {}"), tells_apart("lib.rs", b"fn a() {")], [True, False]) diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 9d0c1d1c..b9252306 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -17,7 +17,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from task_bench import api_proxy, bench_folder, main, runs from test_env import assert_not_root, isolated_env -from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, opened, ran_tests, TimedOut +from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, opened, ran_tests, rust_test_files, TimedOut from task_bench.bugs.plant import drawn from claude_code.entries import Entry, entry_from from failure import Failure @@ -613,6 +613,34 @@ class RunOutcomesTest(unittest.TestCase): mutant = Mutant("lib.rs", 2, "lib.rs:2:7 replace + with -", (b" a + b",), (b" a - b",)) self.assertIsNone(main.planted(self.bench(), 1, mutant)) + def rust_bench(self, files: dict[str, str], *runs: Ran | Failure) -> main.Bench: + for path, text in files.items(): + (self.tree / path).parent.mkdir(parents=True, exist_ok=True) + (self.tree / path).write_text(text) + return self.bench(*runs) + + ADD = "pub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n#[cfg(test)]\nmod tests;\n" + ADDING = Mutant("src/lib.rs", 2, "src/lib.rs:2:7 replace + with -", (b" a + b",), (b" a - b",)) + + def test_a_rust_mutant_in_a_test_file_of_its_own_is_passed_over(self): + bench = self.rust_bench({"src/lib.rs": self.ADD, "src/tests.rs": "fn t() { assert!(1 + 1 == 2); }\n"}) + mutant = Mutant("src/tests.rs", 1, "src/tests.rs:1:20 replace + with -", (b"fn t() { assert!(1 + 1 == 2); }",), (b"fn t() { assert!(1 - 1 == 2); }",)) + self.assertIsNone(main.planted(bench, 1, mutant)) + + def test_a_rust_mutant_in_a_tree_whose_declared_test_file_is_not_found_is_passed_over(self): + self.assertIsNone(main.planted(self.rust_bench({"src/lib.rs": self.ADD}), 1, self.ADDING)) + + def test_a_rust_mutant_in_code_beside_a_test_file_goes_on_to_the_tests(self): + broke = Failure("docker could not start: No such file or directory") + self.assertEqual(main.planted(self.rust_bench({"src/lib.rs": self.ADD, "src/tests.rs": ""}, broke), 1, self.ADDING), broke) + + def test_a_rust_mutant_in_a_tree_whose_rust_file_cannot_be_read_fails_the_bench_naming_the_file(self): + assert_not_root(self) + bench = self.rust_bench({"src/lib.rs": self.ADD, "src/tests.rs": "", "src/other.rs": ""}) + (self.tree / "src/other.rs").chmod(0) + self.addCleanup((self.tree / "src/other.rs").chmod, 0o644) + self.assertFailsWith(main.planted(bench, 1, self.ADDING), "could not find the Rust test files beside src/lib.rs: ") + class ContainersTest(unittest.TestCase): IN_TREE = ["--memory", "512m", "--memory-swap", "512m", "--user", "1000:1000", "--env", "HOME=/tmp", "--volume", "/tree:/work", "--workdir", "/work"] @@ -772,6 +800,55 @@ class CheckedTreeTest(unittest.TestCase): checked_tree(planted, copy, str(self.root / "check")) self.assertEqual(self.held("check")["src/new.rs"], added) + DECLARING = "fn a() { 1 }\n#[cfg(test)]\nmod tests;\n" + + def test_takes_a_rust_test_in_a_file_of_its_own_as_planted_and_the_rest_as_fixed(self): + planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests", "src/other.rs": "bug"}) + copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n", "src/tests.rs": "rewritten", "src/other.rs": "fixed"}) + checked_tree(planted, copy, str(self.root / "check")) + self.assertEqual(self.held("check"), {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n", "src/tests.rs": "old tests", "src/other.rs": "fixed"}) + + def test_takes_a_rust_test_file_the_fix_deleted_as_planted(self): + planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) + copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n"}) + checked_tree(planted, copy, str(self.root / "check")) + self.assertEqual(self.held("check")["src/tests.rs"], "old tests") + + def test_takes_a_rust_test_file_the_fix_added_as_fixed_since_the_planted_tree_declares_none(self): + planted = self.tree("planted", {"src/lib.rs": "fn a() { 1 }\n"}) + copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n", "src/tests.rs": "mine"}) + checked_tree(planted, copy, str(self.root / "check")) + self.assertEqual(self.held("check")["src/tests.rs"], "mine") + + def test_a_task_with_acceptance_tests_takes_a_rust_test_file_as_fixed(self): + planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) + copy = self.tree("copy", {"src/lib.rs": self.DECLARING, "src/tests.rs": "new tests"}) + checked_tree(planted, copy, str(self.root / "check"), rust_tests_planted=False) + self.assertEqual(self.held("check")["src/tests.rs"], "new tests") + + def test_finds_a_rust_test_file_where_the_module_system_puts_it(self): + cases = { + "beside a crate root": ({"src/lib.rs": self.DECLARING, "src/tests.rs": ""}, {"src/tests.rs"}), + "as a folder with a mod.rs": ({"src/main.rs": self.DECLARING, "src/tests/mod.rs": ""}, {"src/tests/mod.rs"}), + "in the folder of a module file": ({"src/pick.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), + "beside a mod.rs": ({"src/pick/mod.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), + "declared by no file": ({"src/lib.rs": "fn a() {}\n", "src/tests.rs": ""}, set()), + } + for name, (files, found) in cases.items(): + with self.subTest(name): + self.assertEqual(rust_test_files(self.tree(name.replace(" ", "-"), files)), found) + + def test_cannot_find_a_rust_test_file_that_is_not_where_its_declaration_puts_it_or_cannot_be_read_from_it(self): + cases = { + "missing": {"src/lib.rs": self.DECLARING}, + "beside a module file, where only a crate root has its modules": {"src/pick.rs": self.DECLARING, "src/tests.rs": ""}, + "moved by a path attribute": {"src/lib.rs": '#[cfg(test)]\n#[path = "t.rs"]\nmod tests;\n', "src/t.rs": ""}, + "in a declaring file whose string is never closed": {"src/lib.rs": '#[cfg(test)]\nmod tests;\nconst A: &str = "\n', "src/tests.rs": ""}, + } + for name, files in cases.items(): + with self.subTest(name): + self.assertIsNone(rust_test_files(self.tree(name.replace(" ", "-"), files))) + def test_leaves_a_rust_link_as_a_link_whatever_it_points_at(self): planted = self.tree("planted", {"z.rs": "fn a() {}\n#[cfg(test)]\nmod tests {}\n", "a.txt": "text"}) copy = self.tree("copy", {"a.txt": "text"}) From b1becdc866fac31bc8ab19fa17f75d12574cacd4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:06:06 +0100 Subject: [PATCH 27/45] Record the reading cost of the chunks since the last figures --- docs/reading-cost.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/reading-cost.md b/docs/reading-cost.md index eb2266a4..aadcccc3 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -3711,3 +3711,33 @@ Read most (opens and searches): - `bin/release_plan/release_standing.py` 3 - `CHANGELOG.md` 1 - `bin/deploy_release/cut.py` 1 + +## Reading cost, chunk 7361c9bb3e9a, finished 2026-11-27T14:31:28Z + +48295 new input tokens before the first commit. + +Read most (opens and searches): + +- `agents/stability-reviewer.md` 3 +- `README.md` 1 +- `agents/systems-architect.md` 1 +- `skills/larv-review/SKILL.md` 1 + +## Reading cost, chunk 73ef8355db51, finished 2026-11-27T14:52:23Z + +61386 new input tokens before the first commit. + +Read most (opens and searches): + +- `agents/stability-reviewer.md` 3 +- `skills/larv-review/SKILL.md` 2 + +## Reading cost, chunk bca62e26ca73, finished 2026-11-27T15:01:02Z + +56538 new input tokens before the first commit. + +Read most (opens and searches): + +- `skills/larv-review/SKILL.md` 2 +- `agents/product-owner-reviewer.md` 1 +- `agents/prose-reviewer.md` 1 From 237a3e05ff5cb36bddf4cf3b12d13d4659e7f171 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:07:21 +0100 Subject: [PATCH 28/45] Order the vendored-settings test so a skipped file doesn't hide a break --- bin/chunk_preflight/test_indentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/chunk_preflight/test_indentation.py b/bin/chunk_preflight/test_indentation.py index 549420fe..eeb594d9 100644 --- a/bin/chunk_preflight/test_indentation.py +++ b/bin/chunk_preflight/test_indentation.py @@ -61,7 +61,7 @@ class SpaceIndentation(unittest.TestCase): def test_leaves_out_vendored_code_and_the_settings_files_it_holds(self): self.assertIsNone(space_indented(self.checkout(**{"vendor__lib.py": SPACED, "web__node_modules__x__index.js": SPACED}))) - vendored = self.checkout(**{"a.py": SPACED, "vendor__lib__.editorconfig": "indent_style = space\n", "third_party__x__package.json": '{"useTabs": false}'}) + vendored = self.checkout(**{"z.py": SPACED, "vendor__lib__.editorconfig": "indent_style = space\n", "third_party__x__package.json": '{"useTabs": false}'}) self.assertEqual(space_indented(vendored), SpaceIndented(spaced=2, tabbed=0)) def test_reads_a_checkout_with_a_file_name_that_is_not_utf8(self): From 63595bb01886451bc25338919e9f98d15beb63d4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:08:07 +0100 Subject: [PATCH 29/45] Finish item 548 in the plan --- CHANGELOG.md | 1 + todo.md | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a374e59a..6c4ff1ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `chunk-pr merge` honours `merge = "human"` and `wait-for-approval` for a chunk whose recorded base is origin's default branch. - larv-review's claimed-output step runs each claim in a fresh clone, without the ignored files earlier runs wrote, and checks claims about what a command writes. - stability-reviewer now flags a regex that validates a whole input with `$`, which also matches before a final newline. - stability-reviewer checks that a guard on whether a file, row or record exists looks at every place the thing passes through. diff --git a/todo.md b/todo.md index 86b5356a..57491a4a 100644 --- a/todo.md +++ b/todo.md @@ -14,7 +14,6 @@ |---|---|---|---|---|---|---|---|---|---|---|---| | 477 | 0.17.0 | | question | **Rewrite `## Goals` and `## Audience` for a setup others install and run apart from their own `~/.claude`.** | 1 | 1 | 2 | 2 | 2 | | 0.0 | | 478 | 0.17.0 | | question | **Name the project, its repo and its two commands, today proposed as `do-release` and `do-epic`.** | 1 | 1 | 2 | 2 | 1 | | 0.0 | -| 548 | 0.17.0 | | defect | **Treat a chunk whose recorded base is origin's default branch as merging into that branch, so `chunk-pr merge` honours `merge = "human"` and `wait-for-approval` there.** | 1 | 2 | 2 | 3 | 1 | 1.1 by 3 | 1.3 | | 552 | 0.17.0 | | defect | **Ask for a review on `chunk-pr push` once the forge shows the pushed head on the pull request, and fail where no open pull request takes it, so a push never skips the review request without saying so.** | 1 | 2 | 2 | 3 | 2 | 1.1 by 3 | 1.2 | | 542 | 0.17.0 | | | **Make chunk-preflight report a project whose code is space-indented with no `.editorconfig` or formatter setting that says so, and narrow the tabs principle to explicit overrides.** | 2 | 2 | 3 | 5 | 4 | 1.1 by 4 | 1.2 | | 523 | 0.17.0 | | | **Make the security pass and stability-reviewer check that a new secret's docs name its scope and its reach, such as the other repositories its account can use.** | 1 | 1 | 2 | 2 | 1 | 1.1 by 2 | 0.9 | @@ -121,17 +120,6 @@ Part of the standalone-install plan lilleman approved on 2026-11-20. `do-release Part of the standalone-install plan lilleman approved on 2026-11-20. Later items say `do-release` and `do-epic` for the names this item picks. The names set the install folders, such as `~/.config/do-release/`, so items 482, 485 and 496, and every item they block, wait for them. -### 548. Treat a chunk whose recorded base is origin's default branch as merging into that branch, so `chunk-pr merge` honours `merge = "human"` and `wait-for-approval` there. - -`base_of` in `bin/chunk_pr/main.py` returns `to_epic=True` for any branch whose `branch..chunk-base` is set in git's config. In a project that sets `epic-branch`, a chunk that goes into the default branch instead of the epic's working branch can still record `chunk-base = main`. Then `chunk-pr merge` skips `merge = "human"` and `wait-for-approval` and runs `gh pr merge` into `main`. In one chunk, only the repo's branch protection stopped that merge. A repo without protection would have merged into its default branch with no person involved. - -The fix: where the recorded base equals origin's default branch, `base_of` returns `Base(default, False)`. Write the test first: a checkout that records `chunk-base` as the default branch under `merge = "human"` leaves the pull request unmerged. - -Touches: - -- `bin/chunk_pr/main.py`: `base_of` (small) -- `bin/chunk_pr/test_chunk_pr.py` - ### 552. Ask for a review on `chunk-pr push` once the forge shows the pushed head on the pull request, and fail where no open pull request takes it, so a push never skips the review request without saying so. `pushed` finds the pull request by the head it just pushed, through `open_pull`. Right after the push, GitHub may still list the pull request's old head. Then `open_pull` returns None, and `push` prints only `Pushed .` with no review request and no warning. That happened on a pull request into an epic's working branch: the external auto-reviewer reviewed only once someone posted the configured comment by hand, about twenty minutes later. From 2fdc4350f22f808181418be0bd146e0e94737d57 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:08:07 +0100 Subject: [PATCH 30/45] Finish item 552 in the plan --- CHANGELOG.md | 1 + todo.md | 11 ----------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c4ff1ad..d4bce196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `chunk-pr push` waits for the forge to show the pushed commit as the head of the branch's open pull request before it asks for a review, and fails naming the pull request where the forge does not. - `chunk-pr merge` honours `merge = "human"` and `wait-for-approval` for a chunk whose recorded base is origin's default branch. - larv-review's claimed-output step runs each claim in a fresh clone, without the ignored files earlier runs wrote, and checks claims about what a command writes. - stability-reviewer now flags a regex that validates a whole input with `$`, which also matches before a final newline. diff --git a/todo.md b/todo.md index 57491a4a..3f0d51ef 100644 --- a/todo.md +++ b/todo.md @@ -14,7 +14,6 @@ |---|---|---|---|---|---|---|---|---|---|---|---| | 477 | 0.17.0 | | question | **Rewrite `## Goals` and `## Audience` for a setup others install and run apart from their own `~/.claude`.** | 1 | 1 | 2 | 2 | 2 | | 0.0 | | 478 | 0.17.0 | | question | **Name the project, its repo and its two commands, today proposed as `do-release` and `do-epic`.** | 1 | 1 | 2 | 2 | 1 | | 0.0 | -| 552 | 0.17.0 | | defect | **Ask for a review on `chunk-pr push` once the forge shows the pushed head on the pull request, and fail where no open pull request takes it, so a push never skips the review request without saying so.** | 1 | 2 | 2 | 3 | 2 | 1.1 by 3 | 1.2 | | 542 | 0.17.0 | | | **Make chunk-preflight report a project whose code is space-indented with no `.editorconfig` or formatter setting that says so, and narrow the tabs principle to explicit overrides.** | 2 | 2 | 3 | 5 | 4 | 1.1 by 4 | 1.2 | | 523 | 0.17.0 | | | **Make the security pass and stability-reviewer check that a new secret's docs name its scope and its reach, such as the other repositories its account can use.** | 1 | 1 | 2 | 2 | 1 | 1.1 by 2 | 0.9 | | 547 | 0.17.0 | | | **Add a technical principle: tell a failure's cause from a status code or a typed error, never from a tool's message text unless the tool documents that text as unique to the cause.** | 1 | 2 | 2 | 3 | 1 | 1.1 by 2 | 0.9 | @@ -120,16 +119,6 @@ Part of the standalone-install plan lilleman approved on 2026-11-20. `do-release Part of the standalone-install plan lilleman approved on 2026-11-20. Later items say `do-release` and `do-epic` for the names this item picks. The names set the install folders, such as `~/.config/do-release/`, so items 482, 485 and 496, and every item they block, wait for them. -### 552. Ask for a review on `chunk-pr push` once the forge shows the pushed head on the pull request, and fail where no open pull request takes it, so a push never skips the review request without saying so. - -`pushed` finds the pull request by the head it just pushed, through `open_pull`. Right after the push, GitHub may still list the pull request's old head. Then `open_pull` returns None, and `push` prints only `Pushed .` with no review request and no warning. That happened on a pull request into an epic's working branch: the external auto-reviewer reviewed only once someone posted the configured comment by hand, about twenty minutes later. - -Fix: after the push, wait a bounded time for an open pull request whose head is the pushed commit, polling as `forge.pulls` already does for checks. Where a pull request from the branch is open but never shows the new head, fail and name it. Where none is open at all, keep printing `Pushed .`, since `push` before `open` is normal. - -Touches: -- `bin/chunk_pr/main.py`: `pushed` -- `bin/chunk_pr/test_chunk_pr.py` - ### 542. Make chunk-preflight report a project whose code is space-indented with no `.editorconfig` or formatter setting that says so, and narrow the tabs principle to explicit overrides. `principles/technical-principles.md` says "Indent with hard tabs by default. A project's own settings win: `.editorconfig`, linter/formatter config, or the surrounding file's existing indentation." The last clause lets a first session set spaces and every later session follow it, and nothing checks that anyone chose it. adf-codec's `AGENTS.md` has said "Two-space indent" since its first commit, with no reason, and 177 code files, 14,500 indented lines, followed it. A survey of the projects on this machine on 2026-11-26 found the same in plainpages, scheduler (`rustfmt.toml` doesn't set `hard_tabs`), oss-opportunity-research, secondhand-watch and playwright-for-agents. Only plainpages-plugin-fastjira says so in an `.editorconfig`. From a8dc5867a7b4139a3f84628c52e65db3c83ef773 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:08:59 +0100 Subject: [PATCH 31/45] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20approved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 0b891b06d8402b1b5dd972305fa8f585c30abdb5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:08:59 +0100 Subject: [PATCH 32/45] =?UTF-8?q?Answer=20prose=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20say=20what?= =?UTF-8?q?=20the=20tabs=20rule=20leaves=20out,=20and=20when=20chunk-prefl?= =?UTF-8?q?ight=20reports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_preflight/indentation.py | 2 +- principles/technical-principles.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/chunk_preflight/indentation.py b/bin/chunk_preflight/indentation.py index 6f445152..51c3f6dc 100644 --- a/bin/chunk_preflight/indentation.py +++ b/bin/chunk_preflight/indentation.py @@ -9,7 +9,7 @@ import re from failure import Failure from git_cli.git_repo import git -# Files of common programming languages, by extension. Markdown, JSON and YAML aren't code: a format fixes their indentation. +# Files of common programming languages, by extension. The check skips Markdown, JSON and YAML, which are prose or data. CODE = re.compile(r".*\.(py|js|mjs|cjs|jsx|ts|tsx|rs|go|php|java|kt|kts|scala|rb|c|h|cc|cpp|hpp|cs|swift|sh|bash|lua|ex|exs|dart|vue|svelte)", re.IGNORECASE) # Committed copies of other people's code follow their authors' style. VENDORED = re.compile(r"(^|/)(vendor|node_modules|third_party)/") diff --git a/principles/technical-principles.md b/principles/technical-principles.md index 3157a948..50bcdedd 100644 --- a/principles/technical-principles.md +++ b/principles/technical-principles.md @@ -119,5 +119,5 @@ - Read config (credentials, hosts, paths) from CLI params or env vars, never hardcoded. * Indent with hard tabs by default. - Overriding it takes two things: a setting a tool reads (`.editorconfig` or a formatter's config, such as Prettier, `rustfmt.toml` or Biome) and a decision in the decision log that names the reason. A prose rule in `AGENTS.md`, or the existing files' habit, doesn't override it. - - Files whose format fixes their indentation, such as YAML (no tabs) or a spelling's JSON, are outside the rule. - - A file already indented with spaces keeps them until the project converts it or records the override, so no file mixes the two. `chunk-preflight` reports a project in that state where `.editorconfig`, `rustfmt.toml`, Prettier and Biome set nothing about it. + - A format that forbids tabs, such as YAML, and output a spec fixes, such as a JSON example it prints, are outside the rule. + - A file already indented with spaces keeps them until the project converts it or records the override, so no file mixes the two. `chunk-preflight` reports a project whose code is mostly indented with spaces where `.editorconfig`, `rustfmt.toml`, Prettier and Biome set nothing about it. From eb2c54ec948300e09769f2f19b19e3e73fc8bffd Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:10:58 +0100 Subject: [PATCH 33/45] Sort the imports of runs.py by their first binding --- bin/task_bench/runs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/task_bench/runs.py b/bin/task_bench/runs.py index ed327f16..e6316e06 100644 --- a/bin/task_bench/runs.py +++ b/bin/task_bench/runs.py @@ -8,11 +8,11 @@ import shutil import subprocess import typing +from task_bench.rust_test_modules import declared, homes, with_tests_of from mutate_changes.tool_process import failed, Ran from failure import Failure from mutate_changes.changed_lines import is_test from task_bench.api_proxy import PORT -from task_bench.rust_test_modules import declared, homes, with_tests_of MODEL = "claude-haiku-5-5" # Where each run's container mounts its copy of the code, and its home folder: the paths in a run's stream start there. From e3616bdd833777ca788fbc6bb92bf3dd226b86e8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:17:53 +0100 Subject: [PATCH 34/45] Finish item 542 in the plan --- CHANGELOG.md | 1 + todo.md | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4bce196..1cbfab72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `chunk-preflight` reports a project whose tracked code is mostly space-indented while no `.editorconfig` or formatter setting sets the indent, and the technical principles' hard-tabs default is overridden only by such a setting plus a recorded decision. - `chunk-pr push` waits for the forge to show the pushed commit as the head of the branch's open pull request before it asks for a review, and fails naming the pull request where the forge does not. - `chunk-pr merge` honours `merge = "human"` and `wait-for-approval` for a chunk whose recorded base is origin's default branch. - larv-review's claimed-output step runs each claim in a fresh clone, without the ignored files earlier runs wrote, and checks claims about what a command writes. diff --git a/todo.md b/todo.md index 3f0d51ef..88151c14 100644 --- a/todo.md +++ b/todo.md @@ -14,7 +14,6 @@ |---|---|---|---|---|---|---|---|---|---|---|---| | 477 | 0.17.0 | | question | **Rewrite `## Goals` and `## Audience` for a setup others install and run apart from their own `~/.claude`.** | 1 | 1 | 2 | 2 | 2 | | 0.0 | | 478 | 0.17.0 | | question | **Name the project, its repo and its two commands, today proposed as `do-release` and `do-epic`.** | 1 | 1 | 2 | 2 | 1 | | 0.0 | -| 542 | 0.17.0 | | | **Make chunk-preflight report a project whose code is space-indented with no `.editorconfig` or formatter setting that says so, and narrow the tabs principle to explicit overrides.** | 2 | 2 | 3 | 5 | 4 | 1.1 by 4 | 1.2 | | 523 | 0.17.0 | | | **Make the security pass and stability-reviewer check that a new secret's docs name its scope and its reach, such as the other repositories its account can use.** | 1 | 1 | 2 | 2 | 1 | 1.1 by 2 | 0.9 | | 547 | 0.17.0 | | | **Add a technical principle: tell a failure's cause from a status code or a typed error, never from a tool's message text unless the tool documents that text as unique to the cause.** | 1 | 2 | 2 | 3 | 1 | 1.1 by 2 | 0.9 | | 541 | 0.17.0 | | | **Find a Gitea pull request by its branch and head however many pull requests are newer, so `chunk-pr clean`, `chunk-pr merge` and `chunk-preflight` see an older one.** | 2 | 2 | 3 | 5 | 2 | 1 by 2 | 0.8 | @@ -119,24 +118,6 @@ Part of the standalone-install plan lilleman approved on 2026-11-20. `do-release Part of the standalone-install plan lilleman approved on 2026-11-20. Later items say `do-release` and `do-epic` for the names this item picks. The names set the install folders, such as `~/.config/do-release/`, so items 482, 485 and 496, and every item they block, wait for them. -### 542. Make chunk-preflight report a project whose code is space-indented with no `.editorconfig` or formatter setting that says so, and narrow the tabs principle to explicit overrides. - -`principles/technical-principles.md` says "Indent with hard tabs by default. A project's own settings win: `.editorconfig`, linter/formatter config, or the surrounding file's existing indentation." The last clause lets a first session set spaces and every later session follow it, and nothing checks that anyone chose it. adf-codec's `AGENTS.md` has said "Two-space indent" since its first commit, with no reason, and 177 code files, 14,500 indented lines, followed it. A survey of the projects on this machine on 2026-11-26 found the same in plainpages, scheduler (`rustfmt.toml` doesn't set `hard_tabs`), oss-opportunity-research, secondhand-watch and playwright-for-agents. Only plainpages-plugin-fastjira says so in an `.editorconfig`. - -Two changes, the tool first: - -- `chunk-preflight` prints one fact where the project's tracked code (the files its language tooling covers, not Markdown, JSON or YAML) has more space-indented than tab-indented lines, and neither an `.editorconfig` with `indent_style` nor a formatter setting (`rustfmt.toml` `hard_tabs`, Prettier `useTabs`, Biome `indentStyle`) says so. The fact names the principle and the two ways out: convert to tabs, or record the override in `.editorconfig` and a decision. It reports and never fails, since a client's repo belongs to its team. -- The principle's override clause counts only a setting a tool reads, `.editorconfig` or a formatter's config, plus a decision in `docs/decisions.md` that names the reason. A prose rule in `AGENTS.md`, or the existing files' habit, no longer overrides it. Output formats a spec fixes, such as a spelling's JSON, are outside the rule. - -Test it with a fake checkout per case: tabs, spaces with a setting, spaces without one, and a repo of Markdown only. - -Touches: - -- `bin/chunk_preflight/facts.py` -- `bin/chunk_preflight/gathered.py` -- `bin/chunk_preflight/test_chunk_preflight.py` -- `principles/technical-principles.md`: `* Indent with hard tabs by default.` (small) - ### 523. Make the security pass and stability-reviewer check that a new secret's docs name its scope and its reach, such as the other repositories its account can use. An outside reviewer found it on a client project's PR that added a secret: a Gitea token documented as able to run Actions on one repository, "and nothing wider". The token reaches every repository its owning account can, so the docs had to require a dedicated account with access to that repository only. Neither `/security-review` nor stability-reviewer raised it. Where a change adds a secret or a token, ask each to check that the doc beside it states what the credential can reach, not only what the change uses it for. From a5b75eab86077dd7c8ce1a6b19f0fe02849995f3 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:17:53 +0100 Subject: [PATCH 35/45] Finish item 547 in the plan --- CHANGELOG.md | 1 + todo.md | 13 ------------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cbfab72..e8838b6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- The technical principles ask code to read why a call failed from a status code, a documented exit code or a typed error, and not from message text. - `chunk-preflight` reports a project whose tracked code is mostly space-indented while no `.editorconfig` or formatter setting sets the indent, and the technical principles' hard-tabs default is overridden only by such a setting plus a recorded decision. - `chunk-pr push` waits for the forge to show the pushed commit as the head of the branch's open pull request before it asks for a review, and fails naming the pull request where the forge does not. - `chunk-pr merge` honours `merge = "human"` and `wait-for-approval` for a chunk whose recorded base is origin's default branch. diff --git a/todo.md b/todo.md index 88151c14..6394897f 100644 --- a/todo.md +++ b/todo.md @@ -15,7 +15,6 @@ | 477 | 0.17.0 | | question | **Rewrite `## Goals` and `## Audience` for a setup others install and run apart from their own `~/.claude`.** | 1 | 1 | 2 | 2 | 2 | | 0.0 | | 478 | 0.17.0 | | question | **Name the project, its repo and its two commands, today proposed as `do-release` and `do-epic`.** | 1 | 1 | 2 | 2 | 1 | | 0.0 | | 523 | 0.17.0 | | | **Make the security pass and stability-reviewer check that a new secret's docs name its scope and its reach, such as the other repositories its account can use.** | 1 | 1 | 2 | 2 | 1 | 1.1 by 2 | 0.9 | -| 547 | 0.17.0 | | | **Add a technical principle: tell a failure's cause from a status code or a typed error, never from a tool's message text unless the tool documents that text as unique to the cause.** | 1 | 2 | 2 | 3 | 1 | 1.1 by 2 | 0.9 | | 541 | 0.17.0 | | | **Find a Gitea pull request by its branch and head however many pull requests are newer, so `chunk-pr clean`, `chunk-pr merge` and `chunk-preflight` see an older one.** | 2 | 2 | 3 | 5 | 2 | 1 by 2 | 0.8 | | 545 | 0.17.0 | | | **Have chunk-preflight name each next-release item with no `Touches:` list while others wait, and have loop-claude launch a subagent that writes the lists before it starts the next chunk.** | 3 | 2 | 3 | 6 | 6 | 1.1 by 4 | 0.6 | | 539 | 0.17.0 | | | **Leave out of a `task-bench` fix a change Haiku makes to a Rust test kept in a file of its own.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 1 | 0.4 | @@ -122,18 +121,6 @@ Part of the standalone-install plan lilleman approved on 2026-11-20. Later items An outside reviewer found it on a client project's PR that added a secret: a Gitea token documented as able to run Actions on one repository, "and nothing wider". The token reaches every repository its owning account can, so the docs had to require a dedicated account with access to that repository only. Neither `/security-review` nor stability-reviewer raised it. Where a change adds a secret or a token, ask each to check that the doc beside it states what the credential can reach, not only what the change uses it for. -### 547. Add a technical principle: tell a failure's cause from a status code or a typed error, never from a tool's message text unless the tool documents that text as unique to the cause. - -An outside auto-reviewer found a fault that our passes missed. A script told a missing container image apart from one it couldn't read by matching the text a CLI printed on stderr. Older versions of that CLI print the same text for a missing image, a refused credential and a failed request. So the script read "no access" as "missing" and went on as if the image didn't exist. The stability and security passes both read the code and took the message at its word. - -The fix asked the registry's HTTP API for the status instead: 404 is missing, and any other failure stops the run. The principle makes that the rule. Where code branches on why a call failed, it reads a status code, an exit code the tool documents, or a typed error. It reads message text only where the tool documents that text as unique to one cause, and it treats every other failure as unknown, which stops the run rather than guessing. - -No deterministic check fits: a linter can't tell whether a string match on output decides a failure's cause. Reviewers apply the principles, so a principle is the first place that fits. - -Touches: - -- `principles/technical-principles.md`: `Handle errors explicitly, as values — avoid the exception path.` (small) - ### 541. Find a Gitea pull request by its branch and head however many pull requests are newer, so `chunk-pr clean`, `chunk-pr merge` and `chunk-preflight` see an older one. Today `pull_at` in `bin/forge/pulls.py` reads only Gitea's first page of 50 pull requests, open or closed, and looks for the branch among them. A pull request with 50 newer ones in that state is missed. PR #652 here merged after 50+ newer PRs had closed, and `chunk-pr clean` then said "no merged pull request from filing-prose-reentry", leaving the worktree and branch to remove by hand. The same lookup serves `open_pull`, so `ready` and `merge` miss an old open one too, and `chunk-preflight` misses a merged chunk's worktree. From 001dfcfc85a33130835f4fb63fa7981630221939 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:33:58 +0100 Subject: [PATCH 36/45] Test that the search for Rust test files leaves a link unread --- bin/task_bench/test_task_bench.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index b9252306..5e36a5aa 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -838,6 +838,11 @@ class CheckedTreeTest(unittest.TestCase): with self.subTest(name): self.assertEqual(rust_test_files(self.tree(name.replace(" ", "-"), files)), found) + def test_leaves_a_rust_link_unread_whatever_it_points_at_when_it_looks_for_test_files(self): + tree = self.tree("linked", {"src/lib.rs": self.DECLARING, "src/tests.rs": ""}) + os.symlink("missing.rs", os.path.join(tree, "src/ghost.rs")) + self.assertEqual(rust_test_files(tree), {"src/tests.rs"}) + def test_cannot_find_a_rust_test_file_that_is_not_where_its_declaration_puts_it_or_cannot_be_read_from_it(self): cases = { "missing": {"src/lib.rs": self.DECLARING}, From fb9ca7757b5669580b726e89348ad28389e783df Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 16:36:18 +0100 Subject: [PATCH 37/45] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20no=20findin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 71842a6a85559fd34a11614b751ae4bd051e492f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:05:37 +0100 Subject: [PATCH 38/45] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20a=20fix=20t?= =?UTF-8?q?hat=20drops=20a=20test=20file's=20declaration=20gets=20the=20pl?= =?UTF-8?q?anted=20file,=20and=20any=20file=20may=20stand=20beside=20or=20?= =?UTF-8?q?under=20its=20declarer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/runs.py | 13 ++++++------ bin/task_bench/rust_test_modules.py | 27 ++++++++++++------------ bin/task_bench/test_rust_test_modules.py | 23 ++++++++++++++++---- bin/task_bench/test_task_bench.py | 15 +++++++++---- 4 files changed, 50 insertions(+), 28 deletions(-) diff --git a/bin/task_bench/runs.py b/bin/task_bench/runs.py index e6316e06..3d94c29a 100644 --- a/bin/task_bench/runs.py +++ b/bin/task_bench/runs.py @@ -168,11 +168,12 @@ def checked_tree(planted: str, copy: str, into: str, rust_tests_planted: bool = """Makes at `into` the tree the tests check a fix in: `planted`, the code with the bug as Haiku got it, with each file that is no test as `copy` holds it after the fix. So a test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder, where Go's tests keep the output they expect. Where rust_tests_planted, a Rust file's inline `#[cfg(test)]` - modules stand as the planted file has them too, as `with_tests_of` says, and so does each Rust file that `rust_test_files` finds. + modules stand as the planted file has them too, as `with_tests_of` says, and so does each file that `rust_test_files` finds in + the planted tree. Raises OSError where a file cannot be copied.""" shutil.copytree(planted, into, symlinks=True) - # `rust_test_files` is None for a tree whose declarations it cannot resolve, which the bench passes over where it plants the bug. + # `rust_test_files` is None for a tree with a declaration whose file it can't find, and the bench plants no bug in such a tree. rust_tests = (rust_test_files(planted) or set()) if rust_tests_planted else set() before, after = set(entries(planted)), set(entries(copy)) for path in before - after: @@ -209,8 +210,8 @@ def of_tests(path: str, rust_tests: typing.AbstractSet[str] = frozenset()) -> bo def rust_test_files(tree: str) -> set[str] | None: - """The Rust files under tree that a `#[cfg(test)] mod name;` declaration names, by their paths from tree. None where a - declaration names no file there, or `declared` cannot tell a file's declarations. + """The Rust files under tree that a `#[cfg(test)] mod name;` declaration names, by their paths from tree. None where a declaration + names no file there, or a string or comment of a Rust file is never closed: the tree may hold a test file this can't find. Raises OSError where a file cannot be read.""" files = set(entries(tree)) @@ -222,10 +223,10 @@ def rust_test_files(tree: str) -> set[str] | None: if names is None: return None for name in names: - standing = [home for home in homes(path, name) if home in files] + standing = files.intersection(homes(path, name)) if not standing: return None - found.add(standing[0]) + found |= standing return found diff --git a/bin/task_bench/rust_test_modules.py b/bin/task_bench/rust_test_modules.py index 2ebed22c..1588b8b7 100644 --- a/bin/task_bench/rust_test_modules.py +++ b/bin/task_bench/rust_test_modules.py @@ -1,6 +1,6 @@ """The `#[cfg(test)]` modules of a Rust file, which stand in the file of the code they test or, as `mod name;` declares, in a file of -their own. Here are where each inline one is, which files hold the others, and a file with the modules of another file put in place -of its own. A file is bytes: a Rust file is UTF-8, and a module is found by ASCII text alone.""" +their own. Here are where each inline one is, which modules a file declares and where their files may stand, and a file with the +modules of another file put in place of its own. A file is bytes: a Rust file is UTF-8, and a module is found by ASCII text alone.""" import pathlib import re @@ -20,9 +20,7 @@ COMMENT_EDGE = re.compile(rb"/\*|\*/") # What follows the attribute that starts an inline module: any other attributes, an optional visibility, then `mod name {`. MODULE = re.compile(rb"\s*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*\{") # What follows the attribute that starts a module kept in a file of its own: any other attributes, an optional visibility, then `mod name;`. -DECLARATION = re.compile(rb"\s*(?P(?:#\[[^\]]*\]\s*)*)(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*;") -PATH_ATTRIBUTE = re.compile(rb"#\[\s*path\b") -KEEP_BESIDE = ("lib.rs", "main.rs", "mod.rs") +DECLARATION = re.compile(rb"\s*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P\w+)\s*;") def tells_apart(path: str, source: bytes) -> bool: @@ -59,8 +57,8 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: def declared(source: bytes) -> list[str] | None: - """The name of each `#[cfg(test)] mod name;` of source, a test module kept in a file of its own, in the order they stand. - None where a `#[path]` attribute moves such a file, or a string or comment is never closed.""" + """The name of each `#[cfg(test)] mod name;` of source, a test module kept in a file of its own, in the order they stand. None where + a string or comment is never closed.""" names = [] position = 0 while match := SCAN.search(source, position): @@ -68,18 +66,16 @@ def declared(source: bytes) -> list[str] | None: return None position = after if match.group() == b"#[cfg(test)]" and (declaration := DECLARATION.match(source, position)): - if PATH_ATTRIBUTE.search(declaration.group("attributes")): - return None names.append(declaration.group("name").decode()) return names def homes(path: str, name: str) -> list[str]: - """Where the file of the module `name`, declared in the Rust file at path, may stand, by its path from the same top. A crate root - (`lib.rs`, `main.rs`) and a `mod.rs` keep their modules beside them; any other file keeps them in a folder of its own name.""" + """Each place the file of the module `name`, declared in the Rust file at path, may stand, by its path from the same top. Rust keeps + it in the folder of the declaring file, or in a folder of that file's name where it is a module file, `a.rs` for `a/`; which of the + two the file is depends on what the crate's root is, so both count.""" declaring = pathlib.PurePosixPath(path) - folder = declaring.parent if declaring.name in KEEP_BESIDE else declaring.parent / declaring.stem - return [str(folder / f"{name}.rs"), str(folder / name / "mod.rs")] + return [str(folder / part) for folder in (declaring.parent, declaring.parent / declaring.stem) for part in (f"{name}.rs", f"{name}/mod.rs")] def after_token(source: bytes, match: re.Match[bytes]) -> int | None: @@ -121,7 +117,10 @@ def with_tests_of(planted: bytes, copy: bytes) -> bytes: Where planted's modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where planted has some and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module - to put them in.""" + to put them in. The same holds for the `mod name;` declarations of planted, whose files stand as planted: a fix that drops one + would leave its tests uncompiled.""" + if not set(declared(planted) or []) <= set(declared(copy) or []): + return planted before, after = modules(planted), modules(copy) # Haiku's file stands where planted's modules can't be told apart. The bench never plants a bug in such a file, and a guess at # which module is which could swap one test for another. Haiku's file is also what the check took before the bench put back diff --git a/bin/task_bench/test_rust_test_modules.py b/bin/task_bench/test_rust_test_modules.py index cfd977c5..6acb2e27 100644 --- a/bin/task_bench/test_rust_test_modules.py +++ b/bin/task_bench/test_rust_test_modules.py @@ -7,7 +7,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from task_bench import rust_test_modules -from task_bench.rust_test_modules import tells_apart +from task_bench.rust_test_modules import homes, tells_apart LIB = textwrap.dedent("""\ pub fn add(a: i32, b: i32) -> i32 { @@ -118,15 +118,20 @@ class DeclaredTest(unittest.TestCase): source = '// #[cfg(test)]\n// mod a;\n/* #[cfg(test)] mod b; */\nconst C: &str = "#[cfg(test)] mod c;";\nconst D: &str = r#"#[cfg(test)] mod d;"#;\n' self.assertEqual(declared(source), []) - def test_cannot_tell_where_a_declaration_moves_its_file_with_a_path_attribute(self): - self.assertIsNone(declared('#[cfg(test)]\n#[path = "elsewhere.rs"]\nmod tests;\n')) - def test_cannot_tell_where_a_string_or_comment_is_never_closed(self): for source in ("#[cfg(test)]\nmod tests;\nconst A: &str = \"\n", "/* open\n#[cfg(test)]\nmod tests;\n"): with self.subTest(source=source): self.assertIsNone(declared(source)) +class HomesTest(unittest.TestCase): + def test_lists_where_the_file_of_a_declared_module_may_stand(self): + self.assertEqual(homes("src/pick.rs", "tests"), ["src/tests.rs", "src/tests/mod.rs", "src/pick/tests.rs", "src/pick/tests/mod.rs"]) + + def test_lists_the_places_by_the_path_from_the_top_of_a_file_there(self): + self.assertEqual(homes("lib.rs", "t"), ["t.rs", "t/mod.rs", "lib/t.rs", "lib/t/mod.rs"]) + + class TellsApartTest(unittest.TestCase): def test_tells_the_modules_of_a_rust_file_apart_where_they_can_be(self): self.assertEqual([tells_apart("lib.rs", b"fn a() {}"), tells_apart("lib.rs", b"fn a() {")], [True, False]) @@ -136,6 +141,16 @@ class TellsApartTest(unittest.TestCase): class WithTestsOfTest(unittest.TestCase): + def test_takes_the_planted_file_where_the_fix_dropped_a_declaration_of_a_test_file(self): + planted = "fn a() { 1 }\n#[cfg(test)]\nmod tests;\n#[cfg(test)]\nmod more;\n" + for name, fixed in {"dropped": "fn a() { 2 }\n", "one of two kept": "fn a() { 2 }\n#[cfg(test)]\nmod more;\n", "string never closed": 'fn a() { "\n#[cfg(test)]\nmod tests;\n#[cfg(test)]\nmod more;\n'}.items(): + with self.subTest(name): + self.assertEqual(with_tests_of(planted, fixed), planted) + + def test_takes_the_fixed_file_where_it_keeps_each_declaration_and_adds_one(self): + fixed = "fn a() { 2 }\n#[cfg(test)]\nmod more;\n#[cfg(test)]\nmod tests;\n" + self.assertEqual(with_tests_of("fn a() { 1 }\n#[cfg(test)]\nmod tests;\n", fixed), fixed) + def test_takes_the_code_as_fixed_and_the_tests_as_planted(self): planted = LIB.replace("a + b", "a - b") fixed = LIB.replace("assert_eq!(add(1, 2), 3);", "assert_eq!(add(1, 2), 0);") diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 5e36a5aa..199569c7 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -338,7 +338,7 @@ class BenchTest(unittest.TestCase): # Passing tests with the bug planted: no message to tell Haiku. (self.repo / "calc_test.go").write_text("exit 0\n") self.commit("Tests that pass with the bug") - self.assertEqual(self.bench(), Failure("None of the 2 mutants the tests kill becomes a bug: each is on a line the head changed, or the test it fails doesn't print a message.")) + self.assertEqual(self.bench(), Failure("None of the 2 mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, in a Rust file, a `#[cfg(test)] mod name;` of the tree names a file the bench can't find.")) def test_a_run_the_api_refuses_fails_the_bench_and_still_removes_what_it_made(self): self.env["FAKE_REFUSED_FROM"] = "1" @@ -639,7 +639,7 @@ class RunOutcomesTest(unittest.TestCase): bench = self.rust_bench({"src/lib.rs": self.ADD, "src/tests.rs": "", "src/other.rs": ""}) (self.tree / "src/other.rs").chmod(0) self.addCleanup((self.tree / "src/other.rs").chmod, 0o644) - self.assertFailsWith(main.planted(bench, 1, self.ADDING), "could not find the Rust test files beside src/lib.rs: ") + self.assertFailsWith(main.planted(bench, 1, self.ADDING), "could not read the Rust files for the mutant in src/lib.rs: ") class ContainersTest(unittest.TestCase): @@ -808,6 +808,12 @@ class CheckedTreeTest(unittest.TestCase): checked_tree(planted, copy, str(self.root / "check")) self.assertEqual(self.held("check"), {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n", "src/tests.rs": "old tests", "src/other.rs": "fixed"}) + def test_takes_the_planted_rust_file_where_the_fix_dropped_the_declaration_of_a_test_file(self): + planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) + copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n", "src/tests.rs": "old tests"}) + checked_tree(planted, copy, str(self.root / "check")) + self.assertEqual(self.held("check"), {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) + def test_takes_a_rust_test_file_the_fix_deleted_as_planted(self): planted = self.tree("planted", {"src/lib.rs": self.DECLARING, "src/tests.rs": "old tests"}) copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests;\n"}) @@ -831,6 +837,7 @@ class CheckedTreeTest(unittest.TestCase): "beside a crate root": ({"src/lib.rs": self.DECLARING, "src/tests.rs": ""}, {"src/tests.rs"}), "as a folder with a mod.rs": ({"src/main.rs": self.DECLARING, "src/tests/mod.rs": ""}, {"src/tests/mod.rs"}), "in the folder of a module file": ({"src/pick.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), + "beside another crate root": ({"src/bin/tool.rs": self.DECLARING, "src/bin/tests.rs": ""}, {"src/bin/tests.rs"}), "beside a mod.rs": ({"src/pick/mod.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), "declared by no file": ({"src/lib.rs": "fn a() {}\n", "src/tests.rs": ""}, set()), } @@ -843,11 +850,11 @@ class CheckedTreeTest(unittest.TestCase): os.symlink("missing.rs", os.path.join(tree, "src/ghost.rs")) self.assertEqual(rust_test_files(tree), {"src/tests.rs"}) - def test_cannot_find_a_rust_test_file_that_is_not_where_its_declaration_puts_it_or_cannot_be_read_from_it(self): + def test_cannot_find_a_rust_test_file_that_is_not_where_its_declaration_puts_it_or_cannot_be_read_from_the_tree(self): cases = { "missing": {"src/lib.rs": self.DECLARING}, - "beside a module file, where only a crate root has its modules": {"src/pick.rs": self.DECLARING, "src/tests.rs": ""}, "moved by a path attribute": {"src/lib.rs": '#[cfg(test)]\n#[path = "t.rs"]\nmod tests;\n', "src/t.rs": ""}, + "inside an inline module": {"src/lib.rs": "mod a {\n#[cfg(test)]\nmod tests;\n}\n", "src/a/tests.rs": ""}, "in a declaring file whose string is never closed": {"src/lib.rs": '#[cfg(test)]\nmod tests;\nconst A: &str = "\n', "src/tests.rs": ""}, } for name, files in cases.items(): From cd916e58e3593b5f71ea8aa6c87fa1ac6edb7a92 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:05:37 +0100 Subject: [PATCH 39/45] =?UTF-8?q?Answer=20product-owner=20round=201:=201?= =?UTF-8?q?=20=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20the=20he?= =?UTF-8?q?lp=20and=20the=20no-bug=20message=20say=20which=20tree=20makes?= =?UTF-8?q?=20a=20Rust=20mutant=20pass=20over?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/main.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 826997c2..a6558e03 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -38,14 +38,14 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. A test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder. The bench tells a test by its path: a folder named `test`, `tests` or `__tests__`, or a file named `test_*.py`, `*_test.py`, `*_test.go`, `*.test.*` or `*.spec.*`. A test of any other name counts as code, such as `src/PickTest.php` or - `src/pick-test.js`, so Haiku's change to it stands. In a Rust file, each - inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. Where the planted file has such - modules and Haiku's file lacks one of them, or its modules cannot be told apart, the planted file stands whole; where the planted - file has none, or its modules cannot be told apart, Haiku's stands. A Rust mutant whose file's modules cannot be told apart, as where two share a name or a brace, string or comment - is never closed, is passed over. A Rust file that a `#[cfg(test)] mod name;` in another file of the planted tree names, as - `src/name.rs` or `src/name/mod.rs` beside a `lib.rs`, `main.rs` or `mod.rs`, or in the folder of any other file's name, is a - test: it stands as the planted tree has it, and no mutant is planted in it. A Rust mutant in a tree where such a declaration - names no file there, as one that `#[path]` moves does, is passed over. + `src/pick-test.js`, so Haiku's change to it stands. In a Rust file, each inline `#[cfg(test)]` module stands as the planted + file has it, and the rest is as Haiku left it. So does each `#[cfg(test)] mod name;` the planted file declares, and the file it + names: `name.rs` or `name/mod.rs`, in the declaring file's folder or in a folder named for that file without `.rs`. Where the + planted file has such modules or declarations and Haiku's file lacks one of them, or its modules cannot be told apart, the + planted file stands whole; where the planted file has none, or its modules cannot be told apart, Haiku's stands. A Rust mutant + whose file's modules cannot be told apart, as where two share a name or a brace, string or comment is never closed, is passed + over. So is each Rust mutant of a tree where a `#[cfg(test)] mod name;` names no file the bench finds, or where a Rust file has a + string or comment that is never closed. No bug is planted in a file that such a declaration names. --image is the project's development image, such as golang:1.27.4. The bench adds Claude Code to it, as its installer installs it, so the image needs curl and bash; the result names the version. Haiku works in that image. So does --test: sh runs that text at @@ -529,7 +529,7 @@ def planted_tasks(bench: Bench, mutants: list[Mutant], seed: int, bugs: int) -> return task tasks += [task] if task else [] if not tasks: - return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, or the test it fails doesn't print a message.") + return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, in a Rust file, a `#[cfg(test)] mod name;` of the tree names a file the bench can't find.") return Planned(tasks, [] if len(tasks) == bugs else [f"Planted {len(tasks)} of the {bugs} bugs asked for: no other mutant the tests kill becomes one."], {"seed": seed}) @@ -590,9 +590,9 @@ def planted(bench: Bench, number: int, mutant: Mutant) -> Task | Failure | None: # The check keeps a Rust file's test modules as planted, which it can only do where it tells them apart. if bugs is None or not all(tells_apart(mutant.path, source) for source in bugs.values()): return None - # ... and a Rust test in a file of its own, which it can only keep where it finds each such file. + # ... and the Rust test files of each side's tree, which it keeps only where it finds every one. A mutant in one of them is no bug. if mutant.path.endswith(".rs"): - standing = on_disk(f"find the Rust test files beside {mutant.path}", lambda: [rust_test_files(tree) for tree in bench.trees.values()]) + standing = on_disk(f"read the Rust files for the mutant in {mutant.path}", lambda: [rust_test_files(tree) for tree in bench.trees.values()]) if isinstance(standing, Failure): return standing if any(tests is None or mutant.path in tests for tests in standing): From a720f461c21b1ae2baa41799e1261a87b452f4d5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:05:37 +0100 Subject: [PATCH 40/45] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(0=20misread);=20docstrings,?= =?UTF-8?q?=20comments=20and=20help=20reworded=20in=20the=20two=20commits?= =?UTF-8?q?=20above?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 86efe8fa57f96b105aa995d41bf864c58c034795 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:11:30 +0100 Subject: [PATCH 41/45] =?UTF-8?q?Answer=20product-owner=20round=202:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20name=20t?= =?UTF-8?q?he=20Rust=20causes=20in=20the=20no-bug=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/main.py | 2 +- bin/task_bench/test_task_bench.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index a6558e03..7dba4ee9 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -529,7 +529,7 @@ def planted_tasks(bench: Bench, mutants: list[Mutant], seed: int, bugs: int) -> return task tasks += [task] if task else [] if not tasks: - return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, in a Rust file, a `#[cfg(test)] mod name;` of the tree names a file the bench can't find.") + return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, for a Rust mutant, it stands in a test file or the tree holds a `#[cfg(test)] mod name;` that names no file the bench finds or a string or comment that is never closed.") return Planned(tasks, [] if len(tasks) == bugs else [f"Planted {len(tasks)} of the {bugs} bugs asked for: no other mutant the tests kill becomes one."], {"seed": seed}) diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 199569c7..7498f8b1 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -338,7 +338,7 @@ class BenchTest(unittest.TestCase): # Passing tests with the bug planted: no message to tell Haiku. (self.repo / "calc_test.go").write_text("exit 0\n") self.commit("Tests that pass with the bug") - self.assertEqual(self.bench(), Failure("None of the 2 mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, in a Rust file, a `#[cfg(test)] mod name;` of the tree names a file the bench can't find.")) + self.assertEqual(self.bench(), Failure("None of the 2 mutants the tests kill becomes a bug: each is on a line the head changed, the test it fails doesn't print a message, or, for a Rust mutant, it stands in a test file or the tree holds a `#[cfg(test)] mod name;` that names no file the bench finds or a string or comment that is never closed.")) def test_a_run_the_api_refuses_fails_the_bench_and_still_removes_what_it_made(self): self.env["FAKE_REFUSED_FROM"] = "1" From ce92bedde98eb009644a84de533c9d74af2e5596 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:11:31 +0100 Subject: [PATCH 42/45] =?UTF-8?q?Answer=20prose=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(0=20misread);=20say=20what?= =?UTF-8?q?=20with=5Ftests=5Fof=20returns=20first,=20and=20word=20the=20Ru?= =?UTF-8?q?st=20help=20and=20docstrings=20plainly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/main.py | 7 ++++--- bin/task_bench/rust_test_modules.py | 16 ++++++++-------- bin/task_bench/test_rust_test_modules.py | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 7dba4ee9..9d4375be 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -40,9 +40,10 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. `*_test.go`, `*.test.*` or `*.spec.*`. A test of any other name counts as code, such as `src/PickTest.php` or `src/pick-test.js`, so Haiku's change to it stands. In a Rust file, each inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. So does each `#[cfg(test)] mod name;` the planted file declares, and the file it - names: `name.rs` or `name/mod.rs`, in the declaring file's folder or in a folder named for that file without `.rs`. Where the - planted file has such modules or declarations and Haiku's file lacks one of them, or its modules cannot be told apart, the - planted file stands whole; where the planted file has none, or its modules cannot be told apart, Haiku's stands. A Rust mutant + names: `name.rs` or `name/mod.rs`, in the declaring file's folder or in a folder named for that file without `.rs`. Where + Haiku's file lacks a module or declaration of the planted file's, or the planted file has inline modules and Haiku's cannot be + told apart, the planted file stands whole; where the planted file's inline modules cannot be told apart, or it has none and + Haiku's cannot be told apart, Haiku's stands. A Rust mutant whose file's modules cannot be told apart, as where two share a name or a brace, string or comment is never closed, is passed over. So is each Rust mutant of a tree where a `#[cfg(test)] mod name;` names no file the bench finds, or where a Rust file has a string or comment that is never closed. No bug is planted in a file that such a declaration names. diff --git a/bin/task_bench/rust_test_modules.py b/bin/task_bench/rust_test_modules.py index 1588b8b7..c5759683 100644 --- a/bin/task_bench/rust_test_modules.py +++ b/bin/task_bench/rust_test_modules.py @@ -57,7 +57,7 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: def declared(source: bytes) -> list[str] | None: - """The name of each `#[cfg(test)] mod name;` of source, a test module kept in a file of its own, in the order they stand. None where + """The name of each `#[cfg(test)] mod name;` of source, in the order they stand. The module's code is in a file of its own. None where a string or comment is never closed.""" names = [] position = 0 @@ -71,9 +71,9 @@ def declared(source: bytes) -> list[str] | None: def homes(path: str, name: str) -> list[str]: - """Each place the file of the module `name`, declared in the Rust file at path, may stand, by its path from the same top. Rust keeps - it in the folder of the declaring file, or in a folder of that file's name where it is a module file, `a.rs` for `a/`; which of the - two the file is depends on what the crate's root is, so both count.""" + """Each place the file of the module `name`, declared in the Rust file at path, may stand, as paths from the same top: beside the + declaring file, or in a folder named for it without `.rs`. Which of the two holds depends on the kind of file the declarer is, which + this doesn't know, so both count.""" declaring = pathlib.PurePosixPath(path) return [str(folder / part) for folder in (declaring.parent, declaring.parent / declaring.stem) for part in (f"{name}.rs", f"{name}/mod.rs")] @@ -115,10 +115,10 @@ def with_tests_of(planted: bytes, copy: bytes) -> bytes: """copy with each of its test modules replaced by the one of that name in planted, and each that planted lacks left out. So a test a fix changed, removed or added doesn't count. - Where planted's modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where - planted has some and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module - to put them in. The same holds for the `mod name;` declarations of planted, whose files stand as planted: a fix that drops one - would leave its tests uncompiled.""" + Where copy lacks a `mod name;` declaration of planted's, or cannot have its declarations told apart, planted is returned: the file + of that module stands as planted, and a fix that drops the declaration would leave its tests uncompiled. Otherwise, where planted's + modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where planted has some + and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module to put them in.""" if not set(declared(planted) or []) <= set(declared(copy) or []): return planted before, after = modules(planted), modules(copy) diff --git a/bin/task_bench/test_rust_test_modules.py b/bin/task_bench/test_rust_test_modules.py index 6acb2e27..6fd3fef9 100644 --- a/bin/task_bench/test_rust_test_modules.py +++ b/bin/task_bench/test_rust_test_modules.py @@ -6,8 +6,8 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from task_bench import rust_test_modules from task_bench.rust_test_modules import homes, tells_apart +from task_bench import rust_test_modules LIB = textwrap.dedent("""\ pub fn add(a: i32, b: i32) -> i32 { From f5940f265d97adc250e81960aed76e80638292a2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:38:20 +0100 Subject: [PATCH 43/45] Test that rust_test_files gathers the files of every declaring file --- bin/task_bench/test_task_bench.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 7498f8b1..15b669d8 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -839,6 +839,7 @@ class CheckedTreeTest(unittest.TestCase): "in the folder of a module file": ({"src/pick.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), "beside another crate root": ({"src/bin/tool.rs": self.DECLARING, "src/bin/tests.rs": ""}, {"src/bin/tests.rs"}), "beside a mod.rs": ({"src/pick/mod.rs": self.DECLARING, "src/pick/tests.rs": ""}, {"src/pick/tests.rs"}), + "declared in two files": ({"src/lib.rs": self.DECLARING, "src/tests.rs": "", "src/pick.rs": self.DECLARING.replace("tests", "checks"), "src/pick/checks.rs": ""}, {"src/tests.rs", "src/pick/checks.rs"}), "declared by no file": ({"src/lib.rs": "fn a() {}\n", "src/tests.rs": ""}, set()), } for name, (files, found) in cases.items(): From 814779c9a137d301f3a28477944b519470d78b68 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 17:43:33 +0100 Subject: [PATCH 44/45] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20compare=20e?= =?UTF-8?q?ach=20test=20declaration's=20whole=20text,=20so=20an=20attribut?= =?UTF-8?q?e=20a=20fix=20adds=20to=20it=20counts=20as=20a=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/task_bench/main.py | 2 +- bin/task_bench/runs.py | 6 +++--- bin/task_bench/rust_test_modules.py | 18 ++++++++++-------- bin/task_bench/test_rust_test_modules.py | 14 ++++++++++++-- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 9d4375be..0267c490 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -41,7 +41,7 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream. `src/pick-test.js`, so Haiku's change to it stands. In a Rust file, each inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. So does each `#[cfg(test)] mod name;` the planted file declares, and the file it names: `name.rs` or `name/mod.rs`, in the declaring file's folder or in a folder named for that file without `.rs`. Where - Haiku's file lacks a module or declaration of the planted file's, or the planted file has inline modules and Haiku's cannot be + Haiku's file lacks a module of the planted file's or a declaration as written there, or the planted file has inline modules and Haiku's cannot be told apart, the planted file stands whole; where the planted file's inline modules cannot be told apart, or it has none and Haiku's cannot be told apart, Haiku's stands. A Rust mutant whose file's modules cannot be told apart, as where two share a name or a brace, string or comment is never closed, is passed diff --git a/bin/task_bench/runs.py b/bin/task_bench/runs.py index 3d94c29a..85d380f9 100644 --- a/bin/task_bench/runs.py +++ b/bin/task_bench/runs.py @@ -219,10 +219,10 @@ def rust_test_files(tree: str) -> set[str] | None: for path in sorted(files): if not path.endswith(".rs") or os.path.islink(os.path.join(tree, path)): continue - names = declared(pathlib.Path(tree, path).read_bytes()) - if names is None: + declarations = declared(pathlib.Path(tree, path).read_bytes()) + if declarations is None: return None - for name in names: + for name, _ in declarations: standing = files.intersection(homes(path, name)) if not standing: return None diff --git a/bin/task_bench/rust_test_modules.py b/bin/task_bench/rust_test_modules.py index c5759683..c32a3a04 100644 --- a/bin/task_bench/rust_test_modules.py +++ b/bin/task_bench/rust_test_modules.py @@ -56,18 +56,19 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None: return found if depth == 0 and inside is None else None -def declared(source: bytes) -> list[str] | None: - """The name of each `#[cfg(test)] mod name;` of source, in the order they stand. The module's code is in a file of its own. None where +def declared(source: bytes) -> list[tuple[str, str]] | None: + """Each `#[cfg(test)] mod name;` of source, in the order they stand, as the module's name and the declaration's text from the + `#[cfg(test)]` to the `;` with its spaces and newlines squeezed to one space. The module's code is in a file of its own. None where a string or comment is never closed.""" - names = [] + found = [] position = 0 while match := SCAN.search(source, position): if (after := after_token(source, match)) is None: return None position = after if match.group() == b"#[cfg(test)]" and (declaration := DECLARATION.match(source, position)): - names.append(declaration.group("name").decode()) - return names + found.append((declaration.group("name").decode(), " ".join(source[match.start():declaration.end()].decode().split()))) + return found def homes(path: str, name: str) -> list[str]: @@ -115,11 +116,12 @@ def with_tests_of(planted: bytes, copy: bytes) -> bytes: """copy with each of its test modules replaced by the one of that name in planted, and each that planted lacks left out. So a test a fix changed, removed or added doesn't count. - Where copy lacks a `mod name;` declaration of planted's, or cannot have its declarations told apart, planted is returned: the file - of that module stands as planted, and a fix that drops the declaration would leave its tests uncompiled. Otherwise, where planted's + Where copy lacks a `mod name;` declaration of planted's, as written, or cannot have its declarations told apart, planted is + returned: the file of that module stands as planted, and a fix that drops the declaration or adds an attribute such as `#[path]` + to it would leave its tests uncompiled or unrun. Otherwise, where planted's modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where planted has some and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module to put them in.""" - if not set(declared(planted) or []) <= set(declared(copy) or []): + if not {text for _, text in declared(planted) or []} <= {text for _, text in declared(copy) or []}: return planted before, after = modules(planted), modules(copy) # Haiku's file stands where planted's modules can't be told apart. The bench never plants a bug in such a file, and a guess at diff --git a/bin/task_bench/test_rust_test_modules.py b/bin/task_bench/test_rust_test_modules.py index 6fd3fef9..83e7ecf1 100644 --- a/bin/task_bench/test_rust_test_modules.py +++ b/bin/task_bench/test_rust_test_modules.py @@ -103,13 +103,13 @@ class ModulesTest(unittest.TestCase): self.assertIsNone(modules(source)) -def declared(source: str) -> list[str] | None: +def declared(source: str) -> list[tuple[str, str]] | None: return rust_test_modules.declared(source.encode()) class DeclaredTest(unittest.TestCase): def test_lists_each_test_module_the_file_declares_without_a_body(self): - self.assertEqual(declared("#[cfg(test)]\nmod tests;\n#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks;\n"), ["tests", "checks"]) + self.assertEqual(declared("#[cfg(test)]\nmod tests;\n#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks;\n"), [("tests", "#[cfg(test)] mod tests;"), ("checks", "#[cfg(test)] #[allow(dead_code)] pub(crate) mod checks;")]) def test_leaves_out_an_inline_module_and_a_declaration_that_is_no_test_module(self): self.assertEqual(declared(LIB + "mod util;\n#[cfg(feature = \"x\")]\nmod extra;\n"), []) @@ -147,6 +147,16 @@ class WithTestsOfTest(unittest.TestCase): with self.subTest(name): self.assertEqual(with_tests_of(planted, fixed), planted) + def test_takes_the_planted_file_where_the_fix_keeps_a_declaration_but_changes_it(self): + planted = "fn a() { 1 }\n#[cfg(test)]\nmod tests;\n" + for name, declaration in {"never compiled": "#[cfg(test)]\n#[cfg(any())]\nmod tests;", "another file": '#[cfg(test)]\n#[path = "empty.rs"]\nmod tests;', "renamed": "#[cfg(test)]\nmod other;"}.items(): + with self.subTest(name): + self.assertEqual(with_tests_of(planted, f"fn a() {{ 2 }}\n{declaration}\n"), planted) + + def test_takes_the_fixed_file_where_it_keeps_a_declaration_with_other_spacing(self): + fixed = "fn a() { 2 }\n#[cfg(test)] mod tests;\n" + self.assertEqual(with_tests_of("fn a() { 1 }\n#[cfg(test)]\nmod tests;\n", fixed), fixed) + def test_takes_the_fixed_file_where_it_keeps_each_declaration_and_adds_one(self): fixed = "fn a() { 2 }\n#[cfg(test)]\nmod more;\n#[cfg(test)]\nmod tests;\n" self.assertEqual(with_tests_of("fn a() { 1 }\n#[cfg(test)]\nmod tests;\n", fixed), fixed) From 177122f18abf14670f46e93479cc341928cdcf9a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 27 Nov 2026 18:44:25 +0100 Subject: [PATCH 45/45] Finish item 539 in the plan --- CHANGELOG.md | 1 + todo.md | 13 ------------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8838b6b..929dd94b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- task-bench leaves out of a fix a change Haiku makes to a Rust test kept in a file of its own, `#[cfg(test)] mod name;` and the file it names, and plants no bug in that file. - The technical principles ask code to read why a call failed from a status code, a documented exit code or a typed error, and not from message text. - `chunk-preflight` reports a project whose tracked code is mostly space-indented while no `.editorconfig` or formatter setting sets the indent, and the technical principles' hard-tabs default is overridden only by such a setting plus a recorded decision. - `chunk-pr push` waits for the forge to show the pushed commit as the head of the branch's open pull request before it asks for a review, and fails naming the pull request where the forge does not. diff --git a/todo.md b/todo.md index 6394897f..44557cbe 100644 --- a/todo.md +++ b/todo.md @@ -17,7 +17,6 @@ | 523 | 0.17.0 | | | **Make the security pass and stability-reviewer check that a new secret's docs name its scope and its reach, such as the other repositories its account can use.** | 1 | 1 | 2 | 2 | 1 | 1.1 by 2 | 0.9 | | 541 | 0.17.0 | | | **Find a Gitea pull request by its branch and head however many pull requests are newer, so `chunk-pr clean`, `chunk-pr merge` and `chunk-preflight` see an older one.** | 2 | 2 | 3 | 5 | 2 | 1 by 2 | 0.8 | | 545 | 0.17.0 | | | **Have chunk-preflight name each next-release item with no `Touches:` list while others wait, and have loop-claude launch a subagent that writes the lists before it starts the next chunk.** | 3 | 2 | 3 | 6 | 6 | 1.1 by 4 | 0.6 | -| 539 | 0.17.0 | | | **Leave out of a `task-bench` fix a change Haiku makes to a Rust test kept in a file of its own.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 1 | 0.4 | | 544 | 0.17.0 | | | **Leave out of a `task-bench` fix a change Haiku makes to a PHP or JavaScript test that PHPUnit or `node --test` finds by a name `is_test` does not know.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 1 | 0.4 | | 480 | 0.18.0 | | owner | **Resolve every path the tools use in one module: the release root (the folder the running code ships in), the config folder, the state folder and the Claude home. Then only that module names `~/.claude`, and the loop still runs from `~/.claude`.** | 3 | 2 | 3 | 6 | 6 | 1.6 by 3, code health by 3 | 2.4 | | 481 | 0.18.0 | 480 | owner | **Put the release's tools on `PATH` for every session the loop starts and every hook it runs, name them bare in the prose in place of `~/.claude/bin/`, and refuse the old spelling in new prose.** | 3 | 2 | 3 | 6 | 6 | 1.4 by 2, code health by 2 | 1.6 | @@ -144,18 +143,6 @@ Three changes: Test each with a fake plan: all lists present, one missing with other items waiting, one missing alone in its release, and a list the item's edit made stale is left alone. -### 539. Leave out of a `task-bench` fix a change Haiku makes to a Rust test kept in a file of its own. - -Rust may keep its unit tests out of line: `#[cfg(test)] mod tests;` in `src/lib.rs`, the tests in `src/tests.rs`. `mutate_changes.changed_lines.is_test` tells a test by a folder named `test`, `tests` or `__tests__`, or by a file name such as `test_*.py` or `*_test.go`, so `src/tests.rs` counts as code, and `checked_tree` in `bin/task_bench/runs.py` takes it as Haiku left it. A fix that edits or deletes the failing test there passes. The help's Check paragraph says so. It holds at the base and at the head alike. - -Recommended: treat as a test a `.rs` file that a `#[cfg(test)] mod ;` declaration in another file of the planted tree names (src/.rs or src//mod.rs, beside the declaring file), found with the scanner in `bin/task_bench/rust_test_modules.py`; where the file cannot be found, pass the mutant over. A product-owner / stability finding on item 532's chunk raised this. Changing `is_test` itself would change what `mutate-changes` skips, so keep the change inside task-bench. - -Touches: -- `bin/task_bench/runs.py`: `of_tests`, `checked_tree` (small) -- `bin/task_bench/rust_test_modules.py` -- `bin/task_bench/test_task_bench.py` -- `bin/task_bench/main.py`: lines 30-37 - ### 544. Leave out of a `task-bench` fix a change Haiku makes to a PHP or JavaScript test that PHPUnit or `node --test` finds by a name `is_test` does not know. PHPUnit finds a test by `*Test.php`, wherever it stands, and `node --test` also by `*-test.js`, `*_test.js`, `test-*.js` and `test.js`, with `.ts`, `.mjs` and `.cjs` alike. `mutate_changes.changed_lines.is_test` tells a test by a folder named `test`, `tests` or `__tests__`, or by a name such as `*.test.*`, so `src/PickTest.php` and `src/pick-test.js` count as code. `checked_tree` in `bin/task_bench/runs.py` then takes such a file as Haiku left it, so a fix that edits or deletes the failing test passes, at both sides alike, and `place_files` in `bin/task_bench/bugs/plant.py` may hand the file to the mutation tool as code. The help's Check paragraph says so.