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,1208 +0,0 @@
1
- """Focused tests for explicit reset modes and causal state recovery."""
2
-
3
- from __future__ import annotations
4
-
5
- import json
6
- import subprocess
7
- import sys
8
- from pathlib import Path
9
-
10
- import pytest
11
-
12
- from utils import causal_reset_selection, orphaned_auto_skipped_ids
13
-
14
- REPO_ROOT = Path(__file__).resolve().parents[2]
15
- PIPELINE_ROOT = REPO_ROOT / "dev-pipeline"
16
-
17
-
18
- def _item(item_id, status="pending", dependencies=None, **extra):
19
- return {
20
- "id": item_id,
21
- "title": item_id,
22
- "status": status,
23
- "dependencies": list(dependencies or []),
24
- **extra,
25
- }
26
-
27
-
28
- @pytest.mark.parametrize(
29
- ("prefix", "root_statuses"),
30
- (
31
- ("F-", {"failed", "skipped"}),
32
- ("B-", {"failed", "skipped", "needs_info"}),
33
- ("R-", {"failed", "skipped"}),
34
- ),
35
- )
36
- def test_causal_selection_single_root_recovers_only_complete_chain(prefix, root_statuses):
37
- items = [
38
- _item(f"{prefix}001", "failed"),
39
- _item(f"{prefix}002", "auto_skipped", [f"{prefix}001"]),
40
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}002"]),
41
- _item(f"{prefix}004", "completed", [f"{prefix}001"], marker="preserve"),
42
- _item(f"{prefix}005", "failed"),
43
- _item(f"{prefix}006", "auto_skipped", [f"{prefix}005"]),
44
- ]
45
-
46
- selected = causal_reset_selection(
47
- items,
48
- selected_id=f"{prefix}001",
49
- blocking_root_statuses=root_statuses,
50
- item_label="Task",
51
- )
52
-
53
- assert selected == (f"{prefix}001", f"{prefix}002", f"{prefix}003")
54
- assert items[3]["status"] == "completed"
55
- assert items[3]["marker"] == "preserve"
56
-
57
-
58
- @pytest.mark.parametrize("prefix", ("F-", "B-", "R-"))
59
- def test_causal_selection_keeps_multi_root_descendant_blocked(prefix):
60
- root_statuses = {"failed", "skipped", "needs_info"} if prefix == "B-" else {"failed", "skipped"}
61
- items = [
62
- _item(f"{prefix}001", "failed"),
63
- _item(f"{prefix}002", "skipped"),
64
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}001"]),
65
- _item(f"{prefix}004", "auto_skipped", [f"{prefix}003", f"{prefix}002"]),
66
- _item(f"{prefix}005", "auto_skipped", [f"{prefix}002"]),
67
- ]
68
-
69
- selected = causal_reset_selection(
70
- items,
71
- selected_id=f"{prefix}001",
72
- blocking_root_statuses=root_statuses,
73
- )
74
-
75
- assert selected == (f"{prefix}001", f"{prefix}003")
76
-
77
-
78
- def test_causal_selection_does_not_cross_an_orphan_auto_skipped_blocker():
79
- items = [
80
- _item("F-001", "failed"),
81
- _item("F-002", "auto_skipped"),
82
- _item("F-003", "auto_skipped", ["F-001", "F-002"]),
83
- ]
84
-
85
- selected = causal_reset_selection(
86
- items,
87
- selected_id="F-001",
88
- blocking_root_statuses={"failed", "skipped"},
89
- )
90
-
91
- assert selected == ("F-001",)
92
-
93
-
94
- @pytest.mark.parametrize("prefix", ("F-", "B-", "R-"))
95
- def test_selecting_auto_skipped_leaf_includes_every_required_root(prefix):
96
- root_statuses = {"failed", "skipped", "needs_info"} if prefix == "B-" else {"failed", "skipped"}
97
- second_root_status = "needs_info" if prefix == "B-" else "skipped"
98
- items = [
99
- _item(f"{prefix}001", "failed"),
100
- _item(f"{prefix}002", second_root_status),
101
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}001"]),
102
- _item(f"{prefix}004", "auto_skipped", [f"{prefix}002"]),
103
- _item(f"{prefix}005", "auto_skipped", [f"{prefix}003", f"{prefix}004"]),
104
- _item(f"{prefix}006", "completed"),
105
- ]
106
-
107
- selected = causal_reset_selection(
108
- items,
109
- selected_id=f"{prefix}005",
110
- blocking_root_statuses=root_statuses,
111
- )
112
-
113
- assert selected == (
114
- f"{prefix}001",
115
- f"{prefix}002",
116
- f"{prefix}003",
117
- f"{prefix}004",
118
- f"{prefix}005",
119
- )
120
-
121
-
122
- @pytest.mark.parametrize(
123
- ("prefix", "root_statuses", "root_status"),
124
- (
125
- ("F-", {"failed", "skipped"}, "skipped"),
126
- ("B-", {"failed", "skipped", "needs_info"}, "needs_info"),
127
- ("R-", {"failed", "skipped"}, "skipped"),
128
- ),
129
- )
130
- def test_causal_selection_all_recovers_every_supported_chain(prefix, root_statuses, root_status):
131
- items = [
132
- _item(f"{prefix}001", "failed"),
133
- _item(f"{prefix}002", root_status),
134
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}001", f"{prefix}002"]),
135
- _item(f"{prefix}004", "completed"),
136
- _item(f"{prefix}005", "pending"),
137
- ]
138
-
139
- selected = causal_reset_selection(
140
- items,
141
- selected_id=None,
142
- blocking_root_statuses=root_statuses,
143
- )
144
-
145
- assert selected == (f"{prefix}001", f"{prefix}002", f"{prefix}003")
146
-
147
-
148
- def test_causal_selection_rejects_missing_and_invalid_targets():
149
- items = [
150
- _item("F-001", "failed"),
151
- _item("F-002", "pending"),
152
- _item("F-003", "auto_skipped"),
153
- ]
154
-
155
- with pytest.raises(ValueError, match="not found"):
156
- causal_reset_selection(items, selected_id="F-999", blocking_root_statuses={"failed", "skipped"})
157
- with pytest.raises(ValueError, match="not recoverable"):
158
- causal_reset_selection(items, selected_id="F-002", blocking_root_statuses={"failed", "skipped"})
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",)
219
-
220
-
221
- def test_causal_selection_rejects_invalid_dependency_graph_before_selection():
222
- items = [
223
- _item("F-001", "failed", ["F-002"]),
224
- _item("F-002", "auto_skipped", ["F-001"]),
225
- ]
226
-
227
- with pytest.raises(ValueError, match="Dependency cycle"):
228
- causal_reset_selection(items, selected_id="F-001", blocking_root_statuses={"failed", "skipped"})
229
-
230
-
231
- FAMILY_CONTRACTS = {
232
- "feature": {
233
- "prefix": "F-",
234
- "list_key": "features",
235
- "list_arg": "--feature-list",
236
- "id_arg": "--feature-id",
237
- "schema": "dev-pipeline-feature-list-v1",
238
- "script": "update-feature-status.py",
239
- "branch_prefix": "dev",
240
- "artifact_root": "specs",
241
- },
242
- "bugfix": {
243
- "prefix": "B-",
244
- "list_key": "bugs",
245
- "list_arg": "--bug-list",
246
- "id_arg": "--bug-id",
247
- "schema": "dev-pipeline-bug-fix-list-v1",
248
- "script": "update-bug-status.py",
249
- "branch_prefix": "bugfix",
250
- "artifact_root": "bugfix",
251
- },
252
- "refactor": {
253
- "prefix": "R-",
254
- "list_key": "refactors",
255
- "list_arg": "--refactor-list",
256
- "id_arg": "--refactor-id",
257
- "schema": "dev-pipeline-refactor-list-v1",
258
- "script": "update-refactor-status.py",
259
- "branch_prefix": "refactor",
260
- "artifact_root": "refactor",
261
- },
262
- }
263
-
264
-
265
- def _make_paths(tmp_path):
266
- from prizmkit_runtime.paths import resolve_runtime_paths
267
-
268
- project_root = tmp_path / "project"
269
- (project_root / ".prizmkit" / "plans").mkdir(parents=True)
270
- return resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=project_root)
271
-
272
-
273
- def _family_and_plan(paths, kind, items):
274
- from prizmkit_runtime.runner_models import family_for
275
-
276
- family = family_for(kind, paths)
277
- contract = FAMILY_CONTRACTS[kind]
278
- family.plan_path.write_text(
279
- json.dumps(
280
- {
281
- "$schema": contract["schema"],
282
- "project_name": "Reset Test",
283
- contract["list_key"]: items,
284
- },
285
- indent=2,
286
- )
287
- + "\n",
288
- encoding="utf-8",
289
- )
290
- return family, family.plan_path
291
-
292
-
293
- def _write_runtime_status(family, item_id, **overrides):
294
- status_dir = family.state_dir / item_id
295
- status_dir.mkdir(parents=True, exist_ok=True)
296
- status = {
297
- f"{family.kind if family.kind != 'bugfix' else 'bug'}_id": item_id,
298
- "retry_count": 4,
299
- "infra_error_count": 3,
300
- "last_infra_error_session_id": "old-session",
301
- "sessions": ["old-session"],
302
- "last_session_id": "old-session",
303
- "last_failed_session_id": "old-session",
304
- "resume_from_phase": 4,
305
- "continuation_pending": True,
306
- "continuation_reason": "context_overflow",
307
- "continuation_count": 2,
308
- "context_overflow_count": 2,
309
- "previous_session_id": "old-session",
310
- "custom_diagnostic": {"keep": True},
311
- **overrides,
312
- }
313
- status_path = status_dir / "status.json"
314
- status_path.write_text(json.dumps(status, indent=2) + "\n", encoding="utf-8")
315
- return status_path, status
316
-
317
-
318
- def _tree_snapshot(root):
319
- if not root.exists():
320
- return {}
321
- return {
322
- str(path.relative_to(root)): path.read_bytes()
323
- for path in sorted(root.rglob("*"))
324
- if path.is_file()
325
- }
326
-
327
-
328
- def _git(project_root, *args):
329
- return subprocess.run(
330
- ["git", *args],
331
- cwd=project_root,
332
- text=True,
333
- stdout=subprocess.PIPE,
334
- stderr=subprocess.PIPE,
335
- check=True,
336
- ).stdout.strip()
337
-
338
-
339
- def _init_git_repository(project_root):
340
- subprocess.run(
341
- ["git", "init", "-b", "main"],
342
- cwd=project_root,
343
- stdout=subprocess.DEVNULL,
344
- check=True,
345
- )
346
- _git(project_root, "config", "user.email", "reset@example.com")
347
- _git(project_root, "config", "user.name", "Reset Test")
348
- source = project_root / "source.txt"
349
- source.write_text("committed\n", encoding="utf-8")
350
- _git(project_root, "add", "source.txt")
351
- _git(project_root, "commit", "-m", "base")
352
- source.write_text("committed\nlocal work\n", encoding="utf-8")
353
- return source
354
-
355
-
356
- @pytest.mark.parametrize("kind", ("feature", "bugfix", "refactor"))
357
- def test_state_only_resets_exact_causal_records_and_preserves_checkout_git_and_artifacts(tmp_path, kind):
358
- from prizmkit_runtime.reset import run_reset_command
359
- from prizmkit_runtime.task_checkout import (
360
- CHECKOUT_MODE_WORKTREE,
361
- TaskCheckout,
362
- persist_task_checkout,
363
- )
364
-
365
- paths = _make_paths(tmp_path / kind)
366
- contract = FAMILY_CONTRACTS[kind]
367
- prefix = contract["prefix"]
368
- root_id = f"{prefix}001"
369
- child_id = f"{prefix}002"
370
- other_root_id = f"{prefix}003"
371
- shared_id = f"{prefix}004"
372
- completed_id = f"{prefix}005"
373
- unrelated_child_id = f"{prefix}006"
374
- items = [
375
- _item(root_id, "failed", marker="root-field"),
376
- _item(child_id, "auto_skipped", [root_id], marker="child-field"),
377
- _item(other_root_id, "failed", marker="other-root-field"),
378
- _item(shared_id, "auto_skipped", [child_id, other_root_id], marker="shared-field"),
379
- _item(completed_id, "completed", marker="completed-field"),
380
- _item(unrelated_child_id, "auto_skipped", [other_root_id], marker="unrelated-field"),
381
- ]
382
- family, plan_path = _family_and_plan(paths, kind, items)
383
- source_path = _init_git_repository(paths.project_root)
384
- branch_name = f"{contract['branch_prefix']}/{root_id}-preserved"
385
- _git(paths.project_root, "branch", branch_name, "main")
386
-
387
- worktree_path = paths.project_root / ".task-worktrees" / root_id
388
- worktree_path.mkdir(parents=True)
389
- worktree_marker = worktree_path / "keep.txt"
390
- worktree_marker.write_text("worktree remains\n", encoding="utf-8")
391
- checkout = TaskCheckout.active(
392
- kind,
393
- root_id,
394
- branch_name,
395
- "main",
396
- checkout_mode=CHECKOUT_MODE_WORKTREE,
397
- worktree_path=str(worktree_path),
398
- )
399
- persist_task_checkout(family.state_dir, checkout)
400
- checkout_path = family.state_dir / root_id / "checkout.json"
401
-
402
- root_status_path, _root_before = _write_runtime_status(
403
- family,
404
- root_id,
405
- active_dev_branch=branch_name,
406
- base_branch="main",
407
- )
408
- child_status_path, _child_before = _write_runtime_status(family, child_id)
409
- other_status_path, _other_before = _write_runtime_status(family, other_root_id)
410
- completed_status_path, _completed_before = _write_runtime_status(family, completed_id)
411
-
412
- session_log = family.state_dir / root_id / "sessions" / "old-session" / "logs" / "session.log"
413
- session_log.parent.mkdir(parents=True)
414
- session_log.write_text("session history\n", encoding="utf-8")
415
- artifact_name = "001-root" if kind == "feature" else root_id
416
- artifact_dir = paths.project_root / ".prizmkit" / contract["artifact_root"] / artifact_name
417
- artifact_dir.mkdir(parents=True)
418
- checkpoint = artifact_dir / "workflow-checkpoint.json"
419
- checkpoint.write_text('{"sentinel":"checkpoint"}\n', encoding="utf-8")
420
- artifact = artifact_dir / "spec.md"
421
- artifact.write_text("artifact remains\n", encoding="utf-8")
422
-
423
- protected_bytes = {
424
- "checkout": checkout_path.read_bytes(),
425
- "session": session_log.read_bytes(),
426
- "checkpoint": checkpoint.read_bytes(),
427
- "artifact": artifact.read_bytes(),
428
- "worktree": worktree_marker.read_bytes(),
429
- "other_status": other_status_path.read_bytes(),
430
- "completed_status": completed_status_path.read_bytes(),
431
- "source": source_path.read_bytes(),
432
- }
433
- branch_refs_before = _git(paths.project_root, "show-ref", "--heads")
434
- branch_before = _git(paths.project_root, "branch", "--show-current")
435
- source_diff_before = _git(paths.project_root, "diff", "--", "source.txt")
436
-
437
- result = run_reset_command(
438
- kind,
439
- (root_id, "--state-only", str(plan_path)),
440
- paths,
441
- )
442
-
443
- assert result.exit_code == 0, result.render()
444
- payload = json.loads(result.render())
445
- assert payload["action"] == "reset_state"
446
- assert payload["reset_count"] == 2
447
- updated = json.loads(plan_path.read_text(encoding="utf-8"))[contract["list_key"]]
448
- statuses = {item["id"]: item["status"] for item in updated}
449
- assert statuses == {
450
- root_id: "pending",
451
- child_id: "pending",
452
- other_root_id: "failed",
453
- shared_id: "auto_skipped",
454
- completed_id: "completed",
455
- unrelated_child_id: "auto_skipped",
456
- }
457
- assert {item["id"]: item["marker"] for item in updated} == {
458
- root_id: "root-field",
459
- child_id: "child-field",
460
- other_root_id: "other-root-field",
461
- shared_id: "shared-field",
462
- completed_id: "completed-field",
463
- unrelated_child_id: "unrelated-field",
464
- }
465
-
466
- for selected_status_path in (root_status_path, child_status_path):
467
- selected_status = json.loads(selected_status_path.read_text(encoding="utf-8"))
468
- assert selected_status["retry_count"] == 0
469
- assert selected_status["infra_error_count"] == 0
470
- assert selected_status["last_infra_error_session_id"] is None
471
- assert selected_status["sessions"] == []
472
- assert selected_status["last_session_id"] is None
473
- assert selected_status["last_failed_session_id"] is None
474
- assert selected_status["resume_from_phase"] is None
475
- assert selected_status["custom_diagnostic"] == {"keep": True}
476
- for continuation_key in (
477
- "continuation_pending",
478
- "continuation_reason",
479
- "continuation_count",
480
- "context_overflow_count",
481
- "previous_session_id",
482
- ):
483
- assert continuation_key not in selected_status
484
-
485
- root_status = json.loads(root_status_path.read_text(encoding="utf-8"))
486
- assert root_status["active_dev_branch"] == branch_name
487
- assert root_status["base_branch"] == "main"
488
- assert checkout_path.read_bytes() == protected_bytes["checkout"]
489
- assert session_log.read_bytes() == protected_bytes["session"]
490
- assert checkpoint.read_bytes() == protected_bytes["checkpoint"]
491
- assert artifact.read_bytes() == protected_bytes["artifact"]
492
- assert worktree_marker.read_bytes() == protected_bytes["worktree"]
493
- assert other_status_path.read_bytes() == protected_bytes["other_status"]
494
- assert completed_status_path.read_bytes() == protected_bytes["completed_status"]
495
- assert source_path.read_bytes() == protected_bytes["source"]
496
- assert _git(paths.project_root, "show-ref", "--heads") == branch_refs_before
497
- assert _git(paths.project_root, "branch", "--show-current") == branch_before
498
- assert _git(paths.project_root, "diff", "--", "source.txt") == source_diff_before
499
- assert not (family.state_dir / "pipeline.json").exists()
500
-
501
-
502
- @pytest.mark.parametrize(
503
- ("kind", "second_root_status"),
504
- (("feature", "skipped"), ("bugfix", "needs_info"), ("refactor", "skipped")),
505
- )
506
- def test_state_only_all_recovers_all_supported_chains_without_pipeline_state(tmp_path, kind, second_root_status):
507
- from prizmkit_runtime.reset import run_reset_command
508
-
509
- paths = _make_paths(tmp_path / kind)
510
- contract = FAMILY_CONTRACTS[kind]
511
- prefix = contract["prefix"]
512
- items = [
513
- _item(f"{prefix}001", "failed"),
514
- _item(f"{prefix}002", second_root_status),
515
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}001", f"{prefix}002"]),
516
- _item(f"{prefix}004", "completed", marker="done"),
517
- _item(f"{prefix}005", "pending", marker="unrelated"),
518
- ]
519
- family, plan_path = _family_and_plan(paths, kind, items)
520
- completed_status_path, _ = _write_runtime_status(family, f"{prefix}004")
521
- completed_before = completed_status_path.read_bytes()
522
-
523
- result = run_reset_command(
524
- kind,
525
- ("--state-only", "--all", str(plan_path)),
526
- paths,
527
- )
528
-
529
- assert result.exit_code == 0, result.render()
530
- payload = json.loads(result.render())
531
- assert payload["action"] == "reset_state"
532
- assert payload["reset_count"] == 3
533
- updated = json.loads(plan_path.read_text(encoding="utf-8"))[contract["list_key"]]
534
- assert [item["status"] for item in updated] == [
535
- "pending",
536
- "pending",
537
- "pending",
538
- "completed",
539
- "pending",
540
- ]
541
- assert completed_status_path.read_bytes() == completed_before
542
- assert not (family.state_dir / "pipeline.json").exists()
543
-
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
-
624
- @pytest.mark.parametrize("kind", ("feature", "bugfix", "refactor"))
625
- def test_reset_without_mode_fails_before_any_mutation(tmp_path, kind):
626
- from prizmkit_runtime.reset import run_reset_command
627
-
628
- paths = _make_paths(tmp_path / kind)
629
- prefix = FAMILY_CONTRACTS[kind]["prefix"]
630
- family, plan_path = _family_and_plan(paths, kind, [_item(f"{prefix}001", "failed")])
631
- marker = family.state_dir / "sentinel.bin"
632
- marker.parent.mkdir(parents=True)
633
- marker.write_bytes(b"runtime-sentinel")
634
- before_plan = plan_path.read_bytes()
635
- before_state = _tree_snapshot(family.state_dir)
636
-
637
- result = run_reset_command(kind, (f"{prefix}001", str(plan_path)), paths)
638
-
639
- assert result.exit_code != 0
640
- assert "Exactly one reset mode is required" in result.render()
641
- assert "--state-only" in result.render()
642
- assert plan_path.read_bytes() == before_plan
643
- assert _tree_snapshot(family.state_dir) == before_state
644
-
645
-
646
- @pytest.mark.parametrize(
647
- "mode_pair",
648
- (
649
- ("--state-only", "--fresh-checkout"),
650
- ("--state-only", "--clean"),
651
- ("--state-only", "--preserve-runtime"),
652
- ("--fresh-checkout", "--clean"),
653
- ("--fresh-checkout", "--preserve-runtime"),
654
- ("--clean", "--preserve-runtime"),
655
- ),
656
- )
657
- def test_conflicting_reset_modes_fail_before_mutation(tmp_path, mode_pair):
658
- from prizmkit_runtime.reset import run_reset_command
659
-
660
- paths = _make_paths(tmp_path)
661
- family, plan_path = _family_and_plan(paths, "feature", [_item("F-001", "failed")])
662
- marker = family.state_dir / "sentinel.bin"
663
- marker.parent.mkdir(parents=True)
664
- marker.write_bytes(b"runtime-sentinel")
665
- before_plan = plan_path.read_bytes()
666
- before_state = _tree_snapshot(family.state_dir)
667
-
668
- result = run_reset_command(
669
- "feature",
670
- ("F-001", *mode_pair, "--failed", str(plan_path)),
671
- paths,
672
- )
673
-
674
- assert result.exit_code != 0
675
- assert "Exactly one reset mode is required" in result.render()
676
- assert plan_path.read_bytes() == before_plan
677
- assert _tree_snapshot(family.state_dir) == before_state
678
-
679
-
680
- @pytest.mark.parametrize(
681
- ("args", "message"),
682
- (
683
- (("F-001", "--standard"), "Unsupported reset arguments"),
684
- (("--state-only",), "requires exactly one item ID or explicit --all"),
685
- (("F-001", "--state-only", "--all"), "requires exactly one item ID or explicit --all"),
686
- (("F-001:F-002", "--state-only"), "ranges and status filters are unsupported"),
687
- (("--failed", "--state-only"), "ranges and status filters are unsupported"),
688
- (("--fresh-checkout",), "requires exactly one item ID, range, or supported status filter"),
689
- (("--fresh-checkout", "--all"), "--all is supported only with --state-only"),
690
- (("--clean",), "requires exactly one item ID, range, or supported status filter"),
691
- (("--clean", "--all"), "--all is supported only with --state-only"),
692
- (("--preserve-runtime",), "requires --failed"),
693
- (("F-001", "--failed", "--preserve-runtime"), "cannot target an ID, range, or --all"),
694
- (("--failed", "--preserve-runtime", "--all"), "cannot target an ID, range, or --all"),
695
- ),
696
- )
697
- def test_reset_selector_matrix_rejects_unsupported_forms_before_mutation(tmp_path, args, message):
698
- from prizmkit_runtime.reset import run_reset_command
699
-
700
- paths = _make_paths(tmp_path)
701
- family, plan_path = _family_and_plan(
702
- paths,
703
- "feature",
704
- [_item("F-001", "failed"), _item("F-002", "auto_skipped", ["F-001"])],
705
- )
706
- marker = family.state_dir / "sentinel.bin"
707
- marker.parent.mkdir(parents=True)
708
- marker.write_bytes(b"runtime-sentinel")
709
- before_plan = plan_path.read_bytes()
710
- before_state = _tree_snapshot(family.state_dir)
711
-
712
- result = run_reset_command("feature", (*args, str(plan_path)), paths)
713
-
714
- assert result.exit_code != 0
715
- assert message in result.render()
716
- assert plan_path.read_bytes() == before_plan
717
- assert _tree_snapshot(family.state_dir) == before_state
718
-
719
-
720
- @pytest.mark.parametrize(
721
- ("items", "args", "message"),
722
- (
723
- ([_item("F-001", "failed")], ("F-999", "--state-only"), "not found"),
724
- ([_item("F-001", "pending")], ("F-001", "--state-only"), "not recoverable"),
725
- ([_item("F-001", "completed")], ("--state-only", "--all"), "No recoverable blocking roots"),
726
- (
727
- [_item("F-001", "failed", ["F-002"]), _item("F-002", "auto_skipped", ["F-001"])],
728
- ("F-001", "--state-only"),
729
- "Dependency cycle",
730
- ),
731
- ),
732
- )
733
- def test_state_only_invalid_target_or_graph_is_fail_closed(tmp_path, items, args, message):
734
- from prizmkit_runtime.reset import run_reset_command
735
-
736
- paths = _make_paths(tmp_path)
737
- family, plan_path = _family_and_plan(paths, "feature", items)
738
- marker = family.state_dir / "sentinel.bin"
739
- marker.parent.mkdir(parents=True)
740
- marker.write_bytes(b"runtime-sentinel")
741
- before_plan = plan_path.read_bytes()
742
- before_state = _tree_snapshot(family.state_dir)
743
-
744
- result = run_reset_command("feature", (*args, str(plan_path)), paths)
745
-
746
- assert result.exit_code != 0
747
- assert message in result.render()
748
- assert plan_path.read_bytes() == before_plan
749
- assert _tree_snapshot(family.state_dir) == before_state
750
-
751
-
752
- @pytest.mark.parametrize("kind", ("feature", "bugfix", "refactor"))
753
- @pytest.mark.parametrize("mode", ("--fresh-checkout", "--clean"))
754
- @pytest.mark.parametrize(
755
- ("selector", "expected_numbers"),
756
- (
757
- (("X-003",), (3,)),
758
- (("X-001:X-002",), (1, 2)),
759
- (("--failed",), (1,)),
760
- ),
761
- )
762
- def test_fresh_checkout_and_clean_keep_id_range_and_filter_selection(
763
- monkeypatch,
764
- tmp_path,
765
- kind,
766
- mode,
767
- selector,
768
- expected_numbers,
769
- ):
770
- from prizmkit_runtime import reset as reset_runtime
771
- from prizmkit_runtime.reset import run_reset_command
772
-
773
- paths = _make_paths(tmp_path)
774
- prefix = FAMILY_CONTRACTS[kind]["prefix"]
775
- normalized_selector = tuple(value.replace("X-", prefix) for value in selector)
776
- family, plan_path = _family_and_plan(
777
- paths,
778
- kind,
779
- [
780
- _item(f"{prefix}001", "failed"),
781
- _item(f"{prefix}002", "auto_skipped", [f"{prefix}001"]),
782
- _item(f"{prefix}003", "pending"),
783
- ],
784
- )
785
- family.state_dir.mkdir(parents=True, exist_ok=True)
786
- (family.state_dir / "pipeline.json").write_text("{}\n", encoding="utf-8")
787
- captured = []
788
-
789
- def fake_reset_one(received_family, item, options, project_root, return_branch, lines):
790
- captured.append((received_family.kind, item.item_id, options.fresh_checkout, options.clean))
791
- return True
792
-
793
- monkeypatch.setattr(reset_runtime, "_reset_one", fake_reset_one)
794
- monkeypatch.setattr(reset_runtime, "default_branch", lambda _root: "main")
795
-
796
- result = run_reset_command(
797
- kind,
798
- (*normalized_selector, mode, str(plan_path)),
799
- paths,
800
- )
801
-
802
- assert result.exit_code == 0, result.render()
803
- expected_ids = [f"{prefix}{number:03d}" for number in expected_numbers]
804
- assert [entry[1] for entry in captured] == expected_ids
805
- assert all(entry[2] is (mode == "--fresh-checkout") for entry in captured)
806
- assert all(entry[3] is (mode == "--clean") for entry in captured)
807
-
808
-
809
- @pytest.mark.parametrize("kind", ("feature", "bugfix", "refactor"))
810
- def test_clean_uses_item_state_without_pipeline_state_but_fresh_checkout_still_requires_it(
811
- monkeypatch,
812
- tmp_path,
813
- kind,
814
- ):
815
- from prizmkit_runtime import reset as reset_runtime
816
- from prizmkit_runtime.reset import run_reset_command
817
- from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
818
-
819
- paths = _make_paths(tmp_path / kind)
820
- contract = FAMILY_CONTRACTS[kind]
821
- item_id = f"{contract['prefix']}001"
822
- family, plan_path = _family_and_plan(paths, kind, [_item(item_id, "in_progress")])
823
- status_path, _ = _write_runtime_status(
824
- family,
825
- item_id,
826
- active_dev_branch=f"{contract['branch_prefix']}/{item_id}-clean",
827
- base_branch="main",
828
- )
829
- checkout_path = persist_task_checkout(
830
- family.state_dir,
831
- TaskCheckout.active(
832
- family.task_type,
833
- item_id,
834
- f"{contract['branch_prefix']}/{item_id}-clean",
835
- "main",
836
- ),
837
- )
838
- captured = []
839
-
840
- def fake_reset_one(received_family, item, options, project_root, return_branch, lines):
841
- captured.append((received_family.kind, item.item_id, options.clean))
842
- return True
843
-
844
- monkeypatch.setattr(reset_runtime, "_reset_one", fake_reset_one)
845
- monkeypatch.setattr(reset_runtime, "default_branch", lambda _root: "main")
846
-
847
- fresh_result = run_reset_command(
848
- kind,
849
- (item_id, "--fresh-checkout", str(plan_path)),
850
- paths,
851
- )
852
-
853
- assert fresh_result.exit_code != 0
854
- assert "No pipeline state found" in fresh_result.render()
855
- assert captured == []
856
- assert status_path.is_file()
857
- assert checkout_path.is_file()
858
- assert not (family.state_dir / "pipeline.json").exists()
859
-
860
- clean_result = run_reset_command(
861
- kind,
862
- (item_id, "--clean", str(plan_path)),
863
- paths,
864
- )
865
-
866
- assert clean_result.exit_code == 0, clean_result.render()
867
- assert captured == [(kind, item_id, True)]
868
-
869
-
870
- def test_feature_clean_removes_stale_workflow_fields_and_preserves_diagnostics(tmp_path):
871
- paths = _make_paths(tmp_path)
872
- family, plan_path = _family_and_plan(
873
- paths,
874
- "feature",
875
- [_item("F-001", "failed")],
876
- )
877
- status_path, _ = _write_runtime_status(
878
- family,
879
- "F-001",
880
- repair_scope="production",
881
- repair_round=2,
882
- blocked_reason="test_blocked",
883
- terminal_status="WORKFLOW_BLOCKED",
884
- )
885
- session_dir = family.state_dir / "F-001" / "sessions" / "old-session"
886
- session_dir.mkdir(parents=True)
887
- (session_dir / "session.log").write_text("old session\n", encoding="utf-8")
888
- feature_slug = "001-f-001"
889
- specs_dir = paths.project_root / ".prizmkit" / "specs" / feature_slug
890
- specs_dir.mkdir(parents=True)
891
- (specs_dir / "spec.md").write_text("old spec\n", encoding="utf-8")
892
- (specs_dir / "continuation-summary.md").write_text(
893
- "old continuation\n",
894
- encoding="utf-8",
895
- )
896
-
897
- result = subprocess.run(
898
- [
899
- sys.executable,
900
- str(PIPELINE_ROOT / "scripts" / "update-feature-status.py"),
901
- "--feature-list",
902
- str(plan_path),
903
- "--state-dir",
904
- str(family.state_dir),
905
- "--feature-id",
906
- "F-001",
907
- "--feature-slug",
908
- feature_slug,
909
- "--project-root",
910
- str(paths.project_root),
911
- "--action",
912
- "clean",
913
- ],
914
- cwd=paths.project_root,
915
- text=True,
916
- stdout=subprocess.PIPE,
917
- stderr=subprocess.PIPE,
918
- check=False,
919
- )
920
-
921
- assert result.returncode == 0, (result.stdout, result.stderr)
922
- payload = json.loads(result.stdout)
923
- assert payload["action"] == "clean"
924
- assert payload["new_status"] == "pending"
925
- updated_list = json.loads(plan_path.read_text(encoding="utf-8"))
926
- assert updated_list["features"][0]["status"] == "pending"
927
- updated_status = json.loads(status_path.read_text(encoding="utf-8"))
928
- for stale_field in (
929
- "repair_scope",
930
- "repair_round",
931
- "blocked_reason",
932
- "terminal_status",
933
- ):
934
- assert stale_field not in updated_status
935
- assert updated_status["retry_count"] == 0
936
- assert updated_status["infra_error_count"] == 0
937
- assert updated_status["sessions"] == []
938
- assert updated_status["last_session_id"] is None
939
- assert updated_status["resume_from_phase"] is None
940
- assert updated_status["custom_diagnostic"] == {"keep": True}
941
- assert "continuation_pending" not in updated_status
942
- assert not session_dir.exists()
943
- assert not specs_dir.exists()
944
-
945
-
946
- def _valid_bug(bug_id, status="pending", dependencies=None):
947
- return {
948
- "id": bug_id,
949
- "title": bug_id,
950
- "description": "Bug description",
951
- "severity": "high",
952
- "error_source": {"type": "failed_test", "content": "failure"},
953
- "verification_type": "automated",
954
- "acceptance_criteria": ["Regression is fixed"],
955
- "status": status,
956
- "dependencies": list(dependencies or []),
957
- }
958
-
959
-
960
- def _run_bug_updater(plan_path, state_dir, *args):
961
- return subprocess.run(
962
- [
963
- sys.executable,
964
- str(PIPELINE_ROOT / "scripts" / "update-bug-status.py"),
965
- "--bug-list",
966
- str(plan_path),
967
- "--state-dir",
968
- str(state_dir),
969
- "--project-root",
970
- str(plan_path.parent),
971
- *args,
972
- ],
973
- cwd=REPO_ROOT,
974
- text=True,
975
- stdout=subprocess.PIPE,
976
- stderr=subprocess.PIPE,
977
- check=False,
978
- )
979
-
980
-
981
- @pytest.mark.parametrize(
982
- ("session_status", "extra_args", "expected_root_status"),
983
- (
984
- ("failed", ("--max-retries", "1"), "failed"),
985
- ("workflow_skipped", (), "skipped"),
986
- ("workflow_blocked", (), "needs_info"),
987
- ),
988
- )
989
- def test_bugfix_terminal_roots_auto_skip_pending_descendants(
990
- tmp_path,
991
- session_status,
992
- extra_args,
993
- expected_root_status,
994
- ):
995
- plan_path = tmp_path / "bug-fix-list.json"
996
- state_dir = tmp_path / "state"
997
- completed_status = state_dir / "B-004" / "status.json"
998
- completed_status.parent.mkdir(parents=True)
999
- completed_status.write_text('{"custom":"unchanged"}\n', encoding="utf-8")
1000
- completed_before = completed_status.read_bytes()
1001
- plan_path.write_text(
1002
- json.dumps(
1003
- {
1004
- "$schema": "dev-pipeline-bug-fix-list-v1",
1005
- "project_name": "Bug Cascade",
1006
- "bugs": [
1007
- _valid_bug("B-001", "in_progress"),
1008
- _valid_bug("B-002", "pending", ["B-001"]),
1009
- _valid_bug("B-003", "pending", ["B-002"]),
1010
- _valid_bug("B-004", "completed"),
1011
- ],
1012
- }
1013
- ),
1014
- encoding="utf-8",
1015
- )
1016
-
1017
- result = _run_bug_updater(
1018
- plan_path,
1019
- state_dir,
1020
- "--action",
1021
- "update",
1022
- "--bug-id",
1023
- "B-001",
1024
- "--session-status",
1025
- session_status,
1026
- *extra_args,
1027
- )
1028
-
1029
- assert result.returncode == 0, (result.stdout, result.stderr)
1030
- summary = json.loads(result.stdout)
1031
- assert summary["auto_skipped"] == ["B-002", "B-003"]
1032
- statuses = {
1033
- bug["id"]: bug["status"]
1034
- for bug in json.loads(plan_path.read_text(encoding="utf-8"))["bugs"]
1035
- }
1036
- assert statuses == {
1037
- "B-001": expected_root_status,
1038
- "B-002": "auto_skipped",
1039
- "B-003": "auto_skipped",
1040
- "B-004": "completed",
1041
- }
1042
- assert completed_status.read_bytes() == completed_before
1043
-
1044
-
1045
- def test_existing_bugfix_list_lazily_normalizes_blocked_pending_descendants(tmp_path):
1046
- plan_path = tmp_path / "bug-fix-list.json"
1047
- state_dir = tmp_path / "state"
1048
- data = {
1049
- "$schema": "dev-pipeline-bug-fix-list-v1",
1050
- "project_name": "Legacy Bug List",
1051
- "bugs": [
1052
- _valid_bug("B-001", "failed"),
1053
- _valid_bug("B-002", "pending", ["B-001"]),
1054
- _valid_bug("B-003", "pending", ["B-002"]),
1055
- _valid_bug("B-004", "completed"),
1056
- ],
1057
- }
1058
- plan_path.write_text(json.dumps(data), encoding="utf-8")
1059
-
1060
- result = _run_bug_updater(plan_path, state_dir, "--action", "get_next")
1061
-
1062
- assert result.returncode == 0, (result.stdout, result.stderr)
1063
- assert result.stdout.strip() == "PIPELINE_COMPLETE"
1064
- updated = json.loads(plan_path.read_text(encoding="utf-8"))
1065
- statuses = {bug["id"]: bug["status"] for bug in updated["bugs"]}
1066
- assert statuses == {
1067
- "B-001": "failed",
1068
- "B-002": "auto_skipped",
1069
- "B-003": "auto_skipped",
1070
- "B-004": "completed",
1071
- }
1072
-
1073
- status_result = _run_bug_updater(plan_path, state_dir, "--action", "status")
1074
- assert status_result.returncode == 0
1075
- assert "Auto-skipped: 2" in status_result.stdout
1076
- assert "[⊘]" in status_result.stdout
1077
-
1078
-
1079
- def test_bugfix_auto_skip_write_failure_is_nonzero_without_partial_state(monkeypatch, tmp_path, capsys):
1080
- plan_path = tmp_path / "bug-fix-list.json"
1081
- state_dir = tmp_path / "state"
1082
- data = {
1083
- "$schema": "dev-pipeline-bug-fix-list-v1",
1084
- "project_name": "Write Failure",
1085
- "bugs": [
1086
- _valid_bug("B-001", "failed"),
1087
- _valid_bug("B-002", "pending", ["B-001"]),
1088
- ],
1089
- }
1090
- plan_path.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
1091
- before = plan_path.read_bytes()
1092
- module = _load_source_module(
1093
- "f060_update_bug_status_write_failure",
1094
- PIPELINE_ROOT / "scripts" / "update-bug-status.py",
1095
- )
1096
- monkeypatch.setattr(module, "write_json_file", lambda *_args, **_kwargs: "permission denied")
1097
-
1098
- with pytest.raises(SystemExit):
1099
- module.auto_skip_blocked_bugs(str(plan_path), str(state_dir), "B-001")
1100
-
1101
- output = capsys.readouterr().out
1102
- assert "Failed to write auto-skipped bugs" in output
1103
- assert plan_path.read_bytes() == before
1104
- assert _tree_snapshot(state_dir) == {}
1105
-
1106
-
1107
- def _load_source_module(name, path):
1108
- import importlib.util
1109
-
1110
- spec = importlib.util.spec_from_file_location(name, path)
1111
- module = importlib.util.module_from_spec(spec)
1112
- assert spec.loader is not None
1113
- spec.loader.exec_module(module)
1114
- return module
1115
-
1116
-
1117
- def test_bugfix_auto_skipped_schema_validators_and_aggregation_are_consistent():
1118
- from prizmkit_runtime.daemon import PROGRESS_COUNTS_BY_KIND
1119
- from prizmkit_runtime.runner_models import family_for
1120
- from prizmkit_runtime.runners import _completion_compatible_statuses
1121
- from prizmkit_runtime.paths import resolve_runtime_paths
1122
-
1123
- schema = json.loads(
1124
- (PIPELINE_ROOT / "templates" / "bug-fix-list-schema.json").read_text(encoding="utf-8")
1125
- )
1126
- status_enum = schema["properties"]["bugs"]["items"]["properties"]["status"]["enum"]
1127
- assert "auto_skipped" in status_enum
1128
-
1129
- init_module = _load_source_module(
1130
- "f060_init_bugfix",
1131
- PIPELINE_ROOT / "scripts" / "init-bugfix-pipeline.py",
1132
- )
1133
- planner_module = _load_source_module(
1134
- "f060_validate_bug_list",
1135
- REPO_ROOT
1136
- / "core"
1137
- / "skills"
1138
- / "orchestration-skill"
1139
- / "pipelines"
1140
- / "bug-planner"
1141
- / "scripts"
1142
- / "validate-bug-list.py",
1143
- )
1144
- assert "auto_skipped" in init_module.VALID_STATUSES
1145
- assert "auto_skipped" in init_module.TERMINAL_STATUSES
1146
- assert "auto_skipped" in planner_module.VALID_STATUSES
1147
-
1148
- bugs = [
1149
- _valid_bug("B-001", "failed"),
1150
- _valid_bug("B-002", "pending", ["B-001"]),
1151
- _valid_bug("B-003", "auto_skipped", ["B-001"]),
1152
- ]
1153
- init_errors, _seen = init_module.validate_bugs(bugs)
1154
- assert init_errors == []
1155
- planner_result = planner_module.validate(
1156
- {
1157
- "$schema": "dev-pipeline-bug-fix-list-v1",
1158
- "project_name": "Validator Test",
1159
- "bugs": bugs,
1160
- }
1161
- )
1162
- assert planner_result["valid"] is True, planner_result["errors"]
1163
-
1164
- assert "auto_skipped" in PROGRESS_COUNTS_BY_KIND["bugfix"]
1165
- paths = resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=REPO_ROOT)
1166
- bug_family = family_for("bugfix", paths)
1167
- assert "auto_skipped" not in _completion_compatible_statuses(bug_family)
1168
-
1169
-
1170
- def test_all_updaters_expose_only_reset_state_internal_recovery_action():
1171
- retired_action = "un" + "skip"
1172
- for contract in FAMILY_CONTRACTS.values():
1173
- source = (PIPELINE_ROOT / "scripts" / contract["script"]).read_text(encoding="utf-8")
1174
- assert retired_action not in source
1175
- assert '"reset_state"' in source
1176
- assert '"action": "reset_state"' in source
1177
-
1178
-
1179
- def test_canonical_reset_guidance_documents_every_explicit_mode_without_generated_outputs():
1180
- launcher_root = (
1181
- REPO_ROOT
1182
- / "core"
1183
- / "skills"
1184
- / "orchestration-skill"
1185
- / "pipelines"
1186
- )
1187
- launchers = {
1188
- "feature-pipeline-launcher": ("feature", "F-001"),
1189
- "bugfix-pipeline-launcher": ("bugfix", "B-001"),
1190
- "refactor-pipeline-launcher": ("refactor", "R-001"),
1191
- }
1192
- for launcher, (family, item_id) in launchers.items():
1193
- source = (launcher_root / launcher / "SKILL.md").read_text(encoding="utf-8")
1194
- assert f"reset {family} {item_id} --state-only" in source
1195
- assert f"reset {family} {item_id} --fresh-checkout" in source
1196
- assert f"reset {family} {item_id} --clean" in source
1197
- assert f"reset {family} --failed --preserve-runtime" in source
1198
- assert "exactly one mode" in source.lower()
1199
-
1200
- memory_source = (REPO_ROOT / "core" / "templates" / "project-memory-template.md").read_text(
1201
- encoding="utf-8"
1202
- )
1203
- assert "reset <family> <task-id> --state-only" in memory_source
1204
- assert "reset <family> --state-only --all" in memory_source
1205
- assert "reset <family> <task-id-or-range> --fresh-checkout" in memory_source
1206
- assert "reset <family> <task-id-or-range> --clean" in memory_source
1207
- assert "reset <family> --failed --preserve-runtime" in memory_source
1208
- assert "<family> " + "un" + "skip" not in memory_source