@jesdi/skills 0.0.43 → 0.0.45

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.
@@ -4,6 +4,7 @@ import fcntl
4
4
  import json
5
5
  import os
6
6
  import subprocess
7
+ import sys
7
8
  import time
8
9
  from pathlib import Path
9
10
 
@@ -13,6 +14,7 @@ import pytest
13
14
  import driver
14
15
  import driver_agents
15
16
  import driver_report
17
+ import driver_state
16
18
 
17
19
  from conftest import GIT, ticket
18
20
 
@@ -33,7 +35,7 @@ def test_a_run_without_dry_run_needs_the_spec(repo, capsys):
33
35
  repo(t01=ticket("01"))
34
36
  assert driver.main(["--gate", "make check"]) == 3
35
37
  assert capsys.readouterr().out == "--spec is required: the spec file the prompts point at\n"
36
- assert "ticket/01" not in subprocess.run(["git", "branch"], capture_output=True, text=True).stdout
38
+ assert "ticket/feat%2Fx/01" not in subprocess.run(["git", "branch"], capture_output=True, text=True).stdout
37
39
 
38
40
 
39
41
  def test_every_environment_and_ticket_error_is_listed_together(repo, capsys):
@@ -158,7 +160,7 @@ def ledger_of(tmp_path):
158
160
 
159
161
  def walked(*short):
160
162
  """The PR tip as the tickets left it: the recovery point of the tidy when there is one, else the tip of feat/x."""
161
- made = subprocess.run(["git", "rev-parse", *short, "-q", "--verify", "refs/implement/recovery"], capture_output=True, text=True)
163
+ made = subprocess.run(["git", "rev-parse", *short, "-q", "--verify", "refs/implement-spec/feat%2Fx/recovery"], capture_output=True, text=True)
162
164
  return made.stdout.strip() or subprocess.run(["git", "rev-parse", *short, "feat/x"], capture_output=True, text=True).stdout.strip()
163
165
 
164
166
 
@@ -242,7 +244,7 @@ def test_a_moved_head_prompt_line_comes_from_its_template(repo, tmp_path, capsys
242
244
  repo()
243
245
  tip = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True).stdout.strip()
244
246
  agents(tmp_path, capsys, "git checkout -q --detach\n")
245
- line = (driver_report.PROMPTS / "moved.md").read_text().replace("{branch}", "ticket/01").replace("{tip}", tip)
247
+ line = (driver_report.PROMPTS / "moved.md").read_text().replace("{branch}", "ticket/feat%2Fx/01").replace("{tip}", tip)
246
248
  assert line in prompt_of(tmp_path) and prompt_of(tmp_path).rstrip().endswith("one ref store.")
247
249
 
248
250
 
@@ -307,10 +309,10 @@ def test_a_timeout_doubles_the_limit_and_a_second_one_blocks(repo, tmp_path, cap
307
309
 
308
310
 
309
311
  @pytest.mark.parametrize("move, problem", [
310
- ("git checkout -q feat/x", "HEAD is on feat/x instead of ticket/01"),
311
- ("git checkout -q --detach", "HEAD is on a detached commit instead of ticket/01"),
312
- ("git checkout -q --detach; git branch -q -D ticket/01", "branch ticket/01 is missing"),
313
- ("git checkout -q -B ticket/01 HEAD~1", "ticket/01 no longer holds"),
312
+ ("git checkout -q feat/x", "HEAD is on feat/x instead of ticket/feat%2Fx/01"),
313
+ ("git checkout -q --detach", "HEAD is on a detached commit instead of ticket/feat%2Fx/01"),
314
+ ("git checkout -q --detach; git branch -q -D ticket/feat%2Fx/01", "branch ticket/feat%2Fx/01 is missing"),
315
+ ("git checkout -q -B ticket/feat%2Fx/01 HEAD~1", "ticket/feat%2Fx/01 no longer holds"),
314
316
  ])
315
317
  def test_a_moved_head_resets_the_slot_and_reruns(repo, tmp_path, capsys, move, problem):
316
318
  repo()
@@ -326,7 +328,7 @@ def test_a_moved_head_resets_the_slot_and_reruns(repo, tmp_path, capsys, move, p
326
328
 
327
329
  def test_an_existing_ticket_branch_stops_the_run(repo, tmp_path, capsys):
328
330
  repo()
329
- subprocess.run(["git", "branch", "ticket/01"], check=True)
331
+ subprocess.run(["git", "branch", "ticket/feat%2Fx/01"], check=True)
330
332
  assert agents(tmp_path, capsys, "exit 0\n") == (3, [])
331
333
 
332
334
 
@@ -357,7 +359,7 @@ echo "$role $nn" >> "${FILE:-work-$nn.txt}"; git add -A; git commit -q -m "$role
357
359
  echo "$nn $PWD" >> "$0.calls"
358
360
  """
359
361
  # Ticket 01 waits until ticket 02 has its branch, so both start from the same PR tip.
360
- TOGETHER = """[ "$nn" != 01 ] || until git rev-parse -q --verify refs/heads/ticket/02 > /dev/null; do sleep 0.02; done\n"""
362
+ TOGETHER = """[ "$nn" != 01 ] || until git rev-parse -q --verify refs/heads/ticket/feat%2Fx/02 > /dev/null; do sleep 0.02; done\n"""
361
363
  REFACTOR = {"seam": "none — refactor"}
362
364
  # A fixer that cannot make the red gate green: the ticket blocks at fix round 1.
363
365
  GIVE_UP = """[ $role != fixer ] || { printf '{"status": "BLOCKED", "commits": [], "files": [], "concerns": ["the gate stays red"], "green": [], "ticket": "01"}' > "$report"; exit 0; }\n"""
@@ -437,7 +439,7 @@ def test_a_conflict_agent_that_does_not_resolve_blocks_the_ticket_and_keeps_its_
437
439
  assert f"BLOCKED at the merge: the conflict agent: report .agent/implement/{number}/conflict-0.json is not" in line
438
440
  assert len([line for line in ledger if "conflict ran on" in line]) == 2 # the one rerun of a violation
439
441
  assert state_of(tmp_path)["tickets"][number]["phase"] == "blocked"
440
- assert f"ticket/{number}" in branches() and f"Ticket {number} is not merged: its phase is blocked." in out
442
+ assert f"ticket/feat%2Fx/{number}" in branches() and f"Ticket {number} is not merged: its phase is blocked." in out
441
443
  for slot in (".", ".agent/worktrees/slot-2"): # the driver's open merge is gone
442
444
  assert out_of("git", "-C", slot, "status", "--porcelain") == ""
443
445
  assert out_of("git", "-C", slot, "rev-parse", "-q", "--verify", "MERGE_HEAD") == ""
@@ -450,7 +452,7 @@ def test_a_conflict_cli_that_fails_stops_the_run_and_leaves_no_open_merge(repo,
450
452
  assert code == 4 and "with no report: ERROR: not signed in" in out, out
451
453
  assert not [line for line in ledger if "BLOCKED" in line]
452
454
  (number,) = [n for n, entry in state_of(tmp_path)["tickets"].items() if entry["phase"] == "merge"]
453
- assert f"ticket/{number}" in branches()
455
+ assert f"ticket/feat%2Fx/{number}" in branches()
454
456
  for slot in (".", ".agent/worktrees/slot-2"):
455
457
  assert out_of("git", "-C", slot, "status", "--porcelain") == ""
456
458
  assert out_of("git", "-C", slot, "rev-parse", "-q", "--verify", "MERGE_HEAD") == ""
@@ -459,7 +461,7 @@ def test_a_conflict_cli_that_fails_stops_the_run_and_leaves_no_open_merge(repo,
459
461
  def test_a_red_gate_is_a_finding_and_the_ticket_it_blocks_never_starts(repo, tmp_path, capsys):
460
462
  two(repo, second="01")
461
463
  code, ledger, out = walk(tmp_path, capsys, GIVE_UP + WORK + REPORT, gate="echo CHECK-OUTPUT; exit 1")
462
- tip = out_of("git", "rev-parse", "--short=7", "ticket/01")
464
+ tip = out_of("git", "rev-parse", "--short=7", "ticket/feat%2Fx/01")
463
465
  assert code == 1 and ledger[-1] == GAVE_UP, out
464
466
  assert ledger[1] == (f"Ticket 01: critical finding of kind code from the gate at "
465
467
  f".agent/implement/01/gate-{tip}.log:0: the gate is red on {tip}.")
@@ -487,7 +489,7 @@ def test_a_tree_that_is_not_clean_is_a_red_gate_and_the_slot_keeps_the_work(repo
487
489
  assert code == 1 and "from the gate at .agent/implement/01/gate-" in ledger[-3] and ledger[-1] == GAVE_UP, out
488
490
  record = next((tmp_path / ".agent/implement/01").glob("gate-*.log")).read_text()
489
491
  assert "status: not clean\n ?? junk.txt\n" in record and "exit: not run" in record and "\nNEVER\n" not in record
490
- assert out_of("git", "symbolic-ref", "--short", "HEAD") == "ticket/01" and (tmp_path / "junk.txt").exists()
492
+ assert out_of("git", "symbolic-ref", "--short", "HEAD") == "ticket/feat%2Fx/01" and (tmp_path / "junk.txt").exists()
491
493
  code, _, out = walk(tmp_path, capsys, "exit 9\n")
492
494
  assert code == 3 and "uncommitted change: junk.txt" in out
493
495
 
@@ -524,7 +526,7 @@ def test_a_resumed_tip_that_is_not_on_the_branch_returns_the_ticket_to_implement
524
526
  base = out_of("git", "rev-parse", "feat/x")
525
527
  code, ledger, out = walk(tmp_path, capsys, WORK + REPORT)
526
528
  assert code == 0, out
527
- assert "Ticket 01: returned to implement from the PR tip: the recorded tip 1111111 is not on ticket/01." in ledger
529
+ assert "Ticket 01: returned to implement from the PR tip: the recorded tip 1111111 is not on ticket/feat%2Fx/01." in ledger
528
530
  assert out_of("git", "rev-parse", "feat/x~1") == base # the earlier, untrusted commit is not in the PR branch
529
531
 
530
532
 
@@ -537,10 +539,102 @@ def test_a_resumed_ticket_with_a_settled_gate_merges_without_a_gate_or_an_agent(
537
539
  (tmp_path / ".agent/implement/state.json").write_text(json.dumps(state))
538
540
  # A gate on the ticket branch is still red, so a second gate for the settled commit would block the ticket. The
539
541
  # one new gate is that of the end of run, on the PR branch.
540
- code, ledger, out = walk(tmp_path, capsys, "exit 9\n", gate='[ "$(git rev-parse --abbrev-ref HEAD)" != ticket/01 ]')
542
+ code, ledger, out = walk(tmp_path, capsys, "exit 9\n", gate='[ "$(git rev-parse --abbrev-ref HEAD)" != ticket/feat%2Fx/01 ]')
541
543
  assert code == 0 and walked() == tip and "| gates run | 2 |" in out
542
544
 
543
545
 
546
+ def as_older_driver(tmp_path, *numbers):
547
+ """Make the run in tmp_path one that an older driver started: no `schema`, and the old names of its ticket
548
+ branches and of its recovery ref."""
549
+ state = state_of(tmp_path)
550
+ del state["run"]["schema"]
551
+ (tmp_path / ".agent/implement/state.json").write_text(json.dumps(state))
552
+ for nn in numbers:
553
+ subprocess.run(["git", "branch", "-m", f"ticket/feat%2Fx/{nn}", f"ticket/{nn}"], check=True)
554
+ if recovery := out_of("git", "rev-parse", "-q", "--verify", "refs/implement-spec/feat%2Fx/recovery"):
555
+ subprocess.run(["git", "update-ref", "refs/implement/recovery", recovery], check=True)
556
+ subprocess.run(["git", "update-ref", "-d", "refs/implement-spec/feat%2Fx/recovery"], check=True)
557
+ return recovery
558
+
559
+
560
+ def test_a_run_of_an_older_driver_resumes_on_its_renamed_ticket_branch(repo, tmp_path, capsys):
561
+ """An older driver named the ticket branch `ticket/NN`. The resume renames it and trusts the recorded tip."""
562
+ entry = blocked_then_edited(repo, tmp_path, capsys, phase="merge")
563
+ state = state_of(tmp_path)
564
+ state["tickets"]["01"]["green_gates"] = [entry["tip"]]
565
+ (tmp_path / ".agent/implement/state.json").write_text(json.dumps(state))
566
+ as_older_driver(tmp_path, "01")
567
+ code, ledger, out = walk(tmp_path, capsys, "exit 9\n")
568
+ assert code == 0, out
569
+ assert "Ticket 01: renamed the branch ticket/01 of an older driver to ticket/feat%2Fx/01." in ledger
570
+ assert not any("returned to implement" in line for line in ledger) and walked() == entry["tip"]
571
+ assert branches() == ["feat/x"]
572
+
573
+
574
+ def test_a_run_of_an_older_driver_on_a_contradicted_ticket_branch_returns_the_ticket_to_implement(repo, tmp_path,
575
+ capsys):
576
+ """Spec review: slot 1 is on `ticket/NN` of an older driver, and git contradicts the recorded tip, so the branch
577
+ keeps its old name. The resume accepts slot 1 there, as the older driver did, and starts the ticket again."""
578
+ blocked_then_edited(repo, tmp_path, capsys, phase="review", tip="1" * 40)
579
+ as_older_driver(tmp_path, "01")
580
+ subprocess.run(["git", "checkout", "-q", "ticket/01"], check=True)
581
+ code, ledger, out = walk(tmp_path, capsys, WORK + REPORT)
582
+ assert code == 0, out
583
+ assert "Ticket 01: returned to implement from the PR tip: the recorded tip 1111111 is not on ticket/feat%2Fx/01." in ledger
584
+ assert not [line for line in ledger if "renamed" in line]
585
+
586
+
587
+ def test_a_ticket_branch_of_an_older_driver_that_git_cannot_rename_stops_the_run(repo, tmp_path, capsys):
588
+ blocked_then_edited(repo, tmp_path, capsys)
589
+ as_older_driver(tmp_path, "01")
590
+ subprocess.run(["git", "branch", "ticket/feat%2Fx"], check=True) # a branch where the folder of the new name goes
591
+ code, ledger, out = walk(tmp_path, capsys, "exit 9\n")
592
+ assert code == 3 and out.startswith("implement-spec: cannot rename the branch ticket/01 of an older driver to "
593
+ "ticket/feat%2Fx/01: "), out
594
+ assert "ticket/01" in branches() and not [line for line in ledger if "renamed" in line]
595
+
596
+
597
+ def test_a_finished_run_of_an_older_driver_gets_the_new_name_of_its_recovery_ref(repo, tmp_path, capsys):
598
+ """Spec review: the recovery ref moves through the driver, before the end of run reads it."""
599
+ repo(t01=ticket("01", **REFACTOR))
600
+ assert walk(tmp_path, capsys, WORK + REPORT)[0] == 0
601
+ recovery = as_older_driver(tmp_path)
602
+ assert recovery
603
+ code, _, out = walk(tmp_path, capsys, "exit 9\n")
604
+ assert code == 0, out
605
+ assert ("Recovery point: moved refs/implement/recovery of an older driver to refs/implement-spec/feat%2Fx/recovery."
606
+ in (tmp_path / ".agent/implement/ledger.md").read_text().splitlines())
607
+ assert out_of("git", "rev-parse", "-q", "--verify", "refs/implement/recovery") == "" and walked() == recovery
608
+
609
+
610
+ def test_no_older_driver_starts_while_a_newer_driver_runs(repo, tmp_path, capsys):
611
+ """Spec review: the newer driver holds the lock of an older driver, shared, for its whole run. The agent tries to
612
+ take that lock as an older driver does, alone, and cannot."""
613
+ repo(t01=ticket("01", **REFACTOR))
614
+ old_lock = Path(out_of("git", "rev-parse", "--git-common-dir")).resolve() / "implement-spec.lock"
615
+ probe = tmp_path.parent / f"{tmp_path.name}-probe"
616
+ older = (f'"{sys.executable}" -c "import fcntl; fcntl.flock(open(\'{old_lock}\', \'a\'), '
617
+ f'fcntl.LOCK_EX | fcntl.LOCK_NB)" 2>/dev/null; echo $? > {probe}\n')
618
+ code, _, out = walk(tmp_path, capsys, older + WORK + REPORT)
619
+ assert code == 0 and probe.read_text() == "1\n", out
620
+
621
+
622
+ @pytest.mark.parametrize("older_run", [False, True])
623
+ def test_a_newer_driver_waits_while_an_older_driver_runs(repo, tmp_path, capsys, older_run):
624
+ """Correctness review: an older driver holds only `implement-spec.lock`, so a newer driver waits for that lock,
625
+ on a run of its own and on a run that an older driver started."""
626
+ blocked_then_edited(repo, tmp_path, capsys)
627
+ if older_run:
628
+ as_older_driver(tmp_path, "01")
629
+ old_lock = Path(out_of("git", "rev-parse", "--git-common-dir")).resolve() / "implement-spec.lock"
630
+ with hold(old_lock):
631
+ code, ledger, out = walk(tmp_path, capsys, "exit 9\n")
632
+ assert code == 3 and out == ("implement-spec: a driver of an older version runs in this repository: it holds the "
633
+ f"lock {old_lock}. Wait until it ends, then run the driver again.\n")
634
+ assert ("ticket/01" if older_run else "ticket/feat%2Fx/01") in branches()
635
+ assert not [line for line in ledger if "renamed" in line] and state_of(tmp_path)["tickets"]["01"]["phase"] == "blocked"
636
+
637
+
544
638
  def test_an_unknown_phase_fails_the_resume(repo, tmp_path, capsys):
545
639
  blocked_then_edited(repo, tmp_path, capsys, phase="polish")
546
640
  code, _, out = walk(tmp_path, capsys, "exit 9\n")
@@ -567,12 +661,23 @@ def test_a_first_run_on_a_detached_head_or_with_no_slot_is_refused(repo, tmp_pat
567
661
  assert code == 3 and "the PR worktree is on a detached HEAD" in out
568
662
 
569
663
 
664
+ def test_a_first_run_in_a_slot_of_another_run_is_refused(repo, tmp_path, capsys):
665
+ """Correctness review: a slot has no state.json of its own, so its ticket branch would name a lock of its own,
666
+ and two drivers would control one worktree."""
667
+ repo(t01=ticket("01", **REFACTOR))
668
+ subprocess.run(["git", "checkout", "-q", "-b", "ticket/feat%2Fx/01"], check=True)
669
+ code, ledger, out = walk(tmp_path, capsys, "exit 9\n")
670
+ assert (code, ledger) == (3, []) and out == (
671
+ "the PR worktree is on the ticket branch ticket/feat%2Fx/01 of a run: check out the PR branch\n")
672
+ assert not (tmp_path / ".agent/implement").exists()
673
+
674
+
570
675
  def test_a_ticket_branch_that_cannot_be_checked_out_blocks_the_ticket(repo, tmp_path, capsys):
571
676
  """A slot of an earlier run with more slots still holds the branch."""
572
677
  blocked_then_edited(repo, tmp_path, capsys, phase="implement")
573
- subprocess.run(["git", "worktree", "add", "-q", str(tmp_path.parent / f"{tmp_path.name}-other"), "ticket/01"], check=True)
678
+ subprocess.run(["git", "worktree", "add", "-q", str(tmp_path.parent / f"{tmp_path.name}-other"), "ticket/feat%2Fx/01"], check=True)
574
679
  code, ledger, _ = walk(tmp_path, capsys, "exit 9\n")
575
- assert code == 1 and "BLOCKED at the start: cannot check out ticket/01 in slot 1" in ledger[-1]
680
+ assert code == 1 and "BLOCKED at the start: cannot check out ticket/feat%2Fx/01 in slot 1" in ledger[-1]
576
681
 
577
682
 
578
683
  def test_an_interrupt_kills_the_running_agents_and_stops_the_driver_at_once(repo, tmp_path, capsys, monkeypatch):
@@ -599,15 +704,62 @@ def test_an_interrupt_kills_the_running_agents_and_stops_the_driver_at_once(repo
599
704
  assert "interrupted; run it again to resume" in capsys.readouterr().out
600
705
 
601
706
 
602
- def test_a_second_driver_on_the_same_repository_exits_3_and_changes_nothing(repo, tmp_path, capsys):
707
+ def hold(lock: Path):
708
+ """The lock of another driver: it holds the kernel lock while it runs."""
709
+ lock.parent.mkdir(parents=True, exist_ok=True)
710
+ held = lock.open("w")
711
+ fcntl.flock(held, fcntl.LOCK_EX | fcntl.LOCK_NB)
712
+ return held
713
+
714
+
715
+ def test_a_driver_on_another_pr_branch_does_not_stop_the_run(repo, tmp_path, capsys):
716
+ """Runs on different PR branches share no state.json, no slot and no ref, so the lock of one stops no other."""
717
+ repo(t01=ticket("01", **REFACTOR))
718
+ locks = Path(out_of("git", "rev-parse", "--git-common-dir")).resolve() / "implement-spec"
719
+ with hold(locks / "feat%2Fother.lock"), hold(locks / "feat.lock"):
720
+ code, _, out = walk(tmp_path, capsys, WORK + REPORT)
721
+ assert code == 0 and "1 of 1 tickets are merged into feat/x." in out
722
+ assert branches() == ["feat/x"] # the merge deleted ticket/feat%2Fx/01
723
+
724
+
725
+ def test_a_driver_that_starts_while_the_first_starts_its_run_locks_the_branch_of_that_run(repo, monkeypatch):
726
+ """Correctness review: right after the second driver reads HEAD, the first one writes state.json and puts slot 1
727
+ on a ticket branch. The PR branch that the second driver locks is still the one of that run."""
728
+ repo(t01=ticket("01", **REFACTOR))
729
+ real = driver.driver_slots.on_branch
730
+
731
+ def first_driver_moves(slot):
732
+ here = real(slot)
733
+ driver.STATE.parent.mkdir(parents=True, exist_ok=True)
734
+ driver.STATE.write_text(json.dumps({"run": {"pr_branch": "feat/x"}}))
735
+ subprocess.run(["git", "checkout", "-q", "-b", "ticket/feat%2Fx/01"], check=True)
736
+ return here
737
+ monkeypatch.setattr(driver.driver_slots, "on_branch", first_driver_moves)
738
+ assert driver._run_branch() == "feat/x"
739
+
740
+
741
+ def test_a_run_that_leaves_its_branch_while_the_driver_takes_the_lock_exits_3(repo, tmp_path, capsys, monkeypatch):
742
+ repo(t01=ticket("01", **REFACTOR))
743
+ real = driver_state.lock
744
+
745
+ def lock_while_another_run_starts(path, shared=False):
746
+ driver.STATE.parent.mkdir(parents=True, exist_ok=True)
747
+ driver.STATE.write_text(json.dumps({"run": {"pr_branch": "feat/other", "schema": driver_state.SCHEMA}}))
748
+ return real(path, shared)
749
+ monkeypatch.setattr(driver_state, "lock", lock_while_another_run_starts)
750
+ code, ledger, out = walk(tmp_path, capsys, WORK + REPORT)
751
+ assert (code, ledger) == (3, []) and out == (
752
+ "implement-spec: the run in this worktree left feat/x while the driver took its lock: run the driver again\n")
753
+
754
+
755
+ def test_a_second_driver_on_the_same_pr_branch_exits_3_and_changes_nothing(repo, tmp_path, capsys):
603
756
  """Final review, correctness 1: two drivers on one state.json lose updates and move the same refs. Ticket 09:
604
757
  the lock is in the git common directory, so it is the same file in every worktree of the repository."""
605
758
  repo(t01=ticket("01", **REFACTOR))
606
- lock = Path(out_of("git", "rev-parse", "--git-common-dir")).resolve() / "implement-spec.lock"
607
- with lock.open("w") as other: # the first driver: it holds the kernel lock while it runs
608
- fcntl.flock(other, fcntl.LOCK_EX | fcntl.LOCK_NB)
759
+ lock = Path(out_of("git", "rev-parse", "--git-common-dir")).resolve() / "implement-spec/feat%2Fx.lock"
760
+ with hold(lock):
609
761
  code, ledger, out = walk(tmp_path, capsys, WORK + REPORT)
610
- assert (code, out) == (3, "implement-spec: another driver runs in this repository: it holds the lock "
762
+ assert (code, out) == (3, "implement-spec: another driver runs on feat/x: it holds the lock "
611
763
  f"{lock}. Wait until it ends, then run the driver again.\n")
612
764
  assert ledger == [] and not (tmp_path / ".agent/implement").exists() and branches() == ["feat/x"]
613
765
  assert not Path(f"{tmp_path}-runner.calls").exists()
@@ -755,7 +907,11 @@ def test_a_merged_ticket_whose_commits_left_the_pr_branch_is_not_merged_on_a_rer
755
907
  assert code == 1 and f"End of run: BLOCKED at feat/x does not hold the tidied tip {tip}" in out, out
756
908
 
757
909
 
758
- def test_a_rerun_after_an_interrupt_keeps_the_work_in_each_slot_and_reruns_the_role(repo, tmp_path, capsys, monkeypatch):
910
+ @pytest.mark.parametrize("older_driver", [False, True])
911
+ def test_a_rerun_after_an_interrupt_keeps_the_work_in_each_slot_and_reruns_the_role(repo, tmp_path, capsys, monkeypatch,
912
+ older_driver):
913
+ """With `older_driver`, the interrupted run is one whose driver named the ticket branches `ticket/NN` (spec
914
+ review): the resume renames each one, also in the slot that has it, and the slot keeps its work."""
759
915
  two(repo)
760
916
  mark = f"{tmp_path.parent}/{tmp_path.name}-started"
761
917
 
@@ -776,6 +932,8 @@ def test_a_rerun_after_an_interrupt_keeps_the_work_in_each_slot_and_reruns_the_r
776
932
  walk(tmp_path, capsys, hang)
777
933
  slot2 = tmp_path / ".agent/worktrees/slot-2"
778
934
  assert (tmp_path / "wip-01.txt").exists() and (slot2 / "wip-02.txt").exists()
935
+ if older_driver:
936
+ as_older_driver(tmp_path, "01", "02")
779
937
  resume = ('grep -q "was interrupted" "$prompt" || exit 9\nnn=$(basename "$(dirname "$report")")\n'
780
938
  '[ "$(cat wip-$nn.txt)" = half ] || exit 8\n')
781
939
  code, ledger, out = walk(tmp_path, capsys, resume + WORK + REPORT)
@@ -785,6 +943,8 @@ def test_a_rerun_after_an_interrupt_keeps_the_work_in_each_slot_and_reruns_the_r
785
943
  assert out_of("git", "show", "feat/x:wip-01.txt") == "half" and out_of("git", "show", "feat/x:wip-02.txt") == "half"
786
944
  assert [line for line in ledger if "Ticket 02: resumed in slot 2 with the work the interrupted implementer left" in line]
787
945
  assert out_of("git", "status", "--porcelain") == "" and branches() == ["feat/x"]
946
+ renamed = [f"Ticket {nn}: renamed the branch ticket/{nn} of an older driver to ticket/feat%2Fx/{nn}." for nn in ("01", "02")]
947
+ assert [line for line in ledger if "renamed the branch" in line] == (renamed if older_driver else [])
788
948
 
789
949
 
790
950
  def test_the_preflight_asks_each_used_entry_once_and_names_each_cli_that_fails(tmp_path, monkeypatch):
@@ -10,7 +10,7 @@ Interface choices (ticket 06):
10
10
  the rebase and the push (ticket 08): test_amendments.py holds those tests.
11
11
  - its agents report into `.agent/implement/final/`, so the fake runner keys them `final/final-reviewer`,
12
12
  `final/fixer` and `final/conflict`; gate records there are `gate-<first 7 hex>.log`.
13
- - recovery point: before the rebase the driver sets `refs/implement/recovery` to the PR tip and writes the ledger
13
+ - recovery point: before the rebase the driver sets `refs/implement-spec/feat%2Fcsv/recovery` to the PR tip and writes the ledger
14
14
  sentence "Recovery point: ... <sha>". An ended run leaves the ref in place.
15
15
  - a tidied commit has the subject `feat(NN): <ticket title>` and a body line `Ticket: <ticket file name>`.
16
16
  - the final fixer's `commits` hold `{"sha", "ticket"}` objects, and the driver renames each fixer commit to
@@ -44,7 +44,7 @@ if step.get("hold"):
44
44
  before = git("rev-parse", "feat/csv")
45
45
  time.sleep(step["hold"])
46
46
  rec["held"] = dict(before=before, after=git("rev-parse", "feat/csv"),
47
- recovery=git("rev-parse", "--verify", "-q", "refs/implement/recovery"))
47
+ recovery=git("rev-parse", "--verify", "-q", "refs/implement-spec/feat%2Fcsv/recovery"))
48
48
  for cmd in step.get("git", []):''', 1).replace(
49
49
  'sha = ""\nif "commit" in step:',
50
50
  '''sha = ""
@@ -142,7 +142,7 @@ class Final(Review):
142
142
  return ref(self.repo, "feat/csv")
143
143
 
144
144
  def recovery(self):
145
- return ref(self.repo, "refs/implement/recovery")
145
+ return ref(self.repo, "refs/implement-spec/feat%2Fcsv/recovery")
146
146
 
147
147
  def commits(self, base, tip="feat/csv"):
148
148
  raw = git(self.repo, "log", "--reverse", "--no-merges", "--format=%H%x1f%s%x1f%b%x1e", f"{base}..{tip}")
@@ -223,7 +223,7 @@ def test_seven_commits_in_merge_order_are_tidied_into_three_ticket_commits_with_
223
223
  rows = rig.commits(rig.start)
224
224
  assert [r["subject"] for r in rows] == [f"feat({nn}): {TITLES[nn]}" for nn in ("01", "03", "02")]
225
225
  assert all(f"Ticket: {FILES[nn]}" in r["body"] for nn, r in zip(("01", "03", "02"), rows))
226
- assert ref(rig.repo, "feat/csv^{tree}") == ref(rig.repo, "refs/implement/recovery^{tree}")
226
+ assert ref(rig.repo, "feat/csv^{tree}") == ref(rig.repo, "refs/implement-spec/feat%2Fcsv/recovery^{tree}")
227
227
 
228
228
 
229
229
  def test_one_gate_record_exists_for_the_tidied_tip_and_the_final_reviewer_is_pointed_at_it(story):
@@ -440,7 +440,7 @@ def test_unattended_with_everything_validated_pushes_once_opens_the_pr_and_write
440
440
 
441
441
 
442
442
  def test_unattended_with_a_blocked_ticket_pushes_nothing_and_exits_1(tmp_path):
443
- rig = Final(tmp_path, THREE, gate={"red": ["ticket/01"]})
443
+ rig = Final(tmp_path, THREE, gate={"red": ["ticket/feat%2Fcsv/01"]})
444
444
  rig.run(plan(), *UNATTENDED)
445
445
  assert rig.code == 1, rig.output()
446
446
  assert rig.pushes() == [] and not rig.prs() and not ref(rig.origin, "refs/heads/feat/csv")
@@ -238,7 +238,6 @@ def test_a_fixture_correction_that_is_rejected_blocks_the_ticket(tmp_path):
238
238
 
239
239
  WEAK = "def test_x():\n assert True\n"
240
240
  LOCKED_01 = tw("01")["files"]["tests/test_01.py"]
241
- REFUSED_01 = "Ticket 02: BLOCKED at the merge: locked file changed: tests/test_01.py."
242
241
  CHEAT = impl("02", files={"demo/export.py": "def fn_02():\n return '02'\n", "tests/test_01.py": WEAK})
243
242
 
244
243
 
@@ -246,14 +245,15 @@ def on_pr(rig, path):
246
245
  return subprocess.run(["git", "-C", str(rig.repo), "show", f"feat/csv:{path}"], capture_output=True, text=True).stdout
247
246
 
248
247
 
249
- def test_a_later_ticket_that_weakens_a_locked_test_of_a_merged_ticket_does_not_land(tmp_path):
248
+ def test_a_later_ticket_that_weakens_a_locked_test_of_a_merged_ticket_lands_only_with_the_test_put_back(tmp_path):
250
249
  """Final review, correctness 3: ticket 02 replaced the locked assertion of ticket 01, merged and was pushed.
251
- Ticket 09: the check is at the landing, on the tree that is about to land, so the review has no such finding."""
250
+ Issue #90: the review finds the change; the restore keeps the gate green, so it closes the finding alone."""
252
251
  rig = Inside(tmp_path, three()).run(plan(**{"02/implementer": [CHEAT]}))
253
- assert blocked(rig, "02") == REFUSED_01 and rig.led("locked file changed") == [REFUSED_01], rig.ledger()
254
- assert json.loads((rig.folder("02") / "findings-0.json").read_text()) == [] and not rig.calls("02", "fixer")
255
- assert on_pr(rig, "tests/test_01.py") == LOCKED_01 and "feat: 02 rows" not in rig.pr_subjects()
256
- assert [rig.state()["tickets"][nn]["phase"] for nn in ("01", "03")] == ["merged", "merged"]
252
+ assert rig.code == 0, rig.ledger()
253
+ assert rig.led("Ticket 02: critical finding of kind fixture from the driver at tests/test_01.py:1")
254
+ assert rig.led("Ticket 02:", "the restore closes it") and not rig.led("locked file changed")
255
+ assert len(rig.calls("02", "test-writer")) == 1 and not rig.calls("02", "fixer")
256
+ assert on_pr(rig, "tests/test_01.py") == LOCKED_01 and "feat: 02 rows" in rig.pr_subjects()
257
257
 
258
258
 
259
259
  def extends(text, listed):
@@ -286,11 +286,11 @@ def test_the_test_writer_of_a_later_ticket_may_extend_the_locked_file_of_a_merge
286
286
 
287
287
 
288
288
  def test_a_refactor_ticket_may_not_change_a_locked_test_of_a_merged_ticket(tmp_path):
289
- """It has no test-writer and no locked file of its own: the landing check is the one that protects ticket 01."""
289
+ """It has no test-writer and no locked file of its own: the review finds the change, and the restore closes it."""
290
290
  files = three(**{"02-quote-fields.md": test_review.ticket("02", "Quote fields", "01", seam="none — refactor", criteria=())})
291
291
  rig = Inside(tmp_path, files).run(plan(**{"02/implementer": [CHEAT]}))
292
- assert blocked(rig, "02") == REFUSED_01 and not rig.calls("02", "test-writer"), rig.ledger()
293
- assert on_pr(rig, "tests/test_01.py") == LOCKED_01
292
+ assert rig.code == 0 and not rig.calls("02", "test-writer"), rig.ledger()
293
+ assert rig.led("Ticket 02:", "the restore closes it") and on_pr(rig, "tests/test_01.py") == LOCKED_01
294
294
  clean = Inside(under(tmp_path, "clean"), files).run(plan())
295
295
  assert clean.code == 0 and not clean.led("locked file changed"), clean.ledger()
296
296
 
@@ -362,6 +362,35 @@ def test_the_restore_before_a_correction_is_committed_so_the_next_fixer_and_its_
362
362
  assert "The driver put back these files at their locked versions" in prompt and "tests/test_01.py" in prompt
363
363
 
364
364
 
365
+ ADAPTED_01 = LOCKED_01 + "# adapted to the interface of 02\n"
366
+ ADAPTS = impl("02", files={"demo/export.py": "def fn_02():\n return '02'\n", "tests/test_01.py": ADAPTED_01})
367
+ RESTORE = "implement-spec: restore the locked files before the correction"
368
+
369
+
370
+ def writes(nn, text, subject):
371
+ """A test-writer correction that writes tests/test_<nn>.py and lists it."""
372
+ return {**tw(nn), "files": {f"tests/test_{nn}.py": text}, "commit": subject}
373
+
374
+
375
+ def test_a_restored_locked_file_of_a_merged_ticket_that_fails_with_the_new_code_must_be_updated_by_the_correction(tmp_path):
376
+ """Issue #90: ticket 02 changes an interface that the locked file of merged ticket 01 uses, and its implementer
377
+ adapts that file. The review finds the change, the driver puts the file back in a commit and gates it: red. The
378
+ correction gets that gate record, and a correction that leaves the file as it is is rejected."""
379
+ leaves = writes("02", "def test_x():\n assert '02' == 'x' # stronger\n", "test: 02 stronger")
380
+ updates = writes("01", ADAPTED_01, "test: 01 adapted to 02")
381
+ updates["report"] = {**updates["report"], "locked": ["tests/test_01.py", "tests/test_02.py"]} # both attempts' files
382
+ rig = Inside(tmp_path, three(), gate={"subjects": [RESTORE]}).run(
383
+ plan(**{"02/implementer": [ADAPTS], "02/test-writer": [tw("02"), leaves, updates]}))
384
+ assert rig.code == 0, rig.ledger()
385
+ assert rig.led("Ticket 02: critical finding of kind fixture from the driver at tests/test_01.py:1")
386
+ assert not rig.calls("02", "fixer")
387
+ (restore,) = [gate["commit"] for gate in rig.gates() if gate["exit"]]
388
+ first, second = rig.calls("02", "test-writer")[1:]
389
+ assert f".agent/implement/02/gate-{restore[:7]}.log" in first["prompt"] and first["head"] == restore
390
+ assert "the gate is red on the restore commit" in second["prompt"] # the rejection of the first attempt
391
+ assert on_pr(rig, "tests/test_01.py") == ADAPTED_01 and "tests/test_01.py" in rig.state()["tickets"]["02"]["locked"]
392
+
393
+
365
394
  ACCENT = "tests/tést.py"
366
395
 
367
396
 
@@ -374,7 +403,7 @@ def accented(tmp_path, name, **steps):
374
403
  return Inside(under(tmp_path, name), three()).run(plan(**{"01/test-writer": [writer], "01/reviewer": proofs, **steps}))
375
404
 
376
405
 
377
- def test_a_locked_file_with_a_name_that_git_quotes_is_protected_at_review_and_at_the_landing(tmp_path):
406
+ def test_a_locked_file_with_a_name_that_git_quotes_is_protected_at_review_for_its_ticket_and_a_later_one(tmp_path):
378
407
  """Review round 1, I2: the quoted form of the path matched nothing, so no check saw the file."""
379
408
  own = impl("01", files={"demo/export.py": "def fn_01():\n return '01'\n", ACCENT: WEAK})
380
409
  rig = accented(tmp_path, "review", **{"01/implementer": [own], "01/fixer": [{}, {}]})
@@ -383,7 +412,7 @@ def test_a_locked_file_with_a_name_that_git_quotes_is_protected_at_review_and_at
383
412
  later = impl("02", files={"demo/export.py": "def fn_02():\n return '02'\n", ACCENT: WEAK})
384
413
  rig = accented(tmp_path, "landing", **{"02/implementer": [later]})
385
414
  assert rig.state()["tickets"]["01"]["locked"] == ["tests/test_01.py", ACCENT], rig.ledger()
386
- assert blocked(rig, "02") == f"Ticket 02: BLOCKED at the merge: locked file changed: {ACCENT}."
415
+ assert rig.code == 0 and rig.led(f"Ticket 02: critical finding of kind fixture from the driver at {ACCENT}:1")
387
416
  assert "assert 1 == 'y'" in on_pr(rig, ACCENT)
388
417
 
389
418
 
@@ -397,7 +426,7 @@ def test_four_rounds_then_blocked_with_the_escalation_at_round_3(tmp_path):
397
426
  assert rig.ledger().count(f"Ticket 01 round 3: escalated to {FABLE}.") == 1
398
427
  assert [len(rig.led("fixer ran on", entry)) for entry in (OPUS, FABLE)] == [2, 2]
399
428
  tips = [rig.sha("01", "implementer")] + [call["sha"] for call in rig.calls("01", "fixer")]
400
- assert [gate["commit"] for gate in rig.gates() if gate["branch"] == "ticket/01"] == tips
429
+ assert [gate["commit"] for gate in rig.gates() if gate["branch"] == "ticket/feat%2Fcsv/01"] == tips
401
430
  assert rig.state()["tickets"]["01"]["tip"] == tips[-1] and not rig.calls("02")
402
431
  assert rig.state()["tickets"]["03"]["phase"] == "merged"
403
432
 
@@ -504,13 +533,13 @@ def test_a_timed_out_read_only_role_is_restored_only_when_no_other_agent_is_in_t
504
533
 
505
534
  DIRTY = [({"files": {"junk.txt": "x\n", "demo/export.py": "mutated\n"}},
506
535
  "the tree is not as the review found it: demo/export.py, junk.txt"),
507
- ({"git": [["checkout", "-q", "--detach"]]}, "the slot is no longer on ticket/01 at "),
508
- ({"commit": "sneak", "files": {"demo/export.py": "x = 2\n"}}, "the slot is no longer on ticket/01 at ")]
536
+ ({"git": [["checkout", "-q", "--detach"]]}, "the slot is no longer on ticket/feat%2Fcsv/01 at "),
537
+ ({"commit": "sneak", "files": {"demo/export.py": "x = 2\n"}}, "the slot is no longer on ticket/feat%2Fcsv/01 at ")]
509
538
 
510
539
 
511
540
  def slot_state(rig):
512
541
  git = lambda *args: subprocess.run(["git", "-C", str(rig.repo), *args], capture_output=True, text=True).stdout.strip()
513
- return git("status", "--porcelain"), git("rev-parse", "ticket/01")
542
+ return git("status", "--porcelain"), git("rev-parse", "ticket/feat%2Fcsv/01")
514
543
 
515
544
 
516
545
  @pytest.mark.parametrize("step, left", DIRTY)
@@ -521,7 +550,7 @@ def test_a_reviewer_that_changes_the_slot_is_run_once_more_on_the_restored_tip(t
521
550
  (line,) = rig.led("Ticket 01: a read-only role broke its rule:")
522
551
  assert left in line and line.endswith(f"the driver restored the slot to {tip[:7]} and runs the review again.")
523
552
  first, second = rig.calls("01", "reviewer")
524
- assert (second["branch"], second["head"], second["status"]) == ("ticket/01", tip, "")
553
+ assert (second["branch"], second["head"], second["status"]) == ("ticket/feat%2Fcsv/01", tip, "")
525
554
  assert rig.tip() == tip and not (rig.repo / "junk.txt").exists()
526
555
 
527
556