prizmkit 1.1.192 → 1.1.193

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