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