prizmkit 1.1.167 → 1.1.170
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundled/VERSION.json +3 -3
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +191 -0
- package/bundled/dev-pipeline/prizmkit_runtime/runners.py +34 -2
- package/bundled/dev-pipeline/scripts/update-bug-status.py +88 -9
- package/bundled/dev-pipeline/scripts/update-feature-status.py +135 -26
- package/bundled/dev-pipeline/scripts/update-refactor-status.py +102 -4
- package/bundled/dev-pipeline/scripts/utils.py +105 -46
- package/bundled/dev-pipeline/tests/test_auto_skip.py +221 -0
- package/bundled/dev-pipeline/tests/test_python_runner_parity.py +194 -3
- package/bundled/dev-pipeline/tests/test_reset_modes.py +142 -6
- package/bundled/dev-pipeline/tests/test_runtime_commit.py +54 -0
- package/bundled/dev-pipeline/tests/test_unified_cli.py +422 -0
- package/bundled/skills/_metadata.json +1 -1
- package/bundled/skills/prizmkit-deploy/SKILL.md +21 -13
- package/bundled/skills/prizmkit-deploy/references/capability-contract.md +11 -3
- package/bundled/skills/prizmkit-deploy/references/legacy-migration.md +1 -1
- package/bundled/skills/prizmkit-deploy/references/policy-and-execution.md +12 -4
- package/bundled/skills/prizmkit-deploy/references/verification-and-recovery.md +3 -1
- package/bundled/skills/prizmkit-deploy/scripts/validate-deploy-artifact.py +372 -8
- package/package.json +1 -1
|
@@ -8,6 +8,8 @@ import sys
|
|
|
8
8
|
import time
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
|
|
11
|
+
import pytest
|
|
12
|
+
|
|
11
13
|
from update_feature_status import (
|
|
12
14
|
auto_skip_blocked_features,
|
|
13
15
|
TERMINAL_STATUSES,
|
|
@@ -1592,6 +1594,225 @@ class TestAutoSkipIntegration:
|
|
|
1592
1594
|
assert statuses["F-001"] == "pending"
|
|
1593
1595
|
|
|
1594
1596
|
|
|
1597
|
+
FAMILY_ORPHAN_CASES = (
|
|
1598
|
+
{
|
|
1599
|
+
"kind": "feature",
|
|
1600
|
+
"script": "update-feature-status.py",
|
|
1601
|
+
"list_option": "--feature-list",
|
|
1602
|
+
"id_option": "--feature-id",
|
|
1603
|
+
"collection": "features",
|
|
1604
|
+
"prefix": "F-",
|
|
1605
|
+
"blocking_status": "failed",
|
|
1606
|
+
},
|
|
1607
|
+
{
|
|
1608
|
+
"kind": "bugfix",
|
|
1609
|
+
"script": "update-bug-status.py",
|
|
1610
|
+
"list_option": "--bug-list",
|
|
1611
|
+
"id_option": "--bug-id",
|
|
1612
|
+
"collection": "bugs",
|
|
1613
|
+
"prefix": "B-",
|
|
1614
|
+
"blocking_status": "needs_info",
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
"kind": "refactor",
|
|
1618
|
+
"script": "update-refactor-status.py",
|
|
1619
|
+
"list_option": "--refactor-list",
|
|
1620
|
+
"id_option": "--refactor-id",
|
|
1621
|
+
"collection": "refactors",
|
|
1622
|
+
"prefix": "R-",
|
|
1623
|
+
"blocking_status": "skipped",
|
|
1624
|
+
},
|
|
1625
|
+
)
|
|
1626
|
+
|
|
1627
|
+
|
|
1628
|
+
def _family_item(case, number, status, dependencies=None):
|
|
1629
|
+
item_id = f"{case['prefix']}{number:03d}"
|
|
1630
|
+
item = {
|
|
1631
|
+
"id": item_id,
|
|
1632
|
+
"title": item_id,
|
|
1633
|
+
"description": "orphan convergence test",
|
|
1634
|
+
"priority": "medium",
|
|
1635
|
+
"dependencies": list(dependencies or []),
|
|
1636
|
+
"status": status,
|
|
1637
|
+
}
|
|
1638
|
+
if case["kind"] == "feature":
|
|
1639
|
+
item["acceptance_criteria"] = ["converges"]
|
|
1640
|
+
elif case["kind"] == "bugfix":
|
|
1641
|
+
item["severity"] = "high"
|
|
1642
|
+
else:
|
|
1643
|
+
item["complexity"] = "medium"
|
|
1644
|
+
return item
|
|
1645
|
+
|
|
1646
|
+
|
|
1647
|
+
def _write_family_orphan_list(tmp_path, case, items):
|
|
1648
|
+
list_path = tmp_path / f"{case['kind']}-list.json"
|
|
1649
|
+
write_json_file(str(list_path), {
|
|
1650
|
+
"project_name": "orphan convergence",
|
|
1651
|
+
case["collection"]: items,
|
|
1652
|
+
})
|
|
1653
|
+
return list_path
|
|
1654
|
+
|
|
1655
|
+
|
|
1656
|
+
def _run_family_orphan_action(
|
|
1657
|
+
case,
|
|
1658
|
+
list_path,
|
|
1659
|
+
state_dir,
|
|
1660
|
+
action,
|
|
1661
|
+
item_id=None,
|
|
1662
|
+
session_status=None,
|
|
1663
|
+
extra_args=None,
|
|
1664
|
+
):
|
|
1665
|
+
script = ROOT / "dev-pipeline" / "scripts" / case["script"]
|
|
1666
|
+
command = [
|
|
1667
|
+
"python3",
|
|
1668
|
+
str(script),
|
|
1669
|
+
case["list_option"],
|
|
1670
|
+
str(list_path),
|
|
1671
|
+
"--state-dir",
|
|
1672
|
+
str(state_dir),
|
|
1673
|
+
"--action",
|
|
1674
|
+
action,
|
|
1675
|
+
]
|
|
1676
|
+
if item_id:
|
|
1677
|
+
command.extend([case["id_option"], item_id])
|
|
1678
|
+
if session_status:
|
|
1679
|
+
command.extend(["--session-status", session_status, "--session-id", "orphan-session"])
|
|
1680
|
+
command.extend(extra_args or [])
|
|
1681
|
+
return subprocess.run(command, capture_output=True, text=True, check=True)
|
|
1682
|
+
|
|
1683
|
+
|
|
1684
|
+
def _family_statuses(case, list_path):
|
|
1685
|
+
data, error = load_json_file(str(list_path))
|
|
1686
|
+
assert error is None
|
|
1687
|
+
return {item["id"]: item["status"] for item in data[case["collection"]]}
|
|
1688
|
+
|
|
1689
|
+
|
|
1690
|
+
@pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
|
|
1691
|
+
def test_start_reconciles_rootless_auto_skipped_descendants_without_deleting_sessions(tmp_path, case):
|
|
1692
|
+
root_id = f"{case['prefix']}001"
|
|
1693
|
+
child_id = f"{case['prefix']}002"
|
|
1694
|
+
leaf_id = f"{case['prefix']}003"
|
|
1695
|
+
list_path = _write_family_orphan_list(tmp_path, case, [
|
|
1696
|
+
_family_item(case, 1, case["blocking_status"]),
|
|
1697
|
+
_family_item(case, 2, "auto_skipped", [root_id]),
|
|
1698
|
+
_family_item(case, 3, "auto_skipped", [child_id]),
|
|
1699
|
+
])
|
|
1700
|
+
state_dir = tmp_path / "state"
|
|
1701
|
+
session_marker = state_dir / child_id / "sessions" / "existing" / "session.log"
|
|
1702
|
+
session_marker.parent.mkdir(parents=True)
|
|
1703
|
+
session_marker.write_text("preserved\n", encoding="utf-8")
|
|
1704
|
+
|
|
1705
|
+
result = _run_family_orphan_action(case, list_path, state_dir, "start", root_id)
|
|
1706
|
+
|
|
1707
|
+
summary = json.loads(result.stdout)
|
|
1708
|
+
assert summary["recovered_auto_skipped"] == [child_id, leaf_id]
|
|
1709
|
+
assert _family_statuses(case, list_path) == {
|
|
1710
|
+
root_id: "in_progress",
|
|
1711
|
+
child_id: "pending",
|
|
1712
|
+
leaf_id: "pending",
|
|
1713
|
+
}
|
|
1714
|
+
assert session_marker.read_text(encoding="utf-8") == "preserved\n"
|
|
1715
|
+
|
|
1716
|
+
|
|
1717
|
+
@pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
|
|
1718
|
+
def test_start_keeps_shared_descendant_skipped_while_another_root_blocks(tmp_path, case):
|
|
1719
|
+
first_id = f"{case['prefix']}001"
|
|
1720
|
+
second_id = f"{case['prefix']}002"
|
|
1721
|
+
child_id = f"{case['prefix']}003"
|
|
1722
|
+
list_path = _write_family_orphan_list(tmp_path, case, [
|
|
1723
|
+
_family_item(case, 1, case["blocking_status"]),
|
|
1724
|
+
_family_item(case, 2, case["blocking_status"]),
|
|
1725
|
+
_family_item(case, 3, "auto_skipped", [first_id, second_id]),
|
|
1726
|
+
])
|
|
1727
|
+
|
|
1728
|
+
result = _run_family_orphan_action(case, list_path, tmp_path / "state", "start", first_id)
|
|
1729
|
+
|
|
1730
|
+
summary = json.loads(result.stdout)
|
|
1731
|
+
assert "recovered_auto_skipped" not in summary
|
|
1732
|
+
assert _family_statuses(case, list_path)[child_id] == "auto_skipped"
|
|
1733
|
+
|
|
1734
|
+
|
|
1735
|
+
@pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
|
|
1736
|
+
def test_success_without_start_reconciles_auto_skipped_descendants(tmp_path, case):
|
|
1737
|
+
root_id = f"{case['prefix']}001"
|
|
1738
|
+
child_id = f"{case['prefix']}002"
|
|
1739
|
+
list_path = _write_family_orphan_list(tmp_path, case, [
|
|
1740
|
+
_family_item(case, 1, case["blocking_status"]),
|
|
1741
|
+
_family_item(case, 2, "auto_skipped", [root_id]),
|
|
1742
|
+
])
|
|
1743
|
+
|
|
1744
|
+
result = _run_family_orphan_action(
|
|
1745
|
+
case,
|
|
1746
|
+
list_path,
|
|
1747
|
+
tmp_path / "state",
|
|
1748
|
+
"update",
|
|
1749
|
+
root_id,
|
|
1750
|
+
session_status="success",
|
|
1751
|
+
)
|
|
1752
|
+
|
|
1753
|
+
summary = json.loads(result.stdout)
|
|
1754
|
+
assert summary["recovered_auto_skipped"] == [child_id]
|
|
1755
|
+
assert _family_statuses(case, list_path) == {
|
|
1756
|
+
root_id: "completed",
|
|
1757
|
+
child_id: "pending",
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
|
|
1761
|
+
@pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
|
|
1762
|
+
def test_get_next_recovers_legacy_orphan_before_pipeline_completion(tmp_path, case):
|
|
1763
|
+
root_id = f"{case['prefix']}001"
|
|
1764
|
+
child_id = f"{case['prefix']}002"
|
|
1765
|
+
list_path = _write_family_orphan_list(tmp_path, case, [
|
|
1766
|
+
_family_item(case, 1, "completed"),
|
|
1767
|
+
_family_item(case, 2, "auto_skipped", [root_id]),
|
|
1768
|
+
])
|
|
1769
|
+
|
|
1770
|
+
result = _run_family_orphan_action(case, list_path, tmp_path / "state", "get_next")
|
|
1771
|
+
|
|
1772
|
+
payload = json.loads(result.stdout)
|
|
1773
|
+
selected_id = payload.get("feature_id") or payload.get("bug_id") or payload.get("refactor_id")
|
|
1774
|
+
assert selected_id == child_id
|
|
1775
|
+
assert child_id in result.stdout
|
|
1776
|
+
assert _family_statuses(case, list_path)[child_id] == "pending"
|
|
1777
|
+
|
|
1778
|
+
|
|
1779
|
+
@pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
|
|
1780
|
+
def test_status_labels_rootless_auto_skipped_as_orphan_without_mutation(tmp_path, case):
|
|
1781
|
+
root_id = f"{case['prefix']}001"
|
|
1782
|
+
child_id = f"{case['prefix']}002"
|
|
1783
|
+
list_path = _write_family_orphan_list(tmp_path, case, [
|
|
1784
|
+
_family_item(case, 1, "completed"),
|
|
1785
|
+
_family_item(case, 2, "auto_skipped", [root_id]),
|
|
1786
|
+
])
|
|
1787
|
+
|
|
1788
|
+
result = _run_family_orphan_action(case, list_path, tmp_path / "state", "status")
|
|
1789
|
+
|
|
1790
|
+
assert "orphaned: no blocking dependency" in result.stdout
|
|
1791
|
+
assert _family_statuses(case, list_path)[child_id] == "auto_skipped"
|
|
1792
|
+
|
|
1793
|
+
|
|
1794
|
+
def test_feature_status_filter_uses_complete_graph_for_orphan_label(tmp_path):
|
|
1795
|
+
case = FAMILY_ORPHAN_CASES[0]
|
|
1796
|
+
root_id = "F-001"
|
|
1797
|
+
child_id = "F-002"
|
|
1798
|
+
list_path = _write_family_orphan_list(tmp_path, case, [
|
|
1799
|
+
_family_item(case, 1, "completed"),
|
|
1800
|
+
_family_item(case, 2, "auto_skipped", [root_id]),
|
|
1801
|
+
])
|
|
1802
|
+
|
|
1803
|
+
result = _run_family_orphan_action(
|
|
1804
|
+
case,
|
|
1805
|
+
list_path,
|
|
1806
|
+
tmp_path / "state",
|
|
1807
|
+
"status",
|
|
1808
|
+
extra_args=["--features", child_id],
|
|
1809
|
+
)
|
|
1810
|
+
|
|
1811
|
+
assert "orphaned: no blocking dependency" in result.stdout
|
|
1812
|
+
assert root_id not in result.stdout
|
|
1813
|
+
assert child_id in result.stdout
|
|
1814
|
+
|
|
1815
|
+
|
|
1595
1816
|
def test_context_overflow_records_no_progress_fingerprint_and_stall(tmp_path):
|
|
1596
1817
|
scripts_dir = Path(__file__).resolve().parents[1] / 'scripts'
|
|
1597
1818
|
feature_list = tmp_path / 'feature-list.json'
|
|
@@ -1187,15 +1187,15 @@ def test_pipeline_aggregate_empty_authoritative_completion(monkeypatch, tmp_path
|
|
|
1187
1187
|
(
|
|
1188
1188
|
("feature", "completed", True),
|
|
1189
1189
|
("feature", "skipped", False),
|
|
1190
|
-
("feature", "auto_skipped",
|
|
1190
|
+
("feature", "auto_skipped", False),
|
|
1191
1191
|
("feature", "split", True),
|
|
1192
1192
|
("bugfix", "completed", True),
|
|
1193
1193
|
("bugfix", "skipped", False),
|
|
1194
|
-
("bugfix", "auto_skipped",
|
|
1194
|
+
("bugfix", "auto_skipped", False),
|
|
1195
1195
|
("bugfix", "split", False),
|
|
1196
1196
|
("refactor", "completed", True),
|
|
1197
1197
|
("refactor", "skipped", False),
|
|
1198
|
-
("refactor", "auto_skipped",
|
|
1198
|
+
("refactor", "auto_skipped", False),
|
|
1199
1199
|
("refactor", "split", False),
|
|
1200
1200
|
),
|
|
1201
1201
|
)
|
|
@@ -1465,6 +1465,8 @@ def _install_runner_session_fakes(monkeypatch, runners, *, statuses=("success",)
|
|
|
1465
1465
|
cleanup_calls = []
|
|
1466
1466
|
merge_calls = []
|
|
1467
1467
|
wip_calls = []
|
|
1468
|
+
restore_calls = []
|
|
1469
|
+
events = []
|
|
1468
1470
|
status_queue = list(statuses)
|
|
1469
1471
|
|
|
1470
1472
|
monkeypatch.setattr(
|
|
@@ -1501,6 +1503,7 @@ def _install_runner_session_fakes(monkeypatch, runners, *, statuses=("success",)
|
|
|
1501
1503
|
)
|
|
1502
1504
|
|
|
1503
1505
|
def fake_generate_prompt(family, invocation, **kwargs):
|
|
1506
|
+
events.append("prompt")
|
|
1504
1507
|
prompt_calls.append(kwargs)
|
|
1505
1508
|
session_paths = kwargs["session_paths"]
|
|
1506
1509
|
execution_root = kwargs.get("execution_root") or kwargs["project_root"]
|
|
@@ -1570,6 +1573,17 @@ def _install_runner_session_fakes(monkeypatch, runners, *, statuses=("success",)
|
|
|
1570
1573
|
wip_calls.append(runtime)
|
|
1571
1574
|
return SimpleNamespace(ok=True, plan=None, results=())
|
|
1572
1575
|
|
|
1576
|
+
def fake_restore_wip(project_root, **kwargs):
|
|
1577
|
+
events.append("restore")
|
|
1578
|
+
restore_calls.append((project_root, kwargs))
|
|
1579
|
+
return SimpleNamespace(
|
|
1580
|
+
ok=True,
|
|
1581
|
+
restored=False,
|
|
1582
|
+
reason="runtime_wip_not_found",
|
|
1583
|
+
wip_head="",
|
|
1584
|
+
restored_head="",
|
|
1585
|
+
)
|
|
1586
|
+
|
|
1573
1587
|
monkeypatch.setattr(runners, "generate_prompt", fake_generate_prompt)
|
|
1574
1588
|
monkeypatch.setattr(runners, "AISessionLauncher", FakeLauncher)
|
|
1575
1589
|
monkeypatch.setattr(runners, "classify_session", fake_classify)
|
|
@@ -1577,6 +1591,7 @@ def _install_runner_session_fakes(monkeypatch, runners, *, statuses=("success",)
|
|
|
1577
1591
|
monkeypatch.setattr(runners, "guarded_worktree_remove", fake_cleanup, raising=False)
|
|
1578
1592
|
monkeypatch.setattr(runners, "merge_linked_worktree", fake_merge, raising=False)
|
|
1579
1593
|
monkeypatch.setattr(runners, "worktree_save_wip", fake_save_wip, raising=False)
|
|
1594
|
+
monkeypatch.setattr(runners, "restore_runtime_wip", fake_restore_wip, raising=False)
|
|
1580
1595
|
return SimpleNamespace(
|
|
1581
1596
|
prompt_calls=prompt_calls,
|
|
1582
1597
|
launch_cwds=launch_cwds,
|
|
@@ -1585,8 +1600,184 @@ def _install_runner_session_fakes(monkeypatch, runners, *, statuses=("success",)
|
|
|
1585
1600
|
cleanup_calls=cleanup_calls,
|
|
1586
1601
|
merge_calls=merge_calls,
|
|
1587
1602
|
wip_calls=wip_calls,
|
|
1603
|
+
restore_calls=restore_calls,
|
|
1604
|
+
events=events,
|
|
1605
|
+
)
|
|
1606
|
+
|
|
1607
|
+
|
|
1608
|
+
def test_runner_does_not_restore_wip_for_first_checkout(monkeypatch, tmp_path):
|
|
1609
|
+
from prizmkit_runtime import runners
|
|
1610
|
+
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1611
|
+
|
|
1612
|
+
paths = _make_paths(tmp_path / "first-checkout-no-wip-restore")
|
|
1613
|
+
family = family_for("feature", paths)
|
|
1614
|
+
invocation = parse_invocation(family, "run", ())
|
|
1615
|
+
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1616
|
+
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1617
|
+
monkeypatch.setattr(
|
|
1618
|
+
runners,
|
|
1619
|
+
"run_git_plan",
|
|
1620
|
+
lambda *args, **kwargs: SimpleNamespace(ok=True, reason="", results=()),
|
|
1588
1621
|
)
|
|
1589
1622
|
|
|
1623
|
+
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1624
|
+
|
|
1625
|
+
assert status == "completed"
|
|
1626
|
+
assert observed.restore_calls == []
|
|
1627
|
+
assert observed.events == ["prompt"]
|
|
1628
|
+
|
|
1629
|
+
|
|
1630
|
+
def test_runner_restores_wip_before_prompt_for_reused_branch_checkout(monkeypatch, tmp_path):
|
|
1631
|
+
from prizmkit_runtime import runners
|
|
1632
|
+
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1633
|
+
from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
|
|
1634
|
+
|
|
1635
|
+
paths = _make_paths(tmp_path / "reused-branch-wip-restore")
|
|
1636
|
+
family = family_for("feature", paths)
|
|
1637
|
+
branch = "dev/feature/F-001-preserved"
|
|
1638
|
+
persist_task_checkout(
|
|
1639
|
+
family.state_dir,
|
|
1640
|
+
TaskCheckout.active(family.task_type, "F-001", branch, "main"),
|
|
1641
|
+
)
|
|
1642
|
+
invocation = parse_invocation(family, "run", ())
|
|
1643
|
+
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1644
|
+
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1645
|
+
monkeypatch.setattr(
|
|
1646
|
+
runners,
|
|
1647
|
+
"run_git_plan",
|
|
1648
|
+
lambda *args, **kwargs: SimpleNamespace(ok=True, reason="", results=()),
|
|
1649
|
+
)
|
|
1650
|
+
|
|
1651
|
+
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1652
|
+
|
|
1653
|
+
assert status == "completed"
|
|
1654
|
+
assert observed.events == ["restore", "prompt"]
|
|
1655
|
+
assert observed.restore_calls == [
|
|
1656
|
+
(
|
|
1657
|
+
paths.project_root,
|
|
1658
|
+
{
|
|
1659
|
+
"family_kind": "feature",
|
|
1660
|
+
"item_id": "F-001",
|
|
1661
|
+
"working_branch": branch,
|
|
1662
|
+
},
|
|
1663
|
+
)
|
|
1664
|
+
]
|
|
1665
|
+
|
|
1666
|
+
|
|
1667
|
+
def test_runner_restores_wip_before_prompt_for_reused_worktree_checkout(monkeypatch, tmp_path):
|
|
1668
|
+
from prizmkit_runtime import runners
|
|
1669
|
+
from prizmkit_runtime.gitops import (
|
|
1670
|
+
BranchContext,
|
|
1671
|
+
WorktreePolicy,
|
|
1672
|
+
worktree_runtime_context,
|
|
1673
|
+
)
|
|
1674
|
+
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1675
|
+
from prizmkit_runtime.task_checkout import (
|
|
1676
|
+
CHECKOUT_MODE_WORKTREE,
|
|
1677
|
+
TaskCheckout,
|
|
1678
|
+
persist_task_checkout,
|
|
1679
|
+
)
|
|
1680
|
+
|
|
1681
|
+
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
1682
|
+
paths = _make_paths(tmp_path / "reused-worktree-wip-restore")
|
|
1683
|
+
family = family_for("feature", paths)
|
|
1684
|
+
branch = "dev/feature/F-001-preserved"
|
|
1685
|
+
expected_runtime = worktree_runtime_context(
|
|
1686
|
+
BranchContext("main", branch, paths.project_root),
|
|
1687
|
+
WorktreePolicy(
|
|
1688
|
+
use_worktree=True,
|
|
1689
|
+
cleanup_on_success=True,
|
|
1690
|
+
preserve_on_failure=True,
|
|
1691
|
+
worktree_root=paths.state_dir / "worktrees",
|
|
1692
|
+
),
|
|
1693
|
+
)
|
|
1694
|
+
worktree_path = expected_runtime.worktree_path
|
|
1695
|
+
persist_task_checkout(
|
|
1696
|
+
family.state_dir,
|
|
1697
|
+
TaskCheckout.active(
|
|
1698
|
+
family.task_type,
|
|
1699
|
+
"F-001",
|
|
1700
|
+
branch,
|
|
1701
|
+
"main",
|
|
1702
|
+
checkout_mode=CHECKOUT_MODE_WORKTREE,
|
|
1703
|
+
worktree_path=str(worktree_path),
|
|
1704
|
+
),
|
|
1705
|
+
)
|
|
1706
|
+
invocation = parse_invocation(family, "run", ())
|
|
1707
|
+
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1708
|
+
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1709
|
+
|
|
1710
|
+
def fake_setup(runtime):
|
|
1711
|
+
runtime.worktree_path.mkdir(parents=True, exist_ok=True)
|
|
1712
|
+
return SimpleNamespace(ok=True, runtime=runtime, reason="")
|
|
1713
|
+
|
|
1714
|
+
monkeypatch.setattr(runners, "ensure_linked_worktree", fake_setup)
|
|
1715
|
+
monkeypatch.setattr(
|
|
1716
|
+
runners,
|
|
1717
|
+
"materialize_worktree_support_assets",
|
|
1718
|
+
lambda *args, **kwargs: SimpleNamespace(ok=True, reason=""),
|
|
1719
|
+
)
|
|
1720
|
+
|
|
1721
|
+
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1722
|
+
|
|
1723
|
+
assert status == "completed"
|
|
1724
|
+
assert observed.events == ["restore", "prompt"]
|
|
1725
|
+
assert observed.restore_calls[0][0] == worktree_path.resolve()
|
|
1726
|
+
assert observed.restore_calls[0][1] == {
|
|
1727
|
+
"family_kind": "feature",
|
|
1728
|
+
"item_id": "F-001",
|
|
1729
|
+
"working_branch": branch,
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
|
|
1733
|
+
def test_runner_blocks_ai_launch_when_reused_wip_restore_fails(monkeypatch, tmp_path):
|
|
1734
|
+
from prizmkit_runtime import runners
|
|
1735
|
+
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1736
|
+
from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
|
|
1737
|
+
|
|
1738
|
+
paths = _make_paths(tmp_path / "failed-branch-wip-restore")
|
|
1739
|
+
family = family_for("feature", paths)
|
|
1740
|
+
branch = "dev/feature/F-001-preserved"
|
|
1741
|
+
persist_task_checkout(
|
|
1742
|
+
family.state_dir,
|
|
1743
|
+
TaskCheckout.active(family.task_type, "F-001", branch, "main"),
|
|
1744
|
+
)
|
|
1745
|
+
invocation = parse_invocation(family, "run", ())
|
|
1746
|
+
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1747
|
+
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1748
|
+
monkeypatch.setattr(
|
|
1749
|
+
runners,
|
|
1750
|
+
"run_git_plan",
|
|
1751
|
+
lambda *args, **kwargs: SimpleNamespace(ok=True, reason="", results=()),
|
|
1752
|
+
)
|
|
1753
|
+
monkeypatch.setattr(
|
|
1754
|
+
runners,
|
|
1755
|
+
"restore_runtime_wip",
|
|
1756
|
+
lambda *args, **kwargs: SimpleNamespace(
|
|
1757
|
+
ok=False,
|
|
1758
|
+
restored=False,
|
|
1759
|
+
reason="runtime_wip_unresolved_merge",
|
|
1760
|
+
wip_head="preserved-head",
|
|
1761
|
+
restored_head="preserved-head",
|
|
1762
|
+
),
|
|
1763
|
+
raising=False,
|
|
1764
|
+
)
|
|
1765
|
+
monkeypatch.setattr(
|
|
1766
|
+
runners,
|
|
1767
|
+
"commit_wip_changes",
|
|
1768
|
+
lambda *args, **kwargs: SimpleNamespace(ok=True),
|
|
1769
|
+
)
|
|
1770
|
+
monkeypatch.setattr(
|
|
1771
|
+
runners,
|
|
1772
|
+
"branch_ensure_return",
|
|
1773
|
+
lambda *args, **kwargs: SimpleNamespace(ok=True),
|
|
1774
|
+
)
|
|
1775
|
+
|
|
1776
|
+
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1777
|
+
|
|
1778
|
+
assert status == "infra_error"
|
|
1779
|
+
assert observed.prompt_calls == []
|
|
1780
|
+
assert observed.launch_cwds == []
|
|
1590
1781
|
|
|
1591
1782
|
|
|
1592
1783
|
def test_outer_runner_routes_cursor_through_native_preflight_and_session_config(monkeypatch, tmp_path):
|
|
@@ -9,7 +9,7 @@ from pathlib import Path
|
|
|
9
9
|
|
|
10
10
|
import pytest
|
|
11
11
|
|
|
12
|
-
from utils import causal_reset_selection
|
|
12
|
+
from utils import causal_reset_selection, orphaned_auto_skipped_ids
|
|
13
13
|
|
|
14
14
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
15
15
|
PIPELINE_ROOT = REPO_ROOT / "dev-pipeline"
|
|
@@ -145,7 +145,7 @@ def test_causal_selection_all_recovers_every_supported_chain(prefix, root_status
|
|
|
145
145
|
assert selected == (f"{prefix}001", f"{prefix}002", f"{prefix}003")
|
|
146
146
|
|
|
147
147
|
|
|
148
|
-
def
|
|
148
|
+
def test_causal_selection_rejects_missing_and_invalid_targets():
|
|
149
149
|
items = [
|
|
150
150
|
_item("F-001", "failed"),
|
|
151
151
|
_item("F-002", "pending"),
|
|
@@ -156,8 +156,66 @@ def test_causal_selection_rejects_missing_invalid_and_orphan_targets():
|
|
|
156
156
|
causal_reset_selection(items, selected_id="F-999", blocking_root_statuses={"failed", "skipped"})
|
|
157
157
|
with pytest.raises(ValueError, match="not recoverable"):
|
|
158
158
|
causal_reset_selection(items, selected_id="F-002", blocking_root_statuses={"failed", "skipped"})
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@pytest.mark.parametrize("prefix", ("F-", "B-", "R-"))
|
|
162
|
+
def test_causal_selection_recovers_selected_orphan_and_eligible_descendants(prefix):
|
|
163
|
+
root_statuses = {"failed", "skipped", "needs_info"} if prefix == "B-" else {"failed", "skipped"}
|
|
164
|
+
items = [
|
|
165
|
+
_item(f"{prefix}001", "completed"),
|
|
166
|
+
_item(f"{prefix}002", "auto_skipped", [f"{prefix}001"]),
|
|
167
|
+
_item(f"{prefix}003", "auto_skipped", [f"{prefix}002"]),
|
|
168
|
+
_item(f"{prefix}004", "auto_skipped", [f"{prefix}001"]),
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
selected = causal_reset_selection(
|
|
172
|
+
items,
|
|
173
|
+
selected_id=f"{prefix}002",
|
|
174
|
+
blocking_root_statuses=root_statuses,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
assert selected == (f"{prefix}002", f"{prefix}003")
|
|
178
|
+
assert orphaned_auto_skipped_ids(
|
|
179
|
+
items,
|
|
180
|
+
blocking_root_statuses=root_statuses,
|
|
181
|
+
) == (f"{prefix}002", f"{prefix}003", f"{prefix}004")
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@pytest.mark.parametrize("prefix", ("F-", "B-", "R-"))
|
|
185
|
+
def test_causal_selection_all_recovers_orphans_when_no_blocking_root_remains(prefix):
|
|
186
|
+
root_statuses = {"failed", "skipped", "needs_info"} if prefix == "B-" else {"failed", "skipped"}
|
|
187
|
+
items = [
|
|
188
|
+
_item(f"{prefix}001", "completed"),
|
|
189
|
+
_item(f"{prefix}002", "auto_skipped", [f"{prefix}001"]),
|
|
190
|
+
_item(f"{prefix}003", "auto_skipped", [f"{prefix}002"]),
|
|
191
|
+
]
|
|
192
|
+
|
|
193
|
+
selected = causal_reset_selection(
|
|
194
|
+
items,
|
|
195
|
+
selected_id=None,
|
|
196
|
+
blocking_root_statuses=root_statuses,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
assert selected == (f"{prefix}002", f"{prefix}003")
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def test_orphan_analysis_keeps_multi_root_item_blocked_until_every_root_resolves():
|
|
203
|
+
items = [
|
|
204
|
+
_item("F-001", "completed"),
|
|
205
|
+
_item("F-002", "failed"),
|
|
206
|
+
_item("F-003", "auto_skipped", ["F-001", "F-002"]),
|
|
207
|
+
]
|
|
208
|
+
|
|
209
|
+
assert orphaned_auto_skipped_ids(
|
|
210
|
+
items,
|
|
211
|
+
blocking_root_statuses={"failed", "skipped"},
|
|
212
|
+
) == ()
|
|
213
|
+
|
|
214
|
+
items[1]["status"] = "in_progress"
|
|
215
|
+
assert orphaned_auto_skipped_ids(
|
|
216
|
+
items,
|
|
217
|
+
blocking_root_statuses={"failed", "skipped"},
|
|
218
|
+
) == ("F-003",)
|
|
161
219
|
|
|
162
220
|
|
|
163
221
|
def test_causal_selection_rejects_invalid_dependency_graph_before_selection():
|
|
@@ -484,6 +542,85 @@ def test_state_only_all_recovers_all_supported_chains_without_pipeline_state(tmp
|
|
|
484
542
|
assert not (family.state_dir / "pipeline.json").exists()
|
|
485
543
|
|
|
486
544
|
|
|
545
|
+
@pytest.mark.parametrize("kind", ("feature", "bugfix", "refactor"))
|
|
546
|
+
def test_state_only_all_recovers_rootless_auto_skipped_chain(tmp_path, kind):
|
|
547
|
+
from prizmkit_runtime.reset import run_reset_command
|
|
548
|
+
|
|
549
|
+
paths = _make_paths(tmp_path / kind)
|
|
550
|
+
contract = FAMILY_CONTRACTS[kind]
|
|
551
|
+
prefix = contract["prefix"]
|
|
552
|
+
root_id = f"{prefix}001"
|
|
553
|
+
child_id = f"{prefix}002"
|
|
554
|
+
leaf_id = f"{prefix}003"
|
|
555
|
+
family, plan_path = _family_and_plan(
|
|
556
|
+
paths,
|
|
557
|
+
kind,
|
|
558
|
+
[
|
|
559
|
+
_item(root_id, "completed"),
|
|
560
|
+
_item(child_id, "auto_skipped", [root_id]),
|
|
561
|
+
_item(leaf_id, "auto_skipped", [child_id]),
|
|
562
|
+
],
|
|
563
|
+
)
|
|
564
|
+
child_status_path, _ = _write_runtime_status(family, child_id)
|
|
565
|
+
session_marker = family.state_dir / child_id / "sessions" / "old-session" / "session.log"
|
|
566
|
+
session_marker.parent.mkdir(parents=True)
|
|
567
|
+
session_marker.write_text("preserve session artifact\n", encoding="utf-8")
|
|
568
|
+
|
|
569
|
+
result = run_reset_command(
|
|
570
|
+
kind,
|
|
571
|
+
("--state-only", "--all", str(plan_path)),
|
|
572
|
+
paths,
|
|
573
|
+
)
|
|
574
|
+
|
|
575
|
+
assert result.exit_code == 0, result.render()
|
|
576
|
+
payload = json.loads(result.render())
|
|
577
|
+
assert payload["reset_count"] == 2
|
|
578
|
+
updated = json.loads(plan_path.read_text(encoding="utf-8"))[contract["list_key"]]
|
|
579
|
+
assert [item["status"] for item in updated] == ["completed", "pending", "pending"]
|
|
580
|
+
assert session_marker.read_text(encoding="utf-8") == "preserve session artifact\n"
|
|
581
|
+
assert json.loads(child_status_path.read_text(encoding="utf-8"))["custom_diagnostic"] == {"keep": True}
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
@pytest.mark.parametrize("kind", ("feature", "bugfix", "refactor"))
|
|
585
|
+
def test_state_only_selected_orphan_recovers_only_its_causal_descendants(tmp_path, kind):
|
|
586
|
+
from prizmkit_runtime.reset import run_reset_command
|
|
587
|
+
|
|
588
|
+
paths = _make_paths(tmp_path / kind)
|
|
589
|
+
contract = FAMILY_CONTRACTS[kind]
|
|
590
|
+
prefix = contract["prefix"]
|
|
591
|
+
root_id = f"{prefix}001"
|
|
592
|
+
selected_id = f"{prefix}002"
|
|
593
|
+
leaf_id = f"{prefix}003"
|
|
594
|
+
sibling_id = f"{prefix}004"
|
|
595
|
+
family, plan_path = _family_and_plan(
|
|
596
|
+
paths,
|
|
597
|
+
kind,
|
|
598
|
+
[
|
|
599
|
+
_item(root_id, "completed"),
|
|
600
|
+
_item(selected_id, "auto_skipped", [root_id]),
|
|
601
|
+
_item(leaf_id, "auto_skipped", [selected_id]),
|
|
602
|
+
_item(sibling_id, "auto_skipped", [root_id]),
|
|
603
|
+
],
|
|
604
|
+
)
|
|
605
|
+
|
|
606
|
+
result = run_reset_command(
|
|
607
|
+
kind,
|
|
608
|
+
(selected_id, "--state-only", str(plan_path)),
|
|
609
|
+
paths,
|
|
610
|
+
)
|
|
611
|
+
|
|
612
|
+
assert result.exit_code == 0, result.render()
|
|
613
|
+
payload = json.loads(result.render())
|
|
614
|
+
assert payload["reset_count"] == 2
|
|
615
|
+
updated = json.loads(plan_path.read_text(encoding="utf-8"))[contract["list_key"]]
|
|
616
|
+
assert {item["id"]: item["status"] for item in updated} == {
|
|
617
|
+
root_id: "completed",
|
|
618
|
+
selected_id: "pending",
|
|
619
|
+
leaf_id: "pending",
|
|
620
|
+
sibling_id: "auto_skipped",
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
|
|
487
624
|
@pytest.mark.parametrize("kind", ("feature", "bugfix", "refactor"))
|
|
488
625
|
def test_reset_without_mode_fails_before_any_mutation(tmp_path, kind):
|
|
489
626
|
from prizmkit_runtime.reset import run_reset_command
|
|
@@ -585,7 +722,6 @@ def test_reset_selector_matrix_rejects_unsupported_forms_before_mutation(tmp_pat
|
|
|
585
722
|
(
|
|
586
723
|
([_item("F-001", "failed")], ("F-999", "--state-only"), "not found"),
|
|
587
724
|
([_item("F-001", "pending")], ("F-001", "--state-only"), "not recoverable"),
|
|
588
|
-
([_item("F-001", "auto_skipped")], ("F-001", "--state-only"), "unresolved auto_skipped blocker"),
|
|
589
725
|
([_item("F-001", "completed")], ("--state-only", "--all"), "No recoverable blocking roots"),
|
|
590
726
|
(
|
|
591
727
|
[_item("F-001", "failed", ["F-002"]), _item("F-002", "auto_skipped", ["F-001"])],
|
|
@@ -1028,7 +1164,7 @@ def test_bugfix_auto_skipped_schema_validators_and_aggregation_are_consistent():
|
|
|
1028
1164
|
assert "auto_skipped" in PROGRESS_COUNTS_BY_KIND["bugfix"]
|
|
1029
1165
|
paths = resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=REPO_ROOT)
|
|
1030
1166
|
bug_family = family_for("bugfix", paths)
|
|
1031
|
-
assert "auto_skipped" in _completion_compatible_statuses(bug_family)
|
|
1167
|
+
assert "auto_skipped" not in _completion_compatible_statuses(bug_family)
|
|
1032
1168
|
|
|
1033
1169
|
|
|
1034
1170
|
def test_all_updaters_expose_only_reset_state_internal_recovery_action():
|