-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_make_helpers.py
More file actions
717 lines (666 loc) · 22.4 KB
/
test_make_helpers.py
File metadata and controls
717 lines (666 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
#!/usr/bin/env python3
import shutil
import subprocess
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
class MakeHelpersTests(unittest.TestCase):
def test_helper_sources_under_dash(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
["dash", "-c", ". scripts/make_helpers.sh"],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
def test_run_agent_enables_multi_agent_for_codex(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"codex() { printf '%s\\n' \"$@\"; }; "
"RUNNER=codex CODEX_MODEL=test-model "
"run_agent /dev/null 'test prompt'"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"exec",
"--enable",
"multi_agent",
"-m",
"test-model",
"-s",
"danger-full-access",
"test prompt",
],
)
def test_skill_prompt_with_context_appends_json_for_codex(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"RUNNER=codex "
"skill_prompt_with_context review-pipeline '/review-pipeline 570' "
"'process PR #570' 'Selected queue item' '{\"pr_number\":570}'"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertIn("Use the repo-local skill", proc.stdout)
self.assertIn("Selected queue item", proc.stdout)
self.assertIn('{"pr_number":570}', proc.stdout)
def test_skill_prompt_with_context_keeps_claude_slash_command_clean(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"RUNNER=claude "
"skill_prompt_with_context review-pipeline '/review-pipeline 570' "
"'process PR #570' 'Selected queue item' '{\"pr_number\":570}'"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(proc.stdout.strip(), "/review-pipeline 570")
def test_poll_project_items_uses_pipeline_board_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"poll_project_items ready /tmp/state.json"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_board.py",
"next",
"ready",
"/tmp/state.json",
"--format",
"text",
"--repo-root",
".",
],
)
def test_move_board_item_uses_pipeline_board_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"move_board_item PVTI_demo final-review"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_board.py",
"move",
"PVTI_demo",
"final-review",
],
)
def test_claim_project_items_uses_pipeline_board_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"claim_project_items ready /tmp/state.json"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_board.py",
"claim-next",
"ready",
"/tmp/state.json",
"--format",
"json",
"--repo-root",
".",
],
)
def test_make_board_next_final_review_passes_repo(self) -> None:
proc = subprocess.run(
[
"make",
"-n",
"board-next",
"MODE=final-review",
"REPO=CodingThrust/problem-reductions",
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertIn(
'poll_project_items "final-review" "$state_file" "$repo"',
proc.stdout,
)
def test_make_board_next_review_forwards_number_and_format(self) -> None:
proc = subprocess.run(
[
"make",
"-n",
"board-next",
"MODE=review",
"REPO=CodingThrust/problem-reductions",
"NUMBER=570",
"FORMAT=json",
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertIn(
'poll_project_items "review" "$state_file" "$repo" "570" "json"',
proc.stdout,
)
def test_make_board_claim_review_forwards_repo_number_and_format(self) -> None:
proc = subprocess.run(
[
"make",
"-n",
"board-claim",
"MODE=review",
"REPO=CodingThrust/problem-reductions",
"NUMBER=570",
"FORMAT=json",
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertIn(
'claim_project_items "review" "$state_file" "$repo" "570" "json"',
proc.stdout,
)
def test_board_next_json_uses_scripted_json_poll(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"board_next_json review CodingThrust/problem-reductions 570 /tmp/review.json"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_board.py",
"next",
"review",
"/tmp/review.json",
"--format",
"json",
"--repo",
"CodingThrust/problem-reductions",
"--number",
"570",
],
)
def test_board_claim_json_uses_scripted_json_claim(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"board_claim_json review CodingThrust/problem-reductions 570 /tmp/review.json"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_board.py",
"claim-next",
"review",
"/tmp/review.json",
"--format",
"json",
"--repo",
"CodingThrust/problem-reductions",
"--number",
"570",
],
)
def test_review_pipeline_context_uses_skill_bundle_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"review_pipeline_context CodingThrust/problem-reductions 570"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_skill_context.py",
"review-pipeline",
"--repo",
"CodingThrust/problem-reductions",
"--format",
"json",
"--pr",
"570",
],
)
def test_make_run_review_uses_skill_bundle_context(self) -> None:
proc = subprocess.run(
["make", "-n", "run-review"],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertIn('review_pipeline_context "$repo"', proc.stdout)
self.assertIn('skill_prompt_with_context review-pipeline', proc.stdout)
def test_make_run_pipeline_uses_scripted_board_selection(self) -> None:
proc = subprocess.run(
["make", "-n", "run-pipeline"],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertIn('board_next_json ready "" "" "$tmp_state"', proc.stdout)
self.assertIn('skill_prompt_with_context project-pipeline', proc.stdout)
def test_watch_and_dispatch_uses_persistent_default_state_file(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"poll_project_items() { printf 'state:%s\\n' \"$2\" >&2; return 2; }; "
"watch_and_dispatch ready run-pipeline 'Ready issues'"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 2, proc.stderr)
self.assertIn(
"state:/tmp/problemreductions-ready-forever-state.json",
proc.stderr,
)
def test_watch_and_dispatch_sleeps_after_successful_dispatch(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"flag=/tmp/test-watch-and-dispatch-$$; "
"rm -f \"$flag\"; "
"date() { printf '2026-03-16 00:00:00'; }; "
"poll_project_items() { "
" if [ ! -f \"$flag\" ]; then : > \"$flag\"; printf 'PVTI_1\\t42\\n'; return 0; fi; "
" return 2; "
"}; "
"make() { printf 'make:%s %s\\n' \"$1\" \"$2\"; return 0; }; "
"ack_polled_item() { printf 'ack:%s\\n' \"$2\"; }; "
"sleep() { printf 'sleep:%s\\n' \"$1\"; return 0; }; "
"MAKE=make POLL_INTERVAL=600 "
"watch_and_dispatch ready run-pipeline 'Ready issues'"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 2, proc.stderr)
self.assertIn("make:run-pipeline N=42", proc.stdout)
self.assertIn("ack:PVTI_1", proc.stdout)
self.assertIn("sleep:600", proc.stdout)
def test_watch_and_dispatch_calls_poll_with_correct_args(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"state_tmp=$(mktemp); "
'printf \'{"pending":["a","b"],"visible":{}}\' > "$state_tmp"; '
"poll_project_items() { printf 'mode:%s state:%s\\n' \"$1\" \"$2\" >&2; return 2; }; "
"STATE_FILE=\"$state_tmp\" "
"watch_and_dispatch ready run-pipeline 'Ready issues'"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 2, proc.stderr)
self.assertIn("mode:ready state:", proc.stderr)
def test_watch_and_dispatch_handles_missing_state_file(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"poll_project_items() { printf 'mode:%s\\n' \"$1\" >&2; return 2; }; "
"STATE_FILE=/tmp/nonexistent-state-$$.json "
"watch_and_dispatch ready run-pipeline 'Ready issues'"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 2, proc.stderr)
self.assertIn("mode:ready", proc.stderr)
def test_pr_snapshot_uses_pipeline_pr_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"pr_snapshot CodingThrust/problem-reductions 570"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_pr.py",
"snapshot",
"--repo",
"CodingThrust/problem-reductions",
"--pr",
"570",
"--format",
"json",
],
)
def test_issue_guards_uses_pipeline_checks_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"issue_guards CodingThrust/problem-reductions 117 /tmp/repo"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_checks.py",
"issue-guards",
"--repo",
"CodingThrust/problem-reductions",
"--issue",
"117",
"--repo-root",
"/tmp/repo",
"--format",
"json",
],
)
def test_pr_wait_ci_uses_pipeline_pr_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"pr_wait_ci CodingThrust/problem-reductions 570 1200 15"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_pr.py",
"wait-ci",
"--repo",
"CodingThrust/problem-reductions",
"--pr",
"570",
"--timeout",
"1200",
"--interval",
"15",
"--format",
"json",
],
)
def test_issue_context_uses_pipeline_checks_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"issue_context CodingThrust/problem-reductions 117 /tmp/repo"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_checks.py",
"issue-context",
"--repo",
"CodingThrust/problem-reductions",
"--issue",
"117",
"--repo-root",
"/tmp/repo",
"--format",
"json",
],
)
def test_make_issue_context_uses_shared_helper(self) -> None:
proc = subprocess.run(
[
"make",
"-n",
"issue-context",
"ISSUE=117",
"REPO=CodingThrust/problem-reductions",
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertIn(
'issue_context "$repo" "117"',
proc.stdout,
)
def test_create_issue_worktree_uses_pipeline_worktree_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"create_issue_worktree 117 graph-partitioning origin/main"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_worktree.py",
"create-issue",
"--issue",
"117",
"--slug",
"graph-partitioning",
"--base",
"origin/main",
"--format",
"json",
],
)
def test_checkout_pr_worktree_uses_pipeline_worktree_cli(self) -> None:
if shutil.which("dash") is None:
self.skipTest("dash is not installed")
proc = subprocess.run(
[
"dash",
"-c",
(
". scripts/make_helpers.sh; "
"python3() { printf '%s\\n' \"$@\"; }; "
"checkout_pr_worktree CodingThrust/problem-reductions 570"
),
],
cwd=REPO_ROOT,
capture_output=True,
text=True,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertEqual(
proc.stdout.splitlines(),
[
"scripts/pipeline_worktree.py",
"checkout-pr",
"--repo",
"CodingThrust/problem-reductions",
"--pr",
"570",
"--format",
"json",
],
)
if __name__ == "__main__":
unittest.main()