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,872 +0,0 @@
1
- """Regression tests for non-destructive failed-chain reset behavior."""
2
-
3
- import json
4
- import shlex
5
- import subprocess
6
- import sys
7
- from pathlib import Path
8
-
9
- import pytest
10
-
11
- REPO_ROOT = Path(__file__).resolve().parents[2]
12
- PIPELINE_ROOT = REPO_ROOT / "dev-pipeline"
13
- CLI_PATH = PIPELINE_ROOT / "cli.py"
14
- if str(PIPELINE_ROOT) not in sys.path:
15
- sys.path.insert(0, str(PIPELINE_ROOT))
16
-
17
-
18
- def _make_paths(tmp_path):
19
- from prizmkit_runtime.paths import resolve_runtime_paths
20
-
21
- project = tmp_path / "project"
22
- (project / ".prizmkit" / "plans").mkdir(parents=True)
23
- return resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=project)
24
-
25
-
26
- def _write_family_plan(paths, kind, items):
27
- plan_config = {
28
- "feature": (paths.feature_plan, "features", "dev-pipeline-feature-list-v1"),
29
- "bugfix": (paths.bugfix_plan, "bugs", "dev-pipeline-bug-fix-list-v1"),
30
- }
31
- plan_path, list_key, schema = plan_config[kind]
32
- plan_path.write_text(
33
- json.dumps({"$schema": schema, "project_name": "Fake", list_key: items}),
34
- encoding="utf-8",
35
- )
36
- return plan_path
37
-
38
-
39
- def _write_semantic_completion_checkpoint(project_root, artifact_dir, workflow_type="feature-pipeline"):
40
- contracts = {
41
- "feature-pipeline": (
42
- "feature_state",
43
- [
44
- "prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
45
- "prizmkit-retrospective", "prizmkit-committer", "completion-summary",
46
- ],
47
- ),
48
- "bugfix-pipeline": (
49
- "bugfix_state",
50
- [
51
- "prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
52
- "prizmkit-retrospective", "prizmkit-committer", "bug-report",
53
- ],
54
- ),
55
- }
56
- state_key, skills = contracts[workflow_type]
57
- steps = []
58
- previous = None
59
- for index, skill in enumerate(skills, start=1):
60
- step = {
61
- "id": f"S{index:02d}",
62
- "skill": skill,
63
- "name": skill,
64
- "status": "completed",
65
- "required_artifacts": [],
66
- "depends_on": previous,
67
- }
68
- if skill == "prizmkit-implement":
69
- step["stage_result"] = "IMPLEMENTED"
70
- if skill == "prizmkit-code-review":
71
- step["stage_result"] = "REVIEW_PASS"
72
- if skill == "prizmkit-test":
73
- step["stage_result"] = "TEST_PASS"
74
- relative_artifact = artifact_dir.relative_to(project_root)
75
- step["required_artifacts"] = [
76
- str(relative_artifact / "test-report.md"),
77
- str(relative_artifact / "test-result.json"),
78
- ]
79
- if skill == "prizmkit-retrospective":
80
- step["stage_result"] = "RETRO_COMPLETE"
81
- if skill == "prizmkit-committer":
82
- step["stage_result"] = "COMMITTED"
83
- steps.append(step)
84
- previous = step["id"]
85
- artifact_dir.mkdir(parents=True, exist_ok=True)
86
- (artifact_dir / "test-report.md").write_text(
87
- "# Test Report\n\n## Final Result\n\n- Result: TEST_PASS\n",
88
- encoding="utf-8",
89
- )
90
- (artifact_dir / "test-result.json").write_text(
91
- json.dumps({
92
- "schema_version": 1,
93
- "result": "TEST_PASS",
94
- "report": "test-report.md",
95
- "main_review_rounds": 1,
96
- "independent_review": {
97
- "status": "downgraded",
98
- "responses": 0,
99
- "downgrade_reason": "read-only capability unavailable",
100
- "final_state_rechecked": False,
101
- },
102
- "repair_rounds": 0,
103
- "production_changed": False,
104
- "unresolved_items": [],
105
- }),
106
- encoding="utf-8",
107
- )
108
- checkpoint = artifact_dir / "workflow-checkpoint.json"
109
- checkpoint.write_text(
110
- json.dumps({
111
- "version": 1,
112
- "workflow_type": workflow_type,
113
- "steps": steps,
114
- state_key: {
115
- "repair_round": 0,
116
- "terminal_status": "WORKFLOW_COMPLETED",
117
- },
118
- }),
119
- encoding="utf-8",
120
- )
121
- return checkpoint
122
-
123
-
124
- def _init_preserve_runtime_repo(paths):
125
- subprocess.run(["git", "init", "-b", "main"], cwd=paths.project_root, check=True, stdout=subprocess.DEVNULL)
126
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=paths.project_root, check=True)
127
- subprocess.run(["git", "config", "user.name", "Test"], cwd=paths.project_root, check=True)
128
- (paths.project_root / "base.txt").write_text("base\n", encoding="utf-8")
129
- subprocess.run(["git", "add", "base.txt"], cwd=paths.project_root, check=True)
130
- subprocess.run(["git", "commit", "-m", "base"], cwd=paths.project_root, check=True, stdout=subprocess.DEVNULL)
131
-
132
-
133
- def _preserve_family_contract(kind):
134
- return {
135
- "feature": ("F-", "dev", "feature-pipeline", "specs"),
136
- "bugfix": ("B-", "bugfix", "bugfix-pipeline", "bugfix"),
137
- }[kind]
138
-
139
-
140
- def _preserve_item_id(prefix, number):
141
- return f"{prefix}{number:03d}"
142
-
143
-
144
- def _preserve_items(kind):
145
- prefix, _branch_prefix, _workflow_type, _artifact_root = _preserve_family_contract(kind)
146
- statuses = [
147
- (1, "failed", []),
148
- (2, "auto_skipped", [_preserve_item_id(prefix, 1)]),
149
- (3, "auto_skipped", [_preserve_item_id(prefix, 2)]),
150
- (4, "completed", []),
151
- (5, "skipped", []),
152
- (6, "auto_skipped", [_preserve_item_id(prefix, 5)]),
153
- (7, "needs_info", []),
154
- (8, "pending", []),
155
- (9, "split", []),
156
- ]
157
- return [
158
- {
159
- "id": _preserve_item_id(prefix, number),
160
- "title": "Root" if number == 1 else f"Item {number}",
161
- "description": "preserve runtime",
162
- "status": status,
163
- "priority": "medium",
164
- "dependencies": dependencies,
165
- }
166
- for number, status, dependencies in statuses
167
- ]
168
-
169
-
170
- def _write_preserve_runtime_state(paths, kind, item_id, branch, *, base_branch="main"):
171
- from prizmkit_runtime.runner_models import family_for
172
- from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
173
-
174
- family = family_for(kind, paths)
175
- family.state_dir.mkdir(parents=True, exist_ok=True)
176
- (family.state_dir / "pipeline.json").write_text(json.dumps({"status": "failed"}), encoding="utf-8")
177
- item_state = family.state_dir / item_id
178
- sessions = item_state / "sessions" / "old-session" / "logs"
179
- sessions.mkdir(parents=True, exist_ok=True)
180
- (sessions / "session.log").write_text("historical log\n", encoding="utf-8")
181
- status = {
182
- "status": "failed",
183
- "retry_count": 7,
184
- "infra_error_count": 4,
185
- "sessions": ["old-session"],
186
- "last_session_id": "old-session",
187
- "previous_session_id": "old-session",
188
- "last_infra_error_session_id": "old-session",
189
- "continuation_pending": False,
190
- "continuation_reason": "code_error",
191
- "continuation_summary_path": "keep-this-path",
192
- "last_progress_fingerprint": {"head": "abc", "checkpoint": "S03"},
193
- "no_progress_count": 2,
194
- "fatal_error_code": "provider_error",
195
- "active_dev_branch": branch,
196
- "base_branch": base_branch,
197
- "custom_diagnostic": {"reason": "preserve me"},
198
- }
199
- status_path = item_state / "status.json"
200
- status_path.write_text(json.dumps(status, indent=2) + "\n", encoding="utf-8")
201
- checkout = TaskCheckout.active(kind, item_id, branch, base_branch)
202
- persist_task_checkout(family.state_dir, checkout)
203
- return family, status_path, status, checkout
204
-
205
-
206
- @pytest.mark.parametrize("kind", ["feature", "bugfix"])
207
- def test_preserve_runtime_restores_failed_chain_and_preserves_existing_checkout_history(tmp_path, kind):
208
- from prizmkit_runtime.reset import run_reset_command
209
- from prizmkit_runtime.task_checkout import load_task_checkout
210
-
211
- paths = _make_paths(tmp_path / kind)
212
- _init_preserve_runtime_repo(paths)
213
- prefix, branch_prefix, workflow_type, artifact_root = _preserve_family_contract(kind)
214
- root_id = _preserve_item_id(prefix, 1)
215
- plan = _write_family_plan(paths, kind, _preserve_items(kind))
216
- branch = f"{branch_prefix}/{root_id}-preserved"
217
- subprocess.run(["git", "branch", branch, "main"], cwd=paths.project_root, check=True)
218
- family, status_path, before_status, checkout = _write_preserve_runtime_state(paths, kind, root_id, branch)
219
- descendant_status = family.state_dir / _preserve_item_id(prefix, 2) / "status.json"
220
- descendant_status.parent.mkdir(parents=True, exist_ok=True)
221
- descendant_status.write_text(
222
- json.dumps({"status": "auto_skipped", "caused_by": root_id, "sessions": ["child-history"]}, indent=2) + "\n",
223
- encoding="utf-8",
224
- )
225
- descendant_status_before = descendant_status.read_bytes()
226
- artifact_name = "001-root" if kind == "feature" else root_id
227
- artifact = paths.project_root / ".prizmkit" / artifact_root / artifact_name
228
- checkpoint = _write_semantic_completion_checkpoint(paths.project_root, artifact, workflow_type)
229
- checkpoint_before = checkpoint.read_bytes()
230
- session_log = family.state_dir / root_id / "sessions" / "old-session" / "logs" / "session.log"
231
- session_before = session_log.read_bytes()
232
- branch_head_before = subprocess.run(
233
- ["git", "rev-parse", branch], cwd=paths.project_root, check=True, stdout=subprocess.PIPE, text=True
234
- ).stdout.strip()
235
-
236
- result = run_reset_command(kind, ("--failed", "--preserve-runtime"), paths)
237
-
238
- assert result.exit_code == 0, result.render()
239
- updated_plan = json.loads(plan.read_text(encoding="utf-8"))
240
- statuses = {item["id"]: item["status"] for item in updated_plan[family.list_key]}
241
- assert statuses[root_id] == "pending"
242
- assert statuses[_preserve_item_id(prefix, 2)] == "pending"
243
- assert statuses[_preserve_item_id(prefix, 3)] == "pending"
244
- assert statuses[_preserve_item_id(prefix, 4)] == "completed"
245
- assert statuses[_preserve_item_id(prefix, 5)] == "skipped"
246
- assert statuses[_preserve_item_id(prefix, 6)] == "auto_skipped"
247
- assert statuses[_preserve_item_id(prefix, 7)] == "needs_info"
248
- assert statuses[_preserve_item_id(prefix, 8)] == "pending"
249
- assert statuses[_preserve_item_id(prefix, 9)] == "split"
250
- expected_status = dict(before_status)
251
- expected_status.update(retry_count=0, infra_error_count=0, continuation_pending=True)
252
- assert json.loads(status_path.read_text(encoding="utf-8")) == expected_status
253
- assert load_task_checkout(family.state_dir, kind, root_id) == checkout
254
- assert descendant_status.read_bytes() == descendant_status_before
255
- assert checkpoint.read_bytes() == checkpoint_before
256
- assert session_log.read_bytes() == session_before
257
- assert subprocess.run(
258
- ["git", "rev-parse", branch], cwd=paths.project_root, check=True, stdout=subprocess.PIPE, text=True
259
- ).stdout.strip() == branch_head_before
260
- assert "Active checkouts reused" in result.render()
261
- assert "Reset did not start a runner" in result.render()
262
-
263
-
264
- @pytest.mark.parametrize("kind", ["feature", "bugfix"])
265
- def test_preserve_runtime_no_failed_root_is_a_noop_without_checkout_state(tmp_path, kind):
266
- from prizmkit_runtime.reset import run_reset_command
267
- from prizmkit_runtime.runner_models import family_for
268
-
269
- paths = _make_paths(tmp_path / kind)
270
- items = _preserve_items(kind)
271
- items[0]["status"] = "completed"
272
- plan = _write_family_plan(paths, kind, items)
273
- family = family_for(kind, paths)
274
- before = plan.read_bytes()
275
-
276
- result = run_reset_command(kind, ("--failed", "--preserve-runtime"), paths)
277
-
278
- assert result.exit_code == 0
279
- assert "No failed" in result.render()
280
- assert plan.read_bytes() == before
281
- assert not any((family.state_dir / item["id"] / "checkout.json").exists() for item in items)
282
-
283
-
284
- def test_preserve_runtime_option_boundaries_and_removed_reset_run_do_not_mutate_state(tmp_path):
285
- from prizmkit_runtime.reset import ResetOptions, run_reset_command
286
- from prizmkit_runtime.runner_models import family_for, parse_invocation
287
-
288
- paths = _make_paths(tmp_path)
289
- plan = _write_family_plan(paths, "feature", _preserve_items("feature"))
290
- family = family_for("feature", paths)
291
- family.state_dir.mkdir(parents=True, exist_ok=True)
292
- (family.state_dir / "pipeline.json").write_text("{}\n", encoding="utf-8")
293
- before = plan.read_bytes()
294
- invalid_cases = [
295
- (("F-001", "--run"), "no longer accepts --run"),
296
- (("--preserve-runtime",), "requires --failed"),
297
- (("--failed", "--preserve-runtime", "--clean"), "Exactly one reset mode"),
298
- (("F-001", "--failed", "--preserve-runtime"), "cannot target an ID, range, or --all"),
299
- (("F-001:F-003", "--failed", "--preserve-runtime"), "cannot target an ID, range, or --all"),
300
- (("--failed", "--preserve-runtime", "--stalled"), "Unsupported reset arguments"),
301
- (("--failed", "--preserve-runtime", "--unknown"), "Unsupported reset arguments"),
302
- ]
303
-
304
- for args, message in invalid_cases:
305
- result = run_reset_command("feature", args, paths)
306
- assert result.exit_code != 0
307
- assert message in result.render()
308
- assert plan.read_bytes() == before
309
- assert "run_after" not in ResetOptions.__dataclass_fields__
310
- invocation = parse_invocation(
311
- family,
312
- "run",
313
- ("F-001", "--max-retries", "6", "--max-infra-retries", "7"),
314
- )
315
- assert invocation.action == "run"
316
- assert invocation.item_id == "F-001"
317
- assert invocation.max_retries == 6
318
- assert invocation.max_infra_retries == 7
319
-
320
-
321
- def test_preserve_runtime_restores_every_failed_root_in_one_successful_pass(tmp_path):
322
- from prizmkit_runtime.reset import run_reset_command
323
-
324
- paths = _make_paths(tmp_path)
325
- _init_preserve_runtime_repo(paths)
326
- items = [
327
- {"id": "F-001", "title": "Root One", "status": "failed", "dependencies": []},
328
- {"id": "F-002", "title": "Child One", "status": "auto_skipped", "dependencies": ["F-001"]},
329
- {"id": "F-003", "title": "Root Two", "status": "failed", "dependencies": []},
330
- {"id": "F-004", "title": "Child Two", "status": "auto_skipped", "dependencies": ["F-003"]},
331
- {"id": "F-005", "title": "Done", "status": "completed", "dependencies": []},
332
- ]
333
- plan = _write_family_plan(paths, "feature", items)
334
- before_statuses = {}
335
- for item_id in ("F-001", "F-003"):
336
- branch = f"dev/{item_id}-existing"
337
- subprocess.run(["git", "branch", branch, "main"], cwd=paths.project_root, check=True)
338
- _family, status_path, status_data, _checkout = _write_preserve_runtime_state(
339
- paths, "feature", item_id, branch
340
- )
341
- before_statuses[item_id] = (status_path, status_data)
342
-
343
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
344
-
345
- assert result.exit_code == 0, result.render()
346
- statuses = {
347
- item["id"]: item["status"]
348
- for item in json.loads(plan.read_text(encoding="utf-8"))["features"]
349
- }
350
- assert statuses == {
351
- "F-001": "pending",
352
- "F-002": "pending",
353
- "F-003": "pending",
354
- "F-004": "pending",
355
- "F-005": "completed",
356
- }
357
- for status_path, before in before_statuses.values():
358
- expected = dict(before)
359
- expected.update(retry_count=0, infra_error_count=0, continuation_pending=True)
360
- assert json.loads(status_path.read_text(encoding="utf-8")) == expected
361
- assert "Failed roots restored: F-001, F-003" in result.render()
362
-
363
- plan_after = plan.read_bytes()
364
- runtime_after = {
365
- item_id: status_path.read_bytes()
366
- for item_id, (status_path, _before) in before_statuses.items()
367
- }
368
- second = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
369
- assert second.exit_code == 0
370
- assert "No failed" in second.render()
371
- assert plan.read_bytes() == plan_after
372
- assert {
373
- item_id: status_path.read_bytes()
374
- for item_id, (status_path, _before) in before_statuses.items()
375
- } == runtime_after
376
-
377
-
378
- def test_preserve_runtime_respects_existing_task_guard_without_mutation(tmp_path):
379
- from prizmkit_runtime.reset import run_reset_command
380
- from prizmkit_runtime.task_checkout import task_checkout_guard
381
-
382
- paths = _make_paths(tmp_path)
383
- _init_preserve_runtime_repo(paths)
384
- plan = _write_family_plan(
385
- paths,
386
- "feature",
387
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
388
- )
389
- subprocess.run(["git", "branch", "dev/F-001-existing", "main"], cwd=paths.project_root, check=True)
390
- family, status_path, _status, _checkout = _write_preserve_runtime_state(
391
- paths, "feature", "F-001", "dev/F-001-existing"
392
- )
393
- plan_before = plan.read_bytes()
394
- status_before = status_path.read_bytes()
395
-
396
- with task_checkout_guard(family.state_dir, "F-001"):
397
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
398
-
399
- assert result.exit_code == 1
400
- assert "checkout lifecycle is busy" in result.render()
401
- assert plan.read_bytes() == plan_before
402
- assert status_path.read_bytes() == status_before
403
-
404
-
405
- @pytest.mark.parametrize(
406
- ("kind", "item_id"),
407
- [("feature", "F-001"), ("bugfix", "B-001")],
408
- )
409
- def test_public_reset_cli_hard_rejects_run_for_every_family_without_state_change(tmp_path, kind, item_id):
410
- project = tmp_path / kind
411
- project.mkdir()
412
-
413
- completed = subprocess.run(
414
- [
415
- sys.executable,
416
- str(CLI_PATH),
417
- "--project-root",
418
- str(project),
419
- "reset",
420
- kind,
421
- item_id,
422
- "--run",
423
- ],
424
- cwd=REPO_ROOT,
425
- stdout=subprocess.PIPE,
426
- stderr=subprocess.PIPE,
427
- text=True,
428
- check=False,
429
- )
430
-
431
- assert completed.returncode == 2
432
- assert "unrecognized arguments: --run" in completed.stdout + completed.stderr
433
- assert not (project / ".prizmkit").exists()
434
-
435
-
436
- @pytest.mark.parametrize(
437
- ("items", "expected_error"),
438
- [
439
- (
440
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": ["F-999"]}],
441
- "unknown dependency F-999",
442
- ),
443
- (
444
- [
445
- {"id": "F-001", "title": "One", "status": "failed", "dependencies": ["F-002"]},
446
- {"id": "F-002", "title": "Two", "status": "auto_skipped", "dependencies": ["F-001"]},
447
- ],
448
- "dependency cycle",
449
- ),
450
- (
451
- [
452
- {"id": "F-001", "title": "One", "status": "failed", "dependencies": []},
453
- {"id": "F-001", "title": "Duplicate", "status": "failed", "dependencies": []},
454
- ],
455
- "duplicate item id: F-001",
456
- ),
457
- ],
458
- )
459
- def test_preserve_runtime_rejects_invalid_dependency_graph_without_state_mutation(
460
- tmp_path,
461
- items,
462
- expected_error,
463
- ):
464
- from prizmkit_runtime.reset import run_reset_command
465
-
466
- paths = _make_paths(tmp_path)
467
- plan = _write_family_plan(paths, "feature", items)
468
- before = plan.read_bytes()
469
-
470
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
471
-
472
- assert result.exit_code == 1
473
- assert expected_error in result.render()
474
- assert plan.read_bytes() == before
475
- assert not paths.feature_state_dir.exists()
476
-
477
-
478
- def test_preserve_runtime_success_quotes_list_path_in_separate_run_instruction(tmp_path):
479
- from prizmkit_runtime.reset import run_reset_command
480
-
481
- paths = _make_paths(tmp_path / "parent with spaces")
482
- _init_preserve_runtime_repo(paths)
483
- plan = _write_family_plan(
484
- paths,
485
- "feature",
486
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
487
- )
488
- subprocess.run(["git", "branch", "dev/F-001-existing", "main"], cwd=paths.project_root, check=True)
489
- _write_preserve_runtime_state(paths, "feature", "F-001", "dev/F-001-existing")
490
-
491
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
492
-
493
- assert result.exit_code == 0
494
- assert f"run feature {shlex.quote(str(plan.resolve()))}" in result.render()
495
-
496
-
497
- def test_preserve_runtime_requires_recorded_base_to_be_a_local_branch(tmp_path):
498
- from prizmkit_runtime.reset import run_reset_command
499
-
500
- paths = _make_paths(tmp_path)
501
- _init_preserve_runtime_repo(paths)
502
- subprocess.run(["git", "tag", "base-tag", "main"], cwd=paths.project_root, check=True)
503
- plan = _write_family_plan(
504
- paths,
505
- "feature",
506
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
507
- )
508
- _family, status_path, _before_status, _checkout = _write_preserve_runtime_state(
509
- paths,
510
- "feature",
511
- "F-001",
512
- "dev/F-001-missing",
513
- base_branch="base-tag",
514
- )
515
- plan_before = plan.read_bytes()
516
- status_before = status_path.read_bytes()
517
-
518
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
519
-
520
- assert result.exit_code == 1
521
- assert "recorded base branch is missing: base-tag" in result.render()
522
- assert plan.read_bytes() == plan_before
523
- assert status_path.read_bytes() == status_before
524
-
525
-
526
- def test_preserve_runtime_preflights_all_failed_roots_before_any_state_change(tmp_path):
527
- from prizmkit_runtime.reset import run_reset_command
528
-
529
- paths = _make_paths(tmp_path)
530
- _init_preserve_runtime_repo(paths)
531
- items = [
532
- {"id": "F-001", "title": "One", "status": "failed", "dependencies": []},
533
- {"id": "F-002", "title": "Two", "status": "failed", "dependencies": []},
534
- {"id": "F-003", "title": "Three", "status": "failed", "dependencies": []},
535
- ]
536
- plan = _write_family_plan(paths, "feature", items)
537
- subprocess.run(["git", "branch", "dev/F-001-existing", "main"], cwd=paths.project_root, check=True)
538
- family, status_one, _data_one, _checkout_one = _write_preserve_runtime_state(
539
- paths, "feature", "F-001", "dev/F-001-existing"
540
- )
541
- _family, status_two, _data_two, _checkout_two = _write_preserve_runtime_state(
542
- paths, "feature", "F-002", "dev/F-002-missing", base_branch="missing-base-two"
543
- )
544
- _family, status_three, _data_three, _checkout_three = _write_preserve_runtime_state(
545
- paths, "feature", "F-003", "dev/F-003-missing", base_branch="missing-base-three"
546
- )
547
- plan_before = plan.read_bytes()
548
- status_one_before = status_one.read_bytes()
549
- status_two_before = status_two.read_bytes()
550
- status_three_before = status_three.read_bytes()
551
- checkout_one_before = (family.state_dir / "F-001" / "checkout.json").read_bytes()
552
- branches_before = subprocess.run(
553
- ["git", "branch", "--format=%(refname:short)"],
554
- cwd=paths.project_root,
555
- check=True,
556
- stdout=subprocess.PIPE,
557
- text=True,
558
- ).stdout
559
-
560
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
561
-
562
- assert result.exit_code == 1
563
- assert "recorded base branch is missing: missing-base-two" in result.render()
564
- assert "recorded base branch is missing: missing-base-three" in result.render()
565
- assert plan.read_bytes() == plan_before
566
- assert status_one.read_bytes() == status_one_before
567
- assert status_two.read_bytes() == status_two_before
568
- assert status_three.read_bytes() == status_three_before
569
- assert (family.state_dir / "F-001" / "checkout.json").read_bytes() == checkout_one_before
570
- assert subprocess.run(
571
- ["git", "branch", "--format=%(refname:short)"],
572
- cwd=paths.project_root,
573
- check=True,
574
- stdout=subprocess.PIPE,
575
- text=True,
576
- ).stdout == branches_before
577
-
578
-
579
- def test_preserve_runtime_invalid_existing_checkpoint_blocks_before_mutation(tmp_path):
580
- from prizmkit_runtime.reset import run_reset_command
581
-
582
- paths = _make_paths(tmp_path)
583
- _init_preserve_runtime_repo(paths)
584
- plan = _write_family_plan(
585
- paths,
586
- "feature",
587
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
588
- )
589
- subprocess.run(["git", "branch", "dev/F-001-existing", "main"], cwd=paths.project_root, check=True)
590
- _family, status_path, _before_status, _checkout = _write_preserve_runtime_state(
591
- paths, "feature", "F-001", "dev/F-001-existing"
592
- )
593
- artifact = paths.project_root / ".prizmkit" / "specs" / "001-root"
594
- artifact.mkdir(parents=True)
595
- checkpoint = artifact / "workflow-checkpoint.json"
596
- checkpoint.write_text("{\"steps\": \"invalid\"}\n", encoding="utf-8")
597
- plan_before = plan.read_bytes()
598
- status_before = status_path.read_bytes()
599
- checkout_before = (
600
- paths.feature_state_dir / "F-001" / "checkout.json"
601
- ).read_bytes()
602
-
603
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
604
-
605
- assert result.exit_code == 1
606
- assert "invalid checkpoint" in result.render()
607
- assert plan.read_bytes() == plan_before
608
- assert status_path.read_bytes() == status_before
609
- assert (paths.feature_state_dir / "F-001" / "checkout.json").read_bytes() == checkout_before
610
- assert checkpoint.read_text(encoding="utf-8") == "{\"steps\": \"invalid\"}\n"
611
-
612
-
613
- def _add_completed_plan_step(checkpoint):
614
- payload = json.loads(checkpoint.read_text(encoding="utf-8"))
615
- payload["steps"].insert(
616
- 0,
617
- {
618
- "id": "S00",
619
- "skill": "prizmkit-plan",
620
- "name": "plan",
621
- "status": "completed",
622
- "stage_result": "PLAN_READY",
623
- "depends_on": None,
624
- "required_artifacts": [],
625
- },
626
- )
627
- payload["steps"][1]["depends_on"] = "S00"
628
- state_key = {
629
- "feature-pipeline": "feature_state",
630
- "bugfix-pipeline": "bugfix_state",
631
- }[payload["workflow_type"]]
632
- payload[state_key]["completed_stages"] = ["plan", "implement", "code-review", "test"]
633
- checkpoint.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")
634
-
635
-
636
- def test_preserve_runtime_missing_branch_creates_replacement_and_rewinds_checkpoint(tmp_path):
637
- from prizmkit_runtime.gitops import local_branch_exists
638
- from prizmkit_runtime.reset import run_reset_command
639
- from prizmkit_runtime.runner_models import family_for
640
- from prizmkit_runtime.task_checkout import load_task_checkout
641
-
642
- paths = _make_paths(tmp_path)
643
- _init_preserve_runtime_repo(paths)
644
- plan = _write_family_plan(
645
- paths,
646
- "feature",
647
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
648
- )
649
- family, status_path, before_status, old_checkout = _write_preserve_runtime_state(
650
- paths, "feature", "F-001", "dev/F-001-deleted"
651
- )
652
- artifact = paths.project_root / ".prizmkit" / "specs" / "001-root"
653
- checkpoint = _write_semantic_completion_checkpoint(paths.project_root, artifact)
654
- _add_completed_plan_step(checkpoint)
655
- (artifact / "implementation-notes.md").write_text("keep context\n", encoding="utf-8")
656
- session_log = family.state_dir / "F-001" / "sessions" / "old-session" / "logs" / "session.log"
657
- session_before = session_log.read_bytes()
658
- base_head = subprocess.run(
659
- ["git", "rev-parse", "main"], cwd=paths.project_root, check=True, stdout=subprocess.PIPE, text=True
660
- ).stdout.strip()
661
-
662
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
663
-
664
- assert result.exit_code == 0, result.render()
665
- checkout = load_task_checkout(family.state_dir, "feature", "F-001")
666
- assert checkout is not None and checkout.is_active and not checkout.is_reset
667
- assert checkout.active_dev_branch != old_checkout.active_dev_branch
668
- assert checkout.active_dev_branch.startswith("dev/F-001-resume-")
669
- assert checkout.base_branch == "main"
670
- assert local_branch_exists(paths.project_root, checkout.active_dev_branch)
671
- assert subprocess.run(
672
- ["git", "rev-parse", checkout.active_dev_branch],
673
- cwd=paths.project_root,
674
- check=True,
675
- stdout=subprocess.PIPE,
676
- text=True,
677
- ).stdout.strip() == base_head
678
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
679
- assert persisted["steps"][0]["status"] == "completed"
680
- assert persisted["steps"][0]["stage_result"] == "PLAN_READY"
681
- assert all(step["status"] == "pending" for step in persisted["steps"][1:])
682
- assert all("stage_result" not in step for step in persisted["steps"][1:])
683
- assert persisted["feature_state"]["stage"] == "implement"
684
- assert persisted["feature_state"]["current_stage"] == "prizmkit-implement"
685
- assert persisted["feature_state"]["completed_stages"] == ["plan"]
686
- assert (artifact / "implementation-notes.md").read_text(encoding="utf-8") == "keep context\n"
687
- expected_status = dict(before_status)
688
- expected_status.update(
689
- retry_count=0,
690
- infra_error_count=0,
691
- continuation_pending=True,
692
- active_dev_branch=checkout.active_dev_branch,
693
- base_branch="main",
694
- )
695
- assert json.loads(status_path.read_text(encoding="utf-8")) == expected_status
696
- assert session_log.read_bytes() == session_before
697
- assert json.loads(plan.read_text(encoding="utf-8"))["features"][0]["status"] == "pending"
698
-
699
-
700
- @pytest.mark.parametrize(
701
- ("kind", "item_id", "branch_prefix", "workflow_type", "artifact_root", "state_key"),
702
- [
703
- ("bugfix", "B-001", "bugfix", "bugfix-pipeline", "bugfix", "bugfix_state"),
704
- ],
705
- )
706
- def test_missing_branch_checkpoint_rewind_has_cross_family_parity(
707
- tmp_path,
708
- kind,
709
- item_id,
710
- branch_prefix,
711
- workflow_type,
712
- artifact_root,
713
- state_key,
714
- ):
715
- from prizmkit_runtime.gitops import local_branch_exists
716
- from prizmkit_runtime.reset import run_reset_command
717
- from prizmkit_runtime.runner_models import family_for
718
- from prizmkit_runtime.task_checkout import load_task_checkout
719
-
720
- paths = _make_paths(tmp_path / kind)
721
- _init_preserve_runtime_repo(paths)
722
- plan = _write_family_plan(
723
- paths,
724
- kind,
725
- [{"id": item_id, "title": "Root", "status": "failed", "dependencies": []}],
726
- )
727
- family, _status_path, _before_status, old_checkout = _write_preserve_runtime_state(
728
- paths, kind, item_id, f"{branch_prefix}/{item_id}-deleted"
729
- )
730
- artifact = paths.project_root / ".prizmkit" / artifact_root / item_id
731
- checkpoint = _write_semantic_completion_checkpoint(
732
- paths.project_root,
733
- artifact,
734
- workflow_type,
735
- )
736
- _add_completed_plan_step(checkpoint)
737
-
738
- result = run_reset_command(kind, ("--failed", "--preserve-runtime"), paths)
739
-
740
- assert result.exit_code == 0, result.render()
741
- checkout = load_task_checkout(family.state_dir, kind, item_id)
742
- assert checkout is not None and checkout.is_active
743
- assert checkout.active_dev_branch != old_checkout.active_dev_branch
744
- assert checkout.active_dev_branch.startswith(f"{branch_prefix}/{item_id}-resume-")
745
- assert local_branch_exists(paths.project_root, checkout.active_dev_branch)
746
- persisted = json.loads(checkpoint.read_text(encoding="utf-8"))
747
- assert persisted["steps"][0]["status"] == "completed"
748
- assert all(step["status"] == "pending" for step in persisted["steps"][1:])
749
- assert persisted[state_key]["stage"] == "implement"
750
- assert persisted[state_key]["current_stage"] == "prizmkit-implement"
751
- collection = {"bugfix": "bugs"}[kind]
752
- assert json.loads(plan.read_text(encoding="utf-8"))[collection][0]["status"] == "pending"
753
-
754
-
755
- def test_preserve_runtime_reuses_branch_checkout_without_cleanup(tmp_path):
756
- from prizmkit_runtime.gitops import create_branch_from_base, local_branch_exists, registered_worktrees
757
- from prizmkit_runtime.reset import run_reset_command
758
- from prizmkit_runtime.runner_models import family_for
759
- from prizmkit_runtime.task_checkout import (
760
- CHECKOUT_MODE_BRANCH,
761
- TaskCheckout,
762
- load_task_checkout,
763
- persist_task_checkout,
764
- )
765
-
766
- paths = _make_paths(tmp_path)
767
- _init_preserve_runtime_repo(paths)
768
- plan = _write_family_plan(
769
- paths,
770
- "feature",
771
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
772
- )
773
- family, status_path, _before_status, _old_checkout = _write_preserve_runtime_state(
774
- paths, "feature", "F-001", "dev/F-001-branch"
775
- )
776
- assert create_branch_from_base(paths.project_root, "dev/F-001-branch", "main").return_code == 0
777
- branch_checkout = TaskCheckout.active(
778
- "feature",
779
- "F-001",
780
- "dev/F-001-branch",
781
- "main",
782
- checkout_mode=CHECKOUT_MODE_BRANCH,
783
- )
784
- persist_task_checkout(family.state_dir, branch_checkout)
785
- artifact = paths.project_root / ".prizmkit" / "specs" / "001-root"
786
- artifact.mkdir(parents=True)
787
- marker = artifact / "partial.md"
788
- marker.write_text("branch WIP\n", encoding="utf-8")
789
- registrations_before = registered_worktrees(paths.project_root)
790
-
791
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
792
-
793
- assert result.exit_code == 0, result.render()
794
- assert load_task_checkout(family.state_dir, "feature", "F-001") == branch_checkout
795
- assert local_branch_exists(paths.project_root, "dev/F-001-branch")
796
- assert marker.read_text(encoding="utf-8") == "branch WIP\n"
797
- assert registered_worktrees(paths.project_root) == registrations_before
798
- assert json.loads(status_path.read_text(encoding="utf-8"))["continuation_pending"] is True
799
- assert json.loads(plan.read_text(encoding="utf-8"))["features"][0]["status"] == "pending"
800
-
801
-
802
- def test_replacement_branch_skips_registered_branch_collision(monkeypatch, tmp_path):
803
- from prizmkit_runtime import reset_preserve
804
- from prizmkit_runtime.gitops import RegisteredWorktree
805
- from prizmkit_runtime.runner_models import family_for
806
-
807
- paths = _make_paths(tmp_path)
808
- _init_preserve_runtime_repo(paths)
809
- family = family_for("feature", paths)
810
- item = reset_preserve.PreservePlanItem(
811
- "F-001", "Root", "001-root", "failed", (), 0
812
- )
813
- monkeypatch.setattr(reset_preserve.time, "strftime", lambda *_args: "20260725120000")
814
- registration = RegisteredWorktree(
815
- tmp_path / "other-checkout",
816
- "dev/F-001-resume-20260725120000",
817
- )
818
-
819
- branch = reset_preserve._replacement_identity(
820
- family,
821
- item,
822
- paths.project_root,
823
- (registration,),
824
- )
825
-
826
- assert branch == "dev/F-001-resume-20260725120000-1"
827
-
828
-
829
- def test_preserve_runtime_rejects_legacy_worktree_checkout(tmp_path):
830
- from prizmkit_runtime.reset import run_reset_command
831
- from prizmkit_runtime.task_checkout import TaskCheckoutError, load_task_checkout
832
-
833
- paths = _make_paths(tmp_path)
834
- _init_preserve_runtime_repo(paths)
835
- plan = _write_family_plan(
836
- paths,
837
- "feature",
838
- [{"id": "F-001", "title": "Root", "status": "failed", "dependencies": []}],
839
- )
840
- family, status_path, _before_status, _branch_checkout = _write_preserve_runtime_state(
841
- paths, "feature", "F-001", "dev/F-001-legacy-worktree"
842
- )
843
- legacy_worktree = tmp_path / "legacy-worktrees" / "dev-F-001-legacy-worktree"
844
- legacy_checkout_path = family.state_dir / "F-001" / "checkout.json"
845
- legacy_checkout_path.write_text(
846
- json.dumps(
847
- {
848
- "task_type": "feature",
849
- "task_id": "F-001",
850
- "state": "active",
851
- "active_dev_branch": "dev/F-001-legacy-worktree",
852
- "base_branch": "main",
853
- "checkout_mode": "worktree",
854
- "worktree_path": str(legacy_worktree),
855
- }
856
- ),
857
- encoding="utf-8",
858
- )
859
-
860
- with pytest.raises(TaskCheckoutError, match="retired worktree checkout mode"):
861
- load_task_checkout(family.state_dir, "feature", "F-001")
862
-
863
- status_before = status_path.read_bytes()
864
- plan_before = plan.read_bytes()
865
-
866
- result = run_reset_command("feature", ("--failed", "--preserve-runtime"), paths)
867
-
868
- assert result.exit_code != 0
869
- assert "retired worktree checkout mode" in result.render()
870
- assert str(legacy_worktree) in result.render()
871
- assert status_path.read_bytes() == status_before
872
- assert plan.read_bytes() == plan_before