prizmkit 1.1.192 → 1.1.193
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundled/VERSION.json +3 -3
- package/bundled/dev-pipeline/README.md +23 -34
- package/bundled/dev-pipeline/assets/feature-list-example.json +0 -1
- package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -0
- package/bundled/dev-pipeline/prizmkit_runtime/config.py +24 -2
- package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +2 -0
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +89 -40
- package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +9 -1
- package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +0 -22
- package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +11 -7
- package/bundled/dev-pipeline/prizmkit_runtime/processes.py +26 -20
- package/bundled/dev-pipeline/prizmkit_runtime/reset.py +37 -4
- package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +20 -41
- package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +74 -36
- package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +0 -66
- package/bundled/dev-pipeline/prizmkit_runtime/runners.py +271 -52
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +51 -13
- package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +43 -15
- package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +27 -24
- package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +0 -1
- package/bundled/dev-pipeline/scripts/check-session-status.py +13 -1
- package/bundled/dev-pipeline/scripts/continuation.py +2 -3
- package/bundled/dev-pipeline/scripts/detect-stuck.py +19 -5
- package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +6 -14
- package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +13 -8
- package/bundled/dev-pipeline/scripts/init-change-artifact.py +17 -2
- package/bundled/dev-pipeline/scripts/prompt_framework.py +39 -21
- package/bundled/dev-pipeline/scripts/update-checkpoint.py +27 -0
- package/bundled/dev-pipeline/templates/bootstrap-tier3.md +1 -1
- package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +6 -6
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +1 -1
- package/bundled/skills/_metadata.json +1 -1
- package/package.json +1 -1
- package/bundled/dev-pipeline/tests/_helpers.py +0 -418
- package/bundled/dev-pipeline/tests/conftest.py +0 -73
- package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +0 -208
- package/bundled/dev-pipeline/tests/test_auto_skip.py +0 -1806
- package/bundled/dev-pipeline/tests/test_checkpoint_state.py +0 -1439
- package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +0 -257
- package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +0 -500
- package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +0 -1654
- package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +0 -629
- package/bundled/dev-pipeline/tests/test_python_runner_parity.py +0 -2973
- package/bundled/dev-pipeline/tests/test_recovery_workflow.py +0 -321
- package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -251
- package/bundled/dev-pipeline/tests/test_reset_modes.py +0 -1196
- package/bundled/dev-pipeline/tests/test_reset_preserve.py +0 -872
- package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +0 -766
- package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +0 -1257
- package/bundled/dev-pipeline/tests/test_runtime_commit.py +0 -1113
- package/bundled/dev-pipeline/tests/test_runtime_helper.py +0 -380
- package/bundled/dev-pipeline/tests/test_session_launch.py +0 -1101
- package/bundled/dev-pipeline/tests/test_stream_progress.py +0 -585
- package/bundled/dev-pipeline/tests/test_unified_cli.py +0 -3625
- package/bundled/dev-pipeline/tests/test_utils.py +0 -170
|
@@ -1,2973 +0,0 @@
|
|
|
1
|
-
"""Parity-focused tests for Python foreground runner helpers."""
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
import shutil
|
|
6
|
-
import signal
|
|
7
|
-
import subprocess
|
|
8
|
-
import sys
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
from types import SimpleNamespace
|
|
11
|
-
|
|
12
|
-
import pytest
|
|
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
|
-
|
|
23
|
-
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
24
|
-
PIPELINE_ROOT = REPO_ROOT / "dev-pipeline"
|
|
25
|
-
CLI_PATH = PIPELINE_ROOT / "cli.py"
|
|
26
|
-
|
|
27
|
-
if str(PIPELINE_ROOT) not in sys.path:
|
|
28
|
-
sys.path.insert(0, str(PIPELINE_ROOT))
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def _python_310_plus() -> str:
|
|
32
|
-
if sys.version_info >= (3, 10):
|
|
33
|
-
return sys.executable
|
|
34
|
-
for executable in ("python3.12", "python3.11", "python3.10"):
|
|
35
|
-
resolved = shutil.which(executable)
|
|
36
|
-
if resolved:
|
|
37
|
-
return resolved
|
|
38
|
-
return sys.executable
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
PYTHON_310_PLUS = _python_310_plus()
|
|
42
|
-
UNIX_RUNTIME_SNAPSHOT = REPO_ROOT / "tests" / "fixtures" / "dev-pipeline-behavior-snapshots" / "unix-runtime.json"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def _load_unix_runtime_snapshot():
|
|
46
|
-
return json.loads(UNIX_RUNTIME_SNAPSHOT.read_text(encoding="utf-8"))
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@pytest.mark.parametrize(
|
|
50
|
-
("kind", "item_id", "filename", "list_key", "schema", "item"),
|
|
51
|
-
[
|
|
52
|
-
(
|
|
53
|
-
"feature", "F-001", "feature-list.json", "features",
|
|
54
|
-
"dev-pipeline-feature-list-v1",
|
|
55
|
-
{
|
|
56
|
-
"id": "F-001", "title": "Preview Feature", "description": "Preview only",
|
|
57
|
-
"priority": "high", "dependencies": [],
|
|
58
|
-
"acceptance_criteria": ["Prompt validates"], "status": "pending",
|
|
59
|
-
},
|
|
60
|
-
),
|
|
61
|
-
(
|
|
62
|
-
"bugfix", "B-001", "bug-fix-list.json", "bugs",
|
|
63
|
-
"dev-pipeline-bug-fix-list-v1",
|
|
64
|
-
{
|
|
65
|
-
"id": "B-001", "title": "Preview Bug", "description": "Preview only",
|
|
66
|
-
"severity": "high", "priority": "high", "dependencies": [],
|
|
67
|
-
"error_source": {"type": "user_report", "reproduction_steps": ["preview"]},
|
|
68
|
-
"verification_type": "automated",
|
|
69
|
-
"acceptance_criteria": ["Prompt validates"], "status": "pending",
|
|
70
|
-
},
|
|
71
|
-
),
|
|
72
|
-
],
|
|
73
|
-
)
|
|
74
|
-
def test_actual_dry_run_is_read_only_and_successful(
|
|
75
|
-
tmp_path, kind, item_id, filename, list_key, schema, item,
|
|
76
|
-
):
|
|
77
|
-
from prizmkit_runtime.paths import resolve_runtime_paths
|
|
78
|
-
from prizmkit_runtime.runners import run_pipeline_command
|
|
79
|
-
|
|
80
|
-
project = tmp_path / kind
|
|
81
|
-
plans = project / ".prizmkit" / "plans"
|
|
82
|
-
plans.mkdir(parents=True)
|
|
83
|
-
plan_path = plans / filename
|
|
84
|
-
plan_path.write_text(
|
|
85
|
-
json.dumps({"$schema": schema, "project_name": "Dry Run", list_key: [item]}),
|
|
86
|
-
encoding="utf-8",
|
|
87
|
-
)
|
|
88
|
-
fake_cli = project / "fake-ai.py"
|
|
89
|
-
fake_cli.write_text(
|
|
90
|
-
"#!/usr/bin/env python3\nfrom pathlib import Path\nPath('AI_WAS_LAUNCHED').write_text('bad')\n",
|
|
91
|
-
encoding="utf-8",
|
|
92
|
-
)
|
|
93
|
-
fake_cli.chmod(0o755)
|
|
94
|
-
(project / ".prizmkit" / "config.json").write_text(
|
|
95
|
-
json.dumps({
|
|
96
|
-
"platform": "pi",
|
|
97
|
-
"ai_cli": str(fake_cli),
|
|
98
|
-
"ai_cli_launch": {"profile": "custom", "prompt_arg": "--prompt"},
|
|
99
|
-
}),
|
|
100
|
-
encoding="utf-8",
|
|
101
|
-
)
|
|
102
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=project, check=True, stdout=subprocess.DEVNULL)
|
|
103
|
-
subprocess.run(["git", "config", "user.name", "Dry Run Test"], cwd=project, check=True)
|
|
104
|
-
subprocess.run(["git", "config", "user.email", "dry-run@example.invalid"], cwd=project, check=True)
|
|
105
|
-
subprocess.run(["git", "add", "."], cwd=project, check=True)
|
|
106
|
-
subprocess.run(["git", "commit", "-m", "initial"], cwd=project, check=True, stdout=subprocess.DEVNULL)
|
|
107
|
-
paths = resolve_runtime_paths(pipeline_root=PIPELINE_ROOT, project_root=project)
|
|
108
|
-
branch_before = subprocess.check_output(["git", "branch", "--show-current"], cwd=project, text=True).strip()
|
|
109
|
-
head_before = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=project, text=True).strip()
|
|
110
|
-
status_before = subprocess.check_output(["git", "status", "--porcelain=v1", "-uall"], cwd=project, text=True)
|
|
111
|
-
|
|
112
|
-
run_args = (
|
|
113
|
-
(str(plan_path), "--dry-run")
|
|
114
|
-
if kind == "feature"
|
|
115
|
-
else (item_id, str(plan_path), "--dry-run")
|
|
116
|
-
)
|
|
117
|
-
result = run_pipeline_command(kind, "run", run_args, paths)
|
|
118
|
-
|
|
119
|
-
assert result.exit_code == 0
|
|
120
|
-
assert "processed=1 completed=False stopped_reason=dry_run" in result.render()
|
|
121
|
-
assert "last_status: dry_run" in result.render()
|
|
122
|
-
assert json.loads(plan_path.read_text(encoding="utf-8"))[list_key][0]["status"] == "pending"
|
|
123
|
-
assert subprocess.check_output(["git", "branch", "--show-current"], cwd=project, text=True).strip() == branch_before
|
|
124
|
-
assert subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=project, text=True).strip() == head_before
|
|
125
|
-
assert subprocess.check_output(["git", "status", "--porcelain=v1", "-uall"], cwd=project, text=True) == status_before
|
|
126
|
-
assert not (project / "AI_WAS_LAUNCHED").exists()
|
|
127
|
-
assert not (project / ".prizmkit" / "state").exists()
|
|
128
|
-
assert not (project / ".prizmkit" / "specs").exists()
|
|
129
|
-
assert not (project / ".prizmkit" / "bugfix").exists()
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def _get_next_result(kind, paths):
|
|
133
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
134
|
-
from prizmkit_runtime.runner_status import get_next
|
|
135
|
-
|
|
136
|
-
family = family_for(kind, paths)
|
|
137
|
-
invocation = parse_invocation(family, "run", ())
|
|
138
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": family.plan_path})
|
|
139
|
-
return get_next(family, invocation, paths.project_root)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def _item_id_from_next_result(kind, result):
|
|
143
|
-
key = {"feature": "feature_id", "bugfix": "bug_id"}[kind]
|
|
144
|
-
return result.data[key]
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
def test_retired_shell_runtime_files_are_absent_from_source():
|
|
148
|
-
retired = [
|
|
149
|
-
"run-feature.sh",
|
|
150
|
-
"run-bugfix.sh",
|
|
151
|
-
"run-recovery.sh",
|
|
152
|
-
"launch-feature-daemon.sh",
|
|
153
|
-
"launch-bugfix-daemon.sh",
|
|
154
|
-
"reset-feature.sh",
|
|
155
|
-
"reset-bug.sh",
|
|
156
|
-
"lib/branch.sh",
|
|
157
|
-
"lib/common.sh",
|
|
158
|
-
"lib/heartbeat.sh",
|
|
159
|
-
]
|
|
160
|
-
|
|
161
|
-
for relative_path in retired:
|
|
162
|
-
assert not (PIPELINE_ROOT / relative_path).exists(), relative_path
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
def test_python_parity_suite_declares_coverage_for_all_legacy_unix_snapshot_scenarios():
|
|
166
|
-
"""Keep the F-011 snapshot as an explicit oracle without reviving shell sources."""
|
|
167
|
-
import ast
|
|
168
|
-
|
|
169
|
-
snapshot = _load_unix_runtime_snapshot()
|
|
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
|
-
|
|
177
|
-
coverage_tokens = {
|
|
178
|
-
"entrypointContracts": {
|
|
179
|
-
"runnerHelpContracts": ["test_cli_help_exposes_only_operation_first_public_namespaces"],
|
|
180
|
-
"runnerMissingListErrors": ["test_python_runner_missing_list_errors_match_snapshot_contract"],
|
|
181
|
-
"resetHelpContracts": ["test_reset_and_daemon_entrypoint_contracts_match_snapshot_contracts"],
|
|
182
|
-
"daemonStatusContracts": ["test_reset_and_daemon_entrypoint_contracts_match_snapshot_contracts"],
|
|
183
|
-
},
|
|
184
|
-
"envResolution": {
|
|
185
|
-
"verboseAndStreamJson": ["test_python_env_resolution_scenarios_match_snapshot_contracts"],
|
|
186
|
-
"effortModelAndCli": ["test_ai_session_command_builders_match_unix_runtime_snapshot"],
|
|
187
|
-
"worktreeIgnored": ["test_runner_environment_retires_use_worktree_and_ignores_env"],
|
|
188
|
-
"autoPushFlag": ["test_successful_branch_session_merges_and_honors_auto_push"],
|
|
189
|
-
},
|
|
190
|
-
"aiCliCommands": {
|
|
191
|
-
"claudeCommand": ["test_ai_session_command_builders_match_unix_runtime_snapshot"],
|
|
192
|
-
"codexCommand": ["test_ai_session_command_builders_match_unix_runtime_snapshot"],
|
|
193
|
-
"customWrapperCommand": ["test_ai_session_command_builders_match_unix_runtime_snapshot"],
|
|
194
|
-
},
|
|
195
|
-
"fakeCliOutcomes": {
|
|
196
|
-
"success": ["test_session_dual_writes_progress_and_recovers_backup"],
|
|
197
|
-
"contextOverflowContinuation": ["test_context_overflow_reuses_branch_and_skips_cleanup_until_terminal_outcome"],
|
|
198
|
-
"infraErrorRetry": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
199
|
-
"crashFailure": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
200
|
-
"timeoutStaleKill": ["test_heartbeat_fatal_error_writes_shell_compatible_markers"],
|
|
201
|
-
},
|
|
202
|
-
"artifactShapes": {
|
|
203
|
-
"sessionLogsAndProgress": ["test_session_dual_writes_progress_and_recovers_backup"],
|
|
204
|
-
"homeBackupNormalization": ["test_session_dual_writes_progress_and_recovers_backup"],
|
|
205
|
-
},
|
|
206
|
-
"resetBehavior": {
|
|
207
|
-
"manualResetWarningOrder": ["test_python_reset_warns_before_mutation_and_matches_snapshot_cleanup"],
|
|
208
|
-
"cleanResetDeletesContinuationArtifacts": ["test_python_clean_reset_deletes_continuation_artifacts_for_all_families"],
|
|
209
|
-
},
|
|
210
|
-
"daemonBehavior": {
|
|
211
|
-
"stalePidStatusByTaskType": ["test_python_daemon_stale_pid_matches_snapshot"],
|
|
212
|
-
"controlledStartStop": ["test_python_daemon_controlled_start_status_stop_matches_snapshot"],
|
|
213
|
-
},
|
|
214
|
-
"continuationBehavior": {
|
|
215
|
-
"noProgressStall": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
216
|
-
"branchAndArtifactReuse": ["test_context_overflow_reuses_branch_and_skips_cleanup_until_terminal_outcome"],
|
|
217
|
-
},
|
|
218
|
-
"statusUpdaterBehavior": {
|
|
219
|
-
"contextOverflowMetadata": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
220
|
-
"infraErrorRetryBudget": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
221
|
-
"crashFailureBudget": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
222
|
-
"resetCleanMetadataCleanup": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
223
|
-
"noProgressStall": ["test_status_updater_behavior_matches_unix_runtime_snapshot"],
|
|
224
|
-
},
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
assert set(coverage_tokens) == set(snapshot["requiredScenarios"])
|
|
228
|
-
for section, scenario_names in snapshot["requiredScenarios"].items():
|
|
229
|
-
assert set(coverage_tokens[section]) == set(scenario_names), section
|
|
230
|
-
for scenario_name, tokens in coverage_tokens[section].items():
|
|
231
|
-
assert tokens, f"{section}.{scenario_name} has no coverage tokens"
|
|
232
|
-
for token in tokens:
|
|
233
|
-
assert token in test_names, f"{section}.{scenario_name} coverage test missing: {token}"
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
def test_python_runner_missing_list_errors_match_snapshot_contract(tmp_path):
|
|
237
|
-
from prizmkit_runtime.runners import run_pipeline_command
|
|
238
|
-
|
|
239
|
-
snapshot = _load_unix_runtime_snapshot()["entrypointContracts"]["runnerMissingListErrors"]
|
|
240
|
-
for kind in ("feature", "bugfix"):
|
|
241
|
-
paths = _make_paths(tmp_path / f"missing-{kind}")
|
|
242
|
-
result = run_pipeline_command(kind, "run", (), paths)
|
|
243
|
-
|
|
244
|
-
assert result.exit_code == snapshot[kind]["exitCode"]
|
|
245
|
-
assert "Plan list not found" in result.render()
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
def test_reset_and_daemon_entrypoint_contracts_match_snapshot_contracts(tmp_path):
|
|
249
|
-
from prizmkit_runtime.daemon import run_daemon_command
|
|
250
|
-
from prizmkit_runtime.paths import resolve_runtime_paths
|
|
251
|
-
from prizmkit_runtime.reset import run_reset_command
|
|
252
|
-
|
|
253
|
-
snapshot = _load_unix_runtime_snapshot()["entrypointContracts"]
|
|
254
|
-
paths = _make_paths(tmp_path / "entrypoints")
|
|
255
|
-
|
|
256
|
-
for kind in ("feature", "bugfix"):
|
|
257
|
-
reset = run_reset_command(kind, ("--help",), paths)
|
|
258
|
-
assert reset.exit_code == snapshot["resetHelpContracts"][kind]["exitCode"]
|
|
259
|
-
assert "Usage: prizmkit-runtime reset" in reset.render()
|
|
260
|
-
|
|
261
|
-
daemon_paths = resolve_runtime_paths(
|
|
262
|
-
pipeline_root=PIPELINE_ROOT,
|
|
263
|
-
project_root=tmp_path / "daemon-status" / kind,
|
|
264
|
-
)
|
|
265
|
-
daemon = run_daemon_command(kind, "status", (), daemon_paths)
|
|
266
|
-
payload = json.loads(daemon.render())
|
|
267
|
-
assert daemon.exit_code == snapshot["daemonStatusContracts"][kind]["exitCode"]
|
|
268
|
-
assert payload["running"] is False
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
def test_python_env_resolution_scenarios_match_snapshot_contracts(tmp_path):
|
|
272
|
-
from prizmkit_runtime.sessions import AISessionConfig, build_ai_session_command, detect_stream_json_support
|
|
273
|
-
|
|
274
|
-
snapshot = _load_unix_runtime_snapshot()["envResolution"]
|
|
275
|
-
prompt = tmp_path / "prompt.md"
|
|
276
|
-
prompt.write_text("hello", encoding="utf-8")
|
|
277
|
-
|
|
278
|
-
claude = build_ai_session_command(
|
|
279
|
-
AISessionConfig(
|
|
280
|
-
cli_command="claude",
|
|
281
|
-
platform="claude",
|
|
282
|
-
model=None,
|
|
283
|
-
prompt_path=prompt,
|
|
284
|
-
cwd=tmp_path,
|
|
285
|
-
verbose=True,
|
|
286
|
-
)
|
|
287
|
-
)
|
|
288
|
-
assert ("--verbose" in claude.argv) is snapshot["verboseAndStreamJson"]["claudeVerboseHasFlag"]
|
|
289
|
-
|
|
290
|
-
codebuddy = build_ai_session_command(
|
|
291
|
-
AISessionConfig(
|
|
292
|
-
cli_command="cbc",
|
|
293
|
-
platform="codebuddy",
|
|
294
|
-
model=None,
|
|
295
|
-
prompt_path=prompt,
|
|
296
|
-
cwd=tmp_path,
|
|
297
|
-
use_stream_json=True,
|
|
298
|
-
)
|
|
299
|
-
)
|
|
300
|
-
assert ("--output-format" in codebuddy.argv and "stream-json" in codebuddy.argv) is snapshot["verboseAndStreamJson"]["codebuddyStreamJsonHasFlag"]
|
|
301
|
-
|
|
302
|
-
codex_support = detect_stream_json_support("codex", "codex", lambda command: "Usage: codex exec --json")
|
|
303
|
-
assert codex_support.enabled is True
|
|
304
|
-
assert codex_support.format == "codex-json"
|
|
305
|
-
|
|
306
|
-
cursor = build_ai_session_command(
|
|
307
|
-
AISessionConfig(
|
|
308
|
-
cli_command="agent",
|
|
309
|
-
platform="cursor",
|
|
310
|
-
model="cursor-model",
|
|
311
|
-
prompt_path=prompt,
|
|
312
|
-
cwd=tmp_path,
|
|
313
|
-
use_stream_json=True,
|
|
314
|
-
)
|
|
315
|
-
)
|
|
316
|
-
assert cursor.argv == (
|
|
317
|
-
"agent", "--print", "--force", "--trust", "--output-format", "stream-json",
|
|
318
|
-
"--model", "cursor-model",
|
|
319
|
-
)
|
|
320
|
-
assert cursor.stdin_text == "hello"
|
|
321
|
-
assert "hello" not in cursor.argv
|
|
322
|
-
cursor_support = detect_stream_json_support(
|
|
323
|
-
"agent",
|
|
324
|
-
"cursor",
|
|
325
|
-
lambda command: "Cursor Agent --print --force --trust --output-format stream-json",
|
|
326
|
-
)
|
|
327
|
-
assert cursor_support.enabled is True
|
|
328
|
-
assert cursor_support.format == "cursor-stream-json"
|
|
329
|
-
|
|
330
|
-
agy = build_ai_session_command(
|
|
331
|
-
AISessionConfig(
|
|
332
|
-
cli_command="agy",
|
|
333
|
-
platform="antigravity",
|
|
334
|
-
model="gemini-model",
|
|
335
|
-
effort="xhigh",
|
|
336
|
-
prompt_path=prompt,
|
|
337
|
-
cwd=tmp_path,
|
|
338
|
-
use_stream_json=True,
|
|
339
|
-
)
|
|
340
|
-
)
|
|
341
|
-
assert agy.argv == (
|
|
342
|
-
"agy", "--dangerously-skip-permissions", "--input-format", "stream-json",
|
|
343
|
-
"--output-format", "stream-json", "--model", "gemini-model", "--effort", "xhigh",
|
|
344
|
-
)
|
|
345
|
-
assert json.loads(agy.stdin_text) == {"event": "user", "message": {"content": "hello"}}
|
|
346
|
-
assert agy.prompt_mode == "stdin"
|
|
347
|
-
assert "hello" not in agy.argv
|
|
348
|
-
|
|
349
|
-
agy_fallback = build_ai_session_command(
|
|
350
|
-
AISessionConfig(
|
|
351
|
-
cli_command="agy",
|
|
352
|
-
platform="antigravity",
|
|
353
|
-
model=None,
|
|
354
|
-
prompt_path=prompt,
|
|
355
|
-
cwd=tmp_path,
|
|
356
|
-
use_stream_json=False,
|
|
357
|
-
)
|
|
358
|
-
)
|
|
359
|
-
assert agy_fallback.argv == ("agy", "-p", "hello", "--dangerously-skip-permissions")
|
|
360
|
-
assert agy_fallback.stdin_text is None
|
|
361
|
-
assert agy_fallback.prompt_mode == "argument"
|
|
362
|
-
|
|
363
|
-
agy_support = detect_stream_json_support(
|
|
364
|
-
"agy",
|
|
365
|
-
"antigravity",
|
|
366
|
-
lambda command: "--print --dangerously-skip-permissions --input-format --output-format stream-json",
|
|
367
|
-
)
|
|
368
|
-
assert agy_support.enabled is True
|
|
369
|
-
assert agy_support.format == "antigravity-stream-json"
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
def test_windows_structural_paths_use_installed_python_runtime_layout(tmp_path):
|
|
373
|
-
from prizmkit_runtime.paths import resolve_runtime_paths
|
|
374
|
-
|
|
375
|
-
installed_pipeline = tmp_path / "project" / ".prizmkit" / "dev-pipeline"
|
|
376
|
-
installed_pipeline.mkdir(parents=True)
|
|
377
|
-
|
|
378
|
-
paths = resolve_runtime_paths(pipeline_root=installed_pipeline)
|
|
379
|
-
|
|
380
|
-
assert paths.layout == "installed"
|
|
381
|
-
assert paths.project_root == tmp_path / "project"
|
|
382
|
-
assert paths.pipeline_root == installed_pipeline.resolve()
|
|
383
|
-
assert all("dev-pipeline-windows" not in str(value) for value in paths.path_values())
|
|
384
|
-
assert all(not str(value).endswith(".ps1") for value in paths.path_values())
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
def test_windows_process_tree_termination_strategy_is_taskkill_backed_without_powershell(monkeypatch, tmp_path):
|
|
388
|
-
from prizmkit_runtime import processes
|
|
389
|
-
from prizmkit_runtime.processes import ProcessHandle, ProcessSpec
|
|
390
|
-
|
|
391
|
-
calls = []
|
|
392
|
-
|
|
393
|
-
class FakeCompleted:
|
|
394
|
-
returncode = 0
|
|
395
|
-
stdout = ""
|
|
396
|
-
stderr = ""
|
|
397
|
-
|
|
398
|
-
def fake_run(command, **kwargs):
|
|
399
|
-
calls.append((tuple(command), kwargs))
|
|
400
|
-
return FakeCompleted()
|
|
401
|
-
|
|
402
|
-
monkeypatch.setattr(processes.os, "name", "nt")
|
|
403
|
-
monkeypatch.setattr(processes.subprocess, "CREATE_NEW_PROCESS_GROUP", 0x200, raising=False)
|
|
404
|
-
monkeypatch.setattr(processes.subprocess, "run", fake_run)
|
|
405
|
-
|
|
406
|
-
spec = ProcessSpec(command=(sys.executable, "-c", "pass"), cwd=tmp_path)
|
|
407
|
-
handle = ProcessHandle(pid=1234, spec=spec, status="running", popen=None)
|
|
408
|
-
launched_flags = processes._creationflags_for_platform(True)
|
|
409
|
-
handle_result = processes.terminate_process_tree(handle, "test-timeout", grace_seconds=0)
|
|
410
|
-
|
|
411
|
-
assert launched_flags == 0x200
|
|
412
|
-
assert processes.platform_termination_strategy() == ("CREATE_NEW_PROCESS_GROUP", "taskkill /PID <pid> /T /F")
|
|
413
|
-
assert handle_result.terminated is True
|
|
414
|
-
assert handle_result.forced is True
|
|
415
|
-
assert calls[-1][0] == ("taskkill", "/PID", "1234", "/T", "/F")
|
|
416
|
-
|
|
417
|
-
calls.clear()
|
|
418
|
-
monkeypatch.setattr(processes, "is_pid_running", lambda pid: True)
|
|
419
|
-
pid_result = processes.terminate_pid_tree(5678, "daemon-stop", grace_seconds=0)
|
|
420
|
-
|
|
421
|
-
assert pid_result.terminated is True
|
|
422
|
-
assert pid_result.forced is True
|
|
423
|
-
assert calls[-1][0] == ("taskkill", "/PID", "5678", "/T", "/F")
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
def test_runner_models_parse_legacy_args_and_environment(tmp_path):
|
|
427
|
-
from prizmkit_runtime.runner_models import RunnerEnvironment, family_for, parse_invocation
|
|
428
|
-
|
|
429
|
-
paths = _make_paths(tmp_path)
|
|
430
|
-
family = family_for("feature", paths)
|
|
431
|
-
invocation = parse_invocation(
|
|
432
|
-
family,
|
|
433
|
-
"run",
|
|
434
|
-
("custom-list.json", "F-2", "--features", "F-003:F-001", "--max-retries", "7", "--max-infra-retries=5"),
|
|
435
|
-
)
|
|
436
|
-
env = RunnerEnvironment.from_env(
|
|
437
|
-
{
|
|
438
|
-
"STOP_ON_FAILURE": "1",
|
|
439
|
-
"AUTO_PUSH": "true",
|
|
440
|
-
"DEV_BRANCH": "dev/custom",
|
|
441
|
-
"VERBOSE": "1",
|
|
442
|
-
"STALE_KILL_THRESHOLD": "9",
|
|
443
|
-
"MAX_RETRIES": "9",
|
|
444
|
-
}
|
|
445
|
-
)
|
|
446
|
-
|
|
447
|
-
assert invocation.list_path == Path("custom-list.json")
|
|
448
|
-
assert invocation.item_id == "F-002"
|
|
449
|
-
assert invocation.item_filter == "F-003:F-001"
|
|
450
|
-
assert invocation.max_retries == 7
|
|
451
|
-
assert invocation.max_infra_retries == 5
|
|
452
|
-
assert not hasattr(invocation, "mode")
|
|
453
|
-
assert env.stop_on_failure is True
|
|
454
|
-
assert env.auto_push is True
|
|
455
|
-
assert env.dev_branch == "dev/custom"
|
|
456
|
-
assert env.stale_kill_threshold_seconds == 9
|
|
457
|
-
assert env.max_retries == 9
|
|
458
|
-
assert not hasattr(env, "enable_deploy")
|
|
459
|
-
assert not hasattr(env, "max_" + "log_size")
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
def test_runner_environment_retires_use_worktree_and_ignores_env():
|
|
463
|
-
from prizmkit_runtime.runner_models import RunnerEnvironment
|
|
464
|
-
|
|
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
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
def test_status_bridge_preserves_feature_filter_selection(tmp_path):
|
|
472
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
473
|
-
from prizmkit_runtime.runner_status import get_next, start_item, update_item
|
|
474
|
-
|
|
475
|
-
paths = _make_paths(tmp_path)
|
|
476
|
-
_write_feature_list(paths)
|
|
477
|
-
family = family_for("feature", paths)
|
|
478
|
-
invocation = parse_invocation(family, "run", ("--features", "F-002:F-003"))
|
|
479
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
480
|
-
|
|
481
|
-
next_result = get_next(family, invocation, paths.project_root)
|
|
482
|
-
assert next_result.ok
|
|
483
|
-
assert isinstance(next_result.data, dict)
|
|
484
|
-
assert next_result.data["feature_id"] == "F-002"
|
|
485
|
-
|
|
486
|
-
start = start_item(family, invocation, "F-002", paths.project_root)
|
|
487
|
-
assert start.ok
|
|
488
|
-
assert start.data["new_status"] == "in_progress"
|
|
489
|
-
|
|
490
|
-
update = update_item(family, invocation, "F-002", "context_overflow", "F-002-session", paths.project_root, active_dev_branch="dev/F-002", base_branch="main", no_progress_count=0, progress_fingerprint={"head_commit": "abc"})
|
|
491
|
-
assert update.ok
|
|
492
|
-
assert update.data["new_status"] == "in_progress"
|
|
493
|
-
assert update.data["restart_policy"] == "context_overflow_continuation"
|
|
494
|
-
assert update.data["context_overflow_count"] == 1
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
def test_status_bridge_uses_stable_dependency_order_across_pipeline_families(tmp_path):
|
|
498
|
-
cases = {
|
|
499
|
-
"feature": [
|
|
500
|
-
{"id": "F-001", "title": "Blocked", "status": "pending", "priority": "critical", "dependencies": ["F-002"]},
|
|
501
|
-
{"id": "F-002", "title": "First", "status": "pending", "priority": "low", "dependencies": []},
|
|
502
|
-
{"id": "F-003", "title": "Independent", "status": "pending", "priority": "high", "dependencies": []},
|
|
503
|
-
],
|
|
504
|
-
"bugfix": [
|
|
505
|
-
{"id": "B-001", "title": "Blocked", "status": "pending", "severity": "critical", "priority": "high", "error_source": {"type": "user_report"}, "verification_type": "manual", "acceptance_criteria": ["fixed"], "dependencies": ["B-002"]},
|
|
506
|
-
{"id": "B-002", "title": "First", "status": "pending", "severity": "low", "priority": "low", "error_source": {"type": "user_report"}, "verification_type": "manual", "acceptance_criteria": ["fixed"], "dependencies": []},
|
|
507
|
-
{"id": "B-003", "title": "Independent", "status": "pending", "severity": "high", "priority": "high", "error_source": {"type": "user_report"}, "verification_type": "manual", "acceptance_criteria": ["fixed"], "dependencies": []},
|
|
508
|
-
],
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
for kind, items in cases.items():
|
|
512
|
-
paths = _make_paths(tmp_path / f"stable-{kind}")
|
|
513
|
-
_write_family_plan(paths, kind, items)
|
|
514
|
-
|
|
515
|
-
result = _get_next_result(kind, paths)
|
|
516
|
-
|
|
517
|
-
assert result.ok
|
|
518
|
-
assert _item_id_from_next_result(kind, result) == {"feature": "F-002", "bugfix": "B-002"}[kind]
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
def test_status_bridge_prefers_in_progress_items_with_satisfied_dependencies(tmp_path):
|
|
522
|
-
cases = {
|
|
523
|
-
"feature": [
|
|
524
|
-
{"id": "F-001", "title": "Done", "status": "completed", "priority": "low", "dependencies": []},
|
|
525
|
-
{"id": "F-002", "title": "Resume", "status": "in_progress", "priority": "low", "dependencies": ["F-001"]},
|
|
526
|
-
{"id": "F-003", "title": "Pending", "status": "pending", "priority": "critical", "dependencies": []},
|
|
527
|
-
],
|
|
528
|
-
"bugfix": [
|
|
529
|
-
{"id": "B-001", "title": "Done", "status": "completed", "severity": "low", "priority": "low", "error_source": {"type": "user_report"}, "verification_type": "manual", "acceptance_criteria": ["fixed"], "dependencies": []},
|
|
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"]},
|
|
531
|
-
{"id": "B-003", "title": "Pending", "status": "pending", "severity": "critical", "priority": "high", "error_source": {"type": "user_report"}, "verification_type": "manual", "acceptance_criteria": ["fixed"], "dependencies": []},
|
|
532
|
-
],
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
for kind, items in cases.items():
|
|
536
|
-
paths = _make_paths(tmp_path / f"resume-{kind}")
|
|
537
|
-
_write_family_plan(paths, kind, items)
|
|
538
|
-
|
|
539
|
-
result = _get_next_result(kind, paths)
|
|
540
|
-
|
|
541
|
-
assert result.ok
|
|
542
|
-
assert _item_id_from_next_result(kind, result) == {"feature": "F-002", "bugfix": "B-002"}[kind]
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
def test_init_scripts_reject_missing_self_and_cycle_dependencies(tmp_path):
|
|
546
|
-
script_config = {
|
|
547
|
-
"feature": ("init-pipeline.py", "--feature-list", "F-", "missing dependency"),
|
|
548
|
-
"bugfix": ("init-bugfix-pipeline.py", "--bug-list", "B-", "missing dependency"),
|
|
549
|
-
}
|
|
550
|
-
scenarios = {
|
|
551
|
-
"missing": lambda kind, prefix: _family_items(kind, [
|
|
552
|
-
(f"{prefix}001", [f"{prefix}999"], "pending"),
|
|
553
|
-
]),
|
|
554
|
-
"self": lambda kind, prefix: _family_items(kind, [
|
|
555
|
-
(f"{prefix}001", [f"{prefix}001"], "pending"),
|
|
556
|
-
]),
|
|
557
|
-
"cycle": lambda kind, prefix: _family_items(kind, [
|
|
558
|
-
(f"{prefix}001", [f"{prefix}002"], "pending"),
|
|
559
|
-
(f"{prefix}002", [f"{prefix}001"], "pending"),
|
|
560
|
-
]),
|
|
561
|
-
}
|
|
562
|
-
expected_fragments = {
|
|
563
|
-
"missing": "missing dependency",
|
|
564
|
-
"self": "cannot depend on itself",
|
|
565
|
-
"cycle": "Dependency cycle detected",
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
for kind, (script_name, list_arg, prefix, _missing_fragment) in script_config.items():
|
|
569
|
-
for scenario, build_items in scenarios.items():
|
|
570
|
-
paths = _make_paths(tmp_path / f"init-{kind}-{scenario}")
|
|
571
|
-
plan_path = _write_family_plan(paths, kind, build_items(kind, prefix))
|
|
572
|
-
result = subprocess.run(
|
|
573
|
-
[
|
|
574
|
-
PYTHON_310_PLUS,
|
|
575
|
-
str(PIPELINE_ROOT / "scripts" / script_name),
|
|
576
|
-
list_arg,
|
|
577
|
-
str(plan_path),
|
|
578
|
-
"--state-dir",
|
|
579
|
-
str(paths.project_root / ".prizmkit" / "state" / f"init-{kind}-{scenario}"),
|
|
580
|
-
],
|
|
581
|
-
cwd=REPO_ROOT,
|
|
582
|
-
stdout=subprocess.PIPE,
|
|
583
|
-
stderr=subprocess.PIPE,
|
|
584
|
-
text=True,
|
|
585
|
-
check=False,
|
|
586
|
-
)
|
|
587
|
-
|
|
588
|
-
assert result.returncode == 1, (kind, scenario, result.stdout, result.stderr)
|
|
589
|
-
payload = json.loads(result.stdout)
|
|
590
|
-
assert any(expected_fragments[scenario] in error for error in payload["errors"])
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
def test_init_scripts_reject_unknown_item_fields(tmp_path):
|
|
594
|
-
script_config = {
|
|
595
|
-
"feature": ("init-pipeline.py", "--feature-list", "F-"),
|
|
596
|
-
"bugfix": ("init-bugfix-pipeline.py", "--bug-list", "B-"),
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
for kind, (script_name, list_arg, prefix) in script_config.items():
|
|
600
|
-
paths = _make_paths(tmp_path / f"init-{kind}-unknown-field")
|
|
601
|
-
items = _family_items(kind, [(f"{prefix}001", [], "pending")])
|
|
602
|
-
items[0]["unexpected_field"] = True
|
|
603
|
-
plan_path = _write_family_plan(paths, kind, items)
|
|
604
|
-
result = subprocess.run(
|
|
605
|
-
[
|
|
606
|
-
PYTHON_310_PLUS,
|
|
607
|
-
str(PIPELINE_ROOT / "scripts" / script_name),
|
|
608
|
-
list_arg,
|
|
609
|
-
str(plan_path),
|
|
610
|
-
"--state-dir",
|
|
611
|
-
str(paths.project_root / ".prizmkit" / "state" / f"init-{kind}-unknown-field"),
|
|
612
|
-
],
|
|
613
|
-
cwd=REPO_ROOT,
|
|
614
|
-
stdout=subprocess.PIPE,
|
|
615
|
-
stderr=subprocess.PIPE,
|
|
616
|
-
text=True,
|
|
617
|
-
check=False,
|
|
618
|
-
)
|
|
619
|
-
|
|
620
|
-
assert result.returncode == 1, (kind, result.stdout, result.stderr)
|
|
621
|
-
payload = json.loads(result.stdout)
|
|
622
|
-
assert any("unknown fields: unexpected_field" in error for error in payload["errors"])
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
def test_init_pipeline_accepts_historical_leftover_nested_fields(tmp_path):
|
|
626
|
-
paths = _make_paths(tmp_path / "init-feature-leftover-nested")
|
|
627
|
-
items = _family_items("feature", [("F-001", [], "pending")])
|
|
628
|
-
items[0]["session_granularity"] = "auto"
|
|
629
|
-
items[0]["sub_features"] = [
|
|
630
|
-
{
|
|
631
|
-
"id": "F-001-A",
|
|
632
|
-
"title": "Nested leftover",
|
|
633
|
-
"description": "Unused nested work that Runtime never scheduled.",
|
|
634
|
-
}
|
|
635
|
-
]
|
|
636
|
-
plan_path = _write_family_plan(paths, "feature", items)
|
|
637
|
-
result = subprocess.run(
|
|
638
|
-
[
|
|
639
|
-
PYTHON_310_PLUS,
|
|
640
|
-
str(PIPELINE_ROOT / "scripts" / "init-pipeline.py"),
|
|
641
|
-
"--feature-list",
|
|
642
|
-
str(plan_path),
|
|
643
|
-
"--state-dir",
|
|
644
|
-
str(paths.project_root / ".prizmkit" / "state" / "init-feature-leftover-nested"),
|
|
645
|
-
],
|
|
646
|
-
cwd=REPO_ROOT,
|
|
647
|
-
stdout=subprocess.PIPE,
|
|
648
|
-
stderr=subprocess.PIPE,
|
|
649
|
-
text=True,
|
|
650
|
-
check=False,
|
|
651
|
-
)
|
|
652
|
-
|
|
653
|
-
assert result.returncode == 0, (result.stdout, result.stderr)
|
|
654
|
-
payload = json.loads(result.stdout)
|
|
655
|
-
assert payload["valid"] is True
|
|
656
|
-
assert "errors" not in payload or payload["errors"] == []
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
@pytest.mark.parametrize("location", ("root", "global_context"))
|
|
660
|
-
def test_init_scripts_reject_unknown_list_fields(tmp_path, location):
|
|
661
|
-
script_config = {
|
|
662
|
-
"feature": ("init-pipeline.py", "--feature-list", "F-"),
|
|
663
|
-
"bugfix": ("init-bugfix-pipeline.py", "--bug-list", "B-"),
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
for kind, (script_name, list_arg, prefix) in script_config.items():
|
|
667
|
-
paths = _make_paths(tmp_path / f"init-{kind}-unknown-{location}")
|
|
668
|
-
items = _family_items(kind, [(f"{prefix}001", [], "pending")])
|
|
669
|
-
plan_path = _write_family_plan(paths, kind, items)
|
|
670
|
-
payload = json.loads(plan_path.read_text(encoding="utf-8"))
|
|
671
|
-
if location == "root":
|
|
672
|
-
payload["unexpected_field"] = True
|
|
673
|
-
else:
|
|
674
|
-
payload["global_context"] = {"unexpected_field": True}
|
|
675
|
-
plan_path.write_text(json.dumps(payload), encoding="utf-8")
|
|
676
|
-
|
|
677
|
-
result = subprocess.run(
|
|
678
|
-
[
|
|
679
|
-
PYTHON_310_PLUS,
|
|
680
|
-
str(PIPELINE_ROOT / "scripts" / script_name),
|
|
681
|
-
list_arg,
|
|
682
|
-
str(plan_path),
|
|
683
|
-
"--state-dir",
|
|
684
|
-
str(paths.project_root / ".prizmkit" / "state" / f"init-{kind}-unknown-{location}"),
|
|
685
|
-
],
|
|
686
|
-
cwd=REPO_ROOT,
|
|
687
|
-
stdout=subprocess.PIPE,
|
|
688
|
-
stderr=subprocess.PIPE,
|
|
689
|
-
text=True,
|
|
690
|
-
check=False,
|
|
691
|
-
)
|
|
692
|
-
|
|
693
|
-
assert result.returncode == 1, (kind, location, result.stdout, result.stderr)
|
|
694
|
-
output = json.loads(result.stdout)
|
|
695
|
-
assert any("unknown fields: unexpected_field" in error for error in output["errors"])
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
def test_planner_validators_reject_unknown_item_fields():
|
|
699
|
-
from importlib.util import module_from_spec, spec_from_file_location
|
|
700
|
-
|
|
701
|
-
planner_config = {
|
|
702
|
-
"feature": (
|
|
703
|
-
"core/skills/orchestration-skill/pipelines/feature-planner/scripts/validate-and-generate.py",
|
|
704
|
-
"validate_feature_list",
|
|
705
|
-
"features",
|
|
706
|
-
"dev-pipeline-feature-list-v1",
|
|
707
|
-
"F-",
|
|
708
|
-
),
|
|
709
|
-
"bugfix": (
|
|
710
|
-
"core/skills/orchestration-skill/pipelines/bug-planner/scripts/validate-bug-list.py",
|
|
711
|
-
"validate",
|
|
712
|
-
"bugs",
|
|
713
|
-
"dev-pipeline-bug-fix-list-v1",
|
|
714
|
-
"B-",
|
|
715
|
-
),
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
for kind, (relative_path, function_name, list_key, schema, prefix) in planner_config.items():
|
|
719
|
-
script_path = REPO_ROOT / relative_path
|
|
720
|
-
spec = spec_from_file_location(f"{kind}_planner_unknown_field", script_path)
|
|
721
|
-
module = module_from_spec(spec)
|
|
722
|
-
spec.loader.exec_module(module)
|
|
723
|
-
items = _family_items(kind, [(f"{prefix}001", [], "pending")])
|
|
724
|
-
items[0]["unexpected_field"] = True
|
|
725
|
-
result = getattr(module, function_name)({
|
|
726
|
-
"$schema": schema,
|
|
727
|
-
"project_name": "Fake",
|
|
728
|
-
list_key: items,
|
|
729
|
-
})
|
|
730
|
-
|
|
731
|
-
assert result["valid"] is False
|
|
732
|
-
assert any("unknown fields: unexpected_field" in error for error in result["errors"])
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
def test_feature_planner_validator_accepts_historical_leftover_nested_fields():
|
|
736
|
-
from importlib.util import module_from_spec, spec_from_file_location
|
|
737
|
-
|
|
738
|
-
script_path = REPO_ROOT / (
|
|
739
|
-
"core/skills/orchestration-skill/pipelines/feature-planner/scripts/validate-and-generate.py"
|
|
740
|
-
)
|
|
741
|
-
spec = spec_from_file_location("feature_planner_leftover_nested", script_path)
|
|
742
|
-
module = module_from_spec(spec)
|
|
743
|
-
spec.loader.exec_module(module)
|
|
744
|
-
items = _family_items("feature", [("F-001", [], "pending")])
|
|
745
|
-
items[0]["description"] = (
|
|
746
|
-
"Historical list item that already stored unused nested leftover "
|
|
747
|
-
"fields from an older planner and must still validate successfully."
|
|
748
|
-
)
|
|
749
|
-
items[0]["session_granularity"] = "auto"
|
|
750
|
-
items[0]["sub_features"] = [
|
|
751
|
-
{
|
|
752
|
-
"id": "F-001-A",
|
|
753
|
-
"title": "Nested leftover",
|
|
754
|
-
"description": "Unused nested work that Runtime never scheduled.",
|
|
755
|
-
}
|
|
756
|
-
]
|
|
757
|
-
result = module.validate_feature_list({
|
|
758
|
-
"$schema": "dev-pipeline-feature-list-v1",
|
|
759
|
-
"project_name": "Fake",
|
|
760
|
-
"features": items,
|
|
761
|
-
})
|
|
762
|
-
|
|
763
|
-
assert result["valid"] is True, result["errors"]
|
|
764
|
-
assert "total_sub_features" not in result["stats"]
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
@pytest.mark.parametrize("location", ("root", "global_context"))
|
|
768
|
-
def test_planner_validators_reject_unknown_list_fields(location):
|
|
769
|
-
from importlib.util import module_from_spec, spec_from_file_location
|
|
770
|
-
|
|
771
|
-
planner_config = {
|
|
772
|
-
"feature": (
|
|
773
|
-
"core/skills/orchestration-skill/pipelines/feature-planner/scripts/validate-and-generate.py",
|
|
774
|
-
"validate_feature_list", "features", "dev-pipeline-feature-list-v1", "F-",
|
|
775
|
-
),
|
|
776
|
-
"bugfix": (
|
|
777
|
-
"core/skills/orchestration-skill/pipelines/bug-planner/scripts/validate-bug-list.py",
|
|
778
|
-
"validate", "bugs", "dev-pipeline-bug-fix-list-v1", "B-",
|
|
779
|
-
),
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
for kind, (relative_path, function_name, list_key, schema, prefix) in planner_config.items():
|
|
783
|
-
script_path = REPO_ROOT / relative_path
|
|
784
|
-
spec = spec_from_file_location(f"{kind}_planner_unknown_{location}", script_path)
|
|
785
|
-
module = module_from_spec(spec)
|
|
786
|
-
spec.loader.exec_module(module)
|
|
787
|
-
payload = {
|
|
788
|
-
"$schema": schema,
|
|
789
|
-
"project_name": "Fake",
|
|
790
|
-
list_key: _family_items(kind, [(f"{prefix}001", [], "pending")]),
|
|
791
|
-
}
|
|
792
|
-
if location == "root":
|
|
793
|
-
payload["unexpected_field"] = True
|
|
794
|
-
else:
|
|
795
|
-
payload["global_context"] = {"unexpected_field": True}
|
|
796
|
-
|
|
797
|
-
result = getattr(module, function_name)(payload)
|
|
798
|
-
|
|
799
|
-
assert result["valid"] is False
|
|
800
|
-
assert any("unknown fields: unexpected_field" in error for error in result["errors"])
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
def test_bug_planner_validator_rejects_dependency_cycles():
|
|
804
|
-
from importlib.util import module_from_spec, spec_from_file_location
|
|
805
|
-
|
|
806
|
-
script_path = REPO_ROOT / "core" / "skills" / "orchestration-skill" / "pipelines" / "bug-planner" / "scripts" / "validate-bug-list.py"
|
|
807
|
-
spec = spec_from_file_location("bug_planner_validate_bug_list", script_path)
|
|
808
|
-
module = module_from_spec(spec)
|
|
809
|
-
spec.loader.exec_module(module)
|
|
810
|
-
|
|
811
|
-
result = module.validate({
|
|
812
|
-
"$schema": "dev-pipeline-bug-fix-list-v1",
|
|
813
|
-
"project_name": "Fake",
|
|
814
|
-
"bugs": [
|
|
815
|
-
{
|
|
816
|
-
"id": "B-001",
|
|
817
|
-
"title": "First",
|
|
818
|
-
"description": "First bug",
|
|
819
|
-
"severity": "medium",
|
|
820
|
-
"error_source": {"type": "user_report"},
|
|
821
|
-
"verification_type": "manual",
|
|
822
|
-
"acceptance_criteria": ["fixed"],
|
|
823
|
-
"dependencies": ["B-002"],
|
|
824
|
-
"status": "pending",
|
|
825
|
-
},
|
|
826
|
-
{
|
|
827
|
-
"id": "B-002",
|
|
828
|
-
"title": "Second",
|
|
829
|
-
"description": "Second bug",
|
|
830
|
-
"severity": "medium",
|
|
831
|
-
"error_source": {"type": "user_report"},
|
|
832
|
-
"verification_type": "manual",
|
|
833
|
-
"acceptance_criteria": ["fixed"],
|
|
834
|
-
"dependencies": ["B-001"],
|
|
835
|
-
"status": "pending",
|
|
836
|
-
},
|
|
837
|
-
],
|
|
838
|
-
})
|
|
839
|
-
|
|
840
|
-
assert result["valid"] is False
|
|
841
|
-
assert any("Dependency cycle detected" in error for error in result["errors"])
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
def _family_items(kind, entries):
|
|
845
|
-
items = []
|
|
846
|
-
for item_id, dependencies, status in entries:
|
|
847
|
-
if kind == "feature":
|
|
848
|
-
items.append({
|
|
849
|
-
"id": item_id,
|
|
850
|
-
"title": item_id,
|
|
851
|
-
"description": "Implement this feature with enough detail for initialization validation.",
|
|
852
|
-
"priority": "medium",
|
|
853
|
-
"dependencies": dependencies,
|
|
854
|
-
"acceptance_criteria": ["done"],
|
|
855
|
-
"status": status,
|
|
856
|
-
})
|
|
857
|
-
elif kind == "bugfix":
|
|
858
|
-
items.append({
|
|
859
|
-
"id": item_id,
|
|
860
|
-
"title": item_id,
|
|
861
|
-
"description": "Bug description",
|
|
862
|
-
"severity": "medium",
|
|
863
|
-
"priority": "medium",
|
|
864
|
-
"error_source": {"type": "user_report"},
|
|
865
|
-
"verification_type": "manual",
|
|
866
|
-
"acceptance_criteria": ["fixed"],
|
|
867
|
-
"dependencies": dependencies,
|
|
868
|
-
"status": status,
|
|
869
|
-
})
|
|
870
|
-
else:
|
|
871
|
-
raise ValueError(f"Unsupported family kind: {kind}")
|
|
872
|
-
return items
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
def test_status_bridge_passes_max_retries_from_invocation_or_environment(monkeypatch, tmp_path):
|
|
876
|
-
import subprocess
|
|
877
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
878
|
-
from prizmkit_runtime.runner_status import status_text
|
|
879
|
-
|
|
880
|
-
paths = _make_paths(tmp_path)
|
|
881
|
-
family = family_for("feature", paths)
|
|
882
|
-
explicit = parse_invocation(family, "run", ("--max-retries", "8"))
|
|
883
|
-
explicit = explicit.__class__(**{**explicit.__dict__, "list_path": paths.feature_plan})
|
|
884
|
-
fallback = parse_invocation(family, "run", ())
|
|
885
|
-
fallback = fallback.__class__(**{**fallback.__dict__, "list_path": paths.feature_plan})
|
|
886
|
-
calls = []
|
|
887
|
-
|
|
888
|
-
def fake_run(command, **kwargs):
|
|
889
|
-
calls.append(tuple(command))
|
|
890
|
-
return subprocess.CompletedProcess(command, 0, stdout="PIPELINE_COMPLETE\n", stderr="")
|
|
891
|
-
|
|
892
|
-
monkeypatch.setattr(subprocess, "run", fake_run)
|
|
893
|
-
monkeypatch.setenv("MAX_RETRIES", "6")
|
|
894
|
-
|
|
895
|
-
status_text(family, explicit, paths.project_root)
|
|
896
|
-
status_text(family, fallback, paths.project_root)
|
|
897
|
-
|
|
898
|
-
first = calls[0]
|
|
899
|
-
second = calls[1]
|
|
900
|
-
assert first[first.index("--max-retries") + 1] == "8"
|
|
901
|
-
assert second[second.index("--max-retries") + 1] == "6"
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
@pytest.mark.parametrize(
|
|
905
|
-
("kind", "item_key"),
|
|
906
|
-
(("feature", "feature_id"), ("bugfix", "bug_id")),
|
|
907
|
-
)
|
|
908
|
-
def test_pipeline_aggregate_reselection_keeps_first_seen_details_and_stops(monkeypatch, tmp_path, kind, item_key):
|
|
909
|
-
from prizmkit_runtime import runners
|
|
910
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
911
|
-
|
|
912
|
-
paths = _make_paths(tmp_path)
|
|
913
|
-
family = family_for(kind, paths)
|
|
914
|
-
invocation = parse_invocation(family, "run", ())
|
|
915
|
-
statuses = iter(("completed", "pending", "completed"))
|
|
916
|
-
queue = [
|
|
917
|
-
SimpleNamespace(ok=True, stdout="", data={item_key: "F-049"}, text=""),
|
|
918
|
-
SimpleNamespace(ok=True, stdout="", data={item_key: "F-050"}, text=""),
|
|
919
|
-
SimpleNamespace(ok=True, stdout="", data={item_key: "F-050"}, text=""),
|
|
920
|
-
SimpleNamespace(ok=True, stdout="PIPELINE_COMPLETE\n", data=None, text="PIPELINE_COMPLETE"),
|
|
921
|
-
]
|
|
922
|
-
|
|
923
|
-
monkeypatch.setattr(runners, "get_next", lambda *args, **kwargs: queue.pop(0))
|
|
924
|
-
monkeypatch.setattr(runners, "_process_item", lambda *args, **kwargs: next(statuses))
|
|
925
|
-
monkeypatch.setattr(runners, "_emit_info", lambda *args, **kwargs: None)
|
|
926
|
-
|
|
927
|
-
result = runners._run_pipeline(family, invocation, paths)
|
|
928
|
-
|
|
929
|
-
assert result.processed == 2
|
|
930
|
-
assert result.completed is False
|
|
931
|
-
assert result.stopped_reason == "reselected_item"
|
|
932
|
-
assert result.last_status == "pending"
|
|
933
|
-
assert result.details == ("F-049:completed", "F-050:pending")
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
@pytest.mark.parametrize(
|
|
937
|
-
("kind", "item_key"),
|
|
938
|
-
(("feature", "feature_id"), ("bugfix", "bug_id")),
|
|
939
|
-
)
|
|
940
|
-
def test_pipeline_aggregate_keeps_distinct_unresolved_item_blocking(monkeypatch, tmp_path, kind, item_key):
|
|
941
|
-
from prizmkit_runtime import runners
|
|
942
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
943
|
-
|
|
944
|
-
paths = _make_paths(tmp_path)
|
|
945
|
-
family = family_for(kind, paths)
|
|
946
|
-
invocation = parse_invocation(family, "run", ())
|
|
947
|
-
statuses = iter(("pending", "completed"))
|
|
948
|
-
queue = [
|
|
949
|
-
SimpleNamespace(ok=True, stdout="", data={item_key: "F-001"}, text=""),
|
|
950
|
-
SimpleNamespace(ok=True, stdout="", data={item_key: "F-002"}, text=""),
|
|
951
|
-
SimpleNamespace(ok=True, stdout="PIPELINE_COMPLETE\n", data=None, text="PIPELINE_COMPLETE"),
|
|
952
|
-
]
|
|
953
|
-
|
|
954
|
-
monkeypatch.setattr(runners, "get_next", lambda *args, **kwargs: queue.pop(0))
|
|
955
|
-
monkeypatch.setattr(runners, "_process_item", lambda *args, **kwargs: next(statuses))
|
|
956
|
-
monkeypatch.setattr(runners, "_emit_info", lambda *args, **kwargs: None)
|
|
957
|
-
|
|
958
|
-
result = runners._run_pipeline(family, invocation, paths)
|
|
959
|
-
|
|
960
|
-
assert result.processed == 2
|
|
961
|
-
assert result.completed is False
|
|
962
|
-
assert result.stopped_reason == "pipeline_complete_with_non_terminal_history"
|
|
963
|
-
assert result.last_status == "pending"
|
|
964
|
-
assert result.details == ("F-001:pending", "F-002:completed")
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
@pytest.mark.parametrize(
|
|
968
|
-
("kind", "item_key"),
|
|
969
|
-
(("feature", "feature_id"), ("bugfix", "bug_id")),
|
|
970
|
-
)
|
|
971
|
-
def test_full_list_stops_after_newly_skipped_item(monkeypatch, tmp_path, kind, item_key):
|
|
972
|
-
from prizmkit_runtime import runners
|
|
973
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
974
|
-
|
|
975
|
-
paths = _make_paths(tmp_path)
|
|
976
|
-
family = family_for(kind, paths)
|
|
977
|
-
invocation = parse_invocation(family, "run", ())
|
|
978
|
-
selector_calls = 0
|
|
979
|
-
processor_calls = []
|
|
980
|
-
|
|
981
|
-
def fake_get_next(*args, **kwargs):
|
|
982
|
-
nonlocal selector_calls
|
|
983
|
-
selector_calls += 1
|
|
984
|
-
if selector_calls > 1:
|
|
985
|
-
raise AssertionError("selector called after terminal skipped item")
|
|
986
|
-
return SimpleNamespace(ok=True, stdout="", data={item_key: "X-001"}, text="")
|
|
987
|
-
|
|
988
|
-
def fake_process(_family, _invocation, item_id, _paths, *, initial_metadata):
|
|
989
|
-
processor_calls.append(item_id)
|
|
990
|
-
return "skipped"
|
|
991
|
-
|
|
992
|
-
monkeypatch.setattr(runners, "get_next", fake_get_next)
|
|
993
|
-
monkeypatch.setattr(runners, "_process_item", fake_process)
|
|
994
|
-
|
|
995
|
-
result = runners._run_pipeline(family, invocation, paths)
|
|
996
|
-
|
|
997
|
-
assert selector_calls == 1
|
|
998
|
-
assert processor_calls == ["X-001"]
|
|
999
|
-
assert result.completed is False
|
|
1000
|
-
assert result.processed == 1
|
|
1001
|
-
assert result.stopped_reason == "item_skipped"
|
|
1002
|
-
assert result.last_status == "skipped"
|
|
1003
|
-
assert result.details == ("X-001:skipped",)
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
@pytest.mark.parametrize(
|
|
1007
|
-
("kind", "item_key"),
|
|
1008
|
-
(("feature", "feature_id"), ("bugfix", "bug_id")),
|
|
1009
|
-
)
|
|
1010
|
-
def test_full_list_rejects_reselected_processed_item_before_second_launch(monkeypatch, tmp_path, kind, item_key):
|
|
1011
|
-
from prizmkit_runtime import runners
|
|
1012
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1013
|
-
|
|
1014
|
-
paths = _make_paths(tmp_path)
|
|
1015
|
-
family = family_for(kind, paths)
|
|
1016
|
-
invocation = parse_invocation(family, "run", ())
|
|
1017
|
-
queue = [
|
|
1018
|
-
SimpleNamespace(ok=True, stdout="", data={item_key: "X-001"}, text=""),
|
|
1019
|
-
SimpleNamespace(ok=True, stdout="", data={item_key: "X-001"}, text=""),
|
|
1020
|
-
SimpleNamespace(ok=True, stdout="PIPELINE_COMPLETE\n", data=None, text="PIPELINE_COMPLETE"),
|
|
1021
|
-
]
|
|
1022
|
-
processor_calls = []
|
|
1023
|
-
|
|
1024
|
-
monkeypatch.setattr(runners, "get_next", lambda *args, **kwargs: queue.pop(0))
|
|
1025
|
-
|
|
1026
|
-
def fake_process(_family, _invocation, item_id, _paths, *, initial_metadata):
|
|
1027
|
-
processor_calls.append(item_id)
|
|
1028
|
-
return "completed"
|
|
1029
|
-
|
|
1030
|
-
monkeypatch.setattr(runners, "_process_item", fake_process)
|
|
1031
|
-
monkeypatch.setattr(runners, "_emit_info", lambda *args, **kwargs: None)
|
|
1032
|
-
|
|
1033
|
-
result = runners._run_pipeline(family, invocation, paths)
|
|
1034
|
-
|
|
1035
|
-
assert processor_calls == ["X-001"]
|
|
1036
|
-
assert result.completed is False
|
|
1037
|
-
assert result.processed == 1
|
|
1038
|
-
assert result.stopped_reason == "reselected_item"
|
|
1039
|
-
assert result.last_status == "completed"
|
|
1040
|
-
assert result.details == ("X-001:completed",)
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
@pytest.mark.parametrize("kind", ("feature", "bugfix"))
|
|
1044
|
-
def test_pipeline_aggregate_empty_authoritative_completion(monkeypatch, tmp_path, kind):
|
|
1045
|
-
from prizmkit_runtime import runners
|
|
1046
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1047
|
-
|
|
1048
|
-
paths = _make_paths(tmp_path)
|
|
1049
|
-
family = family_for(kind, paths)
|
|
1050
|
-
invocation = parse_invocation(family, "run", ())
|
|
1051
|
-
monkeypatch.setattr(
|
|
1052
|
-
runners,
|
|
1053
|
-
"get_next",
|
|
1054
|
-
lambda *args, **kwargs: SimpleNamespace(
|
|
1055
|
-
ok=True,
|
|
1056
|
-
stdout="PIPELINE_COMPLETE\n",
|
|
1057
|
-
data=None,
|
|
1058
|
-
text="PIPELINE_COMPLETE",
|
|
1059
|
-
),
|
|
1060
|
-
)
|
|
1061
|
-
|
|
1062
|
-
result = runners._run_pipeline(family, invocation, paths)
|
|
1063
|
-
|
|
1064
|
-
assert result.processed == 0
|
|
1065
|
-
assert result.completed is True
|
|
1066
|
-
assert result.stopped_reason == "pipeline_complete"
|
|
1067
|
-
assert result.last_status == ""
|
|
1068
|
-
assert result.details == ()
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
@pytest.mark.parametrize(
|
|
1072
|
-
("kind", "status", "expected_completed"),
|
|
1073
|
-
(
|
|
1074
|
-
("feature", "completed", True),
|
|
1075
|
-
("feature", "skipped", False),
|
|
1076
|
-
("feature", "auto_skipped", False),
|
|
1077
|
-
("feature", "split", True),
|
|
1078
|
-
("bugfix", "completed", True),
|
|
1079
|
-
("bugfix", "skipped", False),
|
|
1080
|
-
("bugfix", "auto_skipped", False),
|
|
1081
|
-
("bugfix", "split", False),
|
|
1082
|
-
),
|
|
1083
|
-
)
|
|
1084
|
-
def test_pipeline_aggregate_completion_compatible_statuses(monkeypatch, tmp_path, kind, status, expected_completed):
|
|
1085
|
-
from prizmkit_runtime import runners
|
|
1086
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1087
|
-
|
|
1088
|
-
paths = _make_paths(tmp_path)
|
|
1089
|
-
family = family_for(kind, paths)
|
|
1090
|
-
invocation = parse_invocation(family, "run", ())
|
|
1091
|
-
item_key = {"feature": "feature_id", "bugfix": "bug_id"}[kind]
|
|
1092
|
-
queue = [
|
|
1093
|
-
SimpleNamespace(ok=True, stdout="", data={item_key: "X-001"}, text=""),
|
|
1094
|
-
SimpleNamespace(ok=True, stdout="PIPELINE_COMPLETE\n", data=None, text="PIPELINE_COMPLETE"),
|
|
1095
|
-
]
|
|
1096
|
-
|
|
1097
|
-
monkeypatch.setenv("STOP_ON_FAILURE", "0")
|
|
1098
|
-
monkeypatch.setattr(runners, "get_next", lambda *args, **kwargs: queue.pop(0))
|
|
1099
|
-
monkeypatch.setattr(runners, "_process_item", lambda *args, **kwargs: status)
|
|
1100
|
-
|
|
1101
|
-
result = runners._run_pipeline(family, invocation, paths)
|
|
1102
|
-
|
|
1103
|
-
assert result.completed is expected_completed
|
|
1104
|
-
assert result.stopped_reason == (
|
|
1105
|
-
"item_skipped"
|
|
1106
|
-
if status == "skipped"
|
|
1107
|
-
else ("pipeline_complete" if expected_completed else "pipeline_complete_with_non_terminal_history")
|
|
1108
|
-
)
|
|
1109
|
-
assert result.last_status == status
|
|
1110
|
-
assert result.details == (f"X-001:{status}",)
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
@pytest.mark.parametrize("kind", ("feature", "bugfix"))
|
|
1114
|
-
def test_run_pipeline_command_omits_empty_last_status_detail(monkeypatch, tmp_path, kind):
|
|
1115
|
-
from prizmkit_runtime import runners
|
|
1116
|
-
from prizmkit_runtime.runner_models import PipelineRunResult
|
|
1117
|
-
|
|
1118
|
-
paths = _make_paths(tmp_path)
|
|
1119
|
-
plan_path = {
|
|
1120
|
-
"feature": paths.feature_plan,
|
|
1121
|
-
"bugfix": paths.bugfix_plan,
|
|
1122
|
-
}[kind]
|
|
1123
|
-
plan_path.write_text("{}", encoding="utf-8")
|
|
1124
|
-
monkeypatch.setattr(
|
|
1125
|
-
runners,
|
|
1126
|
-
"_run_pipeline",
|
|
1127
|
-
lambda *args, **kwargs: PipelineRunResult(True, 0, "pipeline_complete"),
|
|
1128
|
-
)
|
|
1129
|
-
|
|
1130
|
-
result = runners.run_pipeline_command(kind, "run", (), paths)
|
|
1131
|
-
|
|
1132
|
-
assert result.exit_code == 0
|
|
1133
|
-
assert result.message == "processed=0 completed=True stopped_reason=pipeline_complete"
|
|
1134
|
-
assert result.details == ()
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
@pytest.mark.parametrize("kind", ("feature", "bugfix"))
|
|
1138
|
-
def test_run_pipeline_command_returns_nonzero_for_terminal_skipped_item(monkeypatch, tmp_path, kind):
|
|
1139
|
-
from prizmkit_runtime import runners
|
|
1140
|
-
from prizmkit_runtime.runner_models import PipelineRunResult
|
|
1141
|
-
|
|
1142
|
-
paths = _make_paths(tmp_path)
|
|
1143
|
-
plan_path = {
|
|
1144
|
-
"feature": paths.feature_plan,
|
|
1145
|
-
"bugfix": paths.bugfix_plan,
|
|
1146
|
-
}[kind]
|
|
1147
|
-
plan_path.write_text("{}", encoding="utf-8")
|
|
1148
|
-
monkeypatch.setattr(
|
|
1149
|
-
runners,
|
|
1150
|
-
"_run_pipeline",
|
|
1151
|
-
lambda *args, **kwargs: PipelineRunResult(
|
|
1152
|
-
False,
|
|
1153
|
-
1,
|
|
1154
|
-
"item_skipped",
|
|
1155
|
-
"skipped",
|
|
1156
|
-
("X-001:skipped",),
|
|
1157
|
-
),
|
|
1158
|
-
)
|
|
1159
|
-
|
|
1160
|
-
result = runners.run_pipeline_command(kind, "run", (), paths)
|
|
1161
|
-
|
|
1162
|
-
assert result.exit_code == 1
|
|
1163
|
-
assert result.message == "processed=1 completed=False stopped_reason=item_skipped"
|
|
1164
|
-
assert result.details == ("X-001:skipped", "last_status: skipped")
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
def test_pipeline_complete_rejects_retryable_detail(monkeypatch, tmp_path):
|
|
1168
|
-
from prizmkit_runtime import runners
|
|
1169
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1170
|
-
|
|
1171
|
-
paths = _make_paths(tmp_path)
|
|
1172
|
-
family = family_for("feature", paths)
|
|
1173
|
-
invocation = parse_invocation(family, "run", ())
|
|
1174
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1175
|
-
queue = [
|
|
1176
|
-
SimpleNamespace(ok=True, stdout=json.dumps({"feature_id": "F-001"}), data={"feature_id": "F-001"}, text=""),
|
|
1177
|
-
SimpleNamespace(ok=True, stdout="PIPELINE_COMPLETE\n", data=None, text="PIPELINE_COMPLETE"),
|
|
1178
|
-
]
|
|
1179
|
-
|
|
1180
|
-
monkeypatch.setenv("STOP_ON_FAILURE", "0")
|
|
1181
|
-
monkeypatch.setattr(runners, "get_next", lambda *args, **kwargs: queue.pop(0))
|
|
1182
|
-
monkeypatch.setattr(runners, "_process_item", lambda *args, **kwargs: "retryable")
|
|
1183
|
-
|
|
1184
|
-
result = runners._run_pipeline(family, invocation, paths)
|
|
1185
|
-
|
|
1186
|
-
assert result.completed is False
|
|
1187
|
-
assert result.stopped_reason == "pipeline_complete_with_non_terminal_history"
|
|
1188
|
-
assert result.last_status == "retryable"
|
|
1189
|
-
assert result.details == ("F-001:retryable",)
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
def test_full_list_continues_from_completed_item_to_next_pending(monkeypatch, tmp_path):
|
|
1193
|
-
from prizmkit_runtime import runners
|
|
1194
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1195
|
-
|
|
1196
|
-
paths = _make_paths(tmp_path)
|
|
1197
|
-
family = family_for("feature", paths)
|
|
1198
|
-
invocation = parse_invocation(family, "run", ())
|
|
1199
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1200
|
-
queue = [
|
|
1201
|
-
SimpleNamespace(ok=True, stdout=json.dumps({"feature_id": "F-001"}), data={"feature_id": "F-001"}, text=""),
|
|
1202
|
-
SimpleNamespace(ok=True, stdout=json.dumps({"feature_id": "F-002"}), data={"feature_id": "F-002"}, text=""),
|
|
1203
|
-
SimpleNamespace(ok=True, stdout="PIPELINE_COMPLETE\n", data=None, text="PIPELINE_COMPLETE"),
|
|
1204
|
-
]
|
|
1205
|
-
processed = []
|
|
1206
|
-
|
|
1207
|
-
monkeypatch.setattr(runners, "get_next", lambda *args, **kwargs: queue.pop(0))
|
|
1208
|
-
|
|
1209
|
-
def fake_process(_family, _invocation, item_id, _paths, *, initial_metadata):
|
|
1210
|
-
processed.append(item_id)
|
|
1211
|
-
return "completed"
|
|
1212
|
-
|
|
1213
|
-
monkeypatch.setattr(runners, "_process_item", fake_process)
|
|
1214
|
-
|
|
1215
|
-
result = runners._run_pipeline(family, invocation, paths)
|
|
1216
|
-
|
|
1217
|
-
assert processed == ["F-001", "F-002"]
|
|
1218
|
-
assert result.completed is True
|
|
1219
|
-
assert result.stopped_reason == "pipeline_complete"
|
|
1220
|
-
assert result.details == ("F-001:completed", "F-002:completed")
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
def test_stop_on_failure_still_stops_on_terminal_status(monkeypatch, tmp_path):
|
|
1224
|
-
from prizmkit_runtime import runners
|
|
1225
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1226
|
-
|
|
1227
|
-
paths = _make_paths(tmp_path)
|
|
1228
|
-
family = family_for("feature", paths)
|
|
1229
|
-
invocation = parse_invocation(family, "run", ())
|
|
1230
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1231
|
-
|
|
1232
|
-
monkeypatch.setenv("STOP_ON_FAILURE", "1")
|
|
1233
|
-
monkeypatch.setattr(
|
|
1234
|
-
runners,
|
|
1235
|
-
"get_next",
|
|
1236
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True, stdout=json.dumps({"feature_id": "F-001"}), data={"feature_id": "F-001"}, text=""),
|
|
1237
|
-
)
|
|
1238
|
-
monkeypatch.setattr(runners, "_process_item", lambda *args, **kwargs: "failed")
|
|
1239
|
-
|
|
1240
|
-
result = runners._run_pipeline(family, invocation, paths)
|
|
1241
|
-
|
|
1242
|
-
assert result.completed is False
|
|
1243
|
-
assert result.stopped_reason == "stop_on_failure"
|
|
1244
|
-
assert result.last_status == "failed"
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
def test_prompt_generation_result_preserves_per_item_model(monkeypatch, tmp_path):
|
|
1248
|
-
from prizmkit_runtime.runner_models import SessionPaths, family_for, parse_invocation
|
|
1249
|
-
from prizmkit_runtime.runner_prompts import generate_prompt
|
|
1250
|
-
|
|
1251
|
-
paths = _make_paths(tmp_path)
|
|
1252
|
-
family = family_for("bugfix", paths)
|
|
1253
|
-
invocation = parse_invocation(family, "run", ())
|
|
1254
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.bugfix_plan})
|
|
1255
|
-
session_paths = SessionPaths.for_item(paths.bugfix_state_dir, "B-001", "B-001-session")
|
|
1256
|
-
|
|
1257
|
-
def fake_run(command, **kwargs):
|
|
1258
|
-
assert str(family.prompt_script) in command
|
|
1259
|
-
assert "--bug-id" in command
|
|
1260
|
-
return subprocess.CompletedProcess(
|
|
1261
|
-
command,
|
|
1262
|
-
0,
|
|
1263
|
-
stdout=json.dumps(
|
|
1264
|
-
{
|
|
1265
|
-
"success": True,
|
|
1266
|
-
"output_path": str(session_paths.prompt_path),
|
|
1267
|
-
"checkpoint_path": str(paths.project_root / ".prizmkit" / "bugfix" / "B-001" / "workflow-checkpoint.json"),
|
|
1268
|
-
"model": "per-item-model",
|
|
1269
|
-
}
|
|
1270
|
-
),
|
|
1271
|
-
stderr="",
|
|
1272
|
-
)
|
|
1273
|
-
|
|
1274
|
-
monkeypatch.setattr(subprocess, "run", fake_run)
|
|
1275
|
-
|
|
1276
|
-
result = generate_prompt(
|
|
1277
|
-
family,
|
|
1278
|
-
invocation,
|
|
1279
|
-
item_id="B-001",
|
|
1280
|
-
session_id="B-001-session",
|
|
1281
|
-
run_id="run-test",
|
|
1282
|
-
retry_count=0,
|
|
1283
|
-
session_paths=session_paths,
|
|
1284
|
-
project_root=paths.project_root,
|
|
1285
|
-
)
|
|
1286
|
-
|
|
1287
|
-
assert result.model == "per-item-model"
|
|
1288
|
-
assert result.output_path == session_paths.prompt_path
|
|
1289
|
-
assert result.artifact_path == paths.project_root / ".prizmkit" / "bugfix" / "B-001"
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
def test_prompt_generation_passes_explicit_execution_root_to_generator(monkeypatch, tmp_path):
|
|
1293
|
-
from prizmkit_runtime.runner_models import SessionPaths, family_for, parse_invocation
|
|
1294
|
-
from prizmkit_runtime.runner_prompts import generate_prompt
|
|
1295
|
-
|
|
1296
|
-
paths = _make_paths(tmp_path)
|
|
1297
|
-
family = family_for("feature", paths)
|
|
1298
|
-
invocation = parse_invocation(family, "run", ())
|
|
1299
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1300
|
-
session_paths = SessionPaths.for_item(paths.feature_state_dir, "F-001", "F-001-session")
|
|
1301
|
-
execution_root = tmp_path / "worktrees" / "dev-F-001"
|
|
1302
|
-
|
|
1303
|
-
def fake_run(command, **kwargs):
|
|
1304
|
-
assert kwargs["cwd"] == str(paths.project_root)
|
|
1305
|
-
assert "--project-root" in command
|
|
1306
|
-
assert command[command.index("--project-root") + 1] == str(execution_root)
|
|
1307
|
-
return subprocess.CompletedProcess(
|
|
1308
|
-
command,
|
|
1309
|
-
0,
|
|
1310
|
-
stdout=json.dumps(
|
|
1311
|
-
{
|
|
1312
|
-
"success": True,
|
|
1313
|
-
"output_path": str(session_paths.prompt_path),
|
|
1314
|
-
"checkpoint_path": str(execution_root / ".prizmkit" / "specs" / "001-low" / "workflow-checkpoint.json"),
|
|
1315
|
-
"model": "",
|
|
1316
|
-
}
|
|
1317
|
-
),
|
|
1318
|
-
stderr="",
|
|
1319
|
-
)
|
|
1320
|
-
|
|
1321
|
-
monkeypatch.setattr(subprocess, "run", fake_run)
|
|
1322
|
-
|
|
1323
|
-
result = generate_prompt(
|
|
1324
|
-
family,
|
|
1325
|
-
invocation,
|
|
1326
|
-
item_id="F-001",
|
|
1327
|
-
session_id="F-001-session",
|
|
1328
|
-
run_id="run-test",
|
|
1329
|
-
retry_count=0,
|
|
1330
|
-
session_paths=session_paths,
|
|
1331
|
-
project_root=paths.project_root,
|
|
1332
|
-
execution_root=execution_root,
|
|
1333
|
-
)
|
|
1334
|
-
|
|
1335
|
-
assert result.artifact_path == execution_root / ".prizmkit" / "specs" / "001-low"
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
def test_runner_does_not_restore_wip_for_first_checkout(monkeypatch, tmp_path):
|
|
1339
|
-
from prizmkit_runtime import runners
|
|
1340
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1341
|
-
|
|
1342
|
-
paths = _make_paths(tmp_path / "first-checkout-no-wip-restore")
|
|
1343
|
-
family = family_for("feature", paths)
|
|
1344
|
-
invocation = parse_invocation(family, "run", ())
|
|
1345
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1346
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1347
|
-
monkeypatch.setattr(
|
|
1348
|
-
runners,
|
|
1349
|
-
"run_git_plan",
|
|
1350
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True, reason="", results=()),
|
|
1351
|
-
)
|
|
1352
|
-
|
|
1353
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1354
|
-
|
|
1355
|
-
assert status == "completed"
|
|
1356
|
-
assert observed.restore_calls == []
|
|
1357
|
-
assert observed.events == ["prompt"]
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
def test_runner_restores_wip_before_prompt_for_reused_branch_checkout(monkeypatch, tmp_path):
|
|
1361
|
-
from prizmkit_runtime import runners
|
|
1362
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1363
|
-
from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
|
|
1364
|
-
|
|
1365
|
-
paths = _make_paths(tmp_path / "reused-branch-wip-restore")
|
|
1366
|
-
family = family_for("feature", paths)
|
|
1367
|
-
branch = "dev/feature/F-001-preserved"
|
|
1368
|
-
persist_task_checkout(
|
|
1369
|
-
family.state_dir,
|
|
1370
|
-
TaskCheckout.active(family.task_type, "F-001", branch, "main"),
|
|
1371
|
-
)
|
|
1372
|
-
invocation = parse_invocation(family, "run", ())
|
|
1373
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1374
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1375
|
-
monkeypatch.setattr(
|
|
1376
|
-
runners,
|
|
1377
|
-
"run_git_plan",
|
|
1378
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True, reason="", results=()),
|
|
1379
|
-
)
|
|
1380
|
-
|
|
1381
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1382
|
-
|
|
1383
|
-
assert status == "completed"
|
|
1384
|
-
assert observed.events == ["restore", "prompt"]
|
|
1385
|
-
assert observed.restore_calls == [
|
|
1386
|
-
(
|
|
1387
|
-
paths.project_root,
|
|
1388
|
-
{
|
|
1389
|
-
"family_kind": "feature",
|
|
1390
|
-
"item_id": "F-001",
|
|
1391
|
-
"working_branch": branch,
|
|
1392
|
-
},
|
|
1393
|
-
)
|
|
1394
|
-
]
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
def test_runner_restores_wip_before_prompt_for_reused_branch_checkout(monkeypatch, tmp_path):
|
|
1398
|
-
from prizmkit_runtime import runners
|
|
1399
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1400
|
-
from prizmkit_runtime.task_checkout import (
|
|
1401
|
-
CHECKOUT_MODE_BRANCH,
|
|
1402
|
-
TaskCheckout,
|
|
1403
|
-
persist_task_checkout,
|
|
1404
|
-
)
|
|
1405
|
-
|
|
1406
|
-
paths = _make_paths(tmp_path / "reused-branch-wip-restore")
|
|
1407
|
-
family = family_for("feature", paths)
|
|
1408
|
-
branch = "dev/feature/F-001-preserved"
|
|
1409
|
-
persist_task_checkout(
|
|
1410
|
-
family.state_dir,
|
|
1411
|
-
TaskCheckout.active(
|
|
1412
|
-
family.task_type,
|
|
1413
|
-
"F-001",
|
|
1414
|
-
branch,
|
|
1415
|
-
"main",
|
|
1416
|
-
checkout_mode=CHECKOUT_MODE_BRANCH,
|
|
1417
|
-
),
|
|
1418
|
-
)
|
|
1419
|
-
invocation = parse_invocation(family, "run", ())
|
|
1420
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1421
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1422
|
-
monkeypatch.setattr(
|
|
1423
|
-
runners,
|
|
1424
|
-
"run_git_plan",
|
|
1425
|
-
lambda project_root, plan: SimpleNamespace(ok=True, plan=plan, results=()),
|
|
1426
|
-
)
|
|
1427
|
-
|
|
1428
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1429
|
-
|
|
1430
|
-
assert status == "completed"
|
|
1431
|
-
assert observed.events == ["restore", "prompt"]
|
|
1432
|
-
assert observed.restore_calls[0][0] == paths.project_root.resolve()
|
|
1433
|
-
assert observed.restore_calls[0][1] == {
|
|
1434
|
-
"family_kind": "feature",
|
|
1435
|
-
"item_id": "F-001",
|
|
1436
|
-
"working_branch": branch,
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
def test_runner_blocks_ai_launch_when_reused_wip_restore_fails(monkeypatch, tmp_path):
|
|
1441
|
-
from prizmkit_runtime import runners
|
|
1442
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1443
|
-
from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
|
|
1444
|
-
|
|
1445
|
-
paths = _make_paths(tmp_path / "failed-branch-wip-restore")
|
|
1446
|
-
family = family_for("feature", paths)
|
|
1447
|
-
branch = "dev/feature/F-001-preserved"
|
|
1448
|
-
persist_task_checkout(
|
|
1449
|
-
family.state_dir,
|
|
1450
|
-
TaskCheckout.active(family.task_type, "F-001", branch, "main"),
|
|
1451
|
-
)
|
|
1452
|
-
invocation = parse_invocation(family, "run", ())
|
|
1453
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1454
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1455
|
-
monkeypatch.setattr(
|
|
1456
|
-
runners,
|
|
1457
|
-
"run_git_plan",
|
|
1458
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True, reason="", results=()),
|
|
1459
|
-
)
|
|
1460
|
-
monkeypatch.setattr(
|
|
1461
|
-
runners,
|
|
1462
|
-
"restore_runtime_wip",
|
|
1463
|
-
lambda *args, **kwargs: SimpleNamespace(
|
|
1464
|
-
ok=False,
|
|
1465
|
-
restored=False,
|
|
1466
|
-
reason="runtime_wip_unresolved_merge",
|
|
1467
|
-
wip_head="preserved-head",
|
|
1468
|
-
restored_head="preserved-head",
|
|
1469
|
-
),
|
|
1470
|
-
raising=False,
|
|
1471
|
-
)
|
|
1472
|
-
monkeypatch.setattr(
|
|
1473
|
-
runners,
|
|
1474
|
-
"commit_wip_changes",
|
|
1475
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True),
|
|
1476
|
-
)
|
|
1477
|
-
monkeypatch.setattr(
|
|
1478
|
-
runners,
|
|
1479
|
-
"branch_ensure_return",
|
|
1480
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True),
|
|
1481
|
-
)
|
|
1482
|
-
|
|
1483
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1484
|
-
|
|
1485
|
-
assert status == "infra_error"
|
|
1486
|
-
assert observed.prompt_calls == []
|
|
1487
|
-
assert observed.launch_cwds == []
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
def test_outer_runner_routes_cursor_through_native_preflight_and_session_config(monkeypatch, tmp_path):
|
|
1491
|
-
from prizmkit_runtime import runners
|
|
1492
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1493
|
-
|
|
1494
|
-
paths = _make_paths(tmp_path / "cursor-outer-runtime")
|
|
1495
|
-
family = family_for("feature", paths)
|
|
1496
|
-
invocation = parse_invocation(family, "run", ())
|
|
1497
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1498
|
-
observed = _install_runner_session_fakes(
|
|
1499
|
-
monkeypatch,
|
|
1500
|
-
runners,
|
|
1501
|
-
statuses=("workflow_skipped",),
|
|
1502
|
-
update_status="completed",
|
|
1503
|
-
)
|
|
1504
|
-
monkeypatch.setattr(
|
|
1505
|
-
runners,
|
|
1506
|
-
"load_runtime_config",
|
|
1507
|
-
lambda _paths: SimpleNamespace(
|
|
1508
|
-
ai_client=SimpleNamespace(command="agent", platform="cursor", launch_profile=None),
|
|
1509
|
-
model="cursor-model",
|
|
1510
|
-
effort=None,
|
|
1511
|
-
effort_validation=SimpleNamespace(valid=True, message=""),
|
|
1512
|
-
),
|
|
1513
|
-
)
|
|
1514
|
-
probes = []
|
|
1515
|
-
|
|
1516
|
-
def cursor_preflight(command, platform):
|
|
1517
|
-
probes.append((command, platform))
|
|
1518
|
-
return SimpleNamespace(enabled=True, notes=())
|
|
1519
|
-
|
|
1520
|
-
monkeypatch.setattr(runners, "detect_stream_json_support", cursor_preflight)
|
|
1521
|
-
monkeypatch.setattr(
|
|
1522
|
-
runners,
|
|
1523
|
-
"run_git_plan",
|
|
1524
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True, reason="", results=()),
|
|
1525
|
-
)
|
|
1526
|
-
|
|
1527
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1528
|
-
|
|
1529
|
-
assert status == "completed"
|
|
1530
|
-
assert probes == [("agent", "cursor")]
|
|
1531
|
-
assert len(observed.launch_configs) == 1
|
|
1532
|
-
launch = observed.launch_configs[0]
|
|
1533
|
-
assert launch.platform == "cursor"
|
|
1534
|
-
assert launch.cli_command == "agent"
|
|
1535
|
-
assert launch.use_stream_json is True
|
|
1536
|
-
assert launch.model == "per-item-model"
|
|
1537
|
-
assert launch.cwd == paths.project_root
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
def test_outer_runner_routes_antigravity_through_native_preflight_and_session_config(monkeypatch, tmp_path):
|
|
1541
|
-
from prizmkit_runtime import runners
|
|
1542
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1543
|
-
|
|
1544
|
-
paths = _make_paths(tmp_path / "agy-outer-runtime")
|
|
1545
|
-
family = family_for("feature", paths)
|
|
1546
|
-
invocation = parse_invocation(family, "run", ())
|
|
1547
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1548
|
-
observed = _install_runner_session_fakes(
|
|
1549
|
-
monkeypatch,
|
|
1550
|
-
runners,
|
|
1551
|
-
statuses=("workflow_skipped",),
|
|
1552
|
-
update_status="completed",
|
|
1553
|
-
)
|
|
1554
|
-
monkeypatch.setattr(
|
|
1555
|
-
runners,
|
|
1556
|
-
"load_runtime_config",
|
|
1557
|
-
lambda _paths: SimpleNamespace(
|
|
1558
|
-
ai_client=SimpleNamespace(command="agy", platform="antigravity", launch_profile=None),
|
|
1559
|
-
model="agy-model",
|
|
1560
|
-
effort="xhigh",
|
|
1561
|
-
effort_validation=SimpleNamespace(valid=True, message=""),
|
|
1562
|
-
),
|
|
1563
|
-
)
|
|
1564
|
-
probes = []
|
|
1565
|
-
|
|
1566
|
-
def agy_preflight(command, platform):
|
|
1567
|
-
probes.append((command, platform))
|
|
1568
|
-
return SimpleNamespace(enabled=True, notes=())
|
|
1569
|
-
|
|
1570
|
-
monkeypatch.setattr(runners, "detect_stream_json_support", agy_preflight)
|
|
1571
|
-
monkeypatch.setattr(
|
|
1572
|
-
runners,
|
|
1573
|
-
"run_git_plan",
|
|
1574
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True, reason="", results=()),
|
|
1575
|
-
)
|
|
1576
|
-
|
|
1577
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1578
|
-
|
|
1579
|
-
assert status == "completed"
|
|
1580
|
-
assert probes == [("agy", "antigravity")]
|
|
1581
|
-
assert len(observed.launch_configs) == 1
|
|
1582
|
-
launch = observed.launch_configs[0]
|
|
1583
|
-
assert launch.platform == "antigravity"
|
|
1584
|
-
assert launch.cli_command == "agy"
|
|
1585
|
-
assert launch.use_stream_json is True
|
|
1586
|
-
assert launch.effort == "xhigh"
|
|
1587
|
-
assert launch.model == "per-item-model"
|
|
1588
|
-
assert launch.cwd == paths.project_root
|
|
1589
|
-
|
|
1590
|
-
monkeypatch.setattr(
|
|
1591
|
-
runners,
|
|
1592
|
-
"load_runtime_config",
|
|
1593
|
-
lambda _paths: SimpleNamespace(
|
|
1594
|
-
ai_client=SimpleNamespace(command="agy", platform="antigravity", launch_profile=None),
|
|
1595
|
-
model="agy-model",
|
|
1596
|
-
effort="invalid-effort",
|
|
1597
|
-
effort_validation=SimpleNamespace(valid=False, message="Unsupported Antigravity PRIZMKIT_EFFORT=invalid-effort"),
|
|
1598
|
-
),
|
|
1599
|
-
)
|
|
1600
|
-
with pytest.raises(RuntimeError, match="Unsupported Antigravity PRIZMKIT_EFFORT=invalid-effort"):
|
|
1601
|
-
runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1602
|
-
|
|
1603
|
-
incompatible_paths = _make_paths(tmp_path / "agy-outer-incompatible")
|
|
1604
|
-
incompatible_family = family_for("feature", incompatible_paths)
|
|
1605
|
-
incompatible_invocation = parse_invocation(incompatible_family, "run", ())
|
|
1606
|
-
incompatible_invocation = incompatible_invocation.__class__(
|
|
1607
|
-
**{**incompatible_invocation.__dict__, "list_path": incompatible_paths.feature_plan}
|
|
1608
|
-
)
|
|
1609
|
-
monkeypatch.setattr(
|
|
1610
|
-
runners,
|
|
1611
|
-
"load_runtime_config",
|
|
1612
|
-
lambda _paths: SimpleNamespace(
|
|
1613
|
-
ai_client=SimpleNamespace(command="agy", platform="antigravity", launch_profile=None),
|
|
1614
|
-
model="agy-model",
|
|
1615
|
-
effort="high",
|
|
1616
|
-
effort_validation=SimpleNamespace(valid=True, message=""),
|
|
1617
|
-
),
|
|
1618
|
-
)
|
|
1619
|
-
monkeypatch.setattr(
|
|
1620
|
-
runners,
|
|
1621
|
-
"detect_stream_json_support",
|
|
1622
|
-
lambda _cmd, _plat: SimpleNamespace(enabled=False, notes=("--input-format not found",)),
|
|
1623
|
-
)
|
|
1624
|
-
with pytest.raises(RuntimeError, match="Antigravity CLI is incompatible with PrizmKit headless execution"):
|
|
1625
|
-
runners._process_item(
|
|
1626
|
-
incompatible_family,
|
|
1627
|
-
incompatible_invocation,
|
|
1628
|
-
"F-001",
|
|
1629
|
-
incompatible_paths,
|
|
1630
|
-
initial_metadata={},
|
|
1631
|
-
)
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
def test_workflow_skipped_is_finalized_as_completed_with_one_warning(monkeypatch, tmp_path, capsys):
|
|
1635
|
-
from prizmkit_runtime import runners
|
|
1636
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1637
|
-
|
|
1638
|
-
paths = _make_paths(tmp_path / "accepted-workflow-skip")
|
|
1639
|
-
family = family_for("feature", paths)
|
|
1640
|
-
invocation = parse_invocation(family, "run", ())
|
|
1641
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1642
|
-
observed = _install_runner_session_fakes(
|
|
1643
|
-
monkeypatch,
|
|
1644
|
-
runners,
|
|
1645
|
-
statuses=("workflow_skipped",),
|
|
1646
|
-
update_status="completed",
|
|
1647
|
-
)
|
|
1648
|
-
plans = []
|
|
1649
|
-
wip_calls = []
|
|
1650
|
-
accepted_commit_calls = []
|
|
1651
|
-
|
|
1652
|
-
def fake_accepted_commit(project_root, **kwargs):
|
|
1653
|
-
accepted_commit_calls.append((project_root, kwargs))
|
|
1654
|
-
return SimpleNamespace(
|
|
1655
|
-
status="not_needed",
|
|
1656
|
-
reason="accepted_workspace_clean",
|
|
1657
|
-
committed=False,
|
|
1658
|
-
commit_hash="",
|
|
1659
|
-
)
|
|
1660
|
-
|
|
1661
|
-
def fake_run_git_plan(_project_root, plan):
|
|
1662
|
-
plans.append(plan.name)
|
|
1663
|
-
return SimpleNamespace(ok=True, reason="", results=())
|
|
1664
|
-
|
|
1665
|
-
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
1666
|
-
monkeypatch.setattr(runners, "finalize_accepted_workspace_commit", fake_accepted_commit)
|
|
1667
|
-
monkeypatch.setattr(
|
|
1668
|
-
runners,
|
|
1669
|
-
"commit_wip_changes",
|
|
1670
|
-
lambda *args, **kwargs: (wip_calls.append((args, kwargs)) or SimpleNamespace(ok=True)),
|
|
1671
|
-
)
|
|
1672
|
-
|
|
1673
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1674
|
-
captured = capsys.readouterr()
|
|
1675
|
-
|
|
1676
|
-
assert status == "completed"
|
|
1677
|
-
assert plans == ["branch_create", "branch_merge"]
|
|
1678
|
-
assert wip_calls == []
|
|
1679
|
-
assert len(accepted_commit_calls) == 1
|
|
1680
|
-
accepted_root, accepted_kwargs = accepted_commit_calls[0]
|
|
1681
|
-
assert accepted_root == paths.project_root
|
|
1682
|
-
assert accepted_kwargs["base_head"] == "base-head"
|
|
1683
|
-
assert accepted_kwargs["artifact_dir"] == paths.project_root / ".prizmkit" / "specs" / "001-low"
|
|
1684
|
-
assert accepted_kwargs["checkpoint_path"] == accepted_kwargs["artifact_dir"] / "workflow-checkpoint.json"
|
|
1685
|
-
assert "F-001" in accepted_kwargs["commit_message"]
|
|
1686
|
-
assert observed.updates[0][0] == "success"
|
|
1687
|
-
assert "classification_reason" not in observed.updates[0][2]
|
|
1688
|
-
assert "accept_workflow_skipped" not in observed.updates[0][2]
|
|
1689
|
-
session_status = json.loads(
|
|
1690
|
-
(
|
|
1691
|
-
paths.feature_state_dir
|
|
1692
|
-
/ "F-001"
|
|
1693
|
-
/ "sessions"
|
|
1694
|
-
/ "F-001-session-1"
|
|
1695
|
-
/ "session-status.json"
|
|
1696
|
-
).read_text(encoding="utf-8")
|
|
1697
|
-
)
|
|
1698
|
-
assert session_status["status"] == "workflow_skipped"
|
|
1699
|
-
assert session_status["reason"] == "workflow_skipped"
|
|
1700
|
-
assert captured.err.count("[WARN]") == 1
|
|
1701
|
-
assert captured.err.count("accepted with incomplete workflow evidence") == 1
|
|
1702
|
-
assert "Reason: workflow_skipped" in captured.err
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
def test_workflow_skipped_uses_successful_branch_merge_path(monkeypatch, tmp_path, capsys):
|
|
1706
|
-
from prizmkit_runtime import runners
|
|
1707
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1708
|
-
|
|
1709
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-accepted")
|
|
1710
|
-
paths = _make_paths(tmp_path / "accepted-branch-skip")
|
|
1711
|
-
family = family_for("feature", paths)
|
|
1712
|
-
invocation = parse_invocation(family, "run", ())
|
|
1713
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1714
|
-
observed = _install_runner_session_fakes(
|
|
1715
|
-
monkeypatch,
|
|
1716
|
-
runners,
|
|
1717
|
-
statuses=("workflow_skipped",),
|
|
1718
|
-
update_status="completed",
|
|
1719
|
-
)
|
|
1720
|
-
plan_names = []
|
|
1721
|
-
wip_calls = []
|
|
1722
|
-
|
|
1723
|
-
def fake_run_git_plan(project_root, plan):
|
|
1724
|
-
plan_names.append(plan.name)
|
|
1725
|
-
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
1726
|
-
|
|
1727
|
-
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
1728
|
-
monkeypatch.setattr(
|
|
1729
|
-
runners,
|
|
1730
|
-
"commit_wip_changes",
|
|
1731
|
-
lambda *args, **kwargs: wip_calls.append(args) or SimpleNamespace(ok=True),
|
|
1732
|
-
)
|
|
1733
|
-
|
|
1734
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1735
|
-
captured = capsys.readouterr()
|
|
1736
|
-
|
|
1737
|
-
assert status == "completed"
|
|
1738
|
-
assert observed.updates[0][0] == "success"
|
|
1739
|
-
assert "branch_merge" in plan_names
|
|
1740
|
-
assert wip_calls == []
|
|
1741
|
-
assert captured.err.count("[WARN]") == 1
|
|
1742
|
-
assert captured.err.count("accepted with incomplete workflow evidence") == 1
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
def test_workflow_skipped_safety_failure_stays_hard_without_acceptance_warning(monkeypatch, tmp_path, capsys):
|
|
1746
|
-
from prizmkit_runtime import runners
|
|
1747
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1748
|
-
|
|
1749
|
-
paths = _make_paths(tmp_path / "rejected-workflow-skip")
|
|
1750
|
-
family = family_for("feature", paths)
|
|
1751
|
-
invocation = parse_invocation(family, "run", ())
|
|
1752
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1753
|
-
observed = _install_runner_session_fakes(
|
|
1754
|
-
monkeypatch,
|
|
1755
|
-
runners,
|
|
1756
|
-
statuses=("workflow_skipped",),
|
|
1757
|
-
update_status="pending",
|
|
1758
|
-
)
|
|
1759
|
-
plans = []
|
|
1760
|
-
wip_calls = []
|
|
1761
|
-
|
|
1762
|
-
monkeypatch.setattr(
|
|
1763
|
-
runners,
|
|
1764
|
-
"finalize_accepted_workspace_commit",
|
|
1765
|
-
lambda *args, **kwargs: SimpleNamespace(
|
|
1766
|
-
status="not_ready",
|
|
1767
|
-
reason="accepted_workspace_not_finalized",
|
|
1768
|
-
committed=False,
|
|
1769
|
-
commit_hash="",
|
|
1770
|
-
),
|
|
1771
|
-
)
|
|
1772
|
-
monkeypatch.setattr(
|
|
1773
|
-
runners,
|
|
1774
|
-
"run_git_plan",
|
|
1775
|
-
lambda _root, plan: (plans.append(plan.name) or SimpleNamespace(ok=True, reason="", results=())),
|
|
1776
|
-
)
|
|
1777
|
-
monkeypatch.setattr(
|
|
1778
|
-
runners,
|
|
1779
|
-
"commit_wip_changes",
|
|
1780
|
-
lambda *args, **kwargs: (wip_calls.append((args, kwargs)) or SimpleNamespace(ok=True)),
|
|
1781
|
-
)
|
|
1782
|
-
monkeypatch.setattr(
|
|
1783
|
-
runners,
|
|
1784
|
-
"branch_ensure_return",
|
|
1785
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True),
|
|
1786
|
-
)
|
|
1787
|
-
|
|
1788
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1789
|
-
captured = capsys.readouterr()
|
|
1790
|
-
|
|
1791
|
-
assert status == "pending"
|
|
1792
|
-
assert plans == ["branch_create"]
|
|
1793
|
-
assert len(wip_calls) == 1
|
|
1794
|
-
assert observed.updates[0][0] == "commit_missing"
|
|
1795
|
-
assert "accepted with incomplete workflow evidence" not in captured.err
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
def test_runner_launch_config_preserves_artifact_paths_live_output_and_split_thresholds(monkeypatch, tmp_path):
|
|
1799
|
-
from prizmkit_runtime import runners
|
|
1800
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1801
|
-
|
|
1802
|
-
monkeypatch.setenv("PRIZMKIT_LIVE_OUTPUT", "0")
|
|
1803
|
-
monkeypatch.setenv("HEARTBEAT_INTERVAL", "7")
|
|
1804
|
-
monkeypatch.setenv("HEARTBEAT_STALE_THRESHOLD", "11")
|
|
1805
|
-
monkeypatch.setenv("STALE_KILL_THRESHOLD", "13")
|
|
1806
|
-
paths = _make_paths(tmp_path / "artifact-wiring")
|
|
1807
|
-
family = family_for("feature", paths)
|
|
1808
|
-
invocation = parse_invocation(family, "run", ())
|
|
1809
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1810
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1811
|
-
monkeypatch.setattr(runners, "run_git_plan", lambda *args, **kwargs: SimpleNamespace(ok=True, reason="", results=()))
|
|
1812
|
-
|
|
1813
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1814
|
-
|
|
1815
|
-
config = observed.launch_configs[0]
|
|
1816
|
-
expected_log = paths.feature_state_dir / "F-001" / "sessions" / "F-001-session-1" / "logs" / "session.log"
|
|
1817
|
-
assert status == "completed"
|
|
1818
|
-
assert config.live_output is False
|
|
1819
|
-
assert config.live_progress_interval_seconds == 7
|
|
1820
|
-
assert config.heartbeat_stale_threshold_seconds == 11
|
|
1821
|
-
assert config.stale_kill_threshold_seconds == 13
|
|
1822
|
-
assert config.log_path == expected_log
|
|
1823
|
-
assert config.progress_path == expected_log.with_name("progress.json")
|
|
1824
|
-
assert config.heartbeat_path == expected_log.with_name("heartbeat.json")
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
@pytest.mark.parametrize(("kind", "item_id", "branch"), [("feature", "F-001", "dev/F-001-test"), ("bugfix", "B-001", "bugfix/B-001-test")])
|
|
1828
|
-
def test_feature_and_bugfix_branch_checkout_launches_from_project_root_even_with_legacy_env(monkeypatch, tmp_path, kind, item_id, branch):
|
|
1829
|
-
from prizmkit_runtime import runners
|
|
1830
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1831
|
-
|
|
1832
|
-
monkeypatch.setenv("USE_WORKTREE", "1")
|
|
1833
|
-
monkeypatch.setenv("DEV_BRANCH", branch)
|
|
1834
|
-
paths = _make_paths(tmp_path / kind)
|
|
1835
|
-
family = family_for(kind, paths)
|
|
1836
|
-
invocation = parse_invocation(family, "run", ())
|
|
1837
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan if kind == "feature" else paths.bugfix_plan})
|
|
1838
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1839
|
-
lifecycle_order = []
|
|
1840
|
-
|
|
1841
|
-
def fake_run_git_plan(project_root, plan):
|
|
1842
|
-
lifecycle_order.append(plan.name)
|
|
1843
|
-
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
1844
|
-
|
|
1845
|
-
def fake_preflight(*args, **kwargs):
|
|
1846
|
-
lifecycle_order.append("preflight")
|
|
1847
|
-
return SimpleNamespace(attempted=False, committed=False, ok=True, result=None)
|
|
1848
|
-
|
|
1849
|
-
monkeypatch.setattr(runners, "commit_preflight_ready_changes", fake_preflight)
|
|
1850
|
-
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
1851
|
-
|
|
1852
|
-
status = runners._process_item(family, invocation, item_id, paths, initial_metadata={})
|
|
1853
|
-
|
|
1854
|
-
assert status == "completed"
|
|
1855
|
-
assert lifecycle_order[:2] == ["preflight", "branch_create"]
|
|
1856
|
-
assert observed.launch_cwds == [paths.project_root]
|
|
1857
|
-
assert observed.prompt_calls[0]["project_root"] == paths.project_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"
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
def test_legacy_worktree_checkout_identity_fails_fast_before_launch(monkeypatch, tmp_path):
|
|
1864
|
-
from prizmkit_runtime import runners
|
|
1865
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1866
|
-
from prizmkit_runtime.task_checkout import TaskCheckoutError, task_checkout_path
|
|
1867
|
-
|
|
1868
|
-
paths = _make_paths(tmp_path)
|
|
1869
|
-
family = family_for("feature", paths)
|
|
1870
|
-
invocation = parse_invocation(family, "run", ())
|
|
1871
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
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
|
-
}
|
|
1885
|
-
),
|
|
1886
|
-
encoding="utf-8",
|
|
1887
|
-
)
|
|
1888
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
1889
|
-
monkeypatch.delenv("USE_WORKTREE", raising=False)
|
|
1890
|
-
monkeypatch.delenv("DEV_BRANCH", raising=False)
|
|
1891
|
-
|
|
1892
|
-
with pytest.raises(TaskCheckoutError, match="retired worktree checkout mode"):
|
|
1893
|
-
runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1894
|
-
|
|
1895
|
-
assert observed.launch_cwds == []
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
def test_successful_branch_session_merges_and_honors_auto_push(monkeypatch, tmp_path):
|
|
1899
|
-
from prizmkit_runtime import runners
|
|
1900
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1901
|
-
|
|
1902
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-test")
|
|
1903
|
-
monkeypatch.setenv("AUTO_PUSH", "1")
|
|
1904
|
-
paths = _make_paths(tmp_path)
|
|
1905
|
-
family = family_for("feature", paths)
|
|
1906
|
-
invocation = parse_invocation(family, "run", ())
|
|
1907
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
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
|
-
)
|
|
1915
|
-
|
|
1916
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1917
|
-
|
|
1918
|
-
assert status == "completed"
|
|
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)
|
|
1922
|
-
checkout = json.loads((paths.feature_state_dir / "F-001" / "checkout.json").read_text(encoding="utf-8"))
|
|
1923
|
-
assert checkout["state"] == "completed"
|
|
1924
|
-
assert checkout["checkout_mode"] == "branch"
|
|
1925
|
-
assert checkout["active_dev_branch"] == "dev/F-001-test"
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
def test_branch_merge_conflict_writes_session_status_and_updates_merge_conflict(monkeypatch, tmp_path):
|
|
1929
|
-
from prizmkit_runtime import runners
|
|
1930
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1931
|
-
|
|
1932
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-test")
|
|
1933
|
-
paths = _make_paths(tmp_path)
|
|
1934
|
-
family = family_for("feature", paths)
|
|
1935
|
-
invocation = parse_invocation(family, "run", ())
|
|
1936
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1937
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
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))
|
|
1947
|
-
|
|
1948
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1949
|
-
|
|
1950
|
-
assert status == "completed"
|
|
1951
|
-
assert observed.updates[-1][0] == "merge_conflict"
|
|
1952
|
-
checkout = json.loads((paths.feature_state_dir / "F-001" / "checkout.json").read_text(encoding="utf-8"))
|
|
1953
|
-
assert checkout["state"] == "active"
|
|
1954
|
-
assert checkout["checkout_mode"] == "branch"
|
|
1955
|
-
session_status = json.loads((paths.feature_state_dir / "F-001" / "sessions" / "F-001-session-1" / "session-status.json").read_text(encoding="utf-8"))
|
|
1956
|
-
assert session_status["status"] == "merge_conflict"
|
|
1957
|
-
assert session_status["task_id"] == "F-001"
|
|
1958
|
-
assert session_status["task_type"] == "feature"
|
|
1959
|
-
assert session_status["base_branch"] == "main"
|
|
1960
|
-
assert session_status["active_dev_branch"] == "dev/F-001-test"
|
|
1961
|
-
assert "worktree_path" not in session_status
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
def test_terminal_branch_failure_saves_wip_and_preserves_checkout(monkeypatch, tmp_path):
|
|
1965
|
-
from prizmkit_runtime import runners
|
|
1966
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1967
|
-
|
|
1968
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-test")
|
|
1969
|
-
paths = _make_paths(tmp_path)
|
|
1970
|
-
family = family_for("feature", paths)
|
|
1971
|
-
invocation = parse_invocation(family, "run", ())
|
|
1972
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
1973
|
-
observed = _install_runner_session_fakes(monkeypatch, runners, statuses=("crashed",), update_status="failed")
|
|
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))
|
|
1979
|
-
|
|
1980
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
1981
|
-
|
|
1982
|
-
assert status == "failed"
|
|
1983
|
-
assert wip_calls
|
|
1984
|
-
assert return_calls == [(paths.project_root, "main", "dev/F-001-test")]
|
|
1985
|
-
checkout = json.loads((paths.feature_state_dir / "F-001" / "checkout.json").read_text(encoding="utf-8"))
|
|
1986
|
-
assert checkout["state"] == "active"
|
|
1987
|
-
assert checkout["checkout_mode"] == "branch"
|
|
1988
|
-
assert observed.updates[-1][0] == "crashed"
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
def test_default_no_worktree_preserves_main_worktree_branch_launch(monkeypatch, tmp_path):
|
|
1992
|
-
from prizmkit_runtime import runners
|
|
1993
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
1994
|
-
|
|
1995
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-test")
|
|
1996
|
-
paths = _make_paths(tmp_path)
|
|
1997
|
-
family = family_for("feature", paths)
|
|
1998
|
-
invocation = parse_invocation(family, "run", ())
|
|
1999
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2000
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
2001
|
-
plan_names = []
|
|
2002
|
-
branch_events = []
|
|
2003
|
-
lifecycle_order = []
|
|
2004
|
-
|
|
2005
|
-
def fake_run_git_plan(project_root, plan):
|
|
2006
|
-
plan_names.append(plan.name)
|
|
2007
|
-
if plan.name == "branch_create":
|
|
2008
|
-
lifecycle_order.append("branch_create")
|
|
2009
|
-
branch_events.append(("create", plan.commands[1].args[2]))
|
|
2010
|
-
if plan.name == "branch_merge":
|
|
2011
|
-
merge_command = next(command for command in plan.commands if command.args[:2] == ("merge", "--ff-only"))
|
|
2012
|
-
branch_events.append(("merge", merge_command.args[2]))
|
|
2013
|
-
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
2014
|
-
|
|
2015
|
-
def fake_start_item(*args, **kwargs):
|
|
2016
|
-
lifecycle_order.append("start_item")
|
|
2017
|
-
return SimpleNamespace(ok=True, text="", data={"new_status": "in_progress"})
|
|
2018
|
-
|
|
2019
|
-
def fake_preflight(*args, **kwargs):
|
|
2020
|
-
lifecycle_order.append("preflight")
|
|
2021
|
-
return SimpleNamespace(attempted=False, committed=False, ok=True, result=None)
|
|
2022
|
-
|
|
2023
|
-
monkeypatch.setattr(runners, "commit_preflight_ready_changes", fake_preflight)
|
|
2024
|
-
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
2025
|
-
monkeypatch.setattr(runners, "start_item", fake_start_item)
|
|
2026
|
-
monkeypatch.setattr(runners, "ensure_linked_worktree", lambda runtime: (_ for _ in ()).throw(AssertionError("worktree setup should not run")), raising=False)
|
|
2027
|
-
|
|
2028
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2029
|
-
|
|
2030
|
-
assert status == "completed"
|
|
2031
|
-
assert observed.launch_cwds == [paths.project_root]
|
|
2032
|
-
assert observed.prompt_calls[0].get("execution_root") == paths.project_root
|
|
2033
|
-
assert "branch_create" in plan_names
|
|
2034
|
-
assert "branch_merge" in plan_names
|
|
2035
|
-
assert lifecycle_order[:3] == ["preflight", "branch_create", "start_item"]
|
|
2036
|
-
assert branch_events == [("create", "dev/F-001-test"), ("merge", "dev/F-001-test")]
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
def test_has_branch_completion_evidence_requires_task_branch_ahead_of_base(tmp_path):
|
|
2040
|
-
from prizmkit_runtime.runner_classification import has_branch_completion_evidence
|
|
2041
|
-
|
|
2042
|
-
subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
2043
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
|
|
2044
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
|
|
2045
|
-
artifact_dir = tmp_path / ".prizmkit" / "specs" / "001-done"
|
|
2046
|
-
(tmp_path / "base.txt").write_text("base", encoding="utf-8")
|
|
2047
|
-
subprocess.run(["git", "add", "base.txt"], cwd=tmp_path, check=True)
|
|
2048
|
-
subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
2049
|
-
subprocess.run(["git", "checkout", "-b", "dev/F-001"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
2050
|
-
(tmp_path / "done.txt").write_text("done", encoding="utf-8")
|
|
2051
|
-
subprocess.run(["git", "add", "done.txt"], cwd=tmp_path, check=True)
|
|
2052
|
-
subprocess.run(["git", "commit", "-m", "done"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
2053
|
-
_write_semantic_completion_checkpoint(tmp_path, artifact_dir)
|
|
2054
|
-
|
|
2055
|
-
assert has_branch_completion_evidence(tmp_path, "main", "dev/F-001", artifact_dir) is True
|
|
2056
|
-
|
|
2057
|
-
subprocess.run(["git", "checkout", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
2058
|
-
(tmp_path / "main.txt").write_text("main", encoding="utf-8")
|
|
2059
|
-
subprocess.run(["git", "add", "main.txt"], cwd=tmp_path, check=True)
|
|
2060
|
-
subprocess.run(["git", "commit", "-m", "advance-main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
|
|
2061
|
-
subprocess.run(["git", "branch", "stale/F-001", "HEAD~1"], cwd=tmp_path, check=True)
|
|
2062
|
-
|
|
2063
|
-
assert has_branch_completion_evidence(tmp_path, "main", "stale/F-001", artifact_dir) is False
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
def test_no_worktree_late_runtime_error_success_updates_and_merges(monkeypatch, tmp_path):
|
|
2067
|
-
from prizmkit_runtime import runners
|
|
2068
|
-
from prizmkit_runtime.runner_models import SessionClassification, family_for, parse_invocation
|
|
2069
|
-
|
|
2070
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-late-error")
|
|
2071
|
-
paths = _make_paths(tmp_path)
|
|
2072
|
-
family = family_for("feature", paths)
|
|
2073
|
-
invocation = parse_invocation(family, "run", ())
|
|
2074
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2075
|
-
observed = _install_runner_session_fakes(monkeypatch, runners, statuses=("infra_error",))
|
|
2076
|
-
events = []
|
|
2077
|
-
|
|
2078
|
-
def fake_classify(*args, **kwargs):
|
|
2079
|
-
return SessionClassification("success", reason="completed_checkpoint_with_late_runtime_error")
|
|
2080
|
-
|
|
2081
|
-
def fake_run_git_plan(project_root, plan):
|
|
2082
|
-
events.append(plan.name)
|
|
2083
|
-
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
2084
|
-
|
|
2085
|
-
monkeypatch.setattr(runners, "classify_session", fake_classify)
|
|
2086
|
-
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
2087
|
-
|
|
2088
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2089
|
-
|
|
2090
|
-
assert status == "completed"
|
|
2091
|
-
assert observed.updates[-1][0] == "success"
|
|
2092
|
-
assert "branch_merge" in events
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
def test_no_worktree_recovers_completed_pending_branch_before_new_session(monkeypatch, tmp_path):
|
|
2096
|
-
from prizmkit_runtime import runners
|
|
2097
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2098
|
-
|
|
2099
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-recover")
|
|
2100
|
-
paths = _make_paths(tmp_path)
|
|
2101
|
-
family = family_for("feature", paths)
|
|
2102
|
-
invocation = parse_invocation(family, "run", ())
|
|
2103
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2104
|
-
session_dir = paths.feature_state_dir / "F-001" / "sessions" / "F-001-session-old"
|
|
2105
|
-
session_dir.mkdir(parents=True)
|
|
2106
|
-
artifact_dir = paths.project_root / ".prizmkit" / "specs" / "001-low"
|
|
2107
|
-
_write_semantic_completion_checkpoint(paths.project_root, artifact_dir)
|
|
2108
|
-
updates = []
|
|
2109
|
-
events = []
|
|
2110
|
-
|
|
2111
|
-
monkeypatch.setattr(
|
|
2112
|
-
runners,
|
|
2113
|
-
"load_runtime_config",
|
|
2114
|
-
lambda paths: SimpleNamespace(ai_client=SimpleNamespace(command="fake-ai", platform="codebuddy"), model="", effort=None),
|
|
2115
|
-
)
|
|
2116
|
-
monkeypatch.setattr(runners, "current_branch", lambda _root: "main")
|
|
2117
|
-
monkeypatch.setattr(runners, "start_item", lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("should not restart completed work")))
|
|
2118
|
-
monkeypatch.setattr(runners, "generate_prompt", lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("should not launch prompt")))
|
|
2119
|
-
monkeypatch.setattr(runners, "has_branch_completion_evidence", lambda *args, **kwargs: True)
|
|
2120
|
-
monkeypatch.setattr(runners, "commit_final_bookkeeping", lambda *args, **kwargs: None)
|
|
2121
|
-
monkeypatch.setattr(runners, "commit_task_branch_changes", lambda *args, **kwargs: None)
|
|
2122
|
-
monkeypatch.setattr(runners, "commit_preflight_ready_changes", lambda *args, **kwargs: SimpleNamespace(attempted=False, committed=False, ok=True, result=None))
|
|
2123
|
-
|
|
2124
|
-
def fake_update(family, invocation, item_id, session_status, session_id, project_root, **metadata):
|
|
2125
|
-
updates.append((session_status, session_id, metadata))
|
|
2126
|
-
return SimpleNamespace(ok=True, text="", data={"new_status": "completed"})
|
|
2127
|
-
|
|
2128
|
-
def fake_run_git_plan(project_root, plan):
|
|
2129
|
-
events.append(plan.name)
|
|
2130
|
-
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
2131
|
-
|
|
2132
|
-
monkeypatch.setattr(runners, "update_item", fake_update)
|
|
2133
|
-
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
2134
|
-
|
|
2135
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={"title": "Low"})
|
|
2136
|
-
|
|
2137
|
-
assert status == "completed"
|
|
2138
|
-
assert updates == [("success", "F-001-session-old", {"active_dev_branch": "dev/F-001-recover", "base_branch": "main"})]
|
|
2139
|
-
assert "branch_merge" in events
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
def test_success_final_commit_failure_preserves_checkout_without_merge(monkeypatch, tmp_path):
|
|
2143
|
-
from prizmkit_runtime import runners
|
|
2144
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2145
|
-
from prizmkit_runtime.task_checkout import load_task_checkout
|
|
2146
|
-
|
|
2147
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-finalize-fail")
|
|
2148
|
-
paths = _make_paths(tmp_path)
|
|
2149
|
-
family = family_for("feature", paths)
|
|
2150
|
-
invocation = parse_invocation(family, "run", ())
|
|
2151
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2152
|
-
_install_runner_session_fakes(monkeypatch, runners)
|
|
2153
|
-
merge_calls = []
|
|
2154
|
-
|
|
2155
|
-
monkeypatch.setattr(
|
|
2156
|
-
runners,
|
|
2157
|
-
"commit_final_bookkeeping",
|
|
2158
|
-
lambda *args, **kwargs: SimpleNamespace(ok=False, attempted=True, committed=False),
|
|
2159
|
-
)
|
|
2160
|
-
monkeypatch.setattr(
|
|
2161
|
-
runners,
|
|
2162
|
-
"commit_task_branch_changes",
|
|
2163
|
-
lambda *args, **kwargs: SimpleNamespace(ok=True, attempted=False, committed=False),
|
|
2164
|
-
)
|
|
2165
|
-
monkeypatch.setattr(
|
|
2166
|
-
runners,
|
|
2167
|
-
"run_git_plan",
|
|
2168
|
-
lambda root, plan: merge_calls.append(plan.name) or SimpleNamespace(ok=True, plan=plan, results=()),
|
|
2169
|
-
)
|
|
2170
|
-
|
|
2171
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2172
|
-
|
|
2173
|
-
assert status == "completed"
|
|
2174
|
-
assert "branch_merge" not in merge_calls
|
|
2175
|
-
checkout = load_task_checkout(family.state_dir, family.task_type, "F-001")
|
|
2176
|
-
assert checkout is not None and checkout.is_active
|
|
2177
|
-
session_status = paths.feature_state_dir / "F-001" / "sessions" / "F-001-session-1" / "session-status.json"
|
|
2178
|
-
assert json.loads(session_status.read_text(encoding="utf-8"))["status"] == "commit_missing"
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
def test_wip_commit_failure_skips_base_return(monkeypatch, tmp_path):
|
|
2182
|
-
from prizmkit_runtime import runners
|
|
2183
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2184
|
-
|
|
2185
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-wip-fail")
|
|
2186
|
-
paths = _make_paths(tmp_path)
|
|
2187
|
-
family = family_for("feature", paths)
|
|
2188
|
-
invocation = parse_invocation(family, "run", ())
|
|
2189
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2190
|
-
_install_runner_session_fakes(monkeypatch, runners, statuses=("crashed",), update_status="failed")
|
|
2191
|
-
returns = []
|
|
2192
|
-
|
|
2193
|
-
monkeypatch.setattr(
|
|
2194
|
-
runners,
|
|
2195
|
-
"commit_wip_changes",
|
|
2196
|
-
lambda *args, **kwargs: SimpleNamespace(ok=False, attempted=True, committed=False),
|
|
2197
|
-
)
|
|
2198
|
-
monkeypatch.setattr(
|
|
2199
|
-
runners,
|
|
2200
|
-
"branch_ensure_return",
|
|
2201
|
-
lambda *args, **kwargs: returns.append(args) or SimpleNamespace(ok=True),
|
|
2202
|
-
)
|
|
2203
|
-
monkeypatch.setattr(
|
|
2204
|
-
runners,
|
|
2205
|
-
"run_git_plan",
|
|
2206
|
-
lambda root, plan: SimpleNamespace(ok=True, plan=plan, results=()),
|
|
2207
|
-
)
|
|
2208
|
-
|
|
2209
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2210
|
-
|
|
2211
|
-
assert status == "failed"
|
|
2212
|
-
assert returns == []
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
def test_default_branch_names_keep_timestamp_for_each_runner_family(monkeypatch, tmp_path):
|
|
2216
|
-
from prizmkit_runtime import runners
|
|
2217
|
-
from prizmkit_runtime.runner_models import family_for
|
|
2218
|
-
|
|
2219
|
-
monkeypatch.setattr(runners.time, "strftime", lambda fmt: "20260707010203")
|
|
2220
|
-
paths = _make_paths(tmp_path)
|
|
2221
|
-
|
|
2222
|
-
assert runners._default_branch_name(family_for("feature", paths), "F-001") == "dev/F-001-20260707010203"
|
|
2223
|
-
assert runners._default_branch_name(family_for("bugfix", paths), "B-001") == "bugfix/B-001-20260707010203"
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
@pytest.mark.parametrize(
|
|
2227
|
-
("kind", "item_id", "branch"),
|
|
2228
|
-
[
|
|
2229
|
-
("feature", "F-001", "dev/F-001-20260707010203"),
|
|
2230
|
-
("bugfix", "B-001", "bugfix/B-001-20260707010203"),
|
|
2231
|
-
],
|
|
2232
|
-
)
|
|
2233
|
-
def test_no_worktree_exhausted_failure_stays_on_task_branch_without_merge_for_all_families(monkeypatch, tmp_path, kind, item_id, branch):
|
|
2234
|
-
from prizmkit_runtime import runners
|
|
2235
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2236
|
-
|
|
2237
|
-
monkeypatch.setenv("DEV_BRANCH", branch)
|
|
2238
|
-
paths = _make_paths(tmp_path / kind)
|
|
2239
|
-
family = family_for(kind, paths)
|
|
2240
|
-
invocation = parse_invocation(family, "run", ())
|
|
2241
|
-
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan}[kind]
|
|
2242
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
|
|
2243
|
-
_install_runner_session_fakes(monkeypatch, runners, statuses=("crashed",), update_status="failed")
|
|
2244
|
-
events = []
|
|
2245
|
-
final_commits = []
|
|
2246
|
-
wip_commits = []
|
|
2247
|
-
|
|
2248
|
-
def fake_run_git_plan(project_root, plan):
|
|
2249
|
-
events.append(plan.name)
|
|
2250
|
-
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
2251
|
-
|
|
2252
|
-
monkeypatch.setattr(runners, "current_branch", lambda _root: "release")
|
|
2253
|
-
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
2254
|
-
monkeypatch.setattr(runners, "branch_ensure_return", lambda project_root, base, task_branch: events.append(("return", base, task_branch)))
|
|
2255
|
-
monkeypatch.setattr(runners, "commit_final_bookkeeping", lambda project_root, family, item_id, status: final_commits.append((project_root, item_id, status)))
|
|
2256
|
-
monkeypatch.setattr(runners, "commit_wip_changes", lambda project_root, family, item_id, status: wip_commits.append((project_root, item_id, status)))
|
|
2257
|
-
|
|
2258
|
-
status = runners._process_item(family, invocation, item_id, paths, initial_metadata={})
|
|
2259
|
-
|
|
2260
|
-
assert status == "failed"
|
|
2261
|
-
assert events[0] == "branch_create"
|
|
2262
|
-
assert "branch_merge" not in events
|
|
2263
|
-
assert events[-1] == ("return", "release", branch)
|
|
2264
|
-
assert final_commits == [(paths.project_root, item_id, "failed")]
|
|
2265
|
-
assert wip_commits == [(paths.project_root, item_id, "failed")]
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
def test_no_worktree_runner_ignores_recovery_side_effect_branch(monkeypatch, tmp_path):
|
|
2269
|
-
from prizmkit_runtime import runners
|
|
2270
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2271
|
-
|
|
2272
|
-
monkeypatch.delenv("DEV_BRANCH", raising=False)
|
|
2273
|
-
paths = _make_paths(tmp_path)
|
|
2274
|
-
subprocess.run(["git", "init", "-b", "trunk"], cwd=paths.project_root, check=True, stdout=subprocess.DEVNULL)
|
|
2275
|
-
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=paths.project_root, check=True)
|
|
2276
|
-
subprocess.run(["git", "config", "user.name", "Test"], cwd=paths.project_root, check=True)
|
|
2277
|
-
subprocess.run(
|
|
2278
|
-
["git", "commit", "--allow-empty", "-m", "base"],
|
|
2279
|
-
cwd=paths.project_root,
|
|
2280
|
-
check=True,
|
|
2281
|
-
stdout=subprocess.DEVNULL,
|
|
2282
|
-
)
|
|
2283
|
-
subprocess.run(["git", "branch", "main"], cwd=paths.project_root, check=True)
|
|
2284
|
-
family = family_for("feature", paths)
|
|
2285
|
-
invocation = parse_invocation(family, "run", ())
|
|
2286
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2287
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
2288
|
-
branch_names = []
|
|
2289
|
-
bases = []
|
|
2290
|
-
|
|
2291
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-recovery-20260707")
|
|
2292
|
-
monkeypatch.setattr(runners, "current_branch", lambda _root: "dev/F-001-recovery-20260707")
|
|
2293
|
-
|
|
2294
|
-
def fake_run_git_plan(project_root, plan):
|
|
2295
|
-
if plan.name == "branch_create":
|
|
2296
|
-
branch_names.append(plan.commands[1].args[2])
|
|
2297
|
-
bases.append(plan.commands[1].args[3])
|
|
2298
|
-
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
2299
|
-
|
|
2300
|
-
monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
|
|
2301
|
-
|
|
2302
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2303
|
-
|
|
2304
|
-
assert status == "completed"
|
|
2305
|
-
assert branch_names and branch_names[0].startswith("dev/F-001-")
|
|
2306
|
-
assert "recovery" not in branch_names[0]
|
|
2307
|
-
assert bases == ["trunk"]
|
|
2308
|
-
assert observed.updates[-1][2]["active_dev_branch"] == branch_names[0]
|
|
2309
|
-
assert observed.updates[-1][2]["base_branch"] == "trunk"
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
@pytest.mark.parametrize(
|
|
2313
|
-
("kind", "item_id", "branch"),
|
|
2314
|
-
[
|
|
2315
|
-
("feature", "F-001", "dev/F-001-preflight-fail"),
|
|
2316
|
-
("bugfix", "B-001", "bugfix/B-001-preflight-fail"),
|
|
2317
|
-
],
|
|
2318
|
-
)
|
|
2319
|
-
def test_preflight_commit_failure_aborts_before_branch_or_status_for_all_families(monkeypatch, tmp_path, kind, item_id, branch):
|
|
2320
|
-
from prizmkit_runtime import runners
|
|
2321
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2322
|
-
|
|
2323
|
-
monkeypatch.setenv("DEV_BRANCH", branch)
|
|
2324
|
-
paths = _make_paths(tmp_path / kind)
|
|
2325
|
-
family = family_for(kind, paths)
|
|
2326
|
-
invocation = parse_invocation(family, "run", ())
|
|
2327
|
-
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan}[kind]
|
|
2328
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
|
|
2329
|
-
events = []
|
|
2330
|
-
|
|
2331
|
-
monkeypatch.setattr(
|
|
2332
|
-
runners,
|
|
2333
|
-
"load_runtime_config",
|
|
2334
|
-
lambda paths: SimpleNamespace(ai_client=SimpleNamespace(command="fake-ai", platform="codebuddy"), model="", effort=None),
|
|
2335
|
-
)
|
|
2336
|
-
monkeypatch.setattr(runners, "current_branch", lambda _root: "main")
|
|
2337
|
-
monkeypatch.setattr(runners, "commit_preflight_ready_changes", lambda *args, **kwargs: SimpleNamespace(attempted=True, committed=False, result=SimpleNamespace(stderr="commit failed\n", stdout="")))
|
|
2338
|
-
monkeypatch.setattr(runners, "run_git_plan", lambda *args, **kwargs: events.append("branch_create"))
|
|
2339
|
-
monkeypatch.setattr(runners, "start_item", lambda *args, **kwargs: events.append("start_item"))
|
|
2340
|
-
|
|
2341
|
-
with pytest.raises(RuntimeError, match="Preflight dirty workspace preservation failed"):
|
|
2342
|
-
runners._process_item(family, invocation, item_id, paths, initial_metadata={})
|
|
2343
|
-
|
|
2344
|
-
assert events == []
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
def test_foreground_runner_emits_structured_feature_progress(monkeypatch, tmp_path, capsys):
|
|
2348
|
-
from prizmkit_runtime import runners
|
|
2349
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2350
|
-
|
|
2351
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-output")
|
|
2352
|
-
monkeypatch.delenv("MAX_RETRIES", raising=False)
|
|
2353
|
-
paths = _make_paths(tmp_path)
|
|
2354
|
-
family = family_for("feature", paths)
|
|
2355
|
-
invocation = parse_invocation(family, "run", ())
|
|
2356
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2357
|
-
_install_runner_session_fakes(monkeypatch, runners)
|
|
2358
|
-
monkeypatch.setattr(runners, "run_git_plan", lambda project_root, plan: SimpleNamespace(ok=True, plan=plan, results=()))
|
|
2359
|
-
|
|
2360
|
-
status = runners._process_item(
|
|
2361
|
-
family,
|
|
2362
|
-
invocation,
|
|
2363
|
-
"F-001",
|
|
2364
|
-
paths,
|
|
2365
|
-
initial_metadata={"title": "Readable output", "retry_count": 1, "infra_error_count": 2},
|
|
2366
|
-
)
|
|
2367
|
-
|
|
2368
|
-
captured = capsys.readouterr()
|
|
2369
|
-
assert status == "completed"
|
|
2370
|
-
assert "────────────────────────────────────────────────────" in captured.err
|
|
2371
|
-
assert "Feature: F-001 — Readable output" in captured.err
|
|
2372
|
-
assert "Code retry: 1 / 3" in captured.err
|
|
2373
|
-
assert "Preflight: no user-visible changes to preserve before feature task F-001" in captured.err
|
|
2374
|
-
assert "Pipeline mode:" not in captured.err
|
|
2375
|
-
assert "Spawning AI CLI session: F-001-session-1" in captured.err
|
|
2376
|
-
assert "Session result: success" in captured.err
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
def test_durable_checkout_reservation_is_first_writer_wins_and_conflicts_fail(tmp_path):
|
|
2380
|
-
from prizmkit_runtime.task_checkout import TaskCheckout, TaskCheckoutError, reserve_task_checkout
|
|
2381
|
-
|
|
2382
|
-
state_dir = tmp_path / "state"
|
|
2383
|
-
first = TaskCheckout.active("feature", "F-001", "dev/F-001-first", "main")
|
|
2384
|
-
conflicting = TaskCheckout.active("feature", "F-001", "dev/F-001-second", "main")
|
|
2385
|
-
|
|
2386
|
-
assert reserve_task_checkout(state_dir, first) == first
|
|
2387
|
-
assert reserve_task_checkout(state_dir, first) == first
|
|
2388
|
-
with pytest.raises(TaskCheckoutError, match="already owns checkout"):
|
|
2389
|
-
reserve_task_checkout(state_dir, conflicting)
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
def test_task_checkout_guard_rejects_concurrent_start_and_reset(tmp_path):
|
|
2393
|
-
from prizmkit_runtime.task_checkout import TaskCheckoutError, task_checkout_guard
|
|
2394
|
-
|
|
2395
|
-
state_dir = tmp_path / "state"
|
|
2396
|
-
with task_checkout_guard(state_dir, "F-001"):
|
|
2397
|
-
with pytest.raises(TaskCheckoutError, match="already running or being reset"):
|
|
2398
|
-
with task_checkout_guard(state_dir, "F-001"):
|
|
2399
|
-
pass
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
def test_completed_checkout_blocks_rerun_until_explicit_reset(monkeypatch, tmp_path):
|
|
2403
|
-
from prizmkit_runtime import runners
|
|
2404
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2405
|
-
from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
|
|
2406
|
-
|
|
2407
|
-
paths = _make_paths(tmp_path)
|
|
2408
|
-
family = family_for("feature", paths)
|
|
2409
|
-
invocation = parse_invocation(family, "run", ())
|
|
2410
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2411
|
-
completed = TaskCheckout.active("feature", "F-001", "dev/F-001-completed", "main").completed()
|
|
2412
|
-
persist_task_checkout(family.state_dir, completed)
|
|
2413
|
-
monkeypatch.setattr(
|
|
2414
|
-
runners,
|
|
2415
|
-
"load_runtime_config",
|
|
2416
|
-
lambda paths: SimpleNamespace(ai_client=SimpleNamespace(command="fake-ai", platform="codebuddy"), model="", effort=None),
|
|
2417
|
-
)
|
|
2418
|
-
|
|
2419
|
-
with pytest.raises(RuntimeError, match="completed; run explicit reset or clean"):
|
|
2420
|
-
runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
def test_no_worktree_interrupt_saves_wip_and_returns_to_base(monkeypatch, tmp_path, capsys):
|
|
2424
|
-
from prizmkit_runtime import runners
|
|
2425
|
-
from prizmkit_runtime.gitops import current_branch as real_current_branch
|
|
2426
|
-
from prizmkit_runtime.gitops import run_git_command as real_run_git_command
|
|
2427
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2428
|
-
from prizmkit_runtime.task_checkout import load_task_checkout
|
|
2429
|
-
|
|
2430
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-interrupt")
|
|
2431
|
-
monkeypatch.delenv("MAX_RETRIES", raising=False)
|
|
2432
|
-
monkeypatch.delenv("MAX_INFRA_RETRIES", raising=False)
|
|
2433
|
-
paths = _make_paths(tmp_path)
|
|
2434
|
-
_init_bookkeeping_repo(paths.project_root)
|
|
2435
|
-
family = family_for("feature", paths)
|
|
2436
|
-
invocation = parse_invocation(family, "run", ())
|
|
2437
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2438
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
2439
|
-
monkeypatch.setattr(runners, "current_branch", real_current_branch)
|
|
2440
|
-
monkeypatch.setattr(runners, "run_git_command", real_run_git_command)
|
|
2441
|
-
|
|
2442
|
-
class InterruptingLauncher:
|
|
2443
|
-
def __init__(self, config):
|
|
2444
|
-
self.config = config
|
|
2445
|
-
|
|
2446
|
-
def run(self):
|
|
2447
|
-
(self.config.cwd / "interrupted.txt").write_text("preserved\n", encoding="utf-8")
|
|
2448
|
-
raise KeyboardInterrupt
|
|
2449
|
-
|
|
2450
|
-
monkeypatch.setattr(runners, "AISessionLauncher", InterruptingLauncher)
|
|
2451
|
-
|
|
2452
|
-
with pytest.raises(KeyboardInterrupt):
|
|
2453
|
-
runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2454
|
-
|
|
2455
|
-
checkout = load_task_checkout(family.state_dir, family.task_type, "F-001")
|
|
2456
|
-
captured = capsys.readouterr()
|
|
2457
|
-
assert checkout is not None
|
|
2458
|
-
assert checkout.is_active
|
|
2459
|
-
assert checkout.active_dev_branch == "dev/F-001-interrupt"
|
|
2460
|
-
assert checkout.base_branch == "main"
|
|
2461
|
-
assert real_current_branch(paths.project_root) == "main"
|
|
2462
|
-
assert subprocess.run(
|
|
2463
|
-
["git", "show", "dev/F-001-interrupt:interrupted.txt"],
|
|
2464
|
-
cwd=paths.project_root,
|
|
2465
|
-
check=True,
|
|
2466
|
-
stdout=subprocess.PIPE,
|
|
2467
|
-
text=True,
|
|
2468
|
-
).stdout == "preserved\n"
|
|
2469
|
-
assert "Interrupt diagnostics: trigger=keyboard_interrupt; platform_signal=SIGINT(2) (inferred)" in captured.err
|
|
2470
|
-
assert "Interrupt context: task=F-001; task_type=feature; session=F-001-session-1" in captured.err
|
|
2471
|
-
assert "Retry accounting unchanged: code=0/3; infrastructure=0/3" in captured.err
|
|
2472
|
-
assert "No session classification or task-status update will be written" in captured.err
|
|
2473
|
-
assert "Interrupted task F-001: WIP committed on dev/F-001-interrupt" in captured.err
|
|
2474
|
-
assert "caller checkout returned to main; no merge or push performed" in captured.err
|
|
2475
|
-
assert observed.updates == []
|
|
2476
|
-
assert not observed.prompt_calls[0]["session_paths"].session_status_json.exists()
|
|
2477
|
-
assert observed.merge_calls == []
|
|
2478
|
-
assert observed.cleanup_calls == []
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
def test_interrupt_return_failure_is_reported_without_forcing_checkout(monkeypatch, tmp_path, capsys):
|
|
2482
|
-
from prizmkit_runtime import runners
|
|
2483
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2484
|
-
|
|
2485
|
-
monkeypatch.setenv("DEV_BRANCH", "dev/F-001-interrupt")
|
|
2486
|
-
paths = _make_paths(tmp_path)
|
|
2487
|
-
family = family_for("feature", paths)
|
|
2488
|
-
invocation = parse_invocation(family, "run", ())
|
|
2489
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
|
|
2490
|
-
_install_runner_session_fakes(monkeypatch, runners)
|
|
2491
|
-
monkeypatch.setattr(runners, "run_git_plan", lambda project_root, plan: SimpleNamespace(ok=True, plan=plan, results=()))
|
|
2492
|
-
failure = SimpleNamespace(
|
|
2493
|
-
ok=False,
|
|
2494
|
-
plan=SimpleNamespace(
|
|
2495
|
-
commands=(
|
|
2496
|
-
SimpleNamespace(allow_failure=True),
|
|
2497
|
-
SimpleNamespace(allow_failure=False),
|
|
2498
|
-
)
|
|
2499
|
-
),
|
|
2500
|
-
results=(
|
|
2501
|
-
SimpleNamespace(
|
|
2502
|
-
args=("commit", "--no-verify", "-m", "wip"),
|
|
2503
|
-
return_code=1,
|
|
2504
|
-
stdout="nothing to commit",
|
|
2505
|
-
stderr="",
|
|
2506
|
-
),
|
|
2507
|
-
SimpleNamespace(
|
|
2508
|
-
args=("checkout", "main"),
|
|
2509
|
-
return_code=1,
|
|
2510
|
-
stdout="",
|
|
2511
|
-
stderr="untracked files would be overwritten\nconflicting path: local.txt",
|
|
2512
|
-
),
|
|
2513
|
-
),
|
|
2514
|
-
)
|
|
2515
|
-
monkeypatch.setattr(runners, "branch_save_wip", lambda project_root, branch: SimpleNamespace(ok=True, results=()))
|
|
2516
|
-
monkeypatch.setattr(runners, "branch_ensure_return", lambda project_root, base, branch: failure)
|
|
2517
|
-
|
|
2518
|
-
class InterruptingLauncher:
|
|
2519
|
-
def __init__(self, config):
|
|
2520
|
-
self.config = config
|
|
2521
|
-
|
|
2522
|
-
def run(self):
|
|
2523
|
-
raise KeyboardInterrupt
|
|
2524
|
-
|
|
2525
|
-
monkeypatch.setattr(runners, "AISessionLauncher", InterruptingLauncher)
|
|
2526
|
-
|
|
2527
|
-
with pytest.raises(KeyboardInterrupt):
|
|
2528
|
-
runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2529
|
-
|
|
2530
|
-
captured = capsys.readouterr()
|
|
2531
|
-
assert "Interrupted WIP for F-001 is safe, but the caller checkout could not return to main" in captured.err
|
|
2532
|
-
assert "git checkout main failed" in captured.err
|
|
2533
|
-
assert "untracked files would be overwritten" in captured.err
|
|
2534
|
-
assert "conflicting path: local.txt" in captured.err
|
|
2535
|
-
assert "After resolving the Git blocker" not in captured.err
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
def test_run_pipeline_command_bridges_sigterm_and_restores_handler(monkeypatch, tmp_path):
|
|
2539
|
-
from prizmkit_runtime import runners
|
|
2540
|
-
from prizmkit_runtime.processes import describe_interruption
|
|
2541
|
-
from prizmkit_runtime.runner_models import PipelineRunResult
|
|
2542
|
-
|
|
2543
|
-
paths = _make_paths(tmp_path)
|
|
2544
|
-
paths.feature_plan.write_text("{}", encoding="utf-8")
|
|
2545
|
-
previous = signal.getsignal(signal.SIGTERM)
|
|
2546
|
-
observed = []
|
|
2547
|
-
|
|
2548
|
-
def interrupted_pipeline(*args, **kwargs):
|
|
2549
|
-
installed = signal.getsignal(signal.SIGTERM)
|
|
2550
|
-
try:
|
|
2551
|
-
installed(signal.SIGTERM, None)
|
|
2552
|
-
except KeyboardInterrupt as interruption:
|
|
2553
|
-
observed.append((installed, describe_interruption(interruption)))
|
|
2554
|
-
return PipelineRunResult(False, 1, "interrupted", "interrupted")
|
|
2555
|
-
raise AssertionError("SIGTERM handler did not interrupt the pipeline")
|
|
2556
|
-
|
|
2557
|
-
monkeypatch.setattr(runners, "_run_pipeline", interrupted_pipeline)
|
|
2558
|
-
|
|
2559
|
-
result = runners.run_pipeline_command("feature", "run", (), paths)
|
|
2560
|
-
|
|
2561
|
-
assert result.exit_code == 1
|
|
2562
|
-
assert result.message == "processed=1 completed=False stopped_reason=interrupted"
|
|
2563
|
-
assert observed and observed[0][0] not in {previous, signal.SIG_DFL, signal.SIG_IGN}
|
|
2564
|
-
assert observed[0][1].trigger == "platform_signal"
|
|
2565
|
-
assert observed[0][1].signal_label == "SIGTERM(15)"
|
|
2566
|
-
assert observed[0][1].signal_exact is True
|
|
2567
|
-
assert signal.getsignal(signal.SIGTERM) is previous
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
def test_interruption_cleanup_shield_ignores_and_restores_signals():
|
|
2571
|
-
from prizmkit_runtime.processes import shield_interruption_signals
|
|
2572
|
-
|
|
2573
|
-
previous_sigint = signal.getsignal(signal.SIGINT)
|
|
2574
|
-
previous_sigterm = signal.getsignal(signal.SIGTERM)
|
|
2575
|
-
|
|
2576
|
-
with shield_interruption_signals():
|
|
2577
|
-
assert signal.getsignal(signal.SIGINT) is signal.SIG_IGN
|
|
2578
|
-
assert signal.getsignal(signal.SIGTERM) is signal.SIG_IGN
|
|
2579
|
-
|
|
2580
|
-
assert signal.getsignal(signal.SIGINT) is previous_sigint
|
|
2581
|
-
assert signal.getsignal(signal.SIGTERM) is previous_sigterm
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
@pytest.mark.parametrize(
|
|
2585
|
-
("kind", "item_id", "branch"),
|
|
2586
|
-
[
|
|
2587
|
-
("feature", "F-001", "dev/F-001-interrupt"),
|
|
2588
|
-
("bugfix", "B-001", "bugfix/B-001-interrupt"),
|
|
2589
|
-
],
|
|
2590
|
-
)
|
|
2591
|
-
def test_interrupted_task_reuses_durable_checkout_on_next_process(monkeypatch, tmp_path, kind, item_id, branch):
|
|
2592
|
-
from prizmkit_runtime import runners
|
|
2593
|
-
from prizmkit_runtime.runner_models import family_for, parse_invocation
|
|
2594
|
-
from prizmkit_runtime.task_checkout import TaskCheckout, persist_task_checkout
|
|
2595
|
-
|
|
2596
|
-
paths = _make_paths(tmp_path / kind)
|
|
2597
|
-
family = family_for(kind, paths)
|
|
2598
|
-
plan_path = {"feature": paths.feature_plan, "bugfix": paths.bugfix_plan}[kind]
|
|
2599
|
-
invocation = parse_invocation(family, "run", ())
|
|
2600
|
-
invocation = invocation.__class__(**{**invocation.__dict__, "list_path": plan_path})
|
|
2601
|
-
persist_task_checkout(family.state_dir, TaskCheckout.active(kind, item_id, branch, "main"))
|
|
2602
|
-
observed = _install_runner_session_fakes(monkeypatch, runners)
|
|
2603
|
-
branch_contexts = []
|
|
2604
|
-
|
|
2605
|
-
def fake_git_plan(project_root, plan):
|
|
2606
|
-
branch_contexts.append((plan.commands[1].args[-2], plan.commands[1].args[-1]))
|
|
2607
|
-
return SimpleNamespace(ok=True, plan=plan, results=())
|
|
2608
|
-
|
|
2609
|
-
monkeypatch.delenv("DEV_BRANCH", raising=False)
|
|
2610
|
-
monkeypatch.setattr(runners, "run_git_plan", fake_git_plan)
|
|
2611
|
-
|
|
2612
|
-
status = runners._process_item(family, invocation, item_id, paths, initial_metadata={})
|
|
2613
|
-
|
|
2614
|
-
assert status == "completed"
|
|
2615
|
-
assert branch_contexts[0] == (branch, "main")
|
|
2616
|
-
assert observed.launch_cwds == [paths.project_root]
|
|
2617
|
-
|
|
2618
|
-
|
|
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
|
|
2622
|
-
|
|
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=()),
|
|
2636
|
-
)
|
|
2637
|
-
|
|
2638
|
-
status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
|
|
2639
|
-
|
|
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]
|
|
2648
|
-
|
|
2649
|
-
|
|
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,
|
|
2656
|
-
stdout=subprocess.PIPE,
|
|
2657
|
-
stderr=subprocess.PIPE,
|
|
2658
|
-
text=True,
|
|
2659
|
-
check=False,
|
|
2660
|
-
)
|
|
2661
|
-
|
|
2662
|
-
assert result.returncode == 0
|
|
2663
|
-
assert "Python feature status" in result.stdout
|
|
2664
|
-
assert "Transition command contract" not in result.stdout
|
|
2665
|
-
|
|
2666
|
-
|
|
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"
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
def test_python_reset_warns_before_mutation_and_matches_snapshot_cleanup(tmp_path):
|
|
2704
|
-
from prizmkit_runtime.reset import run_reset_command
|
|
2705
|
-
from prizmkit_runtime.runner_models import family_for
|
|
2706
|
-
from prizmkit_runtime.task_checkout import load_task_checkout
|
|
2707
|
-
|
|
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"
|
|
2715
|
-
|
|
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 == ""
|
|
2731
|
-
|
|
2732
|
-
|
|
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
|
|
2736
|
-
from prizmkit_runtime.runner_models import family_for
|
|
2737
|
-
from prizmkit_runtime.task_checkout import TaskCheckout, load_task_checkout, persist_task_checkout
|
|
2738
|
-
|
|
2739
|
-
paths = _make_paths(tmp_path)
|
|
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: ())
|
|
2747
|
-
monkeypatch.setattr(
|
|
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=()),
|
|
2752
|
-
)
|
|
2753
|
-
|
|
2754
|
-
result = run_reset_command("feature", ("F-001", "--fresh-checkout"), paths)
|
|
2755
|
-
|
|
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
|
|
2760
|
-
|
|
2761
|
-
|
|
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
|
|
2767
|
-
|
|
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
|
-
)
|
|
2785
|
-
|
|
2786
|
-
result = run_reset_command("feature", ("F-001", "--fresh-checkout"), paths)
|
|
2787
|
-
|
|
2788
|
-
assert result.exit_code == 1
|
|
2789
|
-
assert load_task_checkout(family.state_dir, family.task_type, "F-001") == checkout
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
def test_python_clean_reset_deletes_continuation_artifacts_for_all_families(tmp_path):
|
|
2793
|
-
from prizmkit_runtime.reset import run_reset_command
|
|
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)
|
|
2806
|
-
|
|
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
|
|
2813
|
-
|
|
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")
|
|
2817
|
-
|
|
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
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
def test_python_daemon_stale_pid_matches_snapshot(tmp_path):
|
|
2825
|
-
from prizmkit_runtime.daemon import run_daemon_command
|
|
2826
|
-
|
|
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]
|
|
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 "")
|
|
2841
|
-
|
|
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",
|
|
2861
|
-
)
|
|
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")
|
|
2866
|
-
|
|
2867
|
-
start = run_daemon_command("feature", "start", ("--env", "FOO=bar", "--features", "F-001"), paths)
|
|
2868
|
-
try:
|
|
2869
|
-
start_payload = json.loads(start.render())
|
|
2870
|
-
status = run_daemon_command("feature", "status", (), paths)
|
|
2871
|
-
status_payload = json.loads(status.render())
|
|
2872
|
-
finally:
|
|
2873
|
-
stop = run_daemon_command("feature", "stop", (), paths)
|
|
2874
|
-
|
|
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
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
def test_python_reset_stalled_filter_selects_stalled_context_items(tmp_path):
|
|
2892
|
-
from prizmkit_runtime.reset import run_reset_command
|
|
2893
|
-
|
|
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")
|
|
2904
|
-
|
|
2905
|
-
result = run_reset_command(kind, ("--stalled", "--fresh-checkout"), paths)
|
|
2906
|
-
|
|
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"
|
|
2914
|
-
|
|
2915
|
-
|
|
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
|
|
2919
|
-
|
|
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",
|
|
2930
|
-
)
|
|
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
|
|
2943
|
-
|
|
2944
|
-
summary = _progress_summary(family_for(kind, paths), plan)
|
|
2945
|
-
|
|
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
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
def test_session_status_parser_preserves_current_runtime_outcomes():
|
|
2958
|
-
import importlib.util
|
|
2959
|
-
|
|
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)
|
|
2964
|
-
|
|
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
|
|
2972
|
-
|
|
2973
|
-
|