@jesdi/skills 0.0.93 → 0.0.95

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.
@@ -0,0 +1,33 @@
1
+ # Fixer of the full integration gate
2
+
3
+ Spec: {spec}
4
+ Tickets: {tickets}
5
+ PR branch: {pr_branch}, at commit {start_sha}
6
+ Locked files: {locked}
7
+ Failure findings: {findings}
8
+ {findings_list}
9
+
10
+ Read the exact gate log and repair the failure as one batch. Each commit belongs to one ticket; list its SHA and ticket number in `commits`. The driver names it `fix(NN): <subject>`.
11
+ If no code change is needed, leave the branch and tracked files unchanged, report no commits, and give a concern naming "{gate_title}" with the evidence explaining why. This still consumes the repair attempt. The driver reruns the full gate on the unchanged commit; another failure stops for the operator.
12
+ Never edit a locked file: each one stays as it is at {start_sha}. Report a needed test correction in your concerns and stop BLOCKED for the operator.
13
+ Use targeted tests while you work. Before you report DONE or DONE_WITH_CONCERNS, make the fast gate green on your final commit: run `{gate}` with IMPLEMENT_SPEC_BASE={pr_branch} and IMPLEMENT_SPEC_LOCKED='{locked}' in the environment. Give its summary lines in `green`.
14
+ Commit on the checked-out PR branch, changing no existing commit. Do not dispatch subagents. The full gate and final review follow this batch.
15
+
16
+ Write one JSON report at {report} that matches this schema:
17
+
18
+ ```json
19
+ {
20
+ "type": "object",
21
+ "required": ["status", "commits", "files", "concerns", "green"],
22
+ "properties": {
23
+ "status": {"enum": ["DONE", "DONE_WITH_CONCERNS", "NEEDS_CONTEXT", "BLOCKED"]},
24
+ "commits": {"type": "array", "items": {"type": "object", "required": ["sha", "ticket"], "properties": {"sha": {"type": "string", "pattern": "^[0-9a-f]{7,40}$"}, "ticket": {"type": "string", "pattern": "^[0-9]+$"}}}},
25
+ "files": {"type": "array", "items": {"type": "string"}},
26
+ "concerns": {"type": "array", "items": {"type": "string"}},
27
+ "green": {"type": "array", "items": {"type": "string"}}
28
+ }
29
+ }
30
+ ```
31
+
32
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
33
+ Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -1,2 +1,2 @@
1
1
 
2
- The review passed, and then the driver ran the full gate on {landing_sha}, the commit that would land on {pr_branch}, and it is red: read the output in {landing_record}. The finding from the `gate` in the findings file is that record. Make it green with a commit on {branch}; the driver runs the fast gate on your commit, a re-review, and the full gate again when the ticket lands.
2
+ An earlier driver version passed review and then ran the full gate on {landing_sha}, the commit that would land on {pr_branch}, and it is red: read the output in {landing_record}. The finding from the `gate` in the findings file is that record. Make it green with a commit on {branch}; the driver runs the fast gate on your commit, a re-review, and the full gate after every ticket has merged.
@@ -4,7 +4,7 @@ One commit per ticket, in merge order:
4
4
 
5
5
  {map}
6
6
 
7
- ## Fix commits of the final review
7
+ ## Fix commits of the integrated branch
8
8
 
9
9
  {fixes}
10
10
 
@@ -15,6 +15,6 @@ One commit per ticket, in merge order:
15
15
  ## Review coverage
16
16
 
17
17
  - Branch tip and reviewed tip: {tip}
18
- - Full review: {onto}..{tidied}
18
+ - Full review: {full_review}
19
19
  - Scoped review after the fix batch: {scoped}
20
20
  {providers}
@@ -341,6 +341,46 @@ def test_a_model_the_account_cannot_use_is_skipped_and_its_roles_go_on_with_thei
341
341
  assert launches(w.tmp, "claude"), "the first agent starts on Anthropic"
342
342
 
343
343
 
344
+ def test_a_missing_first_cli_uses_the_available_reviewer_and_discloses_the_fallback(env):
345
+ """No fake runner, so the driver launches the CLI itself: `bin/claude` is a stub on the restricted PATH of `env`
346
+ that logs its argv like the `env` fakes and writes the reviewer's report, never the real claude."""
347
+ opus, unavailable = "anthropic/claude-opus-5@medium", "openai/gpt-astra@medium"
348
+ w = World(env, reviewer=[unavailable, opus], **{"final-reviewer": [unavailable, opus]})
349
+ (w.tmp / "bin/codex").unlink()
350
+ report = dict(status="DONE", files=[], concerns=[], findings=[])
351
+ (w.tmp / "bin/claude").write_text(f"""#!{sys.executable}
352
+ import re, sys
353
+ from pathlib import Path
354
+ prompt = sys.stdin.read()
355
+ if "implement-spec preflight" not in prompt:
356
+ with open({str(w.tmp / "argv-claude")!r}, "a") as log:
357
+ log.write("".join(arg + "\\0" for arg in sys.argv[1:]) + "\\x1e")
358
+ Path(re.search(r"JSON report at (\\S+?)\\.? ", prompt).group(1)).write_text({json.dumps(report)!r})
359
+ """)
360
+ proc = w.run(None, "--only", "reviewer", runner=False)
361
+ ok(proc)
362
+ assert "codex is not on PATH" in proc.stdout
363
+ argvs = launches(w.tmp, "claude")
364
+ assert argvs and all(value_after(argv, "--model") == "claude-opus-5" for argv in argvs), argvs
365
+ assert not launches(w.tmp, "codex")
366
+ assert "the correctness lens and the scoped review run on" in w.ledger()
367
+ assert f"{opus}, the implementer's provider" in w.ledger()
368
+ assert f"reviewer ran on {opus}" in w.ledger()
369
+ assert json.loads((w.repo / ".agent/implement/01/reviewer-0.json").read_text()) == report
370
+
371
+
372
+ def test_a_missing_cli_with_no_reviewer_fallback_fails_before_any_agent(env):
373
+ unavailable = "openai/gpt-astra@medium"
374
+ w = World(env, reviewer=[unavailable])
375
+ (w.tmp / "bin/codex").unlink()
376
+ proc = w.run(None, runner=False)
377
+ assert proc.returncode == 3, proc.stdout + proc.stderr
378
+ assert (f"reviewer: every model entry failed the preflight: model entry {unavailable}: codex is not on PATH"
379
+ in proc.stdout.splitlines())
380
+ assert not launches(w.tmp, "claude") and not launches(w.tmp, "codex")
381
+ assert "ticket/feat%2Fcsv/01" not in git(w.repo, "branch", "--list")
382
+
383
+
344
384
  def test_a_cli_that_fails_with_no_report_stops_the_run_with_exit_4_and_the_same_command_resumes(env):
345
385
  """Stop and ask: the first CLI failure stops the run, with no rerun on another entry of the list."""
346
386
  w = World(env, refactor=True)
@@ -152,7 +152,7 @@ def test_the_summary_keeps_its_table_and_counts_an_arbitration_as_a_reviewer_age
152
152
  # Most fake agents report no cost, so they are counted as not priced.
153
153
  assert names[-4:] == ["fix rounds per ticket", "human stops", "cost", "agents not priced"], rows
154
154
  assert re.search(r"^\| cost \| \d+\.\d\d USD \|$", rows, re.M), rows
155
- for row in ("| fast gates run | 2 |", "| full gates run | 1 |", "| agents, reviewer on anthropic/claude-opus-5@medium | 3 |",
155
+ for row in ("| fast gates run | 2 |", "| full gates run | 0 |", "| agents, reviewer on anthropic/claude-opus-5@medium | 3 |",
156
156
  "| fix rounds per ticket | 01: 1, 02: 0 |", "| human stops | 1 |"):
157
157
  assert row in rows, rows
158
158
 
@@ -223,13 +223,16 @@ def test_dirty_worktree_exits_3_naming_the_paths(env, tmp_path):
223
223
  assert "demo/export.py" in proc.stdout and "notes.txt" in proc.stdout
224
224
 
225
225
 
226
- def test_models_file_naming_a_provider_without_its_cli_exits_3(env, tmp_path):
227
- (tmp_path / "bin/codex").unlink()
226
+ def test_dry_run_checks_models_without_requiring_provider_clis(env, tmp_path):
227
+ for cli in ("claude", "codex"):
228
+ (tmp_path / f"bin/{cli}").unlink()
228
229
  repo = make_repo(tmp_path / "demo", three())
229
230
  models = models_file(tmp_path, implementer=["openai/gpt-sol@medium"])
231
+ before = snapshot(repo)
230
232
  proc = drive(env, repo, "--tickets", ".agent/tickets", "--gate", "make check", "--fast-gate", "make check", "--models", str(models), "--dry-run")
231
- assert proc.returncode == 3, proc.stderr
232
- assert any("implementer" in l and "codex" in l for l in proc.stdout.splitlines())
233
+ assert proc.returncode == 0, proc.stdout + proc.stderr
234
+ assert "max frontier width" in proc.stdout
235
+ assert_untouched(proc, repo, before, tmp_path)
233
236
 
234
237
 
235
238
  def test_one_implementer_model_is_rejected_before_any_agent(env, tmp_path):
@@ -82,7 +82,7 @@ def test_outside_a_git_worktree_git_errors_are_reported(tmp_path, monkeypatch, c
82
82
  assert code == 3 and "git status failed" in out
83
83
 
84
84
 
85
- def test_models_file_checks_the_first_entry_of_each_role(repo, capsys, tmp_path, monkeypatch):
85
+ def test_models_file_checks_configuration_without_runtime_availability(repo, capsys, tmp_path, monkeypatch):
86
86
  repo(t01=ticket("01"))
87
87
  monkeypatch.setattr(driver_agents.shutil, "which", lambda cli: None if cli == "codex" else cli)
88
88
  models = tmp_path.parent / f"{tmp_path.name}-models.json"
@@ -90,8 +90,7 @@ def test_models_file_checks_the_first_entry_of_each_role(repo, capsys, tmp_path,
90
90
  claude = {"reviewer": ["claude-opus-5-5@medium"], "final-reviewer": ["claude-opus-5-5@medium"]}
91
91
  models.write_text(json.dumps({"implementer": ["openai/gpt-sol@medium"], **claude, "fixer": ["other/x@low"]}))
92
92
  assert run(capsys, "--models", str(models)) == (
93
- 3, "implementer: codex is not on PATH (model entry openai/gpt-sol@medium)\n"
94
- "fixer: model entry other/x@low names an unknown provider (known: anthropic, openai)\n"
93
+ 3, "fixer: model entry other/x@low names an unknown provider (known: anthropic, openai)\n"
95
94
  "implementer: a second implementer model entry is required for fix round 2\n")
96
95
 
97
96
 
@@ -184,7 +183,6 @@ def test_accepted_reports_end_the_run_with_exit_0(repo, tmp_path, capsys):
184
183
  "Ticket 01: test-writer ran on claude-sonnet-5-5@medium", "Ticket 01: implementer ran on claude-sonnet-5-5@medium",
185
184
  f"Ticket 01: the fast gate is green on {tip}, record .agent/implement/01/gate-fast-{tip}.log.",
186
185
  "Ticket 01: reviewer ran on openai/gpt-6-astra@medium",
187
- f"Ticket 01: the full gate is green on {tip}, record .agent/implement/01/gate-full-{tip}.log.",
188
186
  f"Ticket 01: merged into feat/x as a fast-forward at {tip}."]
189
187
  assert ledger[1].endswith(", cost 0.25 USD: report accepted.")
190
188
  assert branches() == ["feat/x"] and "nothing to commit" in subprocess.run(
@@ -216,7 +214,7 @@ def test_an_agent_that_writes_no_report_is_rerun_once_then_blocks(repo, tmp_path
216
214
  def test_a_field_of_another_role_is_ignored(repo, tmp_path, capsys, extra):
217
215
  repo()
218
216
  code, ledger = agents(tmp_path, capsys, f"{COMMIT}fields='\"green\": [], {extra}'\n{REPORT}")
219
- assert code == 0 and len(ledger) == 5 and ledger[0].endswith("report accepted.")
217
+ assert code == 0 and len(ledger) == 4 and ledger[0].endswith("report accepted.")
220
218
 
221
219
 
222
220
  @pytest.mark.parametrize("status", ["BLOCKED", "NEEDS_CONTEXT"])
@@ -459,7 +457,7 @@ def two(repo, second="None", touches="`demo/y.py: g`"):
459
457
  return repo(t01=ticket("01", **REFACTOR), t02=ticket("02", second, touches=touches, **REFACTOR))
460
458
 
461
459
 
462
- def test_two_tickets_run_in_two_slots_and_the_second_merge_is_a_gated_merge_commit(repo, tmp_path, capsys):
460
+ def test_two_tickets_run_in_two_slots_and_only_the_integrated_tip_gets_the_full_gate(repo, tmp_path, capsys):
463
461
  two(repo)
464
462
  log = tmp_path.parent / f"{tmp_path.name}-prepare.log"
465
463
  code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT, "--prepare", f"pwd >> {log}")
@@ -467,10 +465,9 @@ def test_two_tickets_run_in_two_slots_and_the_second_merge_is_a_gated_merge_comm
467
465
  calls = dict(line.split() for line in Path(f"{tmp_path}-runner.calls").read_text().splitlines())
468
466
  assert calls == {"01": str(tmp_path.resolve()), "02": str((tmp_path / ".agent/worktrees/slot-2").resolve())}
469
467
  assert len(out_of("git", "rev-list", "--parents", "-n1", walked()).split()) == 3 # a merge commit
470
- # A fast gate on each ticket tip, a full gate on the fast-forward and on the merge commit; the fifth gate is the
471
- # full gate of the end of run, on the tidied tip.
472
- assert len([line for line in ledger if "gate is green" in line]) == 4
473
- assert "| fast gates run | 2 |" in out and "| full gates run | 3 |" in out
468
+ # Fast gates cover each ticket; the full gate covers the final tidied tip.
469
+ assert len([line for line in ledger if "gate is green" in line]) == 2
470
+ assert "| fast gates run | 2 |" in out and "| full gates run | 1 |" in out
474
471
  assert [line for line in ledger if "merged into feat/x as a merge commit" in line]
475
472
  assert {entry["phase"] for entry in state_of(tmp_path)["tickets"].values()} == {"merged"}
476
473
  assert branches() == ["feat/x"] and out_of("git", "status", "--porcelain") == ""
@@ -488,16 +485,15 @@ RESOLVE = """if [ $role = conflict ]; then git add -A; git commit -q -m resolved
488
485
  """
489
486
 
490
487
 
491
- def test_a_merge_conflict_goes_to_the_conflict_agent_once_and_its_commit_is_gated(repo, tmp_path, capsys):
488
+ def test_a_merge_conflict_goes_to_the_conflict_agent_once_before_final_integration_gating(repo, tmp_path, capsys):
492
489
  two(repo)
493
490
  code, ledger, out = walk(tmp_path, capsys, RESOLVE + "FILE=work.txt\n" + WORK + TOGETHER + REPORT)
494
491
  assert code == 0, out
495
492
  (line,) = [line for line in ledger if "the conflict agent resolved the merge conflict in work.txt at " in line]
496
493
  number, tip = line[7:9], walked()
497
494
  assert line.endswith(f" at {tip[:7]}.") and len(out_of("git", "rev-list", "--parents", "-n1", tip).split()) == 3
498
- assert (f"Ticket {number}: the full gate is green on {tip[:7]}, record .agent/implement/{number}/gate-full-{tip[:7]}.log."
499
- in ledger)
500
- assert "| fast gates run | 2 |" in out and "| full gates run | 3 |" in out and "| agents, conflict on claude-opus-5-5@medium | 1 |" in out
495
+ assert not [line for line in ledger if "the full gate" in line]
496
+ assert "| fast gates run | 2 |" in out and "| full gates run | 1 |" in out and "| agents, conflict on claude-opus-5-5@medium | 1 |" in out
501
497
  assert dict(state_of(tmp_path)["run"]["landed"])[number] == tip
502
498
  prompt = (tmp_path / f".agent/implement/{number}/conflict-0.prompt.md").read_text()
503
499
  assert "Files in conflict: work.txt\n" in prompt and prompt.rstrip().endswith("one ref store.")
@@ -548,17 +544,14 @@ def test_a_red_gate_is_a_finding_and_the_ticket_it_blocks_never_starts(repo, tmp
548
544
  assert walk(tmp_path, capsys, "exit 9\n")[0] == 2 # a BLOCKED ticket stays BLOCKED on a rerun
549
545
 
550
546
 
551
- def test_a_merge_gate_red_after_round_2_blocks_the_ticket_and_the_pr_branch_does_not_move(repo, tmp_path, capsys):
547
+ def test_a_gate_that_rejects_merge_commits_runs_only_after_tidy(repo, tmp_path, capsys):
552
548
  two(repo)
553
- gate = '[ -z "$(git rev-parse -q --verify HEAD^2)" ]' # red on each merge commit
554
- code, ledger, out = walk(tmp_path, capsys, WORK + FIXES + TOGETHER + REPORT, gate=gate)
555
- assert code == 1, out
556
- (line,) = [line for line in ledger if "BLOCKED" in line]
557
- assert "BLOCKED at the merge: the full gate is red on " in line
558
- assert len(out_of("git", "rev-list", "--parents", "-n1", "feat/x").split()) == 2 # no merge commit landed
559
- # Red full gates at landing start rounds 1 and 2; the third blocks, with no third round.
560
- assert [line.split()[-2] for line in ledger if "at the landing, so feat/x does not move" in line] == ["1", "2"]
561
- assert len(branches()) == 2 and out_of("git", "status", "--porcelain") == ""
549
+ gate = '[ -z "$(git rev-parse -q --verify HEAD^2)" ]'
550
+ code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT, gate=gate)
551
+ assert code == 0, out
552
+ assert len(out_of("git", "rev-list", "--parents", "-n1", walked()).split()) == 3
553
+ assert "| full gates run | 1 |" in out
554
+ assert {entry["phase"] for entry in state_of(tmp_path)["tickets"].values()} == {"merged"}
562
555
 
563
556
 
564
557
  def test_a_tree_that_is_not_clean_is_a_red_gate_and_the_slot_keeps_the_work(repo, tmp_path, capsys):
@@ -890,22 +883,28 @@ def test_a_run_outside_a_repository_takes_no_lock_and_makes_no_file(tmp_path, mo
890
883
  assert code == 3 and "git status failed" in out and [path.name for path in tmp_path.iterdir()] == [".agent"]
891
884
 
892
885
 
893
- def test_a_pr_branch_that_another_hand_moves_during_the_merge_gate_starts_the_landing_again(repo, tmp_path, capsys):
894
- """Ticket 09: the locked-file check and the ref move are one step. The ref moves only from the tip the check
895
- read; from a tip that moved, the merge, the check and the gate are made again."""
886
+ def move_during_landing(monkeypatch, command):
887
+ """Simulate another writer after the locked-file check and before atomic ref publication."""
888
+ original = driver._refuse_breach
889
+
890
+ def checked(number, run, landing):
891
+ original(number, run, landing)
892
+ if len(out_of("git", "rev-list", "--parents", "-n1", landing.commit).split()) == 3:
893
+ subprocess.run(command, shell=True, check=True)
894
+
895
+ monkeypatch.setattr(driver, "_refuse_breach", checked)
896
+
897
+
898
+ def test_a_pr_branch_that_another_hand_moves_during_landing_retries(repo, tmp_path, capsys, monkeypatch):
896
899
  two(repo)
897
900
  mark = tmp_path.parent / f"{tmp_path.name}-moved"
898
- # The gate of the first merge commit puts one more commit on the PR branch, as another hand would.
899
- gate = (f'[ -e {mark} ] || [ -z "$(git rev-parse -q --verify HEAD^2)" ] || {{ touch {mark}; git update-ref '
900
- 'refs/heads/feat/x "$(git commit-tree "feat/x^{tree}" -p feat/x -m other)"; }')
901
- code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT, gate=gate)
901
+ move_during_landing(monkeypatch, f'[ -e {mark} ] || {{ touch {mark}; {MOVE}; }}')
902
+ code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT)
902
903
  assert code == 0 and mark.exists(), out
903
904
  subjects = out_of("git", "log", "--format=%s", walked()).splitlines()
904
905
  assert "other" in subjects and {"implementer 01", "implementer 02"} <= set(subjects)
905
906
  assert len([line for line in ledger if "merged into feat/x as a merge commit" in line]) == 1
906
- # A fast gate on each ticket tip; a full gate on the fast-forward, the stale merge commit, the new one and at the
907
- # end of run.
908
- assert "| fast gates run | 2 |" in out and "| full gates run | 4 |" in out
907
+ assert "| fast gates run | 2 |" in out and "| full gates run | 1 |" in out
909
908
 
910
909
 
911
910
  # Ticket 09, review round 1 (m1, Codex 6): the restart has a bound, and only a stale ref starts it.
@@ -918,27 +917,18 @@ def merge_blocked(ledger):
918
917
  return line
919
918
 
920
919
 
921
- def test_a_pr_branch_that_moves_at_each_merge_gate_blocks_the_ticket_after_the_second_try(repo, tmp_path, capsys):
920
+ def test_a_pr_branch_that_moves_at_each_landing_blocks_after_the_second_try(repo, tmp_path, capsys, monkeypatch):
922
921
  two(repo)
923
- code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT, gate=MERGE_GATE + MOVE)
922
+ move_during_landing(monkeypatch, MOVE)
923
+ code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT)
924
924
  assert code == 1, out
925
925
  assert "BLOCKED at the merge: " in merge_blocked(ledger) and "feat/x" in merge_blocked(ledger)
926
- # Two ticket tips fast; the fast-forward and two merge commits full: the landing is tried two times.
927
- assert "| fast gates run | 2 |" in out and "| full gates run | 3 |" in out
926
+ # Landing is tried twice; a blocked ticket prevents the final full gate.
927
+ assert "| fast gates run | 2 |" in out and "| full gates run | 0 |" in out
928
928
  assert out_of("git", "log", "--format=%s", "feat/x").splitlines().count("other") == 2
929
929
 
930
930
 
931
- def test_a_red_merge_gate_does_not_start_the_landing_again_when_the_pr_branch_moved(repo, tmp_path, capsys):
932
- two(repo)
933
- mark = tmp_path.parent / f"{tmp_path.name}-red"
934
- gate = MERGE_GATE + f'[ -e {mark} ] || {{ touch {mark}; {MOVE}; exit 1; }}'
935
- code, ledger, out = walk(tmp_path, capsys, WORK + FIXES + TOGETHER + REPORT, gate=gate)
936
- assert code == 0 and not [line for line in ledger if "BLOCKED" in line], out
937
- # The red gate starts fix round 1, not a second landing; the fix lands at the next landing.
938
- assert len([line for line in ledger if "at the landing, so feat/x does not move and fix round 1 starts" in line]) == 1
939
-
940
-
941
- def test_a_conflict_on_the_second_try_blocks_the_ticket_with_no_conflict_agent(repo, tmp_path, capsys):
931
+ def test_a_conflict_on_the_second_try_blocks_the_ticket_with_no_conflict_agent(repo, tmp_path, capsys, monkeypatch):
942
932
  """Requirement 11: the conflict agent runs once for each merge. The second try runs no agent."""
943
933
  two(repo)
944
934
  mark = tmp_path.parent / f"{tmp_path.name}-foreign"
@@ -947,25 +937,12 @@ def test_a_conflict_on_the_second_try_blocks_the_ticket_with_no_conflict_agent(r
947
937
  'blob=$(echo foreign | git hash-object -w --stdin); for nn in 01 02; do '
948
938
  'git update-index --add --cacheinfo 100644,$blob,work-$nn.txt; done; git update-ref refs/heads/feat/x '
949
939
  '"$(git commit-tree "$(git write-tree)" -p feat/x -m other)"; rm "$GIT_INDEX_FILE" )')
950
- gate = MERGE_GATE + f'[ -e {mark} ] || {{ touch {mark}; {foreign}; }}'
951
- code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT, gate=gate)
940
+ move_during_landing(monkeypatch, f'[ -e {mark} ] || {{ touch {mark}; {foreign}; }}')
941
+ code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT)
952
942
  assert code == 1 and mark.exists(), out
953
943
  assert "BLOCKED at the merge: the merge into the PR branch conflicts in work-0" in merge_blocked(ledger)
954
944
  assert not [line for line in ledger if "conflict ran on" in line]
955
- assert "| fast gates run | 2 |" in out and "| full gates run | 2 |" in out
956
-
957
-
958
- # Fix round 1 of ticket 03.
959
-
960
- def test_a_merge_commit_the_slot_cannot_check_out_is_not_gated_and_does_not_land(repo, tmp_path, capsys):
961
- two(repo)
962
- gate = 'touch "$(git rev-parse --git-dir)/index.lock"' # after its gate, the slot can check out nothing
963
- code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT, gate=gate)
964
- assert code == 1, out
965
- (line,) = [line for line in ledger if "BLOCKED" in line]
966
- assert "BLOCKED at the merge: the slot is at " in line and "the full gate did not run" in line
967
- assert len(out_of("git", "rev-list", "--parents", "-n1", "feat/x").split()) == 2 # no merge commit landed
968
- assert "| fast gates run | 2 |" in out and "| full gates run | 1 |" in out # the full one: the fast-forward
945
+ assert "| fast gates run | 2 |" in out and "| full gates run | 0 |" in out
969
946
 
970
947
 
971
948
  @pytest.mark.parametrize("gate, after", [
@@ -1170,3 +1147,20 @@ def test_parallel_checkout_waits_for_worktree_registration_to_finish(repo, tmp_p
1170
1147
  code, _, out = walk(tmp_path, capsys, WORK + REPORT)
1171
1148
  assert code == 0, out + "\n" + "\n".join(failures)
1172
1149
  assert failures == []
1150
+
1151
+
1152
+ def test_failed_landing_checkout_blocks_before_the_local_merge(repo, tmp_path, capsys):
1153
+ repo(t01=ticket("01", **REFACTOR))
1154
+ start = out_of("git", "rev-parse", "feat/x")
1155
+ gate = 'touch "$(git rev-parse --git-dir)/index.lock"'
1156
+ code, ledger, out = walk(tmp_path, capsys, WORK + REPORT, gate=gate)
1157
+ assert code == 2, out
1158
+ assert state_of(tmp_path)["tickets"]["01"]["phase"] == "blocked"
1159
+ assert out_of("git", "rev-parse", "feat/x") == start
1160
+ assert "| full gates run | 0 |" in out
1161
+ assert any("landing checkout failed" in line for line in ledger)
1162
+ (tmp_path / ".git/index.lock").unlink()
1163
+ code, _, out = walk(tmp_path, capsys, WORK + REPORT, "--answer", "01-ticket-blocked-1=retry")
1164
+ assert code == 0, out
1165
+ assert state_of(tmp_path)["tickets"]["01"]["phase"] == "merged"
1166
+ assert "| full gates run | 1 |" in out
@@ -420,7 +420,8 @@ def test_a_conflict_with_the_fetched_base_runs_the_conflict_agent_once_then_the_
420
420
  rig = conflicted
421
421
  assert rig.code == 0, rig.output()
422
422
  (call,) = rig.final_calls("conflict")
423
- (gate,) = [g for g in rig.gates() if g["commit"] == call["sha"]]
423
+ (gate,) = rig.gates("full")
424
+ assert gate["commit"] == rig.branch()
424
425
  assert gate["t0"] >= call["t1"], "the gate follows the resolution"
425
426
  base = ref(rig.origin, "refs/heads/main")
426
427
  git(rig.repo, "merge-base", "--is-ancestor", base, "feat/csv")
@@ -611,3 +612,58 @@ def test_a_cached_body_that_no_longer_validates_is_rewritten_before_gh_pr_create
611
612
  assert len(rig.final_calls("pr-writer")) == 2, "the invalid cached body was not rewritten"
612
613
  (pr,) = rig.prs()
613
614
  assert risk_valid(tmp_path, pr["body"].split("## Tickets")[0]) and "styles" not in pr["body"].split("## Tickets")[0]
615
+
616
+
617
+ def test_full_gate_runs_only_after_every_ticket_is_integrated(tmp_path):
618
+ rig = Final(tmp_path, THREE).run(plan())
619
+ assert rig.code == 0, rig.output()
620
+ full = rig.gates('full')
621
+ assert len(full) == 1
622
+ assert full[0]['commit'] == rig.branch()
623
+ assert all(entry['phase'] == 'merged' for entry in rig.state()['tickets'].values())
624
+ assert len(rig.gates('fast')) == 3
625
+
626
+
627
+ @pytest.mark.parametrize("review_fix", [False, True])
628
+ def test_red_integration_gate_is_repaired_before_full_review_without_ticket_rounds(tmp_path, review_fix):
629
+ rig = Final(tmp_path)
630
+ rig.gate_conf(full={'subjects': ['feat(01): Export rows']})
631
+ repairs = [fixer('fixed\n', 'repair integration', ticket_of='01')]
632
+ if review_fix:
633
+ repairs.append(fixer('reviewed\n', 'repair review finding', ticket_of='01'))
634
+ steps = plan(**{'final/fixer': repairs, 'final/final-spec': [final(finding('FOLLOWUP')) if review_fix else final()]})
635
+ rig.run(steps, '--push')
636
+ assert rig.code == 0, rig.output()
637
+ assert rig.state()['tickets']['01']['round'] == 0
638
+ assert rig.state()['tickets']['01']['phase'] == 'merged'
639
+ assert len(rig.final_calls('fixer')) == 1 + int(review_fix)
640
+ call = rig.final_calls('fixer')[0]
641
+ assert 'gate-full-' in call['prompt']
642
+ assert rig.final_calls('final-spec')[0]['t0'] > call['t1']
643
+ assert [g['exit'] for g in rig.gates('full')] == ([1, 0, 0] if review_fix else [1, 0])
644
+ full_tip = rig.final_calls('final-spec')[0]['head']
645
+ state = rig.state()['run']['final']
646
+ body = rig.prs()[0]['body']
647
+ assert f"Full review: {state['onto']}..{full_tip}" in body
648
+ scoped = f'{full_tip}..{rig.branch()}' if review_fix else 'not needed'
649
+ assert f'Scoped review after the fix batch: {scoped}' in body
650
+ assert 'Fix commits of the integrated branch' in body
651
+
652
+
653
+ @pytest.mark.parametrize('transient', [True, False])
654
+ def test_final_gate_repair_can_prove_no_code_change_but_still_spends_its_attempt(tmp_path, transient):
655
+ rig = Final(tmp_path)
656
+ rig.gate_conf(full={'subjects': ['feat(01): Export rows']})
657
+ no_change = {'report': dict(status='DONE_WITH_CONCERNS', commits=[], files=[], green=['targeted checks pass'],
658
+ concerns=['the full integration gate is red on $HEAD: inspected the exact log; no code change is needed'])}
659
+ if transient:
660
+ no_change['files'] = {str(rig.rig / 'gate.json'): '{}'} # repair the external gate environment
661
+ rig.run(plan(**{'final/fixer': [no_change]}), '--push')
662
+ assert rig.code == (0 if transient else 2), rig.output()
663
+ state = rig.state()['run']['final']
664
+ assert state['gate_repairs'] == 1
665
+ assert rig.branch() == state['tidied']
666
+ assert len(rig.final_calls('fixer')) == 1
667
+ assert [g['exit'] for g in rig.gates('full')] == [1, 0 if transient else 1]
668
+ assert bool(rig.pushes()) == transient
669
+ assert len(rig.final_calls('final-spec')) == int(transient)
@@ -0,0 +1,155 @@
1
+ """Full integration gating through the driver CLI, after ticket landings."""
2
+ import pytest
3
+
4
+ from test_final import fixer
5
+ from test_walk import plan
6
+ from test_fixloop import inside # noqa: F401 (in-process runtime discovery)
7
+ from test_tidy import Inside, tools # noqa: F401 (fake gh and signing config)
8
+
9
+
10
+ @pytest.mark.parametrize("reword", [False, True])
11
+ def test_red_repair_parks_once_and_retry_uses_saved_failure_without_reopening_tickets(tmp_path, reword):
12
+ rig = Inside(tmp_path)
13
+ rig.gate_conf(full={'subjects': ['feat(01): Export rows', 'fix(01): first repair']})
14
+ steps = plan(**{'final/fixer': [fixer('first\n', 'first repair', ticket_of='01'),
15
+ fixer('second\n', 'second repair', ticket_of='01')]})
16
+ rig.run(steps, '--push')
17
+ assert rig.code == 2, rig.output()
18
+ assert len(rig.final_calls('fixer')) == 1
19
+ assert not rig.final_calls('final-spec') and not rig.pushes()
20
+ assert rig.state()['tickets']['01']['phase'] == 'merged'
21
+ assert rig.final()['gate_allowance'] == 1
22
+ assert rig.state()['run']['questions'][0]['resume']['gate_allowance'] == 2
23
+ gate_count = len(rig.gates('full'))
24
+ if reword:
25
+ import json
26
+ state = rig.state()
27
+ state['run']['questions'][0]['subject'] = 'Revised wording for the integration retry'
28
+ (rig.repo / '.agent/implement/state.json').write_text(json.dumps(state))
29
+ rig.run(steps, '--push', '--answer', 'final-ticket-blocked-1=retry')
30
+ assert rig.code == 0, rig.output()
31
+ assert len(rig.final_calls('fixer')) == 2
32
+ assert len(rig.calls('01', 'implementer')) == 1
33
+ assert len(rig.gates('full')) == gate_count + 1
34
+ assert rig.final()['gate_repairs'] == rig.final()['gate_allowance'] == 2
35
+ assert rig.state()['tickets']['01']['round'] == 0
36
+ assert rig.pushes() == [f'refs/heads/feat/csv {rig.branch()}']
37
+
38
+
39
+ def test_editing_after_red_gate_does_not_grant_another_repair(tmp_path):
40
+ rig = Inside(tmp_path)
41
+ rig.gate_conf(full={'subjects': ['feat(01): Export rows', 'fix(01): first repair']})
42
+ steps = plan(**{'final/fixer': [fixer('first\n', 'first repair', ticket_of='01')]})
43
+ rig.run(steps)
44
+ assert rig.code == 2, rig.output()
45
+ snapshot = rig.snap()
46
+ rig.run(steps, '--answer', 'final-ticket-blocked-1=edit')
47
+ assert rig.code == 1, rig.output()
48
+ assert rig.final()['gate_allowance'] == rig.final()['gate_repairs'] == 1
49
+ assert len(rig.calls()) == snapshot.calls and len(rig.gates()) == snapshot.gates
50
+ assert rig.state()['tickets']['01']['phase'] == 'merged'
51
+
52
+
53
+ def test_interrupted_integration_repair_resumes_from_saved_log(tmp_path, monkeypatch):
54
+ import driver_final
55
+ from driver_run import Halted
56
+
57
+ rig = Inside(tmp_path)
58
+ rig.gate_conf(full={'subjects': ['feat(01): Export rows']})
59
+ steps = plan(**{'final/fixer': [fixer('fixed\n', 'repair integration', ticket_of='01')]})
60
+ real = driver_final._run_fixer
61
+
62
+ def interrupted(*args, **kwargs):
63
+ raise Halted('interrupted before repair')
64
+
65
+ monkeypatch.setattr(driver_final, '_run_fixer', interrupted)
66
+ rig.run(steps)
67
+ assert rig.code == 4 and len(rig.gates('full')) == 1, rig.out
68
+ assert rig.final()['gate_failure']['record'].endswith('.log')
69
+ assert rig.final()['gate_repairs'] == 0
70
+ monkeypatch.setattr(driver_final, '_run_fixer', real)
71
+ rig.run(steps)
72
+ assert rig.code == 0, rig.out
73
+ assert [gate['exit'] for gate in rig.gates('full')] == [1, 0]
74
+ assert len(rig.calls('01', 'implementer')) == 1
75
+ assert rig.final()['gate_repairs'] == 1
76
+
77
+
78
+ def test_old_final_state_gains_an_unused_repair_allowance_without_rerunning_work(tmp_path):
79
+ import json
80
+
81
+ rig = Inside(tmp_path).run(plan())
82
+ assert rig.code == 0, rig.out
83
+ snapshot = rig.snap()
84
+ state = rig.state()
85
+ del state['run']['final']['gate_repairs']
86
+ del state['run']['final']['gate_allowance']
87
+ del state['run']['final']['gate_failure']
88
+ del state['run']['final']['lenses']
89
+ (rig.repo / '.agent/implement/state.json').write_text(json.dumps(state))
90
+ rig.run(plan())
91
+ assert rig.code == 0, rig.out
92
+ assert len(rig.calls()) == snapshot.calls and len(rig.gates()) == snapshot.gates
93
+ assert rig.final()['gate_repairs'] == 0 and rig.final()['gate_failure'] is None
94
+ assert rig.final()['gate_allowance'] == 1
95
+ rig.run(plan(), '--push')
96
+ assert rig.code == 0, rig.out
97
+ body = rig.prs()[0]['body']
98
+ assert f"Full review: {rig.final()['onto']}..{rig.final()['tidied']}" in body
99
+ assert 'Scoped review after the fix batch: not needed' in body
100
+
101
+
102
+ def test_gate_repair_after_review_fix_preserves_findings_for_scoped_review(tmp_path):
103
+ from test_final import final
104
+ from test_review import finding
105
+
106
+ rig = Inside(tmp_path)
107
+ rig.gate_conf(full={'subjects': ['fix(01): review fix']})
108
+ steps = plan(**{'final/final-spec': [final(finding('KEEP-THIS-FINDING'))],
109
+ 'final/fixer': [fixer('review\n', 'review fix', ticket_of='01'),
110
+ fixer('gate\n', 'gate repair', ticket_of='01')]})
111
+ rig.run(steps, '--push')
112
+ assert rig.code == 0, rig.out
113
+ assert [gate['exit'] for gate in rig.gates('full')] == [0, 1, 0]
114
+ assert len(rig.final_calls('final-spec')) == 1
115
+ assert len(rig.final_calls('final-reviewer')) == 1
116
+ assert 'KEEP-THIS-FINDING' in (rig.repo / '.agent/implement/final/findings-0.json').read_text()
117
+ scoped = rig.final_calls('final-reviewer')[0]
118
+ assert scoped['head'] == rig.branch()
119
+ assert 'findings-0.json' in scoped['prompt']
120
+ assert rig.final()['reviewed'] == rig.branch()
121
+ assert rig.pushes() == [f'refs/heads/feat/csv {rig.branch()}']
122
+
123
+
124
+ @pytest.mark.parametrize("transient", [True, False])
125
+ def test_evidenced_noop_repair_checks_the_same_tip_and_keeps_the_bound(tmp_path, monkeypatch, transient):
126
+ import test_final
127
+
128
+ monkeypatch.setattr(test_final, "Final", Inside)
129
+ test_final.test_final_gate_repair_can_prove_no_code_change_but_still_spends_its_attempt(tmp_path, transient)
130
+
131
+
132
+ def test_noop_gate_repair_without_failure_evidence_cannot_spend_or_publish(tmp_path):
133
+ rig = Inside(tmp_path)
134
+ rig.gate_conf(full={"subjects": ["feat(01): Export rows"]})
135
+ empty = {"report": dict(status="DONE", commits=[], files=[], green=["passed"], concerns=["no change"])}
136
+ rig.run(plan(**{"final/fixer": [empty, empty]}), "--push")
137
+ assert rig.code == 2, rig.out
138
+ assert rig.final()["gate_repairs"] == 0
139
+ assert len(rig.gates("full")) == 1 and not rig.pushes()
140
+ assert "no concern names the finding the full integration gate is red" in rig.out
141
+
142
+
143
+ def test_gate_repair_preserves_locked_tests_and_escalates_a_needed_correction(tmp_path):
144
+ rig = Inside(tmp_path)
145
+ rig.gate_conf(full={"subjects": ["feat(01): Export rows"]})
146
+ changed = fixer("fixed\n", "alter test", ticket_of="01")
147
+ changed["commits"][0]["files"]["tests/test_01.py"] = "changed = True\n"
148
+ changed["report"]["files"].append("tests/test_01.py")
149
+ retry = {"report": dict(changed["report"], commits=[{"sha": "$HEAD", "ticket": "01"}])}
150
+ rig.run(plan(**{"final/fixer": [changed, retry]}), "--push")
151
+ assert rig.code == 2, rig.out
152
+ assert "locked file changed: tests/test_01.py" in rig.out
153
+ assert rig.final()["gate_repairs"] == 0 and not rig.pushes()
154
+ assert rig.branch() == rig.final()["tidied"]
155
+ assert rig.state()["tickets"]["01"]["phase"] == "merged"