-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_batch_resilience.py
More file actions
696 lines (564 loc) · 26.2 KB
/
Copy pathtest_batch_resilience.py
File metadata and controls
696 lines (564 loc) · 26.2 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
# SPDX-License-Identifier: MIT
# Copyright 2026 SharedIntellect — https://github.com/SharedIntellect/quorum
"""Tests for crash-resilient batch validation: progressive saves, resume, signal handling."""
from __future__ import annotations
import json
import os
import signal
import threading
import time
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
from quorum.config import QuorumConfig
from quorum.models import (
AggregatedReport,
BatchVerdict,
CriticResult,
FileResult,
Verdict,
VerdictStatus,
)
from quorum.pipeline import (
_aggregate_batch,
_write_json_atomic,
resolve_targets,
resume_batch_validation,
run_batch_validation,
)
# ── Fixtures ──────────────────────────────────────────────────────────────────
@pytest.fixture
def quick_config() -> QuorumConfig:
return QuorumConfig(
critics=["correctness"],
model_tier1="m1",
model_tier2="m2",
depth_profile="quick",
enable_prescreen=False,
)
def _make_verdict(status: VerdictStatus = VerdictStatus.PASS) -> Verdict:
return Verdict(
status=status,
reasoning="test",
confidence=0.9,
report=AggregatedReport(findings=[], confidence=0.9),
)
def _make_file_result(path: str, status: VerdictStatus = VerdictStatus.PASS) -> FileResult:
return FileResult(
file_path=path,
verdict=_make_verdict(status),
run_dir="/tmp/run",
)
def _setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider):
"""Wire up the three pipeline mocks to return a passing verdict."""
mock_provider = MagicMock()
MockProvider.return_value = mock_provider
cr = CriticResult(critic_name="correctness", findings=[], confidence=0.9, runtime_ms=50)
MockSupervisor.return_value.run = MagicMock(return_value=[cr])
verdict = _make_verdict()
MockAggregator.return_value.run = MagicMock(return_value=verdict)
# ── 1. Atomic writes ──────────────────────────────────────────────────────────
class TestAtomicWrites:
def test_writes_valid_json(self, tmp_path):
path = tmp_path / "out.json"
_write_json_atomic(path, {"key": "value", "num": 42})
data = json.loads(path.read_text())
assert data == {"key": "value", "num": 42}
def test_no_tmp_file_left_on_success(self, tmp_path):
path = tmp_path / "out.json"
_write_json_atomic(path, {"ok": True})
assert not (tmp_path / "out.tmp").exists()
def test_overwrites_existing(self, tmp_path):
path = tmp_path / "out.json"
_write_json_atomic(path, {"v": 1})
_write_json_atomic(path, {"v": 2})
assert json.loads(path.read_text())["v"] == 2
def test_creates_parent_dirs(self, tmp_path):
path = tmp_path / "a" / "b" / "c.json"
_write_json_atomic(path, {"nested": True})
assert path.exists()
def test_result_is_always_valid_json(self, tmp_path):
"""Even after many rapid overwrites, the file must always parse as JSON."""
path = tmp_path / "manifest.json"
for i in range(20):
_write_json_atomic(path, {"count": i, "data": "x" * 100})
content = path.read_text()
parsed = json.loads(content) # must not raise
assert parsed["count"] == i
# ── 2. Progressive manifest ───────────────────────────────────────────────────
class TestProgressiveManifest:
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_initial_manifest_written_before_files_complete(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
"""batch-manifest.json must exist with status='running' before any file finishes."""
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
test_dir = tmp_path / "input"
test_dir.mkdir()
manifests_seen: list[dict] = []
original_validate = None
def spy_validate(*args, **kwargs):
# Read manifest while a file is "in flight"
manifest_path = tmp_path / "runs" / "batch-manifest.json"
# Find the manifest by scanning for any batch-* dir
for p in (tmp_path / "runs").glob("batch-*/batch-manifest.json"):
try:
manifests_seen.append(json.loads(p.read_text()))
except (json.JSONDecodeError, OSError):
pass # manifest may be partially written during race
return original_validate(*args, **kwargs)
# Create 3 files
for i in range(3):
(test_dir / f"file{i}.md").write_text(f"# File {i}\n")
run_batch_validation(
target=test_dir,
pattern="*.md",
config=quick_config,
runs_dir=tmp_path / "runs",
)
# After completion the final manifest must be completed
batch_dirs = list((tmp_path / "runs").glob("batch-*"))
assert batch_dirs, "No batch directory created"
manifest = json.loads((batch_dirs[0] / "batch-manifest.json").read_text())
assert manifest["status"] == "completed"
assert manifest["total_files"] == 3
assert len(manifest["completed_files"]) == 3
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_manifest_has_completed_files_list(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
test_dir = tmp_path / "input"
test_dir.mkdir()
for i in range(5):
(test_dir / f"f{i}.md").write_text(f"# {i}\n")
run_batch_validation(
target=test_dir,
pattern="*.md",
config=quick_config,
runs_dir=tmp_path / "runs",
)
batch_dirs = list((tmp_path / "runs").glob("batch-*"))
manifest = json.loads((batch_dirs[0] / "batch-manifest.json").read_text())
assert "completed_files" in manifest
assert len(manifest["completed_files"]) == 5
for entry in manifest["completed_files"]:
assert "file" in entry
assert "run_dir" in entry
assert "verdict" in entry
assert "completed_at" in entry
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_manifest_progressive_update_after_each_file(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
"""Verify the manifest 'validated' count grows as files complete."""
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
snapshots: list[int] = []
original_write_atomic = None
import quorum.pipeline as _pipeline_mod
original_write_atomic = _pipeline_mod._write_json_atomic
def capturing_write_atomic(path: Path, data: dict) -> None:
original_write_atomic(path, data)
if path.name == "batch-manifest.json" and data.get("status") == "running":
snapshots.append(data.get("validated", 0))
test_dir = tmp_path / "input"
test_dir.mkdir()
for i in range(4):
(test_dir / f"f{i}.md").write_text(f"# {i}\n")
with patch.object(_pipeline_mod, "_write_json_atomic", side_effect=capturing_write_atomic):
run_batch_validation(
target=test_dir,
pattern="*.md",
config=quick_config,
runs_dir=tmp_path / "runs",
)
# Should have seen at least 1 intermediate snapshot
assert len(snapshots) >= 1
# Each snapshot must be <= 4
assert all(0 <= s <= 4 for s in snapshots)
# ── 3. Resume capability ──────────────────────────────────────────────────────
class TestResumeBatchValidation:
def _build_completed_run_dir(self, batch_dir: Path, file_path: Path) -> Path:
"""Create a fake per-file run directory with a verdict.json."""
run_dir = batch_dir / "per-file" / f"run-{file_path.stem}"
run_dir.mkdir(parents=True, exist_ok=True)
verdict = _make_verdict(VerdictStatus.PASS)
(run_dir / "verdict.json").write_text(
json.dumps(verdict.model_dump(), default=str), encoding="utf-8"
)
return run_dir
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_resume_skips_completed_files(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
"""Resume should only validate the 2 remaining files out of 5."""
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
# Create 5 files
input_dir = tmp_path / "input"
input_dir.mkdir()
files = []
for i in range(5):
f = input_dir / f"file{i}.md"
f.write_text(f"# File {i}\n")
files.append(f)
# Set up a partial batch directory: 3/5 complete
batch_dir = tmp_path / "runs" / "batch-test"
batch_dir.mkdir(parents=True)
completed = []
for f in files[:3]:
run_dir = self._build_completed_run_dir(batch_dir, f)
completed.append({
"file": str(f),
"run_dir": str(run_dir),
"verdict": "PASS",
"completed_at": "2026-03-09T00:00:00+00:00",
})
_write_json_atomic(batch_dir / "batch-manifest.json", {
"target": str(input_dir),
"pattern": "*.md",
"depth": "quick",
"rubric": None,
"total_files": 5,
"validated": 3,
"errors": 0,
"started_at": "2026-03-09T00:00:00+00:00",
"status": "interrupted",
"completed_files": completed,
"failed_files": [],
})
validated_files: list[str] = []
original_validate_one = None
import quorum.pipeline as _pipeline_mod
original_validate_one = _pipeline_mod._validate_one_file
def spy_validate_one(file_path, *args, **kwargs):
validated_files.append(str(file_path))
return original_validate_one(file_path, *args, **kwargs)
with patch.object(_pipeline_mod, "_validate_one_file", side_effect=spy_validate_one):
batch_verdict, out_dir = resume_batch_validation(batch_dir=batch_dir)
# Only the 2 remaining files should have been validated
assert len(validated_files) == 2
for vf in validated_files:
assert vf not in {str(f) for f in files[:3]}
assert batch_verdict.total_files == 5
assert isinstance(batch_verdict, BatchVerdict)
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_resume_final_manifest_status_completed(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
"""After a successful resume, manifest status must be 'completed'."""
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
input_dir = tmp_path / "input"
input_dir.mkdir()
files = []
for i in range(3):
f = input_dir / f"file{i}.md"
f.write_text(f"# {i}\n")
files.append(f)
batch_dir = tmp_path / "runs" / "batch-resume-test"
batch_dir.mkdir(parents=True)
# 1 of 3 already done
run_dir_0 = self._build_completed_run_dir(batch_dir, files[0])
_write_json_atomic(batch_dir / "batch-manifest.json", {
"target": str(input_dir),
"pattern": "*.md",
"depth": "quick",
"rubric": None,
"total_files": 3,
"validated": 1,
"errors": 0,
"started_at": "2026-03-09T00:00:00+00:00",
"status": "interrupted",
"completed_files": [{
"file": str(files[0]),
"run_dir": str(run_dir_0),
"verdict": "PASS",
"completed_at": "2026-03-09T00:00:00+00:00",
}],
"failed_files": [],
})
resume_batch_validation(batch_dir=batch_dir)
manifest = json.loads((batch_dir / "batch-manifest.json").read_text())
assert manifest["status"] == "completed"
assert manifest["validated"] == 3
def test_resume_nonexistent_dir_raises(self, tmp_path):
with pytest.raises(FileNotFoundError):
resume_batch_validation(batch_dir=tmp_path / "nonexistent")
def test_resume_corrupted_manifest_raises(self, tmp_path):
batch_dir = tmp_path / "batch-bad"
batch_dir.mkdir()
(batch_dir / "batch-manifest.json").write_text("NOT JSON {{{{", encoding="utf-8")
with pytest.raises(ValueError, match="Corrupted"):
resume_batch_validation(batch_dir=batch_dir)
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_resume_revalidates_crashed_per_file_dir(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
"""A run_dir that exists on disk but has no verdict.json must be re-validated."""
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
input_dir = tmp_path / "input"
input_dir.mkdir()
files = []
for i in range(3):
f = input_dir / f"file{i}.md"
f.write_text(f"# {i}\n")
files.append(f)
batch_dir = tmp_path / "runs" / "batch-crash"
batch_dir.mkdir(parents=True)
# file0 has a valid run_dir with verdict.json
run_dir_0 = self._build_completed_run_dir(batch_dir, files[0])
# file1 has a run_dir BUT no verdict.json (crashed during validation)
crashed_run_dir = batch_dir / "per-file" / "run-crashed"
crashed_run_dir.mkdir(parents=True)
# No verdict.json here — crash mid-validation
_write_json_atomic(batch_dir / "batch-manifest.json", {
"target": str(input_dir),
"pattern": "*.md",
"depth": "quick",
"rubric": None,
"total_files": 3,
"validated": 2,
"errors": 0,
"started_at": "2026-03-09T00:00:00+00:00",
"status": "interrupted",
"completed_files": [
{
"file": str(files[0]),
"run_dir": str(run_dir_0),
"verdict": "PASS",
"completed_at": "2026-03-09T00:00:00+00:00",
},
{
"file": str(files[1]),
"run_dir": str(crashed_run_dir), # no verdict.json
"verdict": "PASS",
"completed_at": "2026-03-09T00:00:00+00:00",
},
],
"failed_files": [],
})
validated_files: list[str] = []
import quorum.pipeline as _pipeline_mod
original = _pipeline_mod._validate_one_file
def spy(file_path, *args, **kwargs):
validated_files.append(str(file_path))
return original(file_path, *args, **kwargs)
with patch.object(_pipeline_mod, "_validate_one_file", side_effect=spy):
resume_batch_validation(batch_dir=batch_dir)
# file1 (crashed) + file2 (never started) must be re-validated; file0 skipped
assert str(files[0]) not in validated_files
assert str(files[1]) in validated_files
assert str(files[2]) in validated_files
# ── 4. Signal handling ────────────────────────────────────────────────────────
class TestSignalHandling:
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_sigint_sets_interrupted_status(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
"""Send SIGINT mid-batch and verify manifest ends up with status='interrupted'."""
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
input_dir = tmp_path / "input"
input_dir.mkdir()
for i in range(6):
(input_dir / f"f{i}.md").write_text(f"# {i}\n")
import quorum.pipeline as _pipeline_mod
files_started = threading.Event()
original_validate_one = _pipeline_mod._validate_one_file
def slow_validate(file_path, *args, **kwargs):
files_started.set()
# Brief delay to keep the batch running while we send the signal
time.sleep(0.05)
return original_validate_one(file_path, *args, **kwargs)
batch_dir_holder: list[Path] = []
original_run_batch = run_batch_validation
def run_and_signal():
# Wait until at least one file has started, then send SIGINT
files_started.wait(timeout=5)
os.kill(os.getpid(), signal.SIGINT)
signal_thread = threading.Thread(target=run_and_signal, daemon=True)
with patch.object(_pipeline_mod, "_validate_one_file", side_effect=slow_validate):
signal_thread.start()
try:
batch_verdict, batch_dir = run_batch_validation(
target=input_dir,
pattern="*.md",
config=quick_config,
runs_dir=tmp_path / "runs",
)
except SystemExit:
pass # SIGINT may propagate as SystemExit in some contexts
batch_dir_holder.append(batch_dir)
signal_thread.join(timeout=3)
# Find the batch directory
batch_dirs = list((tmp_path / "runs").glob("batch-*"))
if not batch_dirs and batch_dir_holder:
batch_dirs = batch_dir_holder
assert batch_dirs, "No batch directory found"
bd = batch_dirs[0]
manifest = json.loads((bd / "batch-manifest.json").read_text())
assert manifest["status"] == "interrupted"
def test_stop_event_prevents_new_submissions(self, tmp_path, quick_config):
"""Verify that after stop_event is set, remaining files are cancelled."""
# This is a unit test on the stop logic via the _stop_event mechanism
# We verify via the manifest that fewer than all files complete
import quorum.pipeline as _pipeline_mod
input_dir = tmp_path / "input"
input_dir.mkdir()
for i in range(10):
(input_dir / f"f{i}.md").write_text(f"# {i}\n")
call_count = 0
original_validate_one = _pipeline_mod._validate_one_file
def counting_validate(file_path, *args, **kwargs):
nonlocal call_count
call_count += 1
if call_count == 2:
# Simulate an external stop after 2 files
os.kill(os.getpid(), signal.SIGINT)
time.sleep(0.02)
return original_validate_one(file_path, *args, **kwargs)
with patch("quorum.pipeline.LiteLLMProvider"), \
patch("quorum.pipeline.AggregatorAgent") as MockAgg, \
patch("quorum.pipeline.SupervisorAgent") as MockSup:
cr = CriticResult(critic_name="correctness", findings=[], confidence=0.9, runtime_ms=50)
MockSup.return_value.run = MagicMock(return_value=[cr])
verdict = _make_verdict()
MockAgg.return_value.run = MagicMock(return_value=verdict)
with patch.object(_pipeline_mod, "_validate_one_file", side_effect=counting_validate):
try:
_, batch_dir = run_batch_validation(
target=input_dir,
pattern="*.md",
config=quick_config,
runs_dir=tmp_path / "runs",
)
except SystemExit:
batch_dir = list((tmp_path / "runs").glob("batch-*"))[0]
manifest = json.loads((batch_dir / "batch-manifest.json").read_text())
# Must be interrupted and fewer than 10 files completed
assert manifest["status"] == "interrupted"
assert manifest["validated"] < 10
# ── 5. Progressive batch report ───────────────────────────────────────────────
class TestProgressiveBatchReport:
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_batch_report_created_before_completion(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
"""batch-report.md must exist with a header row immediately."""
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
input_dir = tmp_path / "input"
input_dir.mkdir()
for i in range(3):
(input_dir / f"f{i}.md").write_text(f"# {i}\n")
_, batch_dir = run_batch_validation(
target=input_dir,
pattern="*.md",
config=quick_config,
runs_dir=tmp_path / "runs",
)
report_path = batch_dir / "batch-report.md"
assert report_path.exists()
content = report_path.read_text()
assert "# Quorum Batch Validation Report" in content
assert "Per-File Summary" in content
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_batch_report_contains_aggregate_section(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
input_dir = tmp_path / "input"
input_dir.mkdir()
for i in range(2):
(input_dir / f"f{i}.md").write_text(f"# {i}\n")
_, batch_dir = run_batch_validation(
target=input_dir,
pattern="*.md",
config=quick_config,
runs_dir=tmp_path / "runs",
)
content = (batch_dir / "batch-report.md").read_text()
assert "Batch Verdict:" in content
assert "Aggregate Findings" in content
# ── 6. Manifest always valid JSON ─────────────────────────────────────────────
class TestManifestIntegrity:
@patch("quorum.pipeline.LiteLLMProvider")
@patch("quorum.pipeline.AggregatorAgent")
@patch("quorum.pipeline.SupervisorAgent")
def test_manifest_always_parseable(
self, MockSupervisor, MockAggregator, MockProvider, quick_config, tmp_path
):
"""Every version of batch-manifest.json written must be valid JSON."""
_setup_mock_pipeline(MockSupervisor, MockAggregator, MockProvider)
input_dir = tmp_path / "input"
input_dir.mkdir()
for i in range(4):
(input_dir / f"f{i}.md").write_text(f"# {i}\n")
import quorum.pipeline as _pipeline_mod
snapshots: list[str] = []
original = _pipeline_mod._write_json_atomic
def capturing(path: Path, data: dict) -> None:
original(path, data)
if path.name == "batch-manifest.json":
try:
snapshots.append(path.read_text())
except OSError:
pass
with patch.object(_pipeline_mod, "_write_json_atomic", side_effect=capturing):
run_batch_validation(
target=input_dir,
pattern="*.md",
config=quick_config,
runs_dir=tmp_path / "runs",
)
assert snapshots, "No manifest snapshots captured"
for i, snap in enumerate(snapshots):
parsed = json.loads(snap) # must not raise
assert "status" in parsed, f"Snapshot {i} missing 'status'"
def test_initial_manifest_written_immediately(self, tmp_path, quick_config):
"""The manifest exists on disk even before the first file finishes."""
import quorum.pipeline as _pipeline_mod
input_dir = tmp_path / "input"
input_dir.mkdir()
for i in range(3):
(input_dir / f"f{i}.md").write_text(f"# {i}\n")
manifest_exists_during_run = threading.Event()
batch_dir_holder: list[Path] = []
original_validate = _pipeline_mod._validate_one_file
def spy_validate(file_path, index, total, *args, **kwargs):
# On first file, check that manifest already exists
if index == 1:
for p in (tmp_path / "runs").glob("batch-*/batch-manifest.json"):
manifest_exists_during_run.set()
return original_validate(file_path, index, total, *args, **kwargs)
with patch("quorum.pipeline.LiteLLMProvider"), \
patch("quorum.pipeline.AggregatorAgent") as MockAgg, \
patch("quorum.pipeline.SupervisorAgent") as MockSup, \
patch.object(_pipeline_mod, "_validate_one_file", side_effect=spy_validate):
cr = CriticResult(critic_name="correctness", findings=[], confidence=0.9, runtime_ms=50)
MockSup.return_value.run = MagicMock(return_value=[cr])
MockAgg.return_value.run = MagicMock(return_value=_make_verdict())
_, batch_dir = run_batch_validation(
target=input_dir,
pattern="*.md",
config=quick_config,
runs_dir=tmp_path / "runs",
)
assert manifest_exists_during_run.is_set(), (
"batch-manifest.json was not on disk before the first file finished"
)