prizmkit 1.1.169 → 1.1.171
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 +33 -1
- package/bundled/dev-pipeline/tests/test_python_runner_parity.py +191 -0
- 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/app-planner/references/infrastructure-convention-discovery.md +3 -1
- package/bundled/skills/prizmkit-deploy/SKILL.md +29 -15
- package/bundled/skills/prizmkit-deploy/references/capability-contract.md +11 -3
- package/bundled/skills/prizmkit-deploy/references/deploy-record-schema.json +21 -1
- package/bundled/skills/prizmkit-deploy/references/policy-and-execution.md +28 -10
- package/bundled/skills/prizmkit-deploy/references/verification-and-recovery.md +7 -3
- package/bundled/skills/prizmkit-deploy/scripts/validate-deploy-artifact.py +27 -1
- package/package.json +1 -1
package/bundled/VERSION.json
CHANGED
|
@@ -561,6 +561,25 @@ class GitPlanResult:
|
|
|
561
561
|
return True
|
|
562
562
|
|
|
563
563
|
|
|
564
|
+
@dataclass(frozen=True)
|
|
565
|
+
class WipRestoreResult:
|
|
566
|
+
"""Observable result of restoring one exact Runtime-owned WIP tip."""
|
|
567
|
+
|
|
568
|
+
status: str
|
|
569
|
+
reason: str
|
|
570
|
+
wip_head: str = ""
|
|
571
|
+
restored_head: str = ""
|
|
572
|
+
results: tuple[GitCommandResult, ...] = ()
|
|
573
|
+
|
|
574
|
+
@property
|
|
575
|
+
def ok(self) -> bool:
|
|
576
|
+
return self.status in {"restored", "not_needed"}
|
|
577
|
+
|
|
578
|
+
@property
|
|
579
|
+
def restored(self) -> bool:
|
|
580
|
+
return self.status == "restored"
|
|
581
|
+
|
|
582
|
+
|
|
564
583
|
def _git(*args: str, allow_failure: bool = False, description: str = "") -> GitCommand:
|
|
565
584
|
return GitCommand(args=args, allow_failure=allow_failure, description=description)
|
|
566
585
|
|
|
@@ -888,6 +907,178 @@ def worktree_save_wip(runtime: WorktreeRuntimeContext) -> GitPlanResult:
|
|
|
888
907
|
return branch_save_wip(runtime.worktree_path, runtime.context.working_branch)
|
|
889
908
|
|
|
890
909
|
|
|
910
|
+
def _matches_runtime_wip_identity(
|
|
911
|
+
subject: str,
|
|
912
|
+
body: str,
|
|
913
|
+
*,
|
|
914
|
+
family_kind: str,
|
|
915
|
+
item_id: str,
|
|
916
|
+
working_branch: str,
|
|
917
|
+
) -> bool:
|
|
918
|
+
failure_subject = re.fullmatch(
|
|
919
|
+
rf"wip\({re.escape(item_id)}\): preserve {re.escape(family_kind)} [a-z][a-z0-9_]* state",
|
|
920
|
+
subject,
|
|
921
|
+
)
|
|
922
|
+
failure_body = "Pipeline preserved task branch work without merging it to the base branch."
|
|
923
|
+
if failure_subject is not None and body == failure_body:
|
|
924
|
+
return True
|
|
925
|
+
|
|
926
|
+
interruption_subject = f"wip({working_branch}): interrupted — uncommitted work saved"
|
|
927
|
+
interruption_body = (
|
|
928
|
+
"Pipeline was interrupted by signal. This commit preserves work-in-progress.\n\n"
|
|
929
|
+
f"To resume: git checkout {working_branch}"
|
|
930
|
+
)
|
|
931
|
+
return subject == interruption_subject and body == interruption_body
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
def restore_runtime_wip(
|
|
935
|
+
project_root: Path,
|
|
936
|
+
*,
|
|
937
|
+
family_kind: str,
|
|
938
|
+
item_id: str,
|
|
939
|
+
working_branch: str,
|
|
940
|
+
) -> WipRestoreResult:
|
|
941
|
+
"""Rehydrate one exact Runtime-owned WIP tip into the reused task workspace."""
|
|
942
|
+
results: list[GitCommandResult] = []
|
|
943
|
+
active = run_git_command(project_root, ("rev-parse", "--abbrev-ref", "HEAD"))
|
|
944
|
+
results.append(active)
|
|
945
|
+
if active.return_code != 0:
|
|
946
|
+
return WipRestoreResult("failed", "runtime_wip_branch_unavailable", results=tuple(results))
|
|
947
|
+
if active.stdout.strip() != working_branch:
|
|
948
|
+
return WipRestoreResult("failed", "runtime_wip_branch_mismatch", results=tuple(results))
|
|
949
|
+
|
|
950
|
+
unmerged = run_git_command(project_root, ("ls-files", "-u"))
|
|
951
|
+
results.append(unmerged)
|
|
952
|
+
if unmerged.return_code != 0:
|
|
953
|
+
return WipRestoreResult("failed", "runtime_wip_merge_state_unavailable", results=tuple(results))
|
|
954
|
+
if unmerged.stdout.strip():
|
|
955
|
+
return WipRestoreResult("failed", "runtime_wip_unresolved_merge", results=tuple(results))
|
|
956
|
+
|
|
957
|
+
identity = run_git_command(project_root, ("show", "-s", "--format=%H%x00%P%x00%s%x00%b", "HEAD"))
|
|
958
|
+
results.append(identity)
|
|
959
|
+
if identity.return_code != 0:
|
|
960
|
+
return WipRestoreResult("failed", "runtime_wip_identity_unavailable", results=tuple(results))
|
|
961
|
+
parts = identity.stdout.rstrip("\n").split("\0", 3)
|
|
962
|
+
if len(parts) != 4:
|
|
963
|
+
return WipRestoreResult("failed", "runtime_wip_identity_invalid", results=tuple(results))
|
|
964
|
+
head, parents_text, subject, body = parts
|
|
965
|
+
body = body.rstrip("\n")
|
|
966
|
+
if not _matches_runtime_wip_identity(
|
|
967
|
+
subject,
|
|
968
|
+
body,
|
|
969
|
+
family_kind=family_kind,
|
|
970
|
+
item_id=item_id,
|
|
971
|
+
working_branch=working_branch,
|
|
972
|
+
):
|
|
973
|
+
return WipRestoreResult(
|
|
974
|
+
"not_needed",
|
|
975
|
+
"runtime_wip_not_found",
|
|
976
|
+
wip_head=head,
|
|
977
|
+
restored_head=head,
|
|
978
|
+
results=tuple(results),
|
|
979
|
+
)
|
|
980
|
+
|
|
981
|
+
staged = run_git_command(project_root, ("diff", "--cached", "--name-only", "-z"))
|
|
982
|
+
results.append(staged)
|
|
983
|
+
if staged.return_code != 0:
|
|
984
|
+
return WipRestoreResult(
|
|
985
|
+
"failed",
|
|
986
|
+
"runtime_wip_staged_state_unavailable",
|
|
987
|
+
wip_head=head,
|
|
988
|
+
restored_head=head,
|
|
989
|
+
results=tuple(results),
|
|
990
|
+
)
|
|
991
|
+
if staged.stdout.strip("\0"):
|
|
992
|
+
return WipRestoreResult(
|
|
993
|
+
"failed",
|
|
994
|
+
"runtime_wip_staged_changes",
|
|
995
|
+
wip_head=head,
|
|
996
|
+
restored_head=head,
|
|
997
|
+
results=tuple(results),
|
|
998
|
+
)
|
|
999
|
+
|
|
1000
|
+
parents = parents_text.split()
|
|
1001
|
+
if len(parents) != 1:
|
|
1002
|
+
return WipRestoreResult(
|
|
1003
|
+
"failed",
|
|
1004
|
+
"runtime_wip_parent_invalid",
|
|
1005
|
+
wip_head=head,
|
|
1006
|
+
restored_head=head,
|
|
1007
|
+
results=tuple(results),
|
|
1008
|
+
)
|
|
1009
|
+
parent = parents[0]
|
|
1010
|
+
changed = run_git_command(
|
|
1011
|
+
project_root,
|
|
1012
|
+
("diff-tree", "--no-commit-id", "--name-only", "--no-renames", "-r", "-z", head),
|
|
1013
|
+
)
|
|
1014
|
+
results.append(changed)
|
|
1015
|
+
if changed.return_code != 0:
|
|
1016
|
+
return WipRestoreResult(
|
|
1017
|
+
"failed",
|
|
1018
|
+
"runtime_wip_paths_unavailable",
|
|
1019
|
+
wip_head=head,
|
|
1020
|
+
restored_head=head,
|
|
1021
|
+
results=tuple(results),
|
|
1022
|
+
)
|
|
1023
|
+
wip_paths = {path for path in changed.stdout.split("\0") if path}
|
|
1024
|
+
if not wip_paths:
|
|
1025
|
+
return WipRestoreResult(
|
|
1026
|
+
"failed",
|
|
1027
|
+
"runtime_wip_empty_commit",
|
|
1028
|
+
wip_head=head,
|
|
1029
|
+
restored_head=head,
|
|
1030
|
+
results=tuple(results),
|
|
1031
|
+
)
|
|
1032
|
+
|
|
1033
|
+
reset = run_git_command(project_root, ("reset", "--mixed", parent))
|
|
1034
|
+
results.append(reset)
|
|
1035
|
+
if reset.return_code != 0:
|
|
1036
|
+
return WipRestoreResult(
|
|
1037
|
+
"failed",
|
|
1038
|
+
"runtime_wip_restore_failed",
|
|
1039
|
+
wip_head=head,
|
|
1040
|
+
restored_head=head,
|
|
1041
|
+
results=tuple(results),
|
|
1042
|
+
)
|
|
1043
|
+
|
|
1044
|
+
restored_head_result = run_git_command(project_root, ("rev-parse", "HEAD"))
|
|
1045
|
+
results.append(restored_head_result)
|
|
1046
|
+
visible_paths, visible_result = visible_task_paths(project_root)
|
|
1047
|
+
results.append(visible_result)
|
|
1048
|
+
visible_set = set(visible_paths)
|
|
1049
|
+
verified = (
|
|
1050
|
+
restored_head_result.return_code == 0
|
|
1051
|
+
and restored_head_result.stdout.strip() == parent
|
|
1052
|
+
and visible_result.return_code == 0
|
|
1053
|
+
and wip_paths.issubset(visible_set)
|
|
1054
|
+
)
|
|
1055
|
+
if not verified:
|
|
1056
|
+
rollback = run_git_command(project_root, ("reset", "--mixed", head))
|
|
1057
|
+
results.append(rollback)
|
|
1058
|
+
reason = (
|
|
1059
|
+
"runtime_wip_restore_rollback_failed"
|
|
1060
|
+
if rollback.return_code != 0
|
|
1061
|
+
else "runtime_wip_restore_verification_failed"
|
|
1062
|
+
)
|
|
1063
|
+
current = run_git_command(project_root, ("rev-parse", "HEAD"))
|
|
1064
|
+
results.append(current)
|
|
1065
|
+
return WipRestoreResult(
|
|
1066
|
+
"failed",
|
|
1067
|
+
reason,
|
|
1068
|
+
wip_head=head,
|
|
1069
|
+
restored_head=current.stdout.strip() if current.return_code == 0 else "",
|
|
1070
|
+
results=tuple(results),
|
|
1071
|
+
)
|
|
1072
|
+
|
|
1073
|
+
return WipRestoreResult(
|
|
1074
|
+
"restored",
|
|
1075
|
+
"runtime_wip_restored",
|
|
1076
|
+
wip_head=head,
|
|
1077
|
+
restored_head=parent,
|
|
1078
|
+
results=tuple(results),
|
|
1079
|
+
)
|
|
1080
|
+
|
|
1081
|
+
|
|
891
1082
|
def branch_ensure_return(project_root: Path, base_branch: str, working_branch: str = "") -> GitPlanResult:
|
|
892
1083
|
"""Commit Git-visible task WIP when needed, then return the caller checkout to base."""
|
|
893
1084
|
active = current_branch(project_root)
|
|
@@ -29,6 +29,7 @@ from .gitops import (
|
|
|
29
29
|
guarded_worktree_remove,
|
|
30
30
|
materialize_worktree_support_assets,
|
|
31
31
|
merge_linked_worktree,
|
|
32
|
+
restore_runtime_wip,
|
|
32
33
|
run_git_command,
|
|
33
34
|
run_git_plan,
|
|
34
35
|
worktree_runtime_context,
|
|
@@ -565,7 +566,8 @@ def _process_item_locked(
|
|
|
565
566
|
branch_name = _resolve_working_branch(family, item_id, metadata, env, active_branch)
|
|
566
567
|
branch_context = BranchContext(base_branch, branch_name, paths.project_root)
|
|
567
568
|
worktree_runtime = None
|
|
568
|
-
|
|
569
|
+
reusing_checkout = checkout is not None and checkout.is_active
|
|
570
|
+
if reusing_checkout:
|
|
569
571
|
use_worktree = checkout.uses_worktree
|
|
570
572
|
worktree_path = Path(checkout.worktree_path) if checkout.worktree_path else None
|
|
571
573
|
else:
|
|
@@ -641,6 +643,36 @@ def _process_item_locked(
|
|
|
641
643
|
if not branch_result.ok:
|
|
642
644
|
return "infra_error"
|
|
643
645
|
|
|
646
|
+
if reusing_checkout:
|
|
647
|
+
restored_wip = restore_runtime_wip(
|
|
648
|
+
execution_root,
|
|
649
|
+
family_kind=family.kind,
|
|
650
|
+
item_id=item_id,
|
|
651
|
+
working_branch=branch_name,
|
|
652
|
+
)
|
|
653
|
+
if not restored_wip.ok:
|
|
654
|
+
_emit_warning(
|
|
655
|
+
f"Runtime WIP recovery failed for {item_id}: {restored_wip.reason}; "
|
|
656
|
+
"AI launch was blocked and the preserved checkout remains active"
|
|
657
|
+
)
|
|
658
|
+
return _record_setup_failure(
|
|
659
|
+
family,
|
|
660
|
+
invocation,
|
|
661
|
+
item_id,
|
|
662
|
+
paths.project_root,
|
|
663
|
+
execution_root,
|
|
664
|
+
base_branch,
|
|
665
|
+
branch_name,
|
|
666
|
+
worktree_runtime=worktree_runtime,
|
|
667
|
+
)
|
|
668
|
+
if restored_wip.restored:
|
|
669
|
+
_emit_info(
|
|
670
|
+
f"Recovery: restored Runtime-owned WIP {restored_wip.wip_head[:12]} "
|
|
671
|
+
f"into the workspace for {item_id}"
|
|
672
|
+
)
|
|
673
|
+
else:
|
|
674
|
+
_emit_info(f"Recovery: no Runtime-owned WIP tip to restore for {item_id}")
|
|
675
|
+
|
|
644
676
|
_emit_item_header(family, invocation, item_id, metadata)
|
|
645
677
|
status_root = execution_root if use_worktree else paths.project_root
|
|
646
678
|
status_family = _family_for_execution_root(family, paths.project_root, status_root)
|
|
@@ -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):
|
|
@@ -224,6 +224,60 @@ def test_runtime_commit_executes_complete_workspace_and_finalizes_only_checkpoin
|
|
|
224
224
|
).semantic_complete is True
|
|
225
225
|
|
|
226
226
|
|
|
227
|
+
def test_runtime_commit_finalizes_rehydrated_failure_wip(tmp_path):
|
|
228
|
+
from types import SimpleNamespace
|
|
229
|
+
|
|
230
|
+
from prizmkit_runtime.gitops import restore_runtime_wip
|
|
231
|
+
from prizmkit_runtime.runner_bookkeeping import commit_wip_changes
|
|
232
|
+
|
|
233
|
+
base_head = _init_repo(tmp_path)
|
|
234
|
+
branch = "dev/F-005-runtime-wip"
|
|
235
|
+
_git(tmp_path, "checkout", "-b", branch)
|
|
236
|
+
(tmp_path / "tracked.txt").write_text("preserved feature change\n", encoding="utf-8")
|
|
237
|
+
preserved = commit_wip_changes(
|
|
238
|
+
tmp_path,
|
|
239
|
+
SimpleNamespace(kind="feature"),
|
|
240
|
+
"F-005",
|
|
241
|
+
"failed",
|
|
242
|
+
)
|
|
243
|
+
assert preserved.committed is True
|
|
244
|
+
wip_head = _git(tmp_path, "rev-parse", "HEAD")
|
|
245
|
+
assert wip_head != base_head
|
|
246
|
+
assert _git(tmp_path, "status", "--porcelain", "--", "tracked.txt") == ""
|
|
247
|
+
|
|
248
|
+
restored = restore_runtime_wip(
|
|
249
|
+
tmp_path,
|
|
250
|
+
family_kind="feature",
|
|
251
|
+
item_id="F-005",
|
|
252
|
+
working_branch=branch,
|
|
253
|
+
)
|
|
254
|
+
assert restored.ok is True
|
|
255
|
+
assert restored.restored is True
|
|
256
|
+
assert restored.wip_head == wip_head
|
|
257
|
+
assert restored.restored_head == base_head
|
|
258
|
+
assert _git(tmp_path, "rev-parse", "HEAD") == base_head
|
|
259
|
+
assert "tracked.txt" in _git(tmp_path, "status", "--porcelain", "--", "tracked.txt")
|
|
260
|
+
|
|
261
|
+
artifact_dir, checkpoint_path = _write_commit_ready_checkpoint(tmp_path)
|
|
262
|
+
_write_request(tmp_path, artifact_dir, base_head)
|
|
263
|
+
result = finalize_runtime_commit(
|
|
264
|
+
tmp_path,
|
|
265
|
+
artifact_dir=artifact_dir,
|
|
266
|
+
checkpoint_path=checkpoint_path,
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
assert result.status == "committed"
|
|
270
|
+
assert result.reason == "runtime_commit_completed"
|
|
271
|
+
assert result.commit_hash == _git(tmp_path, "rev-parse", "HEAD")
|
|
272
|
+
assert _git(tmp_path, "show", "-s", "--format=%s", "HEAD") == "fix(runtime): finalize prepared task"
|
|
273
|
+
assert _git(tmp_path, "show", "HEAD:tracked.txt") == "preserved feature change"
|
|
274
|
+
assert _git(tmp_path, "rev-list", "--count", f"{base_head}..HEAD") == "1"
|
|
275
|
+
checkpoint = json.loads(checkpoint_path.read_text(encoding="utf-8"))
|
|
276
|
+
assert checkpoint["feature_state"]["runtime_base_head"] == base_head
|
|
277
|
+
assert checkpoint["feature_state"]["runtime_commit_hash"] == result.commit_hash
|
|
278
|
+
assert checkpoint["feature_state"]["terminal_status"] == "WORKFLOW_COMPLETED"
|
|
279
|
+
|
|
280
|
+
|
|
227
281
|
@pytest.mark.parametrize(
|
|
228
282
|
"durable_path",
|
|
229
283
|
[
|