prizmkit 1.1.191 → 1.1.192
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.
- package/bundled/VERSION.json +3 -3
- package/bundled/adapters/antigravity/skill-adapter.js +13 -4
- package/bundled/adapters/codex/skill-adapter.js +28 -8
- package/bundled/adapters/cursor/skill-adapter.js +13 -4
- package/bundled/adapters/pi/skill-adapter.js +28 -7
- package/bundled/dev-pipeline/.env.example +4 -12
- package/bundled/dev-pipeline/README.md +5 -10
- package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -6
- package/bundled/dev-pipeline/prizmkit_runtime/atomic_io.py +48 -0
- package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +66 -23
- package/bundled/dev-pipeline/prizmkit_runtime/cli.py +10 -7
- package/bundled/dev-pipeline/prizmkit_runtime/commands.py +2 -21
- package/bundled/dev-pipeline/prizmkit_runtime/config.py +24 -76
- package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +125 -67
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +77 -430
- package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +93 -49
- package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +1 -3
- package/bundled/dev-pipeline/prizmkit_runtime/paths.py +0 -6
- package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +36 -14
- package/bundled/dev-pipeline/prizmkit_runtime/processes.py +206 -151
- package/bundled/dev-pipeline/prizmkit_runtime/reset.py +2 -23
- package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +15 -134
- package/bundled/dev-pipeline/prizmkit_runtime/results.py +25 -0
- package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +68 -83
- package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +15 -5
- package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +1 -29
- package/bundled/dev-pipeline/prizmkit_runtime/runner_prompts.py +0 -2
- package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +7 -2
- package/bundled/dev-pipeline/prizmkit_runtime/runners.py +276 -217
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +124 -122
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_helper.py +90 -9
- package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +183 -130
- package/bundled/dev-pipeline/prizmkit_runtime/status.py +1 -3
- package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +2780 -0
- package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +27 -101
- package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +58 -4
- package/bundled/dev-pipeline/scripts/check-session-status.py +43 -19
- package/bundled/dev-pipeline/scripts/continuation.py +6 -4
- package/bundled/dev-pipeline/scripts/detect-stuck.py +28 -28
- package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +7 -2
- package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +7 -2
- package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +10 -7
- package/bundled/dev-pipeline/scripts/init-change-artifact.py +8 -2
- package/bundled/dev-pipeline/scripts/init-pipeline.py +14 -69
- package/bundled/dev-pipeline/scripts/parse-stream-progress.py +31 -2616
- package/bundled/dev-pipeline/scripts/patch-completion-notes.py +4 -24
- package/bundled/dev-pipeline/scripts/prompt_framework.py +56 -9
- package/bundled/dev-pipeline/scripts/status_common.py +591 -0
- package/bundled/dev-pipeline/scripts/update-bug-status.py +85 -463
- package/bundled/dev-pipeline/scripts/update-checkpoint.py +227 -65
- package/bundled/dev-pipeline/scripts/update-feature-status.py +76 -509
- package/bundled/dev-pipeline/scripts/utils.py +5 -12
- package/bundled/dev-pipeline/templates/bootstrap-tier3.md +4 -4
- package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +7 -0
- package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +1 -1
- package/bundled/dev-pipeline/templates/sections/artifact-manifest.md +1 -1
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-manual-verification.md +1 -1
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +1 -1
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +2 -1
- package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-browser-verification-auto.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-browser-verification-opencli.md +2 -2
- package/bundled/dev-pipeline/templates/sections/phase-browser-verification.md +2 -2
- package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +2 -1
- package/bundled/dev-pipeline/templates/sections/phase-review-full.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-specify-plan-full.md +3 -6
- package/bundled/dev-pipeline/templates/session-status-schema.json +2 -5
- package/bundled/dev-pipeline/tests/_helpers.py +418 -0
- package/bundled/dev-pipeline/tests/conftest.py +45 -1
- package/bundled/dev-pipeline/tests/test_auto_skip.py +4 -69
- package/bundled/dev-pipeline/tests/test_checkpoint_state.py +126 -1
- package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +257 -0
- package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +500 -0
- package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +59 -117
- package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +12 -10
- package/bundled/dev-pipeline/tests/test_python_runner_parity.py +431 -3099
- package/bundled/dev-pipeline/tests/test_recovery_workflow.py +7 -8
- package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -1
- package/bundled/dev-pipeline/tests/test_reset_modes.py +15 -27
- package/bundled/dev-pipeline/tests/test_reset_preserve.py +54 -139
- package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +766 -0
- package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +1257 -0
- package/bundled/dev-pipeline/tests/test_runtime_helper.py +97 -20
- package/bundled/dev-pipeline/tests/test_session_launch.py +1101 -0
- package/bundled/dev-pipeline/tests/test_stream_progress.py +585 -0
- package/bundled/dev-pipeline/tests/test_unified_cli.py +155 -2034
- package/bundled/dev-pipeline/tests/test_utils.py +3 -3
- package/bundled/skills/_metadata.json +9 -63
- package/bundled/skills/app-planner/SKILL.md +32 -303
- package/bundled/skills/app-planner/references/app-design-guide.md +0 -4
- package/bundled/skills/app-planner/references/generated-plan-review.md +2 -1
- package/bundled/skills/app-planner/references/project-brief-guide.md +14 -0
- package/bundled/skills/app-planner/references/project-conventions-discovery.md +4 -6
- package/bundled/skills/app-planner/references/project-state-detection.md +2 -3
- package/bundled/skills/bug-fix-workflow/SKILL.md +1 -2
- package/bundled/skills/bug-fix-workflow/references/bug-diagnosis.md +4 -7
- package/bundled/skills/bug-planner/SKILL.md +54 -435
- package/bundled/skills/bug-planner/references/generated-plan-review.md +3 -2
- package/bundled/skills/bug-planner/references/input-formats.md +32 -0
- package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +4 -6
- package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +4 -28
- package/bundled/skills/feature-pipeline-launcher/SKILL.md +4 -6
- package/bundled/skills/feature-pipeline-launcher/references/configuration.md +4 -28
- package/bundled/skills/feature-planner/SKILL.md +60 -439
- package/bundled/skills/feature-planner/assets/planning-guide.md +1 -1
- package/bundled/skills/feature-planner/references/completeness-review.md +34 -0
- package/bundled/skills/feature-planner/references/decomposition-patterns.md +2 -2
- package/bundled/skills/feature-planner/references/error-recovery.md +1 -1
- package/bundled/skills/feature-planner/references/generated-plan-review.md +3 -2
- package/bundled/skills/feature-planner/references/incremental-feature-planning.md +3 -1
- package/bundled/skills/feature-workflow/SKILL.md +1 -2
- package/bundled/skills/prizmkit/SKILL.md +7 -1
- package/bundled/skills/prizmkit-code-review/SKILL.md +14 -6
- package/bundled/skills/prizmkit-code-review/references/independent-code-review.md +7 -4
- package/bundled/skills/prizmkit-code-review/references/review-report-template.md +16 -0
- package/bundled/skills/prizmkit-code-review/scripts/render_review_report.py +58 -20
- package/bundled/skills/prizmkit-implement/SKILL.md +1 -1
- package/bundled/skills/prizmkit-init/SKILL.md +24 -127
- package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
- package/bundled/skills/prizmkit-plan/SKILL.md +6 -8
- package/bundled/skills/prizmkit-plan/references/clarify-guide.md +1 -1
- package/bundled/skills/prizmkit-plan/references/independent-plan-review.md +5 -2
- package/bundled/skills/prizmkit-plan/references/review-plan-spec-loop.md +6 -5
- package/bundled/skills/prizmkit-prizm-docs/SKILL.md +1 -13
- package/bundled/skills/prizmkit-prizm-docs/references/op-update.md +1 -1
- package/bundled/skills/prizmkit-retrospective/SKILL.md +6 -4
- package/bundled/skills/prizmkit-test/SKILL.md +25 -133
- package/bundled/skills/prizmkit-test/references/independent-test-review.md +5 -2
- package/bundled/skills/prizmkit-test/references/test-coverage-model.md +6 -0
- package/bundled/skills/prizmkit-workflow/SKILL.md +2 -3
- package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +4 -3
- package/bundled/skills/recovery-workflow/SKILL.md +7 -7
- package/bundled/skills/recovery-workflow/evals/evals.json +1 -1
- package/bundled/skills/recovery-workflow/references/detection.md +1 -3
- package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +0 -6
- package/bundled/templates/project-memory-template.md +1 -2
- package/package.json +1 -1
- package/src/scaffold.js +28 -7
- package/bundled/dev-pipeline/SCHEMA_ANALYSIS.md +0 -53
- package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +0 -649
- package/bundled/dev-pipeline/scripts/init-refactor-pipeline.py +0 -463
- package/bundled/dev-pipeline/scripts/update-refactor-status.py +0 -1512
- package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +0 -240
- package/bundled/dev-pipeline/templates/refactor-list-schema.json +0 -266
- package/bundled/dev-pipeline/templates/sections/refactor-critical-paths.md +0 -15
- package/bundled/dev-pipeline/templates/sections/refactor-mission.md +0 -9
- package/bundled/dev-pipeline/templates/sections/refactor-phase-commit-report.md +0 -24
- package/bundled/dev-pipeline/templates/sections/refactor-phase-implement.md +0 -16
- package/bundled/dev-pipeline/templates/sections/refactor-phase-init.md +0 -9
- package/bundled/dev-pipeline/templates/sections/refactor-phase-plan.md +0 -22
- package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +0 -19
- package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +0 -24
- package/bundled/dev-pipeline/templates/sections/refactor-reminders.md +0 -12
- package/bundled/dev-pipeline/templates/sections/refactor-session-context.md +0 -6
- package/bundled/dev-pipeline/templates/sections/refactor-task-contract.md +0 -52
- package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +0 -478
- package/bundled/skills/feature-planner/assets/evaluation-guide.md +0 -44
- package/bundled/skills/refactor-pipeline-launcher/SKILL.md +0 -219
- package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +0 -78
- package/bundled/skills/refactor-planner/SKILL.md +0 -467
- package/bundled/skills/refactor-planner/assets/planning-guide.md +0 -291
- package/bundled/skills/refactor-planner/references/behavior-preservation.md +0 -187
- package/bundled/skills/refactor-planner/references/error-recovery.md +0 -45
- package/bundled/skills/refactor-planner/references/fast-path.md +0 -59
- package/bundled/skills/refactor-planner/references/generated-plan-review.md +0 -107
- package/bundled/skills/refactor-planner/references/planning-phases.md +0 -172
- package/bundled/skills/refactor-planner/references/refactor-scoping-guide.md +0 -230
- package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +0 -1120
- package/bundled/skills/refactor-workflow/SKILL.md +0 -205
|
@@ -11,6 +11,15 @@ from types import SimpleNamespace
|
|
|
11
11
|
|
|
12
12
|
import pytest
|
|
13
13
|
|
|
14
|
+
from _helpers import (
|
|
15
|
+
_init_bookkeeping_repo,
|
|
16
|
+
_install_runner_session_fakes,
|
|
17
|
+
_make_paths,
|
|
18
|
+
_write_family_plan,
|
|
19
|
+
_write_feature_list,
|
|
20
|
+
_write_semantic_completion_checkpoint,
|
|
21
|
+
)
|
|
22
|
+
|
|
14
23
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
15
24
|
PIPELINE_ROOT = REPO_ROOT / "dev-pipeline"
|
|
16
25
|
CLI_PATH = PIPELINE_ROOT / "cli.py"
|
|
@@ -37,45 +46,6 @@ def _load_unix_runtime_snapshot():
|
|
|
37
46
|
return json.loads(UNIX_RUNTIME_SNAPSHOT.read_text(encoding="utf-8"))
|
|
38
47
|
|
|
39
48
|
|
|
40
|
-
def _make_paths(tmp_path):
|
|
41
|
-
from prizmkit_runtime.paths import resolve_runtime_paths
|
|
42
|
-
|
|
43
|
-
project = tmp_path / "project"
|
|
44
|
-
(project / ".prizmkit" / "plans").mkdir(parents=True)
|
|
45
|
-
return resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=project)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def _write_feature_list(paths):
|
|
49
|
-
paths.feature_plan.write_text(
|
|
50
|
-
json.dumps(
|
|
51
|
-
{
|
|
52
|
-
"$schema": "dev-pipeline-feature-list-v1",
|
|
53
|
-
"project_name": "Fake",
|
|
54
|
-
"features": [
|
|
55
|
-
{"id": "F-001", "title": "Low", "status": "pending", "priority": "low", "dependencies": []},
|
|
56
|
-
{"id": "F-002", "title": "Critical", "status": "pending", "priority": "critical", "dependencies": []},
|
|
57
|
-
{"id": "F-003", "title": "Blocked", "status": "pending", "priority": "high", "dependencies": ["F-001"]},
|
|
58
|
-
],
|
|
59
|
-
}
|
|
60
|
-
),
|
|
61
|
-
encoding="utf-8",
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
def _write_family_plan(paths, kind, items):
|
|
66
|
-
plan_config = {
|
|
67
|
-
"feature": (paths.feature_plan, "features", "dev-pipeline-feature-list-v1"),
|
|
68
|
-
"bugfix": (paths.bugfix_plan, "bugs", "dev-pipeline-bug-fix-list-v1"),
|
|
69
|
-
"refactor": (paths.refactor_plan, "refactors", "dev-pipeline-refactor-list-v1"),
|
|
70
|
-
}
|
|
71
|
-
plan_path, list_key, schema = plan_config[kind]
|
|
72
|
-
plan_path.write_text(
|
|
73
|
-
json.dumps({"$schema": schema, "project_name": "Fake", list_key: items}),
|
|
74
|
-
encoding="utf-8",
|
|
75
|
-
)
|
|
76
|
-
return plan_path
|
|
77
|
-
|
|
78
|
-
|
|
79
49
|
@pytest.mark.parametrize(
|
|
80
50
|
("kind", "item_id", "filename", "list_key", "schema", "item"),
|
|
81
51
|
[
|
|
@@ -99,18 +69,6 @@ def _write_family_plan(paths, kind, items):
|
|
|
99
69
|
"acceptance_criteria": ["Prompt validates"], "status": "pending",
|
|
100
70
|
},
|
|
101
71
|
),
|
|
102
|
-
(
|
|
103
|
-
"refactor", "R-001", "refactor-list.json", "refactors",
|
|
104
|
-
"dev-pipeline-refactor-list-v1",
|
|
105
|
-
{
|
|
106
|
-
"id": "R-001", "title": "Preview Refactor", "description": "Preview only",
|
|
107
|
-
"scope": {"files": ["src/example.js"], "modules": ["example"]},
|
|
108
|
-
"type": "simplify", "priority": "high", "complexity": "low",
|
|
109
|
-
"behavior_preservation": {"strategy": "test-gate", "existing_tests": True},
|
|
110
|
-
"acceptance_criteria": ["Prompt validates"],
|
|
111
|
-
"dependencies": [], "status": "pending",
|
|
112
|
-
},
|
|
113
|
-
),
|
|
114
72
|
],
|
|
115
73
|
)
|
|
116
74
|
def test_actual_dry_run_is_read_only_and_successful(
|
|
@@ -169,7 +127,6 @@ def test_actual_dry_run_is_read_only_and_successful(
|
|
|
169
127
|
assert not (project / ".prizmkit" / "state").exists()
|
|
170
128
|
assert not (project / ".prizmkit" / "specs").exists()
|
|
171
129
|
assert not (project / ".prizmkit" / "bugfix").exists()
|
|
172
|
-
assert not (project / ".prizmkit" / "refactor").exists()
|
|
173
130
|
|
|
174
131
|
|
|
175
132
|
def _get_next_result(kind, paths):
|
|
@@ -183,138 +140,19 @@ def _get_next_result(kind, paths):
|
|
|
183
140
|
|
|
184
141
|
|
|
185
142
|
def _item_id_from_next_result(kind, result):
|
|
186
|
-
key = {"feature": "feature_id", "bugfix": "bug_id"
|
|
143
|
+
key = {"feature": "feature_id", "bugfix": "bug_id"}[kind]
|
|
187
144
|
return result.data[key]
|
|
188
145
|
|
|
189
146
|
|
|
190
|
-
def _write_semantic_completion_checkpoint(project_root, artifact_dir, workflow_type="feature-pipeline"):
|
|
191
|
-
contracts = {
|
|
192
|
-
"feature-pipeline": (
|
|
193
|
-
"feature_state",
|
|
194
|
-
[
|
|
195
|
-
"prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
|
|
196
|
-
"completion-summary", "prizmkit-retrospective", "prizmkit-committer",
|
|
197
|
-
],
|
|
198
|
-
),
|
|
199
|
-
"bugfix-pipeline": (
|
|
200
|
-
"bugfix_state",
|
|
201
|
-
[
|
|
202
|
-
"prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
|
|
203
|
-
"bug-report", "prizmkit-retrospective", "prizmkit-committer",
|
|
204
|
-
],
|
|
205
|
-
),
|
|
206
|
-
"refactor-pipeline": (
|
|
207
|
-
"refactor_state",
|
|
208
|
-
[
|
|
209
|
-
"prizmkit-implement", "prizmkit-code-review", "prizmkit-test",
|
|
210
|
-
"refactor-report", "completion-summary", "prizmkit-retrospective",
|
|
211
|
-
"prizmkit-committer",
|
|
212
|
-
],
|
|
213
|
-
),
|
|
214
|
-
}
|
|
215
|
-
state_key, skills = contracts[workflow_type]
|
|
216
|
-
steps = []
|
|
217
|
-
previous = None
|
|
218
|
-
for index, skill in enumerate(skills, start=1):
|
|
219
|
-
step = {
|
|
220
|
-
"id": f"S{index:02d}",
|
|
221
|
-
"skill": skill,
|
|
222
|
-
"name": skill,
|
|
223
|
-
"status": "completed",
|
|
224
|
-
"required_artifacts": [],
|
|
225
|
-
"depends_on": previous,
|
|
226
|
-
}
|
|
227
|
-
if skill == "prizmkit-implement":
|
|
228
|
-
step["stage_result"] = "IMPLEMENTED"
|
|
229
|
-
if skill == "prizmkit-code-review":
|
|
230
|
-
step["stage_result"] = "REVIEW_PASS"
|
|
231
|
-
if skill == "prizmkit-test":
|
|
232
|
-
step["stage_result"] = "TEST_PASS"
|
|
233
|
-
relative_artifact = artifact_dir.relative_to(project_root)
|
|
234
|
-
step["required_artifacts"] = [
|
|
235
|
-
str(relative_artifact / "test-report.md"),
|
|
236
|
-
str(relative_artifact / "test-result.json"),
|
|
237
|
-
]
|
|
238
|
-
if skill == "prizmkit-retrospective":
|
|
239
|
-
step["stage_result"] = "RETRO_COMPLETE"
|
|
240
|
-
if skill == "prizmkit-committer":
|
|
241
|
-
step["stage_result"] = "COMMITTED"
|
|
242
|
-
steps.append(step)
|
|
243
|
-
previous = step["id"]
|
|
244
|
-
artifact_dir.mkdir(parents=True, exist_ok=True)
|
|
245
|
-
(artifact_dir / "test-report.md").write_text(
|
|
246
|
-
"# Test Report\n\n## Final Result\n\n- Result: TEST_PASS\n",
|
|
247
|
-
encoding="utf-8",
|
|
248
|
-
)
|
|
249
|
-
(artifact_dir / "test-result.json").write_text(
|
|
250
|
-
json.dumps({
|
|
251
|
-
"schema_version": 1,
|
|
252
|
-
"result": "TEST_PASS",
|
|
253
|
-
"report": "test-report.md",
|
|
254
|
-
"main_review_rounds": 1,
|
|
255
|
-
"independent_review": {
|
|
256
|
-
"status": "downgraded",
|
|
257
|
-
"responses": 0,
|
|
258
|
-
"downgrade_reason": "read-only continuation capability unavailable",
|
|
259
|
-
"final_state_rechecked": False,
|
|
260
|
-
},
|
|
261
|
-
"repair_rounds": 0,
|
|
262
|
-
"production_changed": False,
|
|
263
|
-
"unresolved_items": [],
|
|
264
|
-
}),
|
|
265
|
-
encoding="utf-8",
|
|
266
|
-
)
|
|
267
|
-
runtime_commit_hash = "b" * 40
|
|
268
|
-
runtime_base_head = "a" * 40
|
|
269
|
-
head = subprocess.run(
|
|
270
|
-
["git", "rev-parse", "HEAD"],
|
|
271
|
-
cwd=project_root,
|
|
272
|
-
stdout=subprocess.PIPE,
|
|
273
|
-
stderr=subprocess.DEVNULL,
|
|
274
|
-
text=True,
|
|
275
|
-
check=False,
|
|
276
|
-
)
|
|
277
|
-
parent = subprocess.run(
|
|
278
|
-
["git", "rev-parse", "HEAD^"],
|
|
279
|
-
cwd=project_root,
|
|
280
|
-
stdout=subprocess.PIPE,
|
|
281
|
-
stderr=subprocess.DEVNULL,
|
|
282
|
-
text=True,
|
|
283
|
-
check=False,
|
|
284
|
-
)
|
|
285
|
-
if head.returncode == 0 and parent.returncode == 0:
|
|
286
|
-
runtime_commit_hash = head.stdout.strip()
|
|
287
|
-
runtime_base_head = parent.stdout.strip()
|
|
288
|
-
checkpoint = artifact_dir / "workflow-checkpoint.json"
|
|
289
|
-
checkpoint.write_text(
|
|
290
|
-
json.dumps({
|
|
291
|
-
"version": 1,
|
|
292
|
-
"workflow_type": workflow_type,
|
|
293
|
-
"steps": steps,
|
|
294
|
-
state_key: {
|
|
295
|
-
"repair_round": 0,
|
|
296
|
-
"terminal_status": "WORKFLOW_COMPLETED",
|
|
297
|
-
"runtime_base_head": runtime_base_head,
|
|
298
|
-
"runtime_commit_hash": runtime_commit_hash,
|
|
299
|
-
},
|
|
300
|
-
}),
|
|
301
|
-
encoding="utf-8",
|
|
302
|
-
)
|
|
303
|
-
return checkpoint
|
|
304
|
-
|
|
305
|
-
|
|
306
147
|
def test_retired_shell_runtime_files_are_absent_from_source():
|
|
307
148
|
retired = [
|
|
308
149
|
"run-feature.sh",
|
|
309
150
|
"run-bugfix.sh",
|
|
310
|
-
"run-refactor.sh",
|
|
311
151
|
"run-recovery.sh",
|
|
312
152
|
"launch-feature-daemon.sh",
|
|
313
153
|
"launch-bugfix-daemon.sh",
|
|
314
|
-
"launch-refactor-daemon.sh",
|
|
315
154
|
"reset-feature.sh",
|
|
316
155
|
"reset-bug.sh",
|
|
317
|
-
"reset-refactor.sh",
|
|
318
156
|
"lib/branch.sh",
|
|
319
157
|
"lib/common.sh",
|
|
320
158
|
"lib/heartbeat.sh",
|
|
@@ -326,17 +164,19 @@ def test_retired_shell_runtime_files_are_absent_from_source():
|
|
|
326
164
|
|
|
327
165
|
def test_python_parity_suite_declares_coverage_for_all_legacy_unix_snapshot_scenarios():
|
|
328
166
|
"""Keep the F-011 snapshot as an explicit oracle without reviving shell sources."""
|
|
167
|
+
import ast
|
|
168
|
+
|
|
329
169
|
snapshot = _load_unix_runtime_snapshot()
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
(
|
|
335
|
-
|
|
336
|
-
|
|
170
|
+
test_names: set[str] = set()
|
|
171
|
+
for test_file in sorted((PIPELINE_ROOT / "tests").glob("test_*.py")):
|
|
172
|
+
tree = ast.parse(test_file.read_text(encoding="utf-8"), filename=str(test_file))
|
|
173
|
+
for node in ast.walk(tree):
|
|
174
|
+
if isinstance(node, ast.FunctionDef) and node.name.startswith("test_"):
|
|
175
|
+
test_names.add(node.name)
|
|
176
|
+
|
|
337
177
|
coverage_tokens = {
|
|
338
178
|
"entrypointContracts": {
|
|
339
|
-
"runnerHelpContracts": ["
|
|
179
|
+
"runnerHelpContracts": ["test_cli_help_exposes_only_operation_first_public_namespaces"],
|
|
340
180
|
"runnerMissingListErrors": ["test_python_runner_missing_list_errors_match_snapshot_contract"],
|
|
341
181
|
"resetHelpContracts": ["test_reset_and_daemon_entrypoint_contracts_match_snapshot_contracts"],
|
|
342
182
|
"daemonStatusContracts": ["test_reset_and_daemon_entrypoint_contracts_match_snapshot_contracts"],
|
|
@@ -344,8 +184,8 @@ def test_python_parity_suite_declares_coverage_for_all_legacy_unix_snapshot_scen
|
|
|
344
184
|
"envResolution": {
|
|
345
185
|
"verboseAndStreamJson": ["test_python_env_resolution_scenarios_match_snapshot_contracts"],
|
|
346
186
|
"effortModelAndCli": ["test_ai_session_command_builders_match_unix_runtime_snapshot"],
|
|
347
|
-
"worktreeIgnored": ["
|
|
348
|
-
"autoPushFlag": ["
|
|
187
|
+
"worktreeIgnored": ["test_runner_environment_retires_use_worktree_and_ignores_env"],
|
|
188
|
+
"autoPushFlag": ["test_successful_branch_session_merges_and_honors_auto_push"],
|
|
349
189
|
},
|
|
350
190
|
"aiCliCommands": {
|
|
351
191
|
"claudeCommand": ["test_ai_session_command_builders_match_unix_runtime_snapshot"],
|
|
@@ -354,7 +194,7 @@ def test_python_parity_suite_declares_coverage_for_all_legacy_unix_snapshot_scen
|
|
|
354
194
|
},
|
|
355
195
|
"fakeCliOutcomes": {
|
|
356
196
|
"success": ["test_session_dual_writes_progress_and_recovers_backup"],
|
|
357
|
-
"contextOverflowContinuation": ["
|
|
197
|
+
"contextOverflowContinuation": ["test_context_overflow_reuses_branch_and_skips_cleanup_until_terminal_outcome"],
|
|
358
198
|
"infraErrorRetry": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
359
199
|
"crashFailure": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
360
200
|
"timeoutStaleKill": ["test_heartbeat_fatal_error_writes_shell_compatible_markers"],
|
|
@@ -373,7 +213,7 @@ def test_python_parity_suite_declares_coverage_for_all_legacy_unix_snapshot_scen
|
|
|
373
213
|
},
|
|
374
214
|
"continuationBehavior": {
|
|
375
215
|
"noProgressStall": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
376
|
-
"branchAndArtifactReuse": ["
|
|
216
|
+
"branchAndArtifactReuse": ["test_context_overflow_reuses_branch_and_skips_cleanup_until_terminal_outcome"],
|
|
377
217
|
},
|
|
378
218
|
"statusUpdaterBehavior": {
|
|
379
219
|
"contextOverflowMetadata": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
@@ -390,14 +230,14 @@ def test_python_parity_suite_declares_coverage_for_all_legacy_unix_snapshot_scen
|
|
|
390
230
|
for scenario_name, tokens in coverage_tokens[section].items():
|
|
391
231
|
assert tokens, f"{section}.{scenario_name} has no coverage tokens"
|
|
392
232
|
for token in tokens:
|
|
393
|
-
assert token in
|
|
233
|
+
assert token in test_names, f"{section}.{scenario_name} coverage test missing: {token}"
|
|
394
234
|
|
|
395
235
|
|
|
396
236
|
def test_python_runner_missing_list_errors_match_snapshot_contract(tmp_path):
|
|
397
237
|
from prizmkit_runtime.runners import run_pipeline_command
|
|
398
238
|
|
|
399
239
|
snapshot = _load_unix_runtime_snapshot()["entrypointContracts"]["runnerMissingListErrors"]
|
|
400
|
-
for kind in ("feature", "bugfix"
|
|
240
|
+
for kind in ("feature", "bugfix"):
|
|
401
241
|
paths = _make_paths(tmp_path / f"missing-{kind}")
|
|
402
242
|
result = run_pipeline_command(kind, "run", (), paths)
|
|
403
243
|
|
|
@@ -413,7 +253,7 @@ def test_reset_and_daemon_entrypoint_contracts_match_snapshot_contracts(tmp_path
|
|
|
413
253
|
snapshot = _load_unix_runtime_snapshot()["entrypointContracts"]
|
|
414
254
|
paths = _make_paths(tmp_path / "entrypoints")
|
|
415
255
|
|
|
416
|
-
for kind in ("feature", "bugfix"
|
|
256
|
+
for kind in ("feature", "bugfix"):
|
|
417
257
|
reset = run_reset_command(kind, ("--help",), paths)
|
|
418
258
|
assert reset.exit_code == snapshot["resetHelpContracts"][kind]["exitCode"]
|
|
419
259
|
assert "Usage: prizmkit-runtime reset" in reset.render()
|
|
@@ -601,7 +441,6 @@ def test_runner_models_parse_legacy_args_and_environment(tmp_path):
|
|
|
601
441
|
"VERBOSE": "1",
|
|
602
442
|
"STALE_KILL_THRESHOLD": "9",
|
|
603
443
|
"MAX_RETRIES": "9",
|
|
604
|
-
"STRICT_BEHAVIOR_CHECK": "false",
|
|
605
444
|
}
|
|
606
445
|
)
|
|
607
446
|
|
|
@@ -616,22 +455,17 @@ def test_runner_models_parse_legacy_args_and_environment(tmp_path):
|
|
|
616
455
|
assert env.dev_branch == "dev/custom"
|
|
617
456
|
assert env.stale_kill_threshold_seconds == 9
|
|
618
457
|
assert env.max_retries == 9
|
|
619
|
-
assert env.strict_behavior_check is False
|
|
620
458
|
assert not hasattr(env, "enable_deploy")
|
|
621
459
|
assert not hasattr(env, "max_" + "log_size")
|
|
622
460
|
|
|
623
461
|
|
|
624
|
-
def
|
|
462
|
+
def test_runner_environment_retires_use_worktree_and_ignores_env():
|
|
625
463
|
from prizmkit_runtime.runner_models import RunnerEnvironment
|
|
626
464
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
assert RunnerEnvironment.from_env({"USE_WORKTREE": truthy}).use_worktree is True
|
|
632
|
-
|
|
633
|
-
for falsey in ("0", "false", "no", "off"):
|
|
634
|
-
assert RunnerEnvironment.from_env({"USE_WORKTREE": falsey}).use_worktree is False
|
|
465
|
+
for raw in ({}, {"USE_WORKTREE": "1"}, {"USE_WORKTREE": "true"}):
|
|
466
|
+
env = RunnerEnvironment.from_env(raw)
|
|
467
|
+
assert not hasattr(env, "use_worktree")
|
|
468
|
+
assert env.auto_push is False
|
|
635
469
|
|
|
636
470
|
|
|
637
471
|
def test_status_bridge_preserves_feature_filter_selection(tmp_path):
|
|
@@ -672,11 +506,6 @@ def test_status_bridge_uses_stable_dependency_order_across_pipeline_families(tmp
|
|
|
672
506
|
{"id": "B-002", "title": "First", "status": "pending", "severity": "low", "priority": "low", "error_source": {"type": "user_report"}, "verification_type": "manual", "acceptance_criteria": ["fixed"], "dependencies": []},
|
|
673
507
|
{"id": "B-003", "title": "Independent", "status": "pending", "severity": "high", "priority": "high", "error_source": {"type": "user_report"}, "verification_type": "manual", "acceptance_criteria": ["fixed"], "dependencies": []},
|
|
674
508
|
],
|
|
675
|
-
"refactor": [
|
|
676
|
-
{"id": "R-001", "title": "Blocked", "description": "blocked", "scope": {}, "type": "restructure", "priority": "critical", "complexity": "high", "behavior_preservation": {"strategy": "test-gate"}, "acceptance_criteria": ["done"], "dependencies": ["R-002"], "status": "pending"},
|
|
677
|
-
{"id": "R-002", "title": "First", "description": "first", "scope": {}, "type": "extract", "priority": "low", "complexity": "low", "behavior_preservation": {"strategy": "test-gate"}, "acceptance_criteria": ["done"], "dependencies": [], "status": "pending"},
|
|
678
|
-
{"id": "R-003", "title": "Independent", "description": "independent", "scope": {}, "type": "simplify", "priority": "high", "complexity": "medium", "behavior_preservation": {"strategy": "test-gate"}, "acceptance_criteria": ["done"], "dependencies": [], "status": "pending"},
|
|
679
|
-
],
|
|
680
509
|
}
|
|
681
510
|
|
|
682
511
|
for kind, items in cases.items():
|
|
@@ -686,7 +515,7 @@ def test_status_bridge_uses_stable_dependency_order_across_pipeline_families(tmp
|
|
|
686
515
|
result = _get_next_result(kind, paths)
|
|
687
516
|
|
|
688
517
|
assert result.ok
|
|
689
|
-
assert _item_id_from_next_result(kind, result) == {"feature": "F-002", "bugfix": "B-002"
|
|
518
|
+
assert _item_id_from_next_result(kind, result) == {"feature": "F-002", "bugfix": "B-002"}[kind]
|
|
690
519
|
|
|
691
520
|
|
|
692
521
|
def test_status_bridge_prefers_in_progress_items_with_satisfied_dependencies(tmp_path):
|
|
@@ -701,11 +530,6 @@ def test_status_bridge_prefers_in_progress_items_with_satisfied_dependencies(tmp
|
|
|
701
530
|
{"id": "B-002", "title": "Resume", "status": "in_progress", "severity": "low", "priority": "low", "error_source": {"type": "user_report"}, "verification_type": "manual", "acceptance_criteria": ["fixed"], "dependencies": ["B-001"]},
|
|
702
531
|
{"id": "B-003", "title": "Pending", "status": "pending", "severity": "critical", "priority": "high", "error_source": {"type": "user_report"}, "verification_type": "manual", "acceptance_criteria": ["fixed"], "dependencies": []},
|
|
703
532
|
],
|
|
704
|
-
"refactor": [
|
|
705
|
-
{"id": "R-001", "title": "Done", "description": "done", "scope": {}, "type": "extract", "priority": "low", "complexity": "low", "behavior_preservation": {"strategy": "test-gate"}, "acceptance_criteria": ["done"], "dependencies": [], "status": "completed"},
|
|
706
|
-
{"id": "R-002", "title": "Resume", "description": "resume", "scope": {}, "type": "extract", "priority": "low", "complexity": "low", "behavior_preservation": {"strategy": "test-gate"}, "acceptance_criteria": ["done"], "dependencies": ["R-001"], "status": "in_progress"},
|
|
707
|
-
{"id": "R-003", "title": "Pending", "description": "pending", "scope": {}, "type": "migrate", "priority": "critical", "complexity": "high", "behavior_preservation": {"strategy": "test-gate"}, "acceptance_criteria": ["done"], "dependencies": [], "status": "pending"},
|
|
708
|
-
],
|
|
709
533
|
}
|
|
710
534
|
|
|
711
535
|
for kind, items in cases.items():
|
|
@@ -715,32 +539,13 @@ def test_status_bridge_prefers_in_progress_items_with_satisfied_dependencies(tmp
|
|
|
715
539
|
result = _get_next_result(kind, paths)
|
|
716
540
|
|
|
717
541
|
assert result.ok
|
|
718
|
-
assert _item_id_from_next_result(kind, result) == {"feature": "F-002", "bugfix": "B-002"
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
def test_refactor_dependencies_require_completed_not_other_terminal_statuses(tmp_path):
|
|
722
|
-
paths = _make_paths(tmp_path)
|
|
723
|
-
_write_family_plan(
|
|
724
|
-
paths,
|
|
725
|
-
"refactor",
|
|
726
|
-
[
|
|
727
|
-
{"id": "R-001", "title": "Failed Dependency", "description": "failed", "scope": {}, "type": "extract", "priority": "high", "complexity": "low", "behavior_preservation": {"strategy": "test-gate"}, "acceptance_criteria": ["done"], "dependencies": [], "status": "failed"},
|
|
728
|
-
{"id": "R-002", "title": "Blocked", "description": "blocked", "scope": {}, "type": "restructure", "priority": "high", "complexity": "medium", "behavior_preservation": {"strategy": "test-gate"}, "acceptance_criteria": ["done"], "dependencies": ["R-001"], "status": "pending"},
|
|
729
|
-
],
|
|
730
|
-
)
|
|
731
|
-
|
|
732
|
-
result = _get_next_result("refactor", paths)
|
|
733
|
-
|
|
734
|
-
assert result.ok
|
|
735
|
-
assert result.text == "PIPELINE_BLOCKED"
|
|
736
|
-
assert result.data is None
|
|
542
|
+
assert _item_id_from_next_result(kind, result) == {"feature": "F-002", "bugfix": "B-002"}[kind]
|
|
737
543
|
|
|
738
544
|
|
|
739
545
|
def test_init_scripts_reject_missing_self_and_cycle_dependencies(tmp_path):
|
|
740
546
|
script_config = {
|
|
741
547
|
"feature": ("init-pipeline.py", "--feature-list", "F-", "missing dependency"),
|
|
742
548
|
"bugfix": ("init-bugfix-pipeline.py", "--bug-list", "B-", "missing dependency"),
|
|
743
|
-
"refactor": ("init-refactor-pipeline.py", "--refactor-list", "R-", "missing dependency"),
|
|
744
549
|
}
|
|
745
550
|
scenarios = {
|
|
746
551
|
"missing": lambda kind, prefix: _family_items(kind, [
|
|
@@ -789,7 +594,6 @@ def test_init_scripts_reject_unknown_item_fields(tmp_path):
|
|
|
789
594
|
script_config = {
|
|
790
595
|
"feature": ("init-pipeline.py", "--feature-list", "F-"),
|
|
791
596
|
"bugfix": ("init-bugfix-pipeline.py", "--bug-list", "B-"),
|
|
792
|
-
"refactor": ("init-refactor-pipeline.py", "--refactor-list", "R-"),
|
|
793
597
|
}
|
|
794
598
|
|
|
795
599
|
for kind, (script_name, list_arg, prefix) in script_config.items():
|
|
@@ -857,7 +661,6 @@ def test_init_scripts_reject_unknown_list_fields(tmp_path, location):
|
|
|
857
661
|
script_config = {
|
|
858
662
|
"feature": ("init-pipeline.py", "--feature-list", "F-"),
|
|
859
663
|
"bugfix": ("init-bugfix-pipeline.py", "--bug-list", "B-"),
|
|
860
|
-
"refactor": ("init-refactor-pipeline.py", "--refactor-list", "R-"),
|
|
861
664
|
}
|
|
862
665
|
|
|
863
666
|
for kind, (script_name, list_arg, prefix) in script_config.items():
|
|
@@ -910,13 +713,6 @@ def test_planner_validators_reject_unknown_item_fields():
|
|
|
910
713
|
"dev-pipeline-bug-fix-list-v1",
|
|
911
714
|
"B-",
|
|
912
715
|
),
|
|
913
|
-
"refactor": (
|
|
914
|
-
"core/skills/orchestration-skill/pipelines/refactor-planner/scripts/validate-and-generate-refactor.py",
|
|
915
|
-
"validate_refactor_list",
|
|
916
|
-
"refactors",
|
|
917
|
-
"dev-pipeline-refactor-list-v1",
|
|
918
|
-
"R-",
|
|
919
|
-
),
|
|
920
716
|
}
|
|
921
717
|
|
|
922
718
|
for kind, (relative_path, function_name, list_key, schema, prefix) in planner_config.items():
|
|
@@ -981,10 +777,6 @@ def test_planner_validators_reject_unknown_list_fields(location):
|
|
|
981
777
|
"core/skills/orchestration-skill/pipelines/bug-planner/scripts/validate-bug-list.py",
|
|
982
778
|
"validate", "bugs", "dev-pipeline-bug-fix-list-v1", "B-",
|
|
983
779
|
),
|
|
984
|
-
"refactor": (
|
|
985
|
-
"core/skills/orchestration-skill/pipelines/refactor-planner/scripts/validate-and-generate-refactor.py",
|
|
986
|
-
"validate_refactor_list", "refactors", "dev-pipeline-refactor-list-v1", "R-",
|
|
987
|
-
),
|
|
988
780
|
}
|
|
989
781
|
|
|
990
782
|
for kind, (relative_path, function_name, list_key, schema, prefix) in planner_config.items():
|
|
@@ -1049,7 +841,6 @@ def test_bug_planner_validator_rejects_dependency_cycles():
|
|
|
1049
841
|
assert any("Dependency cycle detected" in error for error in result["errors"])
|
|
1050
842
|
|
|
1051
843
|
|
|
1052
|
-
|
|
1053
844
|
def _family_items(kind, entries):
|
|
1054
845
|
items = []
|
|
1055
846
|
for item_id, dependencies, status in entries:
|
|
@@ -1077,19 +868,7 @@ def _family_items(kind, entries):
|
|
|
1077
868
|
"status": status,
|
|
1078
869
|
})
|
|
1079
870
|
else:
|
|
1080
|
-
|
|
1081
|
-
"id": item_id,
|
|
1082
|
-
"title": item_id,
|
|
1083
|
-
"description": "Refactor description",
|
|
1084
|
-
"scope": {},
|
|
1085
|
-
"type": "extract",
|
|
1086
|
-
"priority": "medium",
|
|
1087
|
-
"complexity": "low",
|
|
1088
|
-
"behavior_preservation": {"strategy": "test-gate"},
|
|
1089
|
-
"acceptance_criteria": ["done"],
|
|
1090
|
-
"dependencies": dependencies,
|
|
1091
|
-
"status": status,
|
|
1092
|
-
})
|
|
871
|
+
raise ValueError(f"Unsupported family kind: {kind}")
|
|
1093
872
|
return items
|
|
1094
873
|
|
|
1095
874
|
|
|
@@ -1124,7 +903,7 @@ def test_status_bridge_passes_max_retries_from_invocation_or_environment(monkeyp
|
|
|
1124
903
|
|
|
1125
904
|
@pytest.mark.parametrize(
|
|
1126
905
|
("kind", "item_key"),
|
|
1127
|
-
(("feature", "feature_id"), ("bugfix", "bug_id")
|
|
906
|
+
(("feature", "feature_id"), ("bugfix", "bug_id")),
|
|
1128
907
|
)
|
|
1129
908
|
def test_pipeline_aggregate_reselection_keeps_first_seen_details_and_stops(monkeypatch, tmp_path, kind, item_key):
|
|
1130
909
|
from prizmkit_runtime import runners
|
|
@@ -1156,7 +935,7 @@ def test_pipeline_aggregate_reselection_keeps_first_seen_details_and_stops(monke
|
|
|
1156
935
|
|
|
1157
936
|
@pytest.mark.parametrize(
|
|
1158
937
|
("kind", "item_key"),
|
|
1159
|
-
(("feature", "feature_id"), ("bugfix", "bug_id")
|
|
938
|
+
(("feature", "feature_id"), ("bugfix", "bug_id")),
|
|
1160
939
|
)
|
|
1161
940
|
def test_pipeline_aggregate_keeps_distinct_unresolved_item_blocking(monkeypatch, tmp_path, kind, item_key):
|
|
1162
941
|
from prizmkit_runtime import runners
|
|
@@ -1187,7 +966,7 @@ def test_pipeline_aggregate_keeps_distinct_unresolved_item_blocking(monkeypatch,
|
|
|
1187
966
|
|
|
1188
967
|
@pytest.mark.parametrize(
|
|
1189
968
|
("kind", "item_key"),
|
|
1190
|
-
(("feature", "feature_id"), ("bugfix", "bug_id")
|
|
969
|
+
(("feature", "feature_id"), ("bugfix", "bug_id")),
|
|
1191
970
|
)
|
|
1192
971
|
def test_full_list_stops_after_newly_skipped_item(monkeypatch, tmp_path, kind, item_key):
|
|
1193
972
|
from prizmkit_runtime import runners
|
|
@@ -1226,7 +1005,7 @@ def test_full_list_stops_after_newly_skipped_item(monkeypatch, tmp_path, kind, i
|
|
|
1226
1005
|
|
|
1227
1006
|
@pytest.mark.parametrize(
|
|
1228
1007
|
("kind", "item_key"),
|
|
1229
|
-
(("feature", "feature_id"), ("bugfix", "bug_id")
|
|
1008
|
+
(("feature", "feature_id"), ("bugfix", "bug_id")),
|
|
1230
1009
|
)
|
|
1231
1010
|
def test_full_list_rejects_reselected_processed_item_before_second_launch(monkeypatch, tmp_path, kind, item_key):
|
|
1232
1011
|
from prizmkit_runtime import runners
|
|
@@ -1261,7 +1040,7 @@ def test_full_list_rejects_reselected_processed_item_before_second_launch(monkey
|
|
|
1261
1040
|
assert result.details == ("X-001:completed",)
|
|
1262
1041
|
|
|
1263
1042
|
|
|
1264
|
-
@pytest.mark.parametrize("kind", ("feature", "bugfix"
|
|
1043
|
+
@pytest.mark.parametrize("kind", ("feature", "bugfix"))
|
|
1265
1044
|
def test_pipeline_aggregate_empty_authoritative_completion(monkeypatch, tmp_path, kind):
|
|
1266
1045
|
from prizmkit_runtime import runners
|
|
1267
1046
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
@@ -1300,10 +1079,6 @@ def test_pipeline_aggregate_empty_authoritative_completion(monkeypatch, tmp_path
|
|
|
1300
1079
|
("bugfix", "skipped", False),
|
|
1301
1080
|
("bugfix", "auto_skipped", False),
|
|
1302
1081
|
("bugfix", "split", False),
|
|
1303
|
-
("refactor", "completed", True),
|
|
1304
|
-
("refactor", "skipped", False),
|
|
1305
|
-
("refactor", "auto_skipped", False),
|
|
1306
|
-
("refactor", "split", False),
|
|
1307
1082
|
),
|
|
1308
1083
|
)
|
|
1309
1084
|
def test_pipeline_aggregate_completion_compatible_statuses(monkeypatch, tmp_path, kind, status, expected_completed):
|
|
@@ -1313,7 +1088,7 @@ def test_pipeline_aggregate_completion_compatible_statuses(monkeypatch, tmp_path
|
|
|
1313
1088
|
paths = _make_paths(tmp_path)
|
|
1314
1089
|
family = family_for(kind, paths)
|
|
1315
1090
|
invocation = parse_invocation(family, "run", ())
|
|
1316
|
-
item_key = {"feature": "feature_id", "bugfix": "bug_id"
|
|
1091
|
+
item_key = {"feature": "feature_id", "bugfix": "bug_id"}[kind]
|
|
1317
1092
|
queue = [
|
|
1318
1093
|
SimpleNamespace(ok=True, stdout="", data={item_key: "X-001"}, text=""),
|
|
1319
1094
|
SimpleNamespace(ok=True, stdout="PIPELINE_COMPLETE\n", data=None, text="PIPELINE_COMPLETE"),
|
|
@@ -1335,7 +1110,7 @@ def test_pipeline_aggregate_completion_compatible_statuses(monkeypatch, tmp_path
|
|
|
1335
1110
|
assert result.details == (f"X-001:{status}",)
|
|
1336
1111
|
|
|
1337
1112
|
|
|
1338
|
-
@pytest.mark.parametrize("kind", ("feature", "bugfix"
|
|
1113
|
+
@pytest.mark.parametrize("kind", ("feature", "bugfix"))
|
|
1339
1114
|
def test_run_pipeline_command_omits_empty_last_status_detail(monkeypatch, tmp_path, kind):
|
|
1340
1115
|
from prizmkit_runtime import runners
|
|
1341
1116
|
from prizmkit_runtime.runner_models import PipelineRunResult
|
|
@@ -1344,7 +1119,6 @@ def test_run_pipeline_command_omits_empty_last_status_detail(monkeypatch, tmp_pa
|
|
|
1344
1119
|
plan_path = {
|
|
1345
1120
|
"feature": paths.feature_plan,
|
|
1346
1121
|
"bugfix": paths.bugfix_plan,
|
|
1347
|
-
"refactor": paths.refactor_plan,
|
|
1348
1122
|
}[kind]
|
|
1349
1123
|
plan_path.write_text("{}", encoding="utf-8")
|
|
1350
1124
|
monkeypatch.setattr(
|
|
@@ -1360,7 +1134,7 @@ def test_run_pipeline_command_omits_empty_last_status_detail(monkeypatch, tmp_pa
|
|
|
1360
1134
|
assert result.details == ()
|
|
1361
1135
|
|
|
1362
1136
|
|
|
1363
|
-
@pytest.mark.parametrize("kind", ("feature", "bugfix"
|
|
1137
|
+
@pytest.mark.parametrize("kind", ("feature", "bugfix"))
|
|
1364
1138
|
def test_run_pipeline_command_returns_nonzero_for_terminal_skipped_item(monkeypatch, tmp_path, kind):
|
|
1365
1139
|
from prizmkit_runtime import runners
|
|
1366
1140
|
from prizmkit_runtime.runner_models import PipelineRunResult
|
|
@@ -1369,7 +1143,6 @@ def test_run_pipeline_command_returns_nonzero_for_terminal_skipped_item(monkeypa
|
|
|
1369
1143
|
plan_path = {
|
|
1370
1144
|
"feature": paths.feature_plan,
|
|
1371
1145
|
"bugfix": paths.bugfix_plan,
|
|
1372
|
-
"refactor": paths.refactor_plan,
|
|
1373
1146
|
}[kind]
|
|
1374
1147
|
plan_path.write_text("{}", encoding="utf-8")
|
|
1375
1148
|
monkeypatch.setattr(
|
|
@@ -1562,156 +1335,6 @@ def test_prompt_generation_passes_explicit_execution_root_to_generator(monkeypat
|
|
|
1562
1335
|
assert result.artifact_path == execution_root / ".prizmkit" / "specs" / "001-low"
|
|
1563
1336
|
|
|
1564
1337
|
|
|
1565
|
-
def _install_runner_session_fakes(monkeypatch, runners, *, statuses=("success",), update_status="completed", max_retries=3):
|
|
1566
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult, SessionClassification
|
|
1567
|
-
|
|
1568
|
-
prompt_calls = []
|
|
1569
|
-
launch_cwds = []
|
|
1570
|
-
launch_configs = []
|
|
1571
|
-
updates = []
|
|
1572
|
-
cleanup_calls = []
|
|
1573
|
-
merge_calls = []
|
|
1574
|
-
wip_calls = []
|
|
1575
|
-
restore_calls = []
|
|
1576
|
-
events = []
|
|
1577
|
-
status_queue = list(statuses)
|
|
1578
|
-
|
|
1579
|
-
monkeypatch.setattr(
|
|
1580
|
-
runners,
|
|
1581
|
-
"load_runtime_config",
|
|
1582
|
-
lambda paths: SimpleNamespace(
|
|
1583
|
-
ai_client=SimpleNamespace(command="fake-ai", platform="codebuddy"),
|
|
1584
|
-
model="fallback-model",
|
|
1585
|
-
effort=None,
|
|
1586
|
-
),
|
|
1587
|
-
)
|
|
1588
|
-
monkeypatch.setattr(runners, "detect_stream_json_support", lambda command, platform: SimpleNamespace(enabled=False))
|
|
1589
|
-
monkeypatch.setattr(runners, "start_item", lambda *args, **kwargs: SimpleNamespace(ok=True, text="", data={"new_status": "in_progress"}))
|
|
1590
|
-
monkeypatch.setattr(runners, "commit_preflight_ready_changes", lambda *args, **kwargs: SimpleNamespace(attempted=False, committed=False, ok=True, result=None))
|
|
1591
|
-
monkeypatch.setattr(runners, "commit_pre_branch_bookkeeping", lambda *args, **kwargs: None)
|
|
1592
|
-
monkeypatch.setattr(runners, "commit_final_bookkeeping", lambda *args, **kwargs: None)
|
|
1593
|
-
monkeypatch.setattr(runners, "commit_task_branch_changes", lambda *args, **kwargs: None)
|
|
1594
|
-
monkeypatch.setattr(
|
|
1595
|
-
runners,
|
|
1596
|
-
"finalize_accepted_workspace_commit",
|
|
1597
|
-
lambda *args, **kwargs: SimpleNamespace(
|
|
1598
|
-
status="not_needed",
|
|
1599
|
-
reason="accepted_workspace_clean",
|
|
1600
|
-
committed=False,
|
|
1601
|
-
commit_hash="",
|
|
1602
|
-
),
|
|
1603
|
-
)
|
|
1604
|
-
monkeypatch.setattr(runners, "current_branch", lambda _root: "main")
|
|
1605
|
-
monkeypatch.setattr(runners, "_session_id", lambda item_id: f"{item_id}-session-{len(prompt_calls) + 1}")
|
|
1606
|
-
monkeypatch.setattr(
|
|
1607
|
-
runners,
|
|
1608
|
-
"run_git_command",
|
|
1609
|
-
lambda project_root, args: SimpleNamespace(return_code=0, stdout="base-head\n", stderr="", args=tuple(args)),
|
|
1610
|
-
)
|
|
1611
|
-
|
|
1612
|
-
def fake_generate_prompt(family, invocation, **kwargs):
|
|
1613
|
-
events.append("prompt")
|
|
1614
|
-
prompt_calls.append(kwargs)
|
|
1615
|
-
session_paths = kwargs["session_paths"]
|
|
1616
|
-
execution_root = kwargs.get("execution_root") or kwargs["project_root"]
|
|
1617
|
-
return PromptGenerationResult(
|
|
1618
|
-
output_path=session_paths.prompt_path,
|
|
1619
|
-
model="per-item-model",
|
|
1620
|
-
checkpoint_path=execution_root / ".prizmkit" / "specs" / "001-low" / "workflow-checkpoint.json",
|
|
1621
|
-
artifact_path=execution_root / ".prizmkit" / "specs" / "001-low",
|
|
1622
|
-
raw={},
|
|
1623
|
-
)
|
|
1624
|
-
|
|
1625
|
-
class FakeLauncher:
|
|
1626
|
-
def __init__(self, config):
|
|
1627
|
-
self.config = config
|
|
1628
|
-
|
|
1629
|
-
def run(self):
|
|
1630
|
-
launch_cwds.append(self.config.cwd)
|
|
1631
|
-
launch_configs.append(self.config)
|
|
1632
|
-
return SimpleNamespace(progress_summary=SimpleNamespace(), fatal_error_code="")
|
|
1633
|
-
|
|
1634
|
-
def fake_classify(*args, **kwargs):
|
|
1635
|
-
status = status_queue.pop(0)
|
|
1636
|
-
return SessionClassification(
|
|
1637
|
-
status,
|
|
1638
|
-
reason=status,
|
|
1639
|
-
fatal_error_code="context_overflow" if status == "context_overflow" else "",
|
|
1640
|
-
progress_fingerprint={"head_commit": status},
|
|
1641
|
-
no_progress_count=0,
|
|
1642
|
-
)
|
|
1643
|
-
|
|
1644
|
-
def fake_update(family, invocation, item_id, session_status, session_id, project_root, **metadata):
|
|
1645
|
-
updates.append((session_status, session_id, metadata))
|
|
1646
|
-
normal_retry_count = sum(
|
|
1647
|
-
status in {"context_overflow", "crashed", "timed_out", "failed"}
|
|
1648
|
-
for status, *_ in updates
|
|
1649
|
-
)
|
|
1650
|
-
infra_error_count = sum(status == "infra_error" for status, *_ in updates)
|
|
1651
|
-
current_update_status = update_status
|
|
1652
|
-
if session_status in {"context_overflow", "crashed", "timed_out", "failed"}:
|
|
1653
|
-
if normal_retry_count >= max_retries:
|
|
1654
|
-
current_update_status = "failed"
|
|
1655
|
-
elif len(status_queue) > 0:
|
|
1656
|
-
current_update_status = "in_progress"
|
|
1657
|
-
elif session_status == "infra_error" and len(status_queue) > 0:
|
|
1658
|
-
current_update_status = "in_progress"
|
|
1659
|
-
return SimpleNamespace(
|
|
1660
|
-
ok=True,
|
|
1661
|
-
text="",
|
|
1662
|
-
data={
|
|
1663
|
-
"new_status": current_update_status,
|
|
1664
|
-
"retry_count": normal_retry_count,
|
|
1665
|
-
"infra_error_count": infra_error_count,
|
|
1666
|
-
"continuation_count": len(updates),
|
|
1667
|
-
"context_overflow_count": sum(status == "context_overflow" for status, *_ in updates),
|
|
1668
|
-
},
|
|
1669
|
-
)
|
|
1670
|
-
|
|
1671
|
-
def fake_cleanup(runtime, *, delete_branch=True):
|
|
1672
|
-
cleanup_calls.append((runtime, delete_branch))
|
|
1673
|
-
return SimpleNamespace(ok=True, reason="")
|
|
1674
|
-
|
|
1675
|
-
def fake_merge(runtime, *, auto_push=False):
|
|
1676
|
-
merge_calls.append((runtime, auto_push))
|
|
1677
|
-
return SimpleNamespace(ok=True, reason="", runtime=runtime, results=())
|
|
1678
|
-
|
|
1679
|
-
def fake_save_wip(runtime):
|
|
1680
|
-
wip_calls.append(runtime)
|
|
1681
|
-
return SimpleNamespace(ok=True, plan=None, results=())
|
|
1682
|
-
|
|
1683
|
-
def fake_restore_wip(project_root, **kwargs):
|
|
1684
|
-
events.append("restore")
|
|
1685
|
-
restore_calls.append((project_root, kwargs))
|
|
1686
|
-
return SimpleNamespace(
|
|
1687
|
-
ok=True,
|
|
1688
|
-
restored=False,
|
|
1689
|
-
reason="runtime_wip_not_found",
|
|
1690
|
-
wip_head="",
|
|
1691
|
-
restored_head="",
|
|
1692
|
-
)
|
|
1693
|
-
|
|
1694
|
-
monkeypatch.setattr(runners, "generate_prompt", fake_generate_prompt)
|
|
1695
|
-
monkeypatch.setattr(runners, "AISessionLauncher", FakeLauncher)
|
|
1696
|
-
monkeypatch.setattr(runners, "classify_session", fake_classify)
|
|
1697
|
-
monkeypatch.setattr(runners, "update_item", fake_update)
|
|
1698
|
-
monkeypatch.setattr(runners, "guarded_worktree_remove", fake_cleanup, raising=False)
|
|
1699
|
-
monkeypatch.setattr(runners, "merge_linked_worktree", fake_merge, raising=False)
|
|
1700
|
-
monkeypatch.setattr(runners, "worktree_save_wip", fake_save_wip, raising=False)
|
|
1701
|
-
monkeypatch.setattr(runners, "restore_runtime_wip", fake_restore_wip, raising=False)
|
|
1702
|
-
return SimpleNamespace(
|
|
1703
|
-
prompt_calls=prompt_calls,
|
|
1704
|
-
launch_cwds=launch_cwds,
|
|
1705
|
-
launch_configs=launch_configs,
|
|
1706
|
-
updates=updates,
|
|
1707
|
-
cleanup_calls=cleanup_calls,
|
|
1708
|
-
merge_calls=merge_calls,
|
|
1709
|
-
wip_calls=wip_calls,
|
|
1710
|
-
restore_calls=restore_calls,
|
|
1711
|
-
events=events,
|
|
1712
|
-
)
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
1338
|
def test_runner_does_not_restore_wip_for_first_checkout(monkeypatch, tmp_path):
|
|
1716
1339
|
from prizmkit_runtime import runners
|
|
1717
1340
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
@@ -1771,34 +1394,18 @@ def test_runner_restores_wip_before_prompt_for_reused_branch_checkout(monkeypatc
|
|
|
1771
1394
|
]
|
|
1772
1395
|
|
|
1773
1396
|
|
|
1774
|
-
def
|
|
1397
|
+
def test_runner_restores_wip_before_prompt_for_reused_branch_checkout(monkeypatch, tmp_path):
|
|
1775
1398
|
from prizmkit_runtime import runners
|
|
1776
|
-
from prizmkit_runtime.gitops import (
|
|
1777
|
-
BranchContext,
|
|
1778
|
-
WorktreePolicy,
|
|
1779
|
-
worktree_runtime_context,
|
|
1780
|
-
)
|
|
1781
1399
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1782
1400
|
from prizmkit_runtime.task_checkout import (
|
|
1783
|
-
|
|
1401
|
+
CHECKOUT_MODE_BRANCH,
|
|
1784
1402
|
TaskCheckout,
|
|
1785
1403
|
persist_task_checkout,
|
|
1786
1404
|
)
|
|
1787
1405
|
|
|
1788
|
-
|
|
1789
|
-
paths = _make_paths(tmp_path / "reused-worktree-wip-restore")
|
|
1406
|
+
paths = _make_paths(tmp_path / "reused-branch-wip-restore")
|
|
1790
1407
|
family = family_for("feature", paths)
|
|
1791
1408
|
branch = "dev/feature/F-001-preserved"
|
|
1792
|
-
expected_runtime = worktree_runtime_context(
|
|
1793
|
-
BranchContext("main", branch, paths.project_root),
|
|
1794
|
-
WorktreePolicy(
|
|
1795
|
-
use_worktree=True,
|
|
1796
|
-
cleanup_on_success=True,
|
|
1797
|
-
preserve_on_failure=True,
|
|
1798
|
-
worktree_root=paths.state_dir / "worktrees",
|
|
1799
|
-
),
|
|
1800
|
-
)
|
|
1801
|
-
worktree_path = expected_runtime.worktree_path
|
|
1802
1409
|
persist_task_checkout(
|
|
1803
1410
|
family.state_dir,
|
|
1804
1411
|
TaskCheckout.active(
|
|
@@ -1806,30 +1413,23 @@ def test_runner_restores_wip_before_prompt_for_reused_worktree_checkout(monkeypa
|
|
|
1806
1413
|
"F-001",
|
|
1807
1414
|
branch,
|
|
1808
1415
|
"main",
|
|
1809
|
-
checkout_mode=
|
|
1810
|
-
worktree_path=str(worktree_path),
|
|
1416
|
+
checkout_mode=CHECKOUT_MODE_BRANCH,
|
|
1811
1417
|
),
|
|
1812
1418
|
)
|
|
1813
1419
|
invocation = parse_invocation(family, "run", ())
|
|
1814
1420
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1815
1421
|
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1816
|
-
|
|
1817
|
-
def fake_setup(runtime):
|
|
1818
|
-
runtime.worktree_path.mkdir(parents=True, exist_ok=True)
|
|
1819
|
-
return SimpleNamespace(ok=True, runtime=runtime, reason="")
|
|
1820
|
-
|
|
1821
|
-
monkeypatch.setattr(runners, "ensure_linked_worktree", fake_setup)
|
|
1822
1422
|
monkeypatch.setattr(
|
|
1823
1423
|
runners,
|
|
1824
|
-
"
|
|
1825
|
-
lambda
|
|
1424
|
+
"run_git_plan",
|
|
1425
|
+
lambda project_root, plan: SimpleNamespace(ok=True, plan=plan, results=()),
|
|
1826
1426
|
)
|
|
1827
1427
|
|
|
1828
1428
|
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1829
1429
|
|
|
1830
1430
|
assert status == "completed"
|
|
1831
1431
|
assert observed.events == ["restore", "prompt"]
|
|
1832
|
-
assert observed.restore_calls[0][0] ==
|
|
1432
|
+
assert observed.restore_calls[0][0] == paths.project_root.resolve()
|
|
1833
1433
|
assert observed.restore_calls[0][1] == {
|
|
1834
1434
|
"family_kind": "feature",
|
|
1835
1435
|
"item_id": "F-001",
|
|
@@ -2036,9 +1636,9 @@ def test_workflow_skipped_is_finalized_as_completed_with_one_warning(monkeypatch
|
|
|
2036
1636
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2037
1637
|
|
|
2038
1638
|
paths = _make_paths(tmp_path / "accepted-workflow-skip")
|
|
2039
|
-
family = family_for("
|
|
1639
|
+
family = family_for("feature", paths)
|
|
2040
1640
|
invocation = parse_invocation(family, "run", ())
|
|
2041
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.
|
|
1641
|
+
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2042
1642
|
observed = _install_runner_session_fakes(
|
|
2043
1643
|
monkeypatch,
|
|
2044
1644
|
runners,
|
|
@@ -2070,7 +1670,7 @@ def test_workflow_skipped_is_finalized_as_completed_with_one_warning(monkeypatch
|
|
|
2070
1670
|
lambda *args, **kwargs: (wip_calls.append((args, kwargs)) or SimpleNamespace(ok=True)),
|
|
2071
1671
|
)
|
|
2072
1672
|
|
|
2073
|
-
status = runners._process_item(family, invocation, "
|
|
1673
|
+
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2074
1674
|
captured = capsys.readouterr()
|
|
2075
1675
|
|
|
2076
1676
|
assert status == "completed"
|
|
@@ -2082,16 +1682,16 @@ def test_workflow_skipped_is_finalized_as_completed_with_one_warning(monkeypatch
|
|
|
2082
1682
|
assert accepted_kwargs["base_head"] == "base-head"
|
|
2083
1683
|
assert accepted_kwargs["artifact_dir"] == paths.project_root / ".prizmkit" / "specs" / "001-low"
|
|
2084
1684
|
assert accepted_kwargs["checkpoint_path"] == accepted_kwargs["artifact_dir"] / "workflow-checkpoint.json"
|
|
2085
|
-
assert "
|
|
1685
|
+
assert "F-001" in accepted_kwargs["commit_message"]
|
|
2086
1686
|
assert observed.updates[0][0] == "success"
|
|
2087
1687
|
assert "classification_reason" not in observed.updates[0][2]
|
|
2088
1688
|
assert "accept_workflow_skipped" not in observed.updates[0][2]
|
|
2089
1689
|
session_status = json.loads(
|
|
2090
1690
|
(
|
|
2091
|
-
paths.
|
|
2092
|
-
/ "
|
|
1691
|
+
paths.feature_state_dir
|
|
1692
|
+
/ "F-001"
|
|
2093
1693
|
/ "sessions"
|
|
2094
|
-
/ "
|
|
1694
|
+
/ "F-001-session-1"
|
|
2095
1695
|
/ "session-status.json"
|
|
2096
1696
|
).read_text(encoding="utf-8")
|
|
2097
1697
|
)
|
|
@@ -2102,13 +1702,12 @@ def test_workflow_skipped_is_finalized_as_completed_with_one_warning(monkeypatch
|
|
|
2102
1702
|
assert "Reason: workflow_skipped" in captured.err
|
|
2103
1703
|
|
|
2104
1704
|
|
|
2105
|
-
def
|
|
1705
|
+
def test_workflow_skipped_uses_successful_branch_merge_path(monkeypatch, tmp_path, capsys):
|
|
2106
1706
|
from prizmkit_runtime import runners
|
|
2107
1707
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2108
1708
|
|
|
2109
|
-
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
2110
1709
|
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-accepted")
|
|
2111
|
-
paths = _make_paths(tmp_path / "accepted-
|
|
1710
|
+
paths = _make_paths(tmp_path / "accepted-branch-skip")
|
|
2112
1711
|
family = family_for("feature", paths)
|
|
2113
1712
|
invocation = parse_invocation(family, "run", ())
|
|
2114
1713
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
@@ -2118,16 +1717,18 @@ def test_workflow_skipped_uses_successful_worktree_merge_path(monkeypatch, tmp_p
|
|
|
2118
1717
|
statuses=("workflow_skipped",),
|
|
2119
1718
|
update_status="completed",
|
|
2120
1719
|
)
|
|
1720
|
+
plan_names = []
|
|
1721
|
+
wip_calls = []
|
|
2121
1722
|
|
|
2122
|
-
def
|
|
2123
|
-
|
|
2124
|
-
return SimpleNamespace(ok=True,
|
|
1723
|
+
def fake_run_git_plan(project_root, plan):
|
|
1724
|
+
plan_names.append(plan.name)
|
|
1725
|
+
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
2125
1726
|
|
|
2126
|
-
monkeypatch.setattr(runners, "
|
|
1727
|
+
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
2127
1728
|
monkeypatch.setattr(
|
|
2128
1729
|
runners,
|
|
2129
|
-
"
|
|
2130
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True
|
|
1730
|
+
"commit_wip_changes",
|
|
1731
|
+
lambda *args, **kwargs: wip_calls.append(args) or SimpleNamespace(ok=True),
|
|
2131
1732
|
)
|
|
2132
1733
|
|
|
2133
1734
|
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
@@ -2135,8 +1736,8 @@ def test_workflow_skipped_uses_successful_worktree_merge_path(monkeypatch, tmp_p
|
|
|
2135
1736
|
|
|
2136
1737
|
assert status == "completed"
|
|
2137
1738
|
assert observed.updates[0][0] == "success"
|
|
2138
|
-
assert
|
|
2139
|
-
assert
|
|
1739
|
+
assert "branch_merge" in plan_names
|
|
1740
|
+
assert wip_calls == []
|
|
2140
1741
|
assert captured.err.count("[WARN]") == 1
|
|
2141
1742
|
assert captured.err.count("accepted with incomplete workflow evidence") == 1
|
|
2142
1743
|
|
|
@@ -2146,9 +1747,9 @@ def test_workflow_skipped_safety_failure_stays_hard_without_acceptance_warning(m
|
|
|
2146
1747
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2147
1748
|
|
|
2148
1749
|
paths = _make_paths(tmp_path / "rejected-workflow-skip")
|
|
2149
|
-
family = family_for("
|
|
1750
|
+
family = family_for("feature", paths)
|
|
2150
1751
|
invocation = parse_invocation(family, "run", ())
|
|
2151
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.
|
|
1752
|
+
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2152
1753
|
observed = _install_runner_session_fakes(
|
|
2153
1754
|
monkeypatch,
|
|
2154
1755
|
runners,
|
|
@@ -2184,7 +1785,7 @@ def test_workflow_skipped_safety_failure_stays_hard_without_acceptance_warning(m
|
|
|
2184
1785
|
lambda *args, **kwargs: SimpleNamespace(ok=True),
|
|
2185
1786
|
)
|
|
2186
1787
|
|
|
2187
|
-
status = runners._process_item(family, invocation, "
|
|
1788
|
+
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2188
1789
|
captured = capsys.readouterr()
|
|
2189
1790
|
|
|
2190
1791
|
assert status == "pending"
|
|
@@ -2224,7 +1825,7 @@ def test_runner_launch_config_preserves_artifact_paths_live_output_and_split_thr
|
|
|
2224
1825
|
|
|
2225
1826
|
|
|
2226
1827
|
@pytest.mark.parametrize(("kind", "item_id", "branch"), [("feature", "F-001", "dev/F-001-test"), ("bugfix", "B-001", "bugfix/B-001-test")])
|
|
2227
|
-
def
|
|
1828
|
+
def test_feature_and_bugfix_branch_checkout_launches_from_project_root_even_with_legacy_env(monkeypatch, tmp_path, kind, item_id, branch):
|
|
2228
1829
|
from prizmkit_runtime import runners
|
|
2229
1830
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2230
1831
|
|
|
@@ -2235,246 +1836,158 @@ def test_feature_and_bugfix_explicit_worktree_launches_from_worktree_and_renders
|
|
|
2235
1836
|
invocation = parse_invocation(family, "run", ())
|
|
2236
1837
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan if kind == "feature" else paths.bugfix_plan})
|
|
2237
1838
|
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
2238
|
-
setup_calls = []
|
|
2239
1839
|
lifecycle_order = []
|
|
2240
1840
|
|
|
2241
|
-
def
|
|
2242
|
-
lifecycle_order.append(
|
|
2243
|
-
|
|
2244
|
-
runtime.worktree_path.mkdir(parents=True, exist_ok=True)
|
|
2245
|
-
return SimpleNamespace(ok=True, runtime=runtime, reason="")
|
|
1841
|
+
def fake_run_git_plan(project_root, plan):
|
|
1842
|
+
lifecycle_order.append(plan.name)
|
|
1843
|
+
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
2246
1844
|
|
|
2247
1845
|
def fake_preflight(*args, **kwargs):
|
|
2248
1846
|
lifecycle_order.append("preflight")
|
|
2249
1847
|
return SimpleNamespace(attempted=False, committed=False, ok=True, result=None)
|
|
2250
1848
|
|
|
2251
1849
|
monkeypatch.setattr(runners, "commit_preflight_ready_changes", fake_preflight)
|
|
2252
|
-
monkeypatch.setattr(runners, "
|
|
1850
|
+
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
2253
1851
|
|
|
2254
1852
|
status = runners._process_item(family, invocation, item_id, paths, initial_metadata={})
|
|
2255
1853
|
|
|
2256
|
-
expected_worktree = paths.state_dir / "worktrees" / branch.replace("/", "-")
|
|
2257
1854
|
assert status == "completed"
|
|
2258
|
-
assert lifecycle_order[:2] == ["preflight", "
|
|
2259
|
-
assert
|
|
2260
|
-
assert observed.launch_cwds == [expected_worktree.resolve()]
|
|
1855
|
+
assert lifecycle_order[:2] == ["preflight", "branch_create"]
|
|
1856
|
+
assert observed.launch_cwds == [paths.project_root]
|
|
2261
1857
|
assert observed.prompt_calls[0]["project_root"] == paths.project_root
|
|
2262
|
-
assert observed.prompt_calls[0]["execution_root"] ==
|
|
1858
|
+
assert observed.prompt_calls[0]["execution_root"] == paths.project_root
|
|
1859
|
+
checkout = json.loads((family.state_dir / item_id / "checkout.json").read_text(encoding="utf-8"))
|
|
1860
|
+
assert checkout["checkout_mode"] == "branch"
|
|
2263
1861
|
|
|
2264
1862
|
|
|
2265
|
-
def
|
|
1863
|
+
def test_legacy_worktree_checkout_identity_fails_fast_before_launch(monkeypatch, tmp_path):
|
|
2266
1864
|
from prizmkit_runtime import runners
|
|
2267
1865
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2268
|
-
from prizmkit_runtime.task_checkout import
|
|
1866
|
+
from prizmkit_runtime.task_checkout import TaskCheckoutError, task_checkout_path
|
|
2269
1867
|
|
|
2270
1868
|
paths = _make_paths(tmp_path)
|
|
2271
1869
|
family = family_for("feature", paths)
|
|
2272
1870
|
invocation = parse_invocation(family, "run", ())
|
|
2273
1871
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
1872
|
+
legacy_path = task_checkout_path(family.state_dir, "F-001")
|
|
1873
|
+
legacy_path.parent.mkdir(parents=True, exist_ok=True)
|
|
1874
|
+
legacy_path.write_text(
|
|
1875
|
+
json.dumps(
|
|
1876
|
+
{
|
|
1877
|
+
"task_type": "feature",
|
|
1878
|
+
"task_id": "F-001",
|
|
1879
|
+
"state": "active",
|
|
1880
|
+
"active_dev_branch": "dev/F-001-worktree-resume",
|
|
1881
|
+
"base_branch": "main",
|
|
1882
|
+
"checkout_mode": "worktree",
|
|
1883
|
+
"worktree_path": str((paths.state_dir / "worktrees" / "dev-F-001-worktree-resume").resolve()),
|
|
1884
|
+
}
|
|
2285
1885
|
),
|
|
1886
|
+
encoding="utf-8",
|
|
2286
1887
|
)
|
|
2287
1888
|
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
2288
|
-
setup_calls = []
|
|
2289
|
-
|
|
2290
|
-
def fake_setup(runtime):
|
|
2291
|
-
setup_calls.append(runtime)
|
|
2292
|
-
runtime.worktree_path.mkdir(parents=True, exist_ok=True)
|
|
2293
|
-
return SimpleNamespace(ok=True, runtime=runtime, reason="")
|
|
2294
|
-
|
|
2295
1889
|
monkeypatch.delenv("USE_WORKTREE", raising=False)
|
|
2296
1890
|
monkeypatch.delenv("DEV_BRANCH", raising=False)
|
|
2297
|
-
monkeypatch.setattr(runners, "ensure_linked_worktree", fake_setup)
|
|
2298
1891
|
|
|
2299
|
-
|
|
1892
|
+
with pytest.raises(TaskCheckoutError, match="retired worktree checkout mode"):
|
|
1893
|
+
runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2300
1894
|
|
|
2301
|
-
assert
|
|
2302
|
-
assert setup_calls[0].worktree_path == worktree_path
|
|
2303
|
-
assert observed.launch_cwds == [worktree_path]
|
|
1895
|
+
assert observed.launch_cwds == []
|
|
2304
1896
|
|
|
2305
1897
|
|
|
2306
|
-
def
|
|
1898
|
+
def test_successful_branch_session_merges_and_honors_auto_push(monkeypatch, tmp_path):
|
|
2307
1899
|
from prizmkit_runtime import runners
|
|
2308
1900
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2309
1901
|
|
|
2310
|
-
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
2311
1902
|
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-test")
|
|
2312
1903
|
monkeypatch.setenv("AUTO_PUSH", "1")
|
|
2313
1904
|
paths = _make_paths(tmp_path)
|
|
2314
1905
|
family = family_for("feature", paths)
|
|
2315
1906
|
invocation = parse_invocation(family, "run", ())
|
|
2316
1907
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2317
|
-
|
|
2318
|
-
|
|
1908
|
+
_install_runner_session_fakes(monkeypatch, runners)
|
|
1909
|
+
plans = []
|
|
1910
|
+
monkeypatch.setattr(
|
|
1911
|
+
runners,
|
|
1912
|
+
"run_git_plan",
|
|
1913
|
+
lambda project_root, plan: plans.append(plan) or SimpleNamespace(ok=True, plan=plan, results=()),
|
|
1914
|
+
)
|
|
2319
1915
|
|
|
2320
1916
|
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2321
1917
|
|
|
2322
1918
|
assert status == "completed"
|
|
2323
|
-
|
|
2324
|
-
assert
|
|
1919
|
+
merge_plans = [plan for plan in plans if plan.name == "branch_merge"]
|
|
1920
|
+
assert merge_plans
|
|
1921
|
+
assert any(command.args == ("push",) for command in merge_plans[-1].commands)
|
|
2325
1922
|
checkout = json.loads((paths.feature_state_dir / "F-001" / "checkout.json").read_text(encoding="utf-8"))
|
|
2326
1923
|
assert checkout["state"] == "completed"
|
|
1924
|
+
assert checkout["checkout_mode"] == "branch"
|
|
2327
1925
|
assert checkout["active_dev_branch"] == "dev/F-001-test"
|
|
2328
1926
|
|
|
2329
1927
|
|
|
2330
|
-
def
|
|
1928
|
+
def test_branch_merge_conflict_writes_session_status_and_updates_merge_conflict(monkeypatch, tmp_path):
|
|
2331
1929
|
from prizmkit_runtime import runners
|
|
2332
1930
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2333
1931
|
|
|
2334
|
-
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
2335
1932
|
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-test")
|
|
2336
1933
|
paths = _make_paths(tmp_path)
|
|
2337
1934
|
family = family_for("feature", paths)
|
|
2338
1935
|
invocation = parse_invocation(family, "run", ())
|
|
2339
1936
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2340
1937
|
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
2341
|
-
|
|
2342
|
-
|
|
1938
|
+
|
|
1939
|
+
def fake_run_git_plan(project_root, plan):
|
|
1940
|
+
if plan.name == "branch_merge":
|
|
1941
|
+
return SimpleNamespace(ok=False, plan=plan, results=())
|
|
1942
|
+
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
1943
|
+
|
|
1944
|
+
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
1945
|
+
monkeypatch.setattr(runners, "commit_wip_changes", lambda *args, **kwargs: SimpleNamespace(ok=True))
|
|
1946
|
+
monkeypatch.setattr(runners, "branch_ensure_return", lambda *args, **kwargs: SimpleNamespace(ok=True))
|
|
2343
1947
|
|
|
2344
1948
|
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2345
1949
|
|
|
2346
1950
|
assert status == "completed"
|
|
2347
1951
|
assert observed.updates[-1][0] == "merge_conflict"
|
|
2348
|
-
assert observed.cleanup_calls == []
|
|
2349
1952
|
checkout = json.loads((paths.feature_state_dir / "F-001" / "checkout.json").read_text(encoding="utf-8"))
|
|
2350
1953
|
assert checkout["state"] == "active"
|
|
2351
|
-
assert checkout["checkout_mode"] == "
|
|
1954
|
+
assert checkout["checkout_mode"] == "branch"
|
|
2352
1955
|
session_status = json.loads((paths.feature_state_dir / "F-001" / "sessions" / "F-001-session-1" / "session-status.json").read_text(encoding="utf-8"))
|
|
2353
1956
|
assert session_status["status"] == "merge_conflict"
|
|
2354
1957
|
assert session_status["task_id"] == "F-001"
|
|
2355
1958
|
assert session_status["task_type"] == "feature"
|
|
2356
1959
|
assert session_status["base_branch"] == "main"
|
|
2357
1960
|
assert session_status["active_dev_branch"] == "dev/F-001-test"
|
|
2358
|
-
assert
|
|
1961
|
+
assert "worktree_path" not in session_status
|
|
2359
1962
|
|
|
2360
1963
|
|
|
2361
|
-
def
|
|
1964
|
+
def test_terminal_branch_failure_saves_wip_and_preserves_checkout(monkeypatch, tmp_path):
|
|
2362
1965
|
from prizmkit_runtime import runners
|
|
2363
1966
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2364
1967
|
|
|
2365
|
-
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
2366
1968
|
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-test")
|
|
2367
1969
|
paths = _make_paths(tmp_path)
|
|
2368
1970
|
family = family_for("feature", paths)
|
|
2369
1971
|
invocation = parse_invocation(family, "run", ())
|
|
2370
1972
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2371
1973
|
observed = _install_runner_session_fakes(monkeypatch, runners, statuses=("crashed",), update_status="failed")
|
|
2372
|
-
|
|
1974
|
+
wip_calls = []
|
|
1975
|
+
return_calls = []
|
|
1976
|
+
monkeypatch.setattr(runners, "run_git_plan", lambda project_root, plan: SimpleNamespace(ok=True, plan=plan, results=()))
|
|
1977
|
+
monkeypatch.setattr(runners, "commit_wip_changes", lambda *args, **kwargs: wip_calls.append(args) or SimpleNamespace(ok=True))
|
|
1978
|
+
monkeypatch.setattr(runners, "branch_ensure_return", lambda *args, **kwargs: return_calls.append(args) or SimpleNamespace(ok=True))
|
|
2373
1979
|
|
|
2374
1980
|
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2375
1981
|
|
|
2376
1982
|
assert status == "failed"
|
|
2377
|
-
assert
|
|
2378
|
-
assert
|
|
1983
|
+
assert wip_calls
|
|
1984
|
+
assert return_calls == [(paths.project_root, "main", "dev/F-001-test")]
|
|
2379
1985
|
checkout = json.loads((paths.feature_state_dir / "F-001" / "checkout.json").read_text(encoding="utf-8"))
|
|
2380
1986
|
assert checkout["state"] == "active"
|
|
2381
|
-
assert checkout["checkout_mode"] == "
|
|
1987
|
+
assert checkout["checkout_mode"] == "branch"
|
|
2382
1988
|
assert observed.updates[-1][0] == "crashed"
|
|
2383
1989
|
|
|
2384
1990
|
|
|
2385
|
-
def test_explicit_worktree_materializes_ignored_support_assets_before_prompt_and_launch(monkeypatch, tmp_path):
|
|
2386
|
-
from prizmkit_runtime import runners
|
|
2387
|
-
from prizmkit_runtime.paths import resolve_runtime_paths
|
|
2388
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult, SessionClassification, family_for, parse_invocation
|
|
2389
|
-
|
|
2390
|
-
project = tmp_path / "repo"
|
|
2391
|
-
project.mkdir()
|
|
2392
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=project, check=True, stdout=subprocess.DEVNULL)
|
|
2393
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=project, check=True)
|
|
2394
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=project, check=True)
|
|
2395
|
-
(project / ".gitignore").write_text(".claude/\n.prizmkit/\n", encoding="utf-8")
|
|
2396
|
-
(project / "tracked.txt").write_text("tracked\n", encoding="utf-8")
|
|
2397
|
-
subprocess.run(["git", "add", ".gitignore", "tracked.txt"], cwd=project, check=True)
|
|
2398
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=project, check=True, stdout=subprocess.DEVNULL)
|
|
2399
|
-
|
|
2400
|
-
(project / ".claude" / "commands").mkdir(parents=True)
|
|
2401
|
-
(project / ".claude" / "commands" / "prizmkit.md").write_text("skill", encoding="utf-8")
|
|
2402
|
-
(project / ".prizmkit" / "prizm-docs").mkdir(parents=True)
|
|
2403
|
-
(project / ".prizmkit" / "prizm-docs" / "root.prizm").write_text("PRIZM_VERSION: 1\n", encoding="utf-8")
|
|
2404
|
-
(project / ".prizmkit" / "dev-pipeline" / "scripts").mkdir(parents=True)
|
|
2405
|
-
(project / ".prizmkit" / "dev-pipeline" / "scripts" / "init-change-artifact.py").write_text("# init", encoding="utf-8")
|
|
2406
|
-
(project / ".prizmkit" / "config.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
|
|
2407
|
-
(project / ".prizmkit" / "manifest.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
|
|
2408
|
-
|
|
2409
|
-
paths = resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=project)
|
|
2410
|
-
family = family_for("feature", paths)
|
|
2411
|
-
invocation = parse_invocation(family, "run", ())
|
|
2412
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2413
|
-
launch_cwds = []
|
|
2414
|
-
|
|
2415
|
-
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
2416
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-support-assets")
|
|
2417
|
-
monkeypatch.setattr(
|
|
2418
|
-
runners,
|
|
2419
|
-
"load_runtime_config",
|
|
2420
|
-
lambda paths: SimpleNamespace(
|
|
2421
|
-
ai_client=SimpleNamespace(command="fake-ai", platform="codebuddy"),
|
|
2422
|
-
model="fallback-model",
|
|
2423
|
-
effort=None,
|
|
2424
|
-
),
|
|
2425
|
-
)
|
|
2426
|
-
monkeypatch.setattr(runners, "detect_stream_json_support", lambda command, platform: SimpleNamespace(enabled=False))
|
|
2427
|
-
monkeypatch.setattr(runners, "start_item", lambda *args, **kwargs: SimpleNamespace(ok=True, text="", data={"new_status": "in_progress"}))
|
|
2428
|
-
monkeypatch.setattr(runners, "commit_preflight_ready_changes", lambda *args, **kwargs: SimpleNamespace(attempted=False, committed=False, ok=True, result=None))
|
|
2429
|
-
monkeypatch.setattr(runners, "commit_pre_branch_bookkeeping", lambda *args, **kwargs: None)
|
|
2430
|
-
monkeypatch.setattr(runners, "commit_final_bookkeeping", lambda *args, **kwargs: None)
|
|
2431
|
-
monkeypatch.setattr(runners, "_session_id", lambda item_id: f"{item_id}-session")
|
|
2432
|
-
monkeypatch.setattr(runners, "update_item", lambda *args, **kwargs: SimpleNamespace(ok=True, text="", data={"new_status": "completed"}))
|
|
2433
|
-
|
|
2434
|
-
def fake_generate_prompt(family, invocation, **kwargs):
|
|
2435
|
-
execution_root = kwargs["execution_root"]
|
|
2436
|
-
assert execution_root != project
|
|
2437
|
-
assert (execution_root / ".claude" / "commands" / "prizmkit.md").is_file()
|
|
2438
|
-
assert (execution_root / ".prizmkit" / "prizm-docs" / "root.prizm").is_file()
|
|
2439
|
-
assert (execution_root / ".prizmkit" / "config.json").is_file()
|
|
2440
|
-
assert (execution_root / ".prizmkit" / "manifest.json").is_file()
|
|
2441
|
-
assert (execution_root / ".prizmkit" / "dev-pipeline" / "scripts" / "init-change-artifact.py").is_file()
|
|
2442
|
-
assert not (execution_root / ".prizmkit" / "dev-pipeline" / "run-feature.sh").exists()
|
|
2443
|
-
session_paths = kwargs["session_paths"]
|
|
2444
|
-
return PromptGenerationResult(
|
|
2445
|
-
output_path=session_paths.prompt_path,
|
|
2446
|
-
model="",
|
|
2447
|
-
checkpoint_path=execution_root / ".prizmkit" / "specs" / "001-support" / "workflow-checkpoint.json",
|
|
2448
|
-
artifact_path=execution_root / ".prizmkit" / "specs" / "001-support",
|
|
2449
|
-
raw={},
|
|
2450
|
-
)
|
|
2451
|
-
|
|
2452
|
-
class FakeLauncher:
|
|
2453
|
-
def __init__(self, config):
|
|
2454
|
-
self.config = config
|
|
2455
|
-
|
|
2456
|
-
def run(self):
|
|
2457
|
-
launch_cwds.append(self.config.cwd)
|
|
2458
|
-
return SimpleNamespace(progress_summary=SimpleNamespace(), fatal_error_code="")
|
|
2459
|
-
|
|
2460
|
-
monkeypatch.setattr(runners, "generate_prompt", fake_generate_prompt)
|
|
2461
|
-
monkeypatch.setattr(runners, "AISessionLauncher", FakeLauncher)
|
|
2462
|
-
monkeypatch.setattr(
|
|
2463
|
-
runners,
|
|
2464
|
-
"classify_session",
|
|
2465
|
-
lambda *args, **kwargs: SessionClassification(
|
|
2466
|
-
"success", reason="success", fatal_error_code="",
|
|
2467
|
-
progress_fingerprint={"head_commit": "success"}, no_progress_count=0,
|
|
2468
|
-
),
|
|
2469
|
-
)
|
|
2470
|
-
|
|
2471
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2472
|
-
|
|
2473
|
-
assert status == "completed"
|
|
2474
|
-
assert launch_cwds and launch_cwds[0] == paths.state_dir / "worktrees" / "dev-F-001-support-assets"
|
|
2475
|
-
assert not launch_cwds[0].exists()
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
1991
|
def test_default_no_worktree_preserves_main_worktree_branch_launch(monkeypatch, tmp_path):
|
|
2479
1992
|
from prizmkit_runtime import runners
|
|
2480
1993
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
@@ -2626,72 +2139,12 @@ def test_no_worktree_recovers_completed_pending_branch_before_new_session(monkey
|
|
|
2626
2139
|
assert "branch_merge" in events
|
|
2627
2140
|
|
|
2628
2141
|
|
|
2629
|
-
def
|
|
2142
|
+
def test_success_final_commit_failure_preserves_checkout_without_merge(monkeypatch, tmp_path):
|
|
2630
2143
|
from prizmkit_runtime import runners
|
|
2631
2144
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2145
|
+
from prizmkit_runtime.task_checkout import load_task_checkout
|
|
2632
2146
|
|
|
2633
|
-
monkeypatch.setenv("
|
|
2634
|
-
paths = _make_paths(tmp_path)
|
|
2635
|
-
family = family_for("feature", paths)
|
|
2636
|
-
invocation = parse_invocation(family, "run", ())
|
|
2637
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2638
|
-
base_session_dir = paths.feature_state_dir / "F-001" / "sessions" / "F-001-session-old"
|
|
2639
|
-
base_session_dir.mkdir(parents=True)
|
|
2640
|
-
(base_session_dir / "session-status.json").write_text(
|
|
2641
|
-
json.dumps({"base_branch": "main", "active_dev_branch": "dev/F-001-worktree"}),
|
|
2642
|
-
encoding="utf-8",
|
|
2643
|
-
)
|
|
2644
|
-
updates = []
|
|
2645
|
-
cleanup_calls = []
|
|
2646
|
-
merge_calls = []
|
|
2647
|
-
|
|
2648
|
-
monkeypatch.setattr(
|
|
2649
|
-
runners,
|
|
2650
|
-
"load_runtime_config",
|
|
2651
|
-
lambda paths: SimpleNamespace(ai_client=SimpleNamespace(command="fake-ai", platform="codebuddy"), model="", effort=None),
|
|
2652
|
-
)
|
|
2653
|
-
monkeypatch.setattr(runners, "current_branch", lambda _root: "main")
|
|
2654
|
-
monkeypatch.setattr(runners, "ensure_linked_worktree", lambda runtime: SimpleNamespace(ok=True, runtime=runtime, reason=""), raising=False)
|
|
2655
|
-
monkeypatch.setattr(runners, "materialize_worktree_support_assets", lambda runtime: SimpleNamespace(ok=True, reason=""), raising=False)
|
|
2656
|
-
monkeypatch.setattr(runners, "has_completed_artifact_path", lambda artifact: True)
|
|
2657
|
-
monkeypatch.setattr(runners, "has_branch_completion_evidence", lambda *args, **kwargs: True)
|
|
2658
|
-
monkeypatch.setattr(runners, "start_item", lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("should not restart completed work")))
|
|
2659
|
-
monkeypatch.setattr(runners, "generate_prompt", lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("should not launch prompt")))
|
|
2660
|
-
monkeypatch.setattr(runners, "commit_final_bookkeeping", lambda *args, **kwargs: None)
|
|
2661
|
-
monkeypatch.setattr(runners, "commit_task_branch_changes", lambda *args, **kwargs: None)
|
|
2662
|
-
monkeypatch.setattr(runners, "commit_preflight_ready_changes", lambda *args, **kwargs: SimpleNamespace(attempted=False, committed=False, ok=True, result=None))
|
|
2663
|
-
|
|
2664
|
-
def fake_update(family, invocation, item_id, session_status, session_id, project_root, **metadata):
|
|
2665
|
-
updates.append((session_status, session_id, project_root, metadata))
|
|
2666
|
-
return SimpleNamespace(ok=True, text="", data={"new_status": "completed"})
|
|
2667
|
-
|
|
2668
|
-
def fake_merge(runtime, *, auto_push=False):
|
|
2669
|
-
merge_calls.append((runtime, auto_push))
|
|
2670
|
-
return SimpleNamespace(ok=True, reason="", runtime=runtime, results=())
|
|
2671
|
-
|
|
2672
|
-
def fake_cleanup(runtime, *, delete_branch=True):
|
|
2673
|
-
cleanup_calls.append((runtime, delete_branch))
|
|
2674
|
-
return SimpleNamespace(ok=True, reason="")
|
|
2675
|
-
|
|
2676
|
-
monkeypatch.setattr(runners, "update_item", fake_update)
|
|
2677
|
-
monkeypatch.setattr(runners, "merge_linked_worktree", fake_merge, raising=False)
|
|
2678
|
-
monkeypatch.setattr(runners, "guarded_worktree_remove", fake_cleanup, raising=False)
|
|
2679
|
-
|
|
2680
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={"title": "Low"})
|
|
2681
|
-
|
|
2682
|
-
assert status == "completed"
|
|
2683
|
-
assert updates[0][0] == "success"
|
|
2684
|
-
assert updates[0][1] == "F-001-session-old"
|
|
2685
|
-
assert updates[0][2] != paths.project_root
|
|
2686
|
-
assert merge_calls and cleanup_calls[-1][1] is True
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
def test_success_final_commit_failure_preserves_checkout_without_merge(monkeypatch, tmp_path):
|
|
2690
|
-
from prizmkit_runtime import runners
|
|
2691
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2692
|
-
from prizmkit_runtime.task_checkout import load_task_checkout
|
|
2693
|
-
|
|
2694
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-finalize-fail")
|
|
2147
|
+
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-finalize-fail")
|
|
2695
2148
|
paths = _make_paths(tmp_path)
|
|
2696
2149
|
family = family_for("feature", paths)
|
|
2697
2150
|
invocation = parse_invocation(family, "run", ())
|
|
@@ -2768,7 +2221,6 @@ def test_default_branch_names_keep_timestamp_for_each_runner_family(monkeypatch,
|
|
|
2768
2221
|
|
|
2769
2222
|
assert runners._default_branch_name(family_for("feature", paths), "F-001") == "dev/F-001-20260707010203"
|
|
2770
2223
|
assert runners._default_branch_name(family_for("bugfix", paths), "B-001") == "bugfix/B-001-20260707010203"
|
|
2771
|
-
assert runners._default_branch_name(family_for("refactor", paths), "R-001") == "refactor/R-001-20260707010203"
|
|
2772
2224
|
|
|
2773
2225
|
|
|
2774
2226
|
@pytest.mark.parametrize(
|
|
@@ -2776,7 +2228,6 @@ def test_default_branch_names_keep_timestamp_for_each_runner_family(monkeypatch,
|
|
|
2776
2228
|
[
|
|
2777
2229
|
("feature", "F-001", "dev/F-001-20260707010203"),
|
|
2778
2230
|
("bugfix", "B-001", "bugfix/B-001-20260707010203"),
|
|
2779
|
-
("refactor", "R-001", "refactor/R-001-20260707010203"),
|
|
2780
2231
|
],
|
|
2781
2232
|
)
|
|
2782
2233
|
def test_no_worktree_exhausted_failure_stays_on_task_branch_without_merge_for_all_families(monkeypatch, tmp_path, kind, item_id, branch):
|
|
@@ -2787,7 +2238,7 @@ def test_no_worktree_exhausted_failure_stays_on_task_branch_without_merge_for_al
|
|
|
2787
2238
|
paths = _make_paths(tmp_path / kind)
|
|
2788
2239
|
family = family_for(kind, paths)
|
|
2789
2240
|
invocation = parse_invocation(family, "run", ())
|
|
2790
|
-
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan
|
|
2241
|
+
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan}[kind]
|
|
2791
2242
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
|
|
2792
2243
|
_install_runner_session_fakes(monkeypatch, runners, statuses=("crashed",), update_status="failed")
|
|
2793
2244
|
events = []
|
|
@@ -2863,19 +2314,17 @@ def test_no_worktree_runner_ignores_recovery_side_effect_branch(monkeypatch, tmp
|
|
|
2863
2314
|
[
|
|
2864
2315
|
("feature", "F-001", "dev/F-001-preflight-fail"),
|
|
2865
2316
|
("bugfix", "B-001", "bugfix/B-001-preflight-fail"),
|
|
2866
|
-
("refactor", "R-001", "refactor/R-001-preflight-fail"),
|
|
2867
2317
|
],
|
|
2868
2318
|
)
|
|
2869
|
-
def
|
|
2319
|
+
def test_preflight_commit_failure_aborts_before_branch_or_status_for_all_families(monkeypatch, tmp_path, kind, item_id, branch):
|
|
2870
2320
|
from prizmkit_runtime import runners
|
|
2871
2321
|
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2872
2322
|
|
|
2873
2323
|
monkeypatch.setenv("DEV_BRANCH", branch)
|
|
2874
|
-
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
2875
2324
|
paths = _make_paths(tmp_path / kind)
|
|
2876
2325
|
family = family_for(kind, paths)
|
|
2877
2326
|
invocation = parse_invocation(family, "run", ())
|
|
2878
|
-
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan
|
|
2327
|
+
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan}[kind]
|
|
2879
2328
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
|
|
2880
2329
|
events = []
|
|
2881
2330
|
|
|
@@ -2887,7 +2336,6 @@ def test_preflight_commit_failure_aborts_before_branch_worktree_or_status_for_al
|
|
|
2887
2336
|
monkeypatch.setattr(runners, "current_branch", lambda _root: "main")
|
|
2888
2337
|
monkeypatch.setattr(runners, "commit_preflight_ready_changes", lambda *args, **kwargs: SimpleNamespace(attempted=True, committed=False, result=SimpleNamespace(stderr="commit failed\n", stdout="")))
|
|
2889
2338
|
monkeypatch.setattr(runners, "run_git_plan", lambda *args, **kwargs: events.append("branch_create"))
|
|
2890
|
-
monkeypatch.setattr(runners, "ensure_linked_worktree", lambda *args, **kwargs: events.append("worktree_create"), raising=False)
|
|
2891
2339
|
monkeypatch.setattr(runners, "start_item", lambda *args, **kwargs: events.append("start_item"))
|
|
2892
2340
|
|
|
2893
2341
|
with pytest.raises(RuntimeError, match="Preflight dirty workspace preservation failed"):
|
|
@@ -3087,56 +2535,6 @@ def test_interrupt_return_failure_is_reported_without_forcing_checkout(monkeypat
|
|
|
3087
2535
|
assert "After resolving the Git blocker" not in captured.err
|
|
3088
2536
|
|
|
3089
2537
|
|
|
3090
|
-
def test_worktree_interrupt_uses_same_wip_and_base_return_contract(monkeypatch, tmp_path, capsys):
|
|
3091
|
-
from prizmkit_runtime import runners
|
|
3092
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
3093
|
-
|
|
3094
|
-
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
3095
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-interrupt")
|
|
3096
|
-
paths = _make_paths(tmp_path)
|
|
3097
|
-
family = family_for("feature", paths)
|
|
3098
|
-
invocation = parse_invocation(family, "run", ())
|
|
3099
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
3100
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
3101
|
-
monkeypatch.setattr(
|
|
3102
|
-
runners,
|
|
3103
|
-
"ensure_linked_worktree",
|
|
3104
|
-
lambda runtime: SimpleNamespace(ok=True, runtime=runtime, reason=""),
|
|
3105
|
-
)
|
|
3106
|
-
preserve_calls = []
|
|
3107
|
-
return_calls = []
|
|
3108
|
-
monkeypatch.setattr(
|
|
3109
|
-
runners,
|
|
3110
|
-
"branch_save_wip",
|
|
3111
|
-
lambda root, branch: preserve_calls.append((root, branch)) or SimpleNamespace(ok=True, results=()),
|
|
3112
|
-
)
|
|
3113
|
-
monkeypatch.setattr(
|
|
3114
|
-
runners,
|
|
3115
|
-
"branch_ensure_return",
|
|
3116
|
-
lambda *args: return_calls.append(args) or SimpleNamespace(ok=True, results=()),
|
|
3117
|
-
)
|
|
3118
|
-
|
|
3119
|
-
class InterruptingLauncher:
|
|
3120
|
-
def __init__(self, config):
|
|
3121
|
-
self.config = config
|
|
3122
|
-
|
|
3123
|
-
def run(self):
|
|
3124
|
-
raise KeyboardInterrupt
|
|
3125
|
-
|
|
3126
|
-
monkeypatch.setattr(runners, "AISessionLauncher", InterruptingLauncher)
|
|
3127
|
-
|
|
3128
|
-
with pytest.raises(KeyboardInterrupt):
|
|
3129
|
-
runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
3130
|
-
|
|
3131
|
-
captured = capsys.readouterr()
|
|
3132
|
-
assert preserve_calls and preserve_calls[0][0] != paths.project_root
|
|
3133
|
-
assert return_calls == [(paths.project_root, "main", "dev/F-001-interrupt")]
|
|
3134
|
-
assert "Interrupted task F-001: no WIP commit needed" in captured.err
|
|
3135
|
-
assert "caller checkout returned to main; no merge or push performed" in captured.err
|
|
3136
|
-
assert observed.merge_calls == []
|
|
3137
|
-
assert observed.cleanup_calls == []
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
2538
|
def test_run_pipeline_command_bridges_sigterm_and_restores_handler(monkeypatch, tmp_path):
|
|
3141
2539
|
from prizmkit_runtime import runners
|
|
3142
2540
|
from prizmkit_runtime.processes import describe_interruption
|
|
@@ -3188,7 +2586,6 @@ def test_interruption_cleanup_shield_ignores_and_restores_signals():
|
|
|
3188
2586
|
[
|
|
3189
2587
|
("feature", "F-001", "dev/F-001-interrupt"),
|
|
3190
2588
|
("bugfix", "B-001", "bugfix/B-001-interrupt"),
|
|
3191
|
-
("refactor", "R-001", "refactor/R-001-interrupt"),
|
|
3192
2589
|
],
|
|
3193
2590
|
)
|
|
3194
2591
|
def test_interrupted_task_reuses_durable_checkout_on_next_process(monkeypatch, tmp_path, kind, item_id, branch):
|
|
@@ -3198,7 +2595,7 @@ def test_interrupted_task_reuses_durable_checkout_on_next_process(monkeypatch, t
|
|
|
3198
2595
|
|
|
3199
2596
|
paths = _make_paths(tmp_path / kind)
|
|
3200
2597
|
family = family_for(kind, paths)
|
|
3201
|
-
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan
|
|
2598
|
+
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan}[kind]
|
|
3202
2599
|
invocation = parse_invocation(family, "run", ())
|
|
3203
2600
|
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
|
|
3204
2601
|
persist_task_checkout(family.state_dir, TaskCheckout.active(kind, item_id, branch, "main"))
|
|
@@ -3219,2423 +2616,358 @@ def test_interrupted_task_reuses_durable_checkout_on_next_process(monkeypatch, t
|
|
|
3219
2616
|
assert observed.launch_cwds == [paths.project_root]
|
|
3220
2617
|
|
|
3221
2618
|
|
|
3222
|
-
def
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=project_root, check=True)
|
|
3226
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=project_root, check=True)
|
|
3227
|
-
(project_root / "staged.txt").write_text("base staged\n", encoding="utf-8")
|
|
3228
|
-
(project_root / "unstaged.txt").write_text("base unstaged\n", encoding="utf-8")
|
|
3229
|
-
subprocess.run(["git", "add", "staged.txt", "unstaged.txt"], cwd=project_root, check=True)
|
|
3230
|
-
subprocess.run(
|
|
3231
|
-
[
|
|
3232
|
-
"git",
|
|
3233
|
-
"-c",
|
|
3234
|
-
"user.email=test@example.com",
|
|
3235
|
-
"-c",
|
|
3236
|
-
"user.name=Test",
|
|
3237
|
-
"commit",
|
|
3238
|
-
"-m",
|
|
3239
|
-
"base",
|
|
3240
|
-
],
|
|
3241
|
-
cwd=project_root,
|
|
3242
|
-
check=True,
|
|
3243
|
-
stdout=subprocess.DEVNULL,
|
|
3244
|
-
)
|
|
3245
|
-
|
|
2619
|
+
def test_context_overflow_reuses_branch_and_skips_cleanup_until_terminal_outcome(monkeypatch, tmp_path):
|
|
2620
|
+
from prizmkit_runtime import runners
|
|
2621
|
+
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
3246
2622
|
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
2623
|
+
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-test")
|
|
2624
|
+
paths = _make_paths(tmp_path)
|
|
2625
|
+
family = family_for("feature", paths)
|
|
2626
|
+
invocation = parse_invocation(family, "run", ())
|
|
2627
|
+
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2628
|
+
observed = _install_runner_session_fakes(monkeypatch, runners, statuses=("context_overflow", "success"))
|
|
2629
|
+
sleep_calls = []
|
|
2630
|
+
monkeypatch.setattr(runners.time, "sleep", lambda seconds: sleep_calls.append(seconds))
|
|
2631
|
+
plan_names = []
|
|
2632
|
+
monkeypatch.setattr(
|
|
2633
|
+
runners,
|
|
2634
|
+
"run_git_plan",
|
|
2635
|
+
lambda project_root, plan: plan_names.append(plan.name) or SimpleNamespace(ok=True, plan=plan, results=()),
|
|
3256
2636
|
)
|
|
3257
2637
|
|
|
2638
|
+
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
3258
2639
|
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
def _head_files(project_root):
|
|
3270
|
-
return set(
|
|
3271
|
-
subprocess.run(
|
|
3272
|
-
["git", "show", "--name-only", "--format=", "HEAD"],
|
|
3273
|
-
cwd=project_root,
|
|
3274
|
-
check=True,
|
|
3275
|
-
stdout=subprocess.PIPE,
|
|
3276
|
-
text=True,
|
|
3277
|
-
).stdout.splitlines()
|
|
3278
|
-
)
|
|
2640
|
+
assert status == "completed"
|
|
2641
|
+
assert plan_names == ["branch_create", "branch_merge"]
|
|
2642
|
+
assert observed.launch_cwds == [paths.project_root, paths.project_root]
|
|
2643
|
+
assert observed.prompt_calls[0]["execution_root"] == observed.prompt_calls[1]["execution_root"]
|
|
2644
|
+
assert observed.prompt_calls[0].get("continuation") is None
|
|
2645
|
+
assert observed.prompt_calls[1]["continuation"]["previous_session_id"] == "F-001-session-1"
|
|
2646
|
+
assert observed.updates[0][0] == "context_overflow"
|
|
2647
|
+
assert sleep_calls == [5]
|
|
3279
2648
|
|
|
3280
2649
|
|
|
3281
|
-
|
|
3282
|
-
(
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
("
|
|
3286
|
-
|
|
3287
|
-
],
|
|
3288
|
-
)
|
|
3289
|
-
def test_preflight_ready_commit_preserves_staged_unstaged_and_mixed_visible_changes(tmp_path, scenario, expected_files):
|
|
3290
|
-
from prizmkit_runtime.gitops import HIDDEN_TOOL_WORKTREE_EXCLUDES
|
|
3291
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3292
|
-
|
|
3293
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3294
|
-
if scenario in {"staged_only", "mixed"}:
|
|
3295
|
-
(tmp_path / "staged.txt").write_text("staged change\n", encoding="utf-8")
|
|
3296
|
-
subprocess.run(["git", "add", "staged.txt"], cwd=tmp_path, check=True)
|
|
3297
|
-
if scenario in {"unstaged_only", "mixed"}:
|
|
3298
|
-
(tmp_path / "unstaged.txt").write_text("unstaged change\n", encoding="utf-8")
|
|
3299
|
-
if scenario == "mixed":
|
|
3300
|
-
(tmp_path / "new-visible.txt").write_text("new visible\n", encoding="utf-8")
|
|
3301
|
-
|
|
3302
|
-
before_count = _head_commit_count(tmp_path)
|
|
3303
|
-
result = commit_preflight_ready_changes(tmp_path, "F-123")
|
|
3304
|
-
visible_status = subprocess.run(
|
|
3305
|
-
["git", "status", "--porcelain", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES],
|
|
3306
|
-
cwd=tmp_path,
|
|
3307
|
-
check=True,
|
|
2650
|
+
def test_cli_family_status_uses_python_dispatch_not_transition_description(tmp_path):
|
|
2651
|
+
paths = _make_paths(tmp_path)
|
|
2652
|
+
_write_feature_list(paths)
|
|
2653
|
+
result = subprocess.run(
|
|
2654
|
+
[PYTHON_310_PLUS, str(CLI_PATH), "--project-root", str(paths.project_root), "status", "feature"],
|
|
2655
|
+
cwd=REPO_ROOT,
|
|
3308
2656
|
stdout=subprocess.PIPE,
|
|
2657
|
+
stderr=subprocess.PIPE,
|
|
3309
2658
|
text=True,
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
assert result.attempted is True
|
|
3313
|
-
assert result.committed is True
|
|
3314
|
-
assert _head_commit_count(tmp_path) == before_count + 1
|
|
3315
|
-
assert _head_message(tmp_path) == "chore: ready for F-123"
|
|
3316
|
-
assert expected_files.issubset(_head_files(tmp_path))
|
|
3317
|
-
assert visible_status == ""
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
def test_preflight_ready_commit_handles_exact_special_and_renamed_paths(tmp_path):
|
|
3321
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3322
|
-
|
|
3323
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3324
|
-
old_path = tmp_path / "old name -> café.txt"
|
|
3325
|
-
old_path.write_text("old\n", encoding="utf-8")
|
|
3326
|
-
subprocess.run(["git", "add", old_path.name], cwd=tmp_path, check=True)
|
|
3327
|
-
subprocess.run(["git", "commit", "-m", "track special path"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
3328
|
-
new_path = tmp_path / 'new "quoted" \\ 名称.txt'
|
|
3329
|
-
old_path.rename(new_path)
|
|
3330
|
-
untracked_path = tmp_path / "untracked -> line\nbreak.txt"
|
|
3331
|
-
untracked_path.write_text("new\n", encoding="utf-8")
|
|
3332
|
-
colon_path = tmp_path / ":(glob)**.txt"
|
|
3333
|
-
colon_path.write_text("literal pathspec\n", encoding="utf-8")
|
|
3334
|
-
|
|
3335
|
-
result = commit_preflight_ready_changes(tmp_path, "R-001")
|
|
3336
|
-
committed_files = set(
|
|
3337
|
-
filter(
|
|
3338
|
-
None,
|
|
3339
|
-
subprocess.run(
|
|
3340
|
-
["git", "diff-tree", "--no-commit-id", "--name-only", "-r", "-z", "HEAD"],
|
|
3341
|
-
cwd=tmp_path,
|
|
3342
|
-
check=True,
|
|
3343
|
-
stdout=subprocess.PIPE,
|
|
3344
|
-
).stdout.decode().split("\0"),
|
|
3345
|
-
)
|
|
2659
|
+
check=False,
|
|
3346
2660
|
)
|
|
3347
2661
|
|
|
3348
|
-
assert result.
|
|
3349
|
-
assert
|
|
3350
|
-
assert
|
|
3351
|
-
assert untracked_path.name in committed_files
|
|
3352
|
-
assert colon_path.name in committed_files
|
|
3353
|
-
assert _head_message(tmp_path) == "chore: ready for R-001"
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
@pytest.mark.parametrize("staged", [False, True])
|
|
3357
|
-
def test_preflight_ready_commit_rejects_tracked_local_settings_before_checkout(tmp_path, staged):
|
|
3358
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3359
|
-
|
|
3360
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3361
|
-
local_settings = tmp_path / ".claude" / "settings.local.json"
|
|
3362
|
-
local_settings.parent.mkdir(parents=True)
|
|
3363
|
-
local_settings.write_text('{"permissions": []}\n', encoding="utf-8")
|
|
3364
|
-
subprocess.run(["git", "add", "-f", ".claude/settings.local.json"], cwd=tmp_path, check=True)
|
|
3365
|
-
subprocess.run(["git", "commit", "-m", "track local settings"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
3366
|
-
local_settings.write_text('{"permissions": ["secret"]}\n', encoding="utf-8")
|
|
3367
|
-
if staged:
|
|
3368
|
-
subprocess.run(["git", "add", ".claude/settings.local.json"], cwd=tmp_path, check=True)
|
|
3369
|
-
|
|
3370
|
-
result = commit_preflight_ready_changes(tmp_path, "B-001")
|
|
3371
|
-
|
|
3372
|
-
assert result.attempted is True
|
|
3373
|
-
assert result.committed is False
|
|
3374
|
-
assert result.result is not None
|
|
3375
|
-
assert "Refusing to auto-commit local-only platform settings" in result.result.stderr
|
|
3376
|
-
assert _head_message(tmp_path) == "track local settings"
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
def test_preflight_ready_commit_excludes_untracked_python_cache_outside_support_dirs(tmp_path):
|
|
3380
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3381
|
-
|
|
3382
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3383
|
-
(tmp_path / "visible.txt").write_text("visible\n", encoding="utf-8")
|
|
3384
|
-
cache_paths = [
|
|
3385
|
-
tmp_path / "__pycache__" / "top.cpython-312.pyc",
|
|
3386
|
-
tmp_path / "src" / "package" / "__pycache__" / "module.cpython-312.pyc",
|
|
3387
|
-
tmp_path / "src" / "standalone.pyo",
|
|
3388
|
-
]
|
|
3389
|
-
for path in cache_paths:
|
|
3390
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
3391
|
-
path.write_text("compiled\n", encoding="utf-8")
|
|
2662
|
+
assert result.returncode == 0
|
|
2663
|
+
assert "Python feature status" in result.stdout
|
|
2664
|
+
assert "Transition command contract" not in result.stdout
|
|
3392
2665
|
|
|
3393
|
-
result = commit_preflight_ready_changes(tmp_path, "F-001")
|
|
3394
|
-
committed_files = _head_files(tmp_path)
|
|
3395
2666
|
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
2667
|
+
def _write_family_case(paths, kind, item_id=""):
|
|
2668
|
+
item_id = item_id or {"feature": "F-001", "bugfix": "B-001"}[kind]
|
|
2669
|
+
if kind == "feature":
|
|
2670
|
+
paths.feature_plan.write_text(json.dumps({"features": [{"id": item_id, "title": "Reset Thing", "status": "failed", "dependencies": []}]}), encoding="utf-8")
|
|
2671
|
+
state_dir = paths.feature_state_dir
|
|
2672
|
+
plan = paths.feature_plan
|
|
2673
|
+
elif kind == "bugfix":
|
|
2674
|
+
paths.bugfix_plan.write_text(json.dumps({"bugs": [{"id": item_id, "title": "Reset Bug", "description": "d", "severity": "medium", "priority": "medium", "status": "failed"}]}), encoding="utf-8")
|
|
2675
|
+
state_dir = paths.bugfix_state_dir
|
|
2676
|
+
plan = paths.bugfix_plan
|
|
2677
|
+
else:
|
|
2678
|
+
raise ValueError(f"Unsupported family kind: {kind}")
|
|
2679
|
+
state_dir.mkdir(parents=True, exist_ok=True)
|
|
2680
|
+
(state_dir / "pipeline.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
|
|
2681
|
+
item_state = state_dir / item_id
|
|
2682
|
+
item_state.mkdir(parents=True, exist_ok=True)
|
|
2683
|
+
(item_state / "status.json").write_text(
|
|
2684
|
+
json.dumps(
|
|
2685
|
+
{
|
|
2686
|
+
"status": "in_progress",
|
|
2687
|
+
"retry_count": 2,
|
|
2688
|
+
"infra_error_count": 1,
|
|
2689
|
+
"last_infra_error_session_id": "infra-1",
|
|
2690
|
+
"last_session_id": "sess-1",
|
|
2691
|
+
"sessions": ["sess-1"],
|
|
2692
|
+
"continuation_pending": True,
|
|
2693
|
+
"continuation_reason": "context_overflow",
|
|
2694
|
+
"active_dev_branch": f"{kind}/{item_id}-branch",
|
|
2695
|
+
"continuation_summary_path": str(paths.project_root / ".prizmkit" / ("specs" if kind == "feature" else kind) / item_id / "continuation-summary.md"),
|
|
2696
|
+
}
|
|
2697
|
+
),
|
|
2698
|
+
encoding="utf-8",
|
|
2699
|
+
)
|
|
2700
|
+
return plan, state_dir, item_state / "status.json"
|
|
3399
2701
|
|
|
3400
2702
|
|
|
3401
|
-
def
|
|
3402
|
-
from prizmkit_runtime.
|
|
2703
|
+
def test_python_reset_warns_before_mutation_and_matches_snapshot_cleanup(tmp_path):
|
|
2704
|
+
from prizmkit_runtime.reset import run_reset_command
|
|
3403
2705
|
from prizmkit_runtime.runner_models import family_for
|
|
2706
|
+
from prizmkit_runtime.task_checkout import load_task_checkout
|
|
3404
2707
|
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
tracked_cache.write_text("task change\n", encoding="utf-8")
|
|
3413
|
-
|
|
3414
|
-
result = commit_task_branch_changes(paths.project_root, family_for("bugfix", paths), "B-001", "completed")
|
|
2708
|
+
snapshot = json.loads((REPO_ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json").read_text(encoding="utf-8"))
|
|
2709
|
+
for kind, item_id in [("feature", "F-001"), ("bugfix", "B-001")]:
|
|
2710
|
+
paths = _make_paths(tmp_path / kind)
|
|
2711
|
+
_plan, _state_dir, status_file = _write_family_case(paths, kind, item_id)
|
|
2712
|
+
result = run_reset_command(kind, (item_id, "--fresh-checkout"), paths)
|
|
2713
|
+
output = result.render()
|
|
2714
|
+
reset_marker = f"Resetting {item_id} status"
|
|
3415
2715
|
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
2716
|
+
assert result.exit_code == snapshot["resetBehavior"]["manualResetWarningOrder"][kind]["exitCode"]
|
|
2717
|
+
assert "Continuation pending" in output
|
|
2718
|
+
assert "Pending continuation branch" in output
|
|
2719
|
+
assert output.index("Continuation pending") < output.index(reset_marker)
|
|
2720
|
+
runtime = json.loads(status_file.read_text(encoding="utf-8"))
|
|
2721
|
+
expected_runtime = snapshot["statusUpdaterBehavior"]["resetCleanMetadataCleanup"][kind]["reset"]["runtime"]
|
|
2722
|
+
for key, value in expected_runtime.items():
|
|
2723
|
+
assert runtime.get(key) == value
|
|
2724
|
+
assert "continuation_pending" not in runtime
|
|
2725
|
+
family = family_for(kind, paths)
|
|
2726
|
+
checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
|
|
2727
|
+
assert checkout is not None
|
|
2728
|
+
assert checkout.is_reset
|
|
2729
|
+
assert checkout.active_dev_branch == ""
|
|
2730
|
+
assert checkout.base_branch == ""
|
|
3425
2731
|
|
|
3426
2732
|
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
from prizmkit_runtime import
|
|
3430
|
-
from prizmkit_runtime.gitops import GitCommandResult
|
|
2733
|
+
def test_python_reset_cleans_authoritative_custom_branch_before_reset_marker(monkeypatch, tmp_path):
|
|
2734
|
+
from prizmkit_runtime import reset as reset_runtime
|
|
2735
|
+
from prizmkit_runtime.reset import run_reset_command
|
|
3431
2736
|
from prizmkit_runtime.runner_models import family_for
|
|
2737
|
+
from prizmkit_runtime.task_checkout import TaskCheckout, load_task_checkout, persist_task_checkout
|
|
3432
2738
|
|
|
3433
2739
|
paths = _make_paths(tmp_path)
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
)
|
|
2740
|
+
_write_family_case(paths, "feature", "F-001")
|
|
2741
|
+
family = family_for("feature", paths)
|
|
2742
|
+
custom_branch = "custom/feature-checkout"
|
|
2743
|
+
persist_task_checkout(family.state_dir, TaskCheckout.active("feature", "F-001", custom_branch, "main"))
|
|
2744
|
+
cleanup_calls = []
|
|
2745
|
+
|
|
2746
|
+
monkeypatch.setattr(reset_runtime, "list_reset_branches", lambda *args: ())
|
|
3442
2747
|
monkeypatch.setattr(
|
|
3443
|
-
|
|
3444
|
-
"
|
|
3445
|
-
lambda
|
|
2748
|
+
reset_runtime,
|
|
2749
|
+
"reset_cleanup_branch",
|
|
2750
|
+
lambda project_root, branch, *, return_branch, delete: cleanup_calls.append((branch, delete))
|
|
2751
|
+
or SimpleNamespace(branch=branch, cleaned=True, deleted=False, returned_to=return_branch, warnings=()),
|
|
3446
2752
|
)
|
|
3447
|
-
calls = []
|
|
3448
|
-
|
|
3449
|
-
def fail_add(_root, args):
|
|
3450
|
-
args = tuple(args)
|
|
3451
|
-
calls.append(args)
|
|
3452
|
-
assert args[0] != "commit"
|
|
3453
|
-
return GitCommandResult(args, 1, "", "staging failed")
|
|
3454
|
-
|
|
3455
|
-
monkeypatch.setattr(runner_bookkeeping, "run_git_command", fail_add)
|
|
3456
|
-
helper = getattr(runner_bookkeeping, helper_name)
|
|
3457
2753
|
|
|
3458
|
-
result =
|
|
2754
|
+
result = run_reset_command("feature", ("F-001", "--fresh-checkout"), paths)
|
|
3459
2755
|
|
|
3460
|
-
assert result.
|
|
3461
|
-
assert
|
|
3462
|
-
|
|
3463
|
-
assert
|
|
2756
|
+
assert result.exit_code == 0
|
|
2757
|
+
assert cleanup_calls == [(custom_branch, False)]
|
|
2758
|
+
checkout = load_task_checkout(family.state_dir, family.task_type, "F-001")
|
|
2759
|
+
assert checkout is not None and checkout.is_reset
|
|
3464
2760
|
|
|
3465
2761
|
|
|
3466
|
-
def
|
|
3467
|
-
from prizmkit_runtime
|
|
2762
|
+
def test_python_reset_failure_keeps_authoritative_checkout_active(monkeypatch, tmp_path):
|
|
2763
|
+
from prizmkit_runtime import reset as reset_runtime
|
|
2764
|
+
from prizmkit_runtime.reset import run_reset_command
|
|
2765
|
+
from prizmkit_runtime.runner_models import family_for
|
|
2766
|
+
from prizmkit_runtime.task_checkout import TaskCheckout, load_task_checkout, persist_task_checkout
|
|
3468
2767
|
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
2768
|
+
paths = _make_paths(tmp_path)
|
|
2769
|
+
_write_family_case(paths, "feature", "F-001")
|
|
2770
|
+
family = family_for("feature", paths)
|
|
2771
|
+
checkout = TaskCheckout.active("feature", "F-001", "custom/feature-checkout", "main")
|
|
2772
|
+
persist_task_checkout(family.state_dir, checkout)
|
|
2773
|
+
monkeypatch.setattr(reset_runtime, "list_reset_branches", lambda *args: ())
|
|
2774
|
+
monkeypatch.setattr(
|
|
2775
|
+
reset_runtime,
|
|
2776
|
+
"reset_cleanup_branch",
|
|
2777
|
+
lambda *args, **kwargs: SimpleNamespace(
|
|
2778
|
+
branch="custom/feature-checkout",
|
|
2779
|
+
cleaned=False,
|
|
2780
|
+
deleted=False,
|
|
2781
|
+
returned_to="main",
|
|
2782
|
+
warnings=("could not checkout custom/feature-checkout",),
|
|
2783
|
+
),
|
|
2784
|
+
)
|
|
3478
2785
|
|
|
3479
|
-
result =
|
|
2786
|
+
result = run_reset_command("feature", ("F-001", "--fresh-checkout"), paths)
|
|
3480
2787
|
|
|
3481
|
-
assert result.
|
|
3482
|
-
assert
|
|
3483
|
-
assert untracked_state.relative_to(tmp_path).as_posix() not in _head_files(tmp_path)
|
|
2788
|
+
assert result.exit_code == 1
|
|
2789
|
+
assert load_task_checkout(family.state_dir, family.task_type, "F-001") == checkout
|
|
3484
2790
|
|
|
3485
2791
|
|
|
3486
|
-
def
|
|
3487
|
-
|
|
3488
|
-
manifest_path.parent.mkdir(parents=True, exist_ok=True)
|
|
3489
|
-
manifest_path.write_text('{"version":"baseline"}\n', encoding="utf-8")
|
|
3490
|
-
subprocess.run(["git", "add", ".prizmkit/manifest.json"], cwd=project_root, check=True)
|
|
3491
|
-
subprocess.run(["git", "commit", "-m", "track manifest"], cwd=project_root, check=True, stdout=subprocess.DEVNULL)
|
|
3492
|
-
return manifest_path
|
|
2792
|
+
def test_python_clean_reset_deletes_continuation_artifacts_for_all_families(tmp_path):
|
|
2793
|
+
from prizmkit_runtime.reset import run_reset_command
|
|
3493
2794
|
|
|
2795
|
+
snapshot = json.loads((REPO_ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json").read_text(encoding="utf-8"))
|
|
2796
|
+
cases = [("feature", "F-001", "specs", "001-reset-thing"), ("bugfix", "B-001", "bugfix", "B-001")]
|
|
2797
|
+
for kind, item_id, artifact_root, artifact_name in cases:
|
|
2798
|
+
paths = _make_paths(tmp_path / f"clean-{kind}")
|
|
2799
|
+
_plan, _state_dir, status_file = _write_family_case(paths, kind, item_id)
|
|
2800
|
+
artifact_dir = paths.project_root / ".prizmkit" / artifact_root / artifact_name
|
|
2801
|
+
artifact_dir.mkdir(parents=True, exist_ok=True)
|
|
2802
|
+
continuation = artifact_dir / "continuation-summary.md"
|
|
2803
|
+
continuation.write_text("summary", encoding="utf-8")
|
|
2804
|
+
args = (item_id, "--clean")
|
|
2805
|
+
result = run_reset_command(kind, args, paths)
|
|
3494
2806
|
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
("
|
|
3499
|
-
("
|
|
3500
|
-
|
|
3501
|
-
],
|
|
3502
|
-
)
|
|
3503
|
-
def test_preflight_ready_commit_preserves_tracked_manifest_modification_state(tmp_path, scenario, expected_content):
|
|
3504
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3505
|
-
|
|
3506
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3507
|
-
manifest_path = _track_manifest(tmp_path)
|
|
3508
|
-
if scenario == "staged_only":
|
|
3509
|
-
manifest_path.write_text(expected_content, encoding="utf-8")
|
|
3510
|
-
subprocess.run(["git", "add", ".prizmkit/manifest.json"], cwd=tmp_path, check=True)
|
|
3511
|
-
elif scenario == "unstaged_only":
|
|
3512
|
-
manifest_path.write_text(expected_content, encoding="utf-8")
|
|
3513
|
-
else:
|
|
3514
|
-
manifest_path.write_text('{"version":"index"}\n', encoding="utf-8")
|
|
3515
|
-
subprocess.run(["git", "add", ".prizmkit/manifest.json"], cwd=tmp_path, check=True)
|
|
3516
|
-
manifest_path.write_text(expected_content, encoding="utf-8")
|
|
3517
|
-
|
|
3518
|
-
before_count = _head_commit_count(tmp_path)
|
|
3519
|
-
result = commit_preflight_ready_changes(tmp_path, "F-003")
|
|
3520
|
-
committed_content = subprocess.run(
|
|
3521
|
-
["git", "show", "HEAD:.prizmkit/manifest.json"],
|
|
3522
|
-
cwd=tmp_path,
|
|
3523
|
-
check=True,
|
|
3524
|
-
stdout=subprocess.PIPE,
|
|
3525
|
-
text=True,
|
|
3526
|
-
).stdout
|
|
3527
|
-
|
|
3528
|
-
assert result.attempted is True
|
|
3529
|
-
assert result.committed is True
|
|
3530
|
-
assert _head_commit_count(tmp_path) == before_count + 1
|
|
3531
|
-
assert _head_message(tmp_path) == "chore: ready for F-003"
|
|
3532
|
-
assert _head_files(tmp_path) == {".prizmkit/manifest.json"}
|
|
3533
|
-
assert committed_content == expected_content
|
|
3534
|
-
assert subprocess.run(
|
|
3535
|
-
["git", "status", "--short", "--untracked-files=no"],
|
|
3536
|
-
cwd=tmp_path,
|
|
3537
|
-
check=True,
|
|
3538
|
-
stdout=subprocess.PIPE,
|
|
3539
|
-
text=True,
|
|
3540
|
-
).stdout == ""
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
@pytest.mark.parametrize("staged", [False, True])
|
|
3544
|
-
def test_preflight_ready_commit_preserves_tracked_manifest_deletion(tmp_path, staged):
|
|
3545
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3546
|
-
|
|
3547
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3548
|
-
manifest_path = _track_manifest(tmp_path)
|
|
3549
|
-
manifest_path.unlink()
|
|
3550
|
-
if staged:
|
|
3551
|
-
subprocess.run(["git", "add", "-u", "--", ".prizmkit/manifest.json"], cwd=tmp_path, check=True)
|
|
3552
|
-
(tmp_path / "unstaged.txt").write_text("coexisting tracked change\n", encoding="utf-8")
|
|
3553
|
-
(tmp_path / "coexisting.txt").write_text("coexisting untracked change\n", encoding="utf-8")
|
|
3554
|
-
|
|
3555
|
-
before_count = _head_commit_count(tmp_path)
|
|
3556
|
-
result = commit_preflight_ready_changes(tmp_path, "B-003")
|
|
3557
|
-
manifest_at_head = subprocess.run(
|
|
3558
|
-
["git", "cat-file", "-e", "HEAD:.prizmkit/manifest.json"],
|
|
3559
|
-
cwd=tmp_path,
|
|
3560
|
-
stdout=subprocess.DEVNULL,
|
|
3561
|
-
stderr=subprocess.DEVNULL,
|
|
3562
|
-
)
|
|
2807
|
+
assert result.exit_code == snapshot["resetBehavior"]["cleanResetDeletesContinuationArtifacts"][kind]["exitCode"]
|
|
2808
|
+
assert continuation.exists() is False
|
|
2809
|
+
runtime = json.loads(status_file.read_text(encoding="utf-8"))
|
|
2810
|
+
assert runtime.get("retry_count") == 0
|
|
2811
|
+
assert runtime.get("infra_error_count") == 0
|
|
2812
|
+
assert "continuation_pending" not in runtime
|
|
3563
2813
|
|
|
3564
|
-
assert result.attempted is True
|
|
3565
|
-
assert result.committed is True
|
|
3566
|
-
assert _head_commit_count(tmp_path) == before_count + 1
|
|
3567
|
-
assert _head_message(tmp_path) == "chore: ready for B-003"
|
|
3568
|
-
assert _head_files(tmp_path) == {".prizmkit/manifest.json", "coexisting.txt", "unstaged.txt"}
|
|
3569
|
-
assert manifest_at_head.returncode != 0
|
|
3570
|
-
assert subprocess.run(
|
|
3571
|
-
["git", "status", "--short", "--untracked-files=all"],
|
|
3572
|
-
cwd=tmp_path,
|
|
3573
|
-
check=True,
|
|
3574
|
-
stdout=subprocess.PIPE,
|
|
3575
|
-
text=True,
|
|
3576
|
-
).stdout == ""
|
|
3577
2814
|
|
|
2815
|
+
def test_python_context_overflow_runner_path_does_not_import_reset():
|
|
2816
|
+
runner_text = (PIPELINE_ROOT / "prizmkit_runtime" / "runners.py").read_text(encoding="utf-8")
|
|
3578
2817
|
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
("[]\n", "not a JSON object"),
|
|
3584
|
-
],
|
|
3585
|
-
)
|
|
3586
|
-
def test_preflight_ready_commit_rejects_unsafe_tracked_manifest_before_any_commit(tmp_path, payload, expected_error):
|
|
3587
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3588
|
-
|
|
3589
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3590
|
-
manifest_path = _track_manifest(tmp_path)
|
|
3591
|
-
manifest_path.write_text(payload, encoding="utf-8")
|
|
3592
|
-
(tmp_path / "eligible.txt").write_text("must remain uncommitted\n", encoding="utf-8")
|
|
3593
|
-
before_count = _head_commit_count(tmp_path)
|
|
3594
|
-
|
|
3595
|
-
result = commit_preflight_ready_changes(tmp_path, "R-003")
|
|
3596
|
-
|
|
3597
|
-
assert result.attempted is True
|
|
3598
|
-
assert result.committed is False
|
|
3599
|
-
assert result.result is not None
|
|
3600
|
-
assert expected_error in result.result.stderr
|
|
3601
|
-
assert _head_commit_count(tmp_path) == before_count
|
|
3602
|
-
assert "eligible.txt" not in _head_files(tmp_path)
|
|
3603
|
-
assert subprocess.run(
|
|
3604
|
-
["git", "status", "--short", "--untracked-files=all"],
|
|
3605
|
-
cwd=tmp_path,
|
|
3606
|
-
check=True,
|
|
3607
|
-
stdout=subprocess.PIPE,
|
|
3608
|
-
text=True,
|
|
3609
|
-
).stdout.splitlines() == [" M .prizmkit/manifest.json", "?? eligible.txt"]
|
|
2818
|
+
assert "from .reset" not in runner_text
|
|
2819
|
+
assert "run_reset_command" not in runner_text
|
|
2820
|
+
assert '"context_overflow"' in runner_text
|
|
2821
|
+
assert "update_item" in runner_text
|
|
3610
2822
|
|
|
3611
2823
|
|
|
3612
|
-
def
|
|
3613
|
-
from prizmkit_runtime.
|
|
2824
|
+
def test_python_daemon_stale_pid_matches_snapshot(tmp_path):
|
|
2825
|
+
from prizmkit_runtime.daemon import run_daemon_command
|
|
3614
2826
|
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
3625
|
-
path.write_text("installed\n", encoding="utf-8")
|
|
3626
|
-
tracked_paths = [manifest_path, *tracked_support_paths]
|
|
3627
|
-
subprocess.run(
|
|
3628
|
-
["git", "add", *(path.relative_to(tmp_path).as_posix() for path in tracked_paths)],
|
|
3629
|
-
cwd=tmp_path,
|
|
3630
|
-
check=True,
|
|
3631
|
-
)
|
|
3632
|
-
subprocess.run(["git", "commit", "-m", "track support"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
3633
|
-
manifest_path.write_text('{"version":"1.1.128"}\n', encoding="utf-8")
|
|
3634
|
-
for path in tracked_support_paths:
|
|
3635
|
-
path.write_text("upgraded\n", encoding="utf-8")
|
|
3636
|
-
visible_path = tmp_path / "visible.txt"
|
|
3637
|
-
visible_path.write_text("eligible untracked change\n", encoding="utf-8")
|
|
3638
|
-
|
|
3639
|
-
untracked_support_paths = [
|
|
3640
|
-
tmp_path / ".claude" / "settings.local.json",
|
|
3641
|
-
tmp_path / ".prizmkit" / "dev-pipeline" / "scripts" / "__pycache__" / "runtime.pyc",
|
|
3642
|
-
tmp_path / ".prizmkit" / "state" / "bugfix" / "B-001" / "status.json",
|
|
3643
|
-
]
|
|
3644
|
-
for path in untracked_support_paths:
|
|
3645
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
3646
|
-
path.write_text("transient\n", encoding="utf-8")
|
|
3647
|
-
|
|
3648
|
-
before_count = _head_commit_count(tmp_path)
|
|
3649
|
-
result = commit_preflight_ready_changes(tmp_path, "B-001")
|
|
3650
|
-
|
|
3651
|
-
assert result.attempted is True
|
|
3652
|
-
assert result.committed is True
|
|
3653
|
-
assert _head_commit_count(tmp_path) == before_count + 1
|
|
3654
|
-
assert _head_message(tmp_path) == "chore: ready for B-001"
|
|
3655
|
-
assert _head_files(tmp_path) == {
|
|
3656
|
-
*(path.relative_to(tmp_path).as_posix() for path in tracked_paths),
|
|
3657
|
-
visible_path.relative_to(tmp_path).as_posix(),
|
|
3658
|
-
}
|
|
3659
|
-
assert subprocess.run(
|
|
3660
|
-
["git", "status", "--short", "--untracked-files=no"],
|
|
3661
|
-
cwd=tmp_path,
|
|
3662
|
-
check=True,
|
|
3663
|
-
stdout=subprocess.PIPE,
|
|
3664
|
-
text=True,
|
|
3665
|
-
).stdout == ""
|
|
2827
|
+
snapshot = json.loads((REPO_ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json").read_text(encoding="utf-8"))
|
|
2828
|
+
for kind in ("feature", "bugfix"):
|
|
2829
|
+
paths = _make_paths(tmp_path / f"daemon-{kind}")
|
|
2830
|
+
family_state = {"feature": paths.feature_state_dir, "bugfix": paths.bugfix_state_dir}[kind]
|
|
2831
|
+
family_state.mkdir(parents=True, exist_ok=True)
|
|
2832
|
+
pid_file = family_state / ".pipeline.pid"
|
|
2833
|
+
pid_file.write_text("999999\n", encoding="utf-8")
|
|
2834
|
+
result = run_daemon_command(kind, "status", (), paths)
|
|
2835
|
+
expected = snapshot["daemonBehavior"]["stalePidStatusByTaskType"][kind]
|
|
3666
2836
|
|
|
2837
|
+
assert result.exit_code == expected["exitCode"]
|
|
2838
|
+
assert json.loads(result.render())["running"] is False
|
|
2839
|
+
assert pid_file.exists() is False
|
|
2840
|
+
assert "Cleaned stale PID file" in (result.stderr or "")
|
|
3667
2841
|
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
cleanup_on_success=True,
|
|
3688
|
-
preserve_on_failure=True,
|
|
3689
|
-
worktree_root=tmp_path.parent / f"{tmp_path.name}-worktrees",
|
|
3690
|
-
),
|
|
2842
|
+
|
|
2843
|
+
def test_python_daemon_controlled_start_status_stop_matches_snapshot(tmp_path):
|
|
2844
|
+
from prizmkit_runtime.daemon import run_daemon_command
|
|
2845
|
+
from prizmkit_runtime.paths import resolve_runtime_paths
|
|
2846
|
+
|
|
2847
|
+
snapshot = json.loads((REPO_ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json").read_text(encoding="utf-8"))["daemonBehavior"]["controlledStartStop"]
|
|
2848
|
+
project = tmp_path / "project"
|
|
2849
|
+
pipeline = tmp_path / "runtime"
|
|
2850
|
+
pipeline.mkdir(parents=True)
|
|
2851
|
+
cli = pipeline / "cli.py"
|
|
2852
|
+
cli.write_text(
|
|
2853
|
+
"#!/usr/bin/env python3\n"
|
|
2854
|
+
"import os, sys, time\n"
|
|
2855
|
+
"print('payload env=' + os.environ.get('FOO', ''))\n"
|
|
2856
|
+
"print('payload live=' + os.environ.get('PRIZMKIT_LIVE_OUTPUT', ''))\n"
|
|
2857
|
+
"print('payload args=' + ' '.join(sys.argv[1:]))\n"
|
|
2858
|
+
"sys.stdout.flush()\n"
|
|
2859
|
+
"time.sleep(30)\n",
|
|
2860
|
+
encoding="utf-8",
|
|
3691
2861
|
)
|
|
3692
|
-
|
|
2862
|
+
cli.chmod(0o755)
|
|
2863
|
+
paths = resolve_runtime_paths(pipeline_root=pipeline, project_root=project)
|
|
2864
|
+
paths.plans_dir.mkdir(parents=True)
|
|
2865
|
+
paths.feature_plan.write_text(json.dumps({"features": [{"id": "F-001", "title": "A", "status": "pending"}]}), encoding="utf-8")
|
|
3693
2866
|
|
|
3694
|
-
|
|
3695
|
-
assert setup.ok
|
|
2867
|
+
start = run_daemon_command("feature", "start", ("--env", "FOO=bar", "--features", "F-001"), paths)
|
|
3696
2868
|
try:
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
["git", "status", "--short", "--untracked-files=no"],
|
|
3701
|
-
cwd=tmp_path,
|
|
3702
|
-
check=True,
|
|
3703
|
-
stdout=subprocess.PIPE,
|
|
3704
|
-
text=True,
|
|
3705
|
-
).stdout == ""
|
|
2869
|
+
start_payload = json.loads(start.render())
|
|
2870
|
+
status = run_daemon_command("feature", "status", (), paths)
|
|
2871
|
+
status_payload = json.loads(status.render())
|
|
3706
2872
|
finally:
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
def test_preflight_ready_commit_excludes_untracked_support_assets_and_state(tmp_path):
|
|
3711
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3712
|
-
|
|
3713
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3714
|
-
(tmp_path / "unstaged.txt").write_text("visible change\n", encoding="utf-8")
|
|
3715
|
-
hidden_paths = [
|
|
3716
|
-
tmp_path / ".claude" / "settings.json",
|
|
3717
|
-
tmp_path / ".codebuddy" / "skills" / "local.md",
|
|
3718
|
-
tmp_path / ".agents" / "skills" / "local.md",
|
|
3719
|
-
tmp_path / ".codex" / "config.toml",
|
|
3720
|
-
tmp_path / ".prizmkit" / "state" / "features" / "F-001" / "status.json",
|
|
3721
|
-
tmp_path / ".claude" / "worktrees" / "agent" / "scratch.txt",
|
|
3722
|
-
]
|
|
3723
|
-
for path in hidden_paths:
|
|
3724
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
3725
|
-
path.write_text("hidden support\n", encoding="utf-8")
|
|
3726
|
-
|
|
3727
|
-
result = commit_preflight_ready_changes(tmp_path, "F-124")
|
|
3728
|
-
committed_files = _head_files(tmp_path)
|
|
3729
|
-
hidden_status = subprocess.run(
|
|
3730
|
-
["git", "status", "--porcelain", "--", ".claude", ".codebuddy", ".agents", ".codex", ".prizmkit/state"],
|
|
3731
|
-
cwd=tmp_path,
|
|
3732
|
-
check=True,
|
|
3733
|
-
stdout=subprocess.PIPE,
|
|
3734
|
-
text=True,
|
|
3735
|
-
).stdout
|
|
3736
|
-
|
|
3737
|
-
assert result.committed is True
|
|
3738
|
-
assert committed_files == {"unstaged.txt"}
|
|
3739
|
-
assert ".claude" in hidden_status or ".prizmkit/state" in hidden_status
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
def test_preflight_ready_commit_rejects_unmerged_index(tmp_path):
|
|
3743
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3744
|
-
|
|
3745
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3746
|
-
subprocess.run(["git", "checkout", "-b", "other"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
3747
|
-
(tmp_path / "staged.txt").write_text("other\n", encoding="utf-8")
|
|
3748
|
-
subprocess.run(["git", "commit", "-am", "other"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
3749
|
-
subprocess.run(["git", "checkout", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
3750
|
-
(tmp_path / "staged.txt").write_text("main\n", encoding="utf-8")
|
|
3751
|
-
subprocess.run(["git", "commit", "-am", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
3752
|
-
subprocess.run(["git", "merge", "other"], cwd=tmp_path, check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
3753
|
-
before_count = _head_commit_count(tmp_path)
|
|
3754
|
-
|
|
3755
|
-
result = commit_preflight_ready_changes(tmp_path, "F-126")
|
|
3756
|
-
|
|
3757
|
-
assert result.attempted is True
|
|
3758
|
-
assert result.committed is False
|
|
3759
|
-
assert result.result is not None
|
|
3760
|
-
assert "unmerged Git paths" in result.result.stderr
|
|
3761
|
-
assert _head_commit_count(tmp_path) == before_count
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
def test_preflight_ready_commit_rejects_conflict_markers_and_malformed_manifest(tmp_path):
|
|
3765
|
-
from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
|
|
3766
|
-
|
|
3767
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3768
|
-
(tmp_path / "unstaged.txt").write_text("<<<<<<< Updated upstream\ncurrent\n=======\nstashed\n>>>>>>> Stashed changes\n", encoding="utf-8")
|
|
3769
|
-
|
|
3770
|
-
marker_result = commit_preflight_ready_changes(tmp_path, "F-127")
|
|
3771
|
-
|
|
3772
|
-
assert marker_result.committed is False
|
|
3773
|
-
assert marker_result.result is not None
|
|
3774
|
-
assert "unresolved conflict markers" in marker_result.result.stderr
|
|
3775
|
-
|
|
3776
|
-
(tmp_path / "unstaged.txt").write_text("safe\n", encoding="utf-8")
|
|
3777
|
-
manifest = tmp_path / ".prizmkit" / "manifest.json"
|
|
3778
|
-
manifest.parent.mkdir(parents=True, exist_ok=True)
|
|
3779
|
-
manifest.write_text("<<<<<<< Updated upstream\n{}\n", encoding="utf-8")
|
|
3780
|
-
|
|
3781
|
-
manifest_result = commit_preflight_ready_changes(tmp_path, "F-128")
|
|
3782
|
-
|
|
3783
|
-
assert manifest_result.committed is False
|
|
3784
|
-
assert manifest_result.result is not None
|
|
3785
|
-
assert ".prizmkit/manifest.json" in manifest_result.result.stderr
|
|
3786
|
-
assert "valid JSON" in manifest_result.result.stderr
|
|
3787
|
-
|
|
2873
|
+
stop = run_daemon_command("feature", "stop", (), paths)
|
|
3788
2874
|
|
|
3789
|
-
|
|
3790
|
-
|
|
2875
|
+
assert start.exit_code == snapshot["startExitCode"]
|
|
2876
|
+
assert start_payload["success"] is snapshot["startSuccess"]
|
|
2877
|
+
assert isinstance(start_payload["pid"], int)
|
|
2878
|
+
assert (paths.feature_state_dir / ".pipeline.pid").exists() is snapshot["pidFileExistsAfterStop"]
|
|
2879
|
+
assert status.exit_code == snapshot["statusWhileRunningExitCode"]
|
|
2880
|
+
assert status_payload["running"] is snapshot["statusWhileRunningReportsRunning"]
|
|
2881
|
+
assert isinstance(status_payload["pid"], int)
|
|
2882
|
+
assert status_payload["log_file"].endswith("pipeline-daemon.log")
|
|
2883
|
+
assert stop.exit_code == snapshot["stopExitCode"]
|
|
2884
|
+
assert json.loads(stop.render())["message"] in {"stopped", "already exited", "not running"}
|
|
2885
|
+
log_text = (paths.feature_state_dir / "pipeline-daemon.log").read_text(encoding="utf-8")
|
|
2886
|
+
assert "FOO=bar" in log_text or "payload env=bar" in log_text
|
|
2887
|
+
assert "payload live=0" in log_text
|
|
2888
|
+
assert "--project-root" in log_text
|
|
3791
2889
|
|
|
3792
|
-
_init_bookkeeping_repo(tmp_path)
|
|
3793
|
-
(tmp_path / ".claude" / "worktrees" / "agent").mkdir(parents=True)
|
|
3794
|
-
(tmp_path / ".claude" / "worktrees" / "agent" / "scratch.txt").write_text("hidden only\n", encoding="utf-8")
|
|
3795
|
-
before_count = _head_commit_count(tmp_path)
|
|
3796
2890
|
|
|
3797
|
-
|
|
2891
|
+
def test_python_reset_stalled_filter_selects_stalled_context_items(tmp_path):
|
|
2892
|
+
from prizmkit_runtime.reset import run_reset_command
|
|
3798
2893
|
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
2894
|
+
status_by_kind = {
|
|
2895
|
+
"feature": ("features", "F-001"),
|
|
2896
|
+
"bugfix": ("bugs", "B-001"),
|
|
2897
|
+
}
|
|
2898
|
+
for kind, (_collection, item_id) in status_by_kind.items():
|
|
2899
|
+
paths = _make_paths(tmp_path / f"stalled-{kind}")
|
|
2900
|
+
plan, _state_dir, status_file = _write_family_case(paths, kind, item_id)
|
|
2901
|
+
data = json.loads(plan.read_text(encoding="utf-8"))
|
|
2902
|
+
data[{"feature": "features", "bugfix": "bugs"}[kind]][0]["status"] = "stalled_context_continuation"
|
|
2903
|
+
plan.write_text(json.dumps(data), encoding="utf-8")
|
|
3802
2904
|
|
|
2905
|
+
result = run_reset_command(kind, ("--stalled", "--fresh-checkout"), paths)
|
|
3803
2906
|
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
("
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
)
|
|
3812
|
-
def test_process_item_creates_one_ready_commit_before_branch_setup_for_all_families(
|
|
3813
|
-
monkeypatch,
|
|
3814
|
-
tmp_path,
|
|
3815
|
-
kind,
|
|
3816
|
-
item_id,
|
|
3817
|
-
branch,
|
|
3818
|
-
):
|
|
3819
|
-
from prizmkit_runtime import runner_bookkeeping, runners
|
|
3820
|
-
from prizmkit_runtime.gitops import HIDDEN_TOOL_WORKTREE_EXCLUDES
|
|
3821
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2907
|
+
assert result.exit_code == 0
|
|
2908
|
+
assert f"Reset: {item_id}" in result.render()
|
|
2909
|
+
runtime = json.loads(status_file.read_text(encoding="utf-8"))
|
|
2910
|
+
assert runtime.get("retry_count") == 0
|
|
2911
|
+
assert "continuation_pending" not in runtime
|
|
2912
|
+
updated = json.loads(plan.read_text(encoding="utf-8"))
|
|
2913
|
+
assert updated[{"feature": "features", "bugfix": "bugs"}[kind]][0]["status"] == "pending"
|
|
3822
2914
|
|
|
3823
|
-
paths = _make_paths(tmp_path / kind)
|
|
3824
|
-
_init_bookkeeping_repo(paths.project_root)
|
|
3825
|
-
manifest_path = _track_manifest(paths.project_root)
|
|
3826
|
-
manifest_path.write_text('{"version":"ready"}\n', encoding="utf-8")
|
|
3827
|
-
(paths.project_root / "staged.txt").write_text("staged before run\n", encoding="utf-8")
|
|
3828
|
-
subprocess.run(["git", "add", "staged.txt"], cwd=paths.project_root, check=True)
|
|
3829
|
-
(paths.project_root / "unstaged.txt").write_text("unstaged before run\n", encoding="utf-8")
|
|
3830
|
-
(paths.project_root / "untracked.txt").write_text("untracked before run\n", encoding="utf-8")
|
|
3831
|
-
before_count = _head_commit_count(paths.project_root)
|
|
3832
|
-
branch_events = []
|
|
3833
2915
|
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": family.plan_path})
|
|
3838
|
-
_install_runner_session_fakes(monkeypatch, runners)
|
|
3839
|
-
monkeypatch.setattr(runners, "commit_preflight_ready_changes", runner_bookkeeping.commit_preflight_ready_changes)
|
|
2916
|
+
def test_python_daemon_progress_uses_list_status_without_runtime_files(tmp_path):
|
|
2917
|
+
from prizmkit_runtime.daemon import _progress_summary
|
|
2918
|
+
from prizmkit_runtime.runner_models import family_for
|
|
3840
2919
|
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
"
|
|
3847
|
-
"
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
stdout=subprocess.PIPE,
|
|
3852
|
-
text=True,
|
|
3853
|
-
).stdout,
|
|
3854
|
-
"visible_status": subprocess.run(
|
|
3855
|
-
["git", "status", "--porcelain", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES],
|
|
3856
|
-
cwd=project_root,
|
|
3857
|
-
check=True,
|
|
3858
|
-
stdout=subprocess.PIPE,
|
|
3859
|
-
text=True,
|
|
3860
|
-
).stdout,
|
|
3861
|
-
}
|
|
2920
|
+
for kind in ("feature", "bugfix"):
|
|
2921
|
+
paths = _make_paths(tmp_path / f"progress-{kind}")
|
|
2922
|
+
if kind == "feature":
|
|
2923
|
+
paths.feature_plan.write_text(
|
|
2924
|
+
json.dumps({"features": [
|
|
2925
|
+
{"id": "F-001", "title": "Done", "status": "completed"},
|
|
2926
|
+
{"id": "F-002", "title": "Failed", "status": "failed"},
|
|
2927
|
+
{"id": "F-003", "title": "Skipped", "status": "auto_skipped"},
|
|
2928
|
+
]}),
|
|
2929
|
+
encoding="utf-8",
|
|
3862
2930
|
)
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
"visible_status": "",
|
|
3876
|
-
}
|
|
3877
|
-
]
|
|
3878
|
-
assert _head_commit_count(paths.project_root) == before_count + 1
|
|
3879
|
-
assert {".prizmkit/manifest.json", "staged.txt", "unstaged.txt", "untracked.txt"}.issubset(
|
|
3880
|
-
_head_files(paths.project_root)
|
|
3881
|
-
)
|
|
3882
|
-
|
|
2931
|
+
plan = paths.feature_plan
|
|
2932
|
+
else:
|
|
2933
|
+
paths.bugfix_plan.write_text(
|
|
2934
|
+
json.dumps({"bugs": [
|
|
2935
|
+
{"id": "B-001", "title": "Done", "status": "completed"},
|
|
2936
|
+
{"id": "B-002", "title": "Failed", "status": "failed"},
|
|
2937
|
+
{"id": "B-003", "title": "Needs Info", "status": "needs_info"},
|
|
2938
|
+
{"id": "B-004", "title": "Blocked", "status": "auto_skipped"},
|
|
2939
|
+
]}),
|
|
2940
|
+
encoding="utf-8",
|
|
2941
|
+
)
|
|
2942
|
+
plan = paths.bugfix_plan
|
|
3883
2943
|
|
|
2944
|
+
summary = _progress_summary(family_for(kind, paths), plan)
|
|
3884
2945
|
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
2946
|
+
assert summary["total"] == (4 if kind == "bugfix" else 3)
|
|
2947
|
+
assert summary["completed"] == 1
|
|
2948
|
+
assert summary["failed"] == 1
|
|
2949
|
+
assert summary["percent"] == (25.0 if kind == "bugfix" else 33.3)
|
|
2950
|
+
if kind == "bugfix":
|
|
2951
|
+
assert summary["needs_info"] == 1
|
|
2952
|
+
assert summary["auto_skipped"] == 1
|
|
2953
|
+
else:
|
|
2954
|
+
assert summary["auto_skipped"] == 1
|
|
3889
2955
|
|
|
3890
|
-
monkeypatch.setenv("GIT_CONFIG_GLOBAL", str(tmp_path / "missing-global-gitconfig"))
|
|
3891
|
-
monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
|
|
3892
|
-
for key in ("GIT_AUTHOR_NAME", "GIT_AUTHOR_EMAIL", "GIT_COMMITTER_NAME", "GIT_COMMITTER_EMAIL"):
|
|
3893
|
-
monkeypatch.delenv(key, raising=False)
|
|
3894
|
-
paths = _make_paths(tmp_path)
|
|
3895
|
-
_init_bookkeeping_repo(paths.project_root, configure_identity=False)
|
|
3896
|
-
(paths.project_root / "new-visible.txt").write_text("dirty before run\n", encoding="utf-8")
|
|
3897
|
-
before_count = _head_commit_count(paths.project_root)
|
|
3898
|
-
branch_events = []
|
|
3899
2956
|
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
invocation = parse_invocation(family, "run", ())
|
|
3903
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
3904
|
-
_install_runner_session_fakes(monkeypatch, runners)
|
|
3905
|
-
monkeypatch.setattr(runners, "commit_preflight_ready_changes", runner_bookkeeping.commit_preflight_ready_changes)
|
|
2957
|
+
def test_session_status_parser_preserves_current_runtime_outcomes():
|
|
2958
|
+
import importlib.util
|
|
3906
2959
|
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
cwd=project_root,
|
|
3912
|
-
check=True,
|
|
3913
|
-
stdout=subprocess.PIPE,
|
|
3914
|
-
text=True,
|
|
3915
|
-
).stdout.strip()
|
|
3916
|
-
branch_events.append(
|
|
3917
|
-
{
|
|
3918
|
-
"commit_count": _head_commit_count(project_root),
|
|
3919
|
-
"message": _head_message(project_root),
|
|
3920
|
-
"author": author,
|
|
3921
|
-
"visible_status": subprocess.run(
|
|
3922
|
-
["git", "status", "--porcelain", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES],
|
|
3923
|
-
cwd=project_root,
|
|
3924
|
-
check=True,
|
|
3925
|
-
stdout=subprocess.PIPE,
|
|
3926
|
-
text=True,
|
|
3927
|
-
).stdout,
|
|
3928
|
-
}
|
|
3929
|
-
)
|
|
3930
|
-
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
2960
|
+
script = PIPELINE_ROOT / "scripts" / "check-session-status.py"
|
|
2961
|
+
spec = importlib.util.spec_from_file_location("check_session_status_contract", script)
|
|
2962
|
+
module = importlib.util.module_from_spec(spec)
|
|
2963
|
+
spec.loader.exec_module(module)
|
|
3931
2964
|
|
|
3932
|
-
|
|
2965
|
+
for status in (
|
|
2966
|
+
"infra_error",
|
|
2967
|
+
"stalled_context_continuation",
|
|
2968
|
+
"workflow_blocked",
|
|
2969
|
+
"workflow_skipped",
|
|
2970
|
+
):
|
|
2971
|
+
assert module.determine_status({"status": status}) == status
|
|
3933
2972
|
|
|
3934
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
3935
2973
|
|
|
3936
|
-
assert status == "completed"
|
|
3937
|
-
assert branch_events == [
|
|
3938
|
-
{
|
|
3939
|
-
"commit_count": before_count + 1,
|
|
3940
|
-
"message": "chore: ready for F-001",
|
|
3941
|
-
"author": f"{PIPELINE_FALLBACK_GIT_NAME} <{PIPELINE_FALLBACK_GIT_EMAIL}>",
|
|
3942
|
-
"visible_status": "",
|
|
3943
|
-
}
|
|
3944
|
-
]
|
|
3945
|
-
assert "new-visible.txt" in _head_files(paths.project_root)
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
def test_bookkeeping_commits_only_runner_owned_paths(tmp_path):
|
|
3949
|
-
from prizmkit_runtime.runner_bookkeeping import commit_final_bookkeeping
|
|
3950
|
-
from prizmkit_runtime.runner_models import RunnerFamily
|
|
3951
|
-
|
|
3952
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
3953
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
3954
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
3955
|
-
plans = tmp_path / ".prizmkit" / "plans"
|
|
3956
|
-
state = tmp_path / ".prizmkit" / "state" / "features"
|
|
3957
|
-
item_state = state / "F-001"
|
|
3958
|
-
plans.mkdir(parents=True)
|
|
3959
|
-
item_state.mkdir(parents=True)
|
|
3960
|
-
plan = plans / "feature-list.json"
|
|
3961
|
-
plan.write_text('{"features": []}', encoding="utf-8")
|
|
3962
|
-
(item_state / "status.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
|
|
3963
|
-
source = tmp_path / "src.txt"
|
|
3964
|
-
source.write_text("base", encoding="utf-8")
|
|
3965
|
-
subprocess.run(["git", "add", ".prizmkit/plans/feature-list.json", ".prizmkit/state/features/F-001/status.json", "src.txt"], cwd=tmp_path, check=True)
|
|
3966
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
3967
|
-
plan.write_text('{"features": [{"id": "F-001", "status": "completed"}]}', encoding="utf-8")
|
|
3968
|
-
(item_state / "status.json").write_text('{"last_session_id": "s1"}', encoding="utf-8")
|
|
3969
|
-
source.write_text("dirty source change", encoding="utf-8")
|
|
3970
|
-
family = RunnerFamily(
|
|
3971
|
-
kind="feature",
|
|
3972
|
-
id_prefix="F-",
|
|
3973
|
-
list_key="features",
|
|
3974
|
-
list_arg="--feature-list",
|
|
3975
|
-
item_id_arg="--feature-id",
|
|
3976
|
-
state_dir=state,
|
|
3977
|
-
plan_path=plan,
|
|
3978
|
-
updater_script=tmp_path / "update-feature-status.py",
|
|
3979
|
-
prompt_script=tmp_path / "generate-bootstrap-prompt.py",
|
|
3980
|
-
branch_prefix="dev",
|
|
3981
|
-
artifact_root_name="specs",
|
|
3982
|
-
)
|
|
3983
|
-
|
|
3984
|
-
result = commit_final_bookkeeping(tmp_path, family, "F-001", "completed")
|
|
3985
|
-
committed_files = subprocess.run(
|
|
3986
|
-
["git", "show", "--name-only", "--format=", "HEAD"],
|
|
3987
|
-
cwd=tmp_path,
|
|
3988
|
-
check=True,
|
|
3989
|
-
stdout=subprocess.PIPE,
|
|
3990
|
-
text=True,
|
|
3991
|
-
).stdout.splitlines()
|
|
3992
|
-
dirty_files = subprocess.run(
|
|
3993
|
-
["git", "status", "--porcelain", "--", "src.txt"],
|
|
3994
|
-
cwd=tmp_path,
|
|
3995
|
-
check=True,
|
|
3996
|
-
stdout=subprocess.PIPE,
|
|
3997
|
-
text=True,
|
|
3998
|
-
).stdout
|
|
3999
|
-
|
|
4000
|
-
assert result.committed is True
|
|
4001
|
-
assert committed_files == [".prizmkit/plans/feature-list.json", ".prizmkit/state/features/F-001/status.json"]
|
|
4002
|
-
assert dirty_files.startswith(" M src.txt")
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
def test_context_overflow_reuses_worktree_and_skips_cleanup_until_terminal_outcome(monkeypatch, tmp_path):
|
|
4006
|
-
from prizmkit_runtime import runners
|
|
4007
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
4008
|
-
|
|
4009
|
-
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
4010
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-test")
|
|
4011
|
-
paths = _make_paths(tmp_path)
|
|
4012
|
-
family = family_for("feature", paths)
|
|
4013
|
-
invocation = parse_invocation(family, "run", ())
|
|
4014
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
4015
|
-
observed = _install_runner_session_fakes(monkeypatch, runners, statuses=("context_overflow", "success"))
|
|
4016
|
-
sleep_calls = []
|
|
4017
|
-
monkeypatch.setattr(runners.time, "sleep", lambda seconds: sleep_calls.append(seconds))
|
|
4018
|
-
setup_calls = []
|
|
4019
|
-
monkeypatch.setattr(runners, "ensure_linked_worktree", lambda runtime: (setup_calls.append(runtime) or SimpleNamespace(ok=True, runtime=runtime, reason="")), raising=False)
|
|
4020
|
-
|
|
4021
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
4022
|
-
|
|
4023
|
-
assert status == "completed"
|
|
4024
|
-
assert len(setup_calls) == 1
|
|
4025
|
-
assert observed.launch_cwds[0] == observed.launch_cwds[1]
|
|
4026
|
-
assert observed.prompt_calls[0]["execution_root"] == observed.prompt_calls[1]["execution_root"]
|
|
4027
|
-
assert observed.prompt_calls[0].get("continuation") is None
|
|
4028
|
-
assert observed.prompt_calls[1]["continuation"]["previous_session_id"] == "F-001-session-1"
|
|
4029
|
-
assert observed.updates[0][0] == "context_overflow"
|
|
4030
|
-
assert sleep_calls == [5]
|
|
4031
|
-
assert len(observed.cleanup_calls) == 1
|
|
4032
|
-
assert observed.cleanup_calls[0][1] is True
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
def test_classification_accepts_late_infra_error_with_completed_checkpoint_and_commit(tmp_path):
|
|
4036
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4037
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
4038
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4039
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4040
|
-
|
|
4041
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4042
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
4043
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
4044
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
4045
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
4046
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4047
|
-
base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
4048
|
-
(tmp_path / "done.txt").write_text("done", encoding="utf-8")
|
|
4049
|
-
subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
|
|
4050
|
-
subprocess.run(["git", "commit", "-m", "done"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4051
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-done"
|
|
4052
|
-
checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
|
|
4053
|
-
log = tmp_path / "session.log"
|
|
4054
|
-
log.write_text("model quota exceeded; API error after commit", encoding="utf-8")
|
|
4055
|
-
raw = AISessionResult(
|
|
4056
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
4057
|
-
exit_code=1,
|
|
4058
|
-
timed_out=False,
|
|
4059
|
-
termination_reason=None,
|
|
4060
|
-
stale_marker=None,
|
|
4061
|
-
fatal_error_code="api_error",
|
|
4062
|
-
progress_summary=ProgressSummary(terminal_result_text="quota exceeded"),
|
|
4063
|
-
session_log=log,
|
|
4064
|
-
backup_log=tmp_path / "backup.log",
|
|
4065
|
-
log_recovery=None,
|
|
4066
|
-
started_epoch=0,
|
|
4067
|
-
ended_epoch=1,
|
|
4068
|
-
)
|
|
4069
|
-
prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", checkpoint_path=checkpoint, artifact_path=artifact_dir)
|
|
4070
|
-
|
|
4071
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
|
|
4072
|
-
|
|
4073
|
-
assert classification.session_status == "success"
|
|
4074
|
-
assert classification.reason == "semantic_checkpoint_with_late_runtime_error"
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
def test_classification_accepts_final_success_after_internal_stream_retry(tmp_path):
|
|
4078
|
-
import importlib.util
|
|
4079
|
-
|
|
4080
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4081
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
4082
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4083
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4084
|
-
|
|
4085
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4086
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
4087
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
4088
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
4089
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
4090
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4091
|
-
base_head = subprocess.run(
|
|
4092
|
-
["git", "rev-parse", "HEAD"],
|
|
4093
|
-
cwd=tmp_path,
|
|
4094
|
-
check=True,
|
|
4095
|
-
stdout=subprocess.PIPE,
|
|
4096
|
-
text=True,
|
|
4097
|
-
).stdout.strip()
|
|
4098
|
-
(tmp_path / "done.txt").write_text("done", encoding="utf-8")
|
|
4099
|
-
subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
|
|
4100
|
-
subprocess.run(
|
|
4101
|
-
["git", "commit", "-m", "done"],
|
|
4102
|
-
cwd=tmp_path,
|
|
4103
|
-
check=True,
|
|
4104
|
-
stdout=subprocess.DEVNULL,
|
|
4105
|
-
)
|
|
4106
|
-
artifact_dir = tmp_path / ".prizmkit" / "bugfix" / "B-004"
|
|
4107
|
-
checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir, "bugfix-pipeline")
|
|
4108
|
-
|
|
4109
|
-
parser_path = PIPELINE_ROOT / "scripts" / "parse-stream-progress.py"
|
|
4110
|
-
spec = importlib.util.spec_from_file_location("retry_progress_parser", parser_path)
|
|
4111
|
-
module = importlib.util.module_from_spec(spec)
|
|
4112
|
-
assert spec.loader is not None
|
|
4113
|
-
spec.loader.exec_module(module)
|
|
4114
|
-
tracker = module.ProgressTracker()
|
|
4115
|
-
events = [
|
|
4116
|
-
{"type": "session", "id": "pi-session"},
|
|
4117
|
-
{"type": "agent_start"},
|
|
4118
|
-
{"type": "message_end", "message": {"role": "assistant", "content": [], "stopReason": "error", "errorMessage": "Error Code internal_server_error: unexpected EOF"}},
|
|
4119
|
-
{"type": "agent_end", "willRetry": True, "messages": []},
|
|
4120
|
-
{"type": "auto_retry_start", "attempt": 1, "errorMessage": "Error Code internal_server_error: unexpected EOF"},
|
|
4121
|
-
{"type": "agent_start"},
|
|
4122
|
-
{"type": "auto_retry_end", "attempt": 1},
|
|
4123
|
-
{"type": "message_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "WORKFLOW_COMPLETED"}], "stopReason": "stop"}},
|
|
4124
|
-
{"type": "agent_end", "willRetry": False, "messages": [{"role": "assistant", "content": [{"type": "text", "text": "WORKFLOW_COMPLETED"}], "stopReason": "stop"}]},
|
|
4125
|
-
]
|
|
4126
|
-
for event in events:
|
|
4127
|
-
tracker.process_event(event)
|
|
4128
|
-
data = tracker.to_dict()
|
|
4129
|
-
log = tmp_path / "session.log"
|
|
4130
|
-
log.write_text("[ERROR] transient unexpected EOF\n[SESSION_END] status=success\n", encoding="utf-8")
|
|
4131
|
-
raw = AISessionResult(
|
|
4132
|
-
command=AISessionCommand(("fake",), None, "custom", "stdin"),
|
|
4133
|
-
exit_code=0,
|
|
4134
|
-
timed_out=False,
|
|
4135
|
-
termination_reason=None,
|
|
4136
|
-
stale_marker=None,
|
|
4137
|
-
fatal_error_code=str(data.get("fatal_error_code") or ""),
|
|
4138
|
-
progress_summary=ProgressSummary(
|
|
4139
|
-
result_subtype=str(data.get("result_subtype") or ""),
|
|
4140
|
-
stop_reason=str(data.get("stop_reason") or ""),
|
|
4141
|
-
fatal_error_code=str(data.get("fatal_error_code") or ""),
|
|
4142
|
-
terminal_result_text=str(data.get("terminal_result_text") or ""),
|
|
4143
|
-
errors=tuple(str(item) for item in data.get("errors", [])),
|
|
4144
|
-
),
|
|
4145
|
-
session_log=log,
|
|
4146
|
-
backup_log=tmp_path / "backup.log",
|
|
4147
|
-
log_recovery=None,
|
|
4148
|
-
started_epoch=0,
|
|
4149
|
-
ended_epoch=1,
|
|
4150
|
-
)
|
|
4151
|
-
|
|
4152
|
-
classification = classify_session(
|
|
4153
|
-
raw,
|
|
4154
|
-
project_root=tmp_path,
|
|
4155
|
-
base_head=base_head,
|
|
4156
|
-
prompt=PromptGenerationResult(
|
|
4157
|
-
output_path=tmp_path / "prompt.md",
|
|
4158
|
-
checkpoint_path=checkpoint,
|
|
4159
|
-
artifact_path=artifact_dir,
|
|
4160
|
-
),
|
|
4161
|
-
)
|
|
4162
|
-
|
|
4163
|
-
assert data["last_result_is_error"] is False
|
|
4164
|
-
assert any("unexpected EOF" in str(error) for error in data["errors"])
|
|
4165
|
-
assert classification.session_status == "success"
|
|
4166
|
-
assert classification.reason == "terminal_success_with_semantic_checkpoint"
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
def test_classification_rejects_late_infra_with_completion_summary_only(tmp_path):
|
|
4170
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4171
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
4172
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4173
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4174
|
-
|
|
4175
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4176
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
4177
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
4178
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
4179
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
4180
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4181
|
-
subprocess.run(["git", "checkout", "-b", "side"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4182
|
-
(tmp_path / "side.txt").write_text("side", encoding="utf-8")
|
|
4183
|
-
subprocess.run(["git", "add", "side.txt"], cwd=tmp_path, check=True)
|
|
4184
|
-
subprocess.run(["git", "commit", "-m", "side"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4185
|
-
side_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
4186
|
-
subprocess.run(["git", "checkout", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4187
|
-
(tmp_path / "main.txt").write_text("main", encoding="utf-8")
|
|
4188
|
-
subprocess.run(["git", "add", "main.txt"], cwd=tmp_path, check=True)
|
|
4189
|
-
subprocess.run(["git", "commit", "-m", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4190
|
-
subprocess.run(["git", "checkout", "side"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4191
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-done"
|
|
4192
|
-
artifact_dir.mkdir(parents=True)
|
|
4193
|
-
(artifact_dir / "completion-summary.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
|
|
4194
|
-
log = tmp_path / "session.log"
|
|
4195
|
-
log.write_text("quota exceeded", encoding="utf-8")
|
|
4196
|
-
raw = AISessionResult(
|
|
4197
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
4198
|
-
exit_code=1,
|
|
4199
|
-
timed_out=False,
|
|
4200
|
-
termination_reason=None,
|
|
4201
|
-
stale_marker=None,
|
|
4202
|
-
fatal_error_code="api_error",
|
|
4203
|
-
progress_summary=ProgressSummary(terminal_result_text="quota exceeded"),
|
|
4204
|
-
session_log=log,
|
|
4205
|
-
backup_log=tmp_path / "backup.log",
|
|
4206
|
-
log_recovery=None,
|
|
4207
|
-
started_epoch=0,
|
|
4208
|
-
ended_epoch=1,
|
|
4209
|
-
)
|
|
4210
|
-
prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", artifact_path=artifact_dir)
|
|
4211
|
-
|
|
4212
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=side_head, prompt=prompt)
|
|
4213
|
-
|
|
4214
|
-
assert classification.session_status == "infra_error"
|
|
4215
|
-
assert classification.reason == "ai_runtime_or_provider_error"
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
def test_classification_keeps_pre_completion_provider_error_as_infra_error(tmp_path):
|
|
4219
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4220
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4221
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4222
|
-
|
|
4223
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4224
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
4225
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
4226
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
4227
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
4228
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4229
|
-
base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
4230
|
-
log = tmp_path / "session.log"
|
|
4231
|
-
log.write_text("authentication failed", encoding="utf-8")
|
|
4232
|
-
raw = AISessionResult(
|
|
4233
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
4234
|
-
exit_code=1,
|
|
4235
|
-
timed_out=False,
|
|
4236
|
-
termination_reason=None,
|
|
4237
|
-
stale_marker=None,
|
|
4238
|
-
fatal_error_code="authentication_error",
|
|
4239
|
-
progress_summary=ProgressSummary(terminal_result_text="authentication failed"),
|
|
4240
|
-
session_log=log,
|
|
4241
|
-
backup_log=tmp_path / "backup.log",
|
|
4242
|
-
log_recovery=None,
|
|
4243
|
-
started_epoch=0,
|
|
4244
|
-
ended_epoch=1,
|
|
4245
|
-
)
|
|
4246
|
-
|
|
4247
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
|
|
4248
|
-
|
|
4249
|
-
assert classification.session_status == "infra_error"
|
|
4250
|
-
assert classification.reason == "ai_runtime_or_provider_error"
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
def test_classification_rejects_completed_checkpoint_without_runtime_git_receipt(tmp_path):
|
|
4254
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4255
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
4256
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4257
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4258
|
-
|
|
4259
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4260
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
4261
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
4262
|
-
(tmp_path / ".gitignore").write_text(".prizmkit/*\n", encoding="utf-8")
|
|
4263
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
4264
|
-
subprocess.run(["git", "add", ".gitignore", "base.txt"], cwd=tmp_path, check=True)
|
|
4265
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4266
|
-
base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
4267
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-done"
|
|
4268
|
-
checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
|
|
4269
|
-
(artifact_dir / "completion-summary.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
|
|
4270
|
-
log = tmp_path / "session.log"
|
|
4271
|
-
log.write_text("terminal success", encoding="utf-8")
|
|
4272
|
-
raw = AISessionResult(
|
|
4273
|
-
command=AISessionCommand(("fake",), None, "claude", "stdin"),
|
|
4274
|
-
exit_code=0,
|
|
4275
|
-
timed_out=False,
|
|
4276
|
-
termination_reason=None,
|
|
4277
|
-
stale_marker=None,
|
|
4278
|
-
fatal_error_code="",
|
|
4279
|
-
progress_summary=ProgressSummary(result_subtype="success", terminal_result_text="Completed; working tree clean"),
|
|
4280
|
-
session_log=log,
|
|
4281
|
-
backup_log=tmp_path / "backup.log",
|
|
4282
|
-
log_recovery=None,
|
|
4283
|
-
started_epoch=0,
|
|
4284
|
-
ended_epoch=1,
|
|
4285
|
-
)
|
|
4286
|
-
prompt = PromptGenerationResult(
|
|
4287
|
-
output_path=tmp_path / "prompt.md",
|
|
4288
|
-
checkpoint_path=checkpoint,
|
|
4289
|
-
artifact_path=artifact_dir,
|
|
4290
|
-
)
|
|
4291
|
-
|
|
4292
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
|
|
4293
|
-
assert classification.session_status == "commit_missing"
|
|
4294
|
-
assert classification.reason == "runtime_commit_receipt_mismatch"
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
def test_classification_preserves_success_before_context_overflow(tmp_path):
|
|
4298
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4299
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4300
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4301
|
-
|
|
4302
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4303
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
4304
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
4305
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
4306
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
4307
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4308
|
-
base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
4309
|
-
(tmp_path / "done.txt").write_text("done", encoding="utf-8")
|
|
4310
|
-
subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
|
|
4311
|
-
subprocess.run(["git", "commit", "-m", "done"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4312
|
-
log = tmp_path / "session.log"
|
|
4313
|
-
log.write_text("API Error: input exceeds the context window", encoding="utf-8")
|
|
4314
|
-
|
|
4315
|
-
raw = AISessionResult(
|
|
4316
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
4317
|
-
exit_code=1,
|
|
4318
|
-
timed_out=False,
|
|
4319
|
-
termination_reason=None,
|
|
4320
|
-
stale_marker=None,
|
|
4321
|
-
fatal_error_code="context_overflow",
|
|
4322
|
-
progress_summary=ProgressSummary(fatal_error_code="context_overflow"),
|
|
4323
|
-
session_log=log,
|
|
4324
|
-
backup_log=tmp_path / "backup.log",
|
|
4325
|
-
log_recovery=None,
|
|
4326
|
-
started_epoch=0,
|
|
4327
|
-
ended_epoch=1,
|
|
4328
|
-
)
|
|
4329
|
-
|
|
4330
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
|
|
4331
|
-
assert classification.session_status == "context_overflow"
|
|
4332
|
-
assert classification.reason == "context_overflow"
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
def test_classification_crash_with_commit_since_base_does_not_become_success(tmp_path):
|
|
4336
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4337
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4338
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4339
|
-
|
|
4340
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4341
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
4342
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
4343
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
4344
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
4345
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4346
|
-
base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
4347
|
-
(tmp_path / "done.txt").write_text("done", encoding="utf-8")
|
|
4348
|
-
subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
|
|
4349
|
-
subprocess.run(["git", "commit", "-m", "done"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4350
|
-
log = tmp_path / "session.log"
|
|
4351
|
-
log.write_text("hard failure", encoding="utf-8")
|
|
4352
|
-
raw = AISessionResult(
|
|
4353
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
4354
|
-
exit_code=1,
|
|
4355
|
-
timed_out=False,
|
|
4356
|
-
termination_reason=None,
|
|
4357
|
-
stale_marker=None,
|
|
4358
|
-
fatal_error_code="",
|
|
4359
|
-
progress_summary=ProgressSummary(terminal_result_text="hard failure"),
|
|
4360
|
-
session_log=log,
|
|
4361
|
-
backup_log=tmp_path / "backup.log",
|
|
4362
|
-
log_recovery=None,
|
|
4363
|
-
started_epoch=0,
|
|
4364
|
-
ended_epoch=1,
|
|
4365
|
-
)
|
|
4366
|
-
|
|
4367
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
|
|
4368
|
-
assert classification.session_status == "crashed"
|
|
4369
|
-
assert classification.reason == "exit_code=1"
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
def test_classification_stalls_after_repeated_no_progress_context_overflow(tmp_path):
|
|
4373
|
-
from prizmkit_runtime.runner_classification import classify_session, progress_fingerprint
|
|
4374
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4375
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4376
|
-
|
|
4377
|
-
log = tmp_path / "session.log"
|
|
4378
|
-
log.write_text("PRIZMKIT_FATAL_ERROR=context_overflow", encoding="utf-8")
|
|
4379
|
-
raw = AISessionResult(
|
|
4380
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
4381
|
-
exit_code=1,
|
|
4382
|
-
timed_out=False,
|
|
4383
|
-
termination_reason=None,
|
|
4384
|
-
stale_marker=None,
|
|
4385
|
-
fatal_error_code="context_overflow",
|
|
4386
|
-
progress_summary=ProgressSummary(fatal_error_code="context_overflow"),
|
|
4387
|
-
session_log=log,
|
|
4388
|
-
backup_log=tmp_path / "backup.log",
|
|
4389
|
-
log_recovery=None,
|
|
4390
|
-
started_epoch=0,
|
|
4391
|
-
ended_epoch=1,
|
|
4392
|
-
)
|
|
4393
|
-
previous = progress_fingerprint(tmp_path)
|
|
4394
|
-
|
|
4395
|
-
classification = classify_session(
|
|
4396
|
-
raw,
|
|
4397
|
-
project_root=tmp_path,
|
|
4398
|
-
base_head="",
|
|
4399
|
-
previous_fingerprint=previous,
|
|
4400
|
-
previous_no_progress_count=1,
|
|
4401
|
-
)
|
|
4402
|
-
|
|
4403
|
-
assert classification.session_status == "stalled_context_continuation"
|
|
4404
|
-
assert classification.no_progress_count == 2
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
def test_cli_family_status_uses_python_dispatch_not_transition_description(tmp_path):
|
|
4408
|
-
paths = _make_paths(tmp_path)
|
|
4409
|
-
_write_feature_list(paths)
|
|
4410
|
-
result = subprocess.run(
|
|
4411
|
-
[PYTHON_310_PLUS, str(CLI_PATH), "--project-root", str(paths.project_root), "status", "feature"],
|
|
4412
|
-
cwd=REPO_ROOT,
|
|
4413
|
-
stdout=subprocess.PIPE,
|
|
4414
|
-
stderr=subprocess.PIPE,
|
|
4415
|
-
text=True,
|
|
4416
|
-
check=False,
|
|
4417
|
-
)
|
|
4418
|
-
|
|
4419
|
-
assert result.returncode == 0
|
|
4420
|
-
assert "Python feature status" in result.stdout
|
|
4421
|
-
assert "Transition command contract" not in result.stdout
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
def _write_family_case(paths, kind, item_id=""):
|
|
4425
|
-
item_id = item_id or {"feature": "F-001", "bugfix": "B-001", "refactor": "R-001"}[kind]
|
|
4426
|
-
if kind == "feature":
|
|
4427
|
-
paths.feature_plan.write_text(json.dumps({"features": [{"id": item_id, "title": "Reset Thing", "status": "failed", "dependencies": []}]}), encoding="utf-8")
|
|
4428
|
-
state_dir = paths.feature_state_dir
|
|
4429
|
-
plan = paths.feature_plan
|
|
4430
|
-
elif kind == "bugfix":
|
|
4431
|
-
paths.bugfix_plan.write_text(json.dumps({"bugs": [{"id": item_id, "title": "Reset Bug", "description": "d", "severity": "medium", "priority": "medium", "status": "failed"}]}), encoding="utf-8")
|
|
4432
|
-
state_dir = paths.bugfix_state_dir
|
|
4433
|
-
plan = paths.bugfix_plan
|
|
4434
|
-
else:
|
|
4435
|
-
paths.refactor_plan.write_text(json.dumps({"refactors": [{"id": item_id, "title": "Reset Refactor", "description": "d", "complexity": "medium", "priority": "medium", "status": "failed", "dependencies": []}]}), encoding="utf-8")
|
|
4436
|
-
state_dir = paths.refactor_state_dir
|
|
4437
|
-
plan = paths.refactor_plan
|
|
4438
|
-
state_dir.mkdir(parents=True, exist_ok=True)
|
|
4439
|
-
(state_dir / "pipeline.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
|
|
4440
|
-
item_state = state_dir / item_id
|
|
4441
|
-
item_state.mkdir(parents=True, exist_ok=True)
|
|
4442
|
-
(item_state / "status.json").write_text(
|
|
4443
|
-
json.dumps(
|
|
4444
|
-
{
|
|
4445
|
-
"status": "in_progress",
|
|
4446
|
-
"retry_count": 2,
|
|
4447
|
-
"infra_error_count": 1,
|
|
4448
|
-
"last_infra_error_session_id": "infra-1",
|
|
4449
|
-
"last_session_id": "sess-1",
|
|
4450
|
-
"sessions": ["sess-1"],
|
|
4451
|
-
"continuation_pending": True,
|
|
4452
|
-
"continuation_reason": "context_overflow",
|
|
4453
|
-
"active_dev_branch": f"{kind}/{item_id}-branch",
|
|
4454
|
-
"continuation_summary_path": str(paths.project_root / ".prizmkit" / ("specs" if kind == "feature" else kind) / item_id / "continuation-summary.md"),
|
|
4455
|
-
}
|
|
4456
|
-
),
|
|
4457
|
-
encoding="utf-8",
|
|
4458
|
-
)
|
|
4459
|
-
return plan, state_dir, item_state / "status.json"
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
def test_python_reset_warns_before_mutation_and_matches_snapshot_cleanup(tmp_path):
|
|
4463
|
-
from prizmkit_runtime.reset import run_reset_command
|
|
4464
|
-
from prizmkit_runtime.runner_models import family_for
|
|
4465
|
-
from prizmkit_runtime.task_checkout import load_task_checkout
|
|
4466
|
-
|
|
4467
|
-
snapshot = json.loads((REPO_ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json").read_text(encoding="utf-8"))
|
|
4468
|
-
for kind, item_id in [("feature", "F-001"), ("bugfix", "B-001"), ("refactor", "R-001")]:
|
|
4469
|
-
paths = _make_paths(tmp_path / kind)
|
|
4470
|
-
_plan, _state_dir, status_file = _write_family_case(paths, kind, item_id)
|
|
4471
|
-
result = run_reset_command(kind, (item_id, "--fresh-checkout"), paths)
|
|
4472
|
-
output = result.render()
|
|
4473
|
-
reset_marker = f"Resetting {item_id} status"
|
|
4474
|
-
|
|
4475
|
-
assert result.exit_code == snapshot["resetBehavior"]["manualResetWarningOrder"][kind]["exitCode"]
|
|
4476
|
-
assert "Continuation pending" in output
|
|
4477
|
-
assert "Pending continuation branch" in output
|
|
4478
|
-
assert output.index("Continuation pending") < output.index(reset_marker)
|
|
4479
|
-
runtime = json.loads(status_file.read_text(encoding="utf-8"))
|
|
4480
|
-
expected_runtime = snapshot["statusUpdaterBehavior"]["resetCleanMetadataCleanup"][kind]["reset"]["runtime"]
|
|
4481
|
-
for key, value in expected_runtime.items():
|
|
4482
|
-
assert runtime.get(key) == value
|
|
4483
|
-
assert "continuation_pending" not in runtime
|
|
4484
|
-
family = family_for(kind, paths)
|
|
4485
|
-
checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
|
|
4486
|
-
assert checkout is not None
|
|
4487
|
-
assert checkout.is_reset
|
|
4488
|
-
assert checkout.active_dev_branch == ""
|
|
4489
|
-
assert checkout.base_branch == ""
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
def test_python_reset_cleans_authoritative_custom_branch_before_reset_marker(monkeypatch, tmp_path):
|
|
4493
|
-
from prizmkit_runtime import reset as reset_runtime
|
|
4494
|
-
from prizmkit_runtime.reset import run_reset_command
|
|
4495
|
-
from prizmkit_runtime.runner_models import family_for
|
|
4496
|
-
from prizmkit_runtime.task_checkout import TaskCheckout, load_task_checkout, persist_task_checkout
|
|
4497
|
-
|
|
4498
|
-
paths = _make_paths(tmp_path)
|
|
4499
|
-
_write_family_case(paths, "feature", "F-001")
|
|
4500
|
-
family = family_for("feature", paths)
|
|
4501
|
-
custom_branch = "custom/feature-checkout"
|
|
4502
|
-
persist_task_checkout(family.state_dir, TaskCheckout.active("feature", "F-001", custom_branch, "main"))
|
|
4503
|
-
cleanup_calls = []
|
|
4504
|
-
|
|
4505
|
-
monkeypatch.setattr(reset_runtime, "list_reset_branches", lambda *args: ())
|
|
4506
|
-
monkeypatch.setattr(
|
|
4507
|
-
reset_runtime,
|
|
4508
|
-
"reset_cleanup_branch",
|
|
4509
|
-
lambda project_root, branch, *, return_branch, delete: cleanup_calls.append((branch, delete))
|
|
4510
|
-
or SimpleNamespace(branch=branch, cleaned=True, deleted=False, returned_to=return_branch, warnings=()),
|
|
4511
|
-
)
|
|
4512
|
-
|
|
4513
|
-
result = run_reset_command("feature", ("F-001", "--fresh-checkout"), paths)
|
|
4514
|
-
|
|
4515
|
-
assert result.exit_code == 0
|
|
4516
|
-
assert cleanup_calls == [(custom_branch, False)]
|
|
4517
|
-
checkout = load_task_checkout(family.state_dir, family.task_type, "F-001")
|
|
4518
|
-
assert checkout is not None and checkout.is_reset
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
def test_python_reset_failure_keeps_authoritative_checkout_active(monkeypatch, tmp_path):
|
|
4522
|
-
from prizmkit_runtime import reset as reset_runtime
|
|
4523
|
-
from prizmkit_runtime.reset import run_reset_command
|
|
4524
|
-
from prizmkit_runtime.runner_models import family_for
|
|
4525
|
-
from prizmkit_runtime.task_checkout import TaskCheckout, load_task_checkout, persist_task_checkout
|
|
4526
|
-
|
|
4527
|
-
paths = _make_paths(tmp_path)
|
|
4528
|
-
_write_family_case(paths, "feature", "F-001")
|
|
4529
|
-
family = family_for("feature", paths)
|
|
4530
|
-
checkout = TaskCheckout.active("feature", "F-001", "custom/feature-checkout", "main")
|
|
4531
|
-
persist_task_checkout(family.state_dir, checkout)
|
|
4532
|
-
monkeypatch.setattr(reset_runtime, "list_reset_branches", lambda *args: ())
|
|
4533
|
-
monkeypatch.setattr(
|
|
4534
|
-
reset_runtime,
|
|
4535
|
-
"reset_cleanup_branch",
|
|
4536
|
-
lambda *args, **kwargs: SimpleNamespace(
|
|
4537
|
-
branch="custom/feature-checkout",
|
|
4538
|
-
cleaned=False,
|
|
4539
|
-
deleted=False,
|
|
4540
|
-
returned_to="main",
|
|
4541
|
-
warnings=("could not checkout custom/feature-checkout",),
|
|
4542
|
-
),
|
|
4543
|
-
)
|
|
4544
|
-
|
|
4545
|
-
result = run_reset_command("feature", ("F-001", "--fresh-checkout"), paths)
|
|
4546
|
-
|
|
4547
|
-
assert result.exit_code == 1
|
|
4548
|
-
assert load_task_checkout(family.state_dir, family.task_type, "F-001") == checkout
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
def test_python_clean_reset_deletes_continuation_artifacts_for_all_families(tmp_path):
|
|
4552
|
-
from prizmkit_runtime.reset import run_reset_command
|
|
4553
|
-
|
|
4554
|
-
snapshot = json.loads((REPO_ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json").read_text(encoding="utf-8"))
|
|
4555
|
-
cases = [("feature", "F-001", "specs", "001-reset-thing"), ("bugfix", "B-001", "bugfix", "B-001"), ("refactor", "R-001", "refactor", "R-001")]
|
|
4556
|
-
for kind, item_id, artifact_root, artifact_name in cases:
|
|
4557
|
-
paths = _make_paths(tmp_path / f"clean-{kind}")
|
|
4558
|
-
_plan, _state_dir, status_file = _write_family_case(paths, kind, item_id)
|
|
4559
|
-
artifact_dir = paths.project_root / ".prizmkit" / artifact_root / artifact_name
|
|
4560
|
-
artifact_dir.mkdir(parents=True, exist_ok=True)
|
|
4561
|
-
continuation = artifact_dir / "continuation-summary.md"
|
|
4562
|
-
continuation.write_text("summary", encoding="utf-8")
|
|
4563
|
-
args = (item_id, "--clean")
|
|
4564
|
-
result = run_reset_command(kind, args, paths)
|
|
4565
|
-
|
|
4566
|
-
assert result.exit_code == snapshot["resetBehavior"]["cleanResetDeletesContinuationArtifacts"][kind]["exitCode"]
|
|
4567
|
-
assert continuation.exists() is False
|
|
4568
|
-
runtime = json.loads(status_file.read_text(encoding="utf-8"))
|
|
4569
|
-
assert runtime.get("retry_count") == 0
|
|
4570
|
-
assert runtime.get("infra_error_count") == 0
|
|
4571
|
-
assert "continuation_pending" not in runtime
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
def test_python_context_overflow_runner_path_does_not_import_reset():
|
|
4575
|
-
runner_text = (PIPELINE_ROOT / "prizmkit_runtime" / "runners.py").read_text(encoding="utf-8")
|
|
4576
|
-
|
|
4577
|
-
assert "from .reset" not in runner_text
|
|
4578
|
-
assert "run_reset_command" not in runner_text
|
|
4579
|
-
assert '"context_overflow"' in runner_text
|
|
4580
|
-
assert "update_item" in runner_text
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
def test_python_daemon_stale_pid_matches_snapshot(tmp_path):
|
|
4584
|
-
from prizmkit_runtime.daemon import run_daemon_command
|
|
4585
|
-
|
|
4586
|
-
snapshot = json.loads((REPO_ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json").read_text(encoding="utf-8"))
|
|
4587
|
-
for kind in ("feature", "bugfix", "refactor"):
|
|
4588
|
-
paths = _make_paths(tmp_path / f"daemon-{kind}")
|
|
4589
|
-
family_state = {"feature": paths.feature_state_dir, "bugfix": paths.bugfix_state_dir, "refactor": paths.refactor_state_dir}[kind]
|
|
4590
|
-
family_state.mkdir(parents=True, exist_ok=True)
|
|
4591
|
-
pid_file = family_state / ".pipeline.pid"
|
|
4592
|
-
pid_file.write_text("999999\n", encoding="utf-8")
|
|
4593
|
-
result = run_daemon_command(kind, "status", (), paths)
|
|
4594
|
-
expected = snapshot["daemonBehavior"]["stalePidStatusByTaskType"][kind]
|
|
4595
|
-
|
|
4596
|
-
assert result.exit_code == expected["exitCode"]
|
|
4597
|
-
assert json.loads(result.render())["running"] is False
|
|
4598
|
-
assert pid_file.exists() is False
|
|
4599
|
-
assert "Cleaned stale PID file" in (result.stderr or "")
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
def test_python_daemon_controlled_start_status_stop_matches_snapshot(tmp_path):
|
|
4603
|
-
from prizmkit_runtime.daemon import run_daemon_command
|
|
4604
|
-
from prizmkit_runtime.paths import resolve_runtime_paths
|
|
4605
|
-
|
|
4606
|
-
snapshot = json.loads((REPO_ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json").read_text(encoding="utf-8"))["daemonBehavior"]["controlledStartStop"]
|
|
4607
|
-
project = tmp_path / "project"
|
|
4608
|
-
pipeline = tmp_path / "runtime"
|
|
4609
|
-
pipeline.mkdir(parents=True)
|
|
4610
|
-
cli = pipeline / "cli.py"
|
|
4611
|
-
cli.write_text(
|
|
4612
|
-
"#!/usr/bin/env python3\n"
|
|
4613
|
-
"import os, sys, time\n"
|
|
4614
|
-
"print('payload env=' + os.environ.get('FOO', ''))\n"
|
|
4615
|
-
"print('payload live=' + os.environ.get('PRIZMKIT_LIVE_OUTPUT', ''))\n"
|
|
4616
|
-
"print('payload args=' + ' '.join(sys.argv[1:]))\n"
|
|
4617
|
-
"sys.stdout.flush()\n"
|
|
4618
|
-
"time.sleep(30)\n",
|
|
4619
|
-
encoding="utf-8",
|
|
4620
|
-
)
|
|
4621
|
-
cli.chmod(0o755)
|
|
4622
|
-
paths = resolve_runtime_paths(pipeline_root=pipeline, project_root=project)
|
|
4623
|
-
paths.plans_dir.mkdir(parents=True)
|
|
4624
|
-
paths.feature_plan.write_text(json.dumps({"features": [{"id": "F-001", "title": "A", "status": "pending"}]}), encoding="utf-8")
|
|
4625
|
-
|
|
4626
|
-
start = run_daemon_command("feature", "start", ("--env", "FOO=bar", "--features", "F-001"), paths)
|
|
4627
|
-
try:
|
|
4628
|
-
start_payload = json.loads(start.render())
|
|
4629
|
-
status = run_daemon_command("feature", "status", (), paths)
|
|
4630
|
-
status_payload = json.loads(status.render())
|
|
4631
|
-
finally:
|
|
4632
|
-
stop = run_daemon_command("feature", "stop", (), paths)
|
|
4633
|
-
|
|
4634
|
-
assert start.exit_code == snapshot["startExitCode"]
|
|
4635
|
-
assert start_payload["success"] is snapshot["startSuccess"]
|
|
4636
|
-
assert isinstance(start_payload["pid"], int)
|
|
4637
|
-
assert (paths.feature_state_dir / ".pipeline.pid").exists() is snapshot["pidFileExistsAfterStop"]
|
|
4638
|
-
assert status.exit_code == snapshot["statusWhileRunningExitCode"]
|
|
4639
|
-
assert status_payload["running"] is snapshot["statusWhileRunningReportsRunning"]
|
|
4640
|
-
assert isinstance(status_payload["pid"], int)
|
|
4641
|
-
assert status_payload["log_file"].endswith("pipeline-daemon.log")
|
|
4642
|
-
assert stop.exit_code == snapshot["stopExitCode"]
|
|
4643
|
-
assert json.loads(stop.render())["message"] in {"stopped", "already exited", "not running"}
|
|
4644
|
-
log_text = (paths.feature_state_dir / "pipeline-daemon.log").read_text(encoding="utf-8")
|
|
4645
|
-
assert "FOO=bar" in log_text or "payload env=bar" in log_text
|
|
4646
|
-
assert "payload live=0" in log_text
|
|
4647
|
-
assert "--project-root" in log_text
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
def test_python_reset_stalled_filter_selects_stalled_context_items(tmp_path):
|
|
4651
|
-
from prizmkit_runtime.reset import run_reset_command
|
|
4652
|
-
|
|
4653
|
-
status_by_kind = {
|
|
4654
|
-
"feature": ("features", "F-001"),
|
|
4655
|
-
"bugfix": ("bugs", "B-001"),
|
|
4656
|
-
"refactor": ("refactors", "R-001"),
|
|
4657
|
-
}
|
|
4658
|
-
for kind, (_collection, item_id) in status_by_kind.items():
|
|
4659
|
-
paths = _make_paths(tmp_path / f"stalled-{kind}")
|
|
4660
|
-
plan, _state_dir, status_file = _write_family_case(paths, kind, item_id)
|
|
4661
|
-
data = json.loads(plan.read_text(encoding="utf-8"))
|
|
4662
|
-
data[{"feature": "features", "bugfix": "bugs", "refactor": "refactors"}[kind]][0]["status"] = "stalled_context_continuation"
|
|
4663
|
-
plan.write_text(json.dumps(data), encoding="utf-8")
|
|
4664
|
-
|
|
4665
|
-
result = run_reset_command(kind, ("--stalled", "--fresh-checkout"), paths)
|
|
4666
|
-
|
|
4667
|
-
assert result.exit_code == 0
|
|
4668
|
-
assert f"Reset: {item_id}" in result.render()
|
|
4669
|
-
runtime = json.loads(status_file.read_text(encoding="utf-8"))
|
|
4670
|
-
assert runtime.get("retry_count") == 0
|
|
4671
|
-
assert "continuation_pending" not in runtime
|
|
4672
|
-
updated = json.loads(plan.read_text(encoding="utf-8"))
|
|
4673
|
-
assert updated[{"feature": "features", "bugfix": "bugs", "refactor": "refactors"}[kind]][0]["status"] == "pending"
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
def test_python_daemon_progress_uses_list_status_without_runtime_files(tmp_path):
|
|
4677
|
-
from prizmkit_runtime.daemon import _progress_summary
|
|
4678
|
-
from prizmkit_runtime.runner_models import family_for
|
|
4679
|
-
|
|
4680
|
-
for kind in ("feature", "bugfix", "refactor"):
|
|
4681
|
-
paths = _make_paths(tmp_path / f"progress-{kind}")
|
|
4682
|
-
if kind == "feature":
|
|
4683
|
-
paths.feature_plan.write_text(
|
|
4684
|
-
json.dumps({"features": [
|
|
4685
|
-
{"id": "F-001", "title": "Done", "status": "completed"},
|
|
4686
|
-
{"id": "F-002", "title": "Failed", "status": "failed"},
|
|
4687
|
-
{"id": "F-003", "title": "Skipped", "status": "auto_skipped"},
|
|
4688
|
-
]}),
|
|
4689
|
-
encoding="utf-8",
|
|
4690
|
-
)
|
|
4691
|
-
plan = paths.feature_plan
|
|
4692
|
-
elif kind == "bugfix":
|
|
4693
|
-
paths.bugfix_plan.write_text(
|
|
4694
|
-
json.dumps({"bugs": [
|
|
4695
|
-
{"id": "B-001", "title": "Done", "status": "completed"},
|
|
4696
|
-
{"id": "B-002", "title": "Failed", "status": "failed"},
|
|
4697
|
-
{"id": "B-003", "title": "Needs Info", "status": "needs_info"},
|
|
4698
|
-
{"id": "B-004", "title": "Blocked", "status": "auto_skipped"},
|
|
4699
|
-
]}),
|
|
4700
|
-
encoding="utf-8",
|
|
4701
|
-
)
|
|
4702
|
-
plan = paths.bugfix_plan
|
|
4703
|
-
else:
|
|
4704
|
-
paths.refactor_plan.write_text(
|
|
4705
|
-
json.dumps({"refactors": [
|
|
4706
|
-
{"id": "R-001", "title": "Done", "status": "completed"},
|
|
4707
|
-
{"id": "R-002", "title": "Failed", "status": "failed"},
|
|
4708
|
-
{"id": "R-003", "title": "Skipped", "status": "auto_skipped"},
|
|
4709
|
-
]}),
|
|
4710
|
-
encoding="utf-8",
|
|
4711
|
-
)
|
|
4712
|
-
plan = paths.refactor_plan
|
|
4713
|
-
|
|
4714
|
-
summary = _progress_summary(family_for(kind, paths), plan)
|
|
4715
|
-
|
|
4716
|
-
assert summary["total"] == (4 if kind == "bugfix" else 3)
|
|
4717
|
-
assert summary["completed"] == 1
|
|
4718
|
-
assert summary["failed"] == 1
|
|
4719
|
-
assert summary["percent"] == (25.0 if kind == "bugfix" else 33.3)
|
|
4720
|
-
if kind == "bugfix":
|
|
4721
|
-
assert summary["needs_info"] == 1
|
|
4722
|
-
assert summary["auto_skipped"] == 1
|
|
4723
|
-
else:
|
|
4724
|
-
assert summary["auto_skipped"] == 1
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
def _init_git_repo_for_invalid_checkpoint_test(tmp_path):
|
|
4729
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4730
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
4731
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
4732
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
4733
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
4734
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
4735
|
-
return subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
def _terminal_success_result(tmp_path):
|
|
4739
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4740
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4741
|
-
|
|
4742
|
-
log = tmp_path / "session.log"
|
|
4743
|
-
log.write_text("terminal success", encoding="utf-8")
|
|
4744
|
-
return AISessionResult(
|
|
4745
|
-
command=AISessionCommand(("fake",), None, "claude", "stdin"),
|
|
4746
|
-
exit_code=0,
|
|
4747
|
-
timed_out=False,
|
|
4748
|
-
termination_reason=None,
|
|
4749
|
-
stale_marker=None,
|
|
4750
|
-
fatal_error_code="",
|
|
4751
|
-
progress_summary=ProgressSummary(result_subtype="success", terminal_result_text="Completed"),
|
|
4752
|
-
session_log=log,
|
|
4753
|
-
backup_log=tmp_path / "backup.log",
|
|
4754
|
-
log_recovery=None,
|
|
4755
|
-
started_epoch=0,
|
|
4756
|
-
ended_epoch=1,
|
|
4757
|
-
)
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
def test_session_status_parser_preserves_current_runtime_outcomes():
|
|
4761
|
-
import importlib.util
|
|
4762
|
-
|
|
4763
|
-
script = PIPELINE_ROOT / "scripts" / "check-session-status.py"
|
|
4764
|
-
spec = importlib.util.spec_from_file_location("check_session_status_contract", script)
|
|
4765
|
-
module = importlib.util.module_from_spec(spec)
|
|
4766
|
-
spec.loader.exec_module(module)
|
|
4767
|
-
|
|
4768
|
-
for status in (
|
|
4769
|
-
"infra_error",
|
|
4770
|
-
"stalled_context_continuation",
|
|
4771
|
-
"workflow_blocked",
|
|
4772
|
-
"workflow_skipped",
|
|
4773
|
-
):
|
|
4774
|
-
assert module.determine_status({"status": status}) == status
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
def test_terminal_success_without_semantic_completion_is_skipped(tmp_path):
|
|
4778
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4779
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
4780
|
-
|
|
4781
|
-
base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
|
|
4782
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-incomplete"
|
|
4783
|
-
checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
|
|
4784
|
-
payload = json.loads(checkpoint.read_text(encoding="utf-8"))
|
|
4785
|
-
payload["steps"][2]["required_artifacts"] = [
|
|
4786
|
-
".prizmkit/specs/001-incomplete/test-report.md",
|
|
4787
|
-
".prizmkit/specs/001-incomplete/missing-test-result.json",
|
|
4788
|
-
]
|
|
4789
|
-
checkpoint.write_text(json.dumps(payload), encoding="utf-8")
|
|
4790
|
-
prompt = PromptGenerationResult(
|
|
4791
|
-
output_path=tmp_path / "prompt.md",
|
|
4792
|
-
checkpoint_path=checkpoint,
|
|
4793
|
-
artifact_path=artifact_dir,
|
|
4794
|
-
)
|
|
4795
|
-
|
|
4796
|
-
classification = classify_session(
|
|
4797
|
-
_terminal_success_result(tmp_path),
|
|
4798
|
-
project_root=tmp_path,
|
|
4799
|
-
base_head=base_head,
|
|
4800
|
-
prompt=prompt,
|
|
4801
|
-
)
|
|
4802
|
-
|
|
4803
|
-
assert classification.session_status == "workflow_skipped"
|
|
4804
|
-
assert classification.reason == "no_semantic_completion:incomplete_semantic_evidence"
|
|
4805
|
-
assert classification.fatal_error_code == ""
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
def test_pi_length_stop_with_nonzero_exit_uses_bounded_crash_path(tmp_path):
|
|
4809
|
-
from dataclasses import replace
|
|
4810
|
-
|
|
4811
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4812
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4813
|
-
|
|
4814
|
-
base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
|
|
4815
|
-
raw = replace(
|
|
4816
|
-
_terminal_success_result(tmp_path),
|
|
4817
|
-
exit_code=143,
|
|
4818
|
-
progress_summary=ProgressSummary(result_subtype="success", stop_reason="length"),
|
|
4819
|
-
)
|
|
4820
|
-
|
|
4821
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
|
|
4822
|
-
|
|
4823
|
-
assert classification.session_status == "crashed"
|
|
4824
|
-
assert classification.reason == "exit_code=143"
|
|
4825
|
-
assert classification.fatal_error_code == ""
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
def test_pi_length_stop_with_zero_exit_and_no_checkpoint_uses_recoverable_continuation(tmp_path):
|
|
4829
|
-
from dataclasses import replace
|
|
4830
|
-
|
|
4831
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4832
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4833
|
-
|
|
4834
|
-
base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
|
|
4835
|
-
raw = replace(
|
|
4836
|
-
_terminal_success_result(tmp_path),
|
|
4837
|
-
progress_summary=ProgressSummary(result_subtype="success", stop_reason="length"),
|
|
4838
|
-
)
|
|
4839
|
-
|
|
4840
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head)
|
|
4841
|
-
|
|
4842
|
-
assert classification.session_status == "context_overflow"
|
|
4843
|
-
assert classification.reason == "context_overflow"
|
|
4844
|
-
assert classification.fatal_error_code == "context_overflow"
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
def test_pi_length_stop_with_in_progress_checkpoint_uses_recoverable_continuation(tmp_path):
|
|
4848
|
-
from dataclasses import replace
|
|
4849
|
-
|
|
4850
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4851
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
4852
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4853
|
-
|
|
4854
|
-
base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
|
|
4855
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-length-in-progress"
|
|
4856
|
-
artifact_dir.mkdir(parents=True)
|
|
4857
|
-
checkpoint = artifact_dir / "workflow-checkpoint.json"
|
|
4858
|
-
checkpoint.write_text(
|
|
4859
|
-
json.dumps({
|
|
4860
|
-
"version": 1,
|
|
4861
|
-
"workflow_type": "feature-pipeline",
|
|
4862
|
-
"steps": [
|
|
4863
|
-
{
|
|
4864
|
-
"id": "S01",
|
|
4865
|
-
"skill": "context-snapshot-and-plan",
|
|
4866
|
-
"name": "Specify & Plan",
|
|
4867
|
-
"status": "completed",
|
|
4868
|
-
"required_artifacts": [],
|
|
4869
|
-
"depends_on": None,
|
|
4870
|
-
"stage_result": "PLAN_READY",
|
|
4871
|
-
},
|
|
4872
|
-
{
|
|
4873
|
-
"id": "S02",
|
|
4874
|
-
"skill": "prizmkit-implement",
|
|
4875
|
-
"name": "Implement",
|
|
4876
|
-
"status": "completed",
|
|
4877
|
-
"required_artifacts": [],
|
|
4878
|
-
"depends_on": "S01",
|
|
4879
|
-
"stage_result": "IMPLEMENTED",
|
|
4880
|
-
},
|
|
4881
|
-
{
|
|
4882
|
-
"id": "S03",
|
|
4883
|
-
"skill": "prizmkit-code-review",
|
|
4884
|
-
"name": "Code Review",
|
|
4885
|
-
"status": "in_progress",
|
|
4886
|
-
"required_artifacts": [],
|
|
4887
|
-
"depends_on": "S02",
|
|
4888
|
-
},
|
|
4889
|
-
{
|
|
4890
|
-
"id": "S04",
|
|
4891
|
-
"skill": "prizmkit-test",
|
|
4892
|
-
"name": "Test",
|
|
4893
|
-
"status": "pending",
|
|
4894
|
-
"required_artifacts": [],
|
|
4895
|
-
"depends_on": "S03",
|
|
4896
|
-
},
|
|
4897
|
-
{
|
|
4898
|
-
"id": "S05",
|
|
4899
|
-
"skill": "completion-summary",
|
|
4900
|
-
"name": "Completion Summary",
|
|
4901
|
-
"status": "pending",
|
|
4902
|
-
"required_artifacts": [],
|
|
4903
|
-
"depends_on": "S04",
|
|
4904
|
-
},
|
|
4905
|
-
{
|
|
4906
|
-
"id": "S06",
|
|
4907
|
-
"skill": "prizmkit-retrospective",
|
|
4908
|
-
"name": "Retrospective",
|
|
4909
|
-
"status": "pending",
|
|
4910
|
-
"required_artifacts": [],
|
|
4911
|
-
"depends_on": "S05",
|
|
4912
|
-
},
|
|
4913
|
-
{
|
|
4914
|
-
"id": "S07",
|
|
4915
|
-
"skill": "prizmkit-committer",
|
|
4916
|
-
"name": "Runtime Commit Handoff",
|
|
4917
|
-
"status": "pending",
|
|
4918
|
-
"required_artifacts": [],
|
|
4919
|
-
"depends_on": "S06",
|
|
4920
|
-
},
|
|
4921
|
-
],
|
|
4922
|
-
"feature_state": {
|
|
4923
|
-
"stage": "code-review",
|
|
4924
|
-
"current_stage": "prizmkit-code-review",
|
|
4925
|
-
"status": "in_progress",
|
|
4926
|
-
"repair_scope": None,
|
|
4927
|
-
"repair_round": 0,
|
|
4928
|
-
"next_stage": "prizmkit-code-review",
|
|
4929
|
-
"blocked_reason": None,
|
|
4930
|
-
"terminal_status": None,
|
|
4931
|
-
},
|
|
4932
|
-
}),
|
|
4933
|
-
encoding="utf-8",
|
|
4934
|
-
)
|
|
4935
|
-
prompt = PromptGenerationResult(
|
|
4936
|
-
output_path=tmp_path / "prompt.md",
|
|
4937
|
-
checkpoint_path=checkpoint,
|
|
4938
|
-
artifact_path=artifact_dir,
|
|
4939
|
-
)
|
|
4940
|
-
raw = replace(
|
|
4941
|
-
_terminal_success_result(tmp_path),
|
|
4942
|
-
progress_summary=ProgressSummary(result_subtype="success", stop_reason="length"),
|
|
4943
|
-
)
|
|
4944
|
-
|
|
4945
|
-
classification = classify_session(
|
|
4946
|
-
raw,
|
|
4947
|
-
project_root=tmp_path,
|
|
4948
|
-
base_head=base_head,
|
|
4949
|
-
prompt=prompt,
|
|
4950
|
-
)
|
|
4951
|
-
|
|
4952
|
-
assert classification.session_status == "context_overflow"
|
|
4953
|
-
assert classification.reason == "context_overflow"
|
|
4954
|
-
assert classification.fatal_error_code == "context_overflow"
|
|
4955
|
-
assert classification.checkpoint_state["current_stage"] == "prizmkit-code-review"
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
def test_pi_length_stop_does_not_override_completed_checkpoint(tmp_path):
|
|
4959
|
-
from dataclasses import replace
|
|
4960
|
-
|
|
4961
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4962
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
4963
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4964
|
-
|
|
4965
|
-
base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
|
|
4966
|
-
(tmp_path / "done.txt").write_text("done", encoding="utf-8")
|
|
4967
|
-
subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
|
|
4968
|
-
subprocess.run(
|
|
4969
|
-
["git", "commit", "-m", "done"],
|
|
4970
|
-
cwd=tmp_path,
|
|
4971
|
-
check=True,
|
|
4972
|
-
stdout=subprocess.DEVNULL,
|
|
4973
|
-
)
|
|
4974
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-length-complete"
|
|
4975
|
-
checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
|
|
4976
|
-
prompt = PromptGenerationResult(
|
|
4977
|
-
output_path=tmp_path / "prompt.md",
|
|
4978
|
-
checkpoint_path=checkpoint,
|
|
4979
|
-
artifact_path=artifact_dir,
|
|
4980
|
-
)
|
|
4981
|
-
raw = replace(
|
|
4982
|
-
_terminal_success_result(tmp_path),
|
|
4983
|
-
progress_summary=ProgressSummary(result_subtype="success", stop_reason="length"),
|
|
4984
|
-
)
|
|
4985
|
-
|
|
4986
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
|
|
4987
|
-
|
|
4988
|
-
assert classification.session_status == "success"
|
|
4989
|
-
assert classification.reason == "terminal_success_with_semantic_checkpoint"
|
|
4990
|
-
assert classification.fatal_error_code == ""
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
def test_terminal_success_text_does_not_hide_provider_failure(tmp_path):
|
|
4994
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
4995
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
4996
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
4997
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
4998
|
-
|
|
4999
|
-
base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
|
|
5000
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-provider-error"
|
|
5001
|
-
checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact_dir)
|
|
5002
|
-
payload = json.loads(checkpoint.read_text(encoding="utf-8"))
|
|
5003
|
-
payload["steps"][2]["required_artifacts"] = [
|
|
5004
|
-
".prizmkit/specs/001-provider-error/test-report.md",
|
|
5005
|
-
".prizmkit/specs/001-provider-error/missing-test-result.json",
|
|
5006
|
-
]
|
|
5007
|
-
checkpoint.write_text(json.dumps(payload), encoding="utf-8")
|
|
5008
|
-
log = tmp_path / "provider-error.log"
|
|
5009
|
-
log.write_text("gateway failure after output", encoding="utf-8")
|
|
5010
|
-
raw = AISessionResult(
|
|
5011
|
-
command=AISessionCommand(("fake",), None, "claude", "stdin"),
|
|
5012
|
-
exit_code=0,
|
|
5013
|
-
timed_out=False,
|
|
5014
|
-
termination_reason=None,
|
|
5015
|
-
stale_marker=None,
|
|
5016
|
-
fatal_error_code="provider_error",
|
|
5017
|
-
progress_summary=ProgressSummary(result_subtype="success"),
|
|
5018
|
-
session_log=log,
|
|
5019
|
-
backup_log=tmp_path / "backup.log",
|
|
5020
|
-
log_recovery=None,
|
|
5021
|
-
started_epoch=0,
|
|
5022
|
-
ended_epoch=1,
|
|
5023
|
-
)
|
|
5024
|
-
|
|
5025
|
-
classification = classify_session(
|
|
5026
|
-
raw,
|
|
5027
|
-
project_root=tmp_path,
|
|
5028
|
-
base_head=base_head,
|
|
5029
|
-
prompt=PromptGenerationResult(
|
|
5030
|
-
output_path=tmp_path / "prompt.md",
|
|
5031
|
-
checkpoint_path=checkpoint,
|
|
5032
|
-
artifact_path=artifact_dir,
|
|
5033
|
-
),
|
|
5034
|
-
)
|
|
5035
|
-
|
|
5036
|
-
assert classification.session_status == "infra_error"
|
|
5037
|
-
assert classification.reason == "ai_runtime_or_provider_error"
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
@pytest.mark.parametrize(
|
|
5041
|
-
("kind", "item_id"),
|
|
5042
|
-
[("feature", "F-001"), ("bugfix", "B-001"), ("refactor", "R-001")],
|
|
5043
|
-
)
|
|
5044
|
-
def test_family_success_completion_is_terminal_without_warning_metadata(
|
|
5045
|
-
tmp_path, kind, item_id
|
|
5046
|
-
):
|
|
5047
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
5048
|
-
from prizmkit_runtime.runner_status import start_item, update_item
|
|
5049
|
-
|
|
5050
|
-
paths = _make_paths(tmp_path / kind)
|
|
5051
|
-
item = {
|
|
5052
|
-
"id": item_id,
|
|
5053
|
-
"title": "Skip invalid completion evidence",
|
|
5054
|
-
"status": "pending",
|
|
5055
|
-
"priority": "high",
|
|
5056
|
-
"dependencies": [],
|
|
5057
|
-
}
|
|
5058
|
-
if kind == "bugfix":
|
|
5059
|
-
item.update(severity="high", description="invalid evidence", reproduction_steps=["run"])
|
|
5060
|
-
elif kind == "refactor":
|
|
5061
|
-
item.update(description="invalid evidence", targets=["src"], goals=["preserve"])
|
|
5062
|
-
_write_family_plan(paths, kind, [item])
|
|
5063
|
-
family = family_for(kind, paths)
|
|
5064
|
-
invocation = parse_invocation(family, "run", ())
|
|
5065
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": family.plan_path})
|
|
5066
|
-
assert start_item(family, invocation, item_id, paths.project_root).ok is True
|
|
5067
|
-
|
|
5068
|
-
result = update_item(
|
|
5069
|
-
family,
|
|
5070
|
-
invocation,
|
|
5071
|
-
item_id,
|
|
5072
|
-
"success",
|
|
5073
|
-
"session-1",
|
|
5074
|
-
paths.project_root,
|
|
5075
|
-
checkpoint_state={},
|
|
5076
|
-
)
|
|
5077
|
-
status = json.loads((family.state_dir / item_id / "status.json").read_text(encoding="utf-8"))
|
|
5078
|
-
|
|
5079
|
-
assert result.ok is True
|
|
5080
|
-
assert result.data["new_status"] == "completed"
|
|
5081
|
-
assert status["retry_count"] == 0
|
|
5082
|
-
assert status["infra_error_count"] == 0
|
|
5083
|
-
assert "completion_warning" not in status
|
|
5084
|
-
assert "completion_warning_reason" not in status
|
|
5085
|
-
assert status["resume_from_phase"] is None
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
@pytest.mark.parametrize(
|
|
5089
|
-
("kind", "item_id"),
|
|
5090
|
-
[("feature", "F-001"), ("bugfix", "B-001"), ("refactor", "R-001")],
|
|
5091
|
-
)
|
|
5092
|
-
def test_family_status_preserves_direct_raw_workflow_skip(
|
|
5093
|
-
tmp_path, kind, item_id
|
|
5094
|
-
):
|
|
5095
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
5096
|
-
from prizmkit_runtime.runner_status import start_item, update_item
|
|
5097
|
-
|
|
5098
|
-
paths = _make_paths(tmp_path / f"historical-{kind}")
|
|
5099
|
-
item = {
|
|
5100
|
-
"id": item_id,
|
|
5101
|
-
"title": "Historical workflow skip",
|
|
5102
|
-
"status": "pending",
|
|
5103
|
-
"priority": "high",
|
|
5104
|
-
"dependencies": [],
|
|
5105
|
-
}
|
|
5106
|
-
if kind == "bugfix":
|
|
5107
|
-
item.update(severity="high", description="invalid evidence", reproduction_steps=["run"])
|
|
5108
|
-
elif kind == "refactor":
|
|
5109
|
-
item.update(description="invalid evidence", targets=["src"], goals=["preserve"])
|
|
5110
|
-
_write_family_plan(paths, kind, [item])
|
|
5111
|
-
family = family_for(kind, paths)
|
|
5112
|
-
invocation = parse_invocation(family, "run", ())
|
|
5113
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": family.plan_path})
|
|
5114
|
-
assert start_item(family, invocation, item_id, paths.project_root).ok is True
|
|
5115
|
-
|
|
5116
|
-
result = update_item(
|
|
5117
|
-
family,
|
|
5118
|
-
invocation,
|
|
5119
|
-
item_id,
|
|
5120
|
-
"workflow_skipped",
|
|
5121
|
-
"historical-session",
|
|
5122
|
-
paths.project_root,
|
|
5123
|
-
)
|
|
5124
|
-
|
|
5125
|
-
assert result.ok is True
|
|
5126
|
-
assert result.data["new_status"] == "skipped"
|
|
5127
|
-
assert result.data["restart_policy"] == "terminal_skipped"
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
def test_invalid_existing_checkpoint_skips_terminal_success_with_completion_summary(tmp_path):
|
|
5131
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
5132
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
5133
|
-
|
|
5134
|
-
base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
|
|
5135
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-invalid"
|
|
5136
|
-
artifact_dir.mkdir(parents=True)
|
|
5137
|
-
checkpoint = artifact_dir / "workflow-checkpoint.json"
|
|
5138
|
-
checkpoint.write_text(json.dumps({"steps": [{"id": "S01", "skill": "done", "name": "Done", "status": "not-valid"}]}), encoding="utf-8")
|
|
5139
|
-
(artifact_dir / "completion-summary.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
|
|
5140
|
-
prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", checkpoint_path=checkpoint, artifact_path=artifact_dir)
|
|
5141
|
-
|
|
5142
|
-
classification = classify_session(_terminal_success_result(tmp_path), project_root=tmp_path, base_head=base_head, prompt=prompt)
|
|
5143
|
-
|
|
5144
|
-
assert classification.session_status == "workflow_skipped"
|
|
5145
|
-
assert classification.reason == "invalid_workflow_checkpoint:invalid_status"
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
def test_invalid_existing_checkpoint_blocks_runtime_failure_with_head_change(tmp_path):
|
|
5149
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
5150
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
5151
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
5152
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
5153
|
-
|
|
5154
|
-
base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
|
|
5155
|
-
(tmp_path / "done.txt").write_text("done", encoding="utf-8")
|
|
5156
|
-
subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
|
|
5157
|
-
subprocess.run(["git", "commit", "-m", "done"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5158
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-invalid"
|
|
5159
|
-
artifact_dir.mkdir(parents=True)
|
|
5160
|
-
checkpoint = artifact_dir / "workflow-checkpoint.json"
|
|
5161
|
-
checkpoint.write_text(json.dumps({"steps": [{"id": "bad", "skill": "done", "name": "Done", "status": "completed"}]}), encoding="utf-8")
|
|
5162
|
-
raw = AISessionResult(
|
|
5163
|
-
command=AISessionCommand(("fake",), None, "claude", "stdin"),
|
|
5164
|
-
exit_code=1,
|
|
5165
|
-
timed_out=False,
|
|
5166
|
-
termination_reason=None,
|
|
5167
|
-
stale_marker=None,
|
|
5168
|
-
fatal_error_code="context_overflow",
|
|
5169
|
-
progress_summary=ProgressSummary(fatal_error_code="context_overflow"),
|
|
5170
|
-
session_log=tmp_path / "session.log",
|
|
5171
|
-
backup_log=tmp_path / "backup.log",
|
|
5172
|
-
log_recovery=None,
|
|
5173
|
-
started_epoch=0,
|
|
5174
|
-
ended_epoch=1,
|
|
5175
|
-
)
|
|
5176
|
-
raw.session_log.write_text("context overflow", encoding="utf-8")
|
|
5177
|
-
prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", checkpoint_path=checkpoint, artifact_path=artifact_dir)
|
|
5178
|
-
|
|
5179
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
|
|
5180
|
-
|
|
5181
|
-
assert classification.session_status == "crashed"
|
|
5182
|
-
assert classification.reason == "invalid_workflow_checkpoint:malformed_step_id"
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
def test_invalid_existing_checkpoint_blocks_ambiguous_clean_exit(tmp_path):
|
|
5186
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
5187
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
5188
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
5189
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
5190
|
-
|
|
5191
|
-
base_head = _init_git_repo_for_invalid_checkpoint_test(tmp_path)
|
|
5192
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-invalid"
|
|
5193
|
-
artifact_dir.mkdir(parents=True)
|
|
5194
|
-
checkpoint = artifact_dir / "workflow-checkpoint.json"
|
|
5195
|
-
checkpoint.write_text(json.dumps({"steps": []}), encoding="utf-8")
|
|
5196
|
-
(tmp_path / "dirty.txt").write_text("dirty", encoding="utf-8")
|
|
5197
|
-
log = tmp_path / "session.log"
|
|
5198
|
-
log.write_text("clean exit but dirty workspace", encoding="utf-8")
|
|
5199
|
-
raw = AISessionResult(
|
|
5200
|
-
command=AISessionCommand(("fake",), None, "claude", "stdin"),
|
|
5201
|
-
exit_code=0,
|
|
5202
|
-
timed_out=False,
|
|
5203
|
-
termination_reason=None,
|
|
5204
|
-
stale_marker=None,
|
|
5205
|
-
fatal_error_code="",
|
|
5206
|
-
progress_summary=ProgressSummary(result_subtype="", terminal_result_text=""),
|
|
5207
|
-
session_log=log,
|
|
5208
|
-
backup_log=tmp_path / "backup.log",
|
|
5209
|
-
log_recovery=None,
|
|
5210
|
-
started_epoch=0,
|
|
5211
|
-
ended_epoch=1,
|
|
5212
|
-
)
|
|
5213
|
-
prompt = PromptGenerationResult(output_path=tmp_path / "prompt.md", checkpoint_path=checkpoint, artifact_path=artifact_dir)
|
|
5214
|
-
|
|
5215
|
-
classification = classify_session(raw, project_root=tmp_path, base_head=base_head, prompt=prompt)
|
|
5216
|
-
|
|
5217
|
-
assert classification.session_status == "crashed"
|
|
5218
|
-
assert classification.reason == "invalid_workflow_checkpoint:empty_steps"
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
@pytest.mark.parametrize(
|
|
5222
|
-
("kind", "item_id", "branch"),
|
|
5223
|
-
[
|
|
5224
|
-
("feature", "F-001", "dev/F-001-ai-retry"),
|
|
5225
|
-
("bugfix", "B-001", "bugfix/B-001-ai-retry"),
|
|
5226
|
-
("refactor", "R-001", "refactor/R-001-ai-retry"),
|
|
5227
|
-
],
|
|
5228
|
-
)
|
|
5229
|
-
@pytest.mark.parametrize("retry_status", ["infra_error", "crashed", "timed_out"])
|
|
5230
|
-
def test_retryable_ai_errors_continue_in_process_for_all_families(monkeypatch, tmp_path, kind, item_id, branch, retry_status):
|
|
5231
|
-
from prizmkit_runtime import runners
|
|
5232
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
5233
|
-
|
|
5234
|
-
monkeypatch.setenv("DEV_BRANCH", branch)
|
|
5235
|
-
paths = _make_paths(tmp_path / kind / retry_status)
|
|
5236
|
-
family = family_for(kind, paths)
|
|
5237
|
-
invocation = parse_invocation(family, "run", ())
|
|
5238
|
-
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan, "refactor": paths.refactor_plan}[kind]
|
|
5239
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
|
|
5240
|
-
observed = _install_runner_session_fakes(monkeypatch, runners, statuses=(retry_status, "success"))
|
|
5241
|
-
sleep_calls = []
|
|
5242
|
-
branch_plans = []
|
|
5243
|
-
monkeypatch.setattr(runners.time, "sleep", lambda seconds: sleep_calls.append(seconds))
|
|
5244
|
-
monkeypatch.setattr(
|
|
5245
|
-
runners,
|
|
5246
|
-
"run_git_plan",
|
|
5247
|
-
lambda project_root, plan: (branch_plans.append(plan.name) or SimpleNamespace(ok=True, plan=plan, results=())),
|
|
5248
|
-
)
|
|
5249
|
-
|
|
5250
|
-
status = runners._process_item(family, invocation, item_id, paths, initial_metadata={})
|
|
5251
|
-
|
|
5252
|
-
assert status == "completed"
|
|
5253
|
-
assert sleep_calls == [5]
|
|
5254
|
-
assert len(observed.launch_cwds) == 2
|
|
5255
|
-
assert observed.launch_cwds[0] == observed.launch_cwds[1]
|
|
5256
|
-
assert branch_plans.count("branch_create") == 1
|
|
5257
|
-
assert observed.updates[0][0] == retry_status
|
|
5258
|
-
continuation = observed.prompt_calls[1]["continuation"]
|
|
5259
|
-
assert continuation["previous_session_id"].endswith("session-1")
|
|
5260
|
-
assert continuation["failure_classification"] == retry_status
|
|
5261
|
-
assert continuation["active_dev_branch"] == branch
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
@pytest.mark.parametrize(
|
|
5265
|
-
("kind", "item_id", "branch"),
|
|
5266
|
-
[
|
|
5267
|
-
("feature", "F-001", "dev/F-001-context-budget"),
|
|
5268
|
-
("bugfix", "B-001", "bugfix/B-001-context-budget"),
|
|
5269
|
-
("refactor", "R-001", "refactor/R-001-context-budget"),
|
|
5270
|
-
],
|
|
5271
|
-
)
|
|
5272
|
-
def test_context_overflow_retry_budget_prevents_session_n_plus_one(monkeypatch, tmp_path, kind, item_id, branch):
|
|
5273
|
-
from prizmkit_runtime import runners
|
|
5274
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
5275
|
-
|
|
5276
|
-
monkeypatch.setenv("DEV_BRANCH", branch)
|
|
5277
|
-
paths = _make_paths(tmp_path / kind)
|
|
5278
|
-
family = family_for(kind, paths)
|
|
5279
|
-
invocation = parse_invocation(family, "run", ())
|
|
5280
|
-
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan, "refactor": paths.refactor_plan}[kind]
|
|
5281
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
|
|
5282
|
-
observed = _install_runner_session_fakes(
|
|
5283
|
-
monkeypatch,
|
|
5284
|
-
runners,
|
|
5285
|
-
statuses=("context_overflow", "context_overflow", "context_overflow", "context_overflow"),
|
|
5286
|
-
max_retries=3,
|
|
5287
|
-
)
|
|
5288
|
-
sleep_calls = []
|
|
5289
|
-
monkeypatch.setattr(runners.time, "sleep", lambda seconds: sleep_calls.append(seconds))
|
|
5290
|
-
monkeypatch.setattr(
|
|
5291
|
-
runners,
|
|
5292
|
-
"run_git_plan",
|
|
5293
|
-
lambda project_root, plan: SimpleNamespace(ok=True, plan=plan, results=()),
|
|
5294
|
-
)
|
|
5295
|
-
|
|
5296
|
-
status = runners._process_item(family, invocation, item_id, paths, initial_metadata={})
|
|
5297
|
-
|
|
5298
|
-
assert status == "failed"
|
|
5299
|
-
assert len(observed.launch_cwds) == 3
|
|
5300
|
-
assert len(observed.updates) == 3
|
|
5301
|
-
assert sleep_calls == [5, 5]
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
def test_unique_session_ids_do_not_collide_when_wall_clock_second_is_frozen(monkeypatch):
|
|
5305
|
-
from prizmkit_runtime import runners
|
|
5306
|
-
|
|
5307
|
-
monkeypatch.setattr(runners.time, "strftime", lambda _fmt: "20260711030000")
|
|
5308
|
-
values = iter((101, 102))
|
|
5309
|
-
monkeypatch.setattr(runners.time, "time_ns", lambda: next(values))
|
|
5310
|
-
|
|
5311
|
-
first = runners._session_id("F-001")
|
|
5312
|
-
second = runners._session_id("F-001")
|
|
5313
|
-
|
|
5314
|
-
assert first != second
|
|
5315
|
-
assert first.endswith("-101")
|
|
5316
|
-
assert second.endswith("-102")
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
@pytest.mark.parametrize("summary_text", ["{}", "{not-json", '{"completion_notes": []}', '{"completion_notes": [""]}'])
|
|
5320
|
-
def test_invalid_completion_summary_does_not_prove_late_runtime_success(tmp_path, summary_text):
|
|
5321
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
5322
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
5323
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
5324
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
5325
|
-
|
|
5326
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5327
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
5328
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
5329
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
5330
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
5331
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5332
|
-
base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
5333
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-invalid"
|
|
5334
|
-
artifact_dir.mkdir(parents=True)
|
|
5335
|
-
(artifact_dir / "completion-summary.json").write_text(summary_text, encoding="utf-8")
|
|
5336
|
-
log = tmp_path / "session.log"
|
|
5337
|
-
log.write_text("quota exceeded", encoding="utf-8")
|
|
5338
|
-
result = AISessionResult(
|
|
5339
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
5340
|
-
exit_code=1,
|
|
5341
|
-
timed_out=False,
|
|
5342
|
-
termination_reason=None,
|
|
5343
|
-
stale_marker=None,
|
|
5344
|
-
fatal_error_code="api_error",
|
|
5345
|
-
progress_summary=ProgressSummary(terminal_result_text="quota exceeded"),
|
|
5346
|
-
session_log=log,
|
|
5347
|
-
backup_log=tmp_path / "backup.log",
|
|
5348
|
-
log_recovery=None,
|
|
5349
|
-
started_epoch=0,
|
|
5350
|
-
ended_epoch=1,
|
|
5351
|
-
)
|
|
5352
|
-
|
|
5353
|
-
classification = classify_session(
|
|
5354
|
-
result,
|
|
5355
|
-
project_root=tmp_path,
|
|
5356
|
-
base_head=base_head,
|
|
5357
|
-
prompt=PromptGenerationResult(output_path=tmp_path / "prompt.md", artifact_path=artifact_dir),
|
|
5358
|
-
)
|
|
5359
|
-
|
|
5360
|
-
assert classification.session_status == "infra_error"
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
def test_non_utf8_completion_summary_does_not_abort_classification(tmp_path):
|
|
5364
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
5365
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
5366
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
5367
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
5368
|
-
|
|
5369
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5370
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
5371
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
5372
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
5373
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
5374
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5375
|
-
base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
5376
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-corrupt"
|
|
5377
|
-
artifact_dir.mkdir(parents=True)
|
|
5378
|
-
(artifact_dir / "completion-summary.json").write_bytes(b"\xff\xfe")
|
|
5379
|
-
log = tmp_path / "session.log"
|
|
5380
|
-
log.write_text("quota exceeded", encoding="utf-8")
|
|
5381
|
-
result = AISessionResult(
|
|
5382
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
5383
|
-
exit_code=1,
|
|
5384
|
-
timed_out=False,
|
|
5385
|
-
termination_reason=None,
|
|
5386
|
-
stale_marker=None,
|
|
5387
|
-
fatal_error_code="api_error",
|
|
5388
|
-
progress_summary=ProgressSummary(terminal_result_text="quota exceeded"),
|
|
5389
|
-
session_log=log,
|
|
5390
|
-
backup_log=tmp_path / "backup.log",
|
|
5391
|
-
log_recovery=None,
|
|
5392
|
-
started_epoch=0,
|
|
5393
|
-
ended_epoch=1,
|
|
5394
|
-
)
|
|
5395
|
-
|
|
5396
|
-
classification = classify_session(
|
|
5397
|
-
result,
|
|
5398
|
-
project_root=tmp_path,
|
|
5399
|
-
base_head=base_head,
|
|
5400
|
-
prompt=PromptGenerationResult(output_path=tmp_path / "prompt.md", artifact_path=artifact_dir),
|
|
5401
|
-
)
|
|
5402
|
-
|
|
5403
|
-
assert classification.session_status == "infra_error"
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
@pytest.mark.parametrize(
|
|
5407
|
-
("timed_out", "termination_reason", "expected_status", "expected_reason"),
|
|
5408
|
-
[
|
|
5409
|
-
(True, "timeout", "timed_out", "timeout"),
|
|
5410
|
-
(False, "stale_session", "crashed", "stale_session"),
|
|
5411
|
-
],
|
|
5412
|
-
)
|
|
5413
|
-
def test_timeout_and_stale_termination_override_provider_error_markers(tmp_path, timed_out, termination_reason, expected_status, expected_reason):
|
|
5414
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
5415
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
5416
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
5417
|
-
|
|
5418
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5419
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
5420
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
5421
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
5422
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
5423
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5424
|
-
base_head = subprocess.run(["git", "rev-parse", "HEAD"], cwd=tmp_path, check=True, stdout=subprocess.PIPE, text=True).stdout.strip()
|
|
5425
|
-
log = tmp_path / "session.log"
|
|
5426
|
-
log.write_text("gateway API error", encoding="utf-8")
|
|
5427
|
-
result = AISessionResult(
|
|
5428
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
5429
|
-
exit_code=1,
|
|
5430
|
-
timed_out=timed_out,
|
|
5431
|
-
termination_reason=termination_reason,
|
|
5432
|
-
stale_marker=None,
|
|
5433
|
-
fatal_error_code="api_error",
|
|
5434
|
-
progress_summary=ProgressSummary(terminal_result_text="provider gateway error"),
|
|
5435
|
-
session_log=log,
|
|
5436
|
-
backup_log=tmp_path / "backup.log",
|
|
5437
|
-
log_recovery=None,
|
|
5438
|
-
started_epoch=0,
|
|
5439
|
-
ended_epoch=1,
|
|
5440
|
-
)
|
|
5441
|
-
|
|
5442
|
-
classification = classify_session(result, project_root=tmp_path, base_head=base_head)
|
|
5443
|
-
|
|
5444
|
-
assert classification.session_status == expected_status
|
|
5445
|
-
assert classification.reason == expected_reason
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
@pytest.mark.parametrize("workflow_type", ["feature-pipeline", "bugfix-pipeline", "refactor-pipeline"])
|
|
5450
|
-
def test_semantic_completion_classification_has_cross_family_parity(tmp_path, workflow_type):
|
|
5451
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
5452
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
5453
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
5454
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
5455
|
-
|
|
5456
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5457
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
5458
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
5459
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
5460
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
5461
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5462
|
-
base_head = subprocess.run(
|
|
5463
|
-
["git", "rev-parse", "HEAD"],
|
|
5464
|
-
cwd=tmp_path,
|
|
5465
|
-
check=True,
|
|
5466
|
-
stdout=subprocess.PIPE,
|
|
5467
|
-
text=True,
|
|
5468
|
-
).stdout.strip()
|
|
5469
|
-
(tmp_path / "done.txt").write_text("done", encoding="utf-8")
|
|
5470
|
-
subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
|
|
5471
|
-
subprocess.run(
|
|
5472
|
-
["git", "commit", "-m", "done"],
|
|
5473
|
-
cwd=tmp_path,
|
|
5474
|
-
check=True,
|
|
5475
|
-
stdout=subprocess.DEVNULL,
|
|
5476
|
-
)
|
|
5477
|
-
artifact = tmp_path / ".prizmkit" / "artifacts" / workflow_type
|
|
5478
|
-
checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact, workflow_type)
|
|
5479
|
-
log = tmp_path / f"{workflow_type}.log"
|
|
5480
|
-
log.write_text("success", encoding="utf-8")
|
|
5481
|
-
raw = AISessionResult(
|
|
5482
|
-
command=AISessionCommand(("fake",), None, "claude", "stdin"),
|
|
5483
|
-
exit_code=0,
|
|
5484
|
-
timed_out=False,
|
|
5485
|
-
termination_reason=None,
|
|
5486
|
-
stale_marker=None,
|
|
5487
|
-
fatal_error_code="",
|
|
5488
|
-
progress_summary=ProgressSummary(result_subtype="success"),
|
|
5489
|
-
session_log=log,
|
|
5490
|
-
backup_log=tmp_path / "backup.log",
|
|
5491
|
-
log_recovery=None,
|
|
5492
|
-
started_epoch=0,
|
|
5493
|
-
ended_epoch=1,
|
|
5494
|
-
)
|
|
5495
|
-
|
|
5496
|
-
classification = classify_session(
|
|
5497
|
-
raw,
|
|
5498
|
-
project_root=tmp_path,
|
|
5499
|
-
base_head=base_head,
|
|
5500
|
-
prompt=PromptGenerationResult(
|
|
5501
|
-
output_path=tmp_path / "prompt.md",
|
|
5502
|
-
checkpoint_path=checkpoint,
|
|
5503
|
-
artifact_path=artifact,
|
|
5504
|
-
),
|
|
5505
|
-
)
|
|
5506
|
-
|
|
5507
|
-
assert classification.session_status == "success"
|
|
5508
|
-
assert classification.checkpoint_state["terminal_status"] == "WORKFLOW_COMPLETED"
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
def test_semantic_blocked_classification_is_terminal_and_retry_neutral(tmp_path):
|
|
5512
|
-
from prizmkit_runtime.runner_classification import classify_session
|
|
5513
|
-
from prizmkit_runtime.runner_models import PromptGenerationResult
|
|
5514
|
-
from prizmkit_runtime.sessions import AISessionCommand, AISessionResult
|
|
5515
|
-
from prizmkit_runtime.status import ProgressSummary
|
|
5516
|
-
|
|
5517
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5518
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
5519
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
5520
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
5521
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
5522
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
5523
|
-
artifact = tmp_path / ".prizmkit" / "specs" / "blocked"
|
|
5524
|
-
checkpoint = _write_semantic_completion_checkpoint(tmp_path, artifact)
|
|
5525
|
-
data = json.loads(checkpoint.read_text(encoding="utf-8"))
|
|
5526
|
-
data["feature_state"].update(
|
|
5527
|
-
terminal_status="WORKFLOW_BLOCKED",
|
|
5528
|
-
blocked_reason="repair_round_limit",
|
|
5529
|
-
repair_round=3,
|
|
5530
|
-
)
|
|
5531
|
-
checkpoint.write_text(json.dumps(data), encoding="utf-8")
|
|
5532
|
-
log = tmp_path / "blocked.log"
|
|
5533
|
-
log.write_text("ambiguous failure", encoding="utf-8")
|
|
5534
|
-
raw = AISessionResult(
|
|
5535
|
-
command=AISessionCommand(("fake",), None, "codebuddy", "stdin"),
|
|
5536
|
-
exit_code=1,
|
|
5537
|
-
timed_out=False,
|
|
5538
|
-
termination_reason=None,
|
|
5539
|
-
stale_marker=None,
|
|
5540
|
-
fatal_error_code="",
|
|
5541
|
-
progress_summary=ProgressSummary(terminal_result_text="ambiguous failure"),
|
|
5542
|
-
session_log=log,
|
|
5543
|
-
backup_log=tmp_path / "backup.log",
|
|
5544
|
-
log_recovery=None,
|
|
5545
|
-
started_epoch=0,
|
|
5546
|
-
ended_epoch=1,
|
|
5547
|
-
)
|
|
5548
|
-
|
|
5549
|
-
classification = classify_session(
|
|
5550
|
-
raw,
|
|
5551
|
-
project_root=tmp_path,
|
|
5552
|
-
base_head="",
|
|
5553
|
-
prompt=PromptGenerationResult(
|
|
5554
|
-
output_path=tmp_path / "prompt.md",
|
|
5555
|
-
checkpoint_path=checkpoint,
|
|
5556
|
-
artifact_path=artifact,
|
|
5557
|
-
),
|
|
5558
|
-
)
|
|
5559
|
-
|
|
5560
|
-
assert classification.session_status == "workflow_blocked"
|
|
5561
|
-
assert classification.reason == "repair_round_limit"
|
|
5562
|
-
assert classification.checkpoint_state["repair_round"] == 3
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
def test_runtime_semantic_paths_do_not_invoke_composite_workflow():
|
|
5566
|
-
sources = [
|
|
5567
|
-
PIPELINE_ROOT / "prizmkit_runtime" / "checkpoint_state.py",
|
|
5568
|
-
PIPELINE_ROOT / "prizmkit_runtime" / "runner_classification.py",
|
|
5569
|
-
PIPELINE_ROOT / "prizmkit_runtime" / "runners.py",
|
|
5570
|
-
]
|
|
5571
|
-
|
|
5572
|
-
for source in sources:
|
|
5573
|
-
assert "prizmkit-workflow" not in source.read_text(encoding="utf-8")
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
@pytest.mark.parametrize(
|
|
5578
|
-
("kind", "item_id", "blocked_status"),
|
|
5579
|
-
[("feature", "F-001", "failed"), ("bugfix", "B-001", "needs_info"), ("refactor", "R-001", "failed")],
|
|
5580
|
-
)
|
|
5581
|
-
def test_family_status_persists_identical_semantic_blocked_snapshot_without_retry_spend(
|
|
5582
|
-
tmp_path, kind, item_id, blocked_status
|
|
5583
|
-
):
|
|
5584
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
5585
|
-
from prizmkit_runtime.runner_status import start_item, update_item
|
|
5586
|
-
|
|
5587
|
-
paths = _make_paths(tmp_path)
|
|
5588
|
-
item = {
|
|
5589
|
-
"id": item_id,
|
|
5590
|
-
"title": "Semantic blocked",
|
|
5591
|
-
"status": "pending",
|
|
5592
|
-
"priority": "high",
|
|
5593
|
-
"dependencies": [],
|
|
5594
|
-
}
|
|
5595
|
-
if kind == "bugfix":
|
|
5596
|
-
item.update(severity="high", description="blocked", reproduction_steps=["run"])
|
|
5597
|
-
elif kind == "refactor":
|
|
5598
|
-
item.update(description="blocked", targets=["src"], goals=["preserve"])
|
|
5599
|
-
_write_family_plan(paths, kind, [item])
|
|
5600
|
-
family = family_for(kind, paths)
|
|
5601
|
-
invocation = parse_invocation(family, "run", ())
|
|
5602
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": family.plan_path})
|
|
5603
|
-
assert start_item(family, invocation, item_id, paths.project_root).ok is True
|
|
5604
|
-
semantic = {
|
|
5605
|
-
"current_stage": None,
|
|
5606
|
-
"next_stage": None,
|
|
5607
|
-
"stage_result": "TEST_BLOCKED",
|
|
5608
|
-
"repair_scope": "production",
|
|
5609
|
-
"repair_round": 2,
|
|
5610
|
-
"blocked_reason": "test_blocked",
|
|
5611
|
-
"terminal_status": "WORKFLOW_BLOCKED",
|
|
5612
|
-
}
|
|
5613
|
-
|
|
5614
|
-
result = update_item(
|
|
5615
|
-
family,
|
|
5616
|
-
invocation,
|
|
5617
|
-
item_id,
|
|
5618
|
-
"workflow_blocked",
|
|
5619
|
-
"session-1",
|
|
5620
|
-
paths.project_root,
|
|
5621
|
-
checkpoint_state=semantic,
|
|
5622
|
-
)
|
|
5623
|
-
status = json.loads((family.state_dir / item_id / "status.json").read_text(encoding="utf-8"))
|
|
5624
|
-
|
|
5625
|
-
assert result.ok is True
|
|
5626
|
-
assert result.data["new_status"] == blocked_status
|
|
5627
|
-
assert result.data["checkpoint_state"] == semantic
|
|
5628
|
-
assert result.data["restart_policy"] == "terminal_blocked"
|
|
5629
|
-
assert status["retry_count"] == 0
|
|
5630
|
-
assert status["infra_error_count"] == 0
|
|
5631
|
-
for key, value in semantic.items():
|
|
5632
|
-
assert status[key] == value
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
def test_runtime_sources_do_not_depend_on_direct_lifecycle_composite():
|
|
5636
|
-
runtime_root = REPO_ROOT / "dev-pipeline"
|
|
5637
|
-
source_files = list(runtime_root.rglob("*.py"))
|
|
5638
|
-
for source in source_files:
|
|
5639
|
-
if "__pycache__" in source.parts or "tests" in source.parts or not source.is_file():
|
|
5640
|
-
continue
|
|
5641
|
-
assert "prizmkit-workflow" not in source.read_text(encoding="utf-8")
|