@jesdi/skills 0.0.58 → 0.0.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jesdi/skills",
3
- "version": "0.0.58",
3
+ "version": "0.0.60",
4
4
  "description": "jesdi's agent skills (content package consumed by @jesdi/skills-cli)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -42,7 +42,7 @@ and do not know about the run, except `driver_run.py`, which the three deciding
42
42
  - **A check before the first agent returns a list of errors**, so the operator sees all of them at one time
43
43
  (exit 3). Examples: `precondition_errors`, `driver_tickets.parse`, `driver_report.validate`.
44
44
  - **The modules that do not know about the run return a result, not `Blocked`.** Some return `""` or the reason
45
- as a string (`driver_merge.refused`, `driver_merge.land`); the deciding module raises.
45
+ as a string (`driver_merge.land`), or what they found (`driver_merge.refused`); the deciding module raises.
46
46
  - A slot is a worktree. Slot 1 is the PR worktree; the others are in `.agent/worktrees/`.
47
47
  - A number of a ticket is a string (`"03"`). `FINAL` is used in its place for the end of run.
48
48
 
@@ -80,6 +80,10 @@ and do not know about the run, except `driver_run.py`, which the three deciding
80
80
  a ticket lands (`driver_merge.refused`): the tree that lands must have each of them as the PR tip has it. A
81
81
  ticket's test-writer may change one only when it lists it. So a review finding on such a file goes to a correction
82
82
  too: a fixer's change there is put back, and the ticket would loop until BLOCKED (issue #116).
83
+ - A refused landing asks a `merged-locked-file` question. `driver._rulings` applies its answers at the next landing:
84
+ `restore` is a commit of the driver (`Run.restore_merged_files`), and `adopt` adds the file to the ticket's
85
+ `locked` only when the ticket lands. A red merge gate after a ruling takes the restore commit back and asks again
86
+ (`driver._red_landing`); `driver_decisions.question` leaves out the option that was tried.
83
87
  - A conflict resolution, of a merge or of the rebase, may not change a locked file.
84
88
 
85
89
  ### The PR branch
@@ -146,6 +150,12 @@ and do not know about the run, except `driver_run.py`, which the three deciding
146
150
  - A reviewer or a correctness pass that reports BLOCKED or NEEDS_CONTEXT raises `driver_run.Stopped`, which
147
151
  carries the report. `driver_fixloop._run_reviewers` turns it into a `review-stopped` question, or, after an
148
152
  `accept` ruling on that role (`driver_decisions.accepted`), uses the report as it is.
153
+ - An implementer or a fixer that reports BLOCKED or NEEDS_CONTEXT asks a question in `Run._ask_stop`: `locked-test`
154
+ for a contradicted locked test, else `implementer-stopped` or `fixer-stopped`. The stop of a fixer sets the round
155
+ back by one, so its `retry` (gate and review the tip, then a fixer) runs the same round again.
156
+ - An implementer or a fixer with nothing to change reports DONE with no commit (`driver_report._unchanged_errors`):
157
+ the branch did not move, the tree is clean, and a concern says why. The driver gates and reviews that tip as it
158
+ would a new one.
149
159
  - The correctness prompt carries the checks of `review-diff` (`driver_review.checks`): the pass reads files only
150
160
  from git at the tip and from `.agent/`, and a project-local install sits in an ignored directory.
151
161
 
@@ -57,7 +57,7 @@ Default timeouts in minutes: explorer 30, test-writer 30, implementer 90, review
57
57
  |---|---|
58
58
  | 0 | Done: every ticket is merged and no question is open. Also the end of a valid `--dry-run`. In local mode without `--push`, nothing is pushed. |
59
59
  | 1 | A ticket is BLOCKED, or the end of run is BLOCKED. The other tickets ran as far as they could. |
60
- | 2 | Parked: a question of kind `locked-test`, `locked-test-again`, `review-stopped` or `final-finding` is open. Exit 2 wins over exit 1. |
60
+ | 2 | Parked: a question of kind `locked-test`, `locked-test-again`, `review-stopped`, `implementer-stopped`, `fixer-stopped`, `merged-locked-file` or `final-finding` is open. Exit 2 wins over exit 1. |
61
61
  | 3 | Invalid input or a failed precondition: a usage error, a ticket error, a model error, an uncommitted change, a slot that cannot be made, another driver that runs on the same PR branch. No agent starts. The one exception: a review page that cannot be written gives exit 3 at the end of a run, after agents ran. |
62
62
  | 4 | Stopped: the CLI of an agent failed two times and wrote no report (for example, the account cannot use the model). The driver starts no other agent and lets the running agents end. No ticket is BLOCKED by it: fix the CLI or the model entry, then run the same command again to resume. |
63
63
  | 130 | The operator interrupted the run. The driver stops each agent. The work stays in the slots for the next run. |
@@ -102,7 +102,7 @@ A ticket is ready when each ticket in its **Blocked by** line is merged and no r
102
102
  3. **Gate.** The driver runs `--gate` on the ticket tip.
103
103
  4. **Review.** The driver compares each locked file of the ticket with the test-writer commit. A file that differs is a critical finding `locked file changed: <path>`. A locked file of a merged ticket that the ticket changed since its merge base with the PR branch is a critical `fixture` finding `the ticket changed the locked file of a merged ticket: <path>`, so it goes to a correction (see **Before a correction**). Then the **reviewer** (`prompts/reviewer.md`) runs, and for a ticket with a **Risk** line the **correctness** pass (`prompts/correctness.md`) runs at the same time in the same slot. A read-only role (reviewer, correctness, final-reviewer, pr-writer) leaves its slot and the git config as it found them: all worktrees share one config, and one key written there, such as a `core.worktree` on a temp directory, breaks git in each of them. To run a check off the slot, a reviewer reads the driver's gate record or makes its own `git worktree add --detach` copy and removes it. After read-only roles, the driver checks the slot and the shared config (`git rev-parse --git-common-dir`, then `config`) against what they were before. When one of them changed, the driver restores it, writes `a read-only role broke its rule: ...` to the ledger, and runs the review one more time; a second change blocks the ticket.
104
104
  5. **Merge.** The driver merges the reviewed tip into the PR branch with git plumbing, then deletes the ticket branch. A conflict goes to the **conflict** agent (`prompts/conflict.md`) once. Its resolution may change no locked file of the ticket. A second conflict blocks the ticket.
105
- **The landing check.** Merges are serial. Before the PR branch moves, the driver compares the tree that is about to land (the ticket tip of a fast-forward, or the merge commit) with the PR tip: each locked file of each merged ticket must be the same tree entry in both: the same blob with the same mode, so a file that became a symlink is a difference. A file that only one of them has is a difference. A file that the landing ticket lists in its own `locked` is not checked: the test-writer of a later ticket can add a test to a file that an earlier ticket locked, and must list that file. A test-writer report that changes such a file and does not list it is rejected, with the usual one rerun. The review finds such a change first; the landing check catches a change that no review saw, for example of a ticket that merged after the last review. A difference refuses the landing: the ticket is BLOCKED with `locked file changed: <path>` in the ledger, the PR branch does not move, and no fix round runs. The PR branch moves only from the tip that the check read; when another hand moved the branch in between, the driver makes the merge, the check and the gate again, one time. Only that case starts the landing again: a refused landing and a red merge gate block the ticket. The second try runs no conflict agent, so a conflict there blocks the ticket, and so does a branch that moved again.
105
+ **The landing check.** Merges are serial. Before the PR branch moves, the driver compares the tree that is about to land (the ticket tip of a fast-forward, or the merge commit) with the PR tip: each locked file of each merged ticket must be the same tree entry in both: the same blob with the same mode, so a file that became a symlink is a difference. A file that only one of them has is a difference. A file that the landing ticket lists in its own `locked` is not checked: the test-writer of a later ticket can add a test to a file that an earlier ticket locked, and must list that file. A test-writer report that changes such a file and does not list it is rejected, with the usual one rerun. The review finds such a change first; the landing check catches a change that no review saw, for example of a ticket that merged after the last review. A difference refuses the landing: the ticket is BLOCKED with `locked file changed: <path>` in the ledger and a `merged-locked-file` question for each path, the PR branch does not move, and no fix round runs. `restore` puts the file back to the version of the PR branch in a commit of the driver on the ticket branch, and `adopt` adds the file to the ticket's `locked`; then the landing runs again with its gate. When that gate is red, the driver takes the restore commit back and asks again without the option that was tried. The PR branch moves only from the tip that the check read; when another hand moved the branch in between, the driver makes the merge, the check and the gate again, one time. Only that case starts the landing again: a refused landing and a red merge gate block the ticket. The second try runs no conflict agent, so a conflict there blocks the ticket, and so does a branch that moved again.
106
106
  **Before a correction.** A test-writer that corrects locked tests (after `overrule-test`, or for a `fixture` finding or a `test` finding on a locked file) starts from the locked versions: the driver puts back each locked file of the ticket and each locked file of a merged ticket that the ticket changed, commits them in one commit of its own, and the ledger names each file. A file of a merged ticket goes back to the version of the PR branch. The commit keeps the tree of the next fixer and of the gate clean, whatever files the correction commits. The correction's prompt names the restored files: when a test in one of them fails only because the ticket changed an interface that the test uses, the correction updates the file to the new interface, keeps what each test asserts, and lists the file in `locked`. Each correction also gets `prompts/corrected.md`: when it adds a requirement, it updates each shared fake or fixture that other locked tests use, runs each whole locked file and each locked test of merged tickets, and names each red test in `concerns`.
107
107
  **The gate of the restore.** In the fix loop, the tip before the restore has a green gate, so the driver gates the restore commit and does not leave the question to the correction. A red gate means that a restored file fails with the ticket's code: the correction gets the gate record (`prompts/restored-red.md`), and a DONE correction must list a restored file in `locked`; else it reports BLOCKED with `locked test contradicts spec:`. A green gate with only driver findings to correct closes them with the restore: no test-writer runs. After `overrule-test` the driver does not gate the restore, because the tip before it has no green gate; a change that the next implementer makes to a merged ticket's file is a finding of the next review.
108
108
 
@@ -111,7 +111,7 @@ Rules for each agent:
111
111
  - A call blocks until the agent ends. The driver does not poll.
112
112
  - An agent stops only the processes it started and their child processes, by PID, and never kills a process it did not start, nor uses `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. A process it did not start that blocks it goes into its concerns.
113
113
  - An agent gets one rerun: after a rejected report, after a timeout, or after it left the ticket branch. The rerun prompt is the first prompt plus the reason.
114
- - A report with status `BLOCKED` or `NEEDS_CONTEXT` blocks the ticket. From the reviewer or the correctness pass, it also asks a `review-stopped` question.
114
+ - A report with status `BLOCKED` or `NEEDS_CONTEXT` blocks the ticket. From the reviewer or the correctness pass, it also asks a `review-stopped` question; from the implementer or a fixer, a `locked-test` question when a concern starts with `locked test contradicts spec:`, else an `implementer-stopped` or `fixer-stopped` question. Nothing left to change is no stop: the implementer and the fixer report it as DONE with no commit.
115
115
  - A BLOCKED ticket stops the tickets that it blocks. All other tickets run on.
116
116
 
117
117
  ### Findings and fix rounds
@@ -129,7 +129,7 @@ A red gate on the commit of the implementer or of a fixer is a critical finding
129
129
  - Rounds 1 and 2 run on the first entry of the implementer list.
130
130
  - Rounds 3 and 4 run on the second entry of the implementer list. When the list has one entry, they stay on it and the ledger says so.
131
131
  - There is no ruling at round 2.
132
- - Findings that are open after round 4 make the ticket BLOCKED. The run ends with exit 1, and the driver writes one question of kind `finding` for each. A finding that would get a test-writer correction is one of them: no correction runs after round 4, because its new locked tests would have no fix round to make them green and the merge gate would be red. So `accept` on each question merges the reviewed tip.
132
+ - Findings that are open after round 4 make the ticket BLOCKED. The run ends with exit 1, and the driver writes one question of kind `finding` for each. A finding that would get a test-writer correction is one of them: no correction runs after round 4, because its new locked tests would have no fix round to make them green and the merge gate would be red. So `accept` on each question merges the reviewed tip. A tip that still changes a locked file of a merged ticket gets a `merged-locked-file` question at its landing.
133
133
 
134
134
  ### End of run
135
135
 
@@ -178,7 +178,7 @@ Every report has `status` (`DONE`, `DONE_WITH_CONCERNS`, `NEEDS_CONTEXT`, `BLOCK
178
178
  | Role | Template | More fields | Checks after the schema |
179
179
  |---|---|---|---|
180
180
  | test-writer | `prompts/test-writer.md` | `locked` (test file paths), `red` (`test`, `line`), optional `fixtures` (each locked file that holds no test, as a fake `gh`) | The driver reads a test node id `<file>::<test>` in `locked` as its file. Each fixture is in `locked`; the ticket record keeps it a fixture until a later correction lists the file again. With DONE: one commit, one locked file and one red line or more. Each locked path is in a commit that the role made. Each `line` is in the log. A locked file of a merged ticket that the role changed is in `locked`. A correction (after `overrule-test`, or for a review finding) changes only the files that it lists in `locked` and the files that the driver restored before it. When the gate is red on the restore commit, a DONE correction lists a restored file in `locked`. Each `not_addressed[].finding` is the title of a finding of the correction; a DONE correction with each of its findings there needs no commit. |
181
- | implementer | `prompts/implementer.md` | `green` | With DONE: one commit or more. |
181
+ | implementer | `prompts/implementer.md` | `green` | With DONE and no commit: no new commit on the branch, no uncommitted change, and a concern that says why the start needs no change. The driver then gates and reviews the start commit. |
182
182
  | reviewer | `prompts/reviewer.md` | `findings` (`severity`, `file`, `line`, `title`, `evidence`, `kind`), `mutations` (`test`, `file`, `line`, `red`); `commits` is empty | In a full review (one with no fix range: round 1, and the review after a test-writer correction): `mutations` is required, with a proof for each locked test file (`test` is `<locked file>::<test name>`). A locked fixture needs no proof: it holds no test that a proof could name, and the locked-file check protects it. Each `red` is in the log. |
183
183
  | correctness | `prompts/correctness.md` | the same as the reviewer; `commits` is empty | `mutations` is optional. |
184
184
  | fixer | `prompts/fixer.md` | `green`, `ticket` | With DONE and no commit: no new commit on the branch, no uncommitted change, a gate that is green on the start, and a concern that names each finding of the round. |
@@ -199,6 +199,9 @@ A question is a bounded choice for the operator. `driver_decisions.py` `KINDS` h
199
199
  | `finding` | `<NN>-finding-<n>` | A finding is open after fix round 4. One question for each finding. | 1 | `accept`: close the finding; the ticket merges when each of its findings is accepted. `split` (recommended) and `redesign`: the ticket stays BLOCKED, with the ruling in the ledger. |
200
200
  | `locked-test-again` | `<NN>-locked-test-again-<n>` | A finding for a test-writer correction is open in the review right after a correction, or the driver rejects the correction's report (for example, it changes a file that it does not list in `locked`). One question for each finding. | 2 | `correct-again` (recommended): the ticket resumes from the review, and that review's findings get one more correction. `accept`: no more correction runs for the ticket, its locked tests stay as they are, and the ticket goes on to its fix rounds with its other findings; a changed locked file is still restored. `redesign`: the ticket stays BLOCKED, with the ruling in the ledger. After two `correct-again` stops on a ticket, its next question offers only `accept` (recommended) and `redesign`, so a test-writer and a reviewer that never agree cannot loop. |
201
201
  | `review-stopped` | `<NN>-review-stopped-<n>` | The reviewer or the correctness pass reports `BLOCKED` or `NEEDS_CONTEXT`. One question for each agent that stopped. | 2 | `retry` (recommended): the ticket resumes from the review, and each agent of the review runs again. `accept`: the same, and for the rest of the ticket a `BLOCKED` or `NEEDS_CONTEXT` report of that agent does not stop it: the review goes on with that report's findings and those of the other reports. `redesign`: the ticket stays BLOCKED, with the ruling in the ledger. |
202
+ | `implementer-stopped` | `<NN>-implementer-stopped-<n>` | The implementer reports `BLOCKED` or `NEEDS_CONTEXT`, and no concern starts with `locked test contradicts spec:`. | 2 | `retry` (recommended): the implementer runs again from the tip it left. `accept-tip`: the driver gates and reviews that tip, and the fix rounds close what the review finds. `redesign`: the ticket stays BLOCKED, with the ruling in the ledger. |
203
+ | `fixer-stopped` | `<NN>-fixer-stopped-<n>` | A fixer reports `BLOCKED` or `NEEDS_CONTEXT`, and no concern starts with `locked test contradicts spec:`. | 2 | `retry` (recommended): the round that stopped does not count; the driver gates and reviews the tip the fixer left, and a fixer runs that round again on the review's findings. `redesign`: the ticket stays BLOCKED, with the ruling in the ledger. |
204
+ | `merged-locked-file` | `<NN>-merged-locked-file-<n>` | The landing check refuses the landing: the tree that would land changes this locked file of a merged ticket. One question for each file. | 2 | `restore` (recommended): the driver puts the file back to the version of the PR branch in a commit of its own on the ticket branch, and the ticket resumes from its landing. `adopt`: the ticket adds the file to its `locked`, so its change lands, and resumes from its landing. `redesign`: the ticket stays BLOCKED, with the ruling in the ledger. When the merge gate is red after `restore` or `adopt`, the driver takes the restore commit back and asks again, without the option that was tried. |
202
205
  | `final-finding` | `final-finding-<n>` | A finding is open after the second round of the final review. | 2 | `fix` (recommended): the finding stays open and nothing is pushed. `accept`: close the finding. |
203
206
 
204
207
  `n` counts the questions of that ticket and kind in the run, so an id is never used twice.
@@ -209,7 +212,7 @@ Answer with `--answer <question id>=<option id>` on the next run, or through the
209
212
 
210
213
  | Check | Where it lives |
211
214
  |---|---|
212
- | Locked tests with a demonstrated red | `driver_report.py` `_proof_errors`: each red line of the test-writer report must be in its log. `driver_review.py` `locked_findings`: a locked file of the ticket that differs from the test-writer commit is a critical finding, before each review. `driver_review.py` `merged_changes`: a locked file of a merged ticket that the ticket changed is a critical `fixture` finding, before each review. `driver_merge.py` `refused`, called from `driver.py` `_checked_landing` under the merge lock: a locked file of a merged ticket that differs between the PR tip and the tree that is about to land refuses the landing, so a later ticket cannot change the locked test of an earlier one. `driver_report.py` `_merged_errors` rejects a test-writer report that changes such a file and does not list it. |
215
+ | Locked tests with a demonstrated red | `driver_report.py` `_proof_errors`: each red line of the test-writer report must be in its log. `driver_review.py` `locked_findings`: a locked file of the ticket that differs from the test-writer commit is a critical finding, before each review. `driver_review.py` `merged_changes`: a locked file of a merged ticket that the ticket changed is a critical `fixture` finding, before each review. `driver_merge.py` `refused`, called from `driver.py` `_checked_landing` under the merge lock: a locked file of a merged ticket that differs between the PR tip and the tree that is about to land refuses the landing with a `merged-locked-file` question, so a later ticket changes the locked test of an earlier one only by the operator's `adopt`. `driver_report.py` `_merged_errors` rejects a test-writer report that changes such a file and does not list it. |
213
216
  | One mutation proof for each locked test | `prompts/full-review.md`, the note of each full review, names the locked test files that need a proof: each locked file that is not a fixture. `driver_report.py` `_locked_errors` and `_proof_errors` reject a full review with no proof for a locked test file, or with a red line that is not in the log. `driver_review.py` `follow` finds the proofs that a fix makes due again. |
214
217
  | One independent correctness pass for each risky ticket | `driver_fixloop.py` `_review` adds the pass for a ticket with a **Risk** line. `driver_agents.py` `correctness_entry` picks the entry of another provider, and `load_models` stops the run when there is none or its CLI is not on PATH. |
215
218
  | One full gate for each candidate | `driver_gate.py` `run`, called from `driver_run.py` `Run.gate`: one record for each commit the driver is about to trust. Green is exit 0 on a tree that is clean before and after, with HEAD not moved. |
@@ -48,6 +48,7 @@ ONLY = ("test-writer", "implementer", "reviewer", "correctness") # `--only` is
48
48
  # The phase of a ticket while a role runs, and the phase it reaches when the role's report is accepted.
49
49
  DURING = {"test-writer": "test-writer", "implementer": "implement"}
50
50
  AFTER = {"test-writer": "implement", "implementer": "gate"}
51
+ MERGED_LOCKED = "merged-locked-file" # the question of a landing that changes a locked file of a merged ticket
51
52
 
52
53
 
53
54
  # ---------------------------------------------------------------- one ticket: the roles
@@ -136,6 +137,16 @@ class _Landing:
136
137
  commit: str # what the PR branch moves to: `pr_tip` (merged already), `ticket_tip` (fast-forward) or a merge
137
138
 
138
139
 
140
+ @dataclass
141
+ class _Rulings:
142
+ """The answers to the `merged-locked-file` questions of the ticket, as its landing applies them."""
143
+ before: str # the ticket tip before the driver put a file back
144
+ paths: dict[str, str] # file -> `restore` or `adopt`
145
+
146
+ def adopted(self) -> list[str]:
147
+ return [path for path, answer in self.paths.items() if answer == "adopt"]
148
+
149
+
139
150
  def _resolve_conflict(ticket: Ticket, slot: str, run: Run, tip: str, files: list[str]) -> str:
140
151
  """Run the conflict agent on the merge that is open in the slot. Returns the new ticket tip."""
141
152
  number = ticket.number
@@ -175,41 +186,87 @@ def _merge_commit(ticket: Ticket, slot: str, run: Run, tip: str, may_resolve: bo
175
186
  return _Landing(tip, pr_tip, commit)
176
187
 
177
188
 
178
- def _checked_landing(ticket: Ticket, slot: str, run: Run, may_resolve: bool) -> _Landing:
189
+ def _rulings(number: str, slot: str, run: Run) -> _Rulings:
190
+ """Apply the `restore` rulings on the ticket's files of merged tickets: one commit of the driver. Call it under
191
+ the merge lock."""
192
+ paths = {path: answer for path, answer in
193
+ driver_decisions.ruled(run.state.read()["run"]["questions"], number, MERGED_LOCKED).items()
194
+ if answer != "redesign"}
195
+ rulings = _Rulings(run.state.read()["tickets"][number]["tip"], paths)
196
+ if restore := [path for path, answer in paths.items() if answer == "restore"]:
197
+ git(slot, "checkout", "-q", run.names.ticket(number))
198
+ run.restore_merged_files(number, slot, restore)
199
+ return rulings
200
+
201
+
202
+ def _refused(number: str, run: Run, landing: _Landing, rulings: _Rulings) -> None:
203
+ """The landing check: a locked file of a merged ticket that the landing changes asks a `merged-locked-file`
204
+ question. A file that an `adopt` ruling names is the ticket's own."""
205
+ tickets = run.state.read()["tickets"]
206
+ entry = tickets[number]
207
+ own = {**tickets, number: {**entry, "locked": entry["locked"] + rulings.adopted()}}
208
+ changed, error = driver_merge.refused(own, number, landing.pr_tip, landing.commit)
209
+ if error:
210
+ raise Blocked(error)
211
+ if changed:
212
+ run.ask(number, MERGED_LOCKED, changed,
213
+ f"git diff {landing.pr_tip[:7]} {landing.commit[:7]} -- {' '.join(changed)}")
214
+ raise Blocked("; ".join(f"locked file changed: {path}" for path in changed))
215
+
216
+
217
+ def _red_landing(number: str, slot: str, run: Run, rulings: _Rulings, record: str) -> None:
218
+ """A red merge gate after `restore` or `adopt` rulings: the restore commit leaves the ticket branch, and each
219
+ ruled file is asked again, without the option that was tried."""
220
+ if rulings.paths:
221
+ if run.state.read()["tickets"][number]["tip"] != rulings.before:
222
+ driver_review.restore(slot, run.names.ticket(number), rulings.before)
223
+ run.state.ticket(number, tip=rulings.before)
224
+ ledger(f"Ticket {number}: the merge gate is red after the restore, so the driver took the restore commit "
225
+ f"back: the ticket tip is {rulings.before[:7]} again.")
226
+ run.ask(number, MERGED_LOCKED, list(rulings.paths), record)
227
+
228
+
229
+ def _checked_landing(ticket: Ticket, slot: str, run: Run, may_resolve: bool, rulings: _Rulings) -> _Landing:
179
230
  """The commit to land, with the locked-file check passed and the gate green. Call it under the merge lock."""
180
231
  number = ticket.number
181
232
  # An earlier try left the slot on its merge commit.
182
233
  git(slot, "checkout", "-q", run.names.ticket(number))
183
234
  tip = run.state.ticket(number, phase="merge")["tip"]
184
235
  landing = _merge_commit(ticket, slot, run, tip, may_resolve)
185
- refusal = driver_merge.refused(run.state.read()["tickets"], number, landing.pr_tip, landing.commit)
186
- if refusal:
187
- raise Blocked(refusal)
236
+ _refused(number, run, landing, rulings)
188
237
  if landing.commit != landing.pr_tip:
189
238
  # No gate has seen a merge commit. A fast-forward to a gated tip finds its green record.
190
239
  # When the checkout fails, the slot is on another commit and the gate refuses to run.
191
240
  git(slot, "checkout", "-q", "--detach", landing.commit)
192
- run.gate(number, slot, landing.commit)
241
+ if record := run.red_gate(number, slot, landing.commit):
242
+ _red_landing(number, slot, run, rulings, record)
243
+ raise Blocked(f"the gate is red on {landing.commit[:7]}, record {record}")
193
244
  return landing
194
245
 
195
246
 
196
- def _land(ticket: Ticket, slot: str, run: Run) -> _Landing:
247
+ def _land(ticket: Ticket, slot: str, run: Run) -> tuple[_Landing, _Rulings]:
197
248
  """Move the PR branch to the checked commit. Call it under the merge lock."""
198
- landing = _checked_landing(ticket, slot, run, may_resolve=True)
249
+ rulings = _rulings(ticket.number, slot, run)
250
+ landing = _checked_landing(ticket, slot, run, True, rulings)
199
251
  # git moves the ref only from the tip that the check read, so the check and the move are one step.
200
252
  error = driver_merge.land(run.pr, landing.commit, landing.pr_tip)
201
253
  if error and run.tip() != landing.pr_tip:
202
254
  # Another hand moved the PR branch in between: start again from the new tip, one time, with no conflict agent.
203
- landing = _checked_landing(ticket, slot, run, may_resolve=False)
255
+ landing = _checked_landing(ticket, slot, run, False, rulings)
204
256
  error = driver_merge.land(run.pr, landing.commit, landing.pr_tip)
205
257
  if error:
206
258
  raise Blocked(error)
207
- return landing
259
+ return landing, rulings
208
260
 
209
261
 
210
- def _record_landing(state: dict, number: str, pr_tip: str) -> None:
211
- """The ticket is merged and `pr_tip` is the PR tip its merge made. A later merge of the ticket replaces it."""
212
- state["tickets"][number]["phase"] = "merged"
262
+ def _record_landing(state: dict, number: str, landing: _Landing, adopted: list[str]) -> None:
263
+ """The ticket is merged, and `landing.commit` is the PR tip its merge made: a later merge of the ticket replaces
264
+ it. The ticket locks each `adopted` file from its landed tip on."""
265
+ entry, pr_tip = state["tickets"][number], landing.commit
266
+ entry["phase"] = "merged"
267
+ new = [path for path in adopted if path not in entry["locked"]]
268
+ entry["locked"] += new
269
+ entry["held"].update(dict.fromkeys(new, landing.ticket_tip))
213
270
  earlier = [landed for landed in state["run"]["landed"] if landed[0] != number]
214
271
  state["run"]["landed"] = earlier + [[number, pr_tip]]
215
272
 
@@ -219,8 +276,11 @@ def _merge(ticket: Ticket, slot: str, run: Run) -> None:
219
276
  number, branch = ticket.number, run.names.ticket(ticket.number)
220
277
  # The merge gate and the conflict agent run under the lock: the commit the gate saw is the one that lands.
221
278
  with run.merging, during("the merge"):
222
- landing = _land(ticket, slot, run)
223
- run.state.update(lambda state: _record_landing(state, number, landing.commit))
279
+ landing, rulings = _land(ticket, slot, run)
280
+ run.state.update(lambda state: _record_landing(state, number, landing, rulings.adopted()))
281
+ for path in rulings.adopted():
282
+ ledger(f"Ticket {number}: by the ruling (adopt), the ticket locks {path}, so its change to that locked file of "
283
+ "a merged ticket landed.")
224
284
  driver_slots.release(slot) # git deletes no branch that a worktree has checked out
225
285
  kept = "" if driver_merge.delete(branch, run.pr) else f"; {branch} is kept"
226
286
  if landing.commit == landing.pr_tip:
@@ -91,6 +91,54 @@ KINDS = {
91
91
  "redesign": Option(
92
92
  "Keep the ticket BLOCKED. The design changes before more work on it.",
93
93
  "Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
94
+ "implementer-stopped": Kind(
95
+ True,
96
+ "Ticket {ticket}: the implementer stopped: {subject}",
97
+ "The implementer of ticket {ticket} reported BLOCKED or NEEDS_CONTEXT, and no concern says that a locked test "
98
+ "contradicts the spec. Ticket {ticket} is BLOCKED and each ticket that it blocks waits.",
99
+ "retry",
100
+ {"retry": Option(
101
+ "The implementer runs again from the tip it left.",
102
+ "Ruling: {ticket} implementer runs again (retry): {subject}.", {"phase": "implement"}),
103
+ "accept-tip": Option(
104
+ "The implementer does not run again: the driver gates and reviews the tip it left, and the fix rounds "
105
+ "close what the review finds.",
106
+ "Ruling: {ticket} tip goes to the gate and the review as it is (accept-tip): {subject}.",
107
+ {"phase": "gate"}),
108
+ "redesign": Option(
109
+ "Keep the ticket BLOCKED. The design changes before more work on it.",
110
+ "Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
111
+ "fixer-stopped": Kind(
112
+ True,
113
+ "Ticket {ticket}: the fixer stopped: {subject}",
114
+ "The fixer of ticket {ticket} reported BLOCKED or NEEDS_CONTEXT, and no concern says that a locked test "
115
+ "contradicts the spec. Ticket {ticket} is BLOCKED and each ticket that it blocks waits.",
116
+ "retry",
117
+ {"retry": Option(
118
+ "The round that stopped does not count: the driver gates and reviews the tip the fixer left, and a fixer "
119
+ "runs that round again on what the review finds.",
120
+ "Ruling: {ticket} fix round runs again (retry): {subject}.", {"phase": "review"}),
121
+ "redesign": Option(
122
+ "Keep the ticket BLOCKED. The design changes before more work on it.",
123
+ "Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
124
+ "merged-locked-file": Kind(
125
+ True,
126
+ "Ticket {ticket}: the landing would change the locked file of a merged ticket: {subject}",
127
+ "The landing check found that ticket {ticket} changes this locked file of a merged ticket, so the PR branch "
128
+ "did not move. Ticket {ticket} is BLOCKED and each ticket that it blocks waits.",
129
+ "restore",
130
+ {"restore": Option(
131
+ "The driver puts the file back to the version of the PR branch in a commit of its own on the ticket "
132
+ "branch, then the landing runs again with its gate. A red gate takes the commit back and asks again.",
133
+ "Ruling: {ticket} lands with {subject} put back to the version of the PR branch (restore).",
134
+ {"phase": "merge"}),
135
+ "adopt": Option(
136
+ "The ticket locks the file, so its change lands: the merged ticket's tests in it become the ticket's own. "
137
+ "The landing runs again with its gate. A red gate asks again.",
138
+ "Ruling: {ticket} locks {subject} and lands its change to it (adopt).", {"phase": "merge"}),
139
+ "redesign": Option(
140
+ "Keep the ticket BLOCKED. The design changes before more work on it.",
141
+ "Ruling: {ticket} stays BLOCKED, the design changes first (redesign): {subject}.", {})}),
94
142
  # A final-review question belongs to no ticket: its `ticket` is "".
95
143
  "final-finding": Kind(
96
144
  True,
@@ -119,6 +167,11 @@ def corrections(questions: list[dict], ticket: str) -> tuple[int, bool]:
119
167
  return sum("correct-again" in answers for answers in stops.values()), {"accept"} in stops.values()
120
168
 
121
169
 
170
+ def ruled(questions: list[dict], ticket: str, kind: str) -> dict[str, str]:
171
+ """subject -> the last answer to the questions of `kind` on `ticket`."""
172
+ return {q["subject"]: q["answer"] for q in questions if (q["ticket"], q["kind"]) == (ticket, kind) and q["answer"]}
173
+
174
+
122
175
  def accepted(questions: list[dict], ticket: str, kind: str) -> list[str]:
123
176
  """The subjects of the questions of `kind` on `ticket` that the operator answered `accept`."""
124
177
  return [q["subject"] for q in questions if (q["ticket"], q["kind"], q["answer"]) == (ticket, kind, "accept")]
@@ -140,6 +193,11 @@ def question(kind: str, ticket: str, subject: str, evidence: list[str], asked: l
140
193
  options, recommended = made.options, made.recommended
141
194
  if kind == "locked-test-again" and corrections(asked, ticket)[0] >= AGAIN:
142
195
  options, recommended = {name: options[name] for name in ("accept", "redesign")}, "accept"
196
+ if kind == "merged-locked-file":
197
+ # The file is asked again only when an answer turned the merge gate red: that answer is not offered again.
198
+ tried = {q["answer"] for q in asked if (q["ticket"], q["kind"], q["subject"]) == (ticket, kind, subject)}
199
+ options = {name: option for name, option in options.items() if name == "redesign" or name not in tried}
200
+ recommended = recommended if recommended in options else next(iter(options))
143
201
  return {"id": f"{ticket}-{kind}-{number}".lstrip("-"), "title": made.title.format(**values), "why": made.why.format(**values),
144
202
  "evidence": evidence, "recommended": recommended,
145
203
  "options": [{"id": name, "description": option.description} for name, option in options.items()],
@@ -67,15 +67,16 @@ def _entries(commit: str, paths: list[str]) -> tuple[dict[str, str], str]:
67
67
  return {path: entry for entry, _, path in (line.partition("\t") for line in names(tree.stdout))}, ""
68
68
 
69
69
 
70
- def refused(tickets: dict, number: str, old: str, new: str) -> str:
71
- """"" or why ticket `number` may not land `new` on the PR tip `old`: each locked file of a merged ticket must
72
- be the same blob with the same mode in both."""
70
+ def refused(tickets: dict, number: str, old: str, new: str) -> tuple[list[str], str]:
71
+ """Why ticket `number` may not land `new` on the PR tip `old`: (each locked file of a merged ticket that is not
72
+ the same blob with the same mode in both, "") or ([], why git cannot tell). ([], "") lets it land."""
73
73
  paths = protected(tickets, number)
74
74
  if not paths:
75
- return "" # `git ls-tree` with no path lists the whole tree
75
+ return [], "" # `git ls-tree` with no path lists the whole tree
76
76
  (before, error), (after, failed) = _entries(old, paths), _entries(new, paths)
77
- return error or failed or "; ".join(f"locked file changed: {path}" for path in paths
78
- if before.get(path) != after.get(path))
77
+ if error or failed:
78
+ return [], error or failed
79
+ return [path for path in paths if before.get(path) != after.get(path)], ""
79
80
 
80
81
 
81
82
  def changed(slot: str, pr_tip: str, paths: list[str]) -> list[str]:
@@ -69,14 +69,20 @@ def _commit_errors(report: dict, context: dict) -> list[str]:
69
69
  return errors
70
70
 
71
71
 
72
- def _unchanged_errors(report: dict, context: dict) -> list[str]:
73
- """A DONE fixer with no commit (issue #123): the branch did not move, no change is left uncommitted, the gate of
74
- the start is green, and a concern names each finding, with why it needs no change."""
75
- if "fix" not in context or report["commits"] or report["status"] not in ("DONE", "DONE_WITH_CONCERNS"):
72
+ def _unchanged_errors(role: str, report: dict, context: dict) -> list[str]:
73
+ """A DONE implementer or fixer with no commit (issue #123): the branch did not move, no change is left
74
+ uncommitted, the gate of the start is green, and a concern says why no change is needed: for a fixer, one
75
+ concern names each finding."""
76
+ done = report["status"] in ("DONE", "DONE_WITH_CONCERNS")
77
+ if role not in ("implementer", "fixer") or report["commits"] or not done:
76
78
  return []
77
- return _moved_errors(context) + [
79
+ titles = context.get("fix", [])
80
+ errors = _moved_errors(context) + [
78
81
  f"no commit, and no concern names the finding {title}: give each finding a concern that says why it needs no "
79
- "change" for title in context["fix"] if not any(title in concern for concern in report["concerns"])]
82
+ "change" for title in titles if not any(title in concern for concern in report["concerns"])]
83
+ if not (titles or report["concerns"]):
84
+ errors.append("no commit, and no concern: say in `concerns` why the start needs no change")
85
+ return errors
80
86
 
81
87
 
82
88
  def _moved_errors(context: dict) -> list[str]:
@@ -164,6 +170,7 @@ def validate(role: str, path: str, context: dict) -> list[str]:
164
170
  report = {name: value for name, value in report.items() if name in rules["properties"]}
165
171
  if "locked" in report:
166
172
  report["locked"] = locked_files(report["locked"])
167
- return (_commit_errors(report, context) + _owner_errors(report, context) + _unchanged_errors(report, context)
168
- + _correction_errors(report, context) + _merged_errors(report, context) + _proof_errors(report, context)
169
- + _locked_errors(report, context) + _fixture_errors(report))
173
+ return (_commit_errors(report, context) + _owner_errors(report, context)
174
+ + _unchanged_errors(role, report, context) + _correction_errors(report, context)
175
+ + _merged_errors(report, context) + _proof_errors(report, context) + _locked_errors(report, context)
176
+ + _fixture_errors(report))
@@ -119,15 +119,28 @@ class Run:
119
119
  report = _attempts(self, role, number, slot, values, **options)
120
120
  if role == "test-writer":
121
121
  report["locked"] = driver_report.locked_files(report["locked"]) # as validate read it
122
- if subject := driver_decisions.contradicted(role, report):
123
- # The implementer's commits stay: after the ruling the ticket goes on from them.
124
- evidence = OUT / number / f"{role}-{options.get('fix_round', 0)}.json"
125
- self.ask(number, "locked-test", [subject], str(evidence), tip=driver_slots.head(slot))
126
122
  if report.get("status") in ("BLOCKED", "NEEDS_CONTEXT"):
127
123
  concerns = "; ".join(report["concerns"]) or "no concern given"
128
- raise Stopped(f"the {role} reported {report['status']}: {concerns}", report)
124
+ why = f"the {role} reported {report['status']}: {concerns}"
125
+ if number != FINAL:
126
+ self._ask_stop(role, number, slot, report, why, options.get("fix_round", 0))
127
+ raise Stopped(why, report)
129
128
  return report
130
129
 
130
+ def _ask_stop(self, role: str, number: str, slot: str, report: dict, why: str, fix_round: int) -> None:
131
+ """The question of a stopped implementer or fixer: `locked-test` when it says a locked test contradicts the
132
+ spec, else `<role>-stopped` (issue #123). Its commits stay: after the ruling the ticket goes on from them."""
133
+ if role not in ("implementer", "fixer"):
134
+ return
135
+ evidence, tip = str(OUT / number / f"{role}-{fix_round}.json"), driver_slots.head(slot)
136
+ if subject := driver_decisions.contradicted(role, report):
137
+ self.ask(number, "locked-test", [subject], evidence, tip=tip)
138
+ elif role == "implementer":
139
+ self.ask(number, "implementer-stopped", [why], evidence, tip=tip)
140
+ else:
141
+ # The round that stopped does not count: `retry` reviews the tip and runs that round again.
142
+ self.ask(number, "fixer-stopped", [why], evidence, tip=tip, round=fix_round - 1)
143
+
131
144
  def read_only(self, number: str, slot: str, branch: str, tip: str, review: Callable[[], T]) -> T:
132
145
  """Run `review` (read-only agents) and return its result. A review that changes the slot runs once more."""
133
146
  for last in (False, True):
@@ -180,20 +193,36 @@ class Run:
180
193
  tickets = self.state.read()["tickets"]
181
194
  paths = (driver_review.restore_locked(slot, tickets[number])
182
195
  + driver_merge.restore(slot, self.tip(), driver_merge.protected(tickets, number)))
183
- # A path whose change was never committed is back at HEAD already, and `git commit -- <path>` refuses it.
184
- changed = names(git(slot, "diff", "--name-only", "-z", "HEAD", "--", *paths).stdout) if paths else []
185
- if changed:
186
- words = "implement-spec: restore the locked files before the correction"
187
- made = subprocess.run(["git", "-C", slot, "commit", "-q", "--no-verify", "-m", words, "--", *changed],
188
- capture_output=True, text=True, env={**os.environ, **driver_merge.identity("HEAD", slot)})
189
- if made.returncode:
190
- raise Blocked(f"the driver cannot commit the restored locked files: {made.stderr.strip()}")
191
- self.state.ticket(number, tip=driver_slots.head(slot))
196
+ self._commit_restored(number, slot, paths, "implement-spec: restore the locked files before the correction")
192
197
  for path in paths:
193
198
  ledger(f"Ticket {number}: {path} was not the locked version at the correction: the driver restored it in "
194
199
  "a commit, so the correction starts from the locked version.")
195
200
  return paths
196
201
 
202
+ def restore_merged_files(self, number: str, slot: str, paths: list[str]) -> list[str]:
203
+ """Before a landing, by a `restore` ruling: put each of `paths` that is a locked file of a merged ticket and
204
+ that the ticket changed back to the version of the PR branch, in one commit of the driver. Returns those."""
205
+ protected = driver_merge.protected(self.state.read()["tickets"], number)
206
+ restored = driver_merge.restore(slot, self.tip(), [path for path in paths if path in protected])
207
+ self._commit_restored(number, slot, restored,
208
+ "implement-spec: restore the locked files of merged tickets before the landing")
209
+ for path in restored:
210
+ ledger(f"Ticket {number}: by the ruling (restore), the driver put back {path}, a locked file of a merged "
211
+ "ticket, at the version of the PR branch in a commit before the landing.")
212
+ return restored
213
+
214
+ def _commit_restored(self, number: str, slot: str, paths: list[str], words: str) -> None:
215
+ """Commit the restored `paths` in the slot as a commit of the driver, and make it the ticket tip."""
216
+ # A path whose change was never committed is back at HEAD already, and `git commit -- <path>` refuses it.
217
+ changed = names(git(slot, "diff", "--name-only", "-z", "HEAD", "--", *paths).stdout) if paths else []
218
+ if not changed:
219
+ return
220
+ made = subprocess.run(["git", "-C", slot, "commit", "-q", "--no-verify", "-m", words, "--", *changed],
221
+ capture_output=True, text=True, env={**os.environ, **driver_merge.identity("HEAD", slot)})
222
+ if made.returncode:
223
+ raise Blocked(f"the driver cannot commit the restored locked files: {made.stderr.strip()}")
224
+ self.state.ticket(number, tip=driver_slots.head(slot))
225
+
197
226
 
198
227
  def _restore_if_changed(number: str, slot: str, branch: str, tip: str, config: tuple[Path, bytes],
199
228
  runs_again: bool) -> str:
@@ -14,7 +14,7 @@ Use targeted tests while you work.
14
14
  Before you report DONE or DONE_WITH_CONCERNS, make the gate green on your final commit: run `{gate}` with IMPLEMENT_SPEC_BASE={pr_branch} in the environment, then fix, commit, and run it again until it passes. The driver runs the gate again on that commit, and a re-review reads the lines you changed.
15
15
  A finding from the `gate` is a red gate: its file is the gate record. Read the output there and make the gate green.
16
16
  Commit your work on the checked-out ticket branch. Do not dispatch subagents.
17
- When a finding needs no change, for example because a correction before you already resolved it, change nothing for it. When no finding needs a change, make no commit: report DONE_WITH_CONCERNS, list no commit in `commits`, and give one concern per finding to fix that starts with its title and says why it needs no change. A re-review checks each reason. This is not for a red gate: a fix of a red gate is a commit.
17
+ When a finding needs no change, for example because a correction before you already resolved it, change nothing for it. When no finding needs a change, make no commit: report DONE_WITH_CONCERNS, list no commit in `commits`, and give one concern per finding to fix that starts with its title and says why it needs no change. A re-review checks each reason. This is not for a red gate: a fix of a red gate is a commit. Report NEEDS_CONTEXT or BLOCKED only for a question that stops your work: the operator answers it.
18
18
  In `ticket`, give the number of the ticket that owns your commits. In `green`, give the summary lines of the passing test output.
19
19
 
20
20
  Write one JSON report at {report} that matches this schema:
@@ -11,6 +11,7 @@ Never edit a locked file. If a locked test contradicts the spec or the ticket, s
11
11
  Commit your work on the checked-out ticket branch. Do not dispatch subagents. In `commits`, list only the commits you made: the start commit and each commit before it are not yours.
12
12
  Use targeted tests while you work.
13
13
  Before you report DONE or DONE_WITH_CONCERNS, make the gate green on your final commit: run `{gate}` with IMPLEMENT_SPEC_BASE={pr_branch} in the environment, then fix, commit, and run it again until it passes. The driver runs the gate again on that commit.
14
+ When the start commit already meets the ticket, for example because a test-writer correction made the locked tests green, make no commit: report DONE_WITH_CONCERNS, list no commit in `commits`, and give a concern that says why the start needs no change. The driver gates and reviews the start commit. Report NEEDS_CONTEXT or BLOCKED only for a question that stops your work: the operator answers it.
14
15
  In `green`, give the summary lines of the passing test output.
15
16
 
16
17
  Write one JSON report at {report} that matches this schema:
@@ -21,13 +22,11 @@ Write one JSON report at {report} that matches this schema:
21
22
  "required": ["status", "commits", "files", "concerns", "green"],
22
23
  "properties": {
23
24
  "status": {"enum": ["DONE", "DONE_WITH_CONCERNS", "NEEDS_CONTEXT", "BLOCKED"]},
24
- "commits": {"type": "array", "items": {"type": "string", "pattern": "^[0-9a-f]{7,40}$"}},
25
+ "commits": {"description": "Only the commits you made, so empty when you changed nothing: never list a commit that was on the branch at your start.", "type": "array", "items": {"type": "string", "pattern": "^[0-9a-f]{7,40}$"}},
25
26
  "files": {"type": "array", "items": {"type": "string"}},
26
27
  "concerns": {"type": "array", "items": {"type": "string"}},
27
28
  "green": {"type": "array", "items": {"type": "string"}}
28
- },
29
- "if": {"properties": {"status": {"enum": ["DONE", "DONE_WITH_CONCERNS"]}}},
30
- "then": {"properties": {"commits": {"minItems": 1}}}
29
+ }
31
30
  }
32
31
  ```
33
32
 
@@ -1,3 +1,3 @@
1
1
 
2
2
  The driver put back these files at their locked versions, in a commit before this call, because the implementer or a fixer had changed them: {restored}.
3
- A fixer may not change a locked file. When a test in one of these files now fails only because this ticket changed an interface that the test uses, update that file so it works with the new interface: keep what each test asserts, and list the file in `locked`. Else leave the file as it is.
3
+ A fixer may not change a locked file. When a test in one of these files now fails only because this ticket changed an interface that the test uses, update that file so it works with the new interface: keep what each test asserts, and list the file in `locked`. Else leave the file as it is, unless a finding of this correction is on it.
@@ -13,7 +13,7 @@ import driver_review_page
13
13
  from test_cli import git
14
14
  from test_fixloop import Inside, inside # noqa: F401 (the autouse fixture puts the rig's CLIs on PATH)
15
15
  from test_tidy import Inside as Pushing, tools # noqa: F401 (an unattended run pushes: the rig with an origin and a fake gh)
16
- from test_review import ONE, finding, fix, review
16
+ from test_review import ONE, STUCK, finding, fix, review
17
17
  from test_stops import CONTRA, NEW_TEST, Q1, UNATTENDED, blocked, correction, decisions, stage, steps, write_answers
18
18
  from test_walk import impl, plan, tw
19
19
 
@@ -489,3 +489,83 @@ def test_no_open_question_or_no_file_reads_nothing_and_given_writes_only_valid_a
489
489
  assert driver_answers.given([(Q1, "overrule-test")], one) == []
490
490
  assert driver_answers.read(one) == ({Q1: "overrule-test"}, [])
491
491
  assert driver_answers.read(doc()) == ({}, []), "with no open question the file is history"
492
+
493
+
494
+ # ---------------------------------------------------------------- an implementer or a fixer with nothing to change, or that stops
495
+
496
+ IMPLEMENTER_STOPPED, FIXER_STOPPED = "01-implementer-stopped-1", "01-fixer-stopped-1"
497
+ NO_CHANGE = "the correction made the locked tests green: the start needs no change"
498
+
499
+
500
+ def unchanged():
501
+ """An implementer step with no commit: the start commit already meets the ticket."""
502
+ return {"report": {"status": "DONE_WITH_CONCERNS", "commits": [], "files": [], "concerns": [NO_CHANGE],
503
+ "green": ["1 passed"]}}
504
+
505
+
506
+ def stops(role="implementer", status="NEEDS_CONTEXT"):
507
+ report = {"status": status, "commits": [], "files": [], "concerns": ["the ticket names no column order"],
508
+ "green": [], **({"ticket": "01"} if role == "fixer" else {})}
509
+ return {"report": report}
510
+
511
+
512
+ def test_an_implementer_with_nothing_to_change_after_a_correction_is_accepted_and_its_start_is_gated(tmp_path):
513
+ """Issue 123: after `overrule-test` the correction made the locked tests green, so the implementer had nothing to
514
+ change, and no report of it was valid: NEEDS_CONTEXT blocked the ticket with no question."""
515
+ rig = stopped(tmp_path)
516
+ rig.run(steps(blocked(), unchanged()), "--answer", f"{Q1}=overrule-test")
517
+ assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
518
+ assert len(rig.calls("01", "implementer")) == 2 and rig.led("implementer ran on", "report accepted")
519
+ corrected = rig.calls("01", "test-writer")[1]["sha"]
520
+ assert corrected in [gate["commit"] for gate in rig.gates()]
521
+ assert rig.calls("01", "reviewer")[0]["head"] == corrected
522
+ assert "list no commit" in rig.prompt("implementer-0")
523
+
524
+
525
+ @pytest.mark.parametrize("status", ["NEEDS_CONTEXT", "BLOCKED"])
526
+ def test_an_implementer_that_stops_asks_the_operator_and_retry_runs_it_again(tmp_path, status):
527
+ """Issue 123: a stop of the implementer that is not `locked test contradicts spec:` had no question."""
528
+ rig = Inside(tmp_path, ONE).run(steps(stops(status=status)))
529
+ assert rig.code == 2 and rig.state()["tickets"]["01"]["phase"] == "blocked", rig.ledger()
530
+ (question,) = rig.state()["run"]["questions"]
531
+ assert (question["id"], question["recommended"]) == (IMPLEMENTER_STOPPED, "retry")
532
+ assert [o["id"] for o in question["options"]] == ["retry", "accept-tip", "redesign"]
533
+ assert question["evidence"][0] == ".agent/implement/01/implementer-0.json"
534
+ assert question["subject"] == f"the implementer reported {status}: the ticket names no column order"
535
+ rig.run(steps(stops(status=status), impl("01")), "--answer", f"{IMPLEMENTER_STOPPED}=retry")
536
+ assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
537
+ assert len(rig.calls("01", "implementer")) == 2 and len(rig.calls("01", "test-writer")) == 1
538
+ assert rig.led(f"Ruling: 01 implementer runs again (retry): the implementer reported {status}")
539
+
540
+
541
+ def test_accept_tip_gates_and_reviews_the_tip_the_stopped_implementer_left(tmp_path):
542
+ rig = Inside(tmp_path, ONE).run(steps(stops()))
543
+ assert rig.code == 2, rig.ledger()
544
+ rig.run(steps(stops()), "--answer", f"{IMPLEMENTER_STOPPED}=accept-tip")
545
+ assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
546
+ tip = rig.sha("01", "test-writer")
547
+ assert len(rig.calls("01", "implementer")) == 1 and tip in [gate["commit"] for gate in rig.gates()]
548
+ assert rig.calls("01", "reviewer")[0]["head"] == tip
549
+
550
+
551
+ def test_an_implementer_stop_answered_redesign_keeps_the_ticket_blocked(tmp_path):
552
+ rig = Inside(tmp_path, ONE).run(steps(stops()))
553
+ rig.run(steps(stops()), "--answer", f"{IMPLEMENTER_STOPPED}=redesign")
554
+ assert rig.code == 1 and rig.state()["tickets"]["01"]["phase"] == "blocked", rig.ledger()
555
+ assert len(rig.calls("01", "implementer")) == 1
556
+
557
+
558
+ def test_a_fixer_that_stops_asks_the_operator_and_retry_runs_its_round_again(tmp_path):
559
+ """Issue 123: the round that stopped does not count, so the retry is that round again, after a review."""
560
+ steps = plan(**{"01/reviewer": [review("01", [STUCK]), review("01", [STUCK]), review("01")],
561
+ "01/fixer": [stops("fixer"), fix("01", 1)]})
562
+ rig = Inside(tmp_path, ONE).run(steps)
563
+ assert rig.code == 2 and rig.state()["tickets"]["01"]["round"] == 0, rig.ledger()
564
+ (question,) = rig.state()["run"]["questions"]
565
+ assert (question["id"], question["recommended"]) == (FIXER_STOPPED, "retry")
566
+ assert [o["id"] for o in question["options"]] == ["retry", "redesign"]
567
+ assert question["evidence"][0] == ".agent/implement/01/fixer-1.json"
568
+ rig.run(steps, "--answer", f"{FIXER_STOPPED}=retry")
569
+ assert rig.code == 0 and rig.state()["tickets"]["01"]["phase"] == "merged", rig.ledger()
570
+ assert rig.state()["tickets"]["01"]["round"] == 1 and len(rig.calls("01", "fixer")) == 2
571
+ assert rig.led("Ruling: 01 fix round runs again (retry): the fixer reported NEEDS_CONTEXT")
@@ -221,7 +221,7 @@ def test_a_report_that_says_blocked_blocks_the_ticket_without_a_rerun(repo, tmp_
221
221
  repo()
222
222
  body = f"""printf '{{"status": "{status}", "commits": [], "files": [], "concerns": ["test_x contradicts the spec"], "green": []}}' > "$report"\n"""
223
223
  code, ledger = agents(tmp_path, capsys, body)
224
- assert code == 1 and len(ledger) == 2
224
+ assert code == 2 and len(ledger) == 3 and "question of kind implementer-stopped" in ledger[2]
225
225
  assert ledger[1] == f"Ticket 01: BLOCKED at the implementer: the implementer reported {status}: test_x contradicts the spec."
226
226
 
227
227
 
@@ -364,6 +364,7 @@ REFACTOR = {"seam": "none — refactor"}
364
364
  # A fixer that cannot make the red gate green: the ticket blocks at fix round 1.
365
365
  GIVE_UP = """[ $role != fixer ] || { printf '{"status": "BLOCKED", "commits": [], "files": [], "concerns": ["the gate stays red"], "green": [], "ticket": "01"}' > "$report"; exit 0; }\n"""
366
366
  GAVE_UP = "Ticket 01: BLOCKED at fix round 1: the fixer reported BLOCKED: the gate stays red."
367
+ ASKED = "Ticket 01: the operator decides on 1 question of kind fixer-stopped in .agent/implement/decisions.json."
367
368
 
368
369
 
369
370
  def walk(tmp_path, capsys, body, *args, gate="true"):
@@ -462,14 +463,14 @@ def test_a_red_gate_is_a_finding_and_the_ticket_it_blocks_never_starts(repo, tmp
462
463
  two(repo, second="01")
463
464
  code, ledger, out = walk(tmp_path, capsys, GIVE_UP + WORK + REPORT, gate="echo CHECK-OUTPUT; exit 1")
464
465
  tip = out_of("git", "rev-parse", "--short=7", "ticket/feat%2Fx/01")
465
- assert code == 1 and ledger[-1] == GAVE_UP, out
466
+ assert code == 2 and ledger[-2:] == [GAVE_UP, ASKED], out
466
467
  assert ledger[1] == (f"Ticket 01: critical finding of kind code from the gate at "
467
468
  f".agent/implement/01/gate-{tip}.log:0: the gate is red on {tip}.")
468
469
  record = (tmp_path / f".agent/implement/01/gate-{tip}.log").read_text()
469
470
  assert "status: clean\n" in record and "CHECK-OUTPUT\n\nexit: 1\nafter: clean\nend: " in record
470
471
  assert "Ticket 02 is not merged: its phase is pending." in out and "| gates run | 1 |" in out
471
472
  assert out_of("git", "symbolic-ref", "--short", "HEAD") == "feat/x"
472
- assert walk(tmp_path, capsys, "exit 9\n")[0] == 1 # a BLOCKED ticket stays BLOCKED on a rerun
473
+ assert walk(tmp_path, capsys, "exit 9\n")[0] == 2 # a BLOCKED ticket stays BLOCKED on a rerun
473
474
 
474
475
 
475
476
  def test_a_red_merge_gate_blocks_the_ticket_and_the_pr_branch_does_not_move(repo, tmp_path, capsys):
@@ -486,12 +487,12 @@ def test_a_red_merge_gate_blocks_the_ticket_and_the_pr_branch_does_not_move(repo
486
487
  def test_a_tree_that_is_not_clean_is_a_red_gate_and_the_slot_keeps_the_work(repo, tmp_path, capsys):
487
488
  repo(t01=ticket("01", **REFACTOR))
488
489
  code, ledger, out = walk(tmp_path, capsys, GIVE_UP + WORK + REPORT + "echo left > junk.txt\n", gate="echo NEVER")
489
- assert code == 1 and "from the gate at .agent/implement/01/gate-" in ledger[-3] and ledger[-1] == GAVE_UP, out
490
+ assert code == 2 and "from the gate at .agent/implement/01/gate-" in ledger[-4] and ledger[-2:] == [GAVE_UP, ASKED], out
490
491
  record = next((tmp_path / ".agent/implement/01").glob("gate-*.log")).read_text()
491
492
  assert "status: not clean\n ?? junk.txt\n" in record and "exit: not run" in record and "\nNEVER\n" not in record
492
493
  assert out_of("git", "symbolic-ref", "--short", "HEAD") == "ticket/feat%2Fx/01" and (tmp_path / "junk.txt").exists()
493
494
  code, _, out = walk(tmp_path, capsys, "exit 9\n")
494
- assert code == 3 and "uncommitted change: junk.txt" in out
495
+ assert code == 2 and (tmp_path / "junk.txt").exists(), "the stop repeats: the work in the slot is no error"
495
496
 
496
497
 
497
498
  def test_a_failing_prepare_stops_the_run_and_removes_the_slot(repo, tmp_path, capsys):
@@ -886,7 +887,7 @@ def test_a_merge_commit_the_slot_cannot_check_out_is_not_gated_and_does_not_land
886
887
  def test_a_gate_that_changes_the_tree_or_moves_head_is_red(repo, tmp_path, capsys, gate, after):
887
888
  repo(t01=ticket("01", **REFACTOR))
888
889
  code, ledger, out = walk(tmp_path, capsys, GIVE_UP + WORK + REPORT, gate=gate)
889
- assert code == 1 and "from the gate at .agent/implement/01/gate-" in ledger[-3] and ledger[-1] == GAVE_UP, out
890
+ assert code == 2 and "from the gate at .agent/implement/01/gate-" in ledger[-4] and ledger[-2:] == [GAVE_UP, ASKED], out
890
891
  record = next((tmp_path / ".agent/implement/01").glob("gate-*.log")).read_text()
891
892
  assert "\nexit: 0\n" in record and after in record
892
893
  assert state_of(tmp_path)["tickets"]["01"]["green_gates"] == []
@@ -231,9 +231,12 @@ def test_a_test_finding_on_a_locked_file_gets_the_test_writer_correction_not_a_f
231
231
  entry = rig.state()["tickets"]["01"]
232
232
  assert (entry["round"], entry["test_writer_sha"]) == (0, rig.calls("01", "test-writer")[1]["sha"])
233
233
  assert rig.led("correction in tests/test_01.py, outside the fix rounds: VACUOUS: VACUOUS.")
234
- # Only a severe finding of kind `test` on a locked file goes to the test-writer.
234
+ # Only a severe finding of kind `test` on a locked file goes to the test-writer, and a severe finding of any kind on
235
+ # a locked file of a merged ticket.
235
236
  minor, elsewhere = finding("M", "minor", kind="test", file="tests/test_01.py"), finding("E", kind="test")
236
237
  assert driver_review.route([vacuous, minor, elsewhere], ["tests/test_01.py"], []) == ([vacuous], [elsewhere])
238
+ gap, aside = finding("G", file="tests/test_00.py"), finding("A", "minor", file="tests/test_00.py")
239
+ assert driver_review.route([gap, aside, elsewhere], [], ["tests/test_00.py"]) == ([gap], [elsewhere])
237
240
 
238
241
 
239
242
  NEEDS_CODE = "needs production code: the code has no multi-PR view"
@@ -567,6 +570,76 @@ def test_a_locked_file_with_a_name_that_git_quotes_is_protected_at_review_for_it
567
570
  assert "assert 1 == 'y'" in on_pr(rig, ACCENT)
568
571
 
569
572
 
573
+ # ---------------------------------------------------------------- a ticket that must change a merged ticket's locked file
574
+
575
+ MERGED_LOCKED = "02-merged-locked-file"
576
+ LANDING_RESTORE = "implement-spec: restore the locked files of merged tickets before the landing"
577
+
578
+
579
+ def touches_01(n):
580
+ """Fixer `n` of 02, which also changes tests/test_01.py, the locked file of merged ticket 01."""
581
+ return fix("02", n, files={"demo/export.py": f"def fn_02():\n return 'fix{n}'\n",
582
+ "tests/test_01.py": LOCKED_01 + f"# fix {n}\n"})
583
+
584
+
585
+ def changed_at_round_4(tmp_path, name, files=None, gate=None):
586
+ """Ticket 02 whose fixer of round 4 changes the locked file of merged ticket 01: the review after it finds the
587
+ change, and with no round left it is a `finding` question, which the operator accepts."""
588
+ steps = plan(**{"02/reviewer": [review("02", [STUCK])] * 4 + [review("02")],
589
+ "02/fixer": [fix("02", 1), fix("02", 2), fix("02", 3), touches_01(4)]})
590
+ rig = Inside(under(tmp_path, name), files or three(), gate=gate).run(steps, parallel="1")
591
+ assert rig.code == 1 and asked(rig) == {"02-finding-1": ["accept", "split", "redesign"]}, rig.ledger()
592
+ assert rig.state()["run"]["questions"][0]["subject"].startswith("the ticket changed the locked file of a merged ticket")
593
+ return rig.run(steps, "--answer", "02-finding-1=accept", parallel="1"), steps
594
+
595
+
596
+ def test_an_accepted_change_to_a_merged_ticket_locked_file_asks_at_the_landing_and_restore_lands_it(tmp_path):
597
+ """Issue #116, comment 1: `accept` sent the ticket to its landing, which the landing check refused with no
598
+ question, so no answer could merge it."""
599
+ rig, steps = changed_at_round_4(tmp_path, "restore")
600
+ assert rig.code == 2 and rig.state()["tickets"]["02"]["phase"] == "blocked", rig.ledger()
601
+ assert rig.led("Ticket 02: BLOCKED at the merge: locked file changed: tests/test_01.py.")
602
+ assert asked(rig) == {f"{MERGED_LOCKED}-1": ["restore", "adopt", "redesign"]}
603
+ question = [q for q in rig.state()["run"]["questions"] if q["answer"] is None][0]
604
+ assert question["recommended"] == "restore" and question["subject"] == "tests/test_01.py"
605
+ rig.run(steps, "--answer", f"{MERGED_LOCKED}-1=restore", parallel="1")
606
+ assert rig.code == 0, rig.ledger()
607
+ assert on_pr(rig, "tests/test_01.py") == LOCKED_01 and LANDING_RESTORE in rig.pr_subjects()
608
+ assert rig.led("Ticket 02: by the ruling (restore), the driver put back tests/test_01.py")
609
+ assert rig.state()["tickets"]["02"]["phase"] == "merged"
610
+
611
+
612
+ def test_adopt_lands_the_change_to_the_merged_ticket_locked_file_and_the_ticket_locks_it(tmp_path):
613
+ rig, steps = changed_at_round_4(tmp_path, "adopt")
614
+ rig.run(steps, "--answer", f"{MERGED_LOCKED}-1=adopt", parallel="1")
615
+ assert rig.code == 0, rig.ledger()
616
+ assert on_pr(rig, "tests/test_01.py") == LOCKED_01 + "# fix 4\n"
617
+ assert "tests/test_01.py" in rig.state()["tickets"]["02"]["locked"] and rig.led("by the ruling (adopt)")
618
+
619
+
620
+ def test_redesign_keeps_the_ticket_blocked_at_its_landing(tmp_path):
621
+ rig, steps = changed_at_round_4(tmp_path, "redesign")
622
+ rig.run(steps, "--answer", f"{MERGED_LOCKED}-1=redesign", parallel="1")
623
+ assert rig.code == 1 and rig.state()["tickets"]["02"]["phase"] == "blocked", rig.ledger()
624
+ assert on_pr(rig, "tests/test_01.py") == LOCKED_01 and not asked(rig)
625
+
626
+
627
+ def test_a_restore_that_turns_the_merge_gate_red_is_taken_back_and_asks_again_without_restore(tmp_path):
628
+ """The ticket's code needs its change to the file: the restore commit leaves the ticket branch and the question
629
+ comes back with the options left, so the stop still has an answer."""
630
+ two = {name: text for name, text in three().items() if not name.startswith("03")} # 02 lands as a fast-forward
631
+ rig, steps = changed_at_round_4(tmp_path, "red", files=two, gate={"subjects": [LANDING_RESTORE]})
632
+ rig.run(steps, "--answer", f"{MERGED_LOCKED}-1=restore", parallel="1")
633
+ assert rig.code == 2 and rig.led("Ticket 02: BLOCKED at the merge: the gate is red on"), rig.ledger()
634
+ assert asked(rig) == {f"{MERGED_LOCKED}-2": ["adopt", "redesign"]}
635
+ question = [q for q in rig.state()["run"]["questions"] if q["answer"] is None][0]
636
+ assert question["recommended"] == "adopt" and question["evidence"][0].endswith(".log")
637
+ fixer = rig.calls("02", "fixer")[-1]["sha"]
638
+ assert rig.state()["tickets"]["02"]["tip"] == fixer and on_pr(rig, "tests/test_01.py") == LOCKED_01
639
+ rig.run(steps, "--answer", f"{MERGED_LOCKED}-2=adopt", parallel="1")
640
+ assert rig.code == 0 and on_pr(rig, "tests/test_01.py") == LOCKED_01 + "# fix 4\n", rig.ledger()
641
+
642
+
570
643
  # ---------------------------------------------------------------- the rounds
571
644
 
572
645
  def test_four_rounds_then_blocked_with_the_escalation_at_round_3(tmp_path):
@@ -727,13 +800,11 @@ def test_the_escalation_takes_the_next_entry_of_the_list():
727
800
  assert driver_fixloop.entry({"implementer": ["a@low"]}, 3) == "a@low"
728
801
 
729
802
 
730
- @pytest.mark.parametrize("step, error", [
731
- ({}, "BLOCKED at fix round 1: report .agent/implement/01/fixer-1.json is not"),
732
- ({"report": {"status": "BLOCKED", "commits": [], "files": [], "concerns": ["cannot"], "green": [], "ticket": "01"}},
733
- "BLOCKED at fix round 1: the fixer reported BLOCKED: cannot.")])
734
- def test_a_fixer_that_does_not_finish_blocks_the_ticket_in_its_round(tmp_path, step, error):
735
- rig = Inside(tmp_path).run(plan(**{"01/reviewer": [review("01", [STUCK])], "01/fixer": [step, step]}))
803
+ def test_a_fixer_that_does_not_finish_blocks_the_ticket_in_its_round(tmp_path):
804
+ """A fixer that reports BLOCKED asks a `fixer-stopped` question: test_decisions covers it."""
805
+ rig = Inside(tmp_path).run(plan(**{"01/reviewer": [review("01", [STUCK])], "01/fixer": [{}, {}]}))
736
806
  entry = rig.state()["tickets"]["01"]
807
+ error = "BLOCKED at fix round 1: report .agent/implement/01/fixer-1.json is not"
737
808
  assert error in blocked(rig) and entry["round"] == 1 and entry["tip"] == rig.sha("01", "implementer")
738
809
 
739
810
 
@@ -918,9 +989,10 @@ def conflict(tmp_path, resolve):
918
989
  """01 and 03 both add demo/cli.py and 03 merges first (as test_review.conflicted); `resolve` is 01's conflict step."""
919
990
  rig = Inside(tmp_path, {k: v for k, v in three().items() if not k.startswith("02")})
920
991
  one = impl("01", files={"demo/export.py": "def fn_01():\n return '01'\n", "demo/cli.py": test_review.cli("one")})
921
- return rig.run(plan(**{"01/test-writer": [{**tw("01"), "touch": ["s1"]}], "01/conflict": [resolve, resolve],
922
- "03/implementer": [{**impl("03", "demo/cli.py", test_review.cli("three")), "wait": ["s1"]}],
923
- "01/implementer": [{**one, "wait_pr_moves": True}]}))
992
+ rig.steps = plan(**{"01/test-writer": [{**tw("01"), "touch": ["s1"]}], "01/conflict": [resolve, resolve],
993
+ "03/implementer": [{**impl("03", "demo/cli.py", test_review.cli("three")), "wait": ["s1"]}],
994
+ "01/implementer": [{**one, "wait_pr_moves": True}]})
995
+ return rig.run(rig.steps)
924
996
 
925
997
 
926
998
  def test_a_conflict_resolution_that_changes_a_locked_file_does_not_land(tmp_path):
@@ -937,9 +1009,13 @@ def test_a_conflict_resolution_that_changes_a_locked_file_of_a_merged_ticket_doe
937
1009
  rig = conflict(tmp_path, {"files": {"demo/cli.py": test_review.cli("resolved"), "tests/test_03.py": WEAK},
938
1010
  "commit": "merge: resolve cli", "report": done})
939
1011
  # The resolution is a commit of the ticket; the landing check refuses the tree that it would put on the PR branch.
940
- assert "BLOCKED at the merge: locked file changed: tests/test_03.py." in blocked(rig)
1012
+ assert rig.code == 2 and rig.led("Ticket 01: BLOCKED at the merge: locked file changed: tests/test_03.py."), rig.ledger()
1013
+ assert asked(rig) == {"01-merged-locked-file-1": ["restore", "adopt", "redesign"]}
941
1014
  assert rig.tip() == rig.sha("03", "implementer") and on_pr(rig, "tests/test_03.py") == tw("03")["files"]["tests/test_03.py"]
942
1015
  assert rig.state()["tickets"]["01"]["tip"] == rig.calls("01", "conflict")[0]["sha"]
1016
+ rig.run(rig.steps, "--answer", "01-merged-locked-file-1=restore")
1017
+ assert rig.code == 0 and on_pr(rig, "tests/test_03.py") == tw("03")["files"]["tests/test_03.py"], rig.ledger()
1018
+ assert on_pr(rig, "demo/cli.py") == test_review.cli("resolved") and len(rig.calls("01", "conflict")) == 1
943
1019
 
944
1020
 
945
1021
  def test_a_conflict_agent_that_gives_up_leaves_no_open_merge_in_the_slot(tmp_path):
@@ -5,8 +5,9 @@ and test_final), and through two worktrees of one fixture repository, on two PR
5
5
  files and with `wait_pr_moves`, never with a sleep.
6
6
 
7
7
  Interface choices (ticket 09):
8
- - a ticket that "does not land" ends the run with exit 1 and phase `blocked`; one ledger sentence names the ticket and
9
- `locked file changed: <path>`; no commit of the ticket is on the PR branch. Whether a fix round ran before is free:
8
+ - a ticket that "does not land" ends the run with phase `blocked`; one ledger sentence names the ticket and
9
+ `locked file changed: <path>`, and a `merged-locked-file` question (exit 2) names the path (issue #116); no commit of
10
+ the ticket is on the PR branch. Whether a fix round ran before is free:
10
11
  each plan gives that ticket fixers that write no report.
11
12
  - an implementer "merges the PR branch" with the `git` hook of the fake runner: `git merge --no-edit feat/csv` in its
12
13
  slot, after `wait_pr_moves`, before it writes its files and commits.
@@ -61,18 +62,20 @@ def holds(rig, sha, commit="feat/csv"):
61
62
  return subprocess.run(["git", "merge-base", "--is-ancestor", sha, commit], cwd=rig.repo).returncode == 0
62
63
 
63
64
 
64
- def kept_out(rig, nn):
65
- """Ticket `nn` did not land: the run ends with exit 1 and the PR branch has none of its commits."""
66
- assert rig.code == 1, rig.output()
65
+ def kept_out(rig, nn, codes=(1,)):
66
+ """Ticket `nn` did not land: the run ends with one of `codes` and the PR branch has none of its commits."""
67
+ assert rig.code in codes, rig.output()
67
68
  assert phase(rig, nn) == "blocked"
68
69
  assert not {f"test: {nn} red", f"feat: {nn} rows"} & set(rig.pr_subjects()), rig.pr_subjects()
69
70
  assert not any(holds(rig, c["sha"]) for c in rig.calls(nn) if c["sha"])
70
71
 
71
72
 
72
73
  def refused(rig, nn, path):
73
- """The landing of ticket `nn` was refused for the locked file `path` of a merged ticket."""
74
- kept_out(rig, nn)
74
+ """The landing of ticket `nn` was refused for the locked file `path` of a merged ticket, with a question."""
75
+ kept_out(rig, nn, codes=(2,))
75
76
  assert rig.led(nn, f"locked file changed: {path}"), rig.ledger()
77
+ (question,) = [q for q in rig.state()["run"]["questions"] if q["answer"] is None]
78
+ assert (question["id"], question["subject"]) == (f"{nn}-merged-locked-file-1", path)
76
79
 
77
80
 
78
81
  def restored(rig, nn, path):
@@ -238,8 +241,8 @@ def test_a_ticket_that_lands_while_the_merge_gate_of_another_is_open_does_not_le
238
241
  if phase(rig, "03") == "merged": # 03 landed first, when no merged ticket had locked the file
239
242
  assert rig.code == 0, rig.output()
240
243
  assert landed(rig, rig.sha("03", "implementer")) < landed(rig, rig.sha("02", "test-writer")), rig.ledger()
241
- else: # 02 landed in the window: the driver looked again, or it gave the stale merge commit up
242
- kept_out(rig, "03")
244
+ else: # 02 landed in the window: the driver looked again (a question), or it gave the stale merge commit up
245
+ kept_out(rig, "03", codes=(1, 2))
243
246
  assert on_pr(rig, SHARED) == MORE_SEED
244
247
 
245
248
 
@@ -96,20 +96,20 @@ def test_the_landing_check_refuses_what_it_cannot_read(repo, monkeypatch):
96
96
  sh("git", "branch", "ticket/02")
97
97
  same = commit_on("ticket/02", "a.txt", "a\n")
98
98
  tickets = {"01": {"phase": "merged", "locked": ["t.py", "gone.py"]}, "02": {"phase": "merge", "locked": []}}
99
- assert driver_merge.refused(tickets, "02", base, same) == "" # absent on both sides of two commits that exist
99
+ assert driver_merge.refused(tickets, "02", base, same) == ([], "") # absent on both sides of two commits that exist
100
100
  there = commit_on("ticket/02", "t.py", "t\n")
101
- assert driver_merge.refused(tickets, "02", base, there) == "locked file changed: t.py"
102
- assert driver_merge.refused(tickets, "02", there, base) == "locked file changed: t.py"
101
+ assert driver_merge.refused(tickets, "02", base, there) == (["t.py"], "")
102
+ assert driver_merge.refused(tickets, "02", there, base) == (["t.py"], "")
103
103
  # A candidate that is no commit: an id that does not resolve, and a tree.
104
104
  for bad in ("1" * 40, sh("git", "rev-parse", f"{base}^{{tree}}")):
105
- assert driver_merge.refused(tickets, "02", base, bad).startswith(f"cannot read the locked files at {bad}: ")
106
- assert driver_merge.refused(tickets, "02", bad, base).startswith(f"cannot read the locked files at {bad}: ")
105
+ assert driver_merge.refused(tickets, "02", base, bad)[1].startswith(f"cannot read the locked files at {bad}: ")
106
+ assert driver_merge.refused(tickets, "02", bad, base)[1].startswith(f"cannot read the locked files at {bad}: ")
107
107
  # A record with no `locked` key is a ticket that locked nothing: no error in the middle of a landing.
108
108
  assert driver_merge.protected({"01": {"phase": "merged"}, "02": {"phase": "merge"}}, "02") == []
109
109
  assert driver_merge.protected({"01": {"phase": "merged", "locked": ["a"]}}, "02") == ["a"]
110
110
  # git fails on both sides: the two answers are equal, and the landing is refused all the same.
111
111
  monkeypatch.setenv("GIT_DIR", "/nowhere")
112
- assert driver_merge.refused(tickets, "02", base, there).startswith(f"cannot read the locked files at {base}: ")
112
+ assert driver_merge.refused(tickets, "02", base, there)[1].startswith(f"cannot read the locked files at {base}: ")
113
113
  monkeypatch.delenv("GIT_DIR")
114
114
  assert driver_merge.land("pr", there, "1" * 40) != "" and sh("git", "rev-parse", "pr") == base
115
115
 
@@ -125,9 +125,9 @@ def test_the_landing_check_compares_the_mode_and_the_type_of_a_locked_file_too(r
125
125
  link = commit_on("ticket/02", "t.py", "", lambda path: (os.remove(path), os.symlink("t\n", path)))
126
126
  blob = lambda commit: sh("git", "rev-parse", f"{commit}:t.py")
127
127
  assert blob(file) == blob(runs) == blob(link) and sh("git", "ls-tree", link, "t.py").startswith("120000 ")
128
- assert driver_merge.refused(tickets, "02", file, file) == ""
129
- assert driver_merge.refused(tickets, "02", file, runs) == "locked file changed: t.py"
130
- assert driver_merge.refused(tickets, "02", file, link) == "locked file changed: t.py"
128
+ assert driver_merge.refused(tickets, "02", file, file) == ([], "")
129
+ assert driver_merge.refused(tickets, "02", file, runs) == (["t.py"], "")
130
+ assert driver_merge.refused(tickets, "02", file, link) == (["t.py"], "")
131
131
 
132
132
 
133
133
  def test_begin_opens_the_conflicting_merge_on_a_machine_with_no_git_identity(repo, monkeypatch, tmp_path):
@@ -134,6 +134,17 @@ def test_implementer_without_a_new_commit_is_a_violation(world):
134
134
  assert check("implementer", implementer(shas), start=shas["impl"]) # its only commit is not new
135
135
 
136
136
 
137
+ def test_an_implementer_with_nothing_to_change_reports_no_commit_and_why(world):
138
+ """Issue 123: an implementer whose start already meets the ticket has a report the driver accepts."""
139
+ shas, check, _ = world
140
+ why = ["the correction made the locked tests green: the start needs no change"]
141
+ assert check("implementer", implementer(shas, commits=[], concerns=why), start=shas["impl"]) == []
142
+ assert check("implementer", implementer(shas, commits=[]), start=shas["impl"]) == [
143
+ "no commit, and no concern: say in `concerns` why the start needs no change"]
144
+ assert check("implementer", implementer(shas, commits=[], concerns=why), start=shas["tests"]) == [
145
+ f"commit {shas['impl'][:7]} is on ticket/01 and not in `commits`: list each commit you made"]
146
+
147
+
137
148
  def test_a_fixer_with_nothing_to_change_reports_no_commit_and_a_reason_per_finding(world):
138
149
  """Issue 123: a fixer whose findings need no change has a report the driver accepts: no commit, a concern each."""
139
150
  shas, check, tmp = world
@@ -13,8 +13,8 @@ Interface choices (ticket 05):
13
13
  - question ids are `<NN>-locked-test-<n>` with n counting per run (the first is 1, a second stop on the ticket is 2),
14
14
  and `<NN>-finding-<n>` for an open finding after round 4. Options: `overrule-test` / `overrule-implementer`
15
15
  (recommended: overrule-implementer), and `accept` / `split` / `redesign`.
16
- - an implementer is BLOCKED with a stop only when a `concerns` entry starts with "locked test contradicts spec:";
17
- any other BLOCKED report is an ordinary BLOCKED ticket (exit 1, no decisions file).
16
+ - an implementer is BLOCKED with a `locked-test` stop only when a `concerns` entry starts with "locked test
17
+ contradicts spec:"; any other BLOCKED report is an `implementer-stopped` stop (issue #123).
18
18
  - the answers file is `.agent/implement-answers.json` in the schema.md shape: `v`, `stage: "implement"`, `submitted`
19
19
  (`"changes"`), `revision`, `answers`. A rerun applies it only with `submitted` set and `revision` equal to the current
20
20
  decisions revision; otherwise a ledger line says "ignored" (and "revision" for a stale file, the option id for an
@@ -193,11 +193,11 @@ def test_answer_for_an_unknown_question_id_exits_3_naming_it_before_any_agent(tm
193
193
  assert "no-such-question" in rig.out + rig.err and len(rig.calls()) == seen
194
194
 
195
195
 
196
- def test_a_blocked_report_that_is_not_a_contradicted_locked_test_is_not_a_stop(tmp_path):
196
+ def test_a_blocked_report_that_is_not_a_contradicted_locked_test_is_an_implementer_stop(tmp_path):
197
197
  rig = Review(tmp_path)
198
198
  rig.run(steps(blocked("cannot reach the database")))
199
- assert rig.code == 1, rig.output()
200
- assert not (rig.repo / ".agent/implement/decisions.json").exists()
199
+ assert rig.code == 2, rig.output()
200
+ assert [q["id"] for q in decisions(rig)["questions"]] == ["01-implementer-stopped-1"]
201
201
  assert rig.state()["tickets"]["01"]["phase"] == "blocked"
202
202
 
203
203
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-10-20T15:57:25.481Z",
3
+ "generatedAt": "2026-10-20T17:59:20.836Z",
4
4
  "skills": [
5
5
  {
6
6
  "name": "backlog",
@@ -46,8 +46,8 @@
46
46
  },
47
47
  {
48
48
  "name": "implement-spec",
49
- "version": "0.1.33",
50
- "hash": "sha256-f5d4bb64baedc840c40253138ece3c8781424ebf7619447b2e10858888a93c7c",
49
+ "version": "0.1.35",
50
+ "hash": "sha256-4e94140abbc0dc964ec2dc9c0fbb0e5c4bb4a8e11d1e4c4bbd278c5321223fd6",
51
51
  "description": "Implement a specification in code."
52
52
  },
53
53
  {