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,1314 +0,0 @@
1
- """Tests for shared workflow checkpoint state semantics."""
2
-
3
- from __future__ import annotations
4
-
5
- import json
6
- import subprocess
7
- import sys
8
-
9
- import pytest
10
-
11
- from prizmkit_runtime.checkpoint_state import (
12
- VALID_CHECKPOINT_STATUSES,
13
- VALID_STAGE_RESULTS,
14
- expected_status_for_stage_result,
15
- load_checkpoint_state,
16
- read_checkpoint_cursor,
17
- validate_checkpoint_data,
18
- )
19
- from prizmkit_runtime.test_result import load_test_result
20
- from update_checkpoint import update_checkpoint
21
-
22
-
23
- def _checkpoint(steps):
24
- return {"version": 1, "workflow_type": "feature-pipeline", "steps": steps}
25
-
26
-
27
- def _step(step_id, skill="skill", name="Step", status="pending", depends_on=None):
28
- return {
29
- "id": step_id,
30
- "skill": skill,
31
- "name": name,
32
- "status": status,
33
- "required_artifacts": [],
34
- "depends_on": depends_on,
35
- }
36
-
37
-
38
- def _write(path, data):
39
- path.parent.mkdir(parents=True, exist_ok=True)
40
- path.write_text(json.dumps(data), encoding="utf-8")
41
- return path
42
-
43
-
44
- def _write_test_artifacts(root, slug="feature", *, result="TEST_PASS"):
45
- artifact_dir = root / ".prizmkit" / "specs" / slug
46
- artifact_dir.mkdir(parents=True, exist_ok=True)
47
- (artifact_dir / "test-report.md").write_text(
48
- f"# Test Report\n\n## Final Result\n\n- Result: {result}\n",
49
- encoding="utf-8",
50
- )
51
- projection = {
52
- "schema_version": 1,
53
- "result": result,
54
- "report": "test-report.md",
55
- "main_review_rounds": 1,
56
- "independent_review": {
57
- "status": "downgraded",
58
- "responses": 0,
59
- "downgrade_reason": "read-only continuation capability unavailable",
60
- "final_state_rechecked": False,
61
- },
62
- "repair_rounds": 0,
63
- "production_changed": False,
64
- "unresolved_items": [],
65
- }
66
- (artifact_dir / "test-result.json").write_text(
67
- json.dumps(projection), encoding="utf-8"
68
- )
69
- return artifact_dir
70
-
71
-
72
- def _family_checkpoint(root=None, *, semantic=None, terminal=True):
73
- skills = [
74
- "prizmkit-implement",
75
- "prizmkit-code-review",
76
- "prizmkit-test",
77
- "completion-summary",
78
- "prizmkit-retrospective",
79
- "prizmkit-committer",
80
- ]
81
- steps = []
82
- previous = None
83
- for index, skill in enumerate(skills, start=1):
84
- step = _step(f"S{index:02d}", skill, skill, "completed", previous)
85
- if skill == "prizmkit-implement":
86
- step["stage_result"] = "IMPLEMENTED"
87
- if skill == "prizmkit-code-review":
88
- step["stage_result"] = "REVIEW_PASS"
89
- if skill == "prizmkit-test":
90
- step["stage_result"] = "TEST_PASS"
91
- step["required_artifacts"] = [
92
- ".prizmkit/specs/feature/test-report.md",
93
- ".prizmkit/specs/feature/test-result.json",
94
- ]
95
- if skill == "prizmkit-retrospective":
96
- step["stage_result"] = "RETRO_COMPLETE"
97
- if skill == "prizmkit-committer":
98
- step["stage_result"] = "COMMITTED"
99
- steps.append(step)
100
- previous = step["id"]
101
- if root is not None:
102
- _write_test_artifacts(root)
103
- return {
104
- "version": 1,
105
- "workflow_type": "feature-pipeline",
106
- "steps": steps,
107
- "feature_state": semantic or (
108
- {
109
- "terminal_status": "WORKFLOW_COMPLETED",
110
- "runtime_base_head": "a" * 40,
111
- "runtime_commit_hash": "b" * 40,
112
- }
113
- if terminal else {}
114
- ),
115
- }
116
-
117
-
118
- def test_valid_checkpoint_current_step_uses_first_non_terminal(tmp_path):
119
- path = _write(tmp_path / "workflow-checkpoint.json", _checkpoint([
120
- _step("S01", "plan", "Plan", "completed"),
121
- _step("S02", "implement", "Implement", "in_progress", "S01"),
122
- _step("S03", "review", "Review", "pending", "S02"),
123
- ]))
124
-
125
- state = load_checkpoint_state(path)
126
-
127
- assert state.valid is True
128
- assert state.current_step_name == "Implement"
129
- assert state.cursor == 2
130
- assert state.cursor_signature == "S02:implement:in_progress"
131
- assert read_checkpoint_cursor(path) == 2
132
-
133
-
134
- def test_missing_and_malformed_checkpoints_are_invalid(tmp_path):
135
- missing = load_checkpoint_state(tmp_path / "missing.json")
136
- assert missing.valid is False
137
- assert missing.exists is False
138
- assert missing.error_code == "missing"
139
-
140
- malformed_path = tmp_path / "bad.json"
141
- malformed_path.write_text("{not-json", encoding="utf-8")
142
- malformed = load_checkpoint_state(malformed_path)
143
- assert malformed.valid is False
144
- assert malformed.error_code == "malformed_json"
145
-
146
-
147
- def test_structural_validation_error_codes(tmp_path):
148
- cases = [
149
- ("missing_steps", {}),
150
- ("empty_steps", {"steps": []}),
151
- ("duplicate_step_id", _checkpoint([_step("S01"), _step("S01")])),
152
- ("invalid_status", _checkpoint([_step("S01", status="done")])),
153
- ("invalid_depends_on", _checkpoint([_step("S01", depends_on="S99")])),
154
- ("malformed_step_id", _checkpoint([_step("one")])),
155
- ("invalid_step", {"steps": ["not-object"]}),
156
- ]
157
- for expected_code, payload in cases:
158
- path = _write(tmp_path / f"{expected_code}.json", payload)
159
- state = load_checkpoint_state(path)
160
- assert state.valid is False
161
- assert state.error_code == expected_code
162
- assert read_checkpoint_cursor(path) is None
163
-
164
-
165
- def test_domain_results_map_to_lifecycle_statuses():
166
- expected = {
167
- "PLAN_READY": "completed",
168
- "PLAN_BLOCKED": "failed",
169
- "IMPLEMENTED": "completed",
170
- "IMPLEMENT_REPAIR": "failed",
171
- "IMPLEMENT_BLOCKED": "failed",
172
- "REVIEW_PASS": "completed",
173
- "REVIEW_NEEDS_FIXES": "failed",
174
- "TEST_PASS": "completed",
175
- "TEST_NEEDS_FIXES": "failed",
176
- "TEST_BLOCKED": "failed",
177
- "RETRO_COMPLETE": "completed",
178
- "RETRO_BLOCKED": "failed",
179
- "COMMIT_PENDING": "in_progress",
180
- "COMMITTED": "completed",
181
- "COMMIT_BLOCKED": "failed",
182
- }
183
-
184
- assert VALID_CHECKPOINT_STATUSES == {
185
- "pending", "in_progress", "completed", "failed", "skipped",
186
- }
187
- for result, status in expected.items():
188
- assert expected_status_for_stage_result(result) == status
189
-
190
-
191
- def test_structural_validation_rejects_domain_result_as_status(tmp_path):
192
- for domain_status in [
193
- "PLAN_READY", "IMPLEMENTED", "REVIEW_PASS", "REVIEW_NEEDS_FIXES",
194
- "TEST_PASS", "TEST_NEEDS_FIXES", "TEST_BLOCKED", "RETRO_COMPLETE",
195
- "COMMIT_PENDING", "COMMITTED",
196
- ]:
197
- state = validate_checkpoint_data(
198
- _checkpoint([_step("S01", status=domain_status)]),
199
- path=tmp_path / f"{domain_status}.json",
200
- )
201
- assert state.valid is False
202
- assert state.error_code == "invalid_status"
203
-
204
-
205
- def test_structural_validation_rejects_status_result_mismatch(tmp_path):
206
- step = _step("S01", "prizmkit-code-review", "Review", "failed")
207
- step["stage_result"] = "REVIEW_PASS"
208
-
209
- state = validate_checkpoint_data(
210
- _checkpoint([step]),
211
- path=tmp_path / "mismatch.json",
212
- )
213
-
214
- assert state.valid is False
215
- assert state.error_code == "stage_result_status_mismatch"
216
-
217
-
218
- def test_family_planning_wrappers_own_plan_results(tmp_path):
219
- for skill in ("context-snapshot-and-plan", "bug-diagnosis-and-plan"):
220
- step = _step("S01", skill, "Plan", "completed")
221
- step["stage_result"] = "PLAN_READY"
222
- state = validate_checkpoint_data(
223
- _checkpoint([step]), path=tmp_path / f"{skill}.json",
224
- )
225
- assert state.valid is True
226
-
227
-
228
- def test_structural_validation_rejects_stage_result_owner_mismatch(tmp_path):
229
- for skill in ("prizmkit-test", "custom-stage"):
230
- step = _step("S01", skill, "Step", "completed")
231
- step["stage_result"] = "REVIEW_PASS"
232
-
233
- state = validate_checkpoint_data(
234
- _checkpoint([step]),
235
- path=tmp_path / f"{skill}-owner-mismatch.json",
236
- )
237
-
238
- assert state.valid is False
239
- assert state.error_code == "stage_result_owner_mismatch"
240
-
241
-
242
- def test_semantic_metadata_rejects_legacy_or_mismatched_status(tmp_path):
243
- invalid = [
244
- ({"status": "TEST_PASS", "stage_result": "TEST_PASS"}, "invalid_semantic_status"),
245
- ({"status": "failed", "stage_result": "TEST_PASS"}, "semantic_stage_result_status_mismatch"),
246
- ({"status": "completed", "stage_result": "UNKNOWN_RESULT"}, "invalid_semantic_stage_result"),
247
- ({"stage": "test", "status": "completed", "stage_result": "REVIEW_PASS"}, "semantic_stage_result_owner_mismatch"),
248
- ]
249
-
250
- for index, (semantic, error_code) in enumerate(invalid):
251
- state = validate_checkpoint_data(
252
- _checkpoint([_step("S01")]) | {"feature_state": semantic},
253
- path=tmp_path / f"semantic-status-{index}.json",
254
- )
255
-
256
- assert state.valid is True
257
- assert state.semantic.error_code == error_code
258
-
259
-
260
- def test_semantic_blocker_metadata_requires_blocked_terminal_state(tmp_path):
261
- cases = [
262
- ({"blocked_reason": ""}, "invalid_blocked_reason"),
263
- ({"blocked_reason": " "}, "invalid_blocked_reason"),
264
- ({"blocked_reason": "unexpected blocker"}, "blocked_reason_without_blocked_terminal"),
265
- (
266
- {"blocked_reason": "unexpected blocker", "terminal_status": "WORKFLOW_COMPLETED"},
267
- "completed_workflow_has_blocked_reason",
268
- ),
269
- ({"terminal_status": "WORKFLOW_BLOCKED"}, "missing_blocked_reason"),
270
- ]
271
-
272
- for index, (semantic, expected_error) in enumerate(cases):
273
- payload = _family_checkpoint(tmp_path, semantic=semantic)
274
- state = validate_checkpoint_data(
275
- payload,
276
- path=tmp_path / f"invalid-blocker-{index}.json",
277
- project_root=tmp_path,
278
- )
279
-
280
- assert state.valid is True
281
- assert state.semantic.error_code == expected_error
282
- assert state.semantic_complete is False
283
-
284
-
285
- def test_checkpoint_updater_rejects_invalid_blocker_metadata_without_mutation(tmp_path):
286
- cases = [
287
- ({"blocked_reason": "", "terminal_status": "WORKFLOW_COMPLETED"}, True),
288
- ({"blocked_reason": " ", "terminal_status": "WORKFLOW_COMPLETED"}, True),
289
- ({"blocked_reason": "unexpected blocker", "terminal_status": "WORKFLOW_COMPLETED"}, True),
290
- ({"blocked_reason": "unexpected blocker"}, False),
291
- ({"terminal_status": "WORKFLOW_BLOCKED"}, False),
292
- ]
293
-
294
- for index, (semantic_update, completed) in enumerate(cases):
295
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
296
- if not completed:
297
- payload["steps"][0]["status"] = "in_progress"
298
- for step in payload["steps"][1:]:
299
- step["status"] = "pending"
300
- step.pop("stage_result", None)
301
- checkpoint = _write(tmp_path / f"atomic-blocker-{index}.json", payload)
302
- before = checkpoint.read_bytes()
303
-
304
- result = update_checkpoint(
305
- str(checkpoint),
306
- "S06" if completed else "S01",
307
- "completed" if completed else "in_progress",
308
- semantic_update=semantic_update,
309
- )
310
-
311
- assert result["ok"] is False
312
- assert checkpoint.read_bytes() == before
313
-
314
-
315
- def test_checkpoint_updater_rejects_completed_terminal_for_blocking_stage_result(tmp_path):
316
- for index, blocked_reason in enumerate((None, "safe environment unavailable")):
317
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
318
- payload["steps"][2]["status"] = "in_progress"
319
- payload["steps"][2].pop("stage_result", None)
320
- for step in payload["steps"][3:]:
321
- step["status"] = "pending"
322
- step.pop("stage_result", None)
323
- checkpoint = _write(tmp_path / f"conflicting-test-terminal-{index}.json", payload)
324
- before = checkpoint.read_bytes()
325
- semantic_update = {
326
- "stage_result": "TEST_BLOCKED",
327
- "terminal_status": "WORKFLOW_COMPLETED",
328
- }
329
- if blocked_reason is not None:
330
- semantic_update["blocked_reason"] = blocked_reason
331
-
332
- result = update_checkpoint(
333
- str(checkpoint),
334
- "prizmkit-test",
335
- "failed",
336
- semantic_update=semantic_update,
337
- )
338
-
339
- assert result["ok"] is False
340
- assert checkpoint.read_bytes() == before
341
-
342
-
343
- def test_checkpoint_updater_cli_returns_nonzero_without_mutating_invalid_blocker_input(tmp_path):
344
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
345
- checkpoint = _write(tmp_path / "cli-invalid-blocker.json", payload)
346
- before = checkpoint.read_bytes()
347
- script = __import__("update_checkpoint").__file__
348
-
349
- result = subprocess.run(
350
- [
351
- sys.executable,
352
- script,
353
- "--checkpoint-path",
354
- str(checkpoint),
355
- "--step",
356
- "S06",
357
- "--status",
358
- "completed",
359
- "--terminal-status",
360
- "WORKFLOW_COMPLETED",
361
- "--blocked-reason",
362
- "",
363
- ],
364
- text=True,
365
- capture_output=True,
366
- check=False,
367
- )
368
-
369
- assert result.returncode == 1
370
- assert json.loads(result.stdout)["ok"] is False
371
- assert checkpoint.read_bytes() == before
372
-
373
-
374
- def test_update_checkpoint_reenters_failed_stage_without_stale_result(tmp_path):
375
- payload = _family_checkpoint(
376
- tmp_path,
377
- semantic={
378
- "stage": "code-review",
379
- "status": "failed",
380
- "stage_result": "REVIEW_NEEDS_FIXES",
381
- "repair_scope": "production",
382
- "repair_round": 1,
383
- },
384
- terminal=False,
385
- )
386
- payload["steps"][1]["status"] = "failed"
387
- payload["steps"][1]["stage_result"] = "REVIEW_NEEDS_FIXES"
388
- for step in payload["steps"][2:]:
389
- step["status"] = "pending"
390
- step.pop("stage_result", None)
391
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
392
-
393
- result = update_checkpoint(
394
- str(checkpoint),
395
- "prizmkit-code-review",
396
- "in_progress",
397
- )
398
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
399
-
400
- assert result["ok"] is True
401
- assert result["semantic"]["current_stage"] == "prizmkit-code-review"
402
- assert result["semantic"]["next_stage"] == "prizmkit-code-review"
403
- assert persisted["steps"][1]["status"] == "in_progress"
404
- assert "stage_result" not in persisted["steps"][1]
405
- assert persisted["feature_state"]["stage"] == "code-review"
406
- assert persisted["feature_state"]["status"] == "in_progress"
407
- assert "stage_result" not in persisted["feature_state"]
408
-
409
-
410
- def test_checkpoint_updater_supports_every_prompt_owned_stage_result(tmp_path):
411
- cases = [
412
- ("prizmkit-plan", "PLAN_READY", "completed"),
413
- ("prizmkit-implement", "IMPLEMENTED", "completed"),
414
- ("prizmkit-code-review", "REVIEW_PASS", "completed"),
415
- ("prizmkit-test", "TEST_BLOCKED", "failed"),
416
- ("prizmkit-retrospective", "RETRO_COMPLETE", "completed"),
417
- ]
418
-
419
- assert {stage_result for _skill, stage_result, _status in cases} <= VALID_STAGE_RESULTS
420
- for index, (skill, stage_result, status) in enumerate(cases):
421
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
422
- if skill == "prizmkit-plan":
423
- for offset, step in enumerate(payload["steps"], start=2):
424
- step["id"] = f"S{offset:02d}"
425
- step["depends_on"] = f"S{offset - 1:02d}"
426
- payload["steps"].insert(0, _step("S01", skill, skill, "pending"))
427
- target_index = 0
428
- else:
429
- payload["steps"].insert(
430
- 0,
431
- {
432
- "id": "S00",
433
- "skill": "context-snapshot-and-plan",
434
- "name": "Plan",
435
- "status": "completed",
436
- "stage_result": "PLAN_READY",
437
- "required_artifacts": [],
438
- "depends_on": None,
439
- },
440
- )
441
- payload["steps"][1]["depends_on"] = "S00"
442
- target_index = next(
443
- position
444
- for position, step in enumerate(payload["steps"])
445
- if step["skill"] == skill
446
- )
447
- for step in payload["steps"][target_index:]:
448
- step["status"] = "pending"
449
- step.pop("stage_result", None)
450
- checkpoint = _write(tmp_path / f"owned-result-{index}.json", payload)
451
-
452
- result = update_checkpoint(
453
- str(checkpoint),
454
- skill,
455
- status,
456
- semantic_update={"stage_result": stage_result},
457
- )
458
-
459
- assert result["ok"] is True
460
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
461
- target = next(step for step in persisted["steps"] if step["skill"] == skill)
462
- assert target["status"] == status
463
- assert target["stage_result"] == stage_result
464
- assert persisted["feature_state"]["stage"] == {
465
- "prizmkit-plan": "plan",
466
- "prizmkit-implement": "implement",
467
- "prizmkit-code-review": "code-review",
468
- "prizmkit-test": "test",
469
- "prizmkit-retrospective": "retrospective",
470
- "prizmkit-committer": "committer",
471
- }[skill]
472
- assert persisted["feature_state"]["status"] == status
473
- assert persisted["feature_state"]["stage_result"] == stage_result
474
-
475
-
476
- def test_duplicate_skills_require_exact_step_id(tmp_path):
477
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
478
- for offset, step in enumerate(payload["steps"], start=3):
479
- step["id"] = f"S{offset:02d}"
480
- step["depends_on"] = f"S{offset - 1:02d}"
481
- step["status"] = "pending"
482
- step.pop("stage_result", None)
483
- payload["steps"][:0] = [
484
- _step("S01", "custom-stage", "First", "completed"),
485
- _step("S02", "custom-stage", "Second", "pending", "S01"),
486
- ]
487
- path = _write(tmp_path / "workflow-checkpoint.json", payload)
488
-
489
- rejected = update_checkpoint(str(path), "custom-stage", "completed")
490
- accepted = update_checkpoint(str(path), "S02", "completed")
491
-
492
- assert rejected["ok"] is False
493
- assert "matches multiple checkpoint steps" in rejected["error"]
494
- assert accepted["ok"] is True
495
-
496
-
497
- def test_semantic_completion_requires_family_sequence_and_domain_results(tmp_path):
498
- path = _write(
499
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json",
500
- _family_checkpoint(tmp_path),
501
- )
502
-
503
- state = load_checkpoint_state(path, project_root=tmp_path)
504
-
505
- assert state.valid is True
506
- assert state.all_completed is True
507
- assert state.semantic_complete is True
508
- assert state.semantic.test_result_valid is True
509
- assert state.semantic.terminal_status == "WORKFLOW_COMPLETED"
510
-
511
-
512
- def test_completion_does_not_require_retired_evidence_paths(tmp_path):
513
- payload = _family_checkpoint(tmp_path)
514
- assert "authoritative_evidence_paths" not in payload["steps"][2]
515
- assert "authoritative_evidence_paths" not in payload["feature_state"]
516
-
517
- state = validate_checkpoint_data(payload, project_root=tmp_path)
518
-
519
- assert state.semantic_complete is True
520
- assert state.semantic.test_result_valid is True
521
-
522
-
523
- def test_completed_steps_without_review_or_test_results_do_not_complete(tmp_path):
524
- payload = _family_checkpoint(tmp_path)
525
- payload["steps"][1].pop("stage_result")
526
- payload["steps"][2].pop("stage_result")
527
-
528
- state = validate_checkpoint_data(payload, project_root=tmp_path)
529
-
530
- assert state.semantic_complete is False
531
- assert state.semantic.error_code == "incomplete_semantic_evidence"
532
-
533
-
534
- def test_family_sequence_mismatch_cannot_complete(tmp_path):
535
- payload = _family_checkpoint(tmp_path)
536
- payload["steps"][1], payload["steps"][2] = payload["steps"][2], payload["steps"][1]
537
- payload["steps"][1]["id"] = "S02"
538
- payload["steps"][2]["id"] = "S03"
539
- payload["steps"][1]["depends_on"] = "S01"
540
- payload["steps"][2]["depends_on"] = "S02"
541
-
542
- state = validate_checkpoint_data(payload, project_root=tmp_path)
543
-
544
- assert state.semantic_complete is False
545
- assert state.semantic.sequence_valid is False
546
- assert state.semantic.error_code == "invalid_stage_sequence"
547
-
548
-
549
- def test_test_needs_fixes_routes_to_implementation_and_rewinds_stale_gates(tmp_path):
550
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
551
- payload["steps"].insert(
552
- 0,
553
- {
554
- "id": "S00",
555
- "skill": "context-snapshot-and-plan",
556
- "name": "Plan",
557
- "status": "completed",
558
- "stage_result": "PLAN_READY",
559
- "required_artifacts": [],
560
- "depends_on": None,
561
- },
562
- )
563
- payload["steps"][1]["depends_on"] = "S00"
564
- test_step = next(step for step in payload["steps"] if step["skill"] == "prizmkit-test")
565
- test_index = payload["steps"].index(test_step)
566
- test_step["status"] = "in_progress"
567
- test_step.pop("stage_result")
568
- for step in payload["steps"][test_index + 1:]:
569
- step["status"] = "pending"
570
- step.pop("stage_result", None)
571
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
572
-
573
- result = update_checkpoint(
574
- str(checkpoint),
575
- "prizmkit-test",
576
- "failed",
577
- semantic_update={
578
- "stage_result": "TEST_NEEDS_FIXES",
579
- "repair_scope": "production",
580
- },
581
- )
582
- routed = json.loads(checkpoint.read_text(encoding="utf-8"))
583
-
584
- assert result["ok"] is True
585
- assert test_step["skill"] == "prizmkit-test"
586
- persisted_test = next(
587
- step for step in routed["steps"] if step["skill"] == "prizmkit-test"
588
- )
589
- assert persisted_test["stage_result"] == "TEST_NEEDS_FIXES"
590
- assert routed["feature_state"]["stage_result"] == "TEST_NEEDS_FIXES"
591
- assert routed["feature_state"]["next_stage"] == "prizmkit-implement"
592
- assert routed["feature_state"]["repair_round"] == 1
593
-
594
- restarted = update_checkpoint(
595
- str(checkpoint), "prizmkit-implement", "in_progress"
596
- )
597
- rewound = json.loads(checkpoint.read_text(encoding="utf-8"))
598
-
599
- assert restarted["ok"] is True
600
- implementation = next(
601
- step for step in rewound["steps"] if step["skill"] == "prizmkit-implement"
602
- )
603
- assert implementation["status"] == "in_progress"
604
- for step in rewound["steps"][rewound["steps"].index(implementation) + 1:]:
605
- assert step["status"] == "pending"
606
- assert "stage_result" not in step
607
-
608
-
609
- def test_terminal_atomic_blockers_become_workflow_blocked(tmp_path):
610
- cases = [
611
- ("context-snapshot-and-plan", "PLAN_BLOCKED"),
612
- ("prizmkit-implement", "IMPLEMENT_BLOCKED"),
613
- ("prizmkit-retrospective", "RETRO_BLOCKED"),
614
- ("prizmkit-committer", "COMMIT_BLOCKED"),
615
- ]
616
- for index, (skill, stage_result) in enumerate(cases):
617
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
618
- if skill == "context-snapshot-and-plan":
619
- payload["steps"].insert(
620
- 0,
621
- {
622
- "id": "S00",
623
- "skill": skill,
624
- "name": "Plan",
625
- "status": "pending",
626
- "required_artifacts": [],
627
- "depends_on": None,
628
- },
629
- )
630
- payload["steps"][1]["depends_on"] = "S00"
631
- target_index = 0
632
- else:
633
- target_index = next(
634
- position for position, step in enumerate(payload["steps"])
635
- if step["skill"] == skill
636
- )
637
- for step in payload["steps"][target_index:]:
638
- step["status"] = "pending"
639
- step.pop("stage_result", None)
640
- checkpoint = _write(tmp_path / f"terminal-blocker-{index}.json", payload)
641
-
642
- result = update_checkpoint(
643
- str(checkpoint), skill, "failed",
644
- semantic_update={"stage_result": stage_result},
645
- )
646
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
647
-
648
- assert result["ok"] is True
649
- assert persisted["feature_state"]["terminal_status"] == "WORKFLOW_BLOCKED"
650
- assert persisted["feature_state"]["blocked_reason"]
651
-
652
-
653
- def test_test_blocked_preserves_l1_result_without_evidence_discovery(tmp_path):
654
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
655
- payload["steps"][2]["status"] = "in_progress"
656
- payload["steps"][2].pop("stage_result")
657
- for step in payload["steps"][3:]:
658
- step["status"] = "pending"
659
- step.pop("stage_result", None)
660
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
661
-
662
- result = update_checkpoint(
663
- str(checkpoint),
664
- "prizmkit-test",
665
- "failed",
666
- semantic_update={"stage_result": "TEST_BLOCKED", "blocked_reason": "safe environment unavailable"},
667
- )
668
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
669
-
670
- assert result["ok"] is True
671
- assert persisted["steps"][2]["stage_result"] == "TEST_BLOCKED"
672
- assert persisted["feature_state"]["stage_result"] == "TEST_BLOCKED"
673
- assert persisted["feature_state"]["blocked_reason"] == "test_blocked"
674
- assert "authoritative_evidence_paths" not in persisted["feature_state"]
675
-
676
-
677
- def test_update_checkpoint_completes_test_pass_without_validator(tmp_path):
678
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
679
- payload["steps"][2]["status"] = "in_progress"
680
- payload["steps"][2].pop("stage_result")
681
- for step in payload["steps"][3:]:
682
- step["status"] = "pending"
683
- step.pop("stage_result", None)
684
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
685
-
686
- result = update_checkpoint(
687
- str(checkpoint),
688
- "prizmkit-test",
689
- "completed",
690
- semantic_update={"stage_result": "TEST_PASS"},
691
- )
692
-
693
- assert result["ok"] is True
694
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
695
- assert persisted["steps"][2]["status"] == "completed"
696
- assert persisted["steps"][2]["stage_result"] == "TEST_PASS"
697
- assert "commit_ready" not in result["semantic"]
698
-
699
-
700
- def test_update_checkpoint_rejects_test_completion_for_non_pass(tmp_path):
701
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
702
- payload["steps"][2]["status"] = "in_progress"
703
- payload["steps"][2].pop("stage_result")
704
- for step in payload["steps"][3:]:
705
- step["status"] = "pending"
706
- step.pop("stage_result", None)
707
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
708
-
709
- result = update_checkpoint(
710
- str(checkpoint),
711
- "prizmkit-test",
712
- "completed",
713
- semantic_update={"stage_result": "TEST_NEEDS_FIXES"},
714
- )
715
-
716
- assert result["ok"] is False
717
- assert "requires TEST_PASS" in result["error"]
718
-
719
-
720
- def test_prompt_checkpoint_helper_rejects_runtime_owned_commit_results(tmp_path):
721
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
722
- committer = next(
723
- step for step in payload["steps"] if step["skill"] == "prizmkit-committer"
724
- )
725
- committer["status"] = "in_progress"
726
- committer["stage_result"] = "COMMIT_PENDING"
727
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
728
-
729
- pending = update_checkpoint(
730
- str(checkpoint),
731
- "prizmkit-committer",
732
- "in_progress",
733
- semantic_update={"stage_result": "COMMIT_PENDING"},
734
- )
735
- result = update_checkpoint(
736
- str(checkpoint),
737
- "prizmkit-committer",
738
- "completed",
739
- semantic_update={"stage_result": "COMMITTED"},
740
- )
741
-
742
- assert pending["ok"] is False
743
- assert "Runtime-owned" in pending["error"]
744
- assert result["ok"] is False
745
- assert "Runtime-owned" in result["error"]
746
- without_result = update_checkpoint(
747
- str(checkpoint), "prizmkit-committer", "completed"
748
- )
749
- assert without_result["ok"] is False
750
- assert "Runtime-owned COMMITTED" in without_result["error"]
751
-
752
-
753
- def test_update_checkpoint_rejects_test_before_review_pass(tmp_path):
754
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
755
- payload["steps"][1]["status"] = "skipped"
756
- payload["steps"][1].pop("stage_result", None)
757
- payload["steps"][2]["status"] = "pending"
758
- payload["steps"][2].pop("stage_result", None)
759
- for step in payload["steps"][3:]:
760
- step["status"] = "pending"
761
- step.pop("stage_result", None)
762
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
763
-
764
- result = update_checkpoint(str(checkpoint), "prizmkit-test", "in_progress")
765
-
766
- assert result["ok"] is False
767
- assert "REVIEW_PASS" in result["error"]
768
-
769
-
770
- def test_update_checkpoint_rejects_finalization_before_test_pass(tmp_path):
771
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
772
- payload["steps"][2]["status"] = "skipped"
773
- payload["steps"][2].pop("stage_result", None)
774
- payload["steps"][3]["status"] = "completed"
775
- for step in payload["steps"][4:]:
776
- step["status"] = "pending"
777
- step.pop("stage_result", None)
778
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
779
-
780
- result = update_checkpoint(str(checkpoint), "prizmkit-retrospective", "in_progress")
781
-
782
- assert result["ok"] is False
783
- assert "TEST_PASS" in result["error"]
784
-
785
-
786
- def test_prompt_checkpoint_helper_cannot_block_after_runtime_request_exists(tmp_path):
787
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
788
- committer = next(
789
- step for step in payload["steps"] if step["skill"] == "prizmkit-committer"
790
- )
791
- committer["status"] = "in_progress"
792
- committer.pop("stage_result", None)
793
- committer["required_artifacts"] = [
794
- ".prizmkit/specs/feature/runtime-commit-request.json"
795
- ]
796
- artifact_dir = tmp_path / ".prizmkit/specs/feature"
797
- request = artifact_dir / "runtime-commit-request.json"
798
- request.write_text("{}", encoding="utf-8")
799
- checkpoint = _write(artifact_dir / "workflow-checkpoint.json", payload)
800
-
801
- result = update_checkpoint(
802
- str(checkpoint),
803
- "prizmkit-committer",
804
- "failed",
805
- semantic_update={"stage_result": "COMMIT_BLOCKED"},
806
- )
807
-
808
- assert result["ok"] is False
809
- assert "request already exists" in result["error"]
810
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
811
- persisted_committer = next(
812
- step for step in persisted["steps"]
813
- if step["skill"] == "prizmkit-committer"
814
- )
815
- assert persisted_committer["status"] == "in_progress"
816
- assert "stage_result" not in persisted_committer
817
-
818
-
819
- def test_commit_pending_is_runtime_ready_but_not_workflow_complete(tmp_path):
820
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
821
- payload["steps"].insert(
822
- 0,
823
- {
824
- "id": "S00",
825
- "skill": "context-snapshot-and-plan",
826
- "name": "Plan",
827
- "status": "completed",
828
- "stage_result": "PLAN_READY",
829
- "required_artifacts": [],
830
- "depends_on": None,
831
- },
832
- )
833
- payload["steps"][1]["depends_on"] = "S00"
834
- committer = next(
835
- step for step in payload["steps"] if step["skill"] == "prizmkit-committer"
836
- )
837
- committer["status"] = "in_progress"
838
- committer["stage_result"] = "COMMIT_PENDING"
839
- committer["required_artifacts"] = [
840
- ".prizmkit/specs/feature/runtime-commit-request.json"
841
- ]
842
- artifact_dir = tmp_path / ".prizmkit/specs/feature"
843
- (artifact_dir / "runtime-commit-request.json").write_text("{}", encoding="utf-8")
844
- payload["feature_state"] = {
845
- "stage": "committer",
846
- "status": "in_progress",
847
- "stage_result": "COMMIT_PENDING",
848
- "repair_round": 0,
849
- }
850
- checkpoint = _write(artifact_dir / "workflow-checkpoint.json", payload)
851
-
852
- state = load_checkpoint_state(checkpoint, project_root=tmp_path)
853
-
854
- assert state.valid is True
855
- assert state.semantic_commit_ready is True
856
- assert state.semantic_complete is False
857
- assert state.semantic_snapshot["commit_ready"] is True
858
-
859
-
860
- def test_declared_final_artifact_must_exist_for_completion(tmp_path):
861
- payload = _family_checkpoint(tmp_path)
862
- summary_step = next(
863
- step for step in payload["steps"] if step["skill"] == "completion-summary"
864
- )
865
- summary_step["required_artifacts"] = [
866
- ".prizmkit/specs/feature/completion-summary.json"
867
- ]
868
- checkpoint = _write(
869
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json",
870
- payload,
871
- )
872
-
873
- missing = load_checkpoint_state(checkpoint, project_root=tmp_path)
874
- (checkpoint.parent / "completion-summary.json").write_text("{}", encoding="utf-8")
875
- present = load_checkpoint_state(checkpoint, project_root=tmp_path)
876
-
877
- assert missing.semantic_complete is False
878
- assert missing.semantic.artifacts_valid is False
879
- assert present.semantic_complete is True
880
- assert present.semantic.artifacts_valid is True
881
-
882
-
883
- def test_completion_requires_declared_review_report_with_terminal_pass(tmp_path):
884
- payload = _family_checkpoint(tmp_path)
885
- review = next(
886
- step for step in payload["steps"]
887
- if step["skill"] == "prizmkit-code-review"
888
- )
889
- review["required_artifacts"] = [
890
- ".prizmkit/specs/feature/review-report.md"
891
- ]
892
- checkpoint = _write(
893
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json", payload,
894
- )
895
-
896
- assert load_checkpoint_state(checkpoint, project_root=tmp_path).semantic_complete is False
897
- (checkpoint.parent / "review-report.md").write_text(
898
- "# Review Report\n\n## Final Result\n\n- Verdict: NEEDS_FIXES\n",
899
- encoding="utf-8",
900
- )
901
- assert load_checkpoint_state(checkpoint, project_root=tmp_path).semantic_complete is False
902
- (checkpoint.parent / "review-report.md").write_text(
903
- "# Review Report\n\n## Final Result\n\n- Verdict: PASS\n",
904
- encoding="utf-8",
905
- )
906
- assert load_checkpoint_state(checkpoint, project_root=tmp_path).semantic_complete is True
907
-
908
-
909
- def test_completion_requires_valid_declared_retrospective_result(tmp_path):
910
- payload = _family_checkpoint(tmp_path)
911
- retrospective = next(
912
- step for step in payload["steps"]
913
- if step["skill"] == "prizmkit-retrospective"
914
- )
915
- retrospective["required_artifacts"] = [
916
- ".prizmkit/specs/feature/retrospective-result.json"
917
- ]
918
- checkpoint = _write(
919
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json", payload,
920
- )
921
-
922
- (checkpoint.parent / "retrospective-result.json").write_text(
923
- "{}\n", encoding="utf-8",
924
- )
925
- assert load_checkpoint_state(checkpoint, project_root=tmp_path).semantic_complete is False
926
- (checkpoint.parent / "retrospective-result.json").write_text(
927
- json.dumps(
928
- {
929
- "schema_version": 1,
930
- "outcome": "RETRO_COMPLETE",
931
- "result": "NO_DOC_CHANGE",
932
- "reason": "No durable change",
933
- "change_paths": ["src/example.py"],
934
- "documentation_paths": [],
935
- "validation": [],
936
- }
937
- ),
938
- encoding="utf-8",
939
- )
940
- assert load_checkpoint_state(checkpoint, project_root=tmp_path).semantic_complete is True
941
-
942
-
943
- @pytest.mark.parametrize(
944
- "invalid_path",
945
- [
946
- ".prizmkit/prizm-docs/../escape.prizm",
947
- ".prizmkit/prizm-docs/./module.prizm",
948
- ".prizmkit/prizm-docs//module.prizm",
949
- ".prizmkit\\prizm-docs\\module.prizm",
950
- ".prizmkit/prizm-docs/module.md",
951
- ],
952
- )
953
- def test_completion_rejects_unsafe_retrospective_documentation_path(
954
- tmp_path, invalid_path,
955
- ):
956
- payload = _family_checkpoint(tmp_path)
957
- retrospective = next(
958
- step for step in payload["steps"]
959
- if step["skill"] == "prizmkit-retrospective"
960
- )
961
- retrospective["required_artifacts"] = [
962
- ".prizmkit/specs/feature/retrospective-result.json"
963
- ]
964
- checkpoint = _write(
965
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json", payload,
966
- )
967
- (checkpoint.parent / "retrospective-result.json").write_text(
968
- json.dumps(
969
- {
970
- "schema_version": 1,
971
- "outcome": "RETRO_COMPLETE",
972
- "result": "DOCS_UPDATED",
973
- "reason": "Durable docs changed",
974
- "change_paths": ["src/example.py"],
975
- "documentation_paths": [invalid_path],
976
- "validation": ["validate docs"],
977
- }
978
- ),
979
- encoding="utf-8",
980
- )
981
-
982
- assert load_checkpoint_state(checkpoint, project_root=tmp_path).semantic_complete is False
983
-
984
-
985
- @pytest.mark.parametrize(
986
- "invalid_path",
987
- ["../escape.py", "./src/example.py", "src//example.py", "src\\example.py"],
988
- )
989
- def test_completion_rejects_unsafe_retrospective_change_path(tmp_path, invalid_path):
990
- payload = _family_checkpoint(tmp_path)
991
- retrospective = next(
992
- step for step in payload["steps"]
993
- if step["skill"] == "prizmkit-retrospective"
994
- )
995
- retrospective["required_artifacts"] = [
996
- ".prizmkit/specs/feature/retrospective-result.json"
997
- ]
998
- checkpoint = _write(
999
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json", payload,
1000
- )
1001
- (checkpoint.parent / "retrospective-result.json").write_text(
1002
- json.dumps(
1003
- {
1004
- "schema_version": 1,
1005
- "outcome": "RETRO_COMPLETE",
1006
- "result": "NO_DOC_CHANGE",
1007
- "reason": "No durable change",
1008
- "change_paths": [invalid_path],
1009
- "documentation_paths": [],
1010
- "validation": [],
1011
- }
1012
- ),
1013
- encoding="utf-8",
1014
- )
1015
-
1016
- assert load_checkpoint_state(checkpoint, project_root=tmp_path).semantic_complete is False
1017
-
1018
-
1019
- def test_completion_rejects_configured_verification_after_test(tmp_path):
1020
- payload = _family_checkpoint(tmp_path)
1021
- test_index = next(
1022
- index for index, step in enumerate(payload["steps"])
1023
- if step["skill"] == "prizmkit-test"
1024
- )
1025
- test_step = payload["steps"][test_index]
1026
- following = payload["steps"][test_index + 1]
1027
- payload["steps"].insert(
1028
- test_index + 1,
1029
- {
1030
- "id": "S99",
1031
- "skill": "browser-verification",
1032
- "name": "Browser Verification",
1033
- "status": "completed",
1034
- "required_artifacts": [],
1035
- "depends_on": test_step["id"],
1036
- },
1037
- )
1038
- following["depends_on"] = "S99"
1039
-
1040
- state = validate_checkpoint_data(payload, project_root=tmp_path)
1041
-
1042
- assert state.semantic.sequence_valid is False
1043
- assert "after review and before test" in state.semantic.error_message
1044
-
1045
-
1046
- def test_configured_manual_verification_cannot_be_skipped_for_commit_readiness(tmp_path):
1047
- payload = _family_checkpoint(tmp_path, semantic={}, terminal=False)
1048
- payload["steps"].insert(
1049
- 0,
1050
- {
1051
- "id": "S00",
1052
- "skill": "context-snapshot-and-plan",
1053
- "name": "Plan",
1054
- "status": "completed",
1055
- "stage_result": "PLAN_READY",
1056
- "required_artifacts": [],
1057
- "depends_on": None,
1058
- },
1059
- )
1060
- payload["steps"][1]["depends_on"] = "S00"
1061
- review = next(
1062
- step for step in payload["steps"]
1063
- if step["skill"] == "prizmkit-code-review"
1064
- )
1065
- test = next(
1066
- step for step in payload["steps"] if step["skill"] == "prizmkit-test"
1067
- )
1068
- test_index = payload["steps"].index(test)
1069
- payload["steps"].insert(
1070
- test_index,
1071
- {
1072
- "id": "S99",
1073
- "skill": "manual-verification",
1074
- "name": "Manual Verification",
1075
- "status": "skipped",
1076
- "required_artifacts": [],
1077
- "depends_on": review["id"],
1078
- },
1079
- )
1080
- test["depends_on"] = "S99"
1081
- committer = next(
1082
- step for step in payload["steps"]
1083
- if step["skill"] == "prizmkit-committer"
1084
- )
1085
- committer["status"] = "in_progress"
1086
- committer["stage_result"] = "COMMIT_PENDING"
1087
- committer["required_artifacts"] = [
1088
- ".prizmkit/specs/feature/runtime-commit-request.json"
1089
- ]
1090
- artifact_dir = tmp_path / ".prizmkit/specs/feature"
1091
- (artifact_dir / "runtime-commit-request.json").write_text("{}", encoding="utf-8")
1092
- checkpoint = _write(artifact_dir / "workflow-checkpoint.json", payload)
1093
-
1094
- skipped = load_checkpoint_state(checkpoint, project_root=tmp_path)
1095
- payload["steps"][test_index]["status"] = "completed"
1096
- checkpoint.write_text(json.dumps(payload), encoding="utf-8")
1097
- completed = load_checkpoint_state(checkpoint, project_root=tmp_path)
1098
-
1099
- assert skipped.semantic_commit_ready is False
1100
- assert completed.semantic_commit_ready is True
1101
-
1102
-
1103
- def test_nonpass_test_projection_requires_exact_unresolved_item(tmp_path):
1104
- artifact_dir = _write_test_artifacts(
1105
- tmp_path, slug="nonpass", result="TEST_NEEDS_FIXES"
1106
- )
1107
- result_path = artifact_dir / "test-result.json"
1108
-
1109
- assert load_test_result(result_path) is None
1110
- projection = json.loads(result_path.read_text(encoding="utf-8"))
1111
- projection["unresolved_items"] = ["Public API correction remains"]
1112
- result_path.write_text(json.dumps(projection), encoding="utf-8")
1113
- assert load_test_result(result_path) is not None
1114
-
1115
-
1116
- def test_completion_rejects_invalid_test_result_projection(tmp_path):
1117
- payload = _family_checkpoint(tmp_path)
1118
- checkpoint = _write(
1119
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json",
1120
- payload,
1121
- )
1122
- result_path = checkpoint.parent / "test-result.json"
1123
- result = json.loads(result_path.read_text(encoding="utf-8"))
1124
- result["main_review_rounds"] = 0
1125
- result_path.write_text(json.dumps(result), encoding="utf-8")
1126
-
1127
- state = load_checkpoint_state(checkpoint, project_root=tmp_path)
1128
-
1129
- assert state.semantic_complete is False
1130
- assert state.semantic.artifacts_valid is False
1131
-
1132
-
1133
- def test_completion_rejects_inconsistent_independent_review_metadata(tmp_path):
1134
- payload = _family_checkpoint(tmp_path)
1135
- checkpoint = _write(
1136
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json",
1137
- payload,
1138
- )
1139
- result_path = checkpoint.parent / "test-result.json"
1140
- result = json.loads(result_path.read_text(encoding="utf-8"))
1141
- result["independent_review"] = {
1142
- "status": "completed",
1143
- "responses": 0,
1144
- "downgrade_reason": None,
1145
- "final_state_rechecked": True,
1146
- }
1147
- result_path.write_text(json.dumps(result), encoding="utf-8")
1148
-
1149
- state = load_checkpoint_state(checkpoint, project_root=tmp_path)
1150
-
1151
- assert state.semantic_complete is False
1152
- assert state.semantic.artifacts_valid is False
1153
-
1154
-
1155
- def test_completed_checkpoint_rejects_unknown_test_projection_field(tmp_path):
1156
- payload = _family_checkpoint(tmp_path)
1157
- checkpoint = _write(
1158
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json", payload,
1159
- )
1160
- result_path = checkpoint.parent / "test-result.json"
1161
- projection = json.loads(result_path.read_text(encoding="utf-8"))
1162
- projection["unexpected_field"] = True
1163
- result_path.write_text(json.dumps(projection), encoding="utf-8")
1164
-
1165
- assert load_test_result(result_path) is None
1166
- state = load_checkpoint_state(checkpoint, project_root=tmp_path)
1167
- assert state.semantic_complete is False
1168
- assert state.semantic.artifacts_valid is False
1169
-
1170
-
1171
- def test_completion_accepts_legacy_terminal_result_report(tmp_path):
1172
- payload = _family_checkpoint(tmp_path)
1173
- checkpoint = _write(
1174
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json",
1175
- payload,
1176
- )
1177
- (checkpoint.parent / "test-report.md").write_text(
1178
- "# Test Report\n\n## Terminal Result\n\n- Result: TEST_PASS\n\n"
1179
- "## Final Decision\n\nTEST_PASS\n",
1180
- encoding="utf-8",
1181
- )
1182
-
1183
- state = load_checkpoint_state(checkpoint, project_root=tmp_path)
1184
-
1185
- assert state.semantic_complete is True
1186
- assert state.semantic.artifacts_valid is True
1187
-
1188
-
1189
- def test_completion_rejects_conflicting_supported_report_results(tmp_path):
1190
- payload = _family_checkpoint(tmp_path)
1191
- checkpoint = _write(
1192
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json",
1193
- payload,
1194
- )
1195
- (checkpoint.parent / "test-report.md").write_text(
1196
- "# Test Report\n\n## Terminal Result\n\n- Result: TEST_PASS\n\n"
1197
- "## Final Decision\n\nTEST_BLOCKED\n",
1198
- encoding="utf-8",
1199
- )
1200
-
1201
- state = load_checkpoint_state(checkpoint, project_root=tmp_path)
1202
-
1203
- assert state.semantic_complete is False
1204
- assert state.semantic.artifacts_valid is False
1205
-
1206
-
1207
- def test_completion_rejects_mismatched_test_report_result(tmp_path):
1208
- payload = _family_checkpoint(tmp_path)
1209
- checkpoint = _write(
1210
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json",
1211
- payload,
1212
- )
1213
- (checkpoint.parent / "test-report.md").write_text(
1214
- "# Test Report\n\n## Final Result\n\n- Result: TEST_BLOCKED\n",
1215
- encoding="utf-8",
1216
- )
1217
-
1218
- state = load_checkpoint_state(checkpoint, project_root=tmp_path)
1219
-
1220
- assert state.semantic_complete is False
1221
- assert state.semantic.artifacts_valid is False
1222
-
1223
-
1224
- def test_completion_rejects_report_with_result_only_outside_final_section(tmp_path):
1225
- payload = _family_checkpoint(tmp_path)
1226
- checkpoint = _write(
1227
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json",
1228
- payload,
1229
- )
1230
- (checkpoint.parent / "test-report.md").write_text(
1231
- "# Test Report\n\n## Final Result\n\n- Result: TEST_BLOCKED\n\n"
1232
- "## Remaining Risks and Unresolved Items\n\n- Expected eventual result: TEST_PASS\n",
1233
- encoding="utf-8",
1234
- )
1235
-
1236
- state = load_checkpoint_state(checkpoint, project_root=tmp_path)
1237
-
1238
- assert state.semantic_complete is False
1239
- assert state.semantic.artifacts_valid is False
1240
-
1241
-
1242
- def test_completion_rejects_test_artifacts_outside_project(tmp_path):
1243
- outside = tmp_path.parent / f"{tmp_path.name}-outside"
1244
- outside.mkdir()
1245
- _write_test_artifacts(outside)
1246
- payload = _family_checkpoint(tmp_path)
1247
- test_step = payload["steps"][2]
1248
- test_step["required_artifacts"] = [
1249
- f"../{outside.name}/.prizmkit/specs/feature/test-report.md",
1250
- f"../{outside.name}/.prizmkit/specs/feature/test-result.json",
1251
- ]
1252
- checkpoint = _write(
1253
- tmp_path / ".prizmkit/specs/feature/workflow-checkpoint.json",
1254
- payload,
1255
- )
1256
-
1257
- state = load_checkpoint_state(checkpoint, project_root=tmp_path)
1258
-
1259
- assert state.semantic_complete is False
1260
- assert state.semantic.artifacts_valid is False
1261
-
1262
-
1263
- def test_review_needs_fixes_preserves_implementation_repair_route(tmp_path):
1264
- payload = _family_checkpoint(
1265
- tmp_path,
1266
- semantic={"repair_scope": "production", "repair_round": 0},
1267
- terminal=False,
1268
- )
1269
- payload["steps"][1]["status"] = "in_progress"
1270
- payload["steps"][1].pop("stage_result")
1271
- for step in payload["steps"][2:]:
1272
- step["status"] = "pending"
1273
- step.pop("stage_result", None)
1274
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
1275
-
1276
- result = update_checkpoint(
1277
- str(checkpoint),
1278
- "prizmkit-code-review",
1279
- "failed",
1280
- semantic_update={"stage_result": "REVIEW_NEEDS_FIXES", "repair_scope": "production"},
1281
- )
1282
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
1283
-
1284
- assert result["ok"] is True
1285
- assert result["semantic"]["next_stage"] == "prizmkit-implement"
1286
- assert persisted["feature_state"]["repair_round"] == 1
1287
- assert persisted["feature_state"]["current_stage"] == "prizmkit-code-review"
1288
- assert persisted["feature_state"]["next_stage"] == "prizmkit-implement"
1289
-
1290
-
1291
- def test_review_outer_repair_cap_remains_runtime_owned(tmp_path):
1292
- payload = _family_checkpoint(
1293
- tmp_path, semantic={"repair_scope": "production", "repair_round": 3},
1294
- terminal=False,
1295
- )
1296
- payload["steps"][1]["status"] = "in_progress"
1297
- payload["steps"][1].pop("stage_result")
1298
- for step in payload["steps"][2:]:
1299
- step["status"] = "pending"
1300
- step.pop("stage_result", None)
1301
- checkpoint = _write(tmp_path / "workflow-checkpoint.json", payload)
1302
-
1303
- result = update_checkpoint(
1304
- str(checkpoint),
1305
- "prizmkit-code-review",
1306
- "failed",
1307
- semantic_update={"stage_result": "REVIEW_NEEDS_FIXES", "repair_scope": "production"},
1308
- )
1309
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
1310
-
1311
- assert result["ok"] is True
1312
- assert persisted["feature_state"]["repair_round"] == 3
1313
- assert persisted["feature_state"]["blocked_reason"] == "repair_round_limit"
1314
- assert persisted["feature_state"]["terminal_status"] == "WORKFLOW_BLOCKED"