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,1806 +0,0 @@
1
- """Tests for auto-skip and reset_state functionality in update-feature-status.py."""
2
-
3
- import json
4
- import os
5
- import shutil
6
- import subprocess
7
- import sys
8
- import time
9
- from pathlib import Path
10
-
11
- import pytest
12
-
13
- from update_feature_status import (
14
- auto_skip_blocked_features,
15
- TERMINAL_STATUSES,
16
- load_feature_status,
17
- )
18
-
19
- from utils import load_json_file, write_json_file
20
-
21
-
22
- ROOT = Path(__file__).resolve().parents[2]
23
- UNIX_RUNTIME_SNAPSHOT = ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json"
24
-
25
-
26
- def _python_310_plus() -> str:
27
- if sys.version_info >= (3, 10):
28
- return sys.executable
29
- for executable in ("python3.12", "python3.11", "python3.10"):
30
- resolved = shutil.which(executable)
31
- if resolved:
32
- return resolved
33
- return sys.executable
34
-
35
-
36
- PYTHON_310_PLUS = _python_310_plus()
37
-
38
-
39
- def _load_unix_snapshot_section(section):
40
- with open(UNIX_RUNTIME_SNAPSHOT, encoding="utf-8") as fh:
41
- fixture = json.load(fh)
42
- required = fixture.get("requiredScenarios", {}).get(section)
43
- assert required, f"{section} required scenario list must not be empty"
44
- section_data = fixture.get(section)
45
- assert section_data, f"{section} fixture section must not be empty"
46
- for scenario_id in required:
47
- assert scenario_id in section_data, f"missing {section}.{scenario_id} from fixture"
48
- assert section_data[scenario_id] not in ({}, [], "", None), f"empty {section}.{scenario_id} fixture"
49
- return section_data
50
-
51
-
52
- def _assert_matches_unix_snapshot_section(section, actual):
53
- expected = _load_unix_snapshot_section(section)
54
- for scenario_id in expected:
55
- assert scenario_id in actual, f"missing actual {section}.{scenario_id}"
56
- assert actual == expected
57
-
58
-
59
- # ---------------------------------------------------------------------------
60
- # Helpers
61
- # ---------------------------------------------------------------------------
62
-
63
- def _make_feature(fid, title="Feature", deps=None, status="pending"):
64
- return {
65
- "id": fid,
66
- "title": title,
67
- "description": "desc",
68
- "priority": "medium",
69
- "dependencies": deps or [],
70
- "acceptance_criteria": ["ok"],
71
- "status": status,
72
- }
73
-
74
-
75
- def _make_feature_list(features):
76
- return {
77
- "$schema": "dev-pipeline-feature-list-v1",
78
- "project_name": "test-app",
79
- "features": features,
80
- }
81
-
82
-
83
- def _init_state(tmp_path, feature_ids):
84
- """Create state dir with status.json for each feature."""
85
- state_dir = str(tmp_path / "state" / "features")
86
- for fid in feature_ids:
87
- feature_dir = os.path.join(state_dir, fid, "sessions")
88
- os.makedirs(feature_dir, exist_ok=True)
89
- status_path = os.path.join(state_dir, fid, "status.json")
90
- write_json_file(status_path, {
91
- "feature_id": fid,
92
- "status": "pending",
93
- "retry_count": 0,
94
- "max_retries": 3,
95
- "sessions": [],
96
- "last_session_id": None,
97
- "resume_from_phase": None,
98
- "created_at": "2026-01-01T00:00:00Z",
99
- "updated_at": "2026-01-01T00:00:00Z",
100
- })
101
- return state_dir
102
-
103
-
104
- def _write_fl(tmp_path, features):
105
- """Write feature-list.json and return its path."""
106
- fl_path = str(tmp_path / "feature-list.json")
107
- write_json_file(fl_path, _make_feature_list(features))
108
- return fl_path
109
-
110
-
111
- def _read_statuses(fl_path):
112
- """Return {feature_id: status} from feature-list.json."""
113
- data, _ = load_json_file(fl_path)
114
- return {f["id"]: f["status"] for f in data["features"]}
115
-
116
-
117
-
118
-
119
- # ---------------------------------------------------------------------------
120
- # context_overflow retry semantics
121
- # ---------------------------------------------------------------------------
122
-
123
- class TestContextOverflowRetrySemantics:
124
- def _script_cases(self, scripts_dir):
125
- return [
126
- {
127
- "script": scripts_dir / "update-feature-status.py",
128
- "list_option": "--feature-list",
129
- "id_option": "--feature-id",
130
- "id": "F-001",
131
- "list_name": "feature-list.json",
132
- "collection": "features",
133
- "list_payload": {
134
- "features": [_make_feature("F-001", "Context Overflow", status="in_progress")],
135
- },
136
- },
137
- {
138
- "script": scripts_dir / "update-bug-status.py",
139
- "list_option": "--bug-list",
140
- "id_option": "--bug-id",
141
- "id": "B-001",
142
- "list_name": "bug-fix-list.json",
143
- "collection": "bugs",
144
- "list_payload": {
145
- "bugs": [{
146
- "id": "B-001",
147
- "title": "Context Overflow Bug",
148
- "description": "desc",
149
- "severity": "medium",
150
- "priority": "medium",
151
- "status": "in_progress",
152
- }],
153
- },
154
- },
155
- ]
156
-
157
- def _run_case_update(self, case, list_path, state_dir, session_status, session_id="sess-1", extra_args=None):
158
- cmd = [
159
- "python3",
160
- str(case["script"]),
161
- case["list_option"],
162
- str(list_path),
163
- "--state-dir",
164
- str(state_dir),
165
- case["id_option"],
166
- case["id"],
167
- "--session-id",
168
- session_id,
169
- "--session-status",
170
- session_status,
171
- "--max-retries",
172
- "3",
173
- "--max-infra-retries",
174
- "3",
175
- "--action",
176
- "update",
177
- ]
178
- if extra_args:
179
- cmd.extend(extra_args)
180
- result = subprocess.run(cmd, text=True, capture_output=True, check=True)
181
- return json.loads(result.stdout)
182
-
183
- def _runtime_status(self, state_dir, item_id):
184
- with open(Path(state_dir) / item_id / "status.json", encoding="utf-8") as fh:
185
- return json.load(fh)
186
-
187
- def _assert_no_continuation_runtime_state(self, status):
188
- for key in [
189
- "active_dev_branch",
190
- "base_branch",
191
- "continuation_pending",
192
- "continuation_reason",
193
- "last_context_overflow_session_id",
194
- "previous_session_id",
195
- "last_fatal_error_code",
196
- "continuation_summary_path",
197
- "no_progress_count",
198
- "last_progress_fingerprint",
199
- "needs_attention",
200
- "stalled_context_continuation",
201
- "stalled_reason",
202
- "context_overflow_count",
203
- "continuation_count",
204
- ]:
205
- assert key not in status
206
-
207
- def test_start_and_update_persist_effective_retry_budgets_without_charging_workflow_skip(self, tmp_path):
208
- scripts_dir = Path(__file__).resolve().parents[1] / "scripts"
209
-
210
- for case in self._script_cases(scripts_dir):
211
- case_dir = tmp_path / f"budgets-{case['id']}"
212
- state_dir = case_dir / "state"
213
- list_path = case_dir / case["list_name"]
214
- payload = json.loads(json.dumps(case["list_payload"]))
215
- payload[case["collection"]][0]["status"] = "pending"
216
- write_json_file(str(list_path), payload)
217
-
218
- start = subprocess.run(
219
- [
220
- "python3",
221
- str(case["script"]),
222
- case["list_option"],
223
- str(list_path),
224
- "--state-dir",
225
- str(state_dir),
226
- case["id_option"],
227
- case["id"],
228
- "--action",
229
- "start",
230
- "--max-retries",
231
- "7",
232
- "--max-infra-retries",
233
- "4",
234
- ],
235
- text=True,
236
- capture_output=True,
237
- check=True,
238
- )
239
- assert json.loads(start.stdout)["new_status"] == "in_progress"
240
- started = self._runtime_status(state_dir, case["id"])
241
- assert started["max_retries"] == 7
242
- assert started["max_infra_retries"] == 4
243
-
244
- skipped = subprocess.run(
245
- [
246
- "python3",
247
- str(case["script"]),
248
- case["list_option"],
249
- str(list_path),
250
- "--state-dir",
251
- str(state_dir),
252
- case["id_option"],
253
- case["id"],
254
- "--session-id",
255
- "sess-skip",
256
- "--session-status",
257
- "workflow_skipped",
258
- "--action",
259
- "update",
260
- "--max-retries",
261
- "5",
262
- "--max-infra-retries",
263
- "2",
264
- ],
265
- text=True,
266
- capture_output=True,
267
- check=True,
268
- )
269
- summary = json.loads(skipped.stdout)
270
- runtime = self._runtime_status(state_dir, case["id"])
271
- assert summary["new_status"] == "skipped"
272
- assert runtime["max_retries"] == 5
273
- assert runtime["max_infra_retries"] == 2
274
- assert runtime["retry_count"] == 0
275
- assert runtime["infra_error_count"] == 0
276
-
277
- def test_context_overflow_consumes_retry_and_records_bounded_continuation_metadata(self, tmp_path):
278
- scripts_dir = Path(__file__).resolve().parents[1] / "scripts"
279
-
280
- for case in self._script_cases(scripts_dir):
281
- case_dir = tmp_path / case["id"]
282
- state_dir = case_dir / "state"
283
- list_path = case_dir / case["list_name"]
284
- session_dir = state_dir / case["id"] / "sessions" / "sess-1"
285
- session_dir.mkdir(parents=True)
286
- (session_dir / "session.log").write_text("context overflow diagnostics", encoding="utf-8")
287
- write_json_file(str(list_path), case["list_payload"])
288
- status_path = state_dir / case["id"] / "status.json"
289
- write_json_file(str(status_path), {
290
- "retry_count": 1,
291
- "infra_error_count": 1,
292
- "sessions": [],
293
- "last_session_id": None,
294
- "resume_from_phase": None,
295
- })
296
- before_mtime = list_path.stat().st_mtime_ns
297
- time.sleep(0.01)
298
-
299
- summary = self._run_case_update(
300
- case,
301
- list_path,
302
- state_dir,
303
- "context_overflow",
304
- extra_args=[
305
- "--active-dev-branch",
306
- "dev/existing-branch",
307
- "--base-branch",
308
- "main",
309
- "--last-fatal-error-code",
310
- "context_overflow",
311
- "--continuation-summary-path",
312
- str(session_dir / "continuation-summary.md"),
313
- ],
314
- )
315
-
316
- assert summary["new_status"] == "in_progress"
317
- assert summary["retry_count"] == 2
318
- assert summary["infra_error_count"] == 1
319
- assert summary["context_overflow_count"] == 1
320
- assert summary["continuation_count"] == 1
321
- assert summary["continuation_pending"] is True
322
- assert summary["restart_policy"] == "context_overflow_continuation"
323
- assert summary["artifacts_preserved"] is True
324
- assert "cleanup_performed" not in summary
325
- assert (session_dir / "session.log").exists()
326
- assert list_path.stat().st_mtime_ns == before_mtime
327
-
328
- list_data, _ = load_json_file(str(list_path))
329
- assert list_data[case["collection"]][0]["status"] == "in_progress"
330
-
331
- runtime = self._runtime_status(state_dir, case["id"])
332
- assert runtime["retry_count"] == 2
333
- assert runtime["infra_error_count"] == 1
334
- assert runtime["active_dev_branch"] == "dev/existing-branch"
335
- assert runtime["base_branch"] == "main"
336
- assert runtime["continuation_pending"] is True
337
- assert runtime["continuation_reason"] == "context_overflow"
338
- assert runtime["last_context_overflow_session_id"] == "sess-1"
339
- assert runtime["last_fatal_error_code"] == "context_overflow"
340
- assert runtime["context_overflow_count"] == 1
341
- assert runtime["continuation_count"] == 1
342
- assert runtime["continuation_summary_path"].endswith("continuation-summary.md")
343
- assert runtime["last_session_id"] == "sess-1"
344
- assert runtime.get("last_infra_error_session_id") is None
345
-
346
- get_next = subprocess.run(
347
- [
348
- "python3",
349
- str(case["script"]),
350
- case["list_option"],
351
- str(list_path),
352
- "--state-dir",
353
- str(state_dir),
354
- "--action",
355
- "get_next",
356
- ],
357
- text=True,
358
- capture_output=True,
359
- check=True,
360
- )
361
- selected = json.loads(get_next.stdout)
362
- assert selected["active_dev_branch"] == "dev/existing-branch"
363
- assert selected["base_branch"] == "main"
364
- assert selected["continuation_pending"] is True
365
- assert selected["continuation_reason"] == "context_overflow"
366
- assert selected["last_context_overflow_session_id"] == "sess-1"
367
- assert selected["last_fatal_error_code"] == "context_overflow"
368
- assert selected["context_overflow_count"] == 1
369
- assert selected["continuation_count"] == 1
370
- assert selected["continuation_summary_path"].endswith("continuation-summary.md")
371
-
372
- def test_context_overflow_reaching_retry_limit_stops_all_families(self, tmp_path):
373
- scripts_dir = Path(__file__).resolve().parents[1] / "scripts"
374
-
375
- for case in self._script_cases(scripts_dir):
376
- case_dir = tmp_path / f"bounded-{case['id']}"
377
- state_dir = case_dir / "state"
378
- list_path = case_dir / case["list_name"]
379
- session_dir = state_dir / case["id"] / "sessions" / "sess-limit"
380
- session_dir.mkdir(parents=True)
381
- (session_dir / "session.log").write_text("context overflow diagnostics", encoding="utf-8")
382
- write_json_file(str(list_path), case["list_payload"])
383
- status_path = state_dir / case["id"] / "status.json"
384
- write_json_file(str(status_path), {
385
- "retry_count": 2,
386
- "infra_error_count": 1,
387
- "sessions": [],
388
- "last_session_id": None,
389
- "resume_from_phase": None,
390
- })
391
-
392
- summary = self._run_case_update(
393
- case,
394
- list_path,
395
- state_dir,
396
- "context_overflow",
397
- session_id="sess-limit",
398
- extra_args=[
399
- "--active-dev-branch",
400
- "dev/existing-branch",
401
- "--base-branch",
402
- "main",
403
- "--last-fatal-error-code",
404
- "context_overflow",
405
- ],
406
- )
407
-
408
- assert summary["new_status"] == "failed"
409
- assert summary["retry_count"] == 3
410
- assert summary["infra_error_count"] == 1
411
- assert summary["context_overflow_count"] == 1
412
- assert summary["continuation_count"] == 1
413
- assert summary["continuation_pending"] is False
414
- assert summary["restart_policy"] == "needs_attention"
415
- assert summary["artifacts_preserved"] is True
416
- assert (session_dir / "session.log").exists()
417
-
418
- list_data, _ = load_json_file(str(list_path))
419
- assert list_data[case["collection"]][0]["status"] == "failed"
420
-
421
- runtime = self._runtime_status(state_dir, case["id"])
422
- assert runtime["retry_count"] == 3
423
- assert runtime["continuation_pending"] is False
424
- assert runtime["continuation_reason"] == "context_overflow"
425
- assert runtime["needs_attention"] is True
426
- assert runtime["last_failed_session_id"] == "sess-limit"
427
- assert runtime["context_overflow_count"] == 1
428
- assert runtime["continuation_count"] == 1
429
-
430
- def test_context_overflow_from_non_started_item_marks_in_progress_once(self, tmp_path):
431
- scripts_dir = Path(__file__).resolve().parents[1] / "scripts"
432
-
433
- for case in self._script_cases(scripts_dir):
434
- case_dir = tmp_path / f"pending-{case['id']}"
435
- state_dir = case_dir / "state"
436
- list_path = case_dir / case["list_name"]
437
- payload = json.loads(json.dumps(case["list_payload"]))
438
- payload[case["collection"]][0]["status"] = "pending"
439
- write_json_file(str(list_path), payload)
440
-
441
- summary = self._run_case_update(
442
- case,
443
- list_path,
444
- state_dir,
445
- "context_overflow",
446
- extra_args=["--active-dev-branch", "dev/new", "--base-branch", "main"],
447
- )
448
-
449
- list_data, _ = load_json_file(str(list_path))
450
- assert summary["new_status"] == "in_progress"
451
- assert list_data[case["collection"]][0]["status"] == "in_progress"
452
-
453
- def test_success_clears_pending_continuation_fields_but_preserves_counters(self, tmp_path):
454
- scripts_dir = Path(__file__).resolve().parents[1] / "scripts"
455
-
456
- for case in self._script_cases(scripts_dir):
457
- case_dir = tmp_path / f"success-{case['id']}"
458
- state_dir = case_dir / "state"
459
- list_path = case_dir / case["list_name"]
460
- write_json_file(str(list_path), case["list_payload"])
461
- status_path = state_dir / case["id"] / "status.json"
462
- status_path.parent.mkdir(parents=True)
463
- write_json_file(str(status_path), {
464
- "retry_count": 0,
465
- "infra_error_count": 0,
466
- "active_dev_branch": "dev/existing-branch",
467
- "base_branch": "main",
468
- "continuation_pending": True,
469
- "continuation_reason": "context_overflow",
470
- "last_context_overflow_session_id": "sess-overflow",
471
- "last_fatal_error_code": "context_overflow",
472
- "continuation_summary_path": "summary.md",
473
- "context_overflow_count": 2,
474
- "continuation_count": 2,
475
- "sessions": [],
476
- "last_session_id": None,
477
- "resume_from_phase": None,
478
- })
479
-
480
- summary = self._run_case_update(case, list_path, state_dir, "success", session_id="sess-success")
481
-
482
- assert summary["new_status"] == "completed"
483
- runtime = self._runtime_status(state_dir, case["id"])
484
- for key in [
485
- "active_dev_branch",
486
- "base_branch",
487
- "continuation_pending",
488
- "continuation_reason",
489
- "last_context_overflow_session_id",
490
- "last_fatal_error_code",
491
- "continuation_summary_path",
492
- ]:
493
- assert key not in runtime
494
- assert runtime["context_overflow_count"] == 2
495
- assert runtime["continuation_count"] == 2
496
-
497
- def test_manual_reset_clean_and_reset_state_clear_all_continuation_state(self, tmp_path):
498
- scripts_dir = Path(__file__).resolve().parents[1] / "scripts"
499
-
500
- for action in ["reset", "clean", "reset_state"]:
501
- for case in self._script_cases(scripts_dir):
502
- case_dir = tmp_path / f"{action}-{case['id']}"
503
- state_dir = case_dir / "state"
504
- list_path = case_dir / case["list_name"]
505
- payload = json.loads(json.dumps(case["list_payload"]))
506
- payload[case["collection"]][0]["status"] = "failed"
507
- write_json_file(str(list_path), payload)
508
- status_path = state_dir / case["id"] / "status.json"
509
- status_path.parent.mkdir(parents=True)
510
- write_json_file(str(status_path), {
511
- "retry_count": 3,
512
- "infra_error_count": 2,
513
- "active_dev_branch": "dev/existing-branch",
514
- "base_branch": "main",
515
- "continuation_pending": True,
516
- "continuation_reason": "context_overflow",
517
- "last_context_overflow_session_id": "sess-overflow",
518
- "previous_session_id": "sess-overflow",
519
- "last_fatal_error_code": "context_overflow",
520
- "continuation_summary_path": "continuation-summary.md",
521
- "no_progress_count": 1,
522
- "last_progress_fingerprint": {"checkpoint": "old"},
523
- "needs_attention": True,
524
- "stalled_context_continuation": True,
525
- "stalled_reason": "context_overflow_without_git_checkpoint_or_artifact_progress",
526
- "context_overflow_count": 2,
527
- "continuation_count": 2,
528
- "sessions": ["old"],
529
- "last_session_id": "old",
530
- "resume_from_phase": 4,
531
- })
532
- continuation_files = []
533
- if action == "clean":
534
- stored_summary = case_dir / "continuation-summary.md"
535
- stored_summary.write_text("stored", encoding="utf-8")
536
- continuation_files.append(stored_summary)
537
- if case["id_option"] == "--feature-id":
538
- conventional_summary = case_dir / ".prizmkit" / "specs" / "001-context-overflow" / "continuation-summary.md"
539
- elif case["id_option"] == "--bug-id":
540
- conventional_summary = case_dir / ".prizmkit" / "bugfix" / case["id"] / "continuation-summary.md"
541
- else:
542
- raise ValueError(f"Unsupported id_option: {case['id_option']}")
543
- conventional_summary.parent.mkdir(parents=True)
544
- conventional_summary.write_text("conventional", encoding="utf-8")
545
- continuation_files.append(conventional_summary)
546
-
547
- cmd = [
548
- "python3",
549
- str(case["script"]),
550
- case["list_option"],
551
- str(list_path),
552
- "--state-dir",
553
- str(state_dir),
554
- "--action",
555
- action,
556
- ]
557
- if action in ("reset", "clean"):
558
- cmd.extend([case["id_option"], case["id"]])
559
- elif action == "reset_state":
560
- cmd.extend([case["id_option"], case["id"]])
561
- if action == "clean":
562
- cmd.extend(["--project-root", str(case_dir)])
563
- if case["id_option"] == "--feature-id":
564
- cmd.extend(["--feature-slug", "001-context-overflow"])
565
-
566
- result = subprocess.run(cmd, text=True, capture_output=True, check=True)
567
- assert result.returncode == 0
568
- for continuation_file in continuation_files:
569
- assert not continuation_file.exists()
570
- runtime = self._runtime_status(state_dir, case["id"])
571
- if action == "reset_state":
572
- assert runtime["active_dev_branch"] == "dev/existing-branch"
573
- assert runtime["base_branch"] == "main"
574
- continuation_only = dict(runtime)
575
- continuation_only.pop("active_dev_branch")
576
- continuation_only.pop("base_branch")
577
- self._assert_no_continuation_runtime_state(continuation_only)
578
- else:
579
- self._assert_no_continuation_runtime_state(runtime)
580
- assert runtime["retry_count"] == 0
581
- assert runtime["infra_error_count"] == 0
582
- assert runtime["last_infra_error_session_id"] is None
583
- list_data, _ = load_json_file(str(list_path))
584
- assert list_data[case["collection"]][0]["status"] == "pending"
585
- def test_python_reset_warns_before_manual_continuation_reset(self, tmp_path):
586
- project_root = Path(__file__).resolve().parents[2]
587
- cli_path = project_root / "dev-pipeline" / "cli.py"
588
- script_cases = [
589
- {
590
- "target": "feature",
591
- "list_name": "feature-list.json",
592
- "state_root": "features",
593
- "item_id": "F-001",
594
- "list_payload": {
595
- "features": [_make_feature("F-001", "Context Overflow", status="failed")],
596
- },
597
- },
598
- {
599
- "target": "bugfix",
600
- "list_name": "bug-fix-list.json",
601
- "state_root": "bugfix",
602
- "item_id": "B-001",
603
- "list_payload": {
604
- "bugs": [{
605
- "id": "B-001",
606
- "title": "Context Overflow Bug",
607
- "description": "desc",
608
- "severity": "medium",
609
- "priority": "medium",
610
- "status": "failed",
611
- }],
612
- },
613
- },
614
- ]
615
-
616
- for case in script_cases:
617
- case_dir = tmp_path / case["item_id"]
618
- prizmkit_dir = case_dir / ".prizmkit"
619
- state_dir = prizmkit_dir / "state" / case["state_root"]
620
- item_state_dir = state_dir / case["item_id"]
621
- item_state_dir.mkdir(parents=True)
622
- write_json_file(str(prizmkit_dir / "plans" / case["list_name"]), case["list_payload"])
623
- write_json_file(str(state_dir / "pipeline.json"), {"status": "running"})
624
- write_json_file(str(item_state_dir / "status.json"), {
625
- "retry_count": 1,
626
- "infra_error_count": 0,
627
- "continuation_pending": True,
628
- "continuation_reason": "context_overflow",
629
- "active_dev_branch": "dev/manual-continuation",
630
- "sessions": [],
631
- })
632
- subprocess.run(["git", "init", "-q"], cwd=case_dir, check=True)
633
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=case_dir, check=True)
634
- subprocess.run(["git", "config", "user.name", "Test User"], cwd=case_dir, check=True)
635
- (case_dir / "README.md").write_text("test\n", encoding="utf-8")
636
- subprocess.run(["git", "add", "README.md"], cwd=case_dir, check=True)
637
- subprocess.run(["git", "commit", "-q", "-m", "init"], cwd=case_dir, check=True)
638
-
639
- result = subprocess.run(
640
- [
641
- PYTHON_310_PLUS,
642
- str(cli_path),
643
- "--project-root",
644
- str(case_dir),
645
- "reset",
646
- case["target"],
647
- case["item_id"],
648
- "--fresh-checkout",
649
- str(prizmkit_dir / "plans" / case["list_name"]),
650
- ],
651
- cwd=case_dir,
652
- text=True,
653
- capture_output=True,
654
- )
655
-
656
- output = result.stdout + result.stderr
657
- assert "Manual reset will abandon automatic continuation progress" in output
658
- assert "Pending continuation branch: dev/manual-continuation" in output
659
- assert output.index("Manual reset will abandon automatic continuation progress") < output.index("Resetting")
660
- assert result.returncode == 0, output
661
- runtime = self._runtime_status(state_dir, case["item_id"])
662
- self._assert_no_continuation_runtime_state(runtime)
663
- assert runtime["retry_count"] == 0
664
- assert runtime["infra_error_count"] == 0
665
- assert runtime["last_infra_error_session_id"] is None
666
-
667
-
668
- # ---------------------------------------------------------------------------
669
- # Unix runtime snapshot oracle: status updater behavior
670
- # ---------------------------------------------------------------------------
671
-
672
- _STATUS_SUMMARY_KEYS = [
673
- "new_status",
674
- "retry_count",
675
- "infra_error_count",
676
- "max_infra_retries",
677
- "restart_policy",
678
- "context_overflow_count",
679
- "continuation_count",
680
- "continuation_pending",
681
- "artifacts_preserved",
682
- "needs_attention",
683
- "stalled_context_continuation",
684
- "stalled_reason",
685
- "no_progress_count",
686
- ]
687
-
688
- _RUNTIME_STATUS_KEYS = [
689
- "retry_count",
690
- "infra_error_count",
691
- "last_infra_error_session_id",
692
- "last_failed_session_id",
693
- "active_dev_branch",
694
- "base_branch",
695
- "continuation_pending",
696
- "continuation_reason",
697
- "last_context_overflow_session_id",
698
- "previous_session_id",
699
- "last_fatal_error_code",
700
- "continuation_summary_path",
701
- "context_overflow_count",
702
- "continuation_count",
703
- "no_progress_count",
704
- "last_progress_fingerprint",
705
- "needs_attention",
706
- "stalled_context_continuation",
707
- "stalled_reason",
708
- "last_session_id",
709
- ]
710
-
711
-
712
- def _status_snapshot_cases(scripts_dir):
713
- return [
714
- {
715
- "task": "feature",
716
- "script": scripts_dir / "update-feature-status.py",
717
- "list_option": "--feature-list",
718
- "id_option": "--feature-id",
719
- "id": "F-001",
720
- "list_name": "feature-list.json",
721
- "collection": "features",
722
- "list_payload": {"features": [_make_feature("F-001", "Snapshot", status="in_progress")]},
723
- "feature_slug": "001-snapshot",
724
- },
725
- {
726
- "task": "bugfix",
727
- "script": scripts_dir / "update-bug-status.py",
728
- "list_option": "--bug-list",
729
- "id_option": "--bug-id",
730
- "id": "B-001",
731
- "list_name": "bug-fix-list.json",
732
- "collection": "bugs",
733
- "list_payload": {
734
- "bugs": [{
735
- "id": "B-001",
736
- "title": "Snapshot Bug",
737
- "description": "desc",
738
- "severity": "medium",
739
- "priority": "medium",
740
- "status": "in_progress",
741
- }],
742
- },
743
- },
744
- ]
745
-
746
-
747
- def _deepcopy_json(value):
748
- return json.loads(json.dumps(value))
749
-
750
-
751
- def _prepare_snapshot_case(base_dir, case, list_status="in_progress", runtime_status=None):
752
- case_dir = base_dir / case["task"]
753
- state_dir = case_dir / "state"
754
- list_path = case_dir / case["list_name"]
755
- list_path.parent.mkdir(parents=True, exist_ok=True)
756
- payload = _deepcopy_json(case["list_payload"])
757
- payload[case["collection"]][0]["status"] = list_status
758
- write_json_file(str(list_path), payload)
759
-
760
- status_path = state_dir / case["id"] / "status.json"
761
- status_path.parent.mkdir(parents=True, exist_ok=True)
762
- status_payload = {
763
- "retry_count": 0,
764
- "infra_error_count": 0,
765
- "sessions": [],
766
- "last_session_id": None,
767
- "resume_from_phase": None,
768
- }
769
- if runtime_status:
770
- status_payload.update(runtime_status)
771
- write_json_file(str(status_path), status_payload)
772
- return case_dir, list_path, state_dir
773
-
774
-
775
- def _run_status_snapshot_action(case, list_path, state_dir, action, session_status=None, session_id="sess-1", extra_args=None):
776
- cmd = [
777
- "python3",
778
- str(case["script"]),
779
- case["list_option"],
780
- str(list_path),
781
- "--state-dir",
782
- str(state_dir),
783
- "--action",
784
- action,
785
- ]
786
- if action in {"update", "reset", "clean", "reset_state"}:
787
- cmd.extend([case["id_option"], case["id"]])
788
- if action == "update":
789
- cmd.extend([
790
- "--session-id",
791
- session_id,
792
- "--session-status",
793
- session_status,
794
- "--max-retries",
795
- "3",
796
- "--max-infra-retries",
797
- "3",
798
- ])
799
- if extra_args:
800
- cmd.extend(extra_args)
801
- result = subprocess.run(cmd, text=True, capture_output=True, check=True)
802
- return json.loads(result.stdout) if result.stdout.strip() else {}
803
-
804
-
805
- def _runtime_snapshot(state_dir, case):
806
- with open(state_dir / case["id"] / "status.json", encoding="utf-8") as fh:
807
- return json.load(fh)
808
-
809
-
810
- def _list_item_status(list_path, case):
811
- data, _ = load_json_file(str(list_path))
812
- return data[case["collection"]][0]["status"]
813
-
814
-
815
- def _select_stable_fields(data, keys):
816
- selected = {key: data[key] for key in keys if key in data}
817
- if selected.get("continuation_summary_path"):
818
- selected["continuation_summary_path"] = "<CONTINUATION_SUMMARY>"
819
- return selected
820
-
821
-
822
- def _normalize_status_update(summary, runtime, list_status):
823
- return {
824
- "summary": _select_stable_fields(summary, _STATUS_SUMMARY_KEYS),
825
- "runtime": _select_stable_fields(runtime, _RUNTIME_STATUS_KEYS),
826
- "listStatus": list_status,
827
- }
828
-
829
-
830
- def _continuation_conventional_path(case_dir, case):
831
- if case["task"] == "feature":
832
- return case_dir / ".prizmkit" / "specs" / case["feature_slug"] / "continuation-summary.md"
833
- if case["task"] == "bugfix":
834
- return case_dir / ".prizmkit" / "bugfix" / case["id"] / "continuation-summary.md"
835
- raise ValueError(f"Unsupported task family: {case['task']}")
836
-
837
-
838
- def _build_status_updater_behavior_snapshot(tmp_path):
839
- scripts_dir = Path(__file__).resolve().parents[1] / "scripts"
840
- cases = _status_snapshot_cases(scripts_dir)
841
- snapshot = {
842
- "contextOverflowMetadata": {},
843
- "infraErrorRetryBudget": {},
844
- "crashFailureBudget": {},
845
- "resetCleanMetadataCleanup": {},
846
- "noProgressStall": {},
847
- }
848
-
849
- for case in cases:
850
- task = case["task"]
851
- case_dir, list_path, state_dir = _prepare_snapshot_case(
852
- tmp_path / "context-overflow",
853
- case,
854
- runtime_status={"retry_count": 1, "infra_error_count": 1},
855
- )
856
- summary_path = case_dir / "continuation-summary.md"
857
- summary = _run_status_snapshot_action(
858
- case,
859
- list_path,
860
- state_dir,
861
- "update",
862
- session_status="context_overflow",
863
- extra_args=[
864
- "--active-dev-branch",
865
- "dev/snapshot-branch",
866
- "--base-branch",
867
- "main",
868
- "--last-fatal-error-code",
869
- "context_overflow",
870
- "--continuation-summary-path",
871
- str(summary_path),
872
- ],
873
- )
874
- snapshot["contextOverflowMetadata"][task] = _normalize_status_update(
875
- summary,
876
- _runtime_snapshot(state_dir, case),
877
- _list_item_status(list_path, case),
878
- )
879
-
880
- case_dir, list_path, state_dir = _prepare_snapshot_case(
881
- tmp_path / "infra-error",
882
- case,
883
- runtime_status={"retry_count": 2, "infra_error_count": 0},
884
- )
885
- summary = _run_status_snapshot_action(
886
- case,
887
- list_path,
888
- state_dir,
889
- "update",
890
- session_status="infra_error",
891
- session_id="sess-infra",
892
- )
893
- snapshot["infraErrorRetryBudget"][task] = _normalize_status_update(
894
- summary,
895
- _runtime_snapshot(state_dir, case),
896
- _list_item_status(list_path, case),
897
- )
898
-
899
- case_dir, list_path, state_dir = _prepare_snapshot_case(tmp_path / "crash-failure", case)
900
- summary = _run_status_snapshot_action(
901
- case,
902
- list_path,
903
- state_dir,
904
- "update",
905
- session_status="failed",
906
- session_id="sess-failed",
907
- )
908
- snapshot["crashFailureBudget"][task] = _normalize_status_update(
909
- summary,
910
- _runtime_snapshot(state_dir, case),
911
- _list_item_status(list_path, case),
912
- )
913
-
914
- snapshot["resetCleanMetadataCleanup"][task] = {}
915
- for action in ["reset", "clean"]:
916
- cleanup_root = tmp_path / f"{action}-cleanup"
917
- cleanup_case_dir = cleanup_root / case["task"]
918
- case_dir, list_path, state_dir = _prepare_snapshot_case(
919
- cleanup_root,
920
- case,
921
- list_status="failed",
922
- runtime_status={
923
- "retry_count": 3,
924
- "infra_error_count": 2,
925
- "last_infra_error_session_id": "sess-infra",
926
- "active_dev_branch": "dev/snapshot-branch",
927
- "base_branch": "main",
928
- "continuation_pending": True,
929
- "continuation_reason": "context_overflow",
930
- "last_context_overflow_session_id": "sess-overflow",
931
- "previous_session_id": "sess-overflow",
932
- "last_fatal_error_code": "context_overflow",
933
- "continuation_summary_path": str(cleanup_case_dir / "continuation-summary.md"),
934
- "no_progress_count": 1,
935
- "last_progress_fingerprint": {"head_commit": "abc123"},
936
- "needs_attention": True,
937
- "stalled_context_continuation": True,
938
- "stalled_reason": "context_overflow_without_git_checkpoint_or_artifact_progress",
939
- "context_overflow_count": 2,
940
- "continuation_count": 2,
941
- "sessions": ["old"],
942
- "last_session_id": "old",
943
- "resume_from_phase": 4,
944
- },
945
- )
946
- continuation_files = []
947
- extra_args = []
948
- if action == "clean":
949
- stored_summary = case_dir / "continuation-summary.md"
950
- stored_summary.write_text("stored", encoding="utf-8")
951
- conventional_summary = _continuation_conventional_path(case_dir, case)
952
- conventional_summary.parent.mkdir(parents=True)
953
- conventional_summary.write_text("conventional", encoding="utf-8")
954
- continuation_files = [stored_summary, conventional_summary]
955
- extra_args = ["--project-root", str(case_dir)]
956
- if case["task"] == "feature":
957
- extra_args.extend(["--feature-slug", case["feature_slug"]])
958
- _run_status_snapshot_action(case, list_path, state_dir, action, extra_args=extra_args)
959
- runtime = _runtime_snapshot(state_dir, case)
960
- snapshot["resetCleanMetadataCleanup"][task][action] = {
961
- "runtime": _select_stable_fields(runtime, _RUNTIME_STATUS_KEYS),
962
- "listStatus": _list_item_status(list_path, case),
963
- "continuationFilesDeleted": all(not path.exists() for path in continuation_files),
964
- }
965
-
966
- case_dir, list_path, state_dir = _prepare_snapshot_case(tmp_path / "no-progress", case)
967
- fingerprint = json.dumps({
968
- "git_diff_fingerprint": "same",
969
- "checkpoint_cursor": "S02:pending",
970
- "artifact_fingerprint": "artifact",
971
- "head_commit": "abc123",
972
- })
973
- first_summary = _run_status_snapshot_action(
974
- case,
975
- list_path,
976
- state_dir,
977
- "update",
978
- session_status="context_overflow",
979
- session_id="sess-1",
980
- extra_args=[
981
- "--active-dev-branch",
982
- "dev/snapshot-branch",
983
- "--base-branch",
984
- "main",
985
- "--no-progress-count",
986
- "1",
987
- "--progress-fingerprint",
988
- fingerprint,
989
- ],
990
- )
991
- second_summary = _run_status_snapshot_action(
992
- case,
993
- list_path,
994
- state_dir,
995
- "update",
996
- session_status="stalled_context_continuation",
997
- session_id="sess-2",
998
- extra_args=[
999
- "--active-dev-branch",
1000
- "dev/snapshot-branch",
1001
- "--base-branch",
1002
- "main",
1003
- "--no-progress-count",
1004
- "2",
1005
- "--progress-fingerprint",
1006
- fingerprint,
1007
- ],
1008
- )
1009
- snapshot["noProgressStall"][task] = {
1010
- "first": _normalize_status_update(
1011
- first_summary,
1012
- _runtime_snapshot(state_dir, case),
1013
- _list_item_status(list_path, case),
1014
- )["summary"],
1015
- "second": _normalize_status_update(
1016
- second_summary,
1017
- _runtime_snapshot(state_dir, case),
1018
- _list_item_status(list_path, case),
1019
- ),
1020
- }
1021
-
1022
- return snapshot
1023
-
1024
-
1025
- def test_status_updater_behavior_matches_unix_runtime_snapshot(tmp_path):
1026
- actual = _build_status_updater_behavior_snapshot(tmp_path)
1027
- _assert_matches_unix_snapshot_section("statusUpdaterBehavior", actual)
1028
-
1029
-
1030
- # ---------------------------------------------------------------------------
1031
- # TERMINAL_STATUSES
1032
- # ---------------------------------------------------------------------------
1033
-
1034
- class TestTerminalStatuses:
1035
- def test_auto_skipped_is_terminal(self):
1036
- assert "auto_skipped" in TERMINAL_STATUSES
1037
-
1038
- def test_split_is_terminal(self):
1039
- assert "split" in TERMINAL_STATUSES
1040
-
1041
- def test_all_expected_statuses(self):
1042
- assert TERMINAL_STATUSES == {"completed", "failed", "skipped", "auto_skipped", "split"}
1043
-
1044
-
1045
- # ---------------------------------------------------------------------------
1046
- # auto_skip_blocked_features — linear chain
1047
- # ---------------------------------------------------------------------------
1048
-
1049
- class TestAutoSkipLinearChain:
1050
- """F-001 → F-002 → F-003 linear dependency chain."""
1051
-
1052
- def test_failing_root_skips_all_downstream(self, tmp_path):
1053
- features = [
1054
- _make_feature("F-001", "Root", status="failed"),
1055
- _make_feature("F-002", "Mid", deps=["F-001"]),
1056
- _make_feature("F-003", "Leaf", deps=["F-002"]),
1057
- ]
1058
- fl_path = _write_fl(tmp_path, features)
1059
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003"])
1060
-
1061
- result = auto_skip_blocked_features(fl_path, state_dir, "F-001")
1062
-
1063
- assert len(result) == 2
1064
- skipped_ids = {r["feature_id"] for r in result}
1065
- assert skipped_ids == {"F-002", "F-003"}
1066
-
1067
- statuses = _read_statuses(fl_path)
1068
- assert statuses["F-001"] == "failed"
1069
- assert statuses["F-002"] == "auto_skipped"
1070
- assert statuses["F-003"] == "auto_skipped"
1071
-
1072
- def test_status_json_also_updated(self, tmp_path):
1073
- features = [
1074
- _make_feature("F-001", "Root", status="failed"),
1075
- _make_feature("F-002", "Mid", deps=["F-001"]),
1076
- ]
1077
- fl_path = _write_fl(tmp_path, features)
1078
- state_dir = _init_state(tmp_path, ["F-001", "F-002"])
1079
-
1080
- auto_skip_blocked_features(fl_path, state_dir, "F-001")
1081
-
1082
- # status lives in feature-list.json, not status.json
1083
- statuses = _read_statuses(fl_path)
1084
- assert statuses["F-002"] == "auto_skipped"
1085
- # status.json should have updated_at but no status field
1086
- fs = load_feature_status(state_dir, "F-002")
1087
- assert "status" not in fs
1088
- assert "updated_at" in fs
1089
-
1090
- def test_failing_mid_skips_only_downstream(self, tmp_path):
1091
- features = [
1092
- _make_feature("F-001", "Root", status="completed"),
1093
- _make_feature("F-002", "Mid", deps=["F-001"], status="failed"),
1094
- _make_feature("F-003", "Leaf", deps=["F-002"]),
1095
- ]
1096
- fl_path = _write_fl(tmp_path, features)
1097
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003"])
1098
-
1099
- result = auto_skip_blocked_features(fl_path, state_dir, "F-002")
1100
-
1101
- assert len(result) == 1
1102
- assert result[0]["feature_id"] == "F-003"
1103
-
1104
- statuses = _read_statuses(fl_path)
1105
- assert statuses["F-001"] == "completed"
1106
- assert statuses["F-003"] == "auto_skipped"
1107
-
1108
-
1109
- # ---------------------------------------------------------------------------
1110
- # auto_skip_blocked_features — diamond dependency
1111
- # ---------------------------------------------------------------------------
1112
-
1113
- class TestAutoSkipDiamond:
1114
- """A → C, B → C diamond where only A fails."""
1115
-
1116
- def test_diamond_skips_downstream(self, tmp_path):
1117
- features = [
1118
- _make_feature("F-001", "A", status="failed"),
1119
- _make_feature("F-002", "B", status="completed"),
1120
- _make_feature("F-003", "C", deps=["F-001", "F-002"]),
1121
- ]
1122
- fl_path = _write_fl(tmp_path, features)
1123
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003"])
1124
-
1125
- result = auto_skip_blocked_features(fl_path, state_dir, "F-001")
1126
-
1127
- assert len(result) == 1
1128
- assert result[0]["feature_id"] == "F-003"
1129
-
1130
- def test_no_skip_when_all_deps_ok(self, tmp_path):
1131
- features = [
1132
- _make_feature("F-001", "A", status="completed"),
1133
- _make_feature("F-002", "B", status="completed"),
1134
- _make_feature("F-003", "C", deps=["F-001", "F-002"]),
1135
- ]
1136
- fl_path = _write_fl(tmp_path, features)
1137
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003"])
1138
-
1139
- result = auto_skip_blocked_features(fl_path, state_dir, "F-001")
1140
-
1141
- assert len(result) == 0
1142
- assert _read_statuses(fl_path)["F-003"] == "pending"
1143
-
1144
-
1145
- # ---------------------------------------------------------------------------
1146
- # auto_skip_blocked_features — edge cases
1147
- # ---------------------------------------------------------------------------
1148
-
1149
- class TestAutoSkipEdgeCases:
1150
- def test_no_dependencies_no_skip(self, tmp_path):
1151
- features = [
1152
- _make_feature("F-001", "A", status="failed"),
1153
- _make_feature("F-002", "B"), # independent
1154
- ]
1155
- fl_path = _write_fl(tmp_path, features)
1156
- state_dir = _init_state(tmp_path, ["F-001", "F-002"])
1157
-
1158
- result = auto_skip_blocked_features(fl_path, state_dir, "F-001")
1159
-
1160
- assert len(result) == 0
1161
- assert _read_statuses(fl_path)["F-002"] == "pending"
1162
-
1163
- def test_already_completed_not_skipped(self, tmp_path):
1164
- features = [
1165
- _make_feature("F-001", "A", status="failed"),
1166
- _make_feature("F-002", "B", deps=["F-001"], status="completed"),
1167
- ]
1168
- fl_path = _write_fl(tmp_path, features)
1169
- state_dir = _init_state(tmp_path, ["F-001", "F-002"])
1170
-
1171
- result = auto_skip_blocked_features(fl_path, state_dir, "F-001")
1172
-
1173
- assert len(result) == 0
1174
- assert _read_statuses(fl_path)["F-002"] == "completed"
1175
-
1176
- def test_already_auto_skipped_dep_propagates(self, tmp_path):
1177
- """If a dep is already auto_skipped (from a previous failure),
1178
- new downstream features depending on it should also be skipped."""
1179
- features = [
1180
- _make_feature("F-001", "A", status="failed"),
1181
- _make_feature("F-002", "B", deps=["F-001"], status="auto_skipped"),
1182
- _make_feature("F-003", "C", deps=["F-002"]), # pending
1183
- ]
1184
- fl_path = _write_fl(tmp_path, features)
1185
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003"])
1186
-
1187
- result = auto_skip_blocked_features(fl_path, state_dir, "F-001")
1188
-
1189
- # F-002 is already terminal (auto_skipped), so not re-processed
1190
- # F-003 should be auto_skipped because its dep F-002 is auto_skipped
1191
- skipped_ids = {r["feature_id"] for r in result}
1192
- assert "F-003" in skipped_ids
1193
- assert _read_statuses(fl_path)["F-003"] == "auto_skipped"
1194
-
1195
- def test_split_feature_not_skipped(self, tmp_path):
1196
- features = [
1197
- _make_feature("F-001", "A", status="failed"),
1198
- _make_feature("F-002", "B", deps=["F-001"], status="split"),
1199
- ]
1200
- fl_path = _write_fl(tmp_path, features)
1201
- state_dir = _init_state(tmp_path, ["F-001", "F-002"])
1202
-
1203
- result = auto_skip_blocked_features(fl_path, state_dir, "F-001")
1204
-
1205
- assert len(result) == 0
1206
- assert _read_statuses(fl_path)["F-002"] == "split"
1207
-
1208
- def test_skipped_dep_triggers_auto_skip(self, tmp_path):
1209
- """When a dependency is manually skipped, downstream should be auto_skipped."""
1210
- features = [
1211
- _make_feature("F-001", "A", status="skipped"),
1212
- _make_feature("F-002", "B", deps=["F-001"]),
1213
- _make_feature("F-003", "C", deps=["F-002"]),
1214
- ]
1215
- fl_path = _write_fl(tmp_path, features)
1216
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003"])
1217
-
1218
- result = auto_skip_blocked_features(fl_path, state_dir, "F-001")
1219
-
1220
- assert len(result) == 2
1221
- statuses = _read_statuses(fl_path)
1222
- assert statuses["F-001"] == "skipped"
1223
- assert statuses["F-002"] == "auto_skipped"
1224
- assert statuses["F-003"] == "auto_skipped"
1225
-
1226
-
1227
- # ---------------------------------------------------------------------------
1228
- # action_reset_state — via subprocess (tests the full CLI interface)
1229
- # ---------------------------------------------------------------------------
1230
-
1231
- import subprocess
1232
-
1233
- _SCRIPT = os.path.join(
1234
- os.path.dirname(__file__), "..", "scripts", "update-feature-status.py"
1235
- )
1236
-
1237
-
1238
- def _run_reset_state(fl_path, state_dir, feature_id=None):
1239
- cmd = [
1240
- "python3", _SCRIPT,
1241
- "--feature-list", fl_path,
1242
- "--state-dir", state_dir,
1243
- "--action", "reset_state",
1244
- ]
1245
- if feature_id:
1246
- cmd += ["--feature-id", feature_id]
1247
- result = subprocess.run(cmd, capture_output=True, text=True)
1248
- assert result.returncode == 0, result.stderr
1249
- return json.loads(result.stdout)
1250
-
1251
-
1252
- def _run_get_next(fl_path, state_dir):
1253
- cmd = [
1254
- "python3", _SCRIPT,
1255
- "--feature-list", fl_path,
1256
- "--state-dir", state_dir,
1257
- "--action", "get_next",
1258
- ]
1259
- result = subprocess.run(cmd, capture_output=True, text=True)
1260
- return result.stdout.strip()
1261
-
1262
-
1263
- def _run_update(fl_path, state_dir, feature_id, session_status, session_id="session-1", max_retries=3, max_infra_retries=3):
1264
- cmd = [
1265
- "python3", _SCRIPT,
1266
- "--feature-list", fl_path,
1267
- "--state-dir", state_dir,
1268
- "--feature-id", feature_id,
1269
- "--session-status", session_status,
1270
- "--session-id", session_id,
1271
- "--max-retries", str(max_retries),
1272
- "--max-infra-retries", str(max_infra_retries),
1273
- "--action", "update",
1274
- ]
1275
- result = subprocess.run(cmd, capture_output=True, text=True)
1276
- assert result.returncode == 0, result.stderr
1277
- return json.loads(result.stdout)
1278
-
1279
-
1280
- class TestInfraErrorUpdate:
1281
- def test_infra_error_below_budget_keeps_in_progress_without_consuming_retry(self, tmp_path):
1282
- features = [_make_feature("F-001", "Root", status="in_progress")]
1283
- fl_path = _write_fl(tmp_path, features)
1284
- state_dir = _init_state(tmp_path, ["F-001"])
1285
- status_path = os.path.join(state_dir, "F-001", "status.json")
1286
- fs = load_feature_status(state_dir, "F-001")
1287
- fs["retry_count"] = 2
1288
- write_json_file(status_path, fs)
1289
-
1290
- result = _run_update(
1291
- fl_path,
1292
- state_dir,
1293
- "F-001",
1294
- "infra_error",
1295
- "session-infra",
1296
- max_retries=3,
1297
- max_infra_retries=3,
1298
- )
1299
-
1300
- assert result["new_status"] == "in_progress"
1301
- assert result["retry_count"] == 2
1302
- assert result["infra_error_count"] == 1
1303
- assert result["max_infra_retries"] == 3
1304
- assert result["restart_policy"] == "in_process_ai_error_continuation"
1305
- assert _read_statuses(fl_path)["F-001"] == "in_progress"
1306
-
1307
- fs = load_feature_status(state_dir, "F-001")
1308
- assert fs["retry_count"] == 2
1309
- assert fs["infra_error_count"] == 1
1310
- assert fs["last_infra_error_session_id"] == "session-infra"
1311
- assert fs["max_infra_retries"] == 3
1312
-
1313
- def test_infra_error_at_budget_marks_failed_without_consuming_code_retry(self, tmp_path):
1314
- features = [_make_feature("F-001", "Root", status="in_progress")]
1315
- fl_path = _write_fl(tmp_path, features)
1316
- state_dir = _init_state(tmp_path, ["F-001"])
1317
- status_path = os.path.join(state_dir, "F-001", "status.json")
1318
- fs = load_feature_status(state_dir, "F-001")
1319
- fs["retry_count"] = 1
1320
- fs["infra_error_count"] = 2
1321
- write_json_file(status_path, fs)
1322
-
1323
- result = _run_update(
1324
- fl_path,
1325
- state_dir,
1326
- "F-001",
1327
- "infra_error",
1328
- "session-infra-final",
1329
- max_retries=3,
1330
- max_infra_retries=3,
1331
- )
1332
-
1333
- assert result["new_status"] == "failed"
1334
- assert result["retry_count"] == 1
1335
- assert result["infra_error_count"] == 3
1336
- assert result["restart_policy"] == "needs_attention"
1337
- assert _read_statuses(fl_path)["F-001"] == "failed"
1338
-
1339
- fs = load_feature_status(state_dir, "F-001")
1340
- assert fs["retry_count"] == 1
1341
- assert fs["infra_error_count"] == 3
1342
- assert fs["last_infra_error_session_id"] == "session-infra-final"
1343
- assert fs["last_failed_session_id"] == "session-infra-final"
1344
-
1345
- def test_reset_clears_infra_retry_counters(self, tmp_path):
1346
- features = [_make_feature("F-001", "Root", status="failed")]
1347
- fl_path = _write_fl(tmp_path, features)
1348
- state_dir = _init_state(tmp_path, ["F-001"])
1349
- status_path = os.path.join(state_dir, "F-001", "status.json")
1350
- fs = load_feature_status(state_dir, "F-001")
1351
- fs["retry_count"] = 3
1352
- fs["infra_error_count"] = 3
1353
- fs["last_infra_error_session_id"] = "session-infra-final"
1354
- write_json_file(status_path, fs)
1355
-
1356
- cmd = [
1357
- "python3", _SCRIPT,
1358
- "--feature-list", fl_path,
1359
- "--state-dir", state_dir,
1360
- "--feature-id", "F-001",
1361
- "--action", "reset",
1362
- ]
1363
- result = subprocess.run(cmd, capture_output=True, text=True)
1364
- assert result.returncode == 0, result.stderr
1365
-
1366
- fs = load_feature_status(state_dir, "F-001")
1367
- assert fs["retry_count"] == 0
1368
- assert fs["infra_error_count"] == 0
1369
- assert fs["last_infra_error_session_id"] is None
1370
- assert _read_statuses(fl_path)["F-001"] == "pending"
1371
-
1372
- def test_reset_state_clears_infra_retry_counters(self, tmp_path):
1373
- features = [_make_feature("F-001", "Root", status="failed")]
1374
- fl_path = _write_fl(tmp_path, features)
1375
- state_dir = _init_state(tmp_path, ["F-001"])
1376
- status_path = os.path.join(state_dir, "F-001", "status.json")
1377
- fs = load_feature_status(state_dir, "F-001")
1378
- fs["retry_count"] = 3
1379
- fs["infra_error_count"] = 3
1380
- fs["last_infra_error_session_id"] = "session-infra-final"
1381
- write_json_file(status_path, fs)
1382
-
1383
- _run_reset_state(fl_path, state_dir, "F-001")
1384
-
1385
- fs = load_feature_status(state_dir, "F-001")
1386
- assert fs["retry_count"] == 0
1387
- assert fs["infra_error_count"] == 0
1388
- assert fs["last_infra_error_session_id"] is None
1389
- assert _read_statuses(fl_path)["F-001"] == "pending"
1390
-
1391
- class TestResetStateByFeatureId:
1392
- """ResetState with --feature-id targets a specific failed feature + downstream."""
1393
-
1394
- def test_reset_state_failed_root_resets_all(self, tmp_path):
1395
- features = [
1396
- _make_feature("F-001", "Root", status="failed"),
1397
- _make_feature("F-002", "Mid", deps=["F-001"], status="auto_skipped"),
1398
- _make_feature("F-003", "Leaf", deps=["F-002"], status="auto_skipped"),
1399
- ]
1400
- fl_path = _write_fl(tmp_path, features)
1401
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003"])
1402
-
1403
- result = _run_reset_state(fl_path, state_dir, "F-001")
1404
-
1405
- assert result["reset_count"] == 3
1406
- statuses = _read_statuses(fl_path)
1407
- assert all(s == "pending" for s in statuses.values())
1408
-
1409
- def test_reset_state_auto_skipped_leaf_resets_upstream(self, tmp_path):
1410
- """C2 fix: reset_state F-003 must also find and reset F-001 (failed root)."""
1411
- features = [
1412
- _make_feature("F-001", "Root", status="failed"),
1413
- _make_feature("F-002", "Mid", deps=["F-001"], status="auto_skipped"),
1414
- _make_feature("F-003", "Leaf", deps=["F-002"], status="auto_skipped"),
1415
- ]
1416
- fl_path = _write_fl(tmp_path, features)
1417
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003"])
1418
-
1419
- result = _run_reset_state(fl_path, state_dir, "F-003")
1420
-
1421
- assert result["reset_count"] == 3
1422
- reset_ids = {f["feature_id"] for f in result["features"]}
1423
- assert "F-001" in reset_ids # transitive upstream reset
1424
- assert all(s == "pending" for s in _read_statuses(fl_path).values())
1425
-
1426
- def test_reset_state_preserves_completed_features(self, tmp_path):
1427
- features = [
1428
- _make_feature("F-001", "Done", status="completed"),
1429
- _make_feature("F-002", "Failed", deps=["F-001"], status="failed"),
1430
- _make_feature("F-003", "Skipped", deps=["F-002"], status="auto_skipped"),
1431
- ]
1432
- fl_path = _write_fl(tmp_path, features)
1433
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003"])
1434
-
1435
- result = _run_reset_state(fl_path, state_dir, "F-002")
1436
-
1437
- assert result["reset_count"] == 2
1438
- statuses = _read_statuses(fl_path)
1439
- assert statuses["F-001"] == "completed" # not touched
1440
- assert statuses["F-002"] == "pending"
1441
- assert statuses["F-003"] == "pending"
1442
-
1443
- def test_reset_state_skipped_feature_resets_downstream(self, tmp_path):
1444
- """ResetState a manually-skipped feature should also reset its auto_skipped downstream."""
1445
- features = [
1446
- _make_feature("F-001", "Skipped", status="skipped"),
1447
- _make_feature("F-002", "Child", deps=["F-001"], status="auto_skipped"),
1448
- ]
1449
- fl_path = _write_fl(tmp_path, features)
1450
- state_dir = _init_state(tmp_path, ["F-001", "F-002"])
1451
-
1452
- result = _run_reset_state(fl_path, state_dir, "F-001")
1453
-
1454
- assert result["reset_count"] == 2
1455
- statuses = _read_statuses(fl_path)
1456
- assert statuses["F-001"] == "pending"
1457
- assert statuses["F-002"] == "pending"
1458
-
1459
-
1460
- class TestResetStateAll:
1461
- """ResetState without --feature-id resets all failed + auto_skipped."""
1462
-
1463
- def test_resets_all_failed_and_auto_skipped(self, tmp_path):
1464
- features = [
1465
- _make_feature("F-001", "OK", status="completed"),
1466
- _make_feature("F-002", "Failed", status="failed"),
1467
- _make_feature("F-003", "Skipped", deps=["F-002"], status="auto_skipped"),
1468
- _make_feature("F-004", "Pending", status="pending"),
1469
- ]
1470
- fl_path = _write_fl(tmp_path, features)
1471
- state_dir = _init_state(tmp_path, ["F-001", "F-002", "F-003", "F-004"])
1472
-
1473
- result = _run_reset_state(fl_path, state_dir)
1474
-
1475
- assert result["reset_count"] == 2
1476
- statuses = _read_statuses(fl_path)
1477
- assert statuses["F-001"] == "completed"
1478
- assert statuses["F-002"] == "pending"
1479
- assert statuses["F-003"] == "pending"
1480
- assert statuses["F-004"] == "pending"
1481
-
1482
-
1483
- # ---------------------------------------------------------------------------
1484
- # Integration: auto-skip → get_next → reset_state → get_next
1485
- # ---------------------------------------------------------------------------
1486
-
1487
- class TestAutoSkipIntegration:
1488
- """Full lifecycle: fail → auto-skip → pipeline complete → reset_state → resume."""
1489
-
1490
- def test_full_lifecycle(self, tmp_path):
1491
- features = [
1492
- _make_feature("F-001", "Root", status="failed"),
1493
- _make_feature("F-002", "Child", deps=["F-001"]),
1494
- ]
1495
- fl_path = _write_fl(tmp_path, features)
1496
- state_dir = _init_state(tmp_path, ["F-001", "F-002"])
1497
-
1498
- # 1. Auto-skip cascades
1499
- auto_skip_blocked_features(fl_path, state_dir, "F-001")
1500
- assert _read_statuses(fl_path)["F-002"] == "auto_skipped"
1501
-
1502
- # 2. get_next should return PIPELINE_COMPLETE
1503
- assert _run_get_next(fl_path, state_dir) == "PIPELINE_COMPLETE"
1504
-
1505
- # 3. ResetState recovers everything
1506
- _run_reset_state(fl_path, state_dir, "F-001")
1507
- statuses = _read_statuses(fl_path)
1508
- assert statuses["F-001"] == "pending"
1509
- assert statuses["F-002"] == "pending"
1510
-
1511
- # 4. get_next should now return F-001
1512
- output = _run_get_next(fl_path, state_dir)
1513
- data = json.loads(output)
1514
- assert data["feature_id"] == "F-001"
1515
-
1516
- def test_retry_count_reset_after_reset_state(self, tmp_path):
1517
- features = [
1518
- _make_feature("F-001", "Root", status="failed"),
1519
- ]
1520
- fl_path = _write_fl(tmp_path, features)
1521
- state_dir = _init_state(tmp_path, ["F-001"])
1522
- # Simulate retry_count = 3
1523
- fs_path = os.path.join(state_dir, "F-001", "status.json")
1524
- with open(fs_path) as f:
1525
- fs = json.load(f)
1526
- fs["retry_count"] = 3
1527
- with open(fs_path, "w") as f:
1528
- json.dump(fs, f)
1529
-
1530
- _run_reset_state(fl_path, state_dir, "F-001")
1531
-
1532
- with open(fs_path) as f:
1533
- fs = json.load(f)
1534
- assert fs["retry_count"] == 0
1535
- # status lives in feature-list.json, not status.json
1536
- assert "status" not in fs
1537
- statuses = _read_statuses(fl_path)
1538
- assert statuses["F-001"] == "pending"
1539
-
1540
-
1541
- FAMILY_ORPHAN_CASES = (
1542
- {
1543
- "kind": "feature",
1544
- "script": "update-feature-status.py",
1545
- "list_option": "--feature-list",
1546
- "id_option": "--feature-id",
1547
- "collection": "features",
1548
- "prefix": "F-",
1549
- "blocking_status": "failed",
1550
- },
1551
- {
1552
- "kind": "bugfix",
1553
- "script": "update-bug-status.py",
1554
- "list_option": "--bug-list",
1555
- "id_option": "--bug-id",
1556
- "collection": "bugs",
1557
- "prefix": "B-",
1558
- "blocking_status": "needs_info",
1559
- },
1560
- )
1561
-
1562
-
1563
- def _family_item(case, number, status, dependencies=None):
1564
- item_id = f"{case['prefix']}{number:03d}"
1565
- item = {
1566
- "id": item_id,
1567
- "title": item_id,
1568
- "description": "orphan convergence test",
1569
- "priority": "medium",
1570
- "dependencies": list(dependencies or []),
1571
- "status": status,
1572
- }
1573
- if case["kind"] == "feature":
1574
- item["acceptance_criteria"] = ["converges"]
1575
- elif case["kind"] == "bugfix":
1576
- item["severity"] = "high"
1577
- else:
1578
- raise ValueError(f"Unsupported family: {case['kind']}")
1579
- return item
1580
-
1581
-
1582
- def _write_family_orphan_list(tmp_path, case, items):
1583
- list_path = tmp_path / f"{case['kind']}-list.json"
1584
- write_json_file(str(list_path), {
1585
- "project_name": "orphan convergence",
1586
- case["collection"]: items,
1587
- })
1588
- return list_path
1589
-
1590
-
1591
- def _run_family_orphan_action(
1592
- case,
1593
- list_path,
1594
- state_dir,
1595
- action,
1596
- item_id=None,
1597
- session_status=None,
1598
- extra_args=None,
1599
- ):
1600
- script = ROOT / "dev-pipeline" / "scripts" / case["script"]
1601
- command = [
1602
- "python3",
1603
- str(script),
1604
- case["list_option"],
1605
- str(list_path),
1606
- "--state-dir",
1607
- str(state_dir),
1608
- "--action",
1609
- action,
1610
- ]
1611
- if item_id:
1612
- command.extend([case["id_option"], item_id])
1613
- if session_status:
1614
- command.extend(["--session-status", session_status, "--session-id", "orphan-session"])
1615
- command.extend(extra_args or [])
1616
- return subprocess.run(command, capture_output=True, text=True, check=True)
1617
-
1618
-
1619
- def _family_statuses(case, list_path):
1620
- data, error = load_json_file(str(list_path))
1621
- assert error is None
1622
- return {item["id"]: item["status"] for item in data[case["collection"]]}
1623
-
1624
-
1625
- @pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
1626
- def test_start_reconciles_rootless_auto_skipped_descendants_without_deleting_sessions(tmp_path, case):
1627
- root_id = f"{case['prefix']}001"
1628
- child_id = f"{case['prefix']}002"
1629
- leaf_id = f"{case['prefix']}003"
1630
- list_path = _write_family_orphan_list(tmp_path, case, [
1631
- _family_item(case, 1, case["blocking_status"]),
1632
- _family_item(case, 2, "auto_skipped", [root_id]),
1633
- _family_item(case, 3, "auto_skipped", [child_id]),
1634
- ])
1635
- state_dir = tmp_path / "state"
1636
- session_marker = state_dir / child_id / "sessions" / "existing" / "session.log"
1637
- session_marker.parent.mkdir(parents=True)
1638
- session_marker.write_text("preserved\n", encoding="utf-8")
1639
-
1640
- result = _run_family_orphan_action(case, list_path, state_dir, "start", root_id)
1641
-
1642
- summary = json.loads(result.stdout)
1643
- assert summary["recovered_auto_skipped"] == [child_id, leaf_id]
1644
- assert _family_statuses(case, list_path) == {
1645
- root_id: "in_progress",
1646
- child_id: "pending",
1647
- leaf_id: "pending",
1648
- }
1649
- assert session_marker.read_text(encoding="utf-8") == "preserved\n"
1650
-
1651
-
1652
- @pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
1653
- def test_start_keeps_shared_descendant_skipped_while_another_root_blocks(tmp_path, case):
1654
- first_id = f"{case['prefix']}001"
1655
- second_id = f"{case['prefix']}002"
1656
- child_id = f"{case['prefix']}003"
1657
- list_path = _write_family_orphan_list(tmp_path, case, [
1658
- _family_item(case, 1, case["blocking_status"]),
1659
- _family_item(case, 2, case["blocking_status"]),
1660
- _family_item(case, 3, "auto_skipped", [first_id, second_id]),
1661
- ])
1662
-
1663
- result = _run_family_orphan_action(case, list_path, tmp_path / "state", "start", first_id)
1664
-
1665
- summary = json.loads(result.stdout)
1666
- assert "recovered_auto_skipped" not in summary
1667
- assert _family_statuses(case, list_path)[child_id] == "auto_skipped"
1668
-
1669
-
1670
- @pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
1671
- def test_success_without_start_reconciles_auto_skipped_descendants(tmp_path, case):
1672
- root_id = f"{case['prefix']}001"
1673
- child_id = f"{case['prefix']}002"
1674
- list_path = _write_family_orphan_list(tmp_path, case, [
1675
- _family_item(case, 1, case["blocking_status"]),
1676
- _family_item(case, 2, "auto_skipped", [root_id]),
1677
- ])
1678
-
1679
- result = _run_family_orphan_action(
1680
- case,
1681
- list_path,
1682
- tmp_path / "state",
1683
- "update",
1684
- root_id,
1685
- session_status="success",
1686
- )
1687
-
1688
- summary = json.loads(result.stdout)
1689
- assert summary["recovered_auto_skipped"] == [child_id]
1690
- assert _family_statuses(case, list_path) == {
1691
- root_id: "completed",
1692
- child_id: "pending",
1693
- }
1694
-
1695
-
1696
- @pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
1697
- def test_get_next_recovers_legacy_orphan_before_pipeline_completion(tmp_path, case):
1698
- root_id = f"{case['prefix']}001"
1699
- child_id = f"{case['prefix']}002"
1700
- list_path = _write_family_orphan_list(tmp_path, case, [
1701
- _family_item(case, 1, "completed"),
1702
- _family_item(case, 2, "auto_skipped", [root_id]),
1703
- ])
1704
-
1705
- result = _run_family_orphan_action(case, list_path, tmp_path / "state", "get_next")
1706
-
1707
- payload = json.loads(result.stdout)
1708
- selected_id = payload.get("feature_id") or payload.get("bug_id")
1709
- assert selected_id == child_id
1710
- assert child_id in result.stdout
1711
- assert _family_statuses(case, list_path)[child_id] == "pending"
1712
-
1713
-
1714
- @pytest.mark.parametrize("case", FAMILY_ORPHAN_CASES, ids=lambda case: case["kind"])
1715
- def test_status_labels_rootless_auto_skipped_as_orphan_without_mutation(tmp_path, case):
1716
- root_id = f"{case['prefix']}001"
1717
- child_id = f"{case['prefix']}002"
1718
- list_path = _write_family_orphan_list(tmp_path, case, [
1719
- _family_item(case, 1, "completed"),
1720
- _family_item(case, 2, "auto_skipped", [root_id]),
1721
- ])
1722
-
1723
- result = _run_family_orphan_action(case, list_path, tmp_path / "state", "status")
1724
-
1725
- assert "orphaned: no blocking dependency" in result.stdout
1726
- assert _family_statuses(case, list_path)[child_id] == "auto_skipped"
1727
-
1728
-
1729
- def test_feature_status_filter_uses_complete_graph_for_orphan_label(tmp_path):
1730
- case = FAMILY_ORPHAN_CASES[0]
1731
- root_id = "F-001"
1732
- child_id = "F-002"
1733
- list_path = _write_family_orphan_list(tmp_path, case, [
1734
- _family_item(case, 1, "completed"),
1735
- _family_item(case, 2, "auto_skipped", [root_id]),
1736
- ])
1737
-
1738
- result = _run_family_orphan_action(
1739
- case,
1740
- list_path,
1741
- tmp_path / "state",
1742
- "status",
1743
- extra_args=["--features", child_id],
1744
- )
1745
-
1746
- assert "orphaned: no blocking dependency" in result.stdout
1747
- assert root_id not in result.stdout
1748
- assert child_id in result.stdout
1749
-
1750
-
1751
- def test_context_overflow_records_no_progress_fingerprint_and_stall(tmp_path):
1752
- scripts_dir = Path(__file__).resolve().parents[1] / 'scripts'
1753
- feature_list = tmp_path / 'feature-list.json'
1754
- state_dir = tmp_path / 'state'
1755
- write_json_file(str(feature_list), _make_feature_list([
1756
- _make_feature('F-001', 'Context Continuation', status='in_progress')
1757
- ]))
1758
- fingerprint = json.dumps({
1759
- 'git_diff_fingerprint': 'same',
1760
- 'checkpoint_cursor': 'S02:pending',
1761
- 'artifact_fingerprint': 'artifact',
1762
- 'head_commit': 'abc123',
1763
- })
1764
-
1765
- first = subprocess.run([
1766
- 'python3', str(scripts_dir / 'update-feature-status.py'),
1767
- '--feature-list', str(feature_list),
1768
- '--state-dir', str(state_dir),
1769
- '--feature-id', 'F-001',
1770
- '--session-id', 's1',
1771
- '--session-status', 'context_overflow',
1772
- '--active-dev-branch', 'dev/F-001',
1773
- '--base-branch', 'main',
1774
- '--no-progress-count', '1',
1775
- '--progress-fingerprint', fingerprint,
1776
- '--action', 'update',
1777
- ], text=True, capture_output=True, check=True)
1778
- first_summary = json.loads(first.stdout)
1779
- assert first_summary['new_status'] == 'in_progress'
1780
- assert first_summary['retry_count'] == 1
1781
- assert first_summary['infra_error_count'] == 0
1782
- assert first_summary['no_progress_count'] == 1
1783
-
1784
- second = subprocess.run([
1785
- 'python3', str(scripts_dir / 'update-feature-status.py'),
1786
- '--feature-list', str(feature_list),
1787
- '--state-dir', str(state_dir),
1788
- '--feature-id', 'F-001',
1789
- '--session-id', 's2',
1790
- '--session-status', 'stalled_context_continuation',
1791
- '--active-dev-branch', 'dev/F-001',
1792
- '--base-branch', 'main',
1793
- '--no-progress-count', '2',
1794
- '--progress-fingerprint', fingerprint,
1795
- '--action', 'update',
1796
- ], text=True, capture_output=True, check=True)
1797
- second_summary = json.loads(second.stdout)
1798
- status = load_feature_status(str(state_dir), 'F-001')
1799
- assert second_summary['new_status'] == 'failed'
1800
- assert second_summary['retry_count'] == 1
1801
- assert second_summary['infra_error_count'] == 0
1802
- assert second_summary['needs_attention'] is True
1803
- assert second_summary['stalled_context_continuation'] is True
1804
- assert second_summary['stalled_reason'] == 'context_overflow_without_git_checkpoint_or_artifact_progress'
1805
- assert status['no_progress_count'] == 2
1806
- assert status['last_progress_fingerprint']['head_commit'] == 'abc123'