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,1712 +0,0 @@
1
- """Tests for generate-bootstrap-prompt.py core functions."""
2
-
3
- import json
4
- import os
5
- import re
6
- from argparse import Namespace
7
- from pathlib import Path
8
-
9
- from generate_bootstrap_prompt import (
10
- ACTIVE_AGENT_PROMPTS,
11
- compute_feature_slug,
12
- detect_test_commands,
13
- find_feature,
14
- format_acceptance_criteria,
15
- format_ac_checklist,
16
- format_global_context,
17
- get_completed_dependencies,
18
- process_conditional_blocks,
19
- process_template_blocks,
20
- assemble_sections,
21
- build_replacements,
22
- generate_checkpoint_definition,
23
- merge_checkpoint_state,
24
- load_active_agent_prompts,
25
- validate_rendered,
26
- route_feature_repair,
27
- feature_checkpoint_metadata,
28
- main as generate_bootstrap_main,
29
- )
30
- from continuation import append_continuation_handoff, checkpoint_cursor
31
- from prompt_framework import pipeline_checkpoint_metadata
32
- from utils import resolve_prompt_platform
33
-
34
- REMOVED_MAX_LOG_ENV = "MAX_" + "LOG_SIZE"
35
- REMOVED_MAX_LOG_HUMAN = REMOVED_MAX_LOG_ENV + "_HUMAN"
36
-
37
- FORBIDDEN_DEV_FIX_PROMPT = "dev-" + "fix.md"
38
- FORBIDDEN_DEV_RESUME_PROMPT = "dev-" + "resume.md"
39
- FORBIDDEN_DEV_FIX_PLACEHOLDER = "{{AGENT_PROMPT_DEV_" + "FIX}}"
40
- FORBIDDEN_DEV_RESUME_PLACEHOLDER = "{{AGENT_PROMPT_DEV_" + "RESUME}}"
41
- FORBIDDEN_REVIEW_DEV_FIX = "Reviewer Agent → filter → " + "Dev Agent fix"
42
- FORBIDDEN_REVIEWER_DEV_SPAWN = "Reviewer/" + "Dev agent spawn"
43
- FORBIDDEN_EXPLORE_SUBAGENT = "subagent_type: " + "Explore"
44
- FORBIDDEN_TEST_CMD_PLACEHOLDER = "(" + "$TEST_CMD" + ")"
45
- FORBIDDEN_THREE_STRIKE = "3-" + "strike"
46
- FORBIDDEN_TWENTY_STEP = "20-" + "step window"
47
-
48
- REVIEW_PROMPT_REQUIRED = (
49
- "review-report.md",
50
- "Final Result",
51
- )
52
-
53
- REVIEW_PROMPT_FORBIDDEN = (
54
- "Orchestrator + Reviewer",
55
- "Reviewer reviews",
56
- "Reviewer subagents",
57
- "Reviewer appends Review Notes",
58
- "Implementation Log/Review Notes",
59
- "internal Reviewer Agent",
60
- "spawning Reviewer",
61
- "delayed teammate/reviewer findings",
62
- "Gate checks enforce Implementation Log and Review Notes",
63
- )
64
-
65
-
66
- def assert_unambiguous_main_agent_review(prompt):
67
- for required in REVIEW_PROMPT_REQUIRED:
68
- assert required in prompt
69
- for forbidden in REVIEW_PROMPT_FORBIDDEN:
70
- assert forbidden not in prompt
71
-
72
-
73
- PROMPT_RENDERING_FORBIDDEN = (
74
- "If implementation is delegated to a Dev subagent",
75
- "Document in Implementation Log or review notes",
76
- "{{INIT_SCRIPT_PATH}}",
77
- )
78
-
79
-
80
- def assert_complete_prompt_rendering(prompt):
81
- assert_unambiguous_main_agent_review(prompt)
82
- for forbidden in PROMPT_RENDERING_FORBIDDEN:
83
- assert forbidden not in prompt
84
- assert re.findall(r"\{\{[A-Z][A-Z_0-9]+\}\}", prompt) == []
85
-
86
-
87
- def test_rendered_prompt_validation_rejects_unresolved_control_placeholders():
88
- content = (
89
- "## Your Mission\n"
90
- "## Execution\n"
91
- "Run {{INIT_SCRIPT_PATH}}\n"
92
- "## Failure Capture\n"
93
- )
94
-
95
- is_valid, warnings, errors = validate_rendered(content)
96
-
97
- assert is_valid is False
98
- assert warnings == []
99
- assert errors == ["Unreplaced placeholders: {{INIT_SCRIPT_PATH}}"]
100
-
101
-
102
-
103
- # ---------------------------------------------------------------------------
104
- # compute_feature_slug
105
- # ---------------------------------------------------------------------------
106
-
107
- class TestComputeFeatureSlug:
108
- def test_basic(self):
109
- assert compute_feature_slug("F-001", "Project Infrastructure Setup") == "001-project-infrastructure-setup"
110
-
111
- def test_strips_special_chars(self):
112
- assert compute_feature_slug("F-012", "Add (User) Auth!") == "012-add-user-auth"
113
-
114
- def test_pads_numeric(self):
115
- assert compute_feature_slug("F-1", "Init") == "001-init"
116
-
117
- def test_collapses_hyphens(self):
118
- assert compute_feature_slug("F-003", "foo - - bar") == "003-foo---bar" or \
119
- compute_feature_slug("F-003", "foo bar") == "003-foo-bar"
120
-
121
- def test_empty_title(self):
122
- result = compute_feature_slug("F-099", "")
123
- assert result == "099-"
124
-
125
-
126
- # ---------------------------------------------------------------------------
127
- # find_feature
128
- # ---------------------------------------------------------------------------
129
-
130
- class TestFindFeature:
131
- def test_found(self):
132
- features = [{"id": "F-001", "title": "A"}, {"id": "F-002", "title": "B"}]
133
- assert find_feature(features, "F-002") == {"id": "F-002", "title": "B"}
134
-
135
- def test_not_found(self):
136
- assert find_feature([{"id": "F-001"}], "F-999") is None
137
-
138
- def test_empty_list(self):
139
- assert find_feature([], "F-001") is None
140
-
141
- def test_non_dict_items(self):
142
- assert find_feature(["garbage", 42, None, {"id": "F-001"}], "F-001") == {"id": "F-001"}
143
-
144
-
145
- # ---------------------------------------------------------------------------
146
- # format_acceptance_criteria
147
- # ---------------------------------------------------------------------------
148
-
149
- class TestFormatAcceptanceCriteria:
150
- def test_none(self):
151
- assert format_acceptance_criteria(None) == "- (none specified)"
152
-
153
- def test_empty(self):
154
- assert format_acceptance_criteria([]) == "- (none specified)"
155
-
156
- def test_items(self):
157
- result = format_acceptance_criteria(["Users can log in", "Password reset works"])
158
- assert "- Users can log in" in result
159
- assert "- Password reset works" in result
160
-
161
-
162
- class TestFormatAcChecklist:
163
- def test_empty_does_not_create_unchecked_gate(self):
164
- result = format_ac_checklist([])
165
- assert result == "- (no Verification Gates specified)"
166
- assert "[ ]" not in result
167
-
168
- def test_items_are_unchecked_verification_gates(self):
169
- result = format_ac_checklist(["Users can log in", "Password reset works"])
170
- assert "- [ ] Users can log in" in result
171
- assert "- [ ] Password reset works" in result
172
-
173
-
174
- # ---------------------------------------------------------------------------
175
- # format_global_context
176
- # ---------------------------------------------------------------------------
177
-
178
- class TestFormatGlobalContext:
179
- def test_none(self):
180
- assert format_global_context(None) == "- (none specified)"
181
-
182
- def test_empty(self):
183
- assert format_global_context({}) == "- (none specified)"
184
-
185
- def test_dict(self):
186
- result = format_global_context({"frontend_framework": "React", "lang": "TypeScript"})
187
- assert "**frontend_framework**: React" in result
188
- assert "**lang**: TypeScript" in result
189
-
190
-
191
- class TestExplicitProjectRoot:
192
- def test_build_replacements_uses_cli_project_root_for_rendered_paths(self, tmp_path, monkeypatch):
193
- monkeypatch.setenv("PRIZMKIT_PLATFORM", "claude")
194
- execution_root = tmp_path / "worktree"
195
- main_checkout = tmp_path / "main"
196
- execution_root.mkdir()
197
- main_checkout.mkdir()
198
- (execution_root / ".prizmkit" / "plans").mkdir(parents=True)
199
- (execution_root / ".prizmkit" / "plans" / "project-brief.md").write_text("worktree brief", encoding="utf-8")
200
- args = Namespace(
201
- feature_list=str(main_checkout / ".prizmkit" / "plans" / "feature-list.json"),
202
- feature_id="F-001",
203
- session_id="session-1",
204
- run_id="run-1",
205
- retry_count="0",
206
- resume_phase="null",
207
- state_dir=str(main_checkout / ".prizmkit" / "state" / "features"),
208
- output=str(main_checkout / ".prizmkit" / "state" / "features" / "F-001" / "sessions" / "session-1" / "bootstrap-prompt.md"),
209
- template=None,
210
- extract_baselines=False,
211
- project_root=str(execution_root),
212
- )
213
- feature = {"id": "F-001", "title": "Worktree Prompt", "estimated_complexity": "medium"}
214
-
215
- replacements, _resume, _browser_enabled, _browser_tool = build_replacements(
216
- args,
217
- feature,
218
- [feature],
219
- {},
220
- str(main_checkout / "dev-pipeline" / "scripts"),
221
- )
222
-
223
- assert replacements["{{PROJECT_ROOT}}"] == str(execution_root.resolve())
224
- assert replacements["{{SESSION_STATUS_PATH}}"] == str(
225
- main_checkout / ".prizmkit" / "state" / "features" / "F-001" /
226
- "sessions" / "session-1" / "session-status.json"
227
- )
228
- assert not replacements["{{SESSION_STATUS_PATH}}"].startswith(str(execution_root.resolve()))
229
- assert replacements["{{PROJECT_BRIEF}}"] == "worktree brief"
230
- assert "{{" + "DEV_" + "SUBAGENT_PATH" + "}}" not in replacements
231
- assert replacements["{{SESSION_LOG_PATH}}"].endswith(
232
- ".prizmkit/state/features/F-001/sessions/session-1/logs/session.log"
233
- )
234
- assert "{{" + REMOVED_MAX_LOG_ENV + "}}" not in replacements
235
- assert "{{" + REMOVED_MAX_LOG_HUMAN + "}}" not in replacements
236
-
237
-
238
- def test_main_writes_checkpoint_under_cli_project_root_and_status_under_state_dir(self, tmp_path, monkeypatch):
239
- monkeypatch.setenv("PRIZMKIT_PLATFORM", "claude")
240
- execution_root = tmp_path / "worktree"
241
- main_checkout = tmp_path / "main"
242
- pipeline_root = Path(__file__).resolve().parents[1]
243
- feature_list = main_checkout / ".prizmkit" / "plans" / "feature-list.json"
244
- state_dir = main_checkout / ".prizmkit" / "state" / "features"
245
- output_path = state_dir / "F-001" / "sessions" / "session-1" / "bootstrap-prompt.md"
246
- feature_list.parent.mkdir(parents=True)
247
- state_dir.mkdir(parents=True)
248
- execution_root.mkdir(parents=True)
249
- feature_list.write_text(
250
- json.dumps({"features": [{"id": "F-001", "title": "Worktree Prompt", "estimated_complexity": "medium", "status": "pending"}]}),
251
- encoding="utf-8",
252
- )
253
-
254
- monkeypatch.setattr(
255
- "sys.argv",
256
- [
257
- "generate-bootstrap-prompt.py",
258
- "--feature-list",
259
- str(feature_list),
260
- "--feature-id",
261
- "F-001",
262
- "--session-id",
263
- "session-1",
264
- "--run-id",
265
- "run-1",
266
- "--retry-count",
267
- "0",
268
- "--resume-phase",
269
- "null",
270
- "--state-dir",
271
- str(state_dir),
272
- "--project-root",
273
- str(execution_root),
274
- "--output",
275
- str(output_path),
276
- "--template",
277
- str(pipeline_root / "templates" / "bootstrap-tier3.md"),
278
- ],
279
- )
280
-
281
- try:
282
- generate_bootstrap_main()
283
- except SystemExit as exc:
284
- assert exc.code == 0
285
-
286
- main_checkpoint = main_checkout / ".prizmkit" / "specs" / "001-worktree-prompt" / "workflow-checkpoint.json"
287
- rendered = output_path.read_text(encoding="utf-8")
288
- assert not main_checkpoint.exists()
289
- assert str(execution_root.resolve()) in rendered
290
-
291
-
292
- # ---------------------------------------------------------------------------
293
- # get_completed_dependencies
294
- # ---------------------------------------------------------------------------
295
-
296
- class TestGetCompletedDependencies:
297
- def test_no_deps(self):
298
- feature = {"id": "F-002", "dependencies": []}
299
- assert "no dependencies" in get_completed_dependencies([], feature)
300
-
301
- def test_with_completed_dep(self):
302
- features = [
303
- {"id": "F-001", "title": "Setup", "status": "completed"},
304
- {"id": "F-002", "title": "Auth", "dependencies": ["F-001"]},
305
- ]
306
- result = get_completed_dependencies(features, features[1])
307
- assert "F-001" in result
308
- assert "completed" in result
309
-
310
- def test_no_completed_dep(self):
311
- features = [
312
- {"id": "F-001", "title": "Setup", "status": "pending"},
313
- {"id": "F-002", "title": "Auth", "dependencies": ["F-001"]},
314
- ]
315
- result = get_completed_dependencies(features, features[1])
316
- assert "no completed dependencies" in result
317
-
318
-
319
- # ---------------------------------------------------------------------------
320
- # process_conditional_blocks
321
- # ---------------------------------------------------------------------------
322
-
323
- class TestProcessConditionalBlocks:
324
- def test_fresh_start_keeps_fresh_block(self):
325
- tpl = "before\n{{IF_FRESH_START}}\nfresh content\n{{END_IF_FRESH_START}}\nafter"
326
- result = process_conditional_blocks(tpl, "null")
327
- assert "fresh content" in result
328
- assert "IF_FRESH_START" not in result
329
-
330
- def test_fresh_start_removes_resume_block(self):
331
- tpl = "before\n{{IF_RESUME}}\nresume content\n{{END_IF_RESUME}}\nafter"
332
- result = process_conditional_blocks(tpl, "null")
333
- assert "resume content" not in result
334
-
335
- def test_resume_keeps_resume_block(self):
336
- tpl = "before\n{{IF_RESUME}}\nresume content\n{{END_IF_RESUME}}\nafter"
337
- result = process_conditional_blocks(tpl, "3")
338
- assert "resume content" in result
339
- assert "IF_RESUME" not in result
340
-
341
- def test_resume_removes_fresh_block(self):
342
- tpl = "before\n{{IF_FRESH_START}}\nfresh content\n{{END_IF_FRESH_START}}\nafter"
343
- result = process_conditional_blocks(tpl, "3")
344
- assert "fresh content" not in result
345
-
346
-
347
- # ---------------------------------------------------------------------------
348
- # explicit custom-template conditionals
349
- # ---------------------------------------------------------------------------
350
-
351
- class TestProcessTemplateBlocks:
352
- def test_init_done_keeps_init_done_block(self):
353
- tpl = "{{IF_INIT_DONE}}\ninit done\n{{END_IF_INIT_DONE}}"
354
- result = process_template_blocks(tpl, init_done=True)
355
- assert "init done" in result
356
-
357
- def test_init_needed_when_not_done(self):
358
- tpl = "{{IF_INIT_NEEDED}}\nneed init\n{{END_IF_INIT_NEEDED}}"
359
- result = process_template_blocks(tpl, init_done=False)
360
- assert "need init" in result
361
-
362
-
363
-
364
-
365
- # ---------------------------------------------------------------------------
366
- # section assembly / checkpoint integration
367
- # ---------------------------------------------------------------------------
368
-
369
- class TestScopedFeatureTestGate:
370
- @staticmethod
371
- def _artifacts(slug="123-scope-test"):
372
- return [
373
- f".prizmkit/specs/{slug}/test-report.md",
374
- f".prizmkit/specs/{slug}/test-result.json",
375
- ]
376
-
377
- @staticmethod
378
- def _write_result(root, result="TEST_PASS", *, unresolved=None):
379
- artifact = root / ".prizmkit" / "specs" / "123-scope-test"
380
- artifact.mkdir(parents=True, exist_ok=True)
381
- (artifact / "test-report.md").write_text(
382
- f"# Test Report\n\n## Final Result\n\n- Result: {result}\n",
383
- encoding="utf-8",
384
- )
385
- payload = {
386
- "schema_version": 1,
387
- "result": result,
388
- "report": "test-report.md",
389
- "main_review_rounds": 1,
390
- "independent_review": {
391
- "status": "downgraded",
392
- "responses": 0,
393
- "downgrade_reason": "read-only continuation capability unavailable",
394
- "final_state_rechecked": False,
395
- },
396
- "repair_rounds": 0,
397
- "production_changed": False,
398
- "unresolved_items": unresolved or [],
399
- }
400
- (artifact / "test-result.json").write_text(
401
- json.dumps(payload), encoding="utf-8",
402
- )
403
-
404
- def test_canonical_sections_insert_prizmkit_test_after_review(self):
405
- sections_dir = Path(__file__).resolve().parents[1] / "templates" / "sections"
406
- sections = assemble_sections(
407
- str(sections_dir), init_done=True, browser_enabled=False,
408
- )
409
- names = [name for name, _ in sections]
410
- rendered = "\n".join(content for _, content in sections)
411
-
412
- assert names.index("phase-implement") < names.index("phase-review") < names.index("phase-prizmkit-test")
413
- assert "/prizmkit-test scope=this-change artifact_dir=.prizmkit/specs/{{FEATURE_SLUG}}/" in rendered
414
- assert "test-report.md" in rendered
415
- assert "test-result.json" in rendered
416
- assert "TEST_NEEDS_FIXES" in rendered
417
- assert ".prizmkit/test/evidence" not in rendered
418
- assert "TEST_FAIL" not in rendered
419
-
420
- def test_canonical_sections_include_central_checkpoint_helper(self):
421
- sections_dir = Path(__file__).resolve().parents[1] / "templates" / "sections"
422
- sections = assemble_sections(
423
- str(sections_dir), init_done=True, browser_enabled=False,
424
- )
425
- rendered = "\n".join(content for _, content in sections)
426
-
427
- assert "### Checkpoint Update Helper" in rendered
428
- assert "{{CHECKPOINT_PYTHON_CMD}}" in rendered
429
- assert "--checkpoint-path {{CHECKPOINT_PATH}}" in rendered
430
- assert "--stage-result <optional-domain-result>" in rendered
431
- assert "--status completed --stage-result PLAN_READY" in rendered
432
- assert "--status completed --stage-result IMPLEMENTED" in rendered
433
- assert "--status completed --stage-result REVIEW_PASS" in rendered
434
- assert "--status completed --stage-result TEST_PASS" in rendered
435
- assert "--status completed --stage-result RETRO_COMPLETE" in rendered
436
- assert "--status in_progress --stage-result COMMIT_PENDING" not in rendered
437
- assert "without another checkpoint-helper call for the committer" in rendered
438
- assert "Python Runtime alone validates the request" in rendered
439
- assert "advances the step to `completed/COMMITTED`" in rendered
440
- assert "Do not hand-edit `workflow-checkpoint.json` directly." in rendered
441
- assert "authoritative_evidence_paths" not in rendered
442
-
443
- def test_checkpoint_orders_test_after_review_with_terminal_artifacts(self):
444
- sections_dir = Path(__file__).resolve().parents[1] / "templates" / "sections"
445
- sections = assemble_sections(
446
- str(sections_dir), init_done=True, browser_enabled=False,
447
- )
448
- checkpoint = generate_checkpoint_definition(
449
- sections, workflow_type="feature-pipeline",
450
- item_id="F-123", item_slug="123-scope-test",
451
- session_id="F-123-session", init_done=True,
452
- )
453
- skills = [step["skill"] for step in checkpoint["steps"]]
454
- plan_step = next(
455
- step for step in checkpoint["steps"]
456
- if step["skill"] == "context-snapshot-and-plan"
457
- )
458
- review_step = next(
459
- step for step in checkpoint["steps"]
460
- if step["skill"] == "prizmkit-code-review"
461
- )
462
- test_step = next(step for step in checkpoint["steps"] if step["skill"] == "prizmkit-test")
463
-
464
- assert skills.index("prizmkit-code-review") < skills.index("prizmkit-test")
465
- assert plan_step["required_artifacts"] == [
466
- ".prizmkit/specs/123-scope-test/context-snapshot.md",
467
- ".prizmkit/specs/123-scope-test/spec.md",
468
- ".prizmkit/specs/123-scope-test/plan.md",
469
- ]
470
- assert review_step["required_artifacts"] == [
471
- ".prizmkit/specs/123-scope-test/review-report.md"
472
- ]
473
- assert test_step["required_artifacts"] == self._artifacts()
474
-
475
- def test_merge_rewinds_completed_atomic_stage_without_domain_result(self, tmp_path):
476
- existing = {
477
- "steps": [
478
- {
479
- "id": "S01",
480
- "skill": "context-snapshot-and-plan",
481
- "status": "completed",
482
- "required_artifacts": [],
483
- },
484
- {
485
- "id": "S02",
486
- "skill": "prizmkit-implement",
487
- "status": "completed",
488
- "stage_result": "IMPLEMENTED",
489
- "required_artifacts": [],
490
- },
491
- ]
492
- }
493
- fresh = {
494
- "steps": [
495
- {
496
- "id": "S01",
497
- "skill": "context-snapshot-and-plan",
498
- "status": "pending",
499
- "required_artifacts": [],
500
- },
501
- {
502
- "id": "S02",
503
- "skill": "prizmkit-implement",
504
- "status": "pending",
505
- "required_artifacts": [],
506
- },
507
- ]
508
- }
509
-
510
- merged = merge_checkpoint_state(existing, fresh, str(tmp_path))
511
-
512
- assert [step["status"] for step in merged["steps"]] == ["pending", "pending"]
513
-
514
- def test_merge_keeps_only_consistent_test_pass_artifacts(self, tmp_path):
515
- self._write_result(tmp_path)
516
- existing = {"steps": [{
517
- "id": "S01", "skill": "prizmkit-test", "status": "completed",
518
- "stage_result": "TEST_PASS", "required_artifacts": self._artifacts(),
519
- }]}
520
- fresh = {"steps": [{
521
- "id": "S01", "skill": "prizmkit-test", "status": "pending",
522
- "required_artifacts": self._artifacts(),
523
- }]}
524
-
525
- merged = merge_checkpoint_state(existing, fresh, str(tmp_path))
526
-
527
- assert merged["steps"][0]["status"] == "completed"
528
- assert merged["steps"][0]["stage_result"] == "TEST_PASS"
529
-
530
- def test_merge_resets_missing_or_non_pass_test_artifacts(self, tmp_path):
531
- existing = {"steps": [{
532
- "id": "S01", "skill": "prizmkit-test", "status": "completed",
533
- "stage_result": "TEST_PASS", "required_artifacts": self._artifacts(),
534
- }]}
535
- fresh = {"steps": [{
536
- "id": "S01", "skill": "prizmkit-test", "status": "pending",
537
- "required_artifacts": self._artifacts(),
538
- }]}
539
- missing = merge_checkpoint_state(existing, fresh, str(tmp_path))
540
- assert missing["steps"][0]["status"] == "pending"
541
-
542
- self._write_result(tmp_path, "TEST_NEEDS_FIXES", unresolved=["known correction"])
543
- needs_fixes = merge_checkpoint_state(existing, fresh, str(tmp_path))
544
- assert needs_fixes["steps"][0]["status"] == "pending"
545
-
546
- def test_merge_rejects_malformed_or_inconsistent_terminal_projection(self, tmp_path):
547
- self._write_result(tmp_path)
548
- result_path = tmp_path / ".prizmkit/specs/123-scope-test/test-result.json"
549
- payload = json.loads(result_path.read_text(encoding="utf-8"))
550
- payload["caller_route"] = "prizmkit-code-review"
551
- result_path.write_text(json.dumps(payload), encoding="utf-8")
552
- existing = {"steps": [{
553
- "id": "S01", "skill": "prizmkit-test", "status": "completed",
554
- "stage_result": "TEST_PASS", "required_artifacts": self._artifacts(),
555
- }]}
556
- fresh = {"steps": [{
557
- "id": "S01", "skill": "prizmkit-test", "status": "pending",
558
- "required_artifacts": self._artifacts(),
559
- }]}
560
-
561
- merged = merge_checkpoint_state(existing, fresh, str(tmp_path))
562
-
563
- assert merged["steps"][0]["status"] == "pending"
564
-
565
- def test_feature_result_routing_owns_bounded_outer_repair(self):
566
- review = route_feature_repair(
567
- "REVIEW_NEEDS_FIXES", repair_scope="production", repair_round=0,
568
- )
569
- needs_fixes = route_feature_repair(
570
- "TEST_NEEDS_FIXES", repair_scope="production", repair_round=1,
571
- )
572
- blocked = route_feature_repair("TEST_BLOCKED", repair_round=1)
573
- passed = route_feature_repair("TEST_PASS", repair_round=1)
574
-
575
- assert review["route"] == [
576
- "prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
577
- ]
578
- assert review["repair_round"] == 1
579
- assert needs_fixes["blocked"] is False
580
- assert needs_fixes["route"] == [
581
- "prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
582
- ]
583
- assert needs_fixes["repair_round"] == 2
584
- assert blocked["blocked"] is True
585
- assert blocked["blocked_reason"] == "test_blocked"
586
- assert blocked["terminal_status"] == "WORKFLOW_BLOCKED"
587
- assert passed["route"] == ["family-report", "prizmkit-retrospective"]
588
- assert passed["next_stage"] == "family-report"
589
- unsafe = route_feature_repair("TEST_NEEDS_FIXES", repair_round=0)
590
- assert unsafe["blocked_reason"] == "unsafe_repair_scope"
591
-
592
- def test_pipeline_checkpoint_metadata_rejects_legacy_or_mismatched_status(self):
593
- invalid = [
594
- {"status": "TEST_PASS", "stage_result": "TEST_PASS"},
595
- {"status": "failed", "stage_result": "TEST_PASS"},
596
- {"status": "completed", "stage_result": "UNKNOWN_RESULT"},
597
- ]
598
-
599
- for values in invalid:
600
- try:
601
- pipeline_checkpoint_metadata(
602
- ".prizmkit/specs/contract-test",
603
- stage="test",
604
- **values,
605
- )
606
- except ValueError:
607
- continue
608
- raise AssertionError("invalid lifecycle metadata was accepted: {}".format(values))
609
-
610
- def test_feature_checkpoint_metadata_has_no_evidence_paths(self):
611
- metadata = feature_checkpoint_metadata(
612
- ".prizmkit/specs/123-scope-test",
613
- stage="test", status="failed",
614
- stage_result="TEST_NEEDS_FIXES", repair_round=0,
615
- next_stage=None, resume_from=None,
616
- )
617
-
618
- assert metadata["status"] == "failed"
619
- assert metadata["stage_result"] == "TEST_NEEDS_FIXES"
620
- assert "authoritative_evidence_paths" not in metadata
621
- assert metadata["artifact_dir"] == ".prizmkit/specs/123-scope-test"
622
-
623
- # ---------------------------------------------------------------------------
624
- # Active compaction harness rollback
625
- # ---------------------------------------------------------------------------
626
-
627
- class TestHeadlessRecoveryReframing:
628
- def test_active_prompt_sources_do_not_reference_deleted_log_size_section(self):
629
- deleted_section = "log-size-" + "awareness.md"
630
- loader = "load_" + "log_size_section"
631
- placeholder = "{{LOG_" + "SIZE_AWARENESS}}"
632
- deleted_title = "Session " + "Checkpoint Awareness"
633
- active_paths = [
634
- Path("dev-pipeline/scripts/generate-bootstrap-prompt.py"),
635
- Path("dev-pipeline/templates/bootstrap-tier3.md"),
636
- Path("dev-pipeline/templates/bugfix-bootstrap-prompt.md"),
637
- Path("dev-pipeline/templates/refactor-bootstrap-prompt.md"),
638
- ]
639
-
640
- assert (Path("dev-pipeline/templates/sections") / deleted_section).exists() is False
641
- for path in active_paths:
642
- content = path.read_text(encoding="utf-8")
643
- for forbidden in (deleted_section, loader, placeholder, deleted_title):
644
- assert forbidden not in content
645
-
646
- def test_feature_prompts_do_not_include_retired_execution_unit_timeout_recovery(self):
647
- deleted_section = "subagent-timeout-recovery.md"
648
- deleted_title = "Execution-Unit Timeout Recovery"
649
- active_paths = [
650
- Path("dev-pipeline/scripts/generate-bootstrap-prompt.py"),
651
- Path("dev-pipeline/templates/bootstrap-tier3.md"),
652
- ]
653
-
654
- assert (Path("dev-pipeline/templates/sections") / deleted_section).exists() is False
655
- for path in active_paths:
656
- content = path.read_text(encoding="utf-8")
657
- assert deleted_section not in content
658
- assert deleted_title not in content
659
-
660
- sections_dir = Path("dev-pipeline/templates/sections").resolve()
661
- rendered = "\n".join(
662
- section for _name, section in assemble_sections(
663
- str(sections_dir), init_done=True, browser_enabled=False,
664
- )
665
- )
666
- assert deleted_title not in rendered
667
-
668
- def test_assembled_prompts_do_not_spawn_log_monitor_or_require_compact(self):
669
- sections_dir = Path("dev-pipeline/templates/sections").resolve()
670
- deleted_title = "Session " + "Checkpoint Awareness"
671
- placeholder = "{{LOG_" + "SIZE_AWARENESS}}"
672
-
673
- rendered = "\n".join(
674
- section for _name, section in assemble_sections(
675
- str(sections_dir), init_done=True, browser_enabled=False,
676
- )
677
- )
678
- assert deleted_title not in rendered
679
- assert placeholder not in rendered
680
- assert REMOVED_MAX_LOG_ENV not in rendered
681
- assert REMOVED_MAX_LOG_HUMAN not in rendered
682
- assert ("209" + "7152") not in rendered
683
- assert ("2" + "MB") not in rendered
684
- assert "monitor-log" not in rendered
685
- assert "COMPACT_NEEDED" not in rendered
686
- assert "log-size monitor" not in rendered
687
- assert "The log-size monitor is the only allowed" not in rendered
688
- assert "Run this command and keep it running" not in rendered
689
- assert "Execute `/compact`" not in rendered
690
- assert "run `/compact` after" not in rendered
691
-
692
-
693
- class TestDirectOrchestratorImplementationPrompts:
694
- def test_active_agent_prompt_loader_excludes_retired_dev_implement_prompt(self):
695
- templates_dir = Path("dev-pipeline/templates").resolve()
696
-
697
- replacements = load_active_agent_prompts(str(templates_dir))
698
-
699
- assert "dev-implement.md" not in ACTIVE_AGENT_PROMPTS
700
- assert FORBIDDEN_DEV_FIX_PROMPT not in ACTIVE_AGENT_PROMPTS
701
- assert FORBIDDEN_DEV_RESUME_PROMPT not in ACTIVE_AGENT_PROMPTS
702
- assert "{{AGENT_PROMPT_DEV_IMPLEMENT}}" not in replacements
703
- assert FORBIDDEN_DEV_FIX_PLACEHOLDER not in replacements
704
- assert FORBIDDEN_DEV_RESUME_PLACEHOLDER not in replacements
705
- assert ACTIVE_AGENT_PROMPTS == {}
706
- assert "{{AGENT_PROMPT_REVIEWER_REVIEW}}" not in replacements
707
- assert (templates_dir / "agent-prompts" / "reviewer-review.md").exists() is False
708
- assert (templates_dir / "agent-prompts" / "dev-implement.md").exists() is False
709
- assert (templates_dir / "agent-prompts" / FORBIDDEN_DEV_FIX_PROMPT).exists() is False
710
- assert (templates_dir / "agent-prompts" / FORBIDDEN_DEV_RESUME_PROMPT).exists() is False
711
-
712
- def test_canonical_sections_use_direct_orchestrator_implementation(self):
713
- sections_dir = Path("dev-pipeline/templates/sections").resolve()
714
-
715
- rendered = "\n".join(
716
- section for _name, section in assemble_sections(
717
- str(sections_dir), init_done=True, browser_enabled=False,
718
- )
719
- )
720
-
721
- assert "/prizmkit-implement" in rendered
722
- assert "orchestrator) execute" in rendered or "Run `/prizmkit-implement`" in rendered
723
- assert "Spawn Dev subagent" not in rendered
724
- assert "Spawn Dev agent" not in rendered
725
- assert "Implement — Dev" not in rendered
726
- assert "{{AGENT_PROMPT_DEV_IMPLEMENT}}" not in rendered
727
- assert "dev-implement.md" not in rendered
728
- assert FORBIDDEN_REVIEW_DEV_FIX not in rendered
729
- assert FORBIDDEN_REVIEWER_DEV_SPAWN not in rendered
730
- assert FORBIDDEN_EXPLORE_SUBAGENT not in rendered
731
- assert FORBIDDEN_TEST_CMD_PLACEHOLDER not in rendered
732
- assert FORBIDDEN_THREE_STRIKE not in rendered
733
- assert FORBIDDEN_TWENTY_STEP not in rendered
734
- assert "review-report.md" in rendered
735
- assert "Final Result" in rendered
736
- assert "low=0" not in rendered
737
- assert "Reviewer 3" not in rendered
738
-
739
- def test_all_rendered_pipeline_prompts_have_one_main_agent_review_model(self, tmp_path):
740
- prompts = [
741
- _render_feature_prompt(tmp_path / "feature-low", complexity="low"),
742
- _render_feature_prompt(tmp_path / "feature-medium", complexity="medium"),
743
- _render_feature_prompt(tmp_path / "feature-high", complexity="high"),
744
- _render_feature_prompt(
745
- tmp_path / "feature-compatibility-template",
746
- template="bootstrap-tier3.md",
747
- ),
748
- _render_bugfix_prompt(tmp_path / "bugfix"),
749
- _render_refactor_prompt(tmp_path / "refactor"),
750
- ]
751
-
752
- for prompt in prompts:
753
- assert_complete_prompt_rendering(prompt)
754
-
755
- def test_retained_tier3_fallback_template_uses_direct_orchestrator_implementation(self):
756
- rendered = Path("dev-pipeline/templates/bootstrap-tier3.md").read_text(encoding="utf-8")
757
-
758
- assert "/prizmkit-implement" in rendered
759
- assert "Implement — Plan Execution" in rendered
760
- assert "Spawn Dev subagent" not in rendered
761
- assert "Spawn Dev agent" not in rendered
762
- assert "Spawn Reviewer agent" not in rendered
763
- assert "Reviewer Agent Def" not in rendered
764
- assert "subagent_type=\"" + "-".join(["prizm", "dev", "team", "reviewer"]) + "\"" not in rendered
765
- assert "Implement — Dev" not in rendered
766
- assert "{{AGENT_PROMPT_DEV_IMPLEMENT}}" not in rendered
767
- assert "{{AGENT_PROMPT_REVIEWER_REVIEW}}" not in rendered
768
- assert "reviewer-review.md" not in rendered
769
- assert "dev-implement.md" not in rendered
770
- assert "Bug Fix Documentation Policy" not in rendered
771
- assert "For bug-fix sessions" not in rendered
772
- assert "fix(<scope>)" not in rendered
773
- assert "port check 3000" not in rendered
774
- assert "localhost:3000" not in rendered
775
- assert FORBIDDEN_REVIEW_DEV_FIX not in rendered
776
- assert FORBIDDEN_REVIEWER_DEV_SPAWN not in rendered
777
- assert FORBIDDEN_EXPLORE_SUBAGENT not in rendered
778
- assert FORBIDDEN_TEST_CMD_PLACEHOLDER not in rendered
779
- assert FORBIDDEN_THREE_STRIKE not in rendered
780
- assert FORBIDDEN_TWENTY_STEP not in rendered
781
-
782
-
783
- # ---------------------------------------------------------------------------
784
- # continuation handoff
785
- # ---------------------------------------------------------------------------
786
-
787
- class TestContinuationHandoff:
788
- def test_addendum_and_summary_include_required_context(self, tmp_path):
789
- args = Namespace(
790
- output=str(tmp_path / ".prizmkit/state/features/F-123/sessions/F-123-new/bootstrap-prompt.md"),
791
- state_dir=str(tmp_path / ".prizmkit/state/features"),
792
- continuation_mode="ai_error",
793
- failure_classification="ai_runtime_or_provider_error",
794
- code_retry_count="1",
795
- infra_error_count="2",
796
- max_code_retries="3",
797
- max_infra_retries="3",
798
- no_progress_count="0",
799
- progress_fingerprint=json.dumps({"git_diff_fingerprint": "diff", "head_commit": "abc", "checkpoint_cursor": "S03:pending"}),
800
- previous_session_id="F-123-old",
801
- continuation_count="2",
802
- context_overflow_count="2",
803
- active_dev_branch="dev/F-123",
804
- base_branch="main",
805
- continuation_summary_path="",
806
- )
807
- checkpoint = {"steps": [
808
- {"id": "S01", "skill": "test-baseline", "name": "Test Baseline", "status": "completed"},
809
- {"id": "S02", "skill": "context-snapshot", "name": "Context Snapshot", "status": "skipped"},
810
- {"id": "S03", "skill": "prizmkit-implement", "name": "Implement", "status": "pending"},
811
- ]}
812
-
813
- rendered = append_continuation_handoff(
814
- "NORMAL BOOTSTRAP", args, str(tmp_path), "feature", "F-123",
815
- "123-continuation", checkpoint,
816
- )
817
-
818
- assert rendered.startswith("NORMAL BOOTSTRAP")
819
- assert "## Continuation Addendum" in rendered
820
- assert "This is an automatic continuation after the previous launched AI session ended with `ai_runtime_or_provider_error`." in rendered
821
- assert "This is a fresh headless AI CLI session for the same task." in rendered
822
- assert "Continue on the current branch/worktree." in rendered
823
- assert "Do not reset, clean, switch branches, or discard work." in rendered
824
- assert "Inspect `git status` and `git diff` before editing." in rendered
825
- assert "Treat completed/skipped checkpoint steps as already done." in rendered
826
- assert "Do not read the previous full `session.log` unless explicitly necessary." in rendered
827
- assert "prefer synthesized artifacts and summaries over logs" in rendered
828
- assert "Do not attempt `/compact` as the recovery mechanism." not in rendered
829
- assert ".prizmkit/specs/123-continuation/workflow-checkpoint.json" in rendered
830
- assert ".prizmkit/state/features/F-123/sessions/F-123-new/logs/session.log" in rendered
831
- assert ".prizmkit/state/features/F-123/sessions/F-123-new/logs/progress.json" in rendered
832
- assert ".prizmkit/state/features/F-123/sessions/F-123-new/logs/ai.pid" in rendered
833
- assert ("Log " + "monitor") not in rendered
834
- assert ("log-" + "monitor") not in rendered
835
-
836
- summary = tmp_path / ".prizmkit/specs/123-continuation/continuation-summary.md"
837
- assert summary.exists()
838
- summary_text = summary.read_text(encoding="utf-8")
839
- assert "Previous session id: F-123-old" in summary_text
840
- assert "First pending/in-progress checkpoint step: S03 (prizmkit-implement)" in summary_text
841
- assert "Workflow checkpoint: .prizmkit/specs/123-continuation/workflow-checkpoint.json" in summary_text
842
-
843
- def test_checkpoint_cursor_prefers_in_progress_before_pending(self):
844
- checkpoint = {"steps": [
845
- {"id": "S01", "skill": "done", "name": "Done", "status": "completed"},
846
- {"id": "S02", "skill": "active", "name": "Active", "status": "in_progress", "depends_on": "S01"},
847
- {"id": "S03", "skill": "later", "name": "Later", "status": "pending", "depends_on": "S02"},
848
- ]}
849
- assert checkpoint_cursor(checkpoint)["first_cursor"] == "S02 (active)"
850
-
851
-
852
- def test_modular_feature_prompt_renders_user_context(tmp_path):
853
- prompt = _render_feature_prompt(
854
- tmp_path / "user-context",
855
- user_context=["Use the existing event envelope", "Keep the public API backward compatible"],
856
- )
857
-
858
- assert "Use the existing event envelope" in prompt
859
- assert "Keep the public API backward compatible" in prompt
860
- assert "These materials were provided by the user" in prompt
861
- assert "{{USER_CONTEXT}}" not in prompt
862
-
863
-
864
-
865
- HEADLESS_FORBIDDEN_PROMPT_STRINGS = [
866
- "### Interactive Claude Code Note",
867
- "### Project Conventions",
868
- "Read CLAUDE.md for project-level coding standards and architecture decisions.",
869
- "Scaffold / generated file awareness",
870
- "### Resume Behavior",
871
- "[NEEDS CLARIFICATION]",
872
- "pause for interactive input",
873
- "prizmkit-test-gate.py",
874
- "### Phase 0: Detect Test Commands",
875
- "TEST_CMDS",
876
- ]
877
-
878
-
879
- def _write_feature_list(path, feature):
880
- path.parent.mkdir(parents=True, exist_ok=True)
881
- path.write_text(json.dumps({"features": [feature], "global_context": {"language": "Python"}}), encoding="utf-8")
882
-
883
-
884
- def _render_feature_prompt(tmp_path, template=None, platform="claude", browser_interaction=None, complexity=None, user_context=None, continuation_mode=None):
885
- project = tmp_path / "project"
886
- project.mkdir(parents=True)
887
- (project / ".prizmkit" / "plans").mkdir(parents=True)
888
- (project / ".prizmkit" / "config.json").write_text(
889
- json.dumps({"platform": platform, "ai_cli": platform}), encoding="utf-8"
890
- )
891
- feature = {
892
- "id": "F-123",
893
- "title": "Prompt Cleanup",
894
- "description": "Clean prompt text",
895
- "estimated_complexity": complexity or "medium",
896
- "acceptance_criteria": ["Prompts are clean"],
897
- }
898
- if user_context is not None:
899
- feature["user_context"] = user_context
900
- if browser_interaction is not None:
901
- feature["browser_interaction"] = browser_interaction
902
- feature_list = project / ".prizmkit" / "plans" / "feature-list.json"
903
- _write_feature_list(feature_list, feature)
904
- output = project / "prompt.md"
905
- args = [
906
- "generate-bootstrap-prompt.py",
907
- "--feature-list", str(feature_list),
908
- "--feature-id", "F-123",
909
- "--session-id", "session-1",
910
- "--run-id", "run-1",
911
- "--retry-count", "0",
912
- "--resume-phase", "null",
913
- "--state-dir", str(project / ".prizmkit" / "state" / "features"),
914
- "--project-root", str(project),
915
- "--output", str(output),
916
- ]
917
- if continuation_mode:
918
- args.extend(["--continuation-mode", continuation_mode])
919
- if template:
920
- template_path = Path(template)
921
- if not template_path.is_absolute():
922
- template_path = Path("dev-pipeline/templates") / template_path
923
- args.extend(["--template", str(template_path)])
924
- old_argv = os.sys.argv
925
- old_platform = os.environ.get("PRIZMKIT_PLATFORM")
926
- try:
927
- os.sys.argv = args
928
- if old_platform is not None:
929
- os.environ.pop("PRIZMKIT_PLATFORM")
930
- try:
931
- generate_bootstrap_main()
932
- except SystemExit as exc:
933
- if exc.code not in (0, None):
934
- raise
935
- finally:
936
- os.sys.argv = old_argv
937
- if old_platform is not None:
938
- os.environ["PRIZMKIT_PLATFORM"] = old_platform
939
- return output.read_text(encoding="utf-8")
940
-
941
-
942
- def _ensure_skill_files(project, platforms=None):
943
- """Create minimal skill files so platform resolution succeeds."""
944
- if platforms is None:
945
- platforms = ("claude", "codex")
946
- for plat in platforms:
947
- if plat == "codex":
948
- skill_dir = project / ".agents" / "skills" / "prizmkit"
949
- skill_dir.mkdir(parents=True, exist_ok=True)
950
- (skill_dir / "SKILL.md").write_text("skill\n", encoding="utf-8")
951
- elif plat == "codebuddy":
952
- skill_dir = project / ".codebuddy" / "skills" / "prizmkit"
953
- skill_dir.mkdir(parents=True, exist_ok=True)
954
- (skill_dir / "SKILL.md").write_text("skill\n", encoding="utf-8")
955
- else:
956
- command_dir = project / ".claude" / "commands"
957
- command_dir.mkdir(parents=True, exist_ok=True)
958
- (command_dir / "prizmkit.md").write_text("skill\n", encoding="utf-8")
959
-
960
-
961
- def _render_bugfix_prompt(
962
- tmp_path, platform="claude", explicit_platform=None,
963
- bug_overrides=None, retry_count="0", resume_phase="null",
964
- ):
965
- from generate_bugfix_prompt import main as bugfix_main
966
-
967
- project = tmp_path / "bugfix-project"
968
- project.mkdir(parents=True)
969
- (project / ".prizmkit").mkdir(exist_ok=True)
970
- (project / ".prizmkit" / "config.json").write_text(
971
- json.dumps({"platform": platform, "ai_cli": platform}), encoding="utf-8"
972
- )
973
- _ensure_skill_files(project)
974
- bug_list = project / ".prizmkit" / "plans" / "bug-fix-list.json"
975
- bug_list.parent.mkdir(parents=True)
976
- bug = {"id": "B-001", "title": "Broken", "description": "Fix it", "acceptance_criteria": ["Works"]}
977
- if bug_overrides:
978
- bug.update(bug_overrides)
979
- bug_list.write_text(json.dumps({
980
- "bugs": [bug],
981
- "global_context": {"language": "Python"},
982
- }), encoding="utf-8")
983
- output = project / "bugfix-prompt.md"
984
- old_argv = os.sys.argv
985
- old_platform = os.environ.get("PRIZMKIT_PLATFORM")
986
- try:
987
- if explicit_platform is None:
988
- os.environ.pop("PRIZMKIT_PLATFORM", None)
989
- else:
990
- os.environ["PRIZMKIT_PLATFORM"] = explicit_platform
991
- os.sys.argv = [
992
- "generate-bugfix-prompt.py",
993
- "--bug-list", str(bug_list),
994
- "--bug-id", "B-001",
995
- "--session-id", "session-1",
996
- "--run-id", "run-1",
997
- "--retry-count", retry_count,
998
- "--resume-phase", resume_phase,
999
- "--state-dir", str(project / ".prizmkit" / "state" / "bugfix"),
1000
- "--project-root", str(project),
1001
- "--output", str(output),
1002
- ]
1003
- try:
1004
- bugfix_main()
1005
- except SystemExit as exc:
1006
- if exc.code not in (0, None):
1007
- raise
1008
- finally:
1009
- os.sys.argv = old_argv
1010
- if old_platform is None:
1011
- os.environ.pop("PRIZMKIT_PLATFORM", None)
1012
- else:
1013
- os.environ["PRIZMKIT_PLATFORM"] = old_platform
1014
- return output.read_text(encoding="utf-8")
1015
-
1016
-
1017
- def _render_refactor_prompt(tmp_path, platform="claude", explicit_platform=None, refactor_overrides=None):
1018
- from generate_refactor_prompt import main as refactor_main
1019
-
1020
- project = tmp_path / "refactor-project"
1021
- project.mkdir(parents=True)
1022
- (project / ".prizmkit").mkdir(exist_ok=True)
1023
- (project / ".prizmkit" / "config.json").write_text(
1024
- json.dumps({"platform": platform, "ai_cli": platform}), encoding="utf-8"
1025
- )
1026
- _ensure_skill_files(project)
1027
- refactor_list = project / ".prizmkit" / "plans" / "refactor-list.json"
1028
- refactor_list.parent.mkdir(parents=True)
1029
- refactor = {
1030
- "id": "R-001",
1031
- "title": "Restructure",
1032
- "description": "Preserve behavior",
1033
- "acceptance_criteria": ["Behavior preserved"],
1034
- "scope": {"files": ["src/a.py"], "modules": ["src"]},
1035
- }
1036
- if refactor_overrides:
1037
- refactor.update(refactor_overrides)
1038
- refactor_list.write_text(json.dumps({
1039
- "refactors": [refactor],
1040
- "global_context": {"language": "Python"},
1041
- }), encoding="utf-8")
1042
- output = project / "refactor-prompt.md"
1043
- old_argv = os.sys.argv
1044
- old_platform = os.environ.get("PRIZMKIT_PLATFORM")
1045
- try:
1046
- if explicit_platform is None:
1047
- os.environ.pop("PRIZMKIT_PLATFORM", None)
1048
- else:
1049
- os.environ["PRIZMKIT_PLATFORM"] = explicit_platform
1050
- os.sys.argv = [
1051
- "generate-refactor-prompt.py",
1052
- "--refactor-list", str(refactor_list),
1053
- "--refactor-id", "R-001",
1054
- "--session-id", "session-1",
1055
- "--run-id", "run-1",
1056
- "--retry-count", "0",
1057
- "--resume-phase", "null",
1058
- "--state-dir", str(project / ".prizmkit" / "state" / "refactor"),
1059
- "--project-root", str(project),
1060
- "--output", str(output),
1061
- ]
1062
- try:
1063
- refactor_main()
1064
- except SystemExit as exc:
1065
- if exc.code not in (0, None):
1066
- raise
1067
- finally:
1068
- os.sys.argv = old_argv
1069
- if old_platform is None:
1070
- os.environ.pop("PRIZMKIT_PLATFORM", None)
1071
- else:
1072
- os.environ["PRIZMKIT_PLATFORM"] = old_platform
1073
- return output.read_text(encoding="utf-8")
1074
-
1075
-
1076
- class TestFeaturePromptCanonicalGuidance:
1077
- def test_default_sections_prompt_uses_same_guidance_for_all_complexities(self, tmp_path):
1078
- prompts = {
1079
- complexity: _render_feature_prompt(
1080
- tmp_path / f"complexity-{complexity}",
1081
- complexity=complexity,
1082
- )
1083
- for complexity in ("low", "medium", "high", "critical")
1084
- }
1085
-
1086
- for complexity, prompt in prompts.items():
1087
- assert f"**Complexity**: {complexity}" in prompt
1088
- assert "## Task Contract" in prompt
1089
- assert "## Workflow Checkpoint System" in prompt
1090
- assert "### Specify + Plan (Full Workflow)" in prompt
1091
- assert "The injected session validates artifact presence but does not perform a second planning review" in prompt
1092
- assert "### Scoped Feature Test Gate — PrizmKit Test" in prompt
1093
- assert "## Test Failure Recovery Protocol" not in prompt
1094
- assert "test-report.md" in prompt
1095
- assert "test-result.json" in prompt
1096
- assert "### Browser Verification — MANDATORY" not in prompt
1097
- assert "### Feature Completion Summary" in prompt
1098
- assert "### Runtime Commit Handoff" in prompt
1099
- assert "# Dev-Pipeline Session Bootstrap — Tier 1" not in prompt
1100
- assert "# Dev-Pipeline Session Bootstrap — Tier 2" not in prompt
1101
- assert "### Phase 0: SKIP (already initialized)" not in prompt
1102
-
1103
- # Complexity remains planning metadata; every task gets the same guidance.
1104
- def test_canonical_guidance_has_no_pipeline_mode_context(self, tmp_path):
1105
- prompt = _render_feature_prompt(tmp_path / "canonical", complexity="low")
1106
-
1107
- assert "{{PIPELINE_MODE}}" not in prompt
1108
- assert "compatibility mode" not in prompt
1109
- assert "### Specify + Plan (Full Workflow)" in prompt
1110
- assert "### Plan Self-Check — Orchestrator Direct" not in prompt
1111
- assert "does not perform a second planning review" in prompt
1112
- assert "### Phase 0: SKIP (already initialized)" not in prompt
1113
-
1114
- def test_explicit_custom_template_override_still_renders(self, tmp_path):
1115
- custom = tmp_path / "custom-template.md"
1116
- custom.write_text(
1117
- "## Your Mission\nCUSTOM {{FEATURE_ID}} {{FEATURE_TITLE}} {{COMPLEXITY}} "
1118
- "{{IF_FRESH_START}}fresh{{END_IF_FRESH_START}}\n\n## Execution\ncustom\n\n"
1119
- "## Failure Capture\ncustom",
1120
- encoding="utf-8",
1121
- )
1122
-
1123
- prompt = _render_feature_prompt(
1124
- tmp_path / "custom-template-project",
1125
- complexity="low",
1126
- template=custom,
1127
- )
1128
-
1129
- assert "CUSTOM F-123 Prompt Cleanup low fresh" in prompt
1130
- checkpoint_path = (
1131
- tmp_path / "custom-template-project" / "project" / ".prizmkit"
1132
- / "specs" / "123-prompt-cleanup" / "workflow-checkpoint.json"
1133
- )
1134
- checkpoint = json.loads(checkpoint_path.read_text(encoding="utf-8"))
1135
- assert [step["skill"] for step in checkpoint["steps"]] == [
1136
- "prizmkit-init",
1137
- "context-snapshot-and-plan",
1138
- "prizmkit-implement",
1139
- "prizmkit-code-review",
1140
- "prizmkit-test",
1141
- "completion-summary",
1142
- "prizmkit-retrospective",
1143
- "prizmkit-committer",
1144
- ]
1145
-
1146
- def test_malformed_continuation_addendum_fails_closed(self, tmp_path, monkeypatch):
1147
- import generate_bootstrap_prompt as gbp
1148
-
1149
- monkeypatch.setattr(
1150
- gbp,
1151
- "append_continuation_handoff",
1152
- lambda rendered, *_args, **_kwargs: rendered + "\n{{BROKEN_CONTINUATION}}",
1153
- )
1154
- try:
1155
- _render_feature_prompt(
1156
- tmp_path / "malformed-continuation",
1157
- continuation_mode="ai_error",
1158
- )
1159
- except SystemExit as exc:
1160
- assert exc.code == 1
1161
- else:
1162
- raise AssertionError("malformed continuation Prompt did not fail closed")
1163
-
1164
- def test_missing_canonical_sections_fails_closed(self, tmp_path, monkeypatch):
1165
- import generate_bootstrap_prompt as gbp
1166
-
1167
- original_isdir = os.path.isdir
1168
-
1169
- def fake_isdir(path):
1170
- if str(path).endswith(os.path.join("templates", "sections")):
1171
- return False
1172
- return original_isdir(path)
1173
-
1174
- monkeypatch.setattr(gbp.os.path, "isdir", fake_isdir)
1175
- try:
1176
- _render_feature_prompt(tmp_path / "missing-sections", complexity="low")
1177
- except SystemExit as exc:
1178
- assert exc.code == 1
1179
- else:
1180
- raise AssertionError("missing canonical sections did not fail closed")
1181
-
1182
-
1183
- class TestBrowserBlockingPromptPolicy:
1184
- def test_feature_bugfix_refactor_blocking_browser_policy_stops_before_commit(self, tmp_path):
1185
- browser_interaction = {
1186
- "tool": "auto",
1187
- "blocking": True,
1188
- "verify_steps": ["Open the page"],
1189
- }
1190
- prompts = [
1191
- _render_feature_prompt(tmp_path / "feature-browser-blocking", browser_interaction=browser_interaction),
1192
- _render_bugfix_prompt(tmp_path / "bugfix-browser-blocking", bug_overrides={"browser_interaction": browser_interaction}),
1193
- _render_refactor_prompt(tmp_path / "refactor-browser-blocking", refactor_overrides={"browser_interaction": browser_interaction}),
1194
- ]
1195
-
1196
- test_markers = (
1197
- "### Scoped Feature Test Gate — PrizmKit Test",
1198
- "### Bugfix Test Gate — PrizmKit Test",
1199
- "### Refactor Test Gate — PrizmKit Test",
1200
- )
1201
- for prompt, test_marker in zip(prompts, test_markers, strict=True):
1202
- assert "Browser blocking policy: `true`" in prompt
1203
- assert "stop before commit" in prompt
1204
- assert "Failures do NOT block the commit" not in prompt
1205
- assert prompt.index("### Browser Verification — MANDATORY") < prompt.index(test_marker)
1206
-
1207
- def test_feature_bugfix_refactor_nonblocking_browser_policy_continues(self, tmp_path):
1208
- browser_interaction = {
1209
- "tool": "auto",
1210
- "blocking": False,
1211
- "verify_steps": ["Open the page"],
1212
- }
1213
- prompts = [
1214
- _render_feature_prompt(tmp_path / "feature-browser-nonblocking", browser_interaction=browser_interaction),
1215
- _render_bugfix_prompt(tmp_path / "bugfix-browser-nonblocking", bug_overrides={"browser_interaction": browser_interaction}),
1216
- _render_refactor_prompt(tmp_path / "refactor-browser-nonblocking", refactor_overrides={"browser_interaction": browser_interaction}),
1217
- ]
1218
-
1219
- for prompt in prompts:
1220
- assert "Browser blocking policy: `false`" in prompt
1221
- assert "clean up the dev server/browser, and continue" in prompt
1222
- assert "Failures do NOT block the commit" not in prompt
1223
-
1224
-
1225
- class TestBrowserOptInPromptPolicy:
1226
- @staticmethod
1227
- def _rendered_outputs(tmp_path, browser_interaction=None, env_value=None):
1228
- previous_env = os.environ.get("BROWSER_VERIFY")
1229
- if env_value is None:
1230
- os.environ.pop("BROWSER_VERIFY", None)
1231
- else:
1232
- os.environ["BROWSER_VERIFY"] = env_value
1233
- try:
1234
- feature_prompt = _render_feature_prompt(
1235
- tmp_path / "feature", browser_interaction=browser_interaction,
1236
- )
1237
- bugfix_prompt = _render_bugfix_prompt(
1238
- tmp_path / "bugfix",
1239
- bug_overrides=(
1240
- {"browser_interaction": browser_interaction}
1241
- if browser_interaction is not None else None
1242
- ),
1243
- )
1244
- refactor_prompt = _render_refactor_prompt(
1245
- tmp_path / "refactor",
1246
- refactor_overrides=(
1247
- {"browser_interaction": browser_interaction}
1248
- if browser_interaction is not None else None
1249
- ),
1250
- )
1251
- return feature_prompt, bugfix_prompt, refactor_prompt
1252
- finally:
1253
- if previous_env is None:
1254
- os.environ.pop("BROWSER_VERIFY", None)
1255
- else:
1256
- os.environ["BROWSER_VERIFY"] = previous_env
1257
-
1258
- @staticmethod
1259
- def _checkpoint_skills(project_root, family):
1260
- if family == "feature":
1261
- pattern = "**/workflow-checkpoint.json"
1262
- elif family == "bugfix":
1263
- pattern = "**/bugfix/B-001/workflow-checkpoint.json"
1264
- else:
1265
- pattern = "**/refactor/R-001/workflow-checkpoint.json"
1266
- path = next(project_root.glob(pattern))
1267
- return [step["skill"] for step in json.loads(path.read_text(encoding="utf-8"))["steps"]]
1268
-
1269
- def test_omitted_browser_interaction_disables_browser_for_all_families(self, tmp_path):
1270
- prompts = self._rendered_outputs(tmp_path / "omitted")
1271
-
1272
- for prompt in prompts:
1273
- assert "Browser Verification" not in prompt
1274
- assert "playwright-cli" not in prompt
1275
- assert "opencli" not in prompt
1276
- assert "development-server" not in prompt
1277
- assert "browser-dev-server.pid" not in prompt
1278
-
1279
- assert "browser-verification" not in self._checkpoint_skills(tmp_path / "omitted" / "feature", "feature")
1280
- assert "browser-verification" not in self._checkpoint_skills(tmp_path / "omitted" / "bugfix", "bugfix")
1281
- assert "browser-verification" not in self._checkpoint_skills(tmp_path / "omitted" / "refactor", "refactor")
1282
-
1283
- def test_explicit_browser_interaction_preserves_configuration_for_all_families(self, tmp_path):
1284
- browser_interaction = {
1285
- "tool": "playwright-cli",
1286
- "verify_steps": ["Open the page", "Submit the form"],
1287
- }
1288
- prompts = self._rendered_outputs(tmp_path / "explicit", browser_interaction)
1289
-
1290
- for prompt in prompts:
1291
- assert "Browser Verification" in prompt
1292
- assert "Browser Verification (playwright-cli)" in prompt
1293
- assert "playwright-cli" in prompt
1294
- assert "opencli" not in prompt
1295
- assert "Goal 1: Open the page" in prompt
1296
- assert "Goal 2: Submit the form" in prompt
1297
-
1298
- assert "browser-verification" in self._checkpoint_skills(tmp_path / "explicit" / "feature", "feature")
1299
- assert "browser-verification" in self._checkpoint_skills(tmp_path / "explicit" / "bugfix", "bugfix")
1300
- assert "browser-verification" in self._checkpoint_skills(tmp_path / "explicit" / "refactor", "refactor")
1301
-
1302
- def test_global_disable_suppresses_explicit_browser_for_all_families(self, tmp_path):
1303
- prompts = self._rendered_outputs(
1304
- tmp_path / "global-disable",
1305
- {"tool": "opencli", "verify_steps": ["Open the page"]},
1306
- env_value="false",
1307
- )
1308
-
1309
- for prompt in prompts:
1310
- assert "Browser Verification" not in prompt
1311
- assert "opencli" not in prompt
1312
- assert "browser-dev-server.pid" not in prompt
1313
-
1314
- assert "browser-verification" not in self._checkpoint_skills(tmp_path / "global-disable" / "feature", "feature")
1315
- assert "browser-verification" not in self._checkpoint_skills(tmp_path / "global-disable" / "bugfix", "bugfix")
1316
- assert "browser-verification" not in self._checkpoint_skills(tmp_path / "global-disable" / "refactor", "refactor")
1317
-
1318
- def test_manual_bugfix_prompt_remains_headless_and_committable(self, tmp_path):
1319
- prompt = _render_bugfix_prompt(
1320
- tmp_path / "manual-bugfix",
1321
- bug_overrides={"verification_type": "manual"},
1322
- )
1323
-
1324
- assert "Manual / Hybrid Verification Gate" in prompt
1325
- assert "must complete manual/hybrid verification automatically" in prompt
1326
- assert "Stop before `/prizmkit-retrospective` and `/prizmkit-committer`" not in prompt
1327
- assert "### Runtime Commit Handoff" in prompt
1328
- assert prompt.index("Manual / Hybrid Verification Gate") < prompt.index("### Bugfix Test Gate")
1329
- assert "status=\"partial\"" not in prompt
1330
-
1331
- def test_recovery_manual_bugfix_uses_same_automatic_policy(self, tmp_path):
1332
- prompt = _render_bugfix_prompt(
1333
- tmp_path / "recovery-manual-bugfix",
1334
- bug_overrides={"verification_type": "manual"},
1335
- retry_count="1",
1336
- )
1337
-
1338
- assert "Manual / Hybrid Verification Gate" in prompt
1339
- assert "must complete manual/hybrid verification automatically" in prompt
1340
- assert "Recovery-class session: automated verification may substitute" not in prompt
1341
- assert "### Runtime Commit Handoff" in prompt
1342
-
1343
-
1344
- class TestHeadlessPromptCleanupF033:
1345
- def test_rendered_feature_bugfix_refactor_prompts_are_clean(self, tmp_path):
1346
- prompts = [
1347
- _render_feature_prompt(tmp_path / "low", complexity="low"),
1348
- _render_feature_prompt(tmp_path / "medium", complexity="medium"),
1349
- _render_feature_prompt(tmp_path / "high", complexity="high"),
1350
- ]
1351
- prompts.append(_render_bugfix_prompt(tmp_path))
1352
- prompts.append(_render_refactor_prompt(tmp_path))
1353
-
1354
- for prompt in prompts:
1355
- for forbidden in HEADLESS_FORBIDDEN_PROMPT_STRINGS:
1356
- assert forbidden not in prompt
1357
- if "Feature ID" in prompt:
1358
- assert "/prizmkit-test scope=this-change artifact_dir=.prizmkit/specs/123-prompt-cleanup/" in prompt
1359
- assert "test-report.md" in prompt
1360
- assert "test-result.json" in prompt
1361
- assert "{{RUNTIME_HELPER_CMD}}" not in prompt
1362
- assert "prizmkit-runtime-helper.py" in prompt
1363
- # Anti-Bash guardrails for bugfix/refactor branches (F-039)
1364
- if "Bug ID" in prompt:
1365
- assert "{{RUNTIME_HELPER_CMD}}" not in prompt
1366
- assert "prizmkit-runtime-helper.py" in prompt
1367
- assert "2>/dev/null" not in prompt
1368
- assert "lsof -ti" not in prompt
1369
- assert "which " not in prompt # no which-command shell glue
1370
- if "Refactor ID" in prompt:
1371
- assert "{{RUNTIME_HELPER_CMD}}" not in prompt
1372
- assert "prizmkit-runtime-helper.py" in prompt
1373
- assert "2>/dev/null" not in prompt
1374
- assert "lsof -ti" not in prompt
1375
- assert "which " not in prompt # no which-command shell glue
1376
- assert "python3 {{INIT_SCRIPT_PATH}}" not in prompt
1377
-
1378
- def test_all_families_render_shared_manifest_and_precommit_order(self, tmp_path):
1379
- prompts = {
1380
- "feature": _render_feature_prompt(tmp_path / "manifest-feature"),
1381
- "bugfix": _render_bugfix_prompt(tmp_path / "manifest-bugfix"),
1382
- "refactor": _render_refactor_prompt(tmp_path / "manifest-refactor"),
1383
- }
1384
- common_artifacts = (
1385
- "spec.md",
1386
- "plan.md",
1387
- "context-snapshot.md",
1388
- "review-report.md",
1389
- "test-report.md",
1390
- "test-result.json",
1391
- "retrospective-result.json",
1392
- "failure-log.md",
1393
- "workflow-checkpoint.json",
1394
- "runtime-commit-request.json",
1395
- )
1396
- test_markers = {
1397
- "feature": "### Scoped Feature Test Gate — PrizmKit Test",
1398
- "bugfix": "### Bugfix Test Gate — PrizmKit Test",
1399
- "refactor": "### Refactor Test Gate — PrizmKit Test",
1400
- }
1401
- for family, prompt in prompts.items():
1402
- assert "## Requirement Artifact Manifest" in prompt
1403
- for artifact in common_artifacts:
1404
- assert artifact in prompt
1405
- assert "Atomic Skills write only their stage-owned artifacts and domain results" in prompt
1406
- assert "COMMIT_REQUEST_READY" in prompt
1407
- assert "do not call the checkpoint helper again for the committer stage" in prompt
1408
- assert "do not run another request validator" in prompt
1409
- assert "atomically publishes its own commit-pending checkpoint state" in prompt
1410
- assert '"schema_version": 2' in prompt
1411
- assert '"intended_paths"' not in prompt
1412
- assert "complete final Git-visible workspace" in prompt
1413
- assert "workflow_state_path" not in prompt
1414
- assert "outcome=RETRO_COMPLETE" in prompt
1415
- assert "Never recreate the testing-local repair loop" in prompt
1416
- assert prompt.index(test_markers[family]) < prompt.index("### Retrospective")
1417
- assert prompt.index("### Retrospective") < prompt.index("### Runtime Commit Handoff")
1418
-
1419
- assert prompts["feature"].index("### Feature Completion Summary") < prompts["feature"].index("### Retrospective")
1420
- assert prompts["bugfix"].index("### Bug Fix Report") < prompts["bugfix"].index("### Retrospective")
1421
- assert prompts["refactor"].index("### Refactor Report") < prompts["refactor"].index("### Retrospective")
1422
-
1423
- def test_retained_tier3_template_is_clean_when_rendered(self, tmp_path):
1424
- prompt = _render_feature_prompt(tmp_path / "bootstrap-tier3.md", template="bootstrap-tier3.md")
1425
- for forbidden in HEADLESS_FORBIDDEN_PROMPT_STRINGS:
1426
- assert forbidden not in prompt
1427
- assert "prizmkit-test-gate.py" not in prompt
1428
- assert "python3 {{INIT_SCRIPT_PATH}}" not in prompt
1429
- assert "which playwright-cli" not in prompt
1430
- assert "lsof -ti" not in prompt
1431
- assert "sed -nE" not in prompt
1432
- assert ".prizmkit-test-started" not in prompt
1433
- assert "{{RUNTIME_HELPER_CMD}}" not in prompt
1434
- assert "prizmkit-runtime-helper.py" in prompt
1435
-
1436
- def test_retired_tier1_tier2_templates_are_removed(self):
1437
- assert not Path("dev-pipeline/templates/bootstrap-tier1.md").exists()
1438
- assert not Path("dev-pipeline/templates/bootstrap-tier2.md").exists()
1439
-
1440
- def test_retained_tier3_template_with_browser_blocks_is_shell_free(self, tmp_path):
1441
- forbidden = [
1442
- "python3 {{INIT_SCRIPT_PATH}}",
1443
- "which playwright-cli",
1444
- "which opencli",
1445
- "lsof -ti",
1446
- "sed -nE",
1447
- "SKILL_DIR",
1448
- "DEV_SERVER_PID",
1449
- "opencli doctor 2>/dev/null ||",
1450
- "echo \"=== playwright-cli ===\" &&",
1451
- ]
1452
- prompt = _render_feature_prompt(
1453
- tmp_path / "browser-bootstrap-tier3.md",
1454
- template="bootstrap-tier3.md",
1455
- browser_interaction={"tool": "auto", "verify_steps": ["Open the page"]},
1456
- )
1457
- assert "prizmkit-runtime-helper.py" in prompt
1458
- for snippet in forbidden:
1459
- assert snippet not in prompt
1460
-
1461
- def test_bugfix_refactor_share_claude_platform_resolution(self, tmp_path, monkeypatch):
1462
- from generate_bugfix_prompt import build_replacements as bugfix_build_replacements
1463
-
1464
- monkeypatch.delenv("PRIZMKIT_PLATFORM", raising=False)
1465
- bug_project = tmp_path / "bugfix-replacements"
1466
- bug_project.mkdir()
1467
- (bug_project / ".prizmkit").mkdir()
1468
- (bug_project / ".prizmkit" / "config.json").write_text(
1469
- json.dumps({"platform": "claude", "ai_cli": "claude"}), encoding="utf-8"
1470
- )
1471
- _ensure_skill_files(bug_project)
1472
- args = Namespace(
1473
- bug_id="B-001", session_id="session-1", run_id="run-1",
1474
- retry_count="0", resume_phase="null", state_dir=None,
1475
- output="out.md", project_root=str(bug_project), template=None,
1476
- )
1477
- replacements = bugfix_build_replacements(
1478
- args, {"id": "B-001", "title": "Broken"}, {}, str(Path("dev-pipeline/scripts").resolve())
1479
- )
1480
- refactor_prompt = _render_refactor_prompt(tmp_path / "refactor-mixed", platform="claude")
1481
-
1482
- assert "{{" + "REVIEWER_" + "SUBAGENT_PATH" + "}}" not in replacements
1483
- assert "review-report.md" in refactor_prompt
1484
- assert "Final Result" in refactor_prompt
1485
- assert "Reviewer 3" not in refactor_prompt
1486
-
1487
- def test_bugfix_refactor_explicit_codex_override(self, tmp_path, monkeypatch):
1488
- from generate_bugfix_prompt import build_replacements as bugfix_build_replacements
1489
-
1490
- bug_project = tmp_path / "bugfix-codex-replacements"
1491
- bug_project.mkdir()
1492
- _ensure_skill_files(bug_project)
1493
- monkeypatch.setenv("PRIZMKIT_PLATFORM", "codex")
1494
- args = Namespace(
1495
- bug_id="B-001", session_id="session-1", run_id="run-1",
1496
- retry_count="0", resume_phase="null", state_dir=None,
1497
- output="out.md", project_root=str(bug_project), template=None,
1498
- )
1499
- replacements = bugfix_build_replacements(
1500
- args, {"id": "B-001", "title": "Broken"}, {}, str(Path("dev-pipeline/scripts").resolve())
1501
- )
1502
- refactor_prompt = _render_refactor_prompt(tmp_path / "refactor-codex", platform="claude", explicit_platform="codex")
1503
-
1504
- assert "{{" + "REVIEWER_" + "SUBAGENT_PATH" + "}}" not in replacements
1505
- assert "review-report.md" in refactor_prompt
1506
- assert "Final Result" in refactor_prompt
1507
- assert "Reviewer 3" not in refactor_prompt
1508
-
1509
-
1510
- class TestFeatureBootstrapShellExtraction:
1511
- RETIRED_EXTRACTED_SNIPPETS = [
1512
- "find . -maxdepth",
1513
- "| sed",
1514
- "grep -c '^\\- \\[ \\]'",
1515
- "grep -r \"123-prompt-cleanup\"",
1516
- "2>/dev/null",
1517
- "/dev/null",
1518
- "$DEV_PORT",
1519
- "$!",
1520
- "$HOME",
1521
- "if [ ",
1522
- "which playwright-cli",
1523
- "which opencli",
1524
- "lsof -ti",
1525
- "xargs",
1526
- " kill -",
1527
- "kill -",
1528
- "|| echo",
1529
- "grep -q '^/binary-name$'",
1530
- "echo '/binary-name' >> .gitignore",
1531
- "git log --oneline | grep",
1532
- "grep -n ",
1533
- "sed -n",
1534
- "wc -l",
1535
- "opencli browser open http://localhost:<DEV_PORT> && opencli browser state",
1536
- "opencli browser type 3 \"hello\" && opencli browser click 7",
1537
- ]
1538
-
1539
- @staticmethod
1540
- def assert_shell_extracted_operations_removed(prompt):
1541
- for snippet in TestFeatureBootstrapShellExtraction.RETIRED_EXTRACTED_SNIPPETS:
1542
- assert snippet not in prompt
1543
- assert "{{RUNTIME_HELPER_CMD}}" not in prompt
1544
- assert "python" in prompt.lower()
1545
- assert ".prizmkit/dev-pipeline/scripts/prizmkit-runtime-helper.py" in prompt
1546
- assert "text final-verdict .prizmkit/specs/123-prompt-cleanup/review-report.md" in prompt
1547
-
1548
- def test_rendered_section_feature_prompts_use_runtime_helper_not_extracted_bash(self, tmp_path):
1549
- for complexity in ("low", "medium", "high"):
1550
- prompt = _render_feature_prompt(
1551
- tmp_path / f"section-{complexity}",
1552
- complexity=complexity,
1553
- browser_interaction={"tool": "auto", "verify_steps": ["Open the page"]},
1554
- )
1555
-
1556
- self.assert_shell_extracted_operations_removed(prompt)
1557
- assert "executable version playwright-cli --arg=--version" in prompt
1558
- assert "executable version opencli --arg=--version" in prompt
1559
- assert "process start --pid-file .prizmkit/state/browser-dev-server.pid" in prompt
1560
- assert "process cleanup-pid <pid-from-.prizmkit/state/browser-dev-server.pid>" in prompt
1561
- assert "port check <DEV_PORT>" in prompt
1562
- assert "port check 3000" not in prompt
1563
- assert "localhost:3000" not in prompt
1564
-
1565
- def test_rendered_retained_tier3_feature_prompt_uses_runtime_helper_not_extracted_bash(self, tmp_path):
1566
- prompt = _render_feature_prompt(
1567
- tmp_path / "legacy-bootstrap-tier3.md",
1568
- template="bootstrap-tier3.md",
1569
- browser_interaction={"tool": "playwright-cli", "verify_steps": ["Open the page"]},
1570
- )
1571
-
1572
- self.assert_shell_extracted_operations_removed(prompt)
1573
- assert "process start --pid-file .prizmkit/state/browser-dev-server.pid" in prompt
1574
- assert "process cleanup-pid <pid-from-.prizmkit/state/browser-dev-server.pid>" in prompt
1575
- assert "port check 3000" not in prompt
1576
- assert "localhost:3000" not in prompt
1577
-
1578
- def test_retained_tier3_specific_extracted_operations_map_to_helper_commands(self, tmp_path):
1579
- tier3 = _render_feature_prompt(
1580
- tmp_path / "legacy-tier3-helper-map",
1581
- template="bootstrap-tier3.md",
1582
- )
1583
- assert "text search . --pattern \"123-prompt-cleanup\" --json" in tier3
1584
- assert "text count .prizmkit/specs/123-prompt-cleanup/plan.md --pattern \"- [ ]\"" in tier3
1585
- assert "/prizmkit-committer operation=prepare-runtime-commit" in tier3
1586
- assert "Require a schema-v2 pathless request and `COMMIT_REQUEST_READY`" in tier3
1587
- assert "stop without another committer checkpoint update or request validator" in tier3
1588
- assert "The Python Runtime validates the request, publishes commit readiness" in tier3
1589
- assert "validate the complete Git-visible workspace" in tier3
1590
- assert "Code Review and Test authority must cover every behavior-affecting visible change" in tier3
1591
- assert "Ignored paths remain naturally absent" in tier3
1592
- assert "Never force-add or change/interpret project ignore policy" in tier3
1593
- assert "git add" not in tier3
1594
- assert "git commit" not in tier3
1595
-
1596
-
1597
- # ---------------------------------------------------------------------------
1598
- # detect_test_commands
1599
- # ---------------------------------------------------------------------------
1600
-
1601
- import json as _json
1602
-
1603
- class TestDetectTestCommands:
1604
- def test_no_package_json_returns_empty(self, tmp_path):
1605
- """When no package.json exists, no npm test emitted."""
1606
- result = detect_test_commands(str(tmp_path))
1607
- assert "npm test" not in result
1608
- assert "pnpm test" not in result
1609
- assert "yarn test" not in result
1610
-
1611
- def test_package_json_no_test_script(self, tmp_path):
1612
- """package.json exists but has no test script → no npm test emitted."""
1613
- pkg = tmp_path / "package.json"
1614
- pkg.write_text(_json.dumps({"name": "test", "scripts": {"start": "node index.js"}}), encoding="utf-8")
1615
- result = detect_test_commands(str(tmp_path))
1616
- # Bug: current code returns "npm test" even with no test script
1617
- assert "npm test" not in result, (
1618
- "Should NOT emit npm test when package.json has no test script"
1619
- )
1620
-
1621
- def test_package_json_with_test_script(self, tmp_path):
1622
- """package.json with scripts.test → emits npm test."""
1623
- pkg = tmp_path / "package.json"
1624
- pkg.write_text(_json.dumps({"name": "test", "scripts": {"test": "vitest run"}}), encoding="utf-8")
1625
- result = detect_test_commands(str(tmp_path))
1626
- # Current code returns "npm test" (hardcoded), but at minimum it should
1627
- # still return something test-like. After fix, it becomes "npm test"
1628
- assert "npm test" in result, (
1629
- "Should emit npm test when package.json has test script"
1630
- )
1631
-
1632
- def test_package_json_non_test_scripts_only(self, tmp_path):
1633
- """package.json exists but scripts only has non-test entries."""
1634
- pkg = tmp_path / "package.json"
1635
- pkg.write_text(_json.dumps({"name": "test", "scripts": {"build": "tsc", "start": "node dist/index.js"}}), encoding="utf-8")
1636
- result = detect_test_commands(str(tmp_path))
1637
- assert "npm test" not in result, (
1638
- "Should NOT emit npm test when no test-related scripts exist"
1639
- )
1640
-
1641
- def test_pnpm_detected_from_lockfile(self, tmp_path):
1642
- """pnpm-lock.yaml → emits pnpm test when test script exists."""
1643
- pkg = tmp_path / "package.json"
1644
- pkg.write_text(_json.dumps({"name": "test", "scripts": {"test": "vitest"}}), encoding="utf-8")
1645
- (tmp_path / "pnpm-lock.yaml").write_text("", encoding="utf-8")
1646
- result = detect_test_commands(str(tmp_path))
1647
- assert "pnpm test" in result
1648
-
1649
- def test_yarn_detected_from_lockfile(self, tmp_path):
1650
- """yarn.lock → emits yarn test when test script exists."""
1651
- pkg = tmp_path / "package.json"
1652
- pkg.write_text(_json.dumps({"name": "test", "scripts": {"test": "jest"}}), encoding="utf-8")
1653
- (tmp_path / "yarn.lock").write_text("", encoding="utf-8")
1654
- result = detect_test_commands(str(tmp_path))
1655
- assert "yarn test" in result
1656
-
1657
- def test_corrupt_package_json_graceful_fallback(self, tmp_path):
1658
- """Corrupt/unparseable package.json → skip JS detection gracefully."""
1659
- (tmp_path / "package.json").write_text("not valid json {{{", encoding="utf-8")
1660
- result = detect_test_commands(str(tmp_path))
1661
- # Should not crash, should not emit npm test
1662
- assert "npm test" not in result
1663
-
1664
- def test_non_js_detections_preserved(self, tmp_path):
1665
- """Go, Rust, Python, Makefile detections unchanged."""
1666
- (tmp_path / "go.mod").write_text("", encoding="utf-8")
1667
- (tmp_path / "Cargo.toml").write_text("", encoding="utf-8")
1668
- (tmp_path / "setup.py").write_text("", encoding="utf-8")
1669
- makefile = tmp_path / "Makefile"
1670
- makefile.write_text("test:\n\tpytest\n", encoding="utf-8")
1671
- result = detect_test_commands(str(tmp_path))
1672
- assert "go test ./..." in result
1673
- assert "cargo test" in result
1674
- assert "pytest" in result
1675
- assert "make test" in result
1676
-
1677
- def test_package_json_test_unit_script_only(self, tmp_path):
1678
- """package.json with test:unit but no test → fallback to available test script."""
1679
- pkg = tmp_path / "package.json"
1680
- pkg.write_text(_json.dumps({"name": "test", "scripts": {"test:unit": "vitest run"}}), encoding="utf-8")
1681
- (tmp_path / "package-lock.json").write_text("", encoding="utf-8")
1682
- result = detect_test_commands(str(tmp_path))
1683
- # Should detect test:unit as a viable test script
1684
- assert "npm run test:unit" in result
1685
-
1686
-
1687
-
1688
- def test_feature_checkpoint_generation_skips_noop_and_preserves_finalization_order():
1689
- from generate_bootstrap_prompt import generate_checkpoint_definition
1690
-
1691
- checkpoint = generate_checkpoint_definition(
1692
- [
1693
- ("phase0-test-baseline", "noop"),
1694
- ("phase-context-snapshot", "context"),
1695
- ("feature-completion-summary", "summary"),
1696
- ("phase-commit", "retrospective"),
1697
- ("runtime-commit-handoff", "commit"),
1698
- ],
1699
- "feature-pipeline",
1700
- "F-123",
1701
- "123-prompt-cleanup",
1702
- "session-1",
1703
- )
1704
-
1705
- assert [step["skill"] for step in checkpoint["steps"]] == [
1706
- "context-snapshot",
1707
- "completion-summary",
1708
- "prizmkit-retrospective",
1709
- "prizmkit-committer",
1710
- ]
1711
- assert checkpoint["steps"][0]["depends_on"] is None
1712
- assert checkpoint["steps"][1]["depends_on"] == "S01"