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,1257 +0,0 @@
1
- """Focused tests for runner classification, retry, and semantic lifecycle gates."""
2
-
3
- from __future__ import annotations
4
-
5
- import json
6
- import subprocess
7
- import sys
8
- from types import SimpleNamespace
9
-
10
- import pytest
11
-
12
- from _helpers import (
13
- CLI_PATH,
14
- PIPELINE_ROOT,
15
- PYTHON_310_PLUS,
16
- REPO_ROOT,
17
- _init_git_repo_for_invalid_checkpoint_test,
18
- _install_runner_session_fakes,
19
- _make_paths,
20
- _terminal_success_result,
21
- _write_family_plan,
22
- _write_feature_list,
23
- _write_semantic_completion_checkpoint,
24
- )
25
-
26
- sys.path.insert(0, str(PIPELINE_ROOT))
27
-
28
-
29
- def test_classification_accepts_late_infra_error_with_completed_checkpoint_and_commit(tmp_path):
30
- from prizmkit_runtime.runner_classification import classify_session
31
- from prizmkit_runtime.runner_models import PromptGenerationResult
32
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
33
- from prizmkit_runtime.status import ProgressSummary
34
-
35
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
36
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
37
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
38
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
39
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
40
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
41
- base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
42
- (tmp_path / "done.txt").write_text("done", encoding="utf-8")
43
- subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
44
- subprocess.run(["git", "commit", "-m", "done"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
45
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-done"
46
- checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
47
- log = tmp_path / "session.log"
48
- log.write_text("model quota exceeded; API error after commit", encoding="utf-8")
49
- raw = AISessionResult(
50
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
51
- exit_code=1,
52
- timed_out=False,
53
- termination_reason=None,
54
- stale_marker=None,
55
- fatal_error_code="api_error",
56
- progress_summary=ProgressSummary(terminal_result_text="quota exceeded"),
57
- session_log=log,
58
- backup_log=tmp_path / "backup.log",
59
- log_recovery=None,
60
- started_epoch=0,
61
- ended_epoch=1,
62
- )
63
- prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", checkpoint_path=checkpoint, artifact_path=artifact_dir)
64
-
65
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
66
-
67
- assert classification.session_status == "success"
68
- assert classification.reason == "semantic_checkpoint_with_late_runtime_error"
69
-
70
-
71
- def test_classification_accepts_final_success_after_internal_stream_retry(tmp_path):
72
- import importlib.util
73
-
74
- from prizmkit_runtime.runner_classification import classify_session
75
- from prizmkit_runtime.runner_models import PromptGenerationResult
76
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
77
- from prizmkit_runtime.status import ProgressSummary
78
-
79
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
80
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
81
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
82
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
83
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
84
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
85
- base_head = subprocess.run(
86
- ["git", "rev-parse", "HEAD"],
87
- cwd=tmp_path,
88
- check=True,
89
- stdout=subprocess.PIPE,
90
- text=True,
91
- ).stdout.strip()
92
- (tmp_path / "done.txt").write_text("done", encoding="utf-8")
93
- subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
94
- subprocess.run(
95
- ["git", "commit", "-m", "done"],
96
- cwd=tmp_path,
97
- check=True,
98
- stdout=subprocess.DEVNULL,
99
- )
100
- artifact_dir = tmp_path / ".prizmkit" / "bugfix" / "B-004"
101
- checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir, "bugfix-pipeline")
102
-
103
- parser_path = PIPELINE_ROOT / "scripts" / "parse-stream-progress.py"
104
- spec = importlib.util.spec_from_file_location("retry_progress_parser", parser_path)
105
- module = importlib.util.module_from_spec(spec)
106
- assert spec.loader is not None
107
- spec.loader.exec_module(module)
108
- tracker = module.ProgressTracker()
109
- events = [
110
- {"type": "session", "id": "pi-session"},
111
- {"type": "agent_start"},
112
- {"type": "message_end", "message": {"role": "assistant", "content": [], "stopReason": "error", "errorMessage": "Error Code internal_server_error: unexpected EOF"}},
113
- {"type": "agent_end", "willRetry": True, "messages": []},
114
- {"type": "auto_retry_start", "attempt": 1, "errorMessage": "Error Code internal_server_error: unexpected EOF"},
115
- {"type": "agent_start"},
116
- {"type": "auto_retry_end", "attempt": 1},
117
- {"type": "message_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "WORKFLOW_COMPLETED"}], "stopReason": "stop"}},
118
- {"type": "agent_end", "willRetry": False, "messages": [{"role": "assistant", "content": [{"type": "text", "text": "WORKFLOW_COMPLETED"}], "stopReason": "stop"}]},
119
- ]
120
- for event in events:
121
- tracker.process_event(event)
122
- data = tracker.to_dict()
123
- log = tmp_path / "session.log"
124
- log.write_text("[ERROR] transient unexpected EOF\n[SESSION_END] status=success\n", encoding="utf-8")
125
- raw = AISessionResult(
126
- command=AISessionCommand(("fake",), None, "custom", "stdin"),
127
- exit_code=0,
128
- timed_out=False,
129
- termination_reason=None,
130
- stale_marker=None,
131
- fatal_error_code=str(data.get("fatal_error_code") or ""),
132
- progress_summary=ProgressSummary(
133
- result_subtype=str(data.get("result_subtype") or ""),
134
- stop_reason=str(data.get("stop_reason") or ""),
135
- fatal_error_code=str(data.get("fatal_error_code") or ""),
136
- terminal_result_text=str(data.get("terminal_result_text") or ""),
137
- errors=tuple(str(item) for item in data.get("errors", [])),
138
- ),
139
- session_log=log,
140
- backup_log=tmp_path / "backup.log",
141
- log_recovery=None,
142
- started_epoch=0,
143
- ended_epoch=1,
144
- )
145
-
146
- classification = classify_session(
147
- raw,
148
- project_root=tmp_path,
149
- base_head=base_head,
150
- prompt=PromptGenerationResult(
151
- output_path=tmp_path / "prompt.md",
152
- checkpoint_path=checkpoint,
153
- artifact_path=artifact_dir,
154
- ),
155
- )
156
-
157
- assert data["last_result_is_error"] is False
158
- assert any("unexpected EOF" in str(error) for error in data["errors"])
159
- assert classification.session_status == "success"
160
- assert classification.reason == "terminal_success_with_semantic_checkpoint"
161
-
162
-
163
- def test_classification_rejects_late_infra_with_completion_summary_only(tmp_path):
164
- from prizmkit_runtime.runner_classification import classify_session
165
- from prizmkit_runtime.runner_models import PromptGenerationResult
166
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
167
- from prizmkit_runtime.status import ProgressSummary
168
-
169
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
170
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
171
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
172
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
173
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
174
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
175
- subprocess.run(["git", "checkout", "-b", "side"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
176
- (tmp_path / "side.txt").write_text("side", encoding="utf-8")
177
- subprocess.run(["git", "add", "side.txt"], cwd=tmp_path, check=True)
178
- subprocess.run(["git", "commit", "-m", "side"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
179
- side_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
180
- subprocess.run(["git", "checkout", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
181
- (tmp_path / "main.txt").write_text("main", encoding="utf-8")
182
- subprocess.run(["git", "add", "main.txt"], cwd=tmp_path, check=True)
183
- subprocess.run(["git", "commit", "-m", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
184
- subprocess.run(["git", "checkout", "side"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
185
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-done"
186
- artifact_dir.mkdir(parents=True)
187
- (artifact_dir / "completion-summary.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
188
- log = tmp_path / "session.log"
189
- log.write_text("quota exceeded", encoding="utf-8")
190
- raw = AISessionResult(
191
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
192
- exit_code=1,
193
- timed_out=False,
194
- termination_reason=None,
195
- stale_marker=None,
196
- fatal_error_code="api_error",
197
- progress_summary=ProgressSummary(terminal_result_text="quota exceeded"),
198
- session_log=log,
199
- backup_log=tmp_path / "backup.log",
200
- log_recovery=None,
201
- started_epoch=0,
202
- ended_epoch=1,
203
- )
204
- prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", artifact_path=artifact_dir)
205
-
206
- classification = classify_session(raw, project_root=tmp_path, base_head=side_head, prompt=prompt)
207
-
208
- assert classification.session_status == "infra_error"
209
- assert classification.reason == "ai_runtime_or_provider_error"
210
-
211
-
212
- def test_classification_keeps_pre_completion_provider_error_as_infra_error(tmp_path):
213
- from prizmkit_runtime.runner_classification import classify_session
214
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
215
- from prizmkit_runtime.status import ProgressSummary
216
-
217
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
218
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
219
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
220
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
221
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
222
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
223
- base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
224
- log = tmp_path / "session.log"
225
- log.write_text("authentication failed", encoding="utf-8")
226
- raw = AISessionResult(
227
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
228
- exit_code=1,
229
- timed_out=False,
230
- termination_reason=None,
231
- stale_marker=None,
232
- fatal_error_code="authentication_error",
233
- progress_summary=ProgressSummary(terminal_result_text="authentication failed"),
234
- session_log=log,
235
- backup_log=tmp_path / "backup.log",
236
- log_recovery=None,
237
- started_epoch=0,
238
- ended_epoch=1,
239
- )
240
-
241
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
242
-
243
- assert classification.session_status == "infra_error"
244
- assert classification.reason == "ai_runtime_or_provider_error"
245
-
246
-
247
- def test_classification_rejects_completed_checkpoint_without_runtime_git_receipt(tmp_path):
248
- from prizmkit_runtime.runner_classification import classify_session
249
- from prizmkit_runtime.runner_models import PromptGenerationResult
250
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
251
- from prizmkit_runtime.status import ProgressSummary
252
-
253
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
254
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
255
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
256
- (tmp_path / ".gitignore").write_text(".prizmkit/*\n", encoding="utf-8")
257
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
258
- subprocess.run(["git", "add", ".gitignore", "base.txt"], cwd=tmp_path, check=True)
259
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
260
- base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
261
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-done"
262
- checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
263
- (artifact_dir / "completion-summary.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
264
- log = tmp_path / "session.log"
265
- log.write_text("terminal success", encoding="utf-8")
266
- raw = AISessionResult(
267
- command=AISessionCommand(("fake",), None, "claude", "stdin"),
268
- exit_code=0,
269
- timed_out=False,
270
- termination_reason=None,
271
- stale_marker=None,
272
- fatal_error_code="",
273
- progress_summary=ProgressSummary(result_subtype="success", terminal_result_text="Completed; working tree clean"),
274
- session_log=log,
275
- backup_log=tmp_path / "backup.log",
276
- log_recovery=None,
277
- started_epoch=0,
278
- ended_epoch=1,
279
- )
280
- prompt = PromptGenerationResult(
281
- output_path=tmp_path / "prompt.md",
282
- checkpoint_path=checkpoint,
283
- artifact_path=artifact_dir,
284
- )
285
-
286
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
287
- assert classification.session_status == "commit_missing"
288
- assert classification.reason == "runtime_commit_receipt_mismatch"
289
-
290
-
291
- def test_classification_preserves_success_before_context_overflow(tmp_path):
292
- from prizmkit_runtime.runner_classification import classify_session
293
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
294
- from prizmkit_runtime.status import ProgressSummary
295
-
296
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
297
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
298
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
299
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
300
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
301
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
302
- base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
303
- (tmp_path / "done.txt").write_text("done", encoding="utf-8")
304
- subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
305
- subprocess.run(["git", "commit", "-m", "done"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
306
- log = tmp_path / "session.log"
307
- log.write_text("API Error: input exceeds the context window", encoding="utf-8")
308
-
309
- raw = AISessionResult(
310
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
311
- exit_code=1,
312
- timed_out=False,
313
- termination_reason=None,
314
- stale_marker=None,
315
- fatal_error_code="context_overflow",
316
- progress_summary=ProgressSummary(fatal_error_code="context_overflow"),
317
- session_log=log,
318
- backup_log=tmp_path / "backup.log",
319
- log_recovery=None,
320
- started_epoch=0,
321
- ended_epoch=1,
322
- )
323
-
324
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
325
- assert classification.session_status == "context_overflow"
326
- assert classification.reason == "context_overflow"
327
-
328
-
329
- def test_classification_crash_with_commit_since_base_does_not_become_success(tmp_path):
330
- from prizmkit_runtime.runner_classification import classify_session
331
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
332
- from prizmkit_runtime.status import ProgressSummary
333
-
334
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
335
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
336
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
337
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
338
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
339
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
340
- base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
341
- (tmp_path / "done.txt").write_text("done", encoding="utf-8")
342
- subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
343
- subprocess.run(["git", "commit", "-m", "done"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
344
- log = tmp_path / "session.log"
345
- log.write_text("hard failure", encoding="utf-8")
346
- raw = AISessionResult(
347
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
348
- exit_code=1,
349
- timed_out=False,
350
- termination_reason=None,
351
- stale_marker=None,
352
- fatal_error_code="",
353
- progress_summary=ProgressSummary(terminal_result_text="hard failure"),
354
- session_log=log,
355
- backup_log=tmp_path / "backup.log",
356
- log_recovery=None,
357
- started_epoch=0,
358
- ended_epoch=1,
359
- )
360
-
361
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
362
- assert classification.session_status == "crashed"
363
- assert classification.reason == "exit_code=1"
364
-
365
-
366
- def test_classification_stalls_after_repeated_no_progress_context_overflow(tmp_path):
367
- from prizmkit_runtime.runner_classification import classify_session, progress_fingerprint
368
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
369
- from prizmkit_runtime.status import ProgressSummary
370
-
371
- log = tmp_path / "session.log"
372
- log.write_text("PRIZMKIT_FATAL_ERROR=context_overflow", encoding="utf-8")
373
- raw = AISessionResult(
374
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
375
- exit_code=1,
376
- timed_out=False,
377
- termination_reason=None,
378
- stale_marker=None,
379
- fatal_error_code="context_overflow",
380
- progress_summary=ProgressSummary(fatal_error_code="context_overflow"),
381
- session_log=log,
382
- backup_log=tmp_path / "backup.log",
383
- log_recovery=None,
384
- started_epoch=0,
385
- ended_epoch=1,
386
- )
387
- previous = progress_fingerprint(tmp_path)
388
-
389
- classification = classify_session(
390
- raw,
391
- project_root=tmp_path,
392
- base_head="",
393
- previous_fingerprint=previous,
394
- previous_no_progress_count=1,
395
- )
396
-
397
- assert classification.session_status == "stalled_context_continuation"
398
- assert classification.no_progress_count == 2
399
-
400
-
401
- def test_terminal_success_without_semantic_completion_is_skipped(tmp_path):
402
- from prizmkit_runtime.runner_classification import classify_session
403
- from prizmkit_runtime.runner_models import PromptGenerationResult
404
-
405
- base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
406
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-incomplete"
407
- checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
408
- payload = json.loads(checkpoint.read_text(encoding="utf-8"))
409
- payload["steps"][2]["required_artifacts"] = [
410
- ".prizmkit/specs/001-incomplete/test-report.md",
411
- ".prizmkit/specs/001-incomplete/missing-test-result.json",
412
- ]
413
- checkpoint.write_text(json.dumps(payload), encoding="utf-8")
414
- prompt = PromptGenerationResult(
415
- output_path=tmp_path / "prompt.md",
416
- checkpoint_path=checkpoint,
417
- artifact_path=artifact_dir,
418
- )
419
-
420
- classification = classify_session(
421
- _terminal_success_result(tmp_path),
422
- project_root=tmp_path,
423
- base_head=base_head,
424
- prompt=prompt,
425
- )
426
-
427
- assert classification.session_status == "workflow_skipped"
428
- assert classification.reason == "no_semantic_completion:incomplete_semantic_evidence"
429
- assert classification.fatal_error_code == ""
430
-
431
-
432
- def test_pi_length_stop_with_nonzero_exit_uses_bounded_crash_path(tmp_path):
433
- from dataclasses import replace
434
-
435
- from prizmkit_runtime.runner_classification import classify_session
436
- from prizmkit_runtime.status import ProgressSummary
437
-
438
- base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
439
- raw = replace(
440
- _terminal_success_result(tmp_path),
441
- exit_code=143,
442
- progress_summary=ProgressSummary(result_subtype="success", stop_reason="length"),
443
- )
444
-
445
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
446
-
447
- assert classification.session_status == "crashed"
448
- assert classification.reason == "exit_code=143"
449
- assert classification.fatal_error_code == ""
450
-
451
-
452
- def test_pi_length_stop_with_zero_exit_and_no_checkpoint_uses_recoverable_continuation(tmp_path):
453
- from dataclasses import replace
454
-
455
- from prizmkit_runtime.runner_classification import classify_session
456
- from prizmkit_runtime.status import ProgressSummary
457
-
458
- base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
459
- raw = replace(
460
- _terminal_success_result(tmp_path),
461
- progress_summary=ProgressSummary(result_subtype="success", stop_reason="length"),
462
- )
463
-
464
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
465
-
466
- assert classification.session_status == "context_overflow"
467
- assert classification.reason == "context_overflow"
468
- assert classification.fatal_error_code == "context_overflow"
469
-
470
-
471
- def test_pi_length_stop_with_in_progress_checkpoint_uses_recoverable_continuation(tmp_path):
472
- from dataclasses import replace
473
-
474
- from prizmkit_runtime.runner_classification import classify_session
475
- from prizmkit_runtime.runner_models import PromptGenerationResult
476
- from prizmkit_runtime.status import ProgressSummary
477
-
478
- base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
479
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-length-in-progress"
480
- artifact_dir.mkdir(parents=True)
481
- checkpoint = artifact_dir / "workflow-checkpoint.json"
482
- checkpoint.write_text(
483
- json.dumps({
484
- "version": 1,
485
- "workflow_type": "feature-pipeline",
486
- "steps": [
487
- {
488
- "id": "S01",
489
- "skill": "context-snapshot-and-plan",
490
- "name": "Specify & Plan",
491
- "status": "completed",
492
- "required_artifacts": [],
493
- "depends_on": None,
494
- "stage_result": "PLAN_READY",
495
- },
496
- {
497
- "id": "S02",
498
- "skill": "prizmkit-implement",
499
- "name": "Implement",
500
- "status": "completed",
501
- "required_artifacts": [],
502
- "depends_on": "S01",
503
- "stage_result": "IMPLEMENTED",
504
- },
505
- {
506
- "id": "S03",
507
- "skill": "prizmkit-code-review",
508
- "name": "Code Review",
509
- "status": "in_progress",
510
- "required_artifacts": [],
511
- "depends_on": "S02",
512
- },
513
- {
514
- "id": "S04",
515
- "skill": "prizmkit-test",
516
- "name": "Test",
517
- "status": "pending",
518
- "required_artifacts": [],
519
- "depends_on": "S03",
520
- },
521
- {
522
- "id": "S05",
523
- "skill": "completion-summary",
524
- "name": "Completion Summary",
525
- "status": "pending",
526
- "required_artifacts": [],
527
- "depends_on": "S04",
528
- },
529
- {
530
- "id": "S06",
531
- "skill": "prizmkit-retrospective",
532
- "name": "Retrospective",
533
- "status": "pending",
534
- "required_artifacts": [],
535
- "depends_on": "S05",
536
- },
537
- {
538
- "id": "S07",
539
- "skill": "prizmkit-committer",
540
- "name": "Runtime Commit Handoff",
541
- "status": "pending",
542
- "required_artifacts": [],
543
- "depends_on": "S06",
544
- },
545
- ],
546
- "feature_state": {
547
- "stage": "code-review",
548
- "current_stage": "prizmkit-code-review",
549
- "status": "in_progress",
550
- "repair_scope": None,
551
- "repair_round": 0,
552
- "next_stage": "prizmkit-code-review",
553
- "blocked_reason": None,
554
- "terminal_status": None,
555
- },
556
- }),
557
- encoding="utf-8",
558
- )
559
- prompt = PromptGenerationResult(
560
- output_path=tmp_path / "prompt.md",
561
- checkpoint_path=checkpoint,
562
- artifact_path=artifact_dir,
563
- )
564
- raw = replace(
565
- _terminal_success_result(tmp_path),
566
- progress_summary=ProgressSummary(result_subtype="success", stop_reason="length"),
567
- )
568
-
569
- classification = classify_session(
570
- raw,
571
- project_root=tmp_path,
572
- base_head=base_head,
573
- prompt=prompt,
574
- )
575
-
576
- assert classification.session_status == "context_overflow"
577
- assert classification.reason == "context_overflow"
578
- assert classification.fatal_error_code == "context_overflow"
579
- assert classification.checkpoint_state["current_stage"] == "prizmkit-code-review"
580
-
581
-
582
- def test_pi_length_stop_does_not_override_completed_checkpoint(tmp_path):
583
- from dataclasses import replace
584
-
585
- from prizmkit_runtime.runner_classification import classify_session
586
- from prizmkit_runtime.runner_models import PromptGenerationResult
587
- from prizmkit_runtime.status import ProgressSummary
588
-
589
- base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
590
- (tmp_path / "done.txt").write_text("done", encoding="utf-8")
591
- subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
592
- subprocess.run(
593
- ["git", "commit", "-m", "done"],
594
- cwd=tmp_path,
595
- check=True,
596
- stdout=subprocess.DEVNULL,
597
- )
598
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-length-complete"
599
- checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
600
- prompt = PromptGenerationResult(
601
- output_path=tmp_path / "prompt.md",
602
- checkpoint_path=checkpoint,
603
- artifact_path=artifact_dir,
604
- )
605
- raw = replace(
606
- _terminal_success_result(tmp_path),
607
- progress_summary=ProgressSummary(result_subtype="success", stop_reason="length"),
608
- )
609
-
610
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
611
-
612
- assert classification.session_status == "success"
613
- assert classification.reason == "terminal_success_with_semantic_checkpoint"
614
- assert classification.fatal_error_code == ""
615
-
616
-
617
- def test_terminal_success_text_does_not_hide_provider_failure(tmp_path):
618
- from prizmkit_runtime.runner_classification import classify_session
619
- from prizmkit_runtime.runner_models import PromptGenerationResult
620
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
621
- from prizmkit_runtime.status import ProgressSummary
622
-
623
- base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
624
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-provider-error"
625
- checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
626
- payload = json.loads(checkpoint.read_text(encoding="utf-8"))
627
- payload["steps"][2]["required_artifacts"] = [
628
- ".prizmkit/specs/001-provider-error/test-report.md",
629
- ".prizmkit/specs/001-provider-error/missing-test-result.json",
630
- ]
631
- checkpoint.write_text(json.dumps(payload), encoding="utf-8")
632
- log = tmp_path / "provider-error.log"
633
- log.write_text("gateway failure after output", encoding="utf-8")
634
- raw = AISessionResult(
635
- command=AISessionCommand(("fake",), None, "claude", "stdin"),
636
- exit_code=0,
637
- timed_out=False,
638
- termination_reason=None,
639
- stale_marker=None,
640
- fatal_error_code="provider_error",
641
- progress_summary=ProgressSummary(result_subtype="success"),
642
- session_log=log,
643
- backup_log=tmp_path / "backup.log",
644
- log_recovery=None,
645
- started_epoch=0,
646
- ended_epoch=1,
647
- )
648
-
649
- classification = classify_session(
650
- raw,
651
- project_root=tmp_path,
652
- base_head=base_head,
653
- prompt=PromptGenerationResult(
654
- output_path=tmp_path / "prompt.md",
655
- checkpoint_path=checkpoint,
656
- artifact_path=artifact_dir,
657
- ),
658
- )
659
-
660
- assert classification.session_status == "infra_error"
661
- assert classification.reason == "ai_runtime_or_provider_error"
662
-
663
-
664
- @pytest.mark.parametrize(
665
- ("kind", "item_id"),
666
- [("feature", "F-001"), ("bugfix", "B-001")],
667
- )
668
- def test_family_success_completion_is_terminal_without_warning_metadata(
669
- tmp_path, kind, item_id
670
- ):
671
- from prizmkit_runtime.runner_models import family_for, parse_invocation
672
- from prizmkit_runtime.runner_status import start_item, update_item
673
-
674
- paths = _make_paths(tmp_path / kind)
675
- item = {
676
- "id": item_id,
677
- "title": "Skip invalid completion evidence",
678
- "status": "pending",
679
- "priority": "high",
680
- "dependencies": [],
681
- }
682
- if kind == "bugfix":
683
- item.update(severity="high", description="invalid evidence", reproduction_steps=["run"])
684
- _write_family_plan(paths, kind, [item])
685
- family = family_for(kind, paths)
686
- invocation = parse_invocation(family, "run", ())
687
- invocation = invocation.__class__(**{**invocation.__dict__, "list_path": family.plan_path})
688
- assert start_item(family, invocation, item_id, paths.project_root).ok is True
689
-
690
- result = update_item(
691
- family,
692
- invocation,
693
- item_id,
694
- "success",
695
- "session-1",
696
- paths.project_root,
697
- checkpoint_state={},
698
- )
699
- status = json.loads((family.state_dir / item_id / "status.json").read_text(encoding="utf-8"))
700
-
701
- assert result.ok is True
702
- assert result.data["new_status"] == "completed"
703
- assert status["retry_count"] == 0
704
- assert status["infra_error_count"] == 0
705
- assert "completion_warning" not in status
706
- assert "completion_warning_reason" not in status
707
- assert status["resume_from_phase"] is None
708
-
709
-
710
- @pytest.mark.parametrize(
711
- ("kind", "item_id"),
712
- [("feature", "F-001"), ("bugfix", "B-001")],
713
- )
714
- def test_family_status_preserves_direct_raw_workflow_skip(
715
- tmp_path, kind, item_id
716
- ):
717
- from prizmkit_runtime.runner_models import family_for, parse_invocation
718
- from prizmkit_runtime.runner_status import start_item, update_item
719
-
720
- paths = _make_paths(tmp_path / f"historical-{kind}")
721
- item = {
722
- "id": item_id,
723
- "title": "Historical workflow skip",
724
- "status": "pending",
725
- "priority": "high",
726
- "dependencies": [],
727
- }
728
- if kind == "bugfix":
729
- item.update(severity="high", description="invalid evidence", reproduction_steps=["run"])
730
- _write_family_plan(paths, kind, [item])
731
- family = family_for(kind, paths)
732
- invocation = parse_invocation(family, "run", ())
733
- invocation = invocation.__class__(**{**invocation.__dict__, "list_path": family.plan_path})
734
- assert start_item(family, invocation, item_id, paths.project_root).ok is True
735
-
736
- result = update_item(
737
- family,
738
- invocation,
739
- item_id,
740
- "workflow_skipped",
741
- "historical-session",
742
- paths.project_root,
743
- )
744
-
745
- assert result.ok is True
746
- assert result.data["new_status"] == "skipped"
747
- assert result.data["restart_policy"] == "terminal_skipped"
748
-
749
-
750
- def test_invalid_existing_checkpoint_skips_terminal_success_with_completion_summary(tmp_path):
751
- from prizmkit_runtime.runner_classification import classify_session
752
- from prizmkit_runtime.runner_models import PromptGenerationResult
753
-
754
- base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
755
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-invalid"
756
- artifact_dir.mkdir(parents=True)
757
- checkpoint = artifact_dir / "workflow-checkpoint.json"
758
- checkpoint.write_text(json.dumps({"steps": [{"id": "S01", "skill": "done", "name": "Done", "status": "not-valid"}]}), encoding="utf-8")
759
- (artifact_dir / "completion-summary.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
760
- prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", checkpoint_path=checkpoint, artifact_path=artifact_dir)
761
-
762
- classification = classify_session(_terminal_success_result(tmp_path), project_root=tmp_path, base_head=base_head, prompt=prompt)
763
-
764
- assert classification.session_status == "workflow_skipped"
765
- assert classification.reason == "invalid_workflow_checkpoint:invalid_status"
766
-
767
-
768
- def test_invalid_existing_checkpoint_blocks_runtime_failure_with_head_change(tmp_path):
769
- from prizmkit_runtime.runner_classification import classify_session
770
- from prizmkit_runtime.runner_models import PromptGenerationResult
771
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
772
- from prizmkit_runtime.status import ProgressSummary
773
-
774
- base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
775
- (tmp_path / "done.txt").write_text("done", encoding="utf-8")
776
- subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
777
- subprocess.run(["git", "commit", "-m", "done"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
778
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-invalid"
779
- artifact_dir.mkdir(parents=True)
780
- checkpoint = artifact_dir / "workflow-checkpoint.json"
781
- checkpoint.write_text(json.dumps({"steps": [{"id": "bad", "skill": "done", "name": "Done", "status": "completed"}]}), encoding="utf-8")
782
- raw = AISessionResult(
783
- command=AISessionCommand(("fake",), None, "claude", "stdin"),
784
- exit_code=1,
785
- timed_out=False,
786
- termination_reason=None,
787
- stale_marker=None,
788
- fatal_error_code="context_overflow",
789
- progress_summary=ProgressSummary(fatal_error_code="context_overflow"),
790
- session_log=tmp_path / "session.log",
791
- backup_log=tmp_path / "backup.log",
792
- log_recovery=None,
793
- started_epoch=0,
794
- ended_epoch=1,
795
- )
796
- raw.session_log.write_text("context overflow", encoding="utf-8")
797
- prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", checkpoint_path=checkpoint, artifact_path=artifact_dir)
798
-
799
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
800
-
801
- assert classification.session_status == "crashed"
802
- assert classification.reason == "invalid_workflow_checkpoint:malformed_step_id"
803
-
804
-
805
- def test_invalid_existing_checkpoint_blocks_ambiguous_clean_exit(tmp_path):
806
- from prizmkit_runtime.runner_classification import classify_session
807
- from prizmkit_runtime.runner_models import PromptGenerationResult
808
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
809
- from prizmkit_runtime.status import ProgressSummary
810
-
811
- base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
812
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-invalid"
813
- artifact_dir.mkdir(parents=True)
814
- checkpoint = artifact_dir / "workflow-checkpoint.json"
815
- checkpoint.write_text(json.dumps({"steps": []}), encoding="utf-8")
816
- (tmp_path / "dirty.txt").write_text("dirty", encoding="utf-8")
817
- log = tmp_path / "session.log"
818
- log.write_text("clean exit but dirty workspace", encoding="utf-8")
819
- raw = AISessionResult(
820
- command=AISessionCommand(("fake",), None, "claude", "stdin"),
821
- exit_code=0,
822
- timed_out=False,
823
- termination_reason=None,
824
- stale_marker=None,
825
- fatal_error_code="",
826
- progress_summary=ProgressSummary(result_subtype="", terminal_result_text=""),
827
- session_log=log,
828
- backup_log=tmp_path / "backup.log",
829
- log_recovery=None,
830
- started_epoch=0,
831
- ended_epoch=1,
832
- )
833
- prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", checkpoint_path=checkpoint, artifact_path=artifact_dir)
834
-
835
- classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
836
-
837
- assert classification.session_status == "crashed"
838
- assert classification.reason == "invalid_workflow_checkpoint:empty_steps"
839
-
840
-
841
- @pytest.mark.parametrize(
842
- ("kind", "item_id", "branch"),
843
- [
844
- ("feature", "F-001", "dev/F-001-ai-retry"),
845
- ("bugfix", "B-001", "bugfix/B-001-ai-retry"),
846
- ],
847
- )
848
- @pytest.mark.parametrize("retry_status", ["infra_error", "crashed", "timed_out"])
849
- def test_retryable_ai_errors_continue_in_process_for_all_families(monkeypatch, tmp_path, kind, item_id, branch, retry_status):
850
- from prizmkit_runtime import runners
851
- from prizmkit_runtime.runner_models import family_for, parse_invocation
852
-
853
- monkeypatch.setenv("DEV_BRANCH", branch)
854
- paths = _make_paths(tmp_path / kind / retry_status)
855
- family = family_for(kind, paths)
856
- invocation = parse_invocation(family, "run", ())
857
- plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan}[kind]
858
- invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
859
- observed = _install_runner_session_fakes(monkeypatch, runners, statuses=(retry_status, "success"))
860
- sleep_calls = []
861
- branch_plans = []
862
- monkeypatch.setattr(runners.time, "sleep", lambda seconds: sleep_calls.append(seconds))
863
- monkeypatch.setattr(
864
- runners,
865
- "run_git_plan",
866
- lambda project_root, plan: (branch_plans.append(plan.name) or SimpleNamespace(ok=True, plan=plan, results=())),
867
- )
868
-
869
- status = runners._process_item(family, invocation, item_id, paths, initial_metadata={})
870
-
871
- assert status == "completed"
872
- assert sleep_calls == [5]
873
- assert len(observed.launch_cwds) == 2
874
- assert observed.launch_cwds[0] == observed.launch_cwds[1]
875
- assert branch_plans.count("branch_create") == 1
876
- assert observed.updates[0][0] == retry_status
877
- continuation = observed.prompt_calls[1]["continuation"]
878
- assert continuation["previous_session_id"].endswith("session-1")
879
- assert continuation["failure_classification"] == retry_status
880
- assert continuation["active_dev_branch"] == branch
881
-
882
-
883
- @pytest.mark.parametrize(
884
- ("kind", "item_id", "branch"),
885
- [
886
- ("feature", "F-001", "dev/F-001-context-budget"),
887
- ("bugfix", "B-001", "bugfix/B-001-context-budget"),
888
- ],
889
- )
890
- def test_context_overflow_retry_budget_prevents_session_n_plus_one(monkeypatch, tmp_path, kind, item_id, branch):
891
- from prizmkit_runtime import runners
892
- from prizmkit_runtime.runner_models import family_for, parse_invocation
893
-
894
- monkeypatch.setenv("DEV_BRANCH", branch)
895
- paths = _make_paths(tmp_path / kind)
896
- family = family_for(kind, paths)
897
- invocation = parse_invocation(family, "run", ())
898
- plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan}[kind]
899
- invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
900
- observed = _install_runner_session_fakes(
901
- monkeypatch,
902
- runners,
903
- statuses=("context_overflow", "context_overflow", "context_overflow", "context_overflow"),
904
- max_retries=3,
905
- )
906
- sleep_calls = []
907
- monkeypatch.setattr(runners.time, "sleep", lambda seconds: sleep_calls.append(seconds))
908
- monkeypatch.setattr(
909
- runners,
910
- "run_git_plan",
911
- lambda project_root, plan: SimpleNamespace(ok=True, plan=plan, results=()),
912
- )
913
-
914
- status = runners._process_item(family, invocation, item_id, paths, initial_metadata={})
915
-
916
- assert status == "failed"
917
- assert len(observed.launch_cwds) == 3
918
- assert len(observed.updates) == 3
919
- assert sleep_calls == [5, 5]
920
-
921
-
922
- def test_unique_session_ids_do_not_collide_when_wall_clock_second_is_frozen(monkeypatch):
923
- from prizmkit_runtime import runners
924
-
925
- monkeypatch.setattr(runners.time, "strftime", lambda _fmt: "20260711030000")
926
- values = iter((101, 102))
927
- monkeypatch.setattr(runners.time, "time_ns", lambda: next(values))
928
-
929
- first = runners._session_id("F-001")
930
- second = runners._session_id("F-001")
931
-
932
- assert first != second
933
- assert first.endswith("-101")
934
- assert second.endswith("-102")
935
-
936
-
937
- @pytest.mark.parametrize("summary_text", ["{}", "{not-json", '{"completion_notes": []}', '{"completion_notes": [""]}'])
938
- def test_invalid_completion_summary_does_not_prove_late_runtime_success(tmp_path, summary_text):
939
- from prizmkit_runtime.runner_classification import classify_session
940
- from prizmkit_runtime.runner_models import PromptGenerationResult
941
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
942
- from prizmkit_runtime.status import ProgressSummary
943
-
944
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
945
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
946
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
947
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
948
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
949
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
950
- base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
951
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-invalid"
952
- artifact_dir.mkdir(parents=True)
953
- (artifact_dir / "completion-summary.json").write_text(summary_text, encoding="utf-8")
954
- log = tmp_path / "session.log"
955
- log.write_text("quota exceeded", encoding="utf-8")
956
- result = AISessionResult(
957
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
958
- exit_code=1,
959
- timed_out=False,
960
- termination_reason=None,
961
- stale_marker=None,
962
- fatal_error_code="api_error",
963
- progress_summary=ProgressSummary(terminal_result_text="quota exceeded"),
964
- session_log=log,
965
- backup_log=tmp_path / "backup.log",
966
- log_recovery=None,
967
- started_epoch=0,
968
- ended_epoch=1,
969
- )
970
-
971
- classification = classify_session(
972
- result,
973
- project_root=tmp_path,
974
- base_head=base_head,
975
- prompt=PromptGenerationResult(output_path=tmp_path / "prompt.md", artifact_path=artifact_dir),
976
- )
977
-
978
- assert classification.session_status == "infra_error"
979
-
980
-
981
- def test_non_utf8_completion_summary_does_not_abort_classification(tmp_path):
982
- from prizmkit_runtime.runner_classification import classify_session
983
- from prizmkit_runtime.runner_models import PromptGenerationResult
984
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
985
- from prizmkit_runtime.status import ProgressSummary
986
-
987
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
988
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
989
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
990
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
991
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
992
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
993
- base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
994
- artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-corrupt"
995
- artifact_dir.mkdir(parents=True)
996
- (artifact_dir / "completion-summary.json").write_bytes(b"\xff\xfe")
997
- log = tmp_path / "session.log"
998
- log.write_text("quota exceeded", encoding="utf-8")
999
- result = AISessionResult(
1000
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
1001
- exit_code=1,
1002
- timed_out=False,
1003
- termination_reason=None,
1004
- stale_marker=None,
1005
- fatal_error_code="api_error",
1006
- progress_summary=ProgressSummary(terminal_result_text="quota exceeded"),
1007
- session_log=log,
1008
- backup_log=tmp_path / "backup.log",
1009
- log_recovery=None,
1010
- started_epoch=0,
1011
- ended_epoch=1,
1012
- )
1013
-
1014
- classification = classify_session(
1015
- result,
1016
- project_root=tmp_path,
1017
- base_head=base_head,
1018
- prompt=PromptGenerationResult(output_path=tmp_path / "prompt.md", artifact_path=artifact_dir),
1019
- )
1020
-
1021
- assert classification.session_status == "infra_error"
1022
-
1023
-
1024
- @pytest.mark.parametrize(
1025
- ("timed_out", "termination_reason", "expected_status", "expected_reason"),
1026
- [
1027
- (True, "timeout", "timed_out", "timeout"),
1028
- (False, "stale_session", "crashed", "stale_session"),
1029
- ],
1030
- )
1031
- def test_timeout_and_stale_termination_override_provider_error_markers(tmp_path, timed_out, termination_reason, expected_status, expected_reason):
1032
- from prizmkit_runtime.runner_classification import classify_session
1033
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
1034
- from prizmkit_runtime.status import ProgressSummary
1035
-
1036
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
1037
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
1038
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
1039
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
1040
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
1041
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
1042
- base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
1043
- log = tmp_path / "session.log"
1044
- log.write_text("gateway API error", encoding="utf-8")
1045
- result = AISessionResult(
1046
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
1047
- exit_code=1,
1048
- timed_out=timed_out,
1049
- termination_reason=termination_reason,
1050
- stale_marker=None,
1051
- fatal_error_code="api_error",
1052
- progress_summary=ProgressSummary(terminal_result_text="provider gateway error"),
1053
- session_log=log,
1054
- backup_log=tmp_path / "backup.log",
1055
- log_recovery=None,
1056
- started_epoch=0,
1057
- ended_epoch=1,
1058
- )
1059
-
1060
- classification = classify_session(result, project_root=tmp_path, base_head=base_head)
1061
-
1062
- assert classification.session_status == expected_status
1063
- assert classification.reason == expected_reason
1064
-
1065
-
1066
-
1067
- @pytest.mark.parametrize("workflow_type", ["feature-pipeline", "bugfix-pipeline"])
1068
- def test_semantic_completion_classification_has_cross_family_parity(tmp_path, workflow_type):
1069
- from prizmkit_runtime.runner_classification import classify_session
1070
- from prizmkit_runtime.runner_models import PromptGenerationResult
1071
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
1072
- from prizmkit_runtime.status import ProgressSummary
1073
-
1074
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
1075
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
1076
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
1077
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
1078
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
1079
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
1080
- base_head = subprocess.run(
1081
- ["git", "rev-parse", "HEAD"],
1082
- cwd=tmp_path,
1083
- check=True,
1084
- stdout=subprocess.PIPE,
1085
- text=True,
1086
- ).stdout.strip()
1087
- (tmp_path / "done.txt").write_text("done", encoding="utf-8")
1088
- subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
1089
- subprocess.run(
1090
- ["git", "commit", "-m", "done"],
1091
- cwd=tmp_path,
1092
- check=True,
1093
- stdout=subprocess.DEVNULL,
1094
- )
1095
- artifact = tmp_path / ".prizmkit" / "artifacts" / workflow_type
1096
- checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact, workflow_type)
1097
- log = tmp_path / f"{workflow_type}.log"
1098
- log.write_text("success", encoding="utf-8")
1099
- raw = AISessionResult(
1100
- command=AISessionCommand(("fake",), None, "claude", "stdin"),
1101
- exit_code=0,
1102
- timed_out=False,
1103
- termination_reason=None,
1104
- stale_marker=None,
1105
- fatal_error_code="",
1106
- progress_summary=ProgressSummary(result_subtype="success"),
1107
- session_log=log,
1108
- backup_log=tmp_path / "backup.log",
1109
- log_recovery=None,
1110
- started_epoch=0,
1111
- ended_epoch=1,
1112
- )
1113
-
1114
- classification = classify_session(
1115
- raw,
1116
- project_root=tmp_path,
1117
- base_head=base_head,
1118
- prompt=PromptGenerationResult(
1119
- output_path=tmp_path / "prompt.md",
1120
- checkpoint_path=checkpoint,
1121
- artifact_path=artifact,
1122
- ),
1123
- )
1124
-
1125
- assert classification.session_status == "success"
1126
- assert classification.checkpoint_state["terminal_status"] == "WORKFLOW_COMPLETED"
1127
-
1128
-
1129
- def test_semantic_blocked_classification_is_terminal_and_retry_neutral(tmp_path):
1130
- from prizmkit_runtime.runner_classification import classify_session
1131
- from prizmkit_runtime.runner_models import PromptGenerationResult
1132
- from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
1133
- from prizmkit_runtime.status import ProgressSummary
1134
-
1135
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
1136
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
1137
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
1138
- (tmp_path / "base.txt").write_text("base", encoding="utf-8")
1139
- subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
1140
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
1141
- artifact = tmp_path / ".prizmkit" / "specs" / "blocked"
1142
- checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact)
1143
- data = json.loads(checkpoint.read_text(encoding="utf-8"))
1144
- data["feature_state"].update(
1145
- terminal_status="WORKFLOW_BLOCKED",
1146
- blocked_reason="repair_round_limit",
1147
- repair_round=3,
1148
- )
1149
- checkpoint.write_text(json.dumps(data), encoding="utf-8")
1150
- log = tmp_path / "blocked.log"
1151
- log.write_text("ambiguous failure", encoding="utf-8")
1152
- raw = AISessionResult(
1153
- command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
1154
- exit_code=1,
1155
- timed_out=False,
1156
- termination_reason=None,
1157
- stale_marker=None,
1158
- fatal_error_code="",
1159
- progress_summary=ProgressSummary(terminal_result_text="ambiguous failure"),
1160
- session_log=log,
1161
- backup_log=tmp_path / "backup.log",
1162
- log_recovery=None,
1163
- started_epoch=0,
1164
- ended_epoch=1,
1165
- )
1166
-
1167
- classification = classify_session(
1168
- raw,
1169
- project_root=tmp_path,
1170
- base_head="",
1171
- prompt=PromptGenerationResult(
1172
- output_path=tmp_path / "prompt.md",
1173
- checkpoint_path=checkpoint,
1174
- artifact_path=artifact,
1175
- ),
1176
- )
1177
-
1178
- assert classification.session_status == "workflow_blocked"
1179
- assert classification.reason == "repair_round_limit"
1180
- assert classification.checkpoint_state["repair_round"] == 3
1181
-
1182
-
1183
- def test_runtime_semantic_paths_do_not_invoke_composite_workflow():
1184
- sources = [
1185
- PIPELINE_ROOT / "prizmkit_runtime" / "checkpoint_state.py",
1186
- PIPELINE_ROOT / "prizmkit_runtime" / "runner_classification.py",
1187
- PIPELINE_ROOT / "prizmkit_runtime" / "runners.py",
1188
- ]
1189
-
1190
- for source in sources:
1191
- assert "prizmkit-workflow" not in source.read_text(encoding="utf-8")
1192
-
1193
-
1194
-
1195
- @pytest.mark.parametrize(
1196
- ("kind", "item_id", "blocked_status"),
1197
- [("feature", "F-001", "failed"), ("bugfix", "B-001", "needs_info")],
1198
- )
1199
- def test_family_status_persists_identical_semantic_blocked_snapshot_without_retry_spend(
1200
- tmp_path, kind, item_id, blocked_status
1201
- ):
1202
- from prizmkit_runtime.runner_models import family_for, parse_invocation
1203
- from prizmkit_runtime.runner_status import start_item, update_item
1204
-
1205
- paths = _make_paths(tmp_path)
1206
- item = {
1207
- "id": item_id,
1208
- "title": "Semantic blocked",
1209
- "status": "pending",
1210
- "priority": "high",
1211
- "dependencies": [],
1212
- }
1213
- if kind == "bugfix":
1214
- item.update(severity="high", description="blocked", reproduction_steps=["run"])
1215
- _write_family_plan(paths, kind, [item])
1216
- family = family_for(kind, paths)
1217
- invocation = parse_invocation(family, "run", ())
1218
- invocation = invocation.__class__(**{**invocation.__dict__, "list_path": family.plan_path})
1219
- assert start_item(family, invocation, item_id, paths.project_root).ok is True
1220
- semantic = {
1221
- "current_stage": None,
1222
- "next_stage": None,
1223
- "stage_result": "TEST_BLOCKED",
1224
- "repair_scope": "production",
1225
- "repair_round": 2,
1226
- "blocked_reason": "test_blocked",
1227
- "terminal_status": "WORKFLOW_BLOCKED",
1228
- }
1229
-
1230
- result = update_item(
1231
- family,
1232
- invocation,
1233
- item_id,
1234
- "workflow_blocked",
1235
- "session-1",
1236
- paths.project_root,
1237
- checkpoint_state=semantic,
1238
- )
1239
- status = json.loads((family.state_dir / item_id / "status.json").read_text(encoding="utf-8"))
1240
-
1241
- assert result.ok is True
1242
- assert result.data["new_status"] == blocked_status
1243
- assert result.data["checkpoint_state"] == semantic
1244
- assert result.data["restart_policy"] == "terminal_blocked"
1245
- assert status["retry_count"] == 0
1246
- assert status["infra_error_count"] == 0
1247
- for key, value in semantic.items():
1248
- assert status[key] == value
1249
-
1250
-
1251
- def test_runtime_sources_do_not_depend_on_direct_lifecycle_composite():
1252
- runtime_root = REPO_ROOT / "dev-pipeline"
1253
- source_files = list(runtime_root.rglob("*.py"))
1254
- for source in source_files:
1255
- if "__pycache__" in source.parts or "tests" in source.parts or not source.is_file():
1256
- continue
1257
- assert "prizmkit-workflow" not in source.read_text(encoding="utf-8")