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,1196 +0,0 @@
1
- """Focused tests for explicit reset modes and causal state recovery."""
2
-
3
- from __future__ import annotations
4
-
5
- import json
6
- import subprocess
7
- import sys
8
- from pathlib import Path
9
-
10
- import pytest
11
-
12
- from utils import causal_reset_selection, orphaned_auto_skipped_ids
13
-
14
- REPO_ROOT = Path(__file__).resolve().parents[2]
15
- PIPELINE_ROOT = REPO_ROOT / "dev-pipeline"
16
-
17
-
18
- def _item(item_id, status="pending", dependencies=None, **extra):
19
- return {
20
- "id": item_id,
21
- "title": item_id,
22
- "status": status,
23
- "dependencies": list(dependencies or []),
24
- **extra,
25
- }
26
-
27
-
28
- @pytest.mark.parametrize(
29
- ("prefix", "root_statuses"),
30
- (
31
- ("F-", {"failed", "skipped"}),
32
- ("B-", {"failed", "skipped", "needs_info"}),
33
- ("R-", {"failed", "skipped"}),
34
- ),
35
- )
36
- def test_causal_selection_single_root_recovers_only_complete_chain(prefix, root_statuses):
37
- items = [
38
- _item(f"{prefix}001", "failed"),
39
- _item(f"{prefix}002", "auto_skipped", [f"{prefix}001"]),
40
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}002"]),
41
- _item(f"{prefix}004", "completed", [f"{prefix}001"], marker="preserve"),
42
- _item(f"{prefix}005", "failed"),
43
- _item(f"{prefix}006", "auto_skipped", [f"{prefix}005"]),
44
- ]
45
-
46
- selected = causal_reset_selection(
47
- items,
48
- selected_id=f"{prefix}001",
49
- blocking_root_statuses=root_statuses,
50
- item_label="Task",
51
- )
52
-
53
- assert selected == (f"{prefix}001", f"{prefix}002", f"{prefix}003")
54
- assert items[3]["status"] == "completed"
55
- assert items[3]["marker"] == "preserve"
56
-
57
-
58
- @pytest.mark.parametrize("prefix", ("F-", "B-", "R-"))
59
- def test_causal_selection_keeps_multi_root_descendant_blocked(prefix):
60
- root_statuses = {"failed", "skipped", "needs_info"} if prefix == "B-" else {"failed", "skipped"}
61
- items = [
62
- _item(f"{prefix}001", "failed"),
63
- _item(f"{prefix}002", "skipped"),
64
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}001"]),
65
- _item(f"{prefix}004", "auto_skipped", [f"{prefix}003", f"{prefix}002"]),
66
- _item(f"{prefix}005", "auto_skipped", [f"{prefix}002"]),
67
- ]
68
-
69
- selected = causal_reset_selection(
70
- items,
71
- selected_id=f"{prefix}001",
72
- blocking_root_statuses=root_statuses,
73
- )
74
-
75
- assert selected == (f"{prefix}001", f"{prefix}003")
76
-
77
-
78
- def test_causal_selection_does_not_cross_an_orphan_auto_skipped_blocker():
79
- items = [
80
- _item("F-001", "failed"),
81
- _item("F-002", "auto_skipped"),
82
- _item("F-003", "auto_skipped", ["F-001", "F-002"]),
83
- ]
84
-
85
- selected = causal_reset_selection(
86
- items,
87
- selected_id="F-001",
88
- blocking_root_statuses={"failed", "skipped"},
89
- )
90
-
91
- assert selected == ("F-001",)
92
-
93
-
94
- @pytest.mark.parametrize("prefix", ("F-", "B-", "R-"))
95
- def test_selecting_auto_skipped_leaf_includes_every_required_root(prefix):
96
- root_statuses = {"failed", "skipped", "needs_info"} if prefix == "B-" else {"failed", "skipped"}
97
- second_root_status = "needs_info" if prefix == "B-" else "skipped"
98
- items = [
99
- _item(f"{prefix}001", "failed"),
100
- _item(f"{prefix}002", second_root_status),
101
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}001"]),
102
- _item(f"{prefix}004", "auto_skipped", [f"{prefix}002"]),
103
- _item(f"{prefix}005", "auto_skipped", [f"{prefix}003", f"{prefix}004"]),
104
- _item(f"{prefix}006", "completed"),
105
- ]
106
-
107
- selected = causal_reset_selection(
108
- items,
109
- selected_id=f"{prefix}005",
110
- blocking_root_statuses=root_statuses,
111
- )
112
-
113
- assert selected == (
114
- f"{prefix}001",
115
- f"{prefix}002",
116
- f"{prefix}003",
117
- f"{prefix}004",
118
- f"{prefix}005",
119
- )
120
-
121
-
122
- @pytest.mark.parametrize(
123
- ("prefix", "root_statuses", "root_status"),
124
- (
125
- ("F-", {"failed", "skipped"}, "skipped"),
126
- ("B-", {"failed", "skipped", "needs_info"}, "needs_info"),
127
- ("R-", {"failed", "skipped"}, "skipped"),
128
- ),
129
- )
130
- def test_causal_selection_all_recovers_every_supported_chain(prefix, root_statuses, root_status):
131
- items = [
132
- _item(f"{prefix}001", "failed"),
133
- _item(f"{prefix}002", root_status),
134
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}001", f"{prefix}002"]),
135
- _item(f"{prefix}004", "completed"),
136
- _item(f"{prefix}005", "pending"),
137
- ]
138
-
139
- selected = causal_reset_selection(
140
- items,
141
- selected_id=None,
142
- blocking_root_statuses=root_statuses,
143
- )
144
-
145
- assert selected == (f"{prefix}001", f"{prefix}002", f"{prefix}003")
146
-
147
-
148
- def test_causal_selection_rejects_missing_and_invalid_targets():
149
- items = [
150
- _item("F-001", "failed"),
151
- _item("F-002", "pending"),
152
- _item("F-003", "auto_skipped"),
153
- ]
154
-
155
- with pytest.raises(ValueError, match="not found"):
156
- causal_reset_selection(items, selected_id="F-999", blocking_root_statuses={"failed", "skipped"})
157
- with pytest.raises(ValueError, match="not recoverable"):
158
- causal_reset_selection(items, selected_id="F-002", blocking_root_statuses={"failed", "skipped"})
159
-
160
-
161
- @pytest.mark.parametrize("prefix", ("F-", "B-", "R-"))
162
- def test_causal_selection_recovers_selected_orphan_and_eligible_descendants(prefix):
163
- root_statuses = {"failed", "skipped", "needs_info"} if prefix == "B-" else {"failed", "skipped"}
164
- items = [
165
- _item(f"{prefix}001", "completed"),
166
- _item(f"{prefix}002", "auto_skipped", [f"{prefix}001"]),
167
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}002"]),
168
- _item(f"{prefix}004", "auto_skipped", [f"{prefix}001"]),
169
- ]
170
-
171
- selected = causal_reset_selection(
172
- items,
173
- selected_id=f"{prefix}002",
174
- blocking_root_statuses=root_statuses,
175
- )
176
-
177
- assert selected == (f"{prefix}002", f"{prefix}003")
178
- assert orphaned_auto_skipped_ids(
179
- items,
180
- blocking_root_statuses=root_statuses,
181
- ) == (f"{prefix}002", f"{prefix}003", f"{prefix}004")
182
-
183
-
184
- @pytest.mark.parametrize("prefix", ("F-", "B-", "R-"))
185
- def test_causal_selection_all_recovers_orphans_when_no_blocking_root_remains(prefix):
186
- root_statuses = {"failed", "skipped", "needs_info"} if prefix == "B-" else {"failed", "skipped"}
187
- items = [
188
- _item(f"{prefix}001", "completed"),
189
- _item(f"{prefix}002", "auto_skipped", [f"{prefix}001"]),
190
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}002"]),
191
- ]
192
-
193
- selected = causal_reset_selection(
194
- items,
195
- selected_id=None,
196
- blocking_root_statuses=root_statuses,
197
- )
198
-
199
- assert selected == (f"{prefix}002", f"{prefix}003")
200
-
201
-
202
- def test_orphan_analysis_keeps_multi_root_item_blocked_until_every_root_resolves():
203
- items = [
204
- _item("F-001", "completed"),
205
- _item("F-002", "failed"),
206
- _item("F-003", "auto_skipped", ["F-001", "F-002"]),
207
- ]
208
-
209
- assert orphaned_auto_skipped_ids(
210
- items,
211
- blocking_root_statuses={"failed", "skipped"},
212
- ) == ()
213
-
214
- items[1]["status"] = "in_progress"
215
- assert orphaned_auto_skipped_ids(
216
- items,
217
- blocking_root_statuses={"failed", "skipped"},
218
- ) == ("F-003",)
219
-
220
-
221
- def test_causal_selection_rejects_invalid_dependency_graph_before_selection():
222
- items = [
223
- _item("F-001", "failed", ["F-002"]),
224
- _item("F-002", "auto_skipped", ["F-001"]),
225
- ]
226
-
227
- with pytest.raises(ValueError, match="Dependency cycle"):
228
- causal_reset_selection(items, selected_id="F-001", blocking_root_statuses={"failed", "skipped"})
229
-
230
-
231
- FAMILY_CONTRACTS = {
232
- "feature": {
233
- "prefix": "F-",
234
- "list_key": "features",
235
- "list_arg": "--feature-list",
236
- "id_arg": "--feature-id",
237
- "schema": "dev-pipeline-feature-list-v1",
238
- "script": "update-feature-status.py",
239
- "branch_prefix": "dev",
240
- "artifact_root": "specs",
241
- },
242
- "bugfix": {
243
- "prefix": "B-",
244
- "list_key": "bugs",
245
- "list_arg": "--bug-list",
246
- "id_arg": "--bug-id",
247
- "schema": "dev-pipeline-bug-fix-list-v1",
248
- "script": "update-bug-status.py",
249
- "branch_prefix": "bugfix",
250
- "artifact_root": "bugfix",
251
- },
252
- }
253
-
254
-
255
- def _make_paths(tmp_path):
256
- from prizmkit_runtime.paths import resolve_runtime_paths
257
-
258
- project_root = tmp_path / "project"
259
- (project_root / ".prizmkit" / "plans").mkdir(parents=True)
260
- return resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=project_root)
261
-
262
-
263
- def _family_and_plan(paths, kind, items):
264
- from prizmkit_runtime.runner_models import family_for
265
-
266
- family = family_for(kind, paths)
267
- contract = FAMILY_CONTRACTS[kind]
268
- family.plan_path.write_text(
269
- json.dumps(
270
- {
271
- "$schema": contract["schema"],
272
- "project_name": "Reset Test",
273
- contract["list_key"]: items,
274
- },
275
- indent=2,
276
- )
277
- + "\n",
278
- encoding="utf-8",
279
- )
280
- return family, family.plan_path
281
-
282
-
283
- def _write_runtime_status(family, item_id, **overrides):
284
- status_dir = family.state_dir / item_id
285
- status_dir.mkdir(parents=True, exist_ok=True)
286
- status = {
287
- f"{family.kind if family.kind != 'bugfix' else 'bug'}_id": item_id,
288
- "retry_count": 4,
289
- "infra_error_count": 3,
290
- "last_infra_error_session_id": "old-session",
291
- "sessions": ["old-session"],
292
- "last_session_id": "old-session",
293
- "last_failed_session_id": "old-session",
294
- "resume_from_phase": 4,
295
- "continuation_pending": True,
296
- "continuation_reason": "context_overflow",
297
- "continuation_count": 2,
298
- "context_overflow_count": 2,
299
- "previous_session_id": "old-session",
300
- "custom_diagnostic": {"keep": True},
301
- **overrides,
302
- }
303
- status_path = status_dir / "status.json"
304
- status_path.write_text(json.dumps(status, indent=2) + "\n", encoding="utf-8")
305
- return status_path, status
306
-
307
-
308
- def _tree_snapshot(root):
309
- if not root.exists():
310
- return {}
311
- return {
312
- str(path.relative_to(root)): path.read_bytes()
313
- for path in sorted(root.rglob("*"))
314
- if path.is_file()
315
- }
316
-
317
-
318
- def _git(project_root, *args):
319
- return subprocess.run(
320
- ["git", *args],
321
- cwd=project_root,
322
- text=True,
323
- stdout=subprocess.PIPE,
324
- stderr=subprocess.PIPE,
325
- check=True,
326
- ).stdout.strip()
327
-
328
-
329
- def _init_git_repository(project_root):
330
- subprocess.run(
331
- ["git", "init", "-b", "main"],
332
- cwd=project_root,
333
- stdout=subprocess.DEVNULL,
334
- check=True,
335
- )
336
- _git(project_root, "config", "user.email", "reset@example.com")
337
- _git(project_root, "config", "user.name", "Reset Test")
338
- source = project_root / "source.txt"
339
- source.write_text("committed\n", encoding="utf-8")
340
- _git(project_root, "add", "source.txt")
341
- _git(project_root, "commit", "-m", "base")
342
- source.write_text("committed\nlocal work\n", encoding="utf-8")
343
- return source
344
-
345
-
346
- @pytest.mark.parametrize("kind", ("feature", "bugfix"))
347
- def test_state_only_resets_exact_causal_records_and_preserves_checkout_git_and_artifacts(tmp_path, kind):
348
- from prizmkit_runtime.reset import run_reset_command
349
- from prizmkit_runtime.task_checkout import (
350
- CHECKOUT_MODE_BRANCH,
351
- TaskCheckout,
352
- persist_task_checkout,
353
- )
354
-
355
- paths = _make_paths(tmp_path / kind)
356
- contract = FAMILY_CONTRACTS[kind]
357
- prefix = contract["prefix"]
358
- root_id = f"{prefix}001"
359
- child_id = f"{prefix}002"
360
- other_root_id = f"{prefix}003"
361
- shared_id = f"{prefix}004"
362
- completed_id = f"{prefix}005"
363
- unrelated_child_id = f"{prefix}006"
364
- items = [
365
- _item(root_id, "failed", marker="root-field"),
366
- _item(child_id, "auto_skipped", [root_id], marker="child-field"),
367
- _item(other_root_id, "failed", marker="other-root-field"),
368
- _item(shared_id, "auto_skipped", [child_id, other_root_id], marker="shared-field"),
369
- _item(completed_id, "completed", marker="completed-field"),
370
- _item(unrelated_child_id, "auto_skipped", [other_root_id], marker="unrelated-field"),
371
- ]
372
- family, plan_path = _family_and_plan(paths, kind, items)
373
- source_path = _init_git_repository(paths.project_root)
374
- branch_name = f"{contract['branch_prefix']}/{root_id}-preserved"
375
- _git(paths.project_root, "branch", branch_name, "main")
376
-
377
- extra_dir = paths.project_root / ".task-worktrees" / root_id
378
- extra_dir.mkdir(parents=True)
379
- extra_marker = extra_dir / "keep.txt"
380
- extra_marker.write_text("checkout files remain\n", encoding="utf-8")
381
- checkout = TaskCheckout.active(
382
- kind,
383
- root_id,
384
- branch_name,
385
- "main",
386
- checkout_mode=CHECKOUT_MODE_BRANCH,
387
- )
388
- persist_task_checkout(family.state_dir, checkout)
389
- checkout_path = family.state_dir / root_id / "checkout.json"
390
-
391
- root_status_path, _root_before = _write_runtime_status(
392
- family,
393
- root_id,
394
- active_dev_branch=branch_name,
395
- base_branch="main",
396
- )
397
- child_status_path, _child_before = _write_runtime_status(family, child_id)
398
- other_status_path, _other_before = _write_runtime_status(family, other_root_id)
399
- completed_status_path, _completed_before = _write_runtime_status(family, completed_id)
400
-
401
- session_log = family.state_dir / root_id / "sessions" / "old-session" / "logs" / "session.log"
402
- session_log.parent.mkdir(parents=True)
403
- session_log.write_text("session history\n", encoding="utf-8")
404
- artifact_name = "001-root" if kind == "feature" else root_id
405
- artifact_dir = paths.project_root / ".prizmkit" / contract["artifact_root"] / artifact_name
406
- artifact_dir.mkdir(parents=True)
407
- checkpoint = artifact_dir / "workflow-checkpoint.json"
408
- checkpoint.write_text('{"sentinel":"checkpoint"}\n', encoding="utf-8")
409
- artifact = artifact_dir / "spec.md"
410
- artifact.write_text("artifact remains\n", encoding="utf-8")
411
-
412
- protected_bytes = {
413
- "checkout": checkout_path.read_bytes(),
414
- "session": session_log.read_bytes(),
415
- "checkpoint": checkpoint.read_bytes(),
416
- "artifact": artifact.read_bytes(),
417
- "extra": extra_marker.read_bytes(),
418
- "other_status": other_status_path.read_bytes(),
419
- "completed_status": completed_status_path.read_bytes(),
420
- "source": source_path.read_bytes(),
421
- }
422
- branch_refs_before = _git(paths.project_root, "show-ref", "--heads")
423
- branch_before = _git(paths.project_root, "branch", "--show-current")
424
- source_diff_before = _git(paths.project_root, "diff", "--", "source.txt")
425
-
426
- result = run_reset_command(
427
- kind,
428
- (root_id, "--state-only", str(plan_path)),
429
- paths,
430
- )
431
-
432
- assert result.exit_code == 0, result.render()
433
- payload = json.loads(result.render())
434
- assert payload["action"] == "reset_state"
435
- assert payload["reset_count"] == 2
436
- updated = json.loads(plan_path.read_text(encoding="utf-8"))[contract["list_key"]]
437
- statuses = {item["id"]: item["status"] for item in updated}
438
- assert statuses == {
439
- root_id: "pending",
440
- child_id: "pending",
441
- other_root_id: "failed",
442
- shared_id: "auto_skipped",
443
- completed_id: "completed",
444
- unrelated_child_id: "auto_skipped",
445
- }
446
- assert {item["id"]: item["marker"] for item in updated} == {
447
- root_id: "root-field",
448
- child_id: "child-field",
449
- other_root_id: "other-root-field",
450
- shared_id: "shared-field",
451
- completed_id: "completed-field",
452
- unrelated_child_id: "unrelated-field",
453
- }
454
-
455
- for selected_status_path in (root_status_path, child_status_path):
456
- selected_status = json.loads(selected_status_path.read_text(encoding="utf-8"))
457
- assert selected_status["retry_count"] == 0
458
- assert selected_status["infra_error_count"] == 0
459
- assert selected_status["last_infra_error_session_id"] is None
460
- assert selected_status["sessions"] == []
461
- assert selected_status["last_session_id"] is None
462
- assert selected_status["last_failed_session_id"] is None
463
- assert selected_status["resume_from_phase"] is None
464
- assert selected_status["custom_diagnostic"] == {"keep": True}
465
- for continuation_key in (
466
- "continuation_pending",
467
- "continuation_reason",
468
- "continuation_count",
469
- "context_overflow_count",
470
- "previous_session_id",
471
- ):
472
- assert continuation_key not in selected_status
473
-
474
- root_status = json.loads(root_status_path.read_text(encoding="utf-8"))
475
- assert root_status["active_dev_branch"] == branch_name
476
- assert root_status["base_branch"] == "main"
477
- assert checkout_path.read_bytes() == protected_bytes["checkout"]
478
- assert session_log.read_bytes() == protected_bytes["session"]
479
- assert checkpoint.read_bytes() == protected_bytes["checkpoint"]
480
- assert artifact.read_bytes() == protected_bytes["artifact"]
481
- assert extra_marker.read_bytes() == protected_bytes["extra"]
482
- assert other_status_path.read_bytes() == protected_bytes["other_status"]
483
- assert completed_status_path.read_bytes() == protected_bytes["completed_status"]
484
- assert source_path.read_bytes() == protected_bytes["source"]
485
- assert _git(paths.project_root, "show-ref", "--heads") == branch_refs_before
486
- assert _git(paths.project_root, "branch", "--show-current") == branch_before
487
- assert _git(paths.project_root, "diff", "--", "source.txt") == source_diff_before
488
- assert not (family.state_dir / "pipeline.json").exists()
489
-
490
-
491
- @pytest.mark.parametrize(
492
- ("kind", "second_root_status"),
493
- (("feature", "skipped"), ("bugfix", "needs_info")),
494
- )
495
- def test_state_only_all_recovers_all_supported_chains_without_pipeline_state(tmp_path, kind, second_root_status):
496
- from prizmkit_runtime.reset import run_reset_command
497
-
498
- paths = _make_paths(tmp_path / kind)
499
- contract = FAMILY_CONTRACTS[kind]
500
- prefix = contract["prefix"]
501
- items = [
502
- _item(f"{prefix}001", "failed"),
503
- _item(f"{prefix}002", second_root_status),
504
- _item(f"{prefix}003", "auto_skipped", [f"{prefix}001", f"{prefix}002"]),
505
- _item(f"{prefix}004", "completed", marker="done"),
506
- _item(f"{prefix}005", "pending", marker="unrelated"),
507
- ]
508
- family, plan_path = _family_and_plan(paths, kind, items)
509
- completed_status_path, _ = _write_runtime_status(family, f"{prefix}004")
510
- completed_before = completed_status_path.read_bytes()
511
-
512
- result = run_reset_command(
513
- kind,
514
- ("--state-only", "--all", str(plan_path)),
515
- paths,
516
- )
517
-
518
- assert result.exit_code == 0, result.render()
519
- payload = json.loads(result.render())
520
- assert payload["action"] == "reset_state"
521
- assert payload["reset_count"] == 3
522
- updated = json.loads(plan_path.read_text(encoding="utf-8"))[contract["list_key"]]
523
- assert [item["status"] for item in updated] == [
524
- "pending",
525
- "pending",
526
- "pending",
527
- "completed",
528
- "pending",
529
- ]
530
- assert completed_status_path.read_bytes() == completed_before
531
- assert not (family.state_dir / "pipeline.json").exists()
532
-
533
-
534
- @pytest.mark.parametrize("kind", ("feature", "bugfix"))
535
- def test_state_only_all_recovers_rootless_auto_skipped_chain(tmp_path, kind):
536
- from prizmkit_runtime.reset import run_reset_command
537
-
538
- paths = _make_paths(tmp_path / kind)
539
- contract = FAMILY_CONTRACTS[kind]
540
- prefix = contract["prefix"]
541
- root_id = f"{prefix}001"
542
- child_id = f"{prefix}002"
543
- leaf_id = f"{prefix}003"
544
- family, plan_path = _family_and_plan(
545
- paths,
546
- kind,
547
- [
548
- _item(root_id, "completed"),
549
- _item(child_id, "auto_skipped", [root_id]),
550
- _item(leaf_id, "auto_skipped", [child_id]),
551
- ],
552
- )
553
- child_status_path, _ = _write_runtime_status(family, child_id)
554
- session_marker = family.state_dir / child_id / "sessions" / "old-session" / "session.log"
555
- session_marker.parent.mkdir(parents=True)
556
- session_marker.write_text("preserve session artifact\n", encoding="utf-8")
557
-
558
- result = run_reset_command(
559
- kind,
560
- ("--state-only", "--all", str(plan_path)),
561
- paths,
562
- )
563
-
564
- assert result.exit_code == 0, result.render()
565
- payload = json.loads(result.render())
566
- assert payload["reset_count"] == 2
567
- updated = json.loads(plan_path.read_text(encoding="utf-8"))[contract["list_key"]]
568
- assert [item["status"] for item in updated] == ["completed", "pending", "pending"]
569
- assert session_marker.read_text(encoding="utf-8") == "preserve session artifact\n"
570
- assert json.loads(child_status_path.read_text(encoding="utf-8"))["custom_diagnostic"] == {"keep": True}
571
-
572
-
573
- @pytest.mark.parametrize("kind", ("feature", "bugfix"))
574
- def test_state_only_selected_orphan_recovers_only_its_causal_descendants(tmp_path, kind):
575
- from prizmkit_runtime.reset import run_reset_command
576
-
577
- paths = _make_paths(tmp_path / kind)
578
- contract = FAMILY_CONTRACTS[kind]
579
- prefix = contract["prefix"]
580
- root_id = f"{prefix}001"
581
- selected_id = f"{prefix}002"
582
- leaf_id = f"{prefix}003"
583
- sibling_id = f"{prefix}004"
584
- family, plan_path = _family_and_plan(
585
- paths,
586
- kind,
587
- [
588
- _item(root_id, "completed"),
589
- _item(selected_id, "auto_skipped", [root_id]),
590
- _item(leaf_id, "auto_skipped", [selected_id]),
591
- _item(sibling_id, "auto_skipped", [root_id]),
592
- ],
593
- )
594
-
595
- result = run_reset_command(
596
- kind,
597
- (selected_id, "--state-only", str(plan_path)),
598
- paths,
599
- )
600
-
601
- assert result.exit_code == 0, result.render()
602
- payload = json.loads(result.render())
603
- assert payload["reset_count"] == 2
604
- updated = json.loads(plan_path.read_text(encoding="utf-8"))[contract["list_key"]]
605
- assert {item["id"]: item["status"] for item in updated} == {
606
- root_id: "completed",
607
- selected_id: "pending",
608
- leaf_id: "pending",
609
- sibling_id: "auto_skipped",
610
- }
611
-
612
-
613
- @pytest.mark.parametrize("kind", ("feature", "bugfix"))
614
- def test_reset_without_mode_fails_before_any_mutation(tmp_path, kind):
615
- from prizmkit_runtime.reset import run_reset_command
616
-
617
- paths = _make_paths(tmp_path / kind)
618
- prefix = FAMILY_CONTRACTS[kind]["prefix"]
619
- family, plan_path = _family_and_plan(paths, kind, [_item(f"{prefix}001", "failed")])
620
- marker = family.state_dir / "sentinel.bin"
621
- marker.parent.mkdir(parents=True)
622
- marker.write_bytes(b"runtime-sentinel")
623
- before_plan = plan_path.read_bytes()
624
- before_state = _tree_snapshot(family.state_dir)
625
-
626
- result = run_reset_command(kind, (f"{prefix}001", str(plan_path)), paths)
627
-
628
- assert result.exit_code != 0
629
- assert "Exactly one reset mode is required" in result.render()
630
- assert "--state-only" in result.render()
631
- assert plan_path.read_bytes() == before_plan
632
- assert _tree_snapshot(family.state_dir) == before_state
633
-
634
-
635
- @pytest.mark.parametrize(
636
- "mode_pair",
637
- (
638
- ("--state-only", "--fresh-checkout"),
639
- ("--state-only", "--clean"),
640
- ("--state-only", "--preserve-runtime"),
641
- ("--fresh-checkout", "--clean"),
642
- ("--fresh-checkout", "--preserve-runtime"),
643
- ("--clean", "--preserve-runtime"),
644
- ),
645
- )
646
- def test_conflicting_reset_modes_fail_before_mutation(tmp_path, mode_pair):
647
- from prizmkit_runtime.reset import run_reset_command
648
-
649
- paths = _make_paths(tmp_path)
650
- family, plan_path = _family_and_plan(paths, "feature", [_item("F-001", "failed")])
651
- marker = family.state_dir / "sentinel.bin"
652
- marker.parent.mkdir(parents=True)
653
- marker.write_bytes(b"runtime-sentinel")
654
- before_plan = plan_path.read_bytes()
655
- before_state = _tree_snapshot(family.state_dir)
656
-
657
- result = run_reset_command(
658
- "feature",
659
- ("F-001", *mode_pair, "--failed", str(plan_path)),
660
- paths,
661
- )
662
-
663
- assert result.exit_code != 0
664
- assert "Exactly one reset mode is required" in result.render()
665
- assert plan_path.read_bytes() == before_plan
666
- assert _tree_snapshot(family.state_dir) == before_state
667
-
668
-
669
- @pytest.mark.parametrize(
670
- ("args", "message"),
671
- (
672
- (("F-001", "--standard"), "Unsupported reset arguments"),
673
- (("--state-only",), "requires exactly one item ID or explicit --all"),
674
- (("F-001", "--state-only", "--all"), "requires exactly one item ID or explicit --all"),
675
- (("F-001:F-002", "--state-only"), "ranges and status filters are unsupported"),
676
- (("--failed", "--state-only"), "ranges and status filters are unsupported"),
677
- (("--fresh-checkout",), "requires exactly one item ID, range, or supported status filter"),
678
- (("--fresh-checkout", "--all"), "--all is supported only with --state-only"),
679
- (("--clean",), "requires exactly one item ID, range, or supported status filter"),
680
- (("--clean", "--all"), "--all is supported only with --state-only"),
681
- (("--preserve-runtime",), "requires --failed"),
682
- (("F-001", "--failed", "--preserve-runtime"), "cannot target an ID, range, or --all"),
683
- (("--failed", "--preserve-runtime", "--all"), "cannot target an ID, range, or --all"),
684
- ),
685
- )
686
- def test_reset_selector_matrix_rejects_unsupported_forms_before_mutation(tmp_path, args, message):
687
- from prizmkit_runtime.reset import run_reset_command
688
-
689
- paths = _make_paths(tmp_path)
690
- family, plan_path = _family_and_plan(
691
- paths,
692
- "feature",
693
- [_item("F-001", "failed"), _item("F-002", "auto_skipped", ["F-001"])],
694
- )
695
- marker = family.state_dir / "sentinel.bin"
696
- marker.parent.mkdir(parents=True)
697
- marker.write_bytes(b"runtime-sentinel")
698
- before_plan = plan_path.read_bytes()
699
- before_state = _tree_snapshot(family.state_dir)
700
-
701
- result = run_reset_command("feature", (*args, str(plan_path)), paths)
702
-
703
- assert result.exit_code != 0
704
- assert message in result.render()
705
- assert plan_path.read_bytes() == before_plan
706
- assert _tree_snapshot(family.state_dir) == before_state
707
-
708
-
709
- @pytest.mark.parametrize(
710
- ("items", "args", "message"),
711
- (
712
- ([_item("F-001", "failed")], ("F-999", "--state-only"), "not found"),
713
- ([_item("F-001", "pending")], ("F-001", "--state-only"), "not recoverable"),
714
- ([_item("F-001", "completed")], ("--state-only", "--all"), "No recoverable blocking roots"),
715
- (
716
- [_item("F-001", "failed", ["F-002"]), _item("F-002", "auto_skipped", ["F-001"])],
717
- ("F-001", "--state-only"),
718
- "Dependency cycle",
719
- ),
720
- ),
721
- )
722
- def test_state_only_invalid_target_or_graph_is_fail_closed(tmp_path, items, args, message):
723
- from prizmkit_runtime.reset import run_reset_command
724
-
725
- paths = _make_paths(tmp_path)
726
- family, plan_path = _family_and_plan(paths, "feature", items)
727
- marker = family.state_dir / "sentinel.bin"
728
- marker.parent.mkdir(parents=True)
729
- marker.write_bytes(b"runtime-sentinel")
730
- before_plan = plan_path.read_bytes()
731
- before_state = _tree_snapshot(family.state_dir)
732
-
733
- result = run_reset_command("feature", (*args, str(plan_path)), paths)
734
-
735
- assert result.exit_code != 0
736
- assert message in result.render()
737
- assert plan_path.read_bytes() == before_plan
738
- assert _tree_snapshot(family.state_dir) == before_state
739
-
740
-
741
- @pytest.mark.parametrize("kind", ("feature", "bugfix"))
742
- @pytest.mark.parametrize("mode", ("--fresh-checkout", "--clean"))
743
- @pytest.mark.parametrize(
744
- ("selector", "expected_numbers"),
745
- (
746
- (("X-003",), (3,)),
747
- (("X-001:X-002",), (1, 2)),
748
- (("--failed",), (1,)),
749
- ),
750
- )
751
- def test_fresh_checkout_and_clean_keep_id_range_and_filter_selection(
752
- monkeypatch,
753
- tmp_path,
754
- kind,
755
- mode,
756
- selector,
757
- expected_numbers,
758
- ):
759
- from prizmkit_runtime import reset as reset_runtime
760
- from prizmkit_runtime.reset import run_reset_command
761
-
762
- paths = _make_paths(tmp_path)
763
- prefix = FAMILY_CONTRACTS[kind]["prefix"]
764
- normalized_selector = tuple(value.replace("X-", prefix) for value in selector)
765
- family, plan_path = _family_and_plan(
766
- paths,
767
- kind,
768
- [
769
- _item(f"{prefix}001", "failed"),
770
- _item(f"{prefix}002", "auto_skipped", [f"{prefix}001"]),
771
- _item(f"{prefix}003", "pending"),
772
- ],
773
- )
774
- family.state_dir.mkdir(parents=True, exist_ok=True)
775
- (family.state_dir / "pipeline.json").write_text("{}\n", encoding="utf-8")
776
- captured = []
777
-
778
- def fake_reset_one(received_family, item, options, project_root, return_branch, lines):
779
- captured.append((received_family.kind, item.item_id, options.fresh_checkout, options.clean))
780
- return True
781
-
782
- monkeypatch.setattr(reset_runtime, "_reset_one", fake_reset_one)
783
- monkeypatch.setattr(reset_runtime, "default_branch", lambda _root: "main")
784
-
785
- result = run_reset_command(
786
- kind,
787
- (*normalized_selector, mode, str(plan_path)),
788
- paths,
789
- )
790
-
791
- assert result.exit_code == 0, result.render()
792
- expected_ids = [f"{prefix}{number:03d}" for number in expected_numbers]
793
- assert [entry[1] for entry in captured] == expected_ids
794
- assert all(entry[2] is (mode == "--fresh-checkout") for entry in captured)
795
- assert all(entry[3] is (mode == "--clean") for entry in captured)
796
-
797
-
798
- @pytest.mark.parametrize("kind", ("feature", "bugfix"))
799
- def test_clean_uses_item_state_without_pipeline_state_but_fresh_checkout_still_requires_it(
800
- monkeypatch,
801
- tmp_path,
802
- kind,
803
- ):
804
- from prizmkit_runtime import reset as reset_runtime
805
- from prizmkit_runtime.reset import run_reset_command
806
- from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
807
-
808
- paths = _make_paths(tmp_path / kind)
809
- contract = FAMILY_CONTRACTS[kind]
810
- item_id = f"{contract['prefix']}001"
811
- family, plan_path = _family_and_plan(paths, kind, [_item(item_id, "in_progress")])
812
- status_path, _ = _write_runtime_status(
813
- family,
814
- item_id,
815
- active_dev_branch=f"{contract['branch_prefix']}/{item_id}-clean",
816
- base_branch="main",
817
- )
818
- checkout_path = persist_task_checkout(
819
- family.state_dir,
820
- TaskCheckout.active(
821
- family.task_type,
822
- item_id,
823
- f"{contract['branch_prefix']}/{item_id}-clean",
824
- "main",
825
- ),
826
- )
827
- captured = []
828
-
829
- def fake_reset_one(received_family, item, options, project_root, return_branch, lines):
830
- captured.append((received_family.kind, item.item_id, options.clean))
831
- return True
832
-
833
- monkeypatch.setattr(reset_runtime, "_reset_one", fake_reset_one)
834
- monkeypatch.setattr(reset_runtime, "default_branch", lambda _root: "main")
835
-
836
- fresh_result = run_reset_command(
837
- kind,
838
- (item_id, "--fresh-checkout", str(plan_path)),
839
- paths,
840
- )
841
-
842
- assert fresh_result.exit_code != 0
843
- assert "No pipeline state found" in fresh_result.render()
844
- assert captured == []
845
- assert status_path.is_file()
846
- assert checkout_path.is_file()
847
- assert not (family.state_dir / "pipeline.json").exists()
848
-
849
- clean_result = run_reset_command(
850
- kind,
851
- (item_id, "--clean", str(plan_path)),
852
- paths,
853
- )
854
-
855
- assert clean_result.exit_code == 0, clean_result.render()
856
- assert captured == [(kind, item_id, True)]
857
-
858
-
859
- def test_feature_clean_removes_stale_workflow_fields_and_preserves_diagnostics(tmp_path):
860
- paths = _make_paths(tmp_path)
861
- family, plan_path = _family_and_plan(
862
- paths,
863
- "feature",
864
- [_item("F-001", "failed")],
865
- )
866
- status_path, _ = _write_runtime_status(
867
- family,
868
- "F-001",
869
- repair_scope="production",
870
- repair_round=2,
871
- blocked_reason="test_blocked",
872
- terminal_status="WORKFLOW_BLOCKED",
873
- )
874
- session_dir = family.state_dir / "F-001" / "sessions" / "old-session"
875
- session_dir.mkdir(parents=True)
876
- (session_dir / "session.log").write_text("old session\n", encoding="utf-8")
877
- feature_slug = "001-f-001"
878
- specs_dir = paths.project_root / ".prizmkit" / "specs" / feature_slug
879
- specs_dir.mkdir(parents=True)
880
- (specs_dir / "spec.md").write_text("old spec\n", encoding="utf-8")
881
- (specs_dir / "continuation-summary.md").write_text(
882
- "old continuation\n",
883
- encoding="utf-8",
884
- )
885
-
886
- result = subprocess.run(
887
- [
888
- sys.executable,
889
- str(PIPELINE_ROOT / "scripts" / "update-feature-status.py"),
890
- "--feature-list",
891
- str(plan_path),
892
- "--state-dir",
893
- str(family.state_dir),
894
- "--feature-id",
895
- "F-001",
896
- "--feature-slug",
897
- feature_slug,
898
- "--project-root",
899
- str(paths.project_root),
900
- "--action",
901
- "clean",
902
- ],
903
- cwd=paths.project_root,
904
- text=True,
905
- stdout=subprocess.PIPE,
906
- stderr=subprocess.PIPE,
907
- check=False,
908
- )
909
-
910
- assert result.returncode == 0, (result.stdout, result.stderr)
911
- payload = json.loads(result.stdout)
912
- assert payload["action"] == "clean"
913
- assert payload["new_status"] == "pending"
914
- updated_list = json.loads(plan_path.read_text(encoding="utf-8"))
915
- assert updated_list["features"][0]["status"] == "pending"
916
- updated_status = json.loads(status_path.read_text(encoding="utf-8"))
917
- for stale_field in (
918
- "repair_scope",
919
- "repair_round",
920
- "blocked_reason",
921
- "terminal_status",
922
- ):
923
- assert stale_field not in updated_status
924
- assert updated_status["retry_count"] == 0
925
- assert updated_status["infra_error_count"] == 0
926
- assert updated_status["sessions"] == []
927
- assert updated_status["last_session_id"] is None
928
- assert updated_status["resume_from_phase"] is None
929
- assert updated_status["custom_diagnostic"] == {"keep": True}
930
- assert "continuation_pending" not in updated_status
931
- assert not session_dir.exists()
932
- assert not specs_dir.exists()
933
-
934
-
935
- def _valid_bug(bug_id, status="pending", dependencies=None):
936
- return {
937
- "id": bug_id,
938
- "title": bug_id,
939
- "description": "Bug description",
940
- "severity": "high",
941
- "error_source": {"type": "failed_test", "content": "failure"},
942
- "verification_type": "automated",
943
- "acceptance_criteria": ["Regression is fixed"],
944
- "status": status,
945
- "dependencies": list(dependencies or []),
946
- }
947
-
948
-
949
- def _run_bug_updater(plan_path, state_dir, *args):
950
- return subprocess.run(
951
- [
952
- sys.executable,
953
- str(PIPELINE_ROOT / "scripts" / "update-bug-status.py"),
954
- "--bug-list",
955
- str(plan_path),
956
- "--state-dir",
957
- str(state_dir),
958
- "--project-root",
959
- str(plan_path.parent),
960
- *args,
961
- ],
962
- cwd=REPO_ROOT,
963
- text=True,
964
- stdout=subprocess.PIPE,
965
- stderr=subprocess.PIPE,
966
- check=False,
967
- )
968
-
969
-
970
- @pytest.mark.parametrize(
971
- ("session_status", "extra_args", "expected_root_status"),
972
- (
973
- ("failed", ("--max-retries", "1"), "failed"),
974
- ("workflow_skipped", (), "skipped"),
975
- ("workflow_blocked", (), "needs_info"),
976
- ),
977
- )
978
- def test_bugfix_terminal_roots_auto_skip_pending_descendants(
979
- tmp_path,
980
- session_status,
981
- extra_args,
982
- expected_root_status,
983
- ):
984
- plan_path = tmp_path / "bug-fix-list.json"
985
- state_dir = tmp_path / "state"
986
- completed_status = state_dir / "B-004" / "status.json"
987
- completed_status.parent.mkdir(parents=True)
988
- completed_status.write_text('{"custom":"unchanged"}\n', encoding="utf-8")
989
- completed_before = completed_status.read_bytes()
990
- plan_path.write_text(
991
- json.dumps(
992
- {
993
- "$schema": "dev-pipeline-bug-fix-list-v1",
994
- "project_name": "Bug Cascade",
995
- "bugs": [
996
- _valid_bug("B-001", "in_progress"),
997
- _valid_bug("B-002", "pending", ["B-001"]),
998
- _valid_bug("B-003", "pending", ["B-002"]),
999
- _valid_bug("B-004", "completed"),
1000
- ],
1001
- }
1002
- ),
1003
- encoding="utf-8",
1004
- )
1005
-
1006
- result = _run_bug_updater(
1007
- plan_path,
1008
- state_dir,
1009
- "--action",
1010
- "update",
1011
- "--bug-id",
1012
- "B-001",
1013
- "--session-status",
1014
- session_status,
1015
- *extra_args,
1016
- )
1017
-
1018
- assert result.returncode == 0, (result.stdout, result.stderr)
1019
- summary = json.loads(result.stdout)
1020
- assert summary["auto_skipped"] == ["B-002", "B-003"]
1021
- statuses = {
1022
- bug["id"]: bug["status"]
1023
- for bug in json.loads(plan_path.read_text(encoding="utf-8"))["bugs"]
1024
- }
1025
- assert statuses == {
1026
- "B-001": expected_root_status,
1027
- "B-002": "auto_skipped",
1028
- "B-003": "auto_skipped",
1029
- "B-004": "completed",
1030
- }
1031
- assert completed_status.read_bytes() == completed_before
1032
-
1033
-
1034
- def test_existing_bugfix_list_lazily_normalizes_blocked_pending_descendants(tmp_path):
1035
- plan_path = tmp_path / "bug-fix-list.json"
1036
- state_dir = tmp_path / "state"
1037
- data = {
1038
- "$schema": "dev-pipeline-bug-fix-list-v1",
1039
- "project_name": "Legacy Bug List",
1040
- "bugs": [
1041
- _valid_bug("B-001", "failed"),
1042
- _valid_bug("B-002", "pending", ["B-001"]),
1043
- _valid_bug("B-003", "pending", ["B-002"]),
1044
- _valid_bug("B-004", "completed"),
1045
- ],
1046
- }
1047
- plan_path.write_text(json.dumps(data), encoding="utf-8")
1048
-
1049
- result = _run_bug_updater(plan_path, state_dir, "--action", "get_next")
1050
-
1051
- assert result.returncode == 0, (result.stdout, result.stderr)
1052
- assert result.stdout.strip() == "PIPELINE_COMPLETE"
1053
- updated = json.loads(plan_path.read_text(encoding="utf-8"))
1054
- statuses = {bug["id"]: bug["status"] for bug in updated["bugs"]}
1055
- assert statuses == {
1056
- "B-001": "failed",
1057
- "B-002": "auto_skipped",
1058
- "B-003": "auto_skipped",
1059
- "B-004": "completed",
1060
- }
1061
-
1062
- status_result = _run_bug_updater(plan_path, state_dir, "--action", "status")
1063
- assert status_result.returncode == 0
1064
- assert "Auto-skipped: 2" in status_result.stdout
1065
- assert "[⊘]" in status_result.stdout
1066
-
1067
-
1068
- def test_bugfix_auto_skip_write_failure_is_nonzero_without_partial_state(monkeypatch, tmp_path, capsys):
1069
- plan_path = tmp_path / "bug-fix-list.json"
1070
- state_dir = tmp_path / "state"
1071
- data = {
1072
- "$schema": "dev-pipeline-bug-fix-list-v1",
1073
- "project_name": "Write Failure",
1074
- "bugs": [
1075
- _valid_bug("B-001", "failed"),
1076
- _valid_bug("B-002", "pending", ["B-001"]),
1077
- ],
1078
- }
1079
- plan_path.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
1080
- before = plan_path.read_bytes()
1081
- module = _load_source_module(
1082
- "f060_update_bug_status_write_failure",
1083
- PIPELINE_ROOT / "scripts" / "update-bug-status.py",
1084
- )
1085
- monkeypatch.setattr(module, "write_json_file", lambda *_args, **_kwargs: "permission denied")
1086
-
1087
- with pytest.raises(SystemExit):
1088
- module.auto_skip_blocked_bugs(str(plan_path), str(state_dir), "B-001")
1089
-
1090
- output = capsys.readouterr().out
1091
- assert "Failed to write auto-skipped bugs" in output
1092
- assert plan_path.read_bytes() == before
1093
- assert _tree_snapshot(state_dir) == {}
1094
-
1095
-
1096
- def _load_source_module(name, path):
1097
- import importlib.util
1098
-
1099
- spec = importlib.util.spec_from_file_location(name, path)
1100
- module = importlib.util.module_from_spec(spec)
1101
- assert spec.loader is not None
1102
- spec.loader.exec_module(module)
1103
- return module
1104
-
1105
-
1106
- def test_bugfix_auto_skipped_schema_validators_and_aggregation_are_consistent():
1107
- from prizmkit_runtime.daemon import PROGRESS_COUNTS_BY_KIND
1108
- from prizmkit_runtime.runner_models import family_for
1109
- from prizmkit_runtime.runners import _completion_compatible_statuses
1110
- from prizmkit_runtime.paths import resolve_runtime_paths
1111
-
1112
- schema = json.loads(
1113
- (PIPELINE_ROOT / "templates" / "bug-fix-list-schema.json").read_text(encoding="utf-8")
1114
- )
1115
- status_enum = schema["properties"]["bugs"]["items"]["properties"]["status"]["enum"]
1116
- assert "auto_skipped" in status_enum
1117
-
1118
- init_module = _load_source_module(
1119
- "f060_init_bugfix",
1120
- PIPELINE_ROOT / "scripts" / "init-bugfix-pipeline.py",
1121
- )
1122
- planner_module = _load_source_module(
1123
- "f060_validate_bug_list",
1124
- REPO_ROOT
1125
- / "core"
1126
- / "skills"
1127
- / "orchestration-skill"
1128
- / "pipelines"
1129
- / "bug-planner"
1130
- / "scripts"
1131
- / "validate-bug-list.py",
1132
- )
1133
- assert "auto_skipped" in init_module.VALID_STATUSES
1134
- assert "auto_skipped" in init_module.TERMINAL_STATUSES
1135
- assert "auto_skipped" in planner_module.VALID_STATUSES
1136
-
1137
- bugs = [
1138
- _valid_bug("B-001", "failed"),
1139
- _valid_bug("B-002", "pending", ["B-001"]),
1140
- _valid_bug("B-003", "auto_skipped", ["B-001"]),
1141
- ]
1142
- init_errors, _seen = init_module.validate_bugs(bugs)
1143
- assert init_errors == []
1144
- planner_result = planner_module.validate(
1145
- {
1146
- "$schema": "dev-pipeline-bug-fix-list-v1",
1147
- "project_name": "Validator Test",
1148
- "bugs": bugs,
1149
- }
1150
- )
1151
- assert planner_result["valid"] is True, planner_result["errors"]
1152
-
1153
- assert "auto_skipped" in PROGRESS_COUNTS_BY_KIND["bugfix"]
1154
- paths = resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=REPO_ROOT)
1155
- bug_family = family_for("bugfix", paths)
1156
- assert "auto_skipped" not in _completion_compatible_statuses(bug_family)
1157
-
1158
-
1159
- def test_all_updaters_expose_only_reset_state_internal_recovery_action():
1160
- retired_action = "un" + "skip"
1161
- for contract in FAMILY_CONTRACTS.values():
1162
- source = (PIPELINE_ROOT / "scripts" / contract["script"]).read_text(encoding="utf-8")
1163
- assert retired_action not in source
1164
- assert '"reset_state"' in source
1165
- assert '"action": "reset_state"' in source
1166
-
1167
-
1168
- def test_canonical_reset_guidance_documents_every_explicit_mode_without_generated_outputs():
1169
- launcher_root = (
1170
- REPO_ROOT
1171
- / "core"
1172
- / "skills"
1173
- / "orchestration-skill"
1174
- / "pipelines"
1175
- )
1176
- launchers = {
1177
- "feature-pipeline-launcher": ("feature", "F-001"),
1178
- "bugfix-pipeline-launcher": ("bugfix", "B-001"),
1179
- }
1180
- for launcher, (family, item_id) in launchers.items():
1181
- source = (launcher_root / launcher / "SKILL.md").read_text(encoding="utf-8")
1182
- assert f"reset {family} {item_id} --state-only" in source
1183
- assert f"reset {family} {item_id} --fresh-checkout" in source
1184
- assert f"reset {family} {item_id} --clean" in source
1185
- assert f"reset {family} --failed --preserve-runtime" in source
1186
- assert "exactly one mode" in source.lower()
1187
-
1188
- memory_source = (REPO_ROOT / "core" / "templates" / "project-memory-template.md").read_text(
1189
- encoding="utf-8"
1190
- )
1191
- assert "reset <family> <task-id> --state-only" in memory_source
1192
- assert "reset <family> --state-only --all" in memory_source
1193
- assert "reset <family> <task-id-or-range> --fresh-checkout" in memory_source
1194
- assert "reset <family> <task-id-or-range> --clean" in memory_source
1195
- assert "reset <family> --failed --preserve-runtime" in memory_source
1196
- assert "<family> " + "un" + "skip" not in memory_source