prizmkit 1.1.192 → 1.1.193

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/bundled/VERSION.json +3 -3
  2. package/bundled/dev-pipeline/README.md +23 -34
  3. package/bundled/dev-pipeline/assets/feature-list-example.json +0 -1
  4. package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -0
  5. package/bundled/dev-pipeline/prizmkit_runtime/config.py +24 -2
  6. package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +2 -0
  7. package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +89 -40
  8. package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +9 -1
  9. package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +0 -22
  10. package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +11 -7
  11. package/bundled/dev-pipeline/prizmkit_runtime/processes.py +26 -20
  12. package/bundled/dev-pipeline/prizmkit_runtime/reset.py +37 -4
  13. package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +20 -41
  14. package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +74 -36
  15. package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +0 -66
  16. package/bundled/dev-pipeline/prizmkit_runtime/runners.py +271 -52
  17. package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +51 -13
  18. package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +43 -15
  19. package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +27 -24
  20. package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +0 -1
  21. package/bundled/dev-pipeline/scripts/check-session-status.py +13 -1
  22. package/bundled/dev-pipeline/scripts/continuation.py +2 -3
  23. package/bundled/dev-pipeline/scripts/detect-stuck.py +19 -5
  24. package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +6 -14
  25. package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +13 -8
  26. package/bundled/dev-pipeline/scripts/init-change-artifact.py +17 -2
  27. package/bundled/dev-pipeline/scripts/prompt_framework.py +39 -21
  28. package/bundled/dev-pipeline/scripts/update-checkpoint.py +27 -0
  29. package/bundled/dev-pipeline/templates/bootstrap-tier3.md +1 -1
  30. package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +6 -6
  31. package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +1 -1
  32. package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +1 -1
  33. package/bundled/skills/_metadata.json +1 -1
  34. package/package.json +1 -1
  35. package/bundled/dev-pipeline/tests/_helpers.py +0 -418
  36. package/bundled/dev-pipeline/tests/conftest.py +0 -73
  37. package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +0 -208
  38. package/bundled/dev-pipeline/tests/test_auto_skip.py +0 -1806
  39. package/bundled/dev-pipeline/tests/test_checkpoint_state.py +0 -1439
  40. package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +0 -257
  41. package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +0 -500
  42. package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +0 -1654
  43. package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +0 -629
  44. package/bundled/dev-pipeline/tests/test_python_runner_parity.py +0 -2973
  45. package/bundled/dev-pipeline/tests/test_recovery_workflow.py +0 -321
  46. package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -251
  47. package/bundled/dev-pipeline/tests/test_reset_modes.py +0 -1196
  48. package/bundled/dev-pipeline/tests/test_reset_preserve.py +0 -872
  49. package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +0 -766
  50. package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +0 -1257
  51. package/bundled/dev-pipeline/tests/test_runtime_commit.py +0 -1113
  52. package/bundled/dev-pipeline/tests/test_runtime_helper.py +0 -380
  53. package/bundled/dev-pipeline/tests/test_session_launch.py +0 -1101
  54. package/bundled/dev-pipeline/tests/test_stream_progress.py +0 -585
  55. package/bundled/dev-pipeline/tests/test_unified_cli.py +0 -3625
  56. package/bundled/dev-pipeline/tests/test_utils.py +0 -170
@@ -1,766 +0,0 @@
1
- """Focused tests for runner bookkeeping and preflight workspace isolation."""
2
-
3
- from __future__ import annotations
4
-
5
- import json
6
- import subprocess
7
- import sys
8
- from types import SimpleNamespace
9
-
10
- import pytest
11
-
12
- from _helpers import (
13
- PIPELINE_ROOT,
14
- _init_bookkeeping_repo,
15
- _install_runner_session_fakes,
16
- _make_paths,
17
- )
18
-
19
- sys.path.insert(0, str(PIPELINE_ROOT))
20
-
21
-
22
- def _head_commit_count(project_root):
23
- return int(
24
- subprocess.run(
25
- ["git", "rev-list", "--count", "HEAD"],
26
- cwd=project_root,
27
- check=True,
28
- stdout=subprocess.PIPE,
29
- text=True,
30
- ).stdout.strip()
31
- )
32
-
33
-
34
- def _head_message(project_root):
35
- return subprocess.run(
36
- ["git", "log", "-1", "--format=%s"],
37
- cwd=project_root,
38
- check=True,
39
- stdout=subprocess.PIPE,
40
- text=True,
41
- ).stdout.strip()
42
-
43
-
44
- def _head_files(project_root):
45
- return set(
46
- subprocess.run(
47
- ["git", "show", "--name-only", "--format=", "HEAD"],
48
- cwd=project_root,
49
- check=True,
50
- stdout=subprocess.PIPE,
51
- text=True,
52
- ).stdout.splitlines()
53
- )
54
-
55
-
56
- @pytest.mark.parametrize(
57
- ("scenario", "expected_files"),
58
- [
59
- ("staged_only", {"staged.txt"}),
60
- ("unstaged_only", {"unstaged.txt"}),
61
- ("mixed", {"staged.txt", "unstaged.txt", "new-visible.txt"}),
62
- ],
63
- )
64
- def test_preflight_ready_commit_preserves_staged_unstaged_and_mixed_visible_changes(tmp_path, scenario, expected_files):
65
- from prizmkit_runtime.gitops import HIDDEN_TOOL_WORKTREE_EXCLUDES
66
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
67
-
68
- _init_bookkeeping_repo(tmp_path)
69
- if scenario in {"staged_only", "mixed"}:
70
- (tmp_path / "staged.txt").write_text("staged change\n", encoding="utf-8")
71
- subprocess.run(["git", "add", "staged.txt"], cwd=tmp_path, check=True)
72
- if scenario in {"unstaged_only", "mixed"}:
73
- (tmp_path / "unstaged.txt").write_text("unstaged change\n", encoding="utf-8")
74
- if scenario == "mixed":
75
- (tmp_path / "new-visible.txt").write_text("new visible\n", encoding="utf-8")
76
-
77
- before_count = _head_commit_count(tmp_path)
78
- result = commit_preflight_ready_changes(tmp_path, "F-123")
79
- visible_status = subprocess.run(
80
- ["git", "status", "--porcelain", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES],
81
- cwd=tmp_path,
82
- check=True,
83
- stdout=subprocess.PIPE,
84
- text=True,
85
- ).stdout
86
-
87
- assert result.attempted is True
88
- assert result.committed is True
89
- assert _head_commit_count(tmp_path) == before_count + 1
90
- assert _head_message(tmp_path) == "chore: ready for F-123"
91
- assert expected_files.issubset(_head_files(tmp_path))
92
- assert visible_status == ""
93
-
94
-
95
- def test_preflight_ready_commit_handles_exact_special_and_renamed_paths(tmp_path):
96
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
97
-
98
- _init_bookkeeping_repo(tmp_path)
99
- old_path = tmp_path / "old name -> café.txt"
100
- old_path.write_text("old\n", encoding="utf-8")
101
- subprocess.run(["git", "add", old_path.name], cwd=tmp_path, check=True)
102
- subprocess.run(["git", "commit", "-m", "track special path"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
103
- new_path = tmp_path / 'new "quoted" \\ 名称.txt'
104
- old_path.rename(new_path)
105
- untracked_path = tmp_path / "untracked -> line\nbreak.txt"
106
- untracked_path.write_text("new\n", encoding="utf-8")
107
- colon_path = tmp_path / ":(glob)**.txt"
108
- colon_path.write_text("literal pathspec\n", encoding="utf-8")
109
-
110
- result = commit_preflight_ready_changes(tmp_path, "F-001")
111
- committed_files = set(
112
- filter(
113
- None,
114
- subprocess.run(
115
- ["git", "diff-tree", "--no-commit-id", "--name-only", "-r", "-z", "HEAD"],
116
- cwd=tmp_path,
117
- check=True,
118
- stdout=subprocess.PIPE,
119
- ).stdout.decode().split("\0"),
120
- )
121
- )
122
-
123
- assert result.committed is True
124
- assert old_path.name in committed_files
125
- assert new_path.name in committed_files
126
- assert untracked_path.name in committed_files
127
- assert colon_path.name in committed_files
128
- assert _head_message(tmp_path) == "chore: ready for F-001"
129
-
130
-
131
- @pytest.mark.parametrize("staged", [False, True])
132
- def test_preflight_ready_commit_rejects_tracked_local_settings_before_checkout(tmp_path, staged):
133
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
134
-
135
- _init_bookkeeping_repo(tmp_path)
136
- local_settings = tmp_path / ".claude" / "settings.local.json"
137
- local_settings.parent.mkdir(parents=True)
138
- local_settings.write_text('{"permissions": []}\n', encoding="utf-8")
139
- subprocess.run(["git", "add", "-f", ".claude/settings.local.json"], cwd=tmp_path, check=True)
140
- subprocess.run(["git", "commit", "-m", "track local settings"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
141
- local_settings.write_text('{"permissions": ["secret"]}\n', encoding="utf-8")
142
- if staged:
143
- subprocess.run(["git", "add", ".claude/settings.local.json"], cwd=tmp_path, check=True)
144
-
145
- result = commit_preflight_ready_changes(tmp_path, "B-001")
146
-
147
- assert result.attempted is True
148
- assert result.committed is False
149
- assert result.result is not None
150
- assert "Refusing to auto-commit local-only platform settings" in result.result.stderr
151
- assert _head_message(tmp_path) == "track local settings"
152
-
153
-
154
- def test_preflight_ready_commit_excludes_untracked_python_cache_outside_support_dirs(tmp_path):
155
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
156
-
157
- _init_bookkeeping_repo(tmp_path)
158
- (tmp_path / "visible.txt").write_text("visible\n", encoding="utf-8")
159
- cache_paths = [
160
- tmp_path / "__pycache__" / "top.cpython-312.pyc",
161
- tmp_path / "src" / "package" / "__pycache__" / "module.cpython-312.pyc",
162
- tmp_path / "src" / "standalone.pyo",
163
- ]
164
- for path in cache_paths:
165
- path.parent.mkdir(parents=True, exist_ok=True)
166
- path.write_text("compiled\n", encoding="utf-8")
167
-
168
- result = commit_preflight_ready_changes(tmp_path, "F-001")
169
- committed_files = _head_files(tmp_path)
170
-
171
- assert result.committed is True
172
- assert committed_files == {"visible.txt"}
173
- assert all(path.is_file() for path in cache_paths)
174
-
175
-
176
- def test_tracked_python_cache_remains_visible_to_task_commit(tmp_path):
177
- from prizmkit_runtime.runner_bookkeeping import commit_task_branch_changes
178
- from prizmkit_runtime.runner_models import family_for
179
-
180
- paths = _make_paths(tmp_path)
181
- _init_bookkeeping_repo(paths.project_root)
182
- tracked_cache = paths.project_root / "src" / "__pycache__" / "module.pyc"
183
- tracked_cache.parent.mkdir(parents=True)
184
- tracked_cache.write_text("baseline\n", encoding="utf-8")
185
- subprocess.run(["git", "add", tracked_cache.relative_to(paths.project_root).as_posix()], cwd=paths.project_root, check=True)
186
- subprocess.run(["git", "commit", "-m", "track cache"], cwd=paths.project_root, check=True, stdout=subprocess.DEVNULL)
187
- tracked_cache.write_text("task change\n", encoding="utf-8")
188
-
189
- result = commit_task_branch_changes(paths.project_root, family_for("bugfix", paths), "B-001", "completed")
190
-
191
- assert result.committed is True
192
- assert tracked_cache.relative_to(paths.project_root).as_posix() in _head_files(paths.project_root)
193
- assert subprocess.run(
194
- ["git", "status", "--short", "--untracked-files=no"],
195
- cwd=paths.project_root,
196
- check=True,
197
- stdout=subprocess.PIPE,
198
- text=True,
199
- ).stdout == ""
200
-
201
-
202
- @pytest.mark.parametrize("helper_name", ["commit_task_branch_changes", "commit_wip_changes"])
203
- def test_task_commit_helpers_propagate_staging_failure_without_commit(monkeypatch, tmp_path, helper_name):
204
- from prizmkit_runtime import runner_bookkeeping
205
- from prizmkit_runtime.gitops import GitCommandResult
206
- from prizmkit_runtime.runner_models import family_for
207
-
208
- paths = _make_paths(tmp_path)
209
- family = family_for("bugfix", paths)
210
- status_result = GitCommandResult(("status",), 0, " M app.txt\0", "")
211
- indexed_result = GitCommandResult(("ls-files",), 0, "app.txt\0", "")
212
- monkeypatch.setattr(
213
- runner_bookkeeping,
214
- "visible_task_paths",
215
- lambda _root: (("app.txt",), status_result),
216
- )
217
- monkeypatch.setattr(
218
- runner_bookkeeping,
219
- "addable_task_paths",
220
- lambda _root, _paths: (("app.txt",), indexed_result),
221
- )
222
- calls = []
223
-
224
- def fail_add(_root, args):
225
- args = tuple(args)
226
- calls.append(args)
227
- assert args[0] != "commit"
228
- return GitCommandResult(args, 1, "", "staging failed")
229
-
230
- monkeypatch.setattr(runner_bookkeeping, "run_git_command", fail_add)
231
- helper = getattr(runner_bookkeeping, helper_name)
232
-
233
- result = helper(paths.project_root, family, "B-001", "failed")
234
-
235
- assert result.attempted is True
236
- assert result.committed is False
237
- assert result.result is not None and result.result.stderr == "staging failed"
238
- assert calls and all(args[0] != "commit" for args in calls)
239
-
240
-
241
- def test_preflight_ready_commit_includes_tracked_state_but_excludes_untracked_state(tmp_path):
242
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
243
-
244
- _init_bookkeeping_repo(tmp_path)
245
- tracked_state = tmp_path / ".prizmkit" / "state" / "bugfix" / "B-001" / "tracked.json"
246
- tracked_state.parent.mkdir(parents=True)
247
- tracked_state.write_text("baseline\n", encoding="utf-8")
248
- subprocess.run(["git", "add", "-f", tracked_state.relative_to(tmp_path).as_posix()], cwd=tmp_path, check=True)
249
- subprocess.run(["git", "commit", "-m", "track state"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
250
- tracked_state.write_text("changed\n", encoding="utf-8")
251
- untracked_state = tracked_state.parent / "untracked.json"
252
- untracked_state.write_text("transient\n", encoding="utf-8")
253
-
254
- result = commit_preflight_ready_changes(tmp_path, "B-001")
255
-
256
- assert result.committed is True
257
- assert tracked_state.relative_to(tmp_path).as_posix() in _head_files(tmp_path)
258
- assert untracked_state.relative_to(tmp_path).as_posix() not in _head_files(tmp_path)
259
-
260
-
261
- def _track_manifest(project_root):
262
- manifest_path = project_root / ".prizmkit" / "manifest.json"
263
- manifest_path.parent.mkdir(parents=True, exist_ok=True)
264
- manifest_path.write_text('{"version":"baseline"}\n', encoding="utf-8")
265
- subprocess.run(["git", "add", ".prizmkit/manifest.json"], cwd=project_root, check=True)
266
- subprocess.run(["git", "commit", "-m", "track manifest"], cwd=project_root, check=True, stdout=subprocess.DEVNULL)
267
- return manifest_path
268
-
269
-
270
- @pytest.mark.parametrize(
271
- ("scenario", "expected_content"),
272
- [
273
- ("staged_only", '{"version":"staged"}\n'),
274
- ("unstaged_only", '{"version":"unstaged"}\n'),
275
- ("staged_and_unstaged", '{"version":"working-tree"}\n'),
276
- ],
277
- )
278
- def test_preflight_ready_commit_preserves_tracked_manifest_modification_state(tmp_path, scenario, expected_content):
279
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
280
-
281
- _init_bookkeeping_repo(tmp_path)
282
- manifest_path = _track_manifest(tmp_path)
283
- if scenario == "staged_only":
284
- manifest_path.write_text(expected_content, encoding="utf-8")
285
- subprocess.run(["git", "add", ".prizmkit/manifest.json"], cwd=tmp_path, check=True)
286
- elif scenario == "unstaged_only":
287
- manifest_path.write_text(expected_content, encoding="utf-8")
288
- else:
289
- manifest_path.write_text('{"version":"index"}\n', encoding="utf-8")
290
- subprocess.run(["git", "add", ".prizmkit/manifest.json"], cwd=tmp_path, check=True)
291
- manifest_path.write_text(expected_content, encoding="utf-8")
292
-
293
- before_count = _head_commit_count(tmp_path)
294
- result = commit_preflight_ready_changes(tmp_path, "F-003")
295
- committed_content = subprocess.run(
296
- ["git", "show", "HEAD:.prizmkit/manifest.json"],
297
- cwd=tmp_path,
298
- check=True,
299
- stdout=subprocess.PIPE,
300
- text=True,
301
- ).stdout
302
-
303
- assert result.attempted is True
304
- assert result.committed is True
305
- assert _head_commit_count(tmp_path) == before_count + 1
306
- assert _head_message(tmp_path) == "chore: ready for F-003"
307
- assert _head_files(tmp_path) == {".prizmkit/manifest.json"}
308
- assert committed_content == expected_content
309
- assert subprocess.run(
310
- ["git", "status", "--short", "--untracked-files=no"],
311
- cwd=tmp_path,
312
- check=True,
313
- stdout=subprocess.PIPE,
314
- text=True,
315
- ).stdout == ""
316
-
317
-
318
- @pytest.mark.parametrize("staged", [False, True])
319
- def test_preflight_ready_commit_preserves_tracked_manifest_deletion(tmp_path, staged):
320
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
321
-
322
- _init_bookkeeping_repo(tmp_path)
323
- manifest_path = _track_manifest(tmp_path)
324
- manifest_path.unlink()
325
- if staged:
326
- subprocess.run(["git", "add", "-u", "--", ".prizmkit/manifest.json"], cwd=tmp_path, check=True)
327
- (tmp_path / "unstaged.txt").write_text("coexisting tracked change\n", encoding="utf-8")
328
- (tmp_path / "coexisting.txt").write_text("coexisting untracked change\n", encoding="utf-8")
329
-
330
- before_count = _head_commit_count(tmp_path)
331
- result = commit_preflight_ready_changes(tmp_path, "B-003")
332
- manifest_at_head = subprocess.run(
333
- ["git", "cat-file", "-e", "HEAD:.prizmkit/manifest.json"],
334
- cwd=tmp_path,
335
- stdout=subprocess.DEVNULL,
336
- stderr=subprocess.DEVNULL,
337
- )
338
-
339
- assert result.attempted is True
340
- assert result.committed is True
341
- assert _head_commit_count(tmp_path) == before_count + 1
342
- assert _head_message(tmp_path) == "chore: ready for B-003"
343
- assert _head_files(tmp_path) == {".prizmkit/manifest.json", "coexisting.txt", "unstaged.txt"}
344
- assert manifest_at_head.returncode != 0
345
- assert subprocess.run(
346
- ["git", "status", "--short", "--untracked-files=all"],
347
- cwd=tmp_path,
348
- check=True,
349
- stdout=subprocess.PIPE,
350
- text=True,
351
- ).stdout == ""
352
-
353
-
354
- @pytest.mark.parametrize(
355
- ("payload", "expected_error"),
356
- [
357
- ("{not-json\n", "not valid JSON"),
358
- ("[]\n", "not a JSON object"),
359
- ],
360
- )
361
- def test_preflight_ready_commit_rejects_unsafe_tracked_manifest_before_any_commit(tmp_path, payload, expected_error):
362
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
363
-
364
- _init_bookkeeping_repo(tmp_path)
365
- manifest_path = _track_manifest(tmp_path)
366
- manifest_path.write_text(payload, encoding="utf-8")
367
- (tmp_path / "eligible.txt").write_text("must remain uncommitted\n", encoding="utf-8")
368
- before_count = _head_commit_count(tmp_path)
369
-
370
- result = commit_preflight_ready_changes(tmp_path, "F-003")
371
-
372
- assert result.attempted is True
373
- assert result.committed is False
374
- assert result.result is not None
375
- assert expected_error in result.result.stderr
376
- assert _head_commit_count(tmp_path) == before_count
377
- assert "eligible.txt" not in _head_files(tmp_path)
378
- assert subprocess.run(
379
- ["git", "status", "--short", "--untracked-files=all"],
380
- cwd=tmp_path,
381
- check=True,
382
- stdout=subprocess.PIPE,
383
- text=True,
384
- ).stdout.splitlines() == [" M .prizmkit/manifest.json", "?? eligible.txt"]
385
-
386
-
387
- def test_preflight_ready_commit_preserves_tracked_manifest_with_other_tracked_support(tmp_path):
388
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
389
-
390
- _init_bookkeeping_repo(tmp_path)
391
- manifest_path = tmp_path / ".prizmkit" / "manifest.json"
392
- tracked_support_paths = [
393
- tmp_path / ".prizmkit" / "dev-pipeline" / "prizmkit_runtime" / "runners.py",
394
- tmp_path / ".claude" / "commands" / "prizmkit.md",
395
- ]
396
- manifest_path.parent.mkdir(parents=True, exist_ok=True)
397
- manifest_path.write_text('{"version":"1.1.127"}\n', encoding="utf-8")
398
- for path in tracked_support_paths:
399
- path.parent.mkdir(parents=True, exist_ok=True)
400
- path.write_text("installed\n", encoding="utf-8")
401
- tracked_paths = [manifest_path, *tracked_support_paths]
402
- subprocess.run(
403
- ["git", "add", *(path.relative_to(tmp_path).as_posix() for path in tracked_paths)],
404
- cwd=tmp_path,
405
- check=True,
406
- )
407
- subprocess.run(["git", "commit", "-m", "track support"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
408
- manifest_path.write_text('{"version":"1.1.128"}\n', encoding="utf-8")
409
- for path in tracked_support_paths:
410
- path.write_text("upgraded\n", encoding="utf-8")
411
- visible_path = tmp_path / "visible.txt"
412
- visible_path.write_text("eligible untracked change\n", encoding="utf-8")
413
-
414
- untracked_support_paths = [
415
- tmp_path / ".claude" / "settings.local.json",
416
- tmp_path / ".prizmkit" / "dev-pipeline" / "scripts" / "__pycache__" / "runtime.pyc",
417
- tmp_path / ".prizmkit" / "state" / "bugfix" / "B-001" / "status.json",
418
- ]
419
- for path in untracked_support_paths:
420
- path.parent.mkdir(parents=True, exist_ok=True)
421
- path.write_text("transient\n", encoding="utf-8")
422
-
423
- before_count = _head_commit_count(tmp_path)
424
- result = commit_preflight_ready_changes(tmp_path, "B-001")
425
-
426
- assert result.attempted is True
427
- assert result.committed is True
428
- assert _head_commit_count(tmp_path) == before_count + 1
429
- assert _head_message(tmp_path) == "chore: ready for B-001"
430
- assert _head_files(tmp_path) == {
431
- *(path.relative_to(tmp_path).as_posix() for path in tracked_paths),
432
- visible_path.relative_to(tmp_path).as_posix(),
433
- }
434
- assert subprocess.run(
435
- ["git", "status", "--short", "--untracked-files=no"],
436
- cwd=tmp_path,
437
- check=True,
438
- stdout=subprocess.PIPE,
439
- text=True,
440
- ).stdout == ""
441
-
442
-
443
- def test_preflight_manifest_deletion_is_absent_from_task_branch_created_from_updated_head(tmp_path):
444
- from prizmkit_runtime.gitops import (
445
- BranchContext,
446
- branch_create_plan,
447
- branch_ensure_return,
448
- run_git_plan,
449
- )
450
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
451
-
452
- _init_bookkeeping_repo(tmp_path)
453
- manifest_path = _track_manifest(tmp_path)
454
- manifest_path.unlink()
455
-
456
- result = commit_preflight_ready_changes(tmp_path, "B-003")
457
- context = BranchContext("main", "bugfix/B-003-ready", tmp_path)
458
- setup = run_git_plan(tmp_path, branch_create_plan(context))
459
-
460
- assert result.committed is True
461
- assert setup.ok
462
- try:
463
- assert not manifest_path.exists()
464
- assert subprocess.run(
465
- ["git", "status", "--short", "--untracked-files=no"],
466
- cwd=tmp_path,
467
- check=True,
468
- stdout=subprocess.PIPE,
469
- text=True,
470
- ).stdout == ""
471
- finally:
472
- assert branch_ensure_return(tmp_path, "main", "bugfix/B-003-ready").ok
473
-
474
-
475
- def test_preflight_ready_commit_excludes_untracked_support_assets_and_state(tmp_path):
476
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
477
-
478
- _init_bookkeeping_repo(tmp_path)
479
- (tmp_path / "unstaged.txt").write_text("visible change\n", encoding="utf-8")
480
- hidden_paths = [
481
- tmp_path / ".claude" / "settings.json",
482
- tmp_path / ".codebuddy" / "skills" / "local.md",
483
- tmp_path / ".agents" / "skills" / "local.md",
484
- tmp_path / ".codex" / "config.toml",
485
- tmp_path / ".prizmkit" / "state" / "features" / "F-001" / "status.json",
486
- tmp_path / ".claude" / "worktrees" / "agent" / "scratch.txt",
487
- ]
488
- for path in hidden_paths:
489
- path.parent.mkdir(parents=True, exist_ok=True)
490
- path.write_text("hidden support\n", encoding="utf-8")
491
-
492
- result = commit_preflight_ready_changes(tmp_path, "F-124")
493
- committed_files = _head_files(tmp_path)
494
- hidden_status = subprocess.run(
495
- ["git", "status", "--porcelain", "--", ".claude", ".codebuddy", ".agents", ".codex", ".prizmkit/state"],
496
- cwd=tmp_path,
497
- check=True,
498
- stdout=subprocess.PIPE,
499
- text=True,
500
- ).stdout
501
-
502
- assert result.committed is True
503
- assert committed_files == {"unstaged.txt"}
504
- assert ".claude" in hidden_status or ".prizmkit/state" in hidden_status
505
-
506
-
507
- def test_preflight_ready_commit_rejects_unmerged_index(tmp_path):
508
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
509
-
510
- _init_bookkeeping_repo(tmp_path)
511
- subprocess.run(["git", "checkout", "-b", "other"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
512
- (tmp_path / "staged.txt").write_text("other\n", encoding="utf-8")
513
- subprocess.run(["git", "commit", "-am", "other"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
514
- subprocess.run(["git", "checkout", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
515
- (tmp_path / "staged.txt").write_text("main\n", encoding="utf-8")
516
- subprocess.run(["git", "commit", "-am", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
517
- subprocess.run(["git", "merge", "other"], cwd=tmp_path, check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
518
- before_count = _head_commit_count(tmp_path)
519
-
520
- result = commit_preflight_ready_changes(tmp_path, "F-126")
521
-
522
- assert result.attempted is True
523
- assert result.committed is False
524
- assert result.result is not None
525
- assert "unmerged Git paths" in result.result.stderr
526
- assert _head_commit_count(tmp_path) == before_count
527
-
528
-
529
- def test_preflight_ready_commit_rejects_conflict_markers_and_malformed_manifest(tmp_path):
530
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
531
-
532
- _init_bookkeeping_repo(tmp_path)
533
- (tmp_path / "unstaged.txt").write_text("<<<<<<< Updated upstream\ncurrent\n=======\nstashed\n>>>>>>> Stashed changes\n", encoding="utf-8")
534
-
535
- marker_result = commit_preflight_ready_changes(tmp_path, "F-127")
536
-
537
- assert marker_result.committed is False
538
- assert marker_result.result is not None
539
- assert "unresolved conflict markers" in marker_result.result.stderr
540
-
541
- (tmp_path / "unstaged.txt").write_text("safe\n", encoding="utf-8")
542
- manifest = tmp_path / ".prizmkit" / "manifest.json"
543
- manifest.parent.mkdir(parents=True, exist_ok=True)
544
- manifest.write_text("<<<<<<< Updated upstream\n{}\n", encoding="utf-8")
545
-
546
- manifest_result = commit_preflight_ready_changes(tmp_path, "F-128")
547
-
548
- assert manifest_result.committed is False
549
- assert manifest_result.result is not None
550
- assert ".prizmkit/manifest.json" in manifest_result.result.stderr
551
- assert "valid JSON" in manifest_result.result.stderr
552
-
553
-
554
- def test_preflight_ready_commit_noops_when_workspace_has_no_visible_dirty_content(tmp_path):
555
- from prizmkit_runtime.runner_bookkeeping import commit_preflight_ready_changes
556
-
557
- _init_bookkeeping_repo(tmp_path)
558
- (tmp_path / ".claude" / "worktrees" / "agent").mkdir(parents=True)
559
- (tmp_path / ".claude" / "worktrees" / "agent" / "scratch.txt").write_text("hidden only\n", encoding="utf-8")
560
- before_count = _head_commit_count(tmp_path)
561
-
562
- result = commit_preflight_ready_changes(tmp_path, "F-125")
563
-
564
- assert result.attempted is False
565
- assert result.committed is False
566
- assert _head_commit_count(tmp_path) == before_count
567
-
568
-
569
- @pytest.mark.parametrize(
570
- ("kind", "item_id", "branch"),
571
- [
572
- ("feature", "F-001", "dev/F-001-ready"),
573
- ("bugfix", "B-001", "bugfix/B-001-ready"),
574
- ],
575
- )
576
- def test_process_item_creates_one_ready_commit_before_branch_setup_for_all_families(
577
- monkeypatch,
578
- tmp_path,
579
- kind,
580
- item_id,
581
- branch,
582
- ):
583
- from prizmkit_runtime import runner_bookkeeping, runners
584
- from prizmkit_runtime.gitops import HIDDEN_TOOL_WORKTREE_EXCLUDES
585
- from prizmkit_runtime.runner_models import family_for, parse_invocation
586
-
587
- paths = _make_paths(tmp_path / kind)
588
- _init_bookkeeping_repo(paths.project_root)
589
- manifest_path = _track_manifest(paths.project_root)
590
- manifest_path.write_text('{"version":"ready"}\n', encoding="utf-8")
591
- (paths.project_root / "staged.txt").write_text("staged before run\n", encoding="utf-8")
592
- subprocess.run(["git", "add", "staged.txt"], cwd=paths.project_root, check=True)
593
- (paths.project_root / "unstaged.txt").write_text("unstaged before run\n", encoding="utf-8")
594
- (paths.project_root / "untracked.txt").write_text("untracked before run\n", encoding="utf-8")
595
- before_count = _head_commit_count(paths.project_root)
596
- branch_events = []
597
-
598
- monkeypatch.setenv("DEV_BRANCH", branch)
599
- family = family_for(kind, paths)
600
- invocation = parse_invocation(family, "run", ())
601
- invocation = invocation.__class__(**{**invocation.__dict__, "list_path": family.plan_path})
602
- _install_runner_session_fakes(monkeypatch, runners)
603
- monkeypatch.setattr(runners, "commit_preflight_ready_changes", runner_bookkeeping.commit_preflight_ready_changes)
604
-
605
- def fake_run_git_plan(project_root, plan):
606
- if plan.name == "branch_create":
607
- branch_events.append(
608
- {
609
- "commit_count": _head_commit_count(project_root),
610
- "message": _head_message(project_root),
611
- "manifest_content": subprocess.run(
612
- ["git", "show", "HEAD:.prizmkit/manifest.json"],
613
- cwd=project_root,
614
- check=True,
615
- stdout=subprocess.PIPE,
616
- text=True,
617
- ).stdout,
618
- "visible_status": subprocess.run(
619
- ["git", "status", "--porcelain", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES],
620
- cwd=project_root,
621
- check=True,
622
- stdout=subprocess.PIPE,
623
- text=True,
624
- ).stdout,
625
- }
626
- )
627
- return SimpleNamespace(ok=True, plan=plan, results=())
628
-
629
- monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
630
-
631
- status = runners._process_item(family, invocation, item_id, paths, initial_metadata={})
632
-
633
- assert status == "completed"
634
- assert branch_events == [
635
- {
636
- "commit_count": before_count + 1,
637
- "message": f"chore: ready for {item_id}",
638
- "manifest_content": '{"version":"ready"}\n',
639
- "visible_status": "",
640
- }
641
- ]
642
- assert _head_commit_count(paths.project_root) == before_count + 1
643
- assert {".prizmkit/manifest.json", "staged.txt", "unstaged.txt", "untracked.txt"}.issubset(
644
- _head_files(paths.project_root)
645
- )
646
-
647
-
648
-
649
- def test_process_item_ready_commit_uses_fallback_identity_before_branch_setup(monkeypatch, tmp_path):
650
- from prizmkit_runtime import runner_bookkeeping, runners
651
- from prizmkit_runtime.gitops import HIDDEN_TOOL_WORKTREE_EXCLUDES, PIPELINE_FALLBACK_GIT_EMAIL, PIPELINE_FALLBACK_GIT_NAME
652
- from prizmkit_runtime.runner_models import family_for, parse_invocation
653
-
654
- monkeypatch.setenv("GIT_CONFIG_GLOBAL", str(tmp_path / "missing-global-gitconfig"))
655
- monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
656
- for key in ("GIT_AUTHOR_NAME", "GIT_AUTHOR_EMAIL", "GIT_COMMITTER_NAME", "GIT_COMMITTER_EMAIL"):
657
- monkeypatch.delenv(key, raising=False)
658
- paths = _make_paths(tmp_path)
659
- _init_bookkeeping_repo(paths.project_root, configure_identity=False)
660
- (paths.project_root / "new-visible.txt").write_text("dirty before run\n", encoding="utf-8")
661
- before_count = _head_commit_count(paths.project_root)
662
- branch_events = []
663
-
664
- monkeypatch.setenv("DEV_BRANCH", "dev/F-001-ready-no-identity")
665
- family = family_for("feature", paths)
666
- invocation = parse_invocation(family, "run", ())
667
- invocation = invocation.__class__(**{**invocation.__dict__, "list_path": paths.feature_plan})
668
- _install_runner_session_fakes(monkeypatch, runners)
669
- monkeypatch.setattr(runners, "commit_preflight_ready_changes", runner_bookkeeping.commit_preflight_ready_changes)
670
-
671
- def fake_run_git_plan(project_root, plan):
672
- if plan.name == "branch_create":
673
- author = subprocess.run(
674
- ["git", "log", "-1", "--format=%an <%ae>"],
675
- cwd=project_root,
676
- check=True,
677
- stdout=subprocess.PIPE,
678
- text=True,
679
- ).stdout.strip()
680
- branch_events.append(
681
- {
682
- "commit_count": _head_commit_count(project_root),
683
- "message": _head_message(project_root),
684
- "author": author,
685
- "visible_status": subprocess.run(
686
- ["git", "status", "--porcelain", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES],
687
- cwd=project_root,
688
- check=True,
689
- stdout=subprocess.PIPE,
690
- text=True,
691
- ).stdout,
692
- }
693
- )
694
- return SimpleNamespace(ok=True, plan=plan, results=())
695
-
696
- monkeypatch.setattr(runners, "run_git_plan", fake_run_git_plan)
697
-
698
- status = runners._process_item(family, invocation, "F-001", paths, initial_metadata={})
699
-
700
- assert status == "completed"
701
- assert branch_events == [
702
- {
703
- "commit_count": before_count + 1,
704
- "message": "chore: ready for F-001",
705
- "author": f"{PIPELINE_FALLBACK_GIT_NAME} <{PIPELINE_FALLBACK_GIT_EMAIL}>",
706
- "visible_status": "",
707
- }
708
- ]
709
- assert "new-visible.txt" in _head_files(paths.project_root)
710
-
711
-
712
- def test_bookkeeping_commits_only_runner_owned_paths(tmp_path):
713
- from prizmkit_runtime.runner_bookkeeping import commit_final_bookkeeping
714
- from prizmkit_runtime.runner_models import RunnerFamily
715
-
716
- subprocess.run(["git", "init", "-b", "main"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
717
- subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, check=True)
718
- subprocess.run(["git", "config", "user.name", "Test"], cwd=tmp_path, check=True)
719
- plans = tmp_path / ".prizmkit" / "plans"
720
- state = tmp_path / ".prizmkit" / "state" / "features"
721
- item_state = state / "F-001"
722
- plans.mkdir(parents=True)
723
- item_state.mkdir(parents=True)
724
- plan = plans / "feature-list.json"
725
- plan.write_text('{"features": []}', encoding="utf-8")
726
- (item_state / "status.json").write_text(json.dumps({"completion_notes": ["Completed durable workflow"]}), encoding="utf-8")
727
- source = tmp_path / "src.txt"
728
- source.write_text("base", encoding="utf-8")
729
- subprocess.run(["git", "add", ".prizmkit/plans/feature-list.json", ".prizmkit/state/features/F-001/status.json", "src.txt"], cwd=tmp_path, check=True)
730
- subprocess.run(["git", "commit", "-m", "base"], cwd=tmp_path, check=True, stdout=subprocess.DEVNULL)
731
- plan.write_text('{"features": [{"id": "F-001", "status": "completed"}]}', encoding="utf-8")
732
- (item_state / "status.json").write_text('{"last_session_id": "s1"}', encoding="utf-8")
733
- source.write_text("dirty source change", encoding="utf-8")
734
- family = RunnerFamily(
735
- kind="feature",
736
- id_prefix="F-",
737
- list_key="features",
738
- list_arg="--feature-list",
739
- item_id_arg="--feature-id",
740
- state_dir=state,
741
- plan_path=plan,
742
- updater_script=tmp_path / "update-feature-status.py",
743
- prompt_script=tmp_path / "generate-bootstrap-prompt.py",
744
- branch_prefix="dev",
745
- artifact_root_name="specs",
746
- )
747
-
748
- result = commit_final_bookkeeping(tmp_path, family, "F-001", "completed")
749
- committed_files = subprocess.run(
750
- ["git", "show", "--name-only", "--format=", "HEAD"],
751
- cwd=tmp_path,
752
- check=True,
753
- stdout=subprocess.PIPE,
754
- text=True,
755
- ).stdout.splitlines()
756
- dirty_files = subprocess.run(
757
- ["git", "status", "--porcelain", "--", "src.txt"],
758
- cwd=tmp_path,
759
- check=True,
760
- stdout=subprocess.PIPE,
761
- text=True,
762
- ).stdout
763
-
764
- assert result.committed is True
765
- assert committed_files == [".prizmkit/plans/feature-list.json", ".prizmkit/state/features/F-001/status.json"]
766
- assert dirty_files.startswith(" M src.txt")