prizmkit 1.1.190 → 1.1.192

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 (189) hide show
  1. package/bin/create-prizmkit.js +4 -4
  2. package/bundled/VERSION.json +3 -3
  3. package/bundled/adapters/antigravity/assets/prizmkit-hook.cjs +150 -0
  4. package/bundled/adapters/antigravity/hooks-adapter.js +195 -0
  5. package/bundled/adapters/antigravity/paths.js +14 -0
  6. package/bundled/adapters/antigravity/rules-adapter.js +54 -0
  7. package/bundled/adapters/antigravity/skill-adapter.js +38 -0
  8. package/bundled/adapters/codex/skill-adapter.js +28 -8
  9. package/bundled/adapters/cursor/skill-adapter.js +13 -4
  10. package/bundled/adapters/pi/skill-adapter.js +28 -7
  11. package/bundled/dev-pipeline/.env.example +4 -12
  12. package/bundled/dev-pipeline/README.md +21 -15
  13. package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -6
  14. package/bundled/dev-pipeline/prizmkit_runtime/atomic_io.py +48 -0
  15. package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +66 -23
  16. package/bundled/dev-pipeline/prizmkit_runtime/cli.py +10 -7
  17. package/bundled/dev-pipeline/prizmkit_runtime/commands.py +2 -21
  18. package/bundled/dev-pipeline/prizmkit_runtime/config.py +29 -70
  19. package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +125 -67
  20. package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +89 -442
  21. package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +93 -49
  22. package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +1 -3
  23. package/bundled/dev-pipeline/prizmkit_runtime/paths.py +0 -6
  24. package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +49 -18
  25. package/bundled/dev-pipeline/prizmkit_runtime/processes.py +206 -151
  26. package/bundled/dev-pipeline/prizmkit_runtime/reset.py +2 -23
  27. package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +15 -134
  28. package/bundled/dev-pipeline/prizmkit_runtime/results.py +25 -0
  29. package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +68 -83
  30. package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +15 -5
  31. package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +1 -29
  32. package/bundled/dev-pipeline/prizmkit_runtime/runner_prompts.py +0 -2
  33. package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +7 -2
  34. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +282 -217
  35. package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +124 -122
  36. package/bundled/dev-pipeline/prizmkit_runtime/runtime_helper.py +90 -9
  37. package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +369 -154
  38. package/bundled/dev-pipeline/prizmkit_runtime/status.py +3 -3
  39. package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +2780 -0
  40. package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +27 -101
  41. package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +58 -4
  42. package/bundled/dev-pipeline/scripts/check-session-status.py +43 -19
  43. package/bundled/dev-pipeline/scripts/continuation.py +6 -4
  44. package/bundled/dev-pipeline/scripts/detect-stuck.py +28 -28
  45. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +7 -2
  46. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +7 -2
  47. package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +10 -7
  48. package/bundled/dev-pipeline/scripts/init-change-artifact.py +8 -2
  49. package/bundled/dev-pipeline/scripts/init-pipeline.py +14 -69
  50. package/bundled/dev-pipeline/scripts/parse-stream-progress.py +31 -2328
  51. package/bundled/dev-pipeline/scripts/patch-completion-notes.py +4 -24
  52. package/bundled/dev-pipeline/scripts/prompt_framework.py +56 -9
  53. package/bundled/dev-pipeline/scripts/status_common.py +591 -0
  54. package/bundled/dev-pipeline/scripts/update-bug-status.py +85 -463
  55. package/bundled/dev-pipeline/scripts/update-checkpoint.py +227 -65
  56. package/bundled/dev-pipeline/scripts/update-feature-status.py +76 -509
  57. package/bundled/dev-pipeline/scripts/utils.py +10 -15
  58. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +4 -4
  59. package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +7 -0
  60. package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +1 -1
  61. package/bundled/dev-pipeline/templates/sections/artifact-manifest.md +1 -1
  62. package/bundled/dev-pipeline/templates/sections/bugfix-phase-manual-verification.md +1 -1
  63. package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +1 -1
  64. package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +2 -1
  65. package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +1 -1
  66. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-auto.md +1 -1
  67. package/bundled/dev-pipeline/templates/sections/phase-browser-verification-opencli.md +2 -2
  68. package/bundled/dev-pipeline/templates/sections/phase-browser-verification.md +2 -2
  69. package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +2 -1
  70. package/bundled/dev-pipeline/templates/sections/phase-review-full.md +1 -1
  71. package/bundled/dev-pipeline/templates/sections/phase-specify-plan-full.md +3 -6
  72. package/bundled/dev-pipeline/templates/session-status-schema.json +2 -5
  73. package/bundled/dev-pipeline/tests/_helpers.py +418 -0
  74. package/bundled/dev-pipeline/tests/conftest.py +45 -1
  75. package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +1 -0
  76. package/bundled/dev-pipeline/tests/test_auto_skip.py +4 -69
  77. package/bundled/dev-pipeline/tests/test_checkpoint_state.py +126 -1
  78. package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +257 -0
  79. package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +500 -0
  80. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +59 -117
  81. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +12 -10
  82. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +561 -3094
  83. package/bundled/dev-pipeline/tests/test_recovery_workflow.py +7 -8
  84. package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -1
  85. package/bundled/dev-pipeline/tests/test_reset_modes.py +15 -27
  86. package/bundled/dev-pipeline/tests/test_reset_preserve.py +54 -139
  87. package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +766 -0
  88. package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +1257 -0
  89. package/bundled/dev-pipeline/tests/test_runtime_helper.py +97 -20
  90. package/bundled/dev-pipeline/tests/test_session_launch.py +1101 -0
  91. package/bundled/dev-pipeline/tests/test_stream_progress.py +585 -0
  92. package/bundled/dev-pipeline/tests/test_unified_cli.py +490 -2006
  93. package/bundled/dev-pipeline/tests/test_utils.py +3 -3
  94. package/bundled/rules/USAGE.md +1 -0
  95. package/bundled/skills/_metadata.json +9 -63
  96. package/bundled/skills/app-planner/SKILL.md +32 -303
  97. package/bundled/skills/app-planner/references/app-design-guide.md +0 -4
  98. package/bundled/skills/app-planner/references/generated-plan-review.md +2 -1
  99. package/bundled/skills/app-planner/references/project-brief-guide.md +14 -0
  100. package/bundled/skills/app-planner/references/project-conventions-discovery.md +4 -6
  101. package/bundled/skills/app-planner/references/project-state-detection.md +2 -3
  102. package/bundled/skills/bug-fix-workflow/SKILL.md +1 -2
  103. package/bundled/skills/bug-fix-workflow/references/bug-diagnosis.md +4 -7
  104. package/bundled/skills/bug-planner/SKILL.md +54 -435
  105. package/bundled/skills/bug-planner/references/generated-plan-review.md +3 -2
  106. package/bundled/skills/bug-planner/references/input-formats.md +32 -0
  107. package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +4 -6
  108. package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +4 -28
  109. package/bundled/skills/feature-pipeline-launcher/SKILL.md +4 -6
  110. package/bundled/skills/feature-pipeline-launcher/references/configuration.md +4 -28
  111. package/bundled/skills/feature-planner/SKILL.md +60 -439
  112. package/bundled/skills/feature-planner/assets/planning-guide.md +1 -1
  113. package/bundled/skills/feature-planner/references/completeness-review.md +34 -0
  114. package/bundled/skills/feature-planner/references/decomposition-patterns.md +2 -2
  115. package/bundled/skills/feature-planner/references/error-recovery.md +1 -1
  116. package/bundled/skills/feature-planner/references/generated-plan-review.md +3 -2
  117. package/bundled/skills/feature-planner/references/incremental-feature-planning.md +3 -1
  118. package/bundled/skills/feature-workflow/SKILL.md +1 -2
  119. package/bundled/skills/prizmkit/SKILL.md +7 -1
  120. package/bundled/skills/prizmkit-code-review/SKILL.md +14 -6
  121. package/bundled/skills/prizmkit-code-review/references/independent-code-review.md +7 -4
  122. package/bundled/skills/prizmkit-code-review/references/review-report-template.md +16 -0
  123. package/bundled/skills/prizmkit-code-review/scripts/render_review_report.py +58 -20
  124. package/bundled/skills/prizmkit-implement/SKILL.md +1 -1
  125. package/bundled/skills/prizmkit-init/SKILL.md +25 -128
  126. package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
  127. package/bundled/skills/prizmkit-init/references/config-schema.md +2 -2
  128. package/bundled/skills/prizmkit-plan/SKILL.md +6 -8
  129. package/bundled/skills/prizmkit-plan/references/clarify-guide.md +1 -1
  130. package/bundled/skills/prizmkit-plan/references/independent-plan-review.md +5 -2
  131. package/bundled/skills/prizmkit-plan/references/review-plan-spec-loop.md +6 -5
  132. package/bundled/skills/prizmkit-prizm-docs/SKILL.md +1 -13
  133. package/bundled/skills/prizmkit-prizm-docs/assets/prizm-docs-format.md +1 -1
  134. package/bundled/skills/prizmkit-prizm-docs/references/op-init.md +1 -1
  135. package/bundled/skills/prizmkit-prizm-docs/references/op-update.md +1 -1
  136. package/bundled/skills/prizmkit-retrospective/SKILL.md +6 -4
  137. package/bundled/skills/prizmkit-test/SKILL.md +25 -133
  138. package/bundled/skills/prizmkit-test/references/independent-test-review.md +5 -2
  139. package/bundled/skills/prizmkit-test/references/test-coverage-model.md +6 -0
  140. package/bundled/skills/prizmkit-workflow/SKILL.md +2 -3
  141. package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +4 -3
  142. package/bundled/skills/recovery-workflow/SKILL.md +7 -7
  143. package/bundled/skills/recovery-workflow/evals/evals.json +1 -1
  144. package/bundled/skills/recovery-workflow/references/detection.md +1 -3
  145. package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +0 -6
  146. package/bundled/templates/project-memory-template.md +1 -2
  147. package/package.json +1 -1
  148. package/src/ai-cli-launch.js +1 -1
  149. package/src/clean.js +40 -4
  150. package/src/config.js +64 -4
  151. package/src/detect-platform.js +10 -6
  152. package/src/external-skills.js +2 -2
  153. package/src/index.js +1 -0
  154. package/src/manifest.js +1 -1
  155. package/src/platforms.js +6 -2
  156. package/src/prompts.js +11 -3
  157. package/src/scaffold.js +87 -11
  158. package/src/upgrade.js +9 -3
  159. package/bundled/dev-pipeline/SCHEMA_ANALYSIS.md +0 -53
  160. package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +0 -649
  161. package/bundled/dev-pipeline/scripts/init-refactor-pipeline.py +0 -463
  162. package/bundled/dev-pipeline/scripts/update-refactor-status.py +0 -1512
  163. package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +0 -240
  164. package/bundled/dev-pipeline/templates/refactor-list-schema.json +0 -266
  165. package/bundled/dev-pipeline/templates/sections/refactor-critical-paths.md +0 -15
  166. package/bundled/dev-pipeline/templates/sections/refactor-mission.md +0 -9
  167. package/bundled/dev-pipeline/templates/sections/refactor-phase-commit-report.md +0 -24
  168. package/bundled/dev-pipeline/templates/sections/refactor-phase-implement.md +0 -16
  169. package/bundled/dev-pipeline/templates/sections/refactor-phase-init.md +0 -9
  170. package/bundled/dev-pipeline/templates/sections/refactor-phase-plan.md +0 -22
  171. package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +0 -19
  172. package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +0 -24
  173. package/bundled/dev-pipeline/templates/sections/refactor-reminders.md +0 -12
  174. package/bundled/dev-pipeline/templates/sections/refactor-session-context.md +0 -6
  175. package/bundled/dev-pipeline/templates/sections/refactor-task-contract.md +0 -52
  176. package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +0 -478
  177. package/bundled/skills/feature-planner/assets/evaluation-guide.md +0 -44
  178. package/bundled/skills/refactor-pipeline-launcher/SKILL.md +0 -219
  179. package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +0 -78
  180. package/bundled/skills/refactor-planner/SKILL.md +0 -467
  181. package/bundled/skills/refactor-planner/assets/planning-guide.md +0 -291
  182. package/bundled/skills/refactor-planner/references/behavior-preservation.md +0 -187
  183. package/bundled/skills/refactor-planner/references/error-recovery.md +0 -45
  184. package/bundled/skills/refactor-planner/references/fast-path.md +0 -59
  185. package/bundled/skills/refactor-planner/references/generated-plan-review.md +0 -107
  186. package/bundled/skills/refactor-planner/references/planning-phases.md +0 -172
  187. package/bundled/skills/refactor-planner/references/refactor-scoping-guide.md +0 -230
  188. package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +0 -1120
  189. package/bundled/skills/refactor-workflow/SKILL.md +0 -205
@@ -16,7 +16,11 @@ from prizmkit_runtime.checkpoint_state import (
16
16
  read_checkpoint_cursor,
17
17
  validate_checkpoint_data,
18
18
  )
19
- from prizmkit_runtime.test_result import load_test_result
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
+ )
20
24
  from update_checkpoint import update_checkpoint
21
25
 
22
26
 
@@ -1312,3 +1316,124 @@ def test_review_outer_repair_cap_remains_runtime_owned(tmp_path):
1312
1316
  assert persisted["feature_state"]["repair_round"] == 3
1313
1317
  assert persisted["feature_state"]["blocked_reason"] == "repair_round_limit"
1314
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"
@@ -0,0 +1,257 @@
1
+ """Tests for daemon edge cases, status scripts, stuck detection, and status_common parity."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import importlib.util
6
+ import json
7
+ import os
8
+ import subprocess
9
+ import sys
10
+ from datetime import datetime, timedelta, timezone
11
+ from pathlib import Path
12
+
13
+ import pytest
14
+
15
+ from _helpers import PIPELINE_ROOT, PYTHON_310_PLUS, make_runtime_paths
16
+
17
+
18
+ def _load_script(name: str, filename: str):
19
+ path = PIPELINE_ROOT / "scripts" / filename
20
+ spec = importlib.util.spec_from_file_location(name, path)
21
+ module = importlib.util.module_from_spec(spec)
22
+ assert spec.loader is not None
23
+ spec.loader.exec_module(module)
24
+ return module
25
+
26
+
27
+ def _write_minimal_feature_plan(plan_path: Path) -> None:
28
+ plan_path.write_text(
29
+ json.dumps(
30
+ {
31
+ "$schema": "dev-pipeline-feature-list-v1",
32
+ "project_name": "Demo",
33
+ "features": [
34
+ {
35
+ "id": "F-001",
36
+ "title": "Sample",
37
+ "description": "Sample",
38
+ "priority": "high",
39
+ "dependencies": [],
40
+ "acceptance_criteria": ["ok"],
41
+ "status": "pending",
42
+ }
43
+ ],
44
+ }
45
+ ),
46
+ encoding="utf-8",
47
+ )
48
+
49
+
50
+ def test_daemon_start_lock_fast_exit_crash_tail_and_invalid_env(monkeypatch, tmp_path):
51
+ from prizmkit_runtime import daemon
52
+ from prizmkit_runtime.runner_models import family_for
53
+
54
+ paths = make_runtime_paths(tmp_path)
55
+ _write_minimal_feature_plan(paths.feature_plan)
56
+ family = family_for("feature", paths)
57
+ daemon_paths = daemon._daemon_paths(family)
58
+
59
+ # 1. Start lock contention
60
+ daemon_paths.start_lock.mkdir(parents=True, exist_ok=True)
61
+ (daemon_paths.start_lock / "owner.json").write_text(f'{{"pid": {os.getpid()}}}\n', encoding="utf-8")
62
+ locked = daemon.run_daemon_command("feature", "start", (str(paths.feature_plan),), paths)
63
+ assert locked.exit_code == 1
64
+ assert "already in progress" in locked.stderr
65
+ (daemon_paths.start_lock / "owner.json").unlink()
66
+ daemon_paths.start_lock.rmdir()
67
+
68
+ # 2. Invalid --env key rejection
69
+ with pytest.raises(ValueError, match="Invalid --env variable name"):
70
+ daemon._parse_start_args(family, (str(paths.feature_plan), "--env", "BAD-KEY=1"))
71
+
72
+ # 3. Fast exit code 0 within startup window
73
+ monkeypatch.setattr(daemon, "_start_verify_seconds", lambda: 0.4)
74
+ monkeypatch.setattr(
75
+ daemon,
76
+ "_payload_command",
77
+ lambda *_args: [sys.executable, "-c", "print('quick completion')"],
78
+ )
79
+ fast = daemon.run_daemon_command("feature", "start", (str(paths.feature_plan),), paths)
80
+ assert fast.exit_code == 0
81
+ fast_payload = json.loads(fast.stdout)
82
+ assert fast_payload["completed"] is True
83
+ assert fast_payload["exit_code"] == 0
84
+ assert not daemon_paths.pid_file.exists()
85
+
86
+ # 4. Immediate crash includes log tail in stderr
87
+ monkeypatch.setattr(
88
+ daemon,
89
+ "_payload_command",
90
+ lambda *_args: [sys.executable, "-c", "import sys; print('fatal crash marker'); sys.exit(1)"],
91
+ )
92
+ crashed = daemon.run_daemon_command("feature", "start", (str(paths.feature_plan),), paths)
93
+ assert crashed.exit_code == 1
94
+ assert "died immediately after launch" in crashed.stderr
95
+ assert "--- Last log lines ---" in crashed.stderr
96
+ assert "fatal crash marker" in crashed.stderr
97
+ assert not daemon_paths.pid_file.exists()
98
+
99
+
100
+ def test_check_session_status_accepts_canonical_and_legacy_schemas(tmp_path):
101
+ mod = _load_script("check_session_status_mod", "check-session-status.py")
102
+
103
+ canonical_statuses = (
104
+ "success",
105
+ "failed",
106
+ "crashed",
107
+ "timed_out",
108
+ "infra_error",
109
+ "commit_missing",
110
+ "docs_missing",
111
+ "merge_conflict",
112
+ "context_overflow",
113
+ "stalled_context_continuation",
114
+ "workflow_blocked",
115
+ "workflow_skipped",
116
+ )
117
+ for status in canonical_statuses:
118
+ payload = {
119
+ "session_id": "F-001-sess-1",
120
+ "task_id": "F-001",
121
+ "task_type": "feature",
122
+ "status": status,
123
+ "checkpoint_state": {"current_stage": "prizmkit-test", "stage_result": "TEST_PASS"},
124
+ }
125
+ assert mod.validate_required_fields(payload) == []
126
+ assert mod.determine_status(payload) == status
127
+ report = mod.build_detail_report(payload, status)
128
+ assert report["task_id"] == "F-001"
129
+ assert report["task_type"] == "feature"
130
+ assert report["checkpoint_state"] == payload["checkpoint_state"]
131
+
132
+ # Legacy format still requires timestamp, while missing task_id|feature_id|bug_id is diagnosed
133
+ assert mod.validate_required_fields(
134
+ {"session_id": "s1", "feature_id": "F-001", "status": "success", "timestamp": "2026-01-01T00:00:00Z"}
135
+ ) == []
136
+ assert "timestamp" in mod.validate_required_fields(
137
+ {"session_id": "s1", "feature_id": "F-001", "status": "success"}
138
+ )
139
+ assert "task_id|feature_id|bug_id" in mod.validate_required_fields(
140
+ {"session_id": "s1", "status": "success"}
141
+ )
142
+
143
+ status_file = tmp_path / "session-status.json"
144
+ status_file.write_text(
145
+ json.dumps(
146
+ {
147
+ "session_id": "B-001-sess-1",
148
+ "task_id": "B-001",
149
+ "task_type": "bugfix",
150
+ "status": "workflow_blocked",
151
+ }
152
+ ),
153
+ encoding="utf-8",
154
+ )
155
+ proc = subprocess.run(
156
+ [PYTHON_310_PLUS, str(PIPELINE_ROOT / "scripts" / "check-session-status.py"), "--status-file", str(status_file)],
157
+ text=True,
158
+ stdout=subprocess.PIPE,
159
+ stderr=subprocess.PIPE,
160
+ check=False,
161
+ )
162
+ assert proc.returncode == 0
163
+ assert proc.stdout.strip() == "workflow_blocked"
164
+ detail = json.loads(proc.stderr)
165
+ assert detail["task_id"] == "B-001"
166
+ assert detail["task_type"] == "bugfix"
167
+
168
+
169
+ def test_detect_stuck_handles_canonical_checkpoint_state_and_heartbeat_fields(tmp_path):
170
+ mod = _load_script("detect_stuck_mod", "detect-stuck.py")
171
+
172
+ item_dir = tmp_path / "state" / "features" / "F-001"
173
+ for idx in (1, 2, 3):
174
+ session_dir = item_dir / "sessions" / f"F-001-session-{idx}"
175
+ session_dir.mkdir(parents=True)
176
+ (session_dir / "session-status.json").write_text(
177
+ json.dumps(
178
+ {
179
+ "session_id": f"F-001-session-{idx}",
180
+ "task_id": "F-001",
181
+ "task_type": "feature",
182
+ "status": "failed",
183
+ "checkpoint_state": {
184
+ "current_stage": "prizmkit-implement",
185
+ "stage_result": "IMPLEMENT_REPAIR",
186
+ },
187
+ }
188
+ ),
189
+ encoding="utf-8",
190
+ )
191
+
192
+ stuck = mod.check_stuck_checkpoint(item_dir)
193
+ assert stuck is not None
194
+ assert stuck["reason"] == "stuck_at_checkpoint"
195
+ assert "prizmkit-implement:IMPLEMENT_REPAIR" in stuck["details"]
196
+
197
+ # Heartbeat supporting last_heartbeat_at and updated_at
198
+ hb_path = item_dir / "sessions" / "F-001-session-3" / "heartbeat.json"
199
+ now = datetime.now(timezone.utc)
200
+ fresh = (now - timedelta(seconds=10)).strftime("%Y-%m-%dT%H:%M:%SZ")
201
+ stale = (now - timedelta(seconds=600)).strftime("%Y-%m-%dT%H:%M:%SZ")
202
+ item_status = {"last_session_id": "F-001-session-3"}
203
+
204
+ hb_path.write_text(json.dumps({"last_heartbeat_at": fresh}), encoding="utf-8")
205
+ assert mod.check_stale_heartbeat("F-001", item_status, tmp_path / "state", "features", 120, "in_progress") is None
206
+
207
+ hb_path.write_text(json.dumps({"updated_at": stale}), encoding="utf-8")
208
+ stale_report = mod.check_stale_heartbeat("F-001", item_status, tmp_path / "state", "features", 120, "in_progress")
209
+ assert stale_report is not None
210
+ assert stale_report["reason"] == "stale_heartbeat"
211
+
212
+
213
+ def test_status_common_parity_across_feature_and_bugfix_updaters(tmp_path):
214
+ feat_mod = _load_script("update_feature_status_parity", "update-feature-status.py")
215
+ bug_mod = _load_script("update_bug_status_parity", "update-bug-status.py")
216
+
217
+ feat_plan = tmp_path / "feature-list.json"
218
+ feat_state = tmp_path / "feat-state"
219
+ feat_state.mkdir()
220
+ feat_plan.write_text(
221
+ json.dumps(
222
+ {
223
+ "features": [
224
+ {"id": "F-001", "title": "Root", "status": "failed", "dependencies": []},
225
+ {"id": "F-002", "title": "Child", "status": "pending", "dependencies": ["F-001"]},
226
+ ]
227
+ }
228
+ ),
229
+ encoding="utf-8",
230
+ )
231
+ skipped_f = feat_mod.auto_skip_blocked_features(str(feat_plan), str(feat_state), "F-001")
232
+ assert [entry["feature_id"] for entry in skipped_f] == ["F-002"]
233
+ assert feat_mod.get_feature_status_from_list(str(feat_plan), "F-002") == "auto_skipped"
234
+ feat_mod.update_feature_in_list(str(feat_plan), "F-001", "pending")
235
+ assert feat_mod.reconcile_orphaned_auto_skipped_features(str(feat_plan), str(feat_state)) == ["F-002"]
236
+ assert feat_mod.get_feature_status_from_list(str(feat_plan), "F-002") == "pending"
237
+
238
+ bug_plan = tmp_path / "bug-fix-list.json"
239
+ bug_state = tmp_path / "bug-state"
240
+ bug_state.mkdir()
241
+ bug_plan.write_text(
242
+ json.dumps(
243
+ {
244
+ "bugs": [
245
+ {"id": "B-001", "title": "Root", "status": "needs_info", "dependencies": []},
246
+ {"id": "B-002", "title": "Child", "status": "pending", "dependencies": ["B-001"]},
247
+ ]
248
+ }
249
+ ),
250
+ encoding="utf-8",
251
+ )
252
+ skipped_b = bug_mod.auto_skip_blocked_bugs(str(bug_plan), str(bug_state), "B-001")
253
+ assert [entry["bug_id"] for entry in skipped_b] == ["B-002"]
254
+ assert bug_mod.get_bug_status_from_list(str(bug_plan), "B-002") == "auto_skipped"
255
+ bug_mod.update_bug_in_list(str(bug_plan), "B-001", "pending")
256
+ assert bug_mod.reconcile_orphaned_auto_skipped_bugs(str(bug_plan), str(bug_state)) == ["B-002"]
257
+ assert bug_mod.get_bug_status_from_list(str(bug_plan), "B-002") == "pending"