@jesdi/skills 0.0.94 → 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.
@@ -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
 
@@ -183,7 +183,6 @@ def test_accepted_reports_end_the_run_with_exit_0(repo, tmp_path, capsys):
183
183
  "Ticket 01: test-writer ran on claude-sonnet-5-5@medium", "Ticket 01: implementer ran on claude-sonnet-5-5@medium",
184
184
  f"Ticket 01: the fast gate is green on {tip}, record .agent/implement/01/gate-fast-{tip}.log.",
185
185
  "Ticket 01: reviewer ran on openai/gpt-6-astra@medium",
186
- f"Ticket 01: the full gate is green on {tip}, record .agent/implement/01/gate-full-{tip}.log.",
187
186
  f"Ticket 01: merged into feat/x as a fast-forward at {tip}."]
188
187
  assert ledger[1].endswith(", cost 0.25 USD: report accepted.")
189
188
  assert branches() == ["feat/x"] and "nothing to commit" in subprocess.run(
@@ -215,7 +214,7 @@ def test_an_agent_that_writes_no_report_is_rerun_once_then_blocks(repo, tmp_path
215
214
  def test_a_field_of_another_role_is_ignored(repo, tmp_path, capsys, extra):
216
215
  repo()
217
216
  code, ledger = agents(tmp_path, capsys, f"{COMMIT}fields='\"green\": [], {extra}'\n{REPORT}")
218
- 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.")
219
218
 
220
219
 
221
220
  @pytest.mark.parametrize("status", ["BLOCKED", "NEEDS_CONTEXT"])
@@ -458,7 +457,7 @@ def two(repo, second="None", touches="`demo/y.py: g`"):
458
457
  return repo(t01=ticket("01", **REFACTOR), t02=ticket("02", second, touches=touches, **REFACTOR))
459
458
 
460
459
 
461
- 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):
462
461
  two(repo)
463
462
  log = tmp_path.parent / f"{tmp_path.name}-prepare.log"
464
463
  code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT, "--prepare", f"pwd >> {log}")
@@ -466,10 +465,9 @@ def test_two_tickets_run_in_two_slots_and_the_second_merge_is_a_gated_merge_comm
466
465
  calls = dict(line.split() for line in Path(f"{tmp_path}-runner.calls").read_text().splitlines())
467
466
  assert calls == {"01": str(tmp_path.resolve()), "02": str((tmp_path / ".agent/worktrees/slot-2").resolve())}
468
467
  assert len(out_of("git", "rev-list", "--parents", "-n1", walked()).split()) == 3 # a merge commit
469
- # A fast gate on each ticket tip, a full gate on the fast-forward and on the merge commit; the fifth gate is the
470
- # full gate of the end of run, on the tidied tip.
471
- assert len([line for line in ledger if "gate is green" in line]) == 4
472
- 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
473
471
  assert [line for line in ledger if "merged into feat/x as a merge commit" in line]
474
472
  assert {entry["phase"] for entry in state_of(tmp_path)["tickets"].values()} == {"merged"}
475
473
  assert branches() == ["feat/x"] and out_of("git", "status", "--porcelain") == ""
@@ -487,16 +485,15 @@ RESOLVE = """if [ $role = conflict ]; then git add -A; git commit -q -m resolved
487
485
  """
488
486
 
489
487
 
490
- 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):
491
489
  two(repo)
492
490
  code, ledger, out = walk(tmp_path, capsys, RESOLVE + "FILE=work.txt\n" + WORK + TOGETHER + REPORT)
493
491
  assert code == 0, out
494
492
  (line,) = [line for line in ledger if "the conflict agent resolved the merge conflict in work.txt at " in line]
495
493
  number, tip = line[7:9], walked()
496
494
  assert line.endswith(f" at {tip[:7]}.") and len(out_of("git", "rev-list", "--parents", "-n1", tip).split()) == 3
497
- assert (f"Ticket {number}: the full gate is green on {tip[:7]}, record .agent/implement/{number}/gate-full-{tip[:7]}.log."
498
- in ledger)
499
- 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
500
497
  assert dict(state_of(tmp_path)["run"]["landed"])[number] == tip
501
498
  prompt = (tmp_path / f".agent/implement/{number}/conflict-0.prompt.md").read_text()
502
499
  assert "Files in conflict: work.txt\n" in prompt and prompt.rstrip().endswith("one ref store.")
@@ -547,17 +544,14 @@ def test_a_red_gate_is_a_finding_and_the_ticket_it_blocks_never_starts(repo, tmp
547
544
  assert walk(tmp_path, capsys, "exit 9\n")[0] == 2 # a BLOCKED ticket stays BLOCKED on a rerun
548
545
 
549
546
 
550
- 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):
551
548
  two(repo)
552
- gate = '[ -z "$(git rev-parse -q --verify HEAD^2)" ]' # red on each merge commit
553
- code, ledger, out = walk(tmp_path, capsys, WORK + FIXES + TOGETHER + REPORT, gate=gate)
554
- assert code == 1, out
555
- (line,) = [line for line in ledger if "BLOCKED" in line]
556
- assert "BLOCKED at the merge: the full gate is red on " in line
557
- assert len(out_of("git", "rev-list", "--parents", "-n1", "feat/x").split()) == 2 # no merge commit landed
558
- # Red full gates at landing start rounds 1 and 2; the third blocks, with no third round.
559
- assert [line.split()[-2] for line in ledger if "at the landing, so feat/x does not move" in line] == ["1", "2"]
560
- 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"}
561
555
 
562
556
 
563
557
  def test_a_tree_that_is_not_clean_is_a_red_gate_and_the_slot_keeps_the_work(repo, tmp_path, capsys):
@@ -889,22 +883,28 @@ def test_a_run_outside_a_repository_takes_no_lock_and_makes_no_file(tmp_path, mo
889
883
  assert code == 3 and "git status failed" in out and [path.name for path in tmp_path.iterdir()] == [".agent"]
890
884
 
891
885
 
892
- def test_a_pr_branch_that_another_hand_moves_during_the_merge_gate_starts_the_landing_again(repo, tmp_path, capsys):
893
- """Ticket 09: the locked-file check and the ref move are one step. The ref moves only from the tip the check
894
- 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):
895
899
  two(repo)
896
900
  mark = tmp_path.parent / f"{tmp_path.name}-moved"
897
- # The gate of the first merge commit puts one more commit on the PR branch, as another hand would.
898
- gate = (f'[ -e {mark} ] || [ -z "$(git rev-parse -q --verify HEAD^2)" ] || {{ touch {mark}; git update-ref '
899
- 'refs/heads/feat/x "$(git commit-tree "feat/x^{tree}" -p feat/x -m other)"; }')
900
- 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)
901
903
  assert code == 0 and mark.exists(), out
902
904
  subjects = out_of("git", "log", "--format=%s", walked()).splitlines()
903
905
  assert "other" in subjects and {"implementer 01", "implementer 02"} <= set(subjects)
904
906
  assert len([line for line in ledger if "merged into feat/x as a merge commit" in line]) == 1
905
- # A fast gate on each ticket tip; a full gate on the fast-forward, the stale merge commit, the new one and at the
906
- # end of run.
907
- 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
908
908
 
909
909
 
910
910
  # Ticket 09, review round 1 (m1, Codex 6): the restart has a bound, and only a stale ref starts it.
@@ -917,27 +917,18 @@ def merge_blocked(ledger):
917
917
  return line
918
918
 
919
919
 
920
- 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):
921
921
  two(repo)
922
- 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)
923
924
  assert code == 1, out
924
925
  assert "BLOCKED at the merge: " in merge_blocked(ledger) and "feat/x" in merge_blocked(ledger)
925
- # Two ticket tips fast; the fast-forward and two merge commits full: the landing is tried two times.
926
- 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
927
928
  assert out_of("git", "log", "--format=%s", "feat/x").splitlines().count("other") == 2
928
929
 
929
930
 
930
- def test_a_red_merge_gate_does_not_start_the_landing_again_when_the_pr_branch_moved(repo, tmp_path, capsys):
931
- two(repo)
932
- mark = tmp_path.parent / f"{tmp_path.name}-red"
933
- gate = MERGE_GATE + f'[ -e {mark} ] || {{ touch {mark}; {MOVE}; exit 1; }}'
934
- code, ledger, out = walk(tmp_path, capsys, WORK + FIXES + TOGETHER + REPORT, gate=gate)
935
- assert code == 0 and not [line for line in ledger if "BLOCKED" in line], out
936
- # The red gate starts fix round 1, not a second landing; the fix lands at the next landing.
937
- 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
938
-
939
-
940
- 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):
941
932
  """Requirement 11: the conflict agent runs once for each merge. The second try runs no agent."""
942
933
  two(repo)
943
934
  mark = tmp_path.parent / f"{tmp_path.name}-foreign"
@@ -946,25 +937,12 @@ def test_a_conflict_on_the_second_try_blocks_the_ticket_with_no_conflict_agent(r
946
937
  'blob=$(echo foreign | git hash-object -w --stdin); for nn in 01 02; do '
947
938
  'git update-index --add --cacheinfo 100644,$blob,work-$nn.txt; done; git update-ref refs/heads/feat/x '
948
939
  '"$(git commit-tree "$(git write-tree)" -p feat/x -m other)"; rm "$GIT_INDEX_FILE" )')
949
- gate = MERGE_GATE + f'[ -e {mark} ] || {{ touch {mark}; {foreign}; }}'
950
- 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)
951
942
  assert code == 1 and mark.exists(), out
952
943
  assert "BLOCKED at the merge: the merge into the PR branch conflicts in work-0" in merge_blocked(ledger)
953
944
  assert not [line for line in ledger if "conflict ran on" in line]
954
- assert "| fast gates run | 2 |" in out and "| full gates run | 2 |" in out
955
-
956
-
957
- # Fix round 1 of ticket 03.
958
-
959
- def test_a_merge_commit_the_slot_cannot_check_out_is_not_gated_and_does_not_land(repo, tmp_path, capsys):
960
- two(repo)
961
- gate = 'touch "$(git rev-parse --git-dir)/index.lock"' # after its gate, the slot can check out nothing
962
- code, ledger, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT, gate=gate)
963
- assert code == 1, out
964
- (line,) = [line for line in ledger if "BLOCKED" in line]
965
- assert "BLOCKED at the merge: the slot is at " in line and "the full gate did not run" in line
966
- assert len(out_of("git", "rev-list", "--parents", "-n1", "feat/x").split()) == 2 # no merge commit landed
967
- 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
968
946
 
969
947
 
970
948
  @pytest.mark.parametrize("gate, after", [
@@ -1169,3 +1147,20 @@ def test_parallel_checkout_waits_for_worktree_registration_to_finish(repo, tmp_p
1169
1147
  code, _, out = walk(tmp_path, capsys, WORK + REPORT)
1170
1148
  assert code == 0, out + "\n" + "\n".join(failures)
1171
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"
@@ -656,89 +656,35 @@ def test_a_red_gate_on_the_implementer_commit_starts_fix_round_1_with_the_record
656
656
  assert [gate["commit"] for gate in rig.gates()].count(tip) == 1 and not rig.led("killed by signal")
657
657
 
658
658
 
659
- # ---------------------------------------------------------------- a red full gate at landing
660
-
661
- def full_red(rig, commit):
662
- """The exit of each full gate that the rig's gate logged on `commit`."""
663
- return [gate["exit"] for gate in rig.gates("full") if gate["commit"] == commit]
664
-
665
-
666
- def test_a_red_full_gate_at_landing_starts_round_1_and_the_fix_gets_a_fast_gate_a_re_review_and_a_full_gate(tmp_path):
667
- rig = Inside(tmp_path, gate={"full": {"subjects": ["feat: 01 rows"]}})
668
- rig.run(plan(**{"01/fixer": [fix("01", 1)]}))
669
- assert rig.code == 0, rig.ledger()
670
- assert [call["role"] for call in rig.calls("01")] == ["test-writer", "implementer", "reviewer", "fixer", "reviewer"]
671
- tip, fixed = rig.sha("01", "implementer"), rig.sha("01", "fixer")
672
- record = f".agent/implement/01/gate-full-{tip[:7]}.log"
673
- assert full_red(rig, tip) == [1] and full_red(rig, fixed) == [0]
674
- assert [gate["commit"] for gate in rig.gates("fast")] == [tip, fixed]
675
- # The PR branch did not move to the red tip: the fixer started with the PR branch at the spec commit.
676
- fixer_call = rig.calls("01", "fixer")[0]
677
- assert "feat: 01 rows" not in fixer_call["pr_log"] and fixer_call["branch"] == "ticket/feat%2Fcsv/01"
678
- *review_findings, gate = json.loads((rig.folder() / "findings-0.json").read_text())
679
- assert (gate["source"], gate["severity"], gate["kind"], gate["file"]) == ("gate", "critical", "code", record)
680
- assert gate["title"] == f"the full gate is red on {tip[:7]}"
681
- assert rig.led(f"Ticket 01: the full gate is red on {tip[:7]} at the landing, so feat/csv does not move and fix "
682
- "round 1 starts.")
683
- prompt = rig.prompt("fixer-1")
684
- assert "findings-0.json" in prompt and record in prompt and "not on ticket/feat%2Fcsv/01" not in prompt
685
- assert f"The fix is {tip}..{fixed}" in rig.prompt("reviewer-1")
686
- entry = rig.state()["tickets"]["01"]
687
- assert (entry["round"], entry["phase"], entry["landing"]) == (1, "merged", None)
688
-
689
-
690
- def test_a_red_full_gate_on_a_merge_commit_sends_the_fixer_to_the_ticket_branch_with_the_merge_commit(tmp_path):
691
- files = {"01-export-rows.md": ticket("01", "Export rows"),
692
- "02-quote-fields.md": ticket("02", "Quote fields", touches="`demo/other.py: g`")}
693
- rig = Inside(tmp_path, files, gate={"full": {"subjects": ["feat: 02 rows"]}})
694
- rig.run(plan(**{"02/implementer": [impl("02", "demo/other.py", wait_pr_moves=True)],
695
- "02/fixer": [fix("02", 1, files={"demo/other.py": "x = 1\n"})]}))
696
- assert rig.code == 0, "\n".join(rig.ledger())
697
- tip = rig.sha("02", "implementer")
698
- (merge,) = [gate["commit"] for gate in rig.gates("full") if gate["exit"]]
699
- assert merge != tip and tip not in [gate["commit"] for gate in rig.gates("full")]
700
- fixer_call = rig.calls("02", "fixer")[0]
701
- assert (fixer_call["branch"], fixer_call["head"]) == ("ticket/feat%2Fcsv/02", tip)
702
- prompt = rig.prompt("fixer-1", "02")
703
- assert f"{merge[:7]} is not on ticket/feat%2Fcsv/02: it is the merge commit" in prompt
704
- assert f"implement/02/gate-full-{merge[:7]}.log" in prompt and "git merge --no-commit --no-ff feat/csv" in prompt
705
- assert rig.state()["tickets"]["02"]["phase"] == "merged"
706
-
707
-
708
- def test_a_red_full_gate_at_landing_after_round_2_blocks_the_ticket_and_its_dependent(tmp_path):
709
- rig = Inside(tmp_path, three(), gate={"full": {"subjects": ["fix: 01 round 2"]}})
710
- rig.run(plan(**{"01/reviewer": [review("01", [STUCK]), review("01", [STUCK]), review("01")],
711
- "01/fixer": [fix("01", n) for n in (1, 2)]}))
712
- (red,) = [gate["commit"] for gate in rig.gates("full") if gate["exit"]] # 03 may land first: then a merge commit
713
- assert f"BLOCKED at the merge: the full gate is red on {red[:7]}" in blocked(rig), rig.ledger()
714
- assert len(rig.calls("01", "fixer")) == 2 and rig.state()["tickets"]["01"]["round"] == 2
715
- assert "fix: 01 round 2" not in rig.pr_subjects() and "Ticket 01: merged" not in "".join(rig.ledger())
716
- assert not rig.calls("02") and rig.state()["tickets"]["02"]["phase"] == "pending"
717
- assert rig.state()["tickets"]["03"]["phase"] == "merged"
718
-
719
-
720
- def test_a_run_stopped_after_a_red_full_gate_at_landing_resumes_with_the_fixer(tmp_path, monkeypatch):
721
- rig = Inside(tmp_path, gate={"full": {"subjects": ["feat: 01 rows"]}})
722
- real = driver_fixloop.red_landing
723
-
724
- def stop(*args):
725
- try:
726
- real(*args)
727
- except driver_fixloop.Unlanded:
728
- raise driver_run.Halted("stopped right after the red landing") from None
729
-
730
- monkeypatch.setattr(driver_fixloop, "red_landing", stop)
659
+ # Old persisted landing rounds remain resumable; new landings never start one.
660
+ def test_legacy_red_landing_round_resumes_without_another_landing_gate(tmp_path, monkeypatch):
661
+ rig = Inside(tmp_path)
662
+ real = driver._checked_landing
663
+
664
+ def old_landing(ticket, slot, run, may_resolve):
665
+ landing = real(ticket, slot, run, may_resolve)
666
+ record = f".agent/implement/{ticket.number}/gate-full-{landing.commit[:7]}.log"
667
+ (rig.repo / record).write_text("legacy full gate failure\n")
668
+ found = [{"severity": "critical", "kind": "code", "source": "gate", "file": record,
669
+ "line": 0, "title": "legacy landing failure", "evidence": record}]
670
+ (rig.folder() / "findings-0.json").write_text(json.dumps(found))
671
+ run.state.ticket(ticket.number, phase="fix", round=1, landing=landing.commit)
672
+ raise driver_run.Halted("stopped after legacy red landing")
673
+
674
+ monkeypatch.setattr(driver, "_checked_landing", old_landing)
731
675
  steps = plan(**{"01/fixer": [fix("01", 1)]})
732
676
  rig.run(steps)
733
677
  assert rig.code == 4 and not rig.calls("01", "fixer"), rig.ledger()
734
- entry, tip = rig.state()["tickets"]["01"], rig.sha("01", "implementer")
735
- assert (entry["phase"], entry["round"], entry["landing"]) == ("fix", 1, tip)
736
- monkeypatch.setattr(driver_fixloop, "red_landing", real)
678
+ entry = rig.state()["tickets"]["01"]
679
+ assert (entry["phase"], entry["round"]) == ("fix", 1)
680
+ monkeypatch.setattr(driver, "_checked_landing", real)
737
681
  rig.run(steps)
738
682
  assert rig.code == 0, rig.ledger()
739
- roles = [call["role"] for call in rig.calls("01")]
740
- assert roles == ["test-writer", "implementer", "reviewer", "fixer", "reviewer"]
741
- assert full_red(rig, tip) == [1] and rig.state()["tickets"]["01"]["round"] == 1
683
+ assert [call["role"] for call in rig.calls("01")] == [
684
+ "test-writer", "implementer", "reviewer", "fixer", "reviewer"]
685
+ assert rig.state()["tickets"]["01"]["round"] == 1
686
+ assert f"gate-full-{entry['landing'][:7]}.log" in rig.prompt("fixer-1")
687
+ assert all(gate["branch"] == "feat/csv" for gate in rig.gates("full"))
742
688
 
743
689
 
744
690
  def killed(rig, subject, times, end="os.kill(os.getpid(), signal.SIGTERM)"):
@@ -1091,7 +1037,8 @@ def test_a_reviewer_that_times_out_starts_again_from_the_clean_tip(tmp_path):
1091
1037
  def test_a_conflict_is_resolved_once_in_the_ticket_slot_and_a_second_one_blocks(tmp_path):
1092
1038
  rig = test_review.conflicted(under(tmp_path, "once"))
1093
1039
  assert rig.code == 0, rig.ledger()
1094
- assert rig.tip() in [gate["commit"] for gate in rig.gates()] and dict(rig.state()["run"]["landed"])["01"] == rig.tip()
1040
+ assert dict(rig.state()["run"]["landed"])["01"] == rig.tip()
1041
+ assert len(rig.gates("full")) == 1 and rig.gates("full")[0]["branch"] == "feat/csv"
1095
1042
  assert rig.led("Ticket 01: the conflict agent resolved the merge conflict in demo/cli.py at ")
1096
1043
  prompt = rig.prompt("conflict-0")
1097
1044
  assert "Files in conflict: demo/cli.py\n" in prompt and f"at commit {rig.sha('03', 'implementer')}\n" in prompt
@@ -265,9 +265,13 @@ def cli(text):
265
265
  return f"def main():\n return {text!r}\n"
266
266
 
267
267
 
268
- def conflicted(tmp, moves_again=False):
268
+ def conflicted(tmp, moves_again=False, dirty=False):
269
269
  """01 and 03 both add demo/cli.py; 03 merges first, so 01's merge conflicts."""
270
270
  rig = Review(tmp, {k: v for k, v in three().items() if not k.startswith("02")})
271
+ if dirty:
272
+ runner = rig.rig / "run-agent"
273
+ runner.write_text(runner.read_text().replace('if step.get("report") is not None:',
274
+ 'if role == "conflict": Path("leftover.txt").write_text("uncommitted work")\nif step.get("report") is not None:'))
271
275
  resolve = {"files": {"demo/cli.py": cli("resolved")}, "commit": "merge: resolve cli",
272
276
  "report": {"status": "DONE", "commits": ["$SHA"], "files": ["demo/cli.py"], "concerns": []}}
273
277
  if moves_again: # while the agent works, another commit lands on the PR branch and changes the same file
@@ -285,12 +289,12 @@ def conflicted(tmp, moves_again=False):
285
289
  "01/conflict": [resolve]}))
286
290
 
287
291
 
288
- def test_a_conflicting_merge_runs_the_conflict_agent_once_then_the_gate_on_the_merge_commit(tmp_path):
292
+ def test_a_conflicting_merge_runs_the_conflict_agent_once_then_the_final_integration_gate(tmp_path):
289
293
  rig = conflicted(tmp_path)
290
294
  assert rig.code == 0, rig.output()
291
295
  (call,) = rig.calls("01", "conflict")
292
296
  assert call["cwd"] == rig.calls("01", "implementer")[0]["cwd"], "in the ticket's slot"
293
- assert rig.tip() in [g["commit"] for g in rig.gates()], "the merge commit is gated"
297
+ assert [g["commit"] for g in rig.gates("full")] == [git(rig.repo, "rev-parse", "feat/csv").strip()]
294
298
  assert git(rig.repo, "show", "feat/csv:demo/cli.py") == cli("resolved")
295
299
  assert rig.led("demo/cli.py", "onflict")
296
300
 
@@ -301,3 +305,12 @@ def test_a_second_conflict_on_the_same_merge_blocks_the_ticket(tmp_path):
301
305
  assert len(rig.calls("01", "conflict")) == 1
302
306
  assert rig.led("01", "BLOCKED") and rig.state()["tickets"]["01"]["phase"] == "blocked"
303
307
  assert rig.state()["tickets"]["03"]["phase"] == "merged"
308
+
309
+
310
+ def test_conflict_resolution_with_uncommitted_work_does_not_land(tmp_path):
311
+ rig = conflicted(tmp_path, dirty=True)
312
+ assert rig.state()["tickets"]["01"]["phase"] == "blocked", rig.output()
313
+ assert len(rig.calls("01", "conflict")) == 1
314
+ assert not rig.gates("full")
315
+ assert rig.led("uncommitted", "BLOCKED")
316
+ assert "ticket/feat%2Fcsv/01" in rig.branches()