prizmkit 1.1.191 → 1.1.193

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.
Files changed (165) hide show
  1. package/bundled/VERSION.json +3 -3
  2. package/bundled/adapters/antigravity/skill-adapter.js +13 -4
  3. package/bundled/adapters/codex/skill-adapter.js +28 -8
  4. package/bundled/adapters/cursor/skill-adapter.js +13 -4
  5. package/bundled/adapters/pi/skill-adapter.js +28 -7
  6. package/bundled/dev-pipeline/.env.example +4 -12
  7. package/bundled/dev-pipeline/README.md +28 -44
  8. package/bundled/dev-pipeline/assets/feature-list-example.json +0 -1
  9. package/bundled/dev-pipeline/assets/skill-subagent-integration.md +6 -6
  10. package/bundled/dev-pipeline/prizmkit_runtime/atomic_io.py +48 -0
  11. package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +66 -23
  12. package/bundled/dev-pipeline/prizmkit_runtime/cli.py +10 -7
  13. package/bundled/dev-pipeline/prizmkit_runtime/commands.py +2 -21
  14. package/bundled/dev-pipeline/prizmkit_runtime/config.py +48 -78
  15. package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +127 -67
  16. package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +158 -462
  17. package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +102 -50
  18. package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +1 -25
  19. package/bundled/dev-pipeline/prizmkit_runtime/paths.py +0 -6
  20. package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +47 -21
  21. package/bundled/dev-pipeline/prizmkit_runtime/processes.py +217 -156
  22. package/bundled/dev-pipeline/prizmkit_runtime/reset.py +39 -27
  23. package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +34 -174
  24. package/bundled/dev-pipeline/prizmkit_runtime/results.py +25 -0
  25. package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +133 -110
  26. package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +15 -5
  27. package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +1 -95
  28. package/bundled/dev-pipeline/prizmkit_runtime/runner_prompts.py +0 -2
  29. package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +7 -2
  30. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +540 -262
  31. package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +175 -135
  32. package/bundled/dev-pipeline/prizmkit_runtime/runtime_helper.py +90 -9
  33. package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +214 -133
  34. package/bundled/dev-pipeline/prizmkit_runtime/status.py +1 -3
  35. package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +2783 -0
  36. package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +27 -102
  37. package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +58 -4
  38. package/bundled/dev-pipeline/scripts/check-session-status.py +56 -20
  39. package/bundled/dev-pipeline/scripts/continuation.py +8 -7
  40. package/bundled/dev-pipeline/scripts/detect-stuck.py +47 -33
  41. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +13 -16
  42. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +20 -10
  43. package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +10 -7
  44. package/bundled/dev-pipeline/scripts/init-change-artifact.py +25 -4
  45. package/bundled/dev-pipeline/scripts/init-pipeline.py +14 -69
  46. package/bundled/dev-pipeline/scripts/parse-stream-progress.py +31 -2616
  47. package/bundled/dev-pipeline/scripts/patch-completion-notes.py +4 -24
  48. package/bundled/dev-pipeline/scripts/prompt_framework.py +85 -20
  49. package/bundled/dev-pipeline/scripts/status_common.py +591 -0
  50. package/bundled/dev-pipeline/scripts/update-bug-status.py +85 -463
  51. package/bundled/dev-pipeline/scripts/update-checkpoint.py +254 -65
  52. package/bundled/dev-pipeline/scripts/update-feature-status.py +76 -509
  53. package/bundled/dev-pipeline/scripts/utils.py +5 -12
  54. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +5 -5
  55. package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +7 -0
  56. package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +7 -7
  57. package/bundled/dev-pipeline/templates/sections/artifact-manifest.md +1 -1
  58. package/bundled/dev-pipeline/templates/sections/bugfix-phase-manual-verification.md +1 -1
  59. package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +1 -1
  60. package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +2 -1
  61. package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +1 -1
  62. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-auto.md +1 -1
  63. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-opencli.md +2 -2
  64. package/bundled/dev-pipeline/templates/sections/phase-browser-verification.md +2 -2
  65. package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +2 -1
  66. package/bundled/dev-pipeline/templates/sections/phase-review-full.md +1 -1
  67. package/bundled/dev-pipeline/templates/sections/phase-specify-plan-full.md +3 -6
  68. package/bundled/dev-pipeline/templates/session-status-schema.json +2 -5
  69. package/bundled/skills/_metadata.json +9 -63
  70. package/bundled/skills/app-planner/SKILL.md +32 -303
  71. package/bundled/skills/app-planner/references/app-design-guide.md +0 -4
  72. package/bundled/skills/app-planner/references/generated-plan-review.md +2 -1
  73. package/bundled/skills/app-planner/references/project-brief-guide.md +14 -0
  74. package/bundled/skills/app-planner/references/project-conventions-discovery.md +4 -6
  75. package/bundled/skills/app-planner/references/project-state-detection.md +2 -3
  76. package/bundled/skills/bug-fix-workflow/SKILL.md +1 -2
  77. package/bundled/skills/bug-fix-workflow/references/bug-diagnosis.md +4 -7
  78. package/bundled/skills/bug-planner/SKILL.md +54 -435
  79. package/bundled/skills/bug-planner/references/generated-plan-review.md +3 -2
  80. package/bundled/skills/bug-planner/references/input-formats.md +32 -0
  81. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +4 -6
  82. package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +4 -28
  83. package/bundled/skills/feature-pipeline-launcher/SKILL.md +4 -6
  84. package/bundled/skills/feature-pipeline-launcher/references/configuration.md +4 -28
  85. package/bundled/skills/feature-planner/SKILL.md +60 -439
  86. package/bundled/skills/feature-planner/assets/planning-guide.md +1 -1
  87. package/bundled/skills/feature-planner/references/completeness-review.md +34 -0
  88. package/bundled/skills/feature-planner/references/decomposition-patterns.md +2 -2
  89. package/bundled/skills/feature-planner/references/error-recovery.md +1 -1
  90. package/bundled/skills/feature-planner/references/generated-plan-review.md +3 -2
  91. package/bundled/skills/feature-planner/references/incremental-feature-planning.md +3 -1
  92. package/bundled/skills/feature-workflow/SKILL.md +1 -2
  93. package/bundled/skills/prizmkit/SKILL.md +7 -1
  94. package/bundled/skills/prizmkit-code-review/SKILL.md +14 -6
  95. package/bundled/skills/prizmkit-code-review/references/independent-code-review.md +7 -4
  96. package/bundled/skills/prizmkit-code-review/references/review-report-template.md +16 -0
  97. package/bundled/skills/prizmkit-code-review/scripts/render_review_report.py +58 -20
  98. package/bundled/skills/prizmkit-implement/SKILL.md +1 -1
  99. package/bundled/skills/prizmkit-init/SKILL.md +24 -127
  100. package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
  101. package/bundled/skills/prizmkit-plan/SKILL.md +6 -8
  102. package/bundled/skills/prizmkit-plan/references/clarify-guide.md +1 -1
  103. package/bundled/skills/prizmkit-plan/references/independent-plan-review.md +5 -2
  104. package/bundled/skills/prizmkit-plan/references/review-plan-spec-loop.md +6 -5
  105. package/bundled/skills/prizmkit-prizm-docs/SKILL.md +1 -13
  106. package/bundled/skills/prizmkit-prizm-docs/references/op-update.md +1 -1
  107. package/bundled/skills/prizmkit-retrospective/SKILL.md +6 -4
  108. package/bundled/skills/prizmkit-test/SKILL.md +25 -133
  109. package/bundled/skills/prizmkit-test/references/independent-test-review.md +5 -2
  110. package/bundled/skills/prizmkit-test/references/test-coverage-model.md +6 -0
  111. package/bundled/skills/prizmkit-workflow/SKILL.md +2 -3
  112. package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +4 -3
  113. package/bundled/skills/recovery-workflow/SKILL.md +7 -7
  114. package/bundled/skills/recovery-workflow/evals/evals.json +1 -1
  115. package/bundled/skills/recovery-workflow/references/detection.md +1 -3
  116. package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +0 -6
  117. package/bundled/templates/project-memory-template.md +1 -2
  118. package/package.json +1 -1
  119. package/src/scaffold.js +28 -7
  120. package/bundled/dev-pipeline/SCHEMA_ANALYSIS.md +0 -53
  121. package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +0 -649
  122. package/bundled/dev-pipeline/scripts/init-refactor-pipeline.py +0 -463
  123. package/bundled/dev-pipeline/scripts/update-refactor-status.py +0 -1512
  124. package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +0 -240
  125. package/bundled/dev-pipeline/templates/refactor-list-schema.json +0 -266
  126. package/bundled/dev-pipeline/templates/sections/refactor-critical-paths.md +0 -15
  127. package/bundled/dev-pipeline/templates/sections/refactor-mission.md +0 -9
  128. package/bundled/dev-pipeline/templates/sections/refactor-phase-commit-report.md +0 -24
  129. package/bundled/dev-pipeline/templates/sections/refactor-phase-implement.md +0 -16
  130. package/bundled/dev-pipeline/templates/sections/refactor-phase-init.md +0 -9
  131. package/bundled/dev-pipeline/templates/sections/refactor-phase-plan.md +0 -22
  132. package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +0 -19
  133. package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +0 -24
  134. package/bundled/dev-pipeline/templates/sections/refactor-reminders.md +0 -12
  135. package/bundled/dev-pipeline/templates/sections/refactor-session-context.md +0 -6
  136. package/bundled/dev-pipeline/templates/sections/refactor-task-contract.md +0 -52
  137. package/bundled/dev-pipeline/tests/conftest.py +0 -29
  138. package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +0 -208
  139. package/bundled/dev-pipeline/tests/test_auto_skip.py +0 -1871
  140. package/bundled/dev-pipeline/tests/test_checkpoint_state.py +0 -1314
  141. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +0 -1712
  142. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +0 -627
  143. package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +0 -478
  144. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +0 -5641
  145. package/bundled/dev-pipeline/tests/test_recovery_workflow.py +0 -322
  146. package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -252
  147. package/bundled/dev-pipeline/tests/test_reset_modes.py +0 -1208
  148. package/bundled/dev-pipeline/tests/test_reset_preserve.py +0 -957
  149. package/bundled/dev-pipeline/tests/test_runtime_commit.py +0 -1113
  150. package/bundled/dev-pipeline/tests/test_runtime_helper.py +0 -303
  151. package/bundled/dev-pipeline/tests/test_unified_cli.py +0 -5504
  152. package/bundled/dev-pipeline/tests/test_utils.py +0 -170
  153. package/bundled/skills/feature-planner/assets/evaluation-guide.md +0 -44
  154. package/bundled/skills/refactor-pipeline-launcher/SKILL.md +0 -219
  155. package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +0 -78
  156. package/bundled/skills/refactor-planner/SKILL.md +0 -467
  157. package/bundled/skills/refactor-planner/assets/planning-guide.md +0 -291
  158. package/bundled/skills/refactor-planner/references/behavior-preservation.md +0 -187
  159. package/bundled/skills/refactor-planner/references/error-recovery.md +0 -45
  160. package/bundled/skills/refactor-planner/references/fast-path.md +0 -59
  161. package/bundled/skills/refactor-planner/references/generated-plan-review.md +0 -107
  162. package/bundled/skills/refactor-planner/references/planning-phases.md +0 -172
  163. package/bundled/skills/refactor-planner/references/refactor-scoping-guide.md +0 -230
  164. package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +0 -1120
  165. package/bundled/skills/refactor-workflow/SKILL.md +0 -205
@@ -1,957 +0,0 @@
1
- """Regression tests for non-destructive failed-chain reset behavior."""
2
-
3
- import json
4
- import shlex
5
- import subprocess
6
- import sys
7
- from pathlib import Path
8
-
9
- import pytest
10
-
11
- REPO_ROOT = Path(__file__).resolve().parents[2]
12
- PIPELINE_ROOT = REPO_ROOT / "dev-pipeline"
13
- CLI_PATH = PIPELINE_ROOT / "cli.py"
14
- if str(PIPELINE_ROOT) not in sys.path:
15
- sys.path.insert(0, str(PIPELINE_ROOT))
16
-
17
-
18
- def _make_paths(tmp_path):
19
- from prizmkit_runtime.paths import resolve_runtime_paths
20
-
21
- project = tmp_path / "project"
22
- (project / ".prizmkit" / "plans").mkdir(parents=True)
23
- return resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=project)
24
-
25
-
26
- def _write_family_plan(paths, kind, items):
27
- plan_config = {
28
- "feature": (paths.feature_plan, "features", "dev-pipeline-feature-list-v1"),
29
- "bugfix": (paths.bugfix_plan, "bugs", "dev-pipeline-bug-fix-list-v1"),
30
- "refactor": (paths.refactor_plan, "refactors", "dev-pipeline-refactor-list-v1"),
31
- }
32
- plan_path, list_key, schema = plan_config[kind]
33
- plan_path.write_text(
34
- json.dumps({"$schema": schema, "project_name": "Fake", list_key: items}),
35
- encoding="utf-8",
36
- )
37
- return plan_path
38
-
39
-
40
- def _write_semantic_completion_checkpoint(project_root, artifact_dir, workflow_type="feature-pipeline"):
41
- contracts = {
42
- "feature-pipeline": (
43
- "feature_state",
44
- [
45
- "prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
46
- "prizmkit-retrospective", "prizmkit-committer", "completion-summary",
47
- ],
48
- ),
49
- "bugfix-pipeline": (
50
- "bugfix_state",
51
- [
52
- "prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
53
- "prizmkit-retrospective", "prizmkit-committer", "bug-report",
54
- ],
55
- ),
56
- "refactor-pipeline": (
57
- "refactor_state",
58
- [
59
- "prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
60
- "prizmkit-retrospective", "prizmkit-committer", "refactor-report",
61
- "completion-summary",
62
- ],
63
- ),
64
- }
65
- state_key, skills = contracts[workflow_type]
66
- steps = []
67
- previous = None
68
- for index, skill in enumerate(skills, start=1):
69
- step = {
70
- "id": f"S{index:02d}",
71
- "skill": skill,
72
- "name": skill,
73
- "status": "completed",
74
- "required_artifacts": [],
75
- "depends_on": previous,
76
- }
77
- if skill == "prizmkit-implement":
78
- step["stage_result"] = "IMPLEMENTED"
79
- if skill == "prizmkit-code-review":
80
- step["stage_result"] = "REVIEW_PASS"
81
- if skill == "prizmkit-test":
82
- step["stage_result"] = "TEST_PASS"
83
- relative_artifact = artifact_dir.relative_to(project_root)
84
- step["required_artifacts"] = [
85
- str(relative_artifact / "test-report.md"),
86
- str(relative_artifact / "test-result.json"),
87
- ]
88
- if skill == "prizmkit-retrospective":
89
- step["stage_result"] = "RETRO_COMPLETE"
90
- if skill == "prizmkit-committer":
91
- step["stage_result"] = "COMMITTED"
92
- steps.append(step)
93
- previous = step["id"]
94
- artifact_dir.mkdir(parents=True, exist_ok=True)
95
- (artifact_dir / "test-report.md").write_text(
96
- "# Test Report\n\n## Final Result\n\n- Result: TEST_PASS\n",
97
- encoding="utf-8",
98
- )
99
- (artifact_dir / "test-result.json").write_text(
100
- json.dumps({
101
- "schema_version": 1,
102
- "result": "TEST_PASS",
103
- "report": "test-report.md",
104
- "main_review_rounds": 1,
105
- "independent_review": {
106
- "status": "downgraded",
107
- "responses": 0,
108
- "downgrade_reason": "read-only capability unavailable",
109
- "final_state_rechecked": False,
110
- },
111
- "repair_rounds": 0,
112
- "production_changed": False,
113
- "unresolved_items": [],
114
- }),
115
- encoding="utf-8",
116
- )
117
- checkpoint = artifact_dir / "workflow-checkpoint.json"
118
- checkpoint.write_text(
119
- json.dumps({
120
- "version": 1,
121
- "workflow_type": workflow_type,
122
- "steps": steps,
123
- state_key: {
124
- "repair_round": 0,
125
- "terminal_status": "WORKFLOW_COMPLETED",
126
- },
127
- }),
128
- encoding="utf-8",
129
- )
130
- return checkpoint
131
-
132
-
133
- def _init_preserve_runtime_repo(paths):
134
- subprocess.run(["git", "init", "-b", "main"], cwd=paths.project_root, check=True, stdout=subprocess.DEVNULL)
135
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=paths.project_root, check=True)
136
- subprocess.run(["git", "config", "user.name", "Test"], cwd=paths.project_root, check=True)
137
- (paths.project_root / "base.txt").write_text("base\n", encoding="utf-8")
138
- subprocess.run(["git", "add", "base.txt"], cwd=paths.project_root, check=True)
139
- subprocess.run(["git", "commit", "-m", "base"], cwd=paths.project_root, check=True, stdout=subprocess.DEVNULL)
140
-
141
-
142
- def _preserve_family_contract(kind):
143
- return {
144
- "feature": ("F-", "dev", "feature-pipeline", "specs"),
145
- "bugfix": ("B-", "bugfix", "bugfix-pipeline", "bugfix"),
146
- "refactor": ("R-", "refactor", "refactor-pipeline", "refactor"),
147
- }[kind]
148
-
149
-
150
- def _preserve_item_id(prefix, number):
151
- return f"{prefix}{number:03d}"
152
-
153
-
154
- def _preserve_items(kind):
155
- prefix, _branch_prefix, _workflow_type, _artifact_root = _preserve_family_contract(kind)
156
- statuses = [
157
- (1, "failed", []),
158
- (2, "auto_skipped", [_preserve_item_id(prefix, 1)]),
159
- (3, "auto_skipped", [_preserve_item_id(prefix, 2)]),
160
- (4, "completed", []),
161
- (5, "skipped", []),
162
- (6, "auto_skipped", [_preserve_item_id(prefix, 5)]),
163
- (7, "needs_info", []),
164
- (8, "pending", []),
165
- (9, "split", []),
166
- ]
167
- return [
168
- {
169
- "id": _preserve_item_id(prefix, number),
170
- "title": "Root" if number == 1 else f"Item {number}",
171
- "description": "preserve runtime",
172
- "status": status,
173
- "priority": "medium",
174
- "dependencies": dependencies,
175
- }
176
- for number, status, dependencies in statuses
177
- ]
178
-
179
-
180
- def _write_preserve_runtime_state(paths, kind, item_id, branch, *, base_branch="main"):
181
- from prizmkit_runtime.runner_models import family_for
182
- from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
183
-
184
- family = family_for(kind, paths)
185
- family.state_dir.mkdir(parents=True, exist_ok=True)
186
- (family.state_dir / "pipeline.json").write_text(json.dumps({"status": "failed"}), encoding="utf-8")
187
- item_state = family.state_dir / item_id
188
- sessions = item_state / "sessions" / "old-session" / "logs"
189
- sessions.mkdir(parents=True, exist_ok=True)
190
- (sessions / "session.log").write_text("historical log\n", encoding="utf-8")
191
- status = {
192
- "status": "failed",
193
- "retry_count": 7,
194
- "infra_error_count": 4,
195
- "sessions": ["old-session"],
196
- "last_session_id": "old-session",
197
- "previous_session_id": "old-session",
198
- "last_infra_error_session_id": "old-session",
199
- "continuation_pending": False,
200
- "continuation_reason": "code_error",
201
- "continuation_summary_path": "keep-this-path",
202
- "last_progress_fingerprint": {"head": "abc", "checkpoint": "S03"},
203
- "no_progress_count": 2,
204
- "fatal_error_code": "provider_error",
205
- "active_dev_branch": branch,
206
- "base_branch": base_branch,
207
- "custom_diagnostic": {"reason": "preserve me"},
208
- }
209
- status_path = item_state / "status.json"
210
- status_path.write_text(json.dumps(status, indent=2) + "\n", encoding="utf-8")
211
- checkout = TaskCheckout.active(kind, item_id, branch, base_branch)
212
- persist_task_checkout(family.state_dir, checkout)
213
- return family, status_path, status, checkout
214
-
215
-
216
- @pytest.mark.parametrize("kind", ["feature", "bugfix", "refactor"])
217
- def test_preserve_runtime_restores_failed_chain_and_preserves_existing_checkout_history(tmp_path, kind):
218
- from prizmkit_runtime.reset import run_reset_command
219
- from prizmkit_runtime.task_checkout import load_task_checkout
220
-
221
- paths = _make_paths(tmp_path / kind)
222
- _init_preserve_runtime_repo(paths)
223
- prefix, branch_prefix, workflow_type, artifact_root = _preserve_family_contract(kind)
224
- root_id = _preserve_item_id(prefix, 1)
225
- plan = _write_family_plan(paths, kind, _preserve_items(kind))
226
- branch = f"{branch_prefix}/{root_id}-preserved"
227
- subprocess.run(["git", "branch", branch, "main"], cwd=paths.project_root, check=True)
228
- family, status_path, before_status, checkout = _write_preserve_runtime_state(paths, kind, root_id, branch)
229
- descendant_status = family.state_dir / _preserve_item_id(prefix, 2) / "status.json"
230
- descendant_status.parent.mkdir(parents=True, exist_ok=True)
231
- descendant_status.write_text(
232
- json.dumps({"status": "auto_skipped", "caused_by": root_id, "sessions": ["child-history"]}, indent=2) + "\n",
233
- encoding="utf-8",
234
- )
235
- descendant_status_before = descendant_status.read_bytes()
236
- artifact_name = "001-root" if kind == "feature" else root_id
237
- artifact = paths.project_root / ".prizmkit" / artifact_root / artifact_name
238
- checkpoint = _write_semantic_completion_checkpoint(paths.project_root, artifact, workflow_type)
239
- checkpoint_before = checkpoint.read_bytes()
240
- session_log = family.state_dir / root_id / "sessions" / "old-session" / "logs" / "session.log"
241
- session_before = session_log.read_bytes()
242
- branch_head_before = subprocess.run(
243
- ["git", "rev-parse", branch], cwd=paths.project_root, check=True, stdout=subprocess.PIPE, text=True
244
- ).stdout.strip()
245
-
246
- result = run_reset_command(kind, ("--failed", "--preserve-runtime"), paths)
247
-
248
- assert result.exit_code == 0, result.render()
249
- updated_plan = json.loads(plan.read_text(encoding="utf-8"))
250
- statuses = {item["id"]: item["status"] for item in updated_plan[family.list_key]}
251
- assert statuses[root_id] == "pending"
252
- assert statuses[_preserve_item_id(prefix, 2)] == "pending"
253
- assert statuses[_preserve_item_id(prefix, 3)] == "pending"
254
- assert statuses[_preserve_item_id(prefix, 4)] == "completed"
255
- assert statuses[_preserve_item_id(prefix, 5)] == "skipped"
256
- assert statuses[_preserve_item_id(prefix, 6)] == "auto_skipped"
257
- assert statuses[_preserve_item_id(prefix, 7)] == "needs_info"
258
- assert statuses[_preserve_item_id(prefix, 8)] == "pending"
259
- assert statuses[_preserve_item_id(prefix, 9)] == "split"
260
- expected_status = dict(before_status)
261
- expected_status.update(retry_count=0, infra_error_count=0, continuation_pending=True)
262
- assert json.loads(status_path.read_text(encoding="utf-8")) == expected_status
263
- assert load_task_checkout(family.state_dir, kind, root_id) == checkout
264
- assert descendant_status.read_bytes() == descendant_status_before
265
- assert checkpoint.read_bytes() == checkpoint_before
266
- assert session_log.read_bytes() == session_before
267
- assert subprocess.run(
268
- ["git", "rev-parse", branch], cwd=paths.project_root, check=True, stdout=subprocess.PIPE, text=True
269
- ).stdout.strip() == branch_head_before
270
- assert "Active checkouts reused" in result.render()
271
- assert "Reset did not start a runner" in result.render()
272
-
273
-
274
- @pytest.mark.parametrize("kind", ["feature", "bugfix", "refactor"])
275
- def test_preserve_runtime_no_failed_root_is_a_noop_without_checkout_state(tmp_path, kind):
276
- from prizmkit_runtime.reset import run_reset_command
277
- from prizmkit_runtime.runner_models import family_for
278
-
279
- paths = _make_paths(tmp_path / kind)
280
- items = _preserve_items(kind)
281
- items[0]["status"] = "completed"
282
- plan = _write_family_plan(paths, kind, items)
283
- family = family_for(kind, paths)
284
- before = plan.read_bytes()
285
-
286
- result = run_reset_command(kind, ("--failed", "--preserve-runtime"), paths)
287
-
288
- assert result.exit_code == 0
289
- assert "No failed" in result.render()
290
- assert plan.read_bytes() == before
291
- assert not any((family.state_dir / item["id"] / "checkout.json").exists() for item in items)
292
-
293
-
294
- def test_preserve_runtime_option_boundaries_and_removed_reset_run_do_not_mutate_state(tmp_path):
295
- from prizmkit_runtime.reset import ResetOptions, run_reset_command
296
- from prizmkit_runtime.runner_models import family_for, parse_invocation
297
-
298
- paths = _make_paths(tmp_path)
299
- plan = _write_family_plan(paths, "feature", _preserve_items("feature"))
300
- family = family_for("feature", paths)
301
- family.state_dir.mkdir(parents=True, exist_ok=True)
302
- (family.state_dir / "pipeline.json").write_text("{}\n", encoding="utf-8")
303
- before = plan.read_bytes()
304
- invalid_cases = [
305
- (("F-001", "--run"), "no longer accepts --run"),
306
- (("--preserve-runtime",), "requires --failed"),
307
- (("--failed", "--preserve-runtime", "--clean"), "Exactly one reset mode"),
308
- (("F-001", "--failed", "--preserve-runtime"), "cannot target an ID, range, or --all"),
309
- (("F-001:F-003", "--failed", "--preserve-runtime"), "cannot target an ID, range, or --all"),
310
- (("--failed", "--preserve-runtime", "--stalled"), "Unsupported reset arguments"),
311
- (("--failed", "--preserve-runtime", "--unknown"), "Unsupported reset arguments"),
312
- ]
313
-
314
- for args, message in invalid_cases:
315
- result = run_reset_command("feature", args, paths)
316
- assert result.exit_code != 0
317
- assert message in result.render()
318
- assert plan.read_bytes() == before
319
- assert "run_after" not in ResetOptions.__dataclass_fields__
320
- invocation = parse_invocation(
321
- family,
322
- "run",
323
- ("F-001", "--max-retries", "6", "--max-infra-retries", "7"),
324
- )
325
- assert invocation.action == "run"
326
- assert invocation.item_id == "F-001"
327
- assert invocation.max_retries == 6
328
- assert invocation.max_infra_retries == 7
329
-
330
-
331
- def test_preserve_runtime_restores_every_failed_root_in_one_successful_pass(tmp_path):
332
- from prizmkit_runtime.reset import run_reset_command
333
-
334
- paths = _make_paths(tmp_path)
335
- _init_preserve_runtime_repo(paths)
336
- items = [
337
- {"id": "F-001", "title": "Root One", "status": "failed", "dependencies": []},
338
- {"id": "F-002", "title": "Child One", "status": "auto_skipped", "dependencies": ["F-001"]},
339
- {"id": "F-003", "title": "Root Two", "status": "failed", "dependencies": []},
340
- {"id": "F-004", "title": "Child Two", "status": "auto_skipped", "dependencies": ["F-003"]},
341
- {"id": "F-005", "title": "Done", "status": "completed", "dependencies": []},
342
- ]
343
- plan = _write_family_plan(paths, "feature", items)
344
- before_statuses = {}
345
- for item_id in ("F-001", "F-003"):
346
- branch = f"dev/{item_id}-existing"
347
- subprocess.run(["git", "branch", branch, "main"], cwd=paths.project_root, check=True)
348
- _family, status_path, status_data, _checkout = _write_preserve_runtime_state(
349
- paths, "feature", item_id, branch
350
- )
351
- before_statuses[item_id] = (status_path, status_data)
352
-
353
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
354
-
355
- assert result.exit_code == 0, result.render()
356
- statuses = {
357
- item["id"]: item["status"]
358
- for item in json.loads(plan.read_text(encoding="utf-8"))["features"]
359
- }
360
- assert statuses == {
361
- "F-001": "pending",
362
- "F-002": "pending",
363
- "F-003": "pending",
364
- "F-004": "pending",
365
- "F-005": "completed",
366
- }
367
- for status_path, before in before_statuses.values():
368
- expected = dict(before)
369
- expected.update(retry_count=0, infra_error_count=0, continuation_pending=True)
370
- assert json.loads(status_path.read_text(encoding="utf-8")) == expected
371
- assert "Failed roots restored: F-001, F-003" in result.render()
372
-
373
- plan_after = plan.read_bytes()
374
- runtime_after = {
375
- item_id: status_path.read_bytes()
376
- for item_id, (status_path, _before) in before_statuses.items()
377
- }
378
- second = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
379
- assert second.exit_code == 0
380
- assert "No failed" in second.render()
381
- assert plan.read_bytes() == plan_after
382
- assert {
383
- item_id: status_path.read_bytes()
384
- for item_id, (status_path, _before) in before_statuses.items()
385
- } == runtime_after
386
-
387
-
388
- def test_preserve_runtime_respects_existing_task_guard_without_mutation(tmp_path):
389
- from prizmkit_runtime.reset import run_reset_command
390
- from prizmkit_runtime.task_checkout import task_checkout_guard
391
-
392
- paths = _make_paths(tmp_path)
393
- _init_preserve_runtime_repo(paths)
394
- plan = _write_family_plan(
395
- paths,
396
- "feature",
397
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
398
- )
399
- subprocess.run(["git", "branch", "dev/F-001-existing", "main"], cwd=paths.project_root, check=True)
400
- family, status_path, _status, _checkout = _write_preserve_runtime_state(
401
- paths, "feature", "F-001", "dev/F-001-existing"
402
- )
403
- plan_before = plan.read_bytes()
404
- status_before = status_path.read_bytes()
405
-
406
- with task_checkout_guard(family.state_dir, "F-001"):
407
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
408
-
409
- assert result.exit_code == 1
410
- assert "checkout lifecycle is busy" in result.render()
411
- assert plan.read_bytes() == plan_before
412
- assert status_path.read_bytes() == status_before
413
-
414
-
415
- @pytest.mark.parametrize(
416
- ("kind", "item_id"),
417
- [("feature", "F-001"), ("bugfix", "B-001"), ("refactor", "R-001")],
418
- )
419
- def test_public_reset_cli_hard_rejects_run_for_every_family_without_state_change(tmp_path, kind, item_id):
420
- project = tmp_path / kind
421
- project.mkdir()
422
-
423
- completed = subprocess.run(
424
- [
425
- sys.executable,
426
- str(CLI_PATH),
427
- "--project-root",
428
- str(project),
429
- "reset",
430
- kind,
431
- item_id,
432
- "--run",
433
- ],
434
- cwd=REPO_ROOT,
435
- stdout=subprocess.PIPE,
436
- stderr=subprocess.PIPE,
437
- text=True,
438
- check=False,
439
- )
440
-
441
- assert completed.returncode == 2
442
- assert "unrecognized arguments: --run" in completed.stdout + completed.stderr
443
- assert not (project / ".prizmkit").exists()
444
-
445
-
446
- @pytest.mark.parametrize(
447
- ("items", "expected_error"),
448
- [
449
- (
450
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": ["F-999"]}],
451
- "unknown dependency F-999",
452
- ),
453
- (
454
- [
455
- {"id": "F-001", "title": "One", "status": "failed", "dependencies": ["F-002"]},
456
- {"id": "F-002", "title": "Two", "status": "auto_skipped", "dependencies": ["F-001"]},
457
- ],
458
- "dependency cycle",
459
- ),
460
- (
461
- [
462
- {"id": "F-001", "title": "One", "status": "failed", "dependencies": []},
463
- {"id": "F-001", "title": "Duplicate", "status": "failed", "dependencies": []},
464
- ],
465
- "duplicate item id: F-001",
466
- ),
467
- ],
468
- )
469
- def test_preserve_runtime_rejects_invalid_dependency_graph_without_state_mutation(
470
- tmp_path,
471
- items,
472
- expected_error,
473
- ):
474
- from prizmkit_runtime.reset import run_reset_command
475
-
476
- paths = _make_paths(tmp_path)
477
- plan = _write_family_plan(paths, "feature", items)
478
- before = plan.read_bytes()
479
-
480
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
481
-
482
- assert result.exit_code == 1
483
- assert expected_error in result.render()
484
- assert plan.read_bytes() == before
485
- assert not paths.feature_state_dir.exists()
486
-
487
-
488
- def test_preserve_runtime_success_quotes_list_path_in_separate_run_instruction(tmp_path):
489
- from prizmkit_runtime.reset import run_reset_command
490
-
491
- paths = _make_paths(tmp_path / "parent with spaces")
492
- _init_preserve_runtime_repo(paths)
493
- plan = _write_family_plan(
494
- paths,
495
- "feature",
496
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
497
- )
498
- subprocess.run(["git", "branch", "dev/F-001-existing", "main"], cwd=paths.project_root, check=True)
499
- _write_preserve_runtime_state(paths, "feature", "F-001", "dev/F-001-existing")
500
-
501
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
502
-
503
- assert result.exit_code == 0
504
- assert f"run feature {shlex.quote(str(plan.resolve()))}" in result.render()
505
-
506
-
507
- def test_preserve_runtime_requires_recorded_base_to_be_a_local_branch(tmp_path):
508
- from prizmkit_runtime.reset import run_reset_command
509
-
510
- paths = _make_paths(tmp_path)
511
- _init_preserve_runtime_repo(paths)
512
- subprocess.run(["git", "tag", "base-tag", "main"], cwd=paths.project_root, check=True)
513
- plan = _write_family_plan(
514
- paths,
515
- "feature",
516
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
517
- )
518
- _family, status_path, _before_status, _checkout = _write_preserve_runtime_state(
519
- paths,
520
- "feature",
521
- "F-001",
522
- "dev/F-001-missing",
523
- base_branch="base-tag",
524
- )
525
- plan_before = plan.read_bytes()
526
- status_before = status_path.read_bytes()
527
-
528
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
529
-
530
- assert result.exit_code == 1
531
- assert "recorded base branch is missing: base-tag" in result.render()
532
- assert plan.read_bytes() == plan_before
533
- assert status_path.read_bytes() == status_before
534
-
535
-
536
- def test_preserve_runtime_preflights_all_failed_roots_before_any_state_change(tmp_path):
537
- from prizmkit_runtime.reset import run_reset_command
538
-
539
- paths = _make_paths(tmp_path)
540
- _init_preserve_runtime_repo(paths)
541
- items = [
542
- {"id": "F-001", "title": "One", "status": "failed", "dependencies": []},
543
- {"id": "F-002", "title": "Two", "status": "failed", "dependencies": []},
544
- {"id": "F-003", "title": "Three", "status": "failed", "dependencies": []},
545
- ]
546
- plan = _write_family_plan(paths, "feature", items)
547
- subprocess.run(["git", "branch", "dev/F-001-existing", "main"], cwd=paths.project_root, check=True)
548
- family, status_one, _data_one, _checkout_one = _write_preserve_runtime_state(
549
- paths, "feature", "F-001", "dev/F-001-existing"
550
- )
551
- _family, status_two, _data_two, _checkout_two = _write_preserve_runtime_state(
552
- paths, "feature", "F-002", "dev/F-002-missing", base_branch="missing-base-two"
553
- )
554
- _family, status_three, _data_three, _checkout_three = _write_preserve_runtime_state(
555
- paths, "feature", "F-003", "dev/F-003-missing", base_branch="missing-base-three"
556
- )
557
- plan_before = plan.read_bytes()
558
- status_one_before = status_one.read_bytes()
559
- status_two_before = status_two.read_bytes()
560
- status_three_before = status_three.read_bytes()
561
- checkout_one_before = (family.state_dir / "F-001" / "checkout.json").read_bytes()
562
- branches_before = subprocess.run(
563
- ["git", "branch", "--format=%(refname:short)"],
564
- cwd=paths.project_root,
565
- check=True,
566
- stdout=subprocess.PIPE,
567
- text=True,
568
- ).stdout
569
-
570
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
571
-
572
- assert result.exit_code == 1
573
- assert "recorded base branch is missing: missing-base-two" in result.render()
574
- assert "recorded base branch is missing: missing-base-three" in result.render()
575
- assert plan.read_bytes() == plan_before
576
- assert status_one.read_bytes() == status_one_before
577
- assert status_two.read_bytes() == status_two_before
578
- assert status_three.read_bytes() == status_three_before
579
- assert (family.state_dir / "F-001" / "checkout.json").read_bytes() == checkout_one_before
580
- assert subprocess.run(
581
- ["git", "branch", "--format=%(refname:short)"],
582
- cwd=paths.project_root,
583
- check=True,
584
- stdout=subprocess.PIPE,
585
- text=True,
586
- ).stdout == branches_before
587
-
588
-
589
- def test_preserve_runtime_invalid_existing_checkpoint_blocks_before_mutation(tmp_path):
590
- from prizmkit_runtime.reset import run_reset_command
591
-
592
- paths = _make_paths(tmp_path)
593
- _init_preserve_runtime_repo(paths)
594
- plan = _write_family_plan(
595
- paths,
596
- "feature",
597
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
598
- )
599
- subprocess.run(["git", "branch", "dev/F-001-existing", "main"], cwd=paths.project_root, check=True)
600
- _family, status_path, _before_status, _checkout = _write_preserve_runtime_state(
601
- paths, "feature", "F-001", "dev/F-001-existing"
602
- )
603
- artifact = paths.project_root / ".prizmkit" / "specs" / "001-root"
604
- artifact.mkdir(parents=True)
605
- checkpoint = artifact / "workflow-checkpoint.json"
606
- checkpoint.write_text("{\"steps\": \"invalid\"}\n", encoding="utf-8")
607
- plan_before = plan.read_bytes()
608
- status_before = status_path.read_bytes()
609
- checkout_before = (
610
- paths.feature_state_dir / "F-001" / "checkout.json"
611
- ).read_bytes()
612
-
613
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
614
-
615
- assert result.exit_code == 1
616
- assert "invalid checkpoint" in result.render()
617
- assert plan.read_bytes() == plan_before
618
- assert status_path.read_bytes() == status_before
619
- assert (paths.feature_state_dir / "F-001" / "checkout.json").read_bytes() == checkout_before
620
- assert checkpoint.read_text(encoding="utf-8") == "{\"steps\": \"invalid\"}\n"
621
-
622
-
623
- def _add_completed_plan_step(checkpoint):
624
- payload = json.loads(checkpoint.read_text(encoding="utf-8"))
625
- payload["steps"].insert(
626
- 0,
627
- {
628
- "id": "S00",
629
- "skill": "prizmkit-plan",
630
- "name": "plan",
631
- "status": "completed",
632
- "stage_result": "PLAN_READY",
633
- "depends_on": None,
634
- "required_artifacts": [],
635
- },
636
- )
637
- payload["steps"][1]["depends_on"] = "S00"
638
- state_key = {
639
- "feature-pipeline": "feature_state",
640
- "bugfix-pipeline": "bugfix_state",
641
- "refactor-pipeline": "refactor_state",
642
- }[payload["workflow_type"]]
643
- payload[state_key]["completed_stages"] = ["plan", "implement", "code-review", "test"]
644
- checkpoint.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")
645
-
646
-
647
- def test_preserve_runtime_missing_branch_creates_replacement_and_rewinds_checkpoint(tmp_path):
648
- from prizmkit_runtime.gitops import local_branch_exists
649
- from prizmkit_runtime.reset import run_reset_command
650
- from prizmkit_runtime.runner_models import family_for
651
- from prizmkit_runtime.task_checkout import load_task_checkout
652
-
653
- paths = _make_paths(tmp_path)
654
- _init_preserve_runtime_repo(paths)
655
- plan = _write_family_plan(
656
- paths,
657
- "feature",
658
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
659
- )
660
- family, status_path, before_status, old_checkout = _write_preserve_runtime_state(
661
- paths, "feature", "F-001", "dev/F-001-deleted"
662
- )
663
- artifact = paths.project_root / ".prizmkit" / "specs" / "001-root"
664
- checkpoint = _write_semantic_completion_checkpoint(paths.project_root, artifact)
665
- _add_completed_plan_step(checkpoint)
666
- (artifact / "implementation-notes.md").write_text("keep context\n", encoding="utf-8")
667
- session_log = family.state_dir / "F-001" / "sessions" / "old-session" / "logs" / "session.log"
668
- session_before = session_log.read_bytes()
669
- base_head = subprocess.run(
670
- ["git", "rev-parse", "main"], cwd=paths.project_root, check=True, stdout=subprocess.PIPE, text=True
671
- ).stdout.strip()
672
-
673
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
674
-
675
- assert result.exit_code == 0, result.render()
676
- checkout = load_task_checkout(family.state_dir, "feature", "F-001")
677
- assert checkout is not None and checkout.is_active and not checkout.is_reset
678
- assert checkout.active_dev_branch != old_checkout.active_dev_branch
679
- assert checkout.active_dev_branch.startswith("dev/F-001-resume-")
680
- assert checkout.base_branch == "main"
681
- assert local_branch_exists(paths.project_root, checkout.active_dev_branch)
682
- assert subprocess.run(
683
- ["git", "rev-parse", checkout.active_dev_branch],
684
- cwd=paths.project_root,
685
- check=True,
686
- stdout=subprocess.PIPE,
687
- text=True,
688
- ).stdout.strip() == base_head
689
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
690
- assert persisted["steps"][0]["status"] == "completed"
691
- assert persisted["steps"][0]["stage_result"] == "PLAN_READY"
692
- assert all(step["status"] == "pending" for step in persisted["steps"][1:])
693
- assert all("stage_result" not in step for step in persisted["steps"][1:])
694
- assert persisted["feature_state"]["stage"] == "implement"
695
- assert persisted["feature_state"]["current_stage"] == "prizmkit-implement"
696
- assert persisted["feature_state"]["completed_stages"] == ["plan"]
697
- assert (artifact / "implementation-notes.md").read_text(encoding="utf-8") == "keep context\n"
698
- expected_status = dict(before_status)
699
- expected_status.update(
700
- retry_count=0,
701
- infra_error_count=0,
702
- continuation_pending=True,
703
- active_dev_branch=checkout.active_dev_branch,
704
- base_branch="main",
705
- )
706
- assert json.loads(status_path.read_text(encoding="utf-8")) == expected_status
707
- assert session_log.read_bytes() == session_before
708
- assert json.loads(plan.read_text(encoding="utf-8"))["features"][0]["status"] == "pending"
709
-
710
-
711
- @pytest.mark.parametrize(
712
- ("kind", "item_id", "branch_prefix", "workflow_type", "artifact_root", "state_key"),
713
- [
714
- ("bugfix", "B-001", "bugfix", "bugfix-pipeline", "bugfix", "bugfix_state"),
715
- ("refactor", "R-001", "refactor", "refactor-pipeline", "refactor", "refactor_state"),
716
- ],
717
- )
718
- def test_missing_branch_checkpoint_rewind_has_cross_family_parity(
719
- tmp_path,
720
- kind,
721
- item_id,
722
- branch_prefix,
723
- workflow_type,
724
- artifact_root,
725
- state_key,
726
- ):
727
- from prizmkit_runtime.gitops import local_branch_exists
728
- from prizmkit_runtime.reset import run_reset_command
729
- from prizmkit_runtime.runner_models import family_for
730
- from prizmkit_runtime.task_checkout import load_task_checkout
731
-
732
- paths = _make_paths(tmp_path / kind)
733
- _init_preserve_runtime_repo(paths)
734
- plan = _write_family_plan(
735
- paths,
736
- kind,
737
- [{"id": item_id, "title": "Root", "status": "failed", "dependencies": []}],
738
- )
739
- family, _status_path, _before_status, old_checkout = _write_preserve_runtime_state(
740
- paths, kind, item_id, f"{branch_prefix}/{item_id}-deleted"
741
- )
742
- artifact = paths.project_root / ".prizmkit" / artifact_root / item_id
743
- checkpoint = _write_semantic_completion_checkpoint(
744
- paths.project_root,
745
- artifact,
746
- workflow_type,
747
- )
748
- _add_completed_plan_step(checkpoint)
749
-
750
- result = run_reset_command(kind, ("--failed", "--preserve-runtime"), paths)
751
-
752
- assert result.exit_code == 0, result.render()
753
- checkout = load_task_checkout(family.state_dir, kind, item_id)
754
- assert checkout is not None and checkout.is_active
755
- assert checkout.active_dev_branch != old_checkout.active_dev_branch
756
- assert checkout.active_dev_branch.startswith(f"{branch_prefix}/{item_id}-resume-")
757
- assert local_branch_exists(paths.project_root, checkout.active_dev_branch)
758
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
759
- assert persisted["steps"][0]["status"] == "completed"
760
- assert all(step["status"] == "pending" for step in persisted["steps"][1:])
761
- assert persisted[state_key]["stage"] == "implement"
762
- assert persisted[state_key]["current_stage"] == "prizmkit-implement"
763
- collection = {"bugfix": "bugs", "refactor": "refactors"}[kind]
764
- assert json.loads(plan.read_text(encoding="utf-8"))[collection][0]["status"] == "pending"
765
-
766
-
767
- def test_preserve_runtime_reuses_registered_worktree_without_cleanup(tmp_path):
768
- from prizmkit_runtime.gitops import (
769
- BranchContext,
770
- WorktreePolicy,
771
- ensure_linked_worktree,
772
- registered_worktrees,
773
- worktree_runtime_context,
774
- )
775
- from prizmkit_runtime.reset import run_reset_command
776
- from prizmkit_runtime.runner_models import family_for
777
- from prizmkit_runtime.task_checkout import (
778
- CHECKOUT_MODE_WORKTREE,
779
- TaskCheckout,
780
- load_task_checkout,
781
- persist_task_checkout,
782
- )
783
-
784
- paths = _make_paths(tmp_path)
785
- _init_preserve_runtime_repo(paths)
786
- plan = _write_family_plan(
787
- paths,
788
- "feature",
789
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
790
- )
791
- family, status_path, _before_status, _old_checkout = _write_preserve_runtime_state(
792
- paths, "feature", "F-001", "dev/F-001-worktree"
793
- )
794
- runtime = worktree_runtime_context(
795
- BranchContext("main", "dev/F-001-worktree", paths.project_root),
796
- WorktreePolicy(True, True, True, tmp_path / "worktrees"),
797
- )
798
- assert ensure_linked_worktree(runtime).ok
799
- worktree_checkout = TaskCheckout.active(
800
- "feature",
801
- "F-001",
802
- "dev/F-001-worktree",
803
- "main",
804
- checkout_mode=CHECKOUT_MODE_WORKTREE,
805
- worktree_path=str(runtime.worktree_path),
806
- )
807
- persist_task_checkout(family.state_dir, worktree_checkout)
808
- artifact = runtime.worktree_path / ".prizmkit" / "specs" / "001-root"
809
- artifact.mkdir(parents=True)
810
- marker = artifact / "partial.md"
811
- marker.write_text("worktree WIP\n", encoding="utf-8")
812
- registrations_before = registered_worktrees(paths.project_root)
813
-
814
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
815
-
816
- assert result.exit_code == 0, result.render()
817
- assert load_task_checkout(family.state_dir, "feature", "F-001") == worktree_checkout
818
- assert runtime.worktree_path.is_dir()
819
- assert marker.read_text(encoding="utf-8") == "worktree WIP\n"
820
- assert registered_worktrees(paths.project_root) == registrations_before
821
- assert json.loads(status_path.read_text(encoding="utf-8"))["continuation_pending"] is True
822
- assert json.loads(plan.read_text(encoding="utf-8"))["features"][0]["status"] == "pending"
823
-
824
-
825
- def test_replacement_worktree_skips_registered_path_collision_even_when_path_is_absent(monkeypatch, tmp_path):
826
- from prizmkit_runtime import reset_preserve
827
- from prizmkit_runtime.gitops import (
828
- BranchContext,
829
- RegisteredWorktree,
830
- WorktreePolicy,
831
- worktree_runtime_context,
832
- )
833
- from prizmkit_runtime.runner_models import family_for
834
- from prizmkit_runtime.task_checkout import CHECKOUT_MODE_WORKTREE, TaskCheckout
835
-
836
- paths = _make_paths(tmp_path)
837
- _init_preserve_runtime_repo(paths)
838
- family = family_for("feature", paths)
839
- worktree_root = tmp_path / "worktrees"
840
- old_runtime = worktree_runtime_context(
841
- BranchContext("main", "dev/F-001-old", paths.project_root),
842
- WorktreePolicy(True, True, True, worktree_root),
843
- )
844
- checkout = TaskCheckout.active(
845
- "feature",
846
- "F-001",
847
- "dev/F-001-old",
848
- "main",
849
- checkout_mode=CHECKOUT_MODE_WORKTREE,
850
- worktree_path=str(old_runtime.worktree_path),
851
- )
852
- item = reset_preserve.PreservePlanItem(
853
- "F-001", "Root", "001-root", "failed", (), 0
854
- )
855
- monkeypatch.setattr(reset_preserve.time, "strftime", lambda *_args: "20260725120000")
856
- colliding_runtime = worktree_runtime_context(
857
- BranchContext(
858
- "main",
859
- "dev/F-001-resume-20260725120000",
860
- paths.project_root,
861
- ),
862
- WorktreePolicy(True, True, True, worktree_root),
863
- )
864
- registration = RegisteredWorktree(
865
- colliding_runtime.worktree_path,
866
- "different/branch-with-same-normalized-path",
867
- )
868
-
869
- branch, runtime = reset_preserve._replacement_identity(
870
- family,
871
- item,
872
- checkout,
873
- paths.project_root,
874
- (registration,),
875
- old_runtime,
876
- )
877
-
878
- assert branch == "dev/F-001-resume-20260725120000-1"
879
- assert runtime is not None
880
- assert runtime.worktree_path != colliding_runtime.worktree_path
881
-
882
-
883
- def test_preserve_runtime_missing_worktree_copies_reference_artifacts_without_deleting_old_site(tmp_path):
884
- from prizmkit_runtime.gitops import BranchContext, WorktreePolicy, worktree_runtime_context
885
- from prizmkit_runtime.reset import run_reset_command
886
- from prizmkit_runtime.runner_models import family_for
887
- from prizmkit_runtime.task_checkout import (
888
- CHECKOUT_MODE_WORKTREE,
889
- TaskCheckout,
890
- load_task_checkout,
891
- persist_task_checkout,
892
- )
893
-
894
- paths = _make_paths(tmp_path)
895
- _init_preserve_runtime_repo(paths)
896
- plan = _write_family_plan(
897
- paths,
898
- "feature",
899
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
900
- )
901
- family, status_path, before_status, _branch_checkout = _write_preserve_runtime_state(
902
- paths, "feature", "F-001", "dev/F-001-deleted-worktree"
903
- )
904
- old_runtime = worktree_runtime_context(
905
- BranchContext("main", "dev/F-001-deleted-worktree", paths.project_root),
906
- WorktreePolicy(True, True, True, tmp_path / "worktrees"),
907
- )
908
- old_runtime.worktree_path.mkdir(parents=True)
909
- old_checkout = TaskCheckout.active(
910
- "feature",
911
- "F-001",
912
- "dev/F-001-deleted-worktree",
913
- "main",
914
- checkout_mode=CHECKOUT_MODE_WORKTREE,
915
- worktree_path=str(old_runtime.worktree_path),
916
- )
917
- persist_task_checkout(family.state_dir, old_checkout)
918
- old_artifact = old_runtime.worktree_path / ".prizmkit" / "specs" / "001-root"
919
- old_checkpoint = _write_semantic_completion_checkpoint(old_runtime.worktree_path, old_artifact)
920
- _add_completed_plan_step(old_checkpoint)
921
- old_marker = old_artifact / "partial.md"
922
- old_marker.write_text("old reference\n", encoding="utf-8")
923
- external_reference = tmp_path / "external-reference.txt"
924
- external_reference.write_text("do not copy through symlink\n", encoding="utf-8")
925
- old_link = old_artifact / "external-reference"
926
- old_link.symlink_to(external_reference)
927
- old_checkpoint_before = old_checkpoint.read_bytes()
928
-
929
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
930
-
931
- assert result.exit_code == 0, result.render()
932
- checkout = load_task_checkout(family.state_dir, "feature", "F-001")
933
- assert checkout is not None and checkout.is_active and checkout.uses_worktree
934
- assert checkout.active_dev_branch.startswith("dev/F-001-resume-")
935
- assert Path(checkout.worktree_path) != old_runtime.worktree_path
936
- assert Path(checkout.worktree_path).is_dir()
937
- assert old_runtime.worktree_path.is_dir()
938
- assert old_checkpoint.read_bytes() == old_checkpoint_before
939
- assert old_marker.read_text(encoding="utf-8") == "old reference\n"
940
- copied_artifact = Path(checkout.worktree_path) / ".prizmkit" / "specs" / "001-root"
941
- assert (copied_artifact / "partial.md").read_text(encoding="utf-8") == "old reference\n"
942
- copied_link = copied_artifact / "external-reference"
943
- assert copied_link.is_symlink()
944
- assert copied_link.resolve() == external_reference.resolve()
945
- copied_checkpoint = json.loads((copied_artifact / "workflow-checkpoint.json").read_text(encoding="utf-8"))
946
- assert copied_checkpoint["steps"][0]["status"] == "completed"
947
- assert all(step["status"] == "pending" for step in copied_checkpoint["steps"][1:])
948
- expected_status = dict(before_status)
949
- expected_status.update(
950
- retry_count=0,
951
- infra_error_count=0,
952
- continuation_pending=True,
953
- active_dev_branch=checkout.active_dev_branch,
954
- base_branch="main",
955
- )
956
- assert json.loads(status_path.read_text(encoding="utf-8")) == expected_status
957
- assert json.loads(plan.read_text(encoding="utf-8"))["features"][0]["status"] == "pending"