-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validate.py
More file actions
650 lines (581 loc) · 26 KB
/
test_validate.py
File metadata and controls
650 lines (581 loc) · 26 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
"""Tests for orchestrator.validate — design and execution validation gates."""
import json
from pathlib import Path
import pytest
import yaml
from orchestrator.validate import validate_design, validate_execution, _check_unexpected_files
VALID_BUNDLE = {
"metadata": {"iteration": 1, "family": "test", "research_question": "Does X work?"},
"arms": [
{"type": "h-main", "prediction": "+20%", "mechanism": "cause", "diagnostic": "check"},
{"type": "h-control-negative", "prediction": "no effect", "mechanism": "none", "diagnostic": "check"},
],
}
VALID_BUNDLE_WITH_CODE = {
"metadata": {"iteration": 1, "family": "test", "research_question": "Does X work?"},
"arms": [
{
"type": "h-main", "prediction": "+20%", "mechanism": "cause", "diagnostic": "check",
"code_changes": [{"file": "src/engine.go", "intent": "enable batch mode", "rationale": "test"}],
},
{"type": "h-control-negative", "prediction": "no effect", "mechanism": "none", "diagnostic": "check"},
],
}
VALID_FINDINGS = {
"iteration": 1,
"bundle_ref": "runs/iter-1/bundle.yaml",
"arms": [
{"arm_type": "h-main", "predicted": "+20%", "observed": "+22%",
"status": "CONFIRMED", "error_type": None, "diagnostic_note": None},
],
"experiment_valid": True,
"discrepancy_analysis": "All confirmed.",
"dominant_component_pct": None,
}
VALID_PLAN = {
"metadata": {"iteration": 1, "bundle_ref": "runs/iter-1/bundle.yaml"},
"arms": [
{"arm_id": "h-main", "conditions": [
{"name": "baseline", "cmd": "echo baseline"},
]},
],
}
VALID_PRINCIPLES = [
{
"id": "RP-1", "statement": "X works", "confidence": "high",
"regime": "all", "evidence": ["iter-1"], "contradicts": [],
"extraction_iteration": 1, "mechanism": "cause",
"applicability_bounds": "test", "superseded_by": None,
"category": "domain", "status": "active",
},
]
def _setup_design(d: Path) -> None:
d.mkdir(parents=True, exist_ok=True)
(d / "problem.md").write_text("## Research Question\nDoes X work?\n")
(d / "bundle.yaml").write_text(yaml.safe_dump(VALID_BUNDLE))
(d / "handoff_snapshot.md").write_text("## Handoff\n### Goal\nTest X.\n")
def _setup_execution(d: Path, bundle: dict | None = None) -> None:
d.mkdir(parents=True, exist_ok=True)
(d / "bundle.yaml").write_text(yaml.safe_dump(bundle or VALID_BUNDLE))
(d / "experiment_plan.yaml").write_text(yaml.safe_dump(VALID_PLAN))
(d / "findings.json").write_text(json.dumps(VALID_FINDINGS, indent=2))
(d / "principle_updates.json").write_text(json.dumps(VALID_PRINCIPLES, indent=2))
class TestValidateDesign:
def test_pass(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_design(d)
result = validate_design(d)
assert result["status"] == "pass"
def test_missing_problem(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_design(d)
(d / "problem.md").unlink()
result = validate_design(d)
assert result["status"] == "fail"
assert any("problem.md" in e for e in result["errors"])
def test_empty_problem(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_design(d)
(d / "problem.md").write_text("")
result = validate_design(d)
assert result["status"] == "fail"
assert any("empty" in e for e in result["errors"])
def test_missing_bundle(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_design(d)
(d / "bundle.yaml").unlink()
result = validate_design(d)
assert result["status"] == "fail"
assert any("bundle.yaml" in e for e in result["errors"])
def test_invalid_bundle_schema(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_design(d)
(d / "bundle.yaml").write_text(yaml.safe_dump({"bad": "data"}))
result = validate_design(d)
assert result["status"] == "fail"
assert any("schema" in e for e in result["errors"])
def test_missing_handoff(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_design(d)
(d / "handoff_snapshot.md").unlink()
result = validate_design(d)
assert result["status"] == "fail"
assert any("handoff" in e for e in result["errors"])
def test_unexpected_file_at_root(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_design(d)
(d / "stray_probe.json").write_text("{}")
result = validate_design(d)
assert result["status"] == "fail"
assert any("unexpected file" in e for e in result["errors"])
def test_sdk_executor_log_under_inputs_passes(self, tmp_path: Path) -> None:
"""#190: SDK dispatcher writes executor_log.jsonl under inputs/.
The validator must accept the design iter dir even when the SDK has
teed a streaming log there — that's where the dispatcher belongs.
"""
d = tmp_path / "iter-1"
_setup_design(d)
(d / "inputs").mkdir(exist_ok=True)
(d / "inputs" / "executor_log.jsonl").write_text(
'{"type": "AssistantMessage", "ts": 1.0}\n'
)
result = validate_design(d)
assert result["status"] == "pass"
def test_campaign_iter_root_extensions_allow_extra_files(self, tmp_path: Path) -> None:
"""#199: campaign.validation.iter_root_extensions adds to the
global whitelist. Paper-* campaigns need this for analysis_summary.json,
manifest.json, probe_report.md.
"""
d = tmp_path / "iter-1"
_setup_design(d)
(d / "analysis_summary.json").write_text("{}")
(d / "manifest.json").write_text("{}")
(d / "probe_report.md").write_text("# Probe report")
# Without the extension: reject all three.
result = validate_design(d)
assert result["status"] == "fail"
assert sum(
1 for e in result["errors"]
if any(name in e for name in (
"analysis_summary.json",
"manifest.json",
"probe_report.md",
))
) == 3
# With the extension: pass.
campaign = {
"validation": {
"iter_root_extensions": [
"analysis_summary.json",
"manifest.json",
"probe_report.md",
],
},
}
result = validate_design(d, campaign=campaign)
assert result["status"] == "pass", result
def test_extension_does_not_disable_whitelist(self, tmp_path: Path) -> None:
"""#199: even with extensions, files outside both lists still fail."""
d = tmp_path / "iter-1"
_setup_design(d)
(d / "analysis_summary.json").write_text("{}") # extension
(d / "rogue_file.txt").write_text("nope") # not extension
campaign = {
"validation": {"iter_root_extensions": ["analysis_summary.json"]},
}
result = validate_design(d, campaign=campaign)
assert result["status"] == "fail"
assert any("rogue_file.txt" in e for e in result["errors"])
assert not any(
"analysis_summary.json" in e and "unexpected file" in e
for e in result["errors"]
)
def test_no_validation_block_keeps_strict_default(self, tmp_path: Path) -> None:
"""#199: campaigns that don't declare extensions get the strict default."""
d = tmp_path / "iter-1"
_setup_design(d)
(d / "analysis_summary.json").write_text("{}") # not on default whitelist
result = validate_design(d, campaign={}) # no validation block
assert result["status"] == "fail"
assert any("analysis_summary.json" in e for e in result["errors"])
def test_executor_log_at_iter_root_still_rejected(self, tmp_path: Path) -> None:
"""#190 contract: the iter root remains artifact-only.
Putting executor_log.jsonl at the iter root is the legacy bug shape
and should continue to fail the validator. This pins the invariant.
"""
d = tmp_path / "iter-1"
_setup_design(d)
(d / "executor_log.jsonl").write_text(
'{"type": "AssistantMessage", "ts": 1.0}\n'
)
result = validate_design(d)
assert result["status"] == "fail"
assert any(
"executor_log.jsonl" in e and "unexpected file" in e
for e in result["errors"]
)
class TestValidateExecution:
def test_pass_observe_mode(self, tmp_path: Path) -> None:
"""Observe mode: no code_changes, no patches needed."""
d = tmp_path / "iter-1"
_setup_execution(d)
result = validate_execution(d)
assert result["status"] == "pass"
def test_pass_evolve_mode(self, tmp_path: Path) -> None:
"""Evolve mode: code_changes present, patches required."""
d = tmp_path / "iter-1"
_setup_execution(d, bundle=VALID_BUNDLE_WITH_CODE)
patches = d / "patches"
patches.mkdir()
(patches / "h-main.patch").write_text("diff --git a/src/engine.go\n+batch=true\n")
result = validate_execution(d)
assert result["status"] == "pass"
def test_missing_findings(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "findings.json").unlink()
result = validate_execution(d)
assert result["status"] == "fail"
assert any("findings.json" in e for e in result["errors"])
def test_invalid_findings_schema(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "findings.json").write_text(json.dumps({"bad": "data"}))
result = validate_execution(d)
assert result["status"] == "fail"
assert any("schema" in e for e in result["errors"])
def test_missing_principles(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "principle_updates.json").unlink()
result = validate_execution(d)
assert result["status"] == "fail"
assert any("principle_updates" in e for e in result["errors"])
def test_missing_patches_when_code_changes(self, tmp_path: Path) -> None:
"""Evolve mode: bundle has code_changes but no patches directory."""
d = tmp_path / "iter-1"
_setup_execution(d, bundle=VALID_BUNDLE_WITH_CODE)
result = validate_execution(d)
assert result["status"] == "fail"
assert any("patches" in e for e in result["errors"])
def test_empty_patch_file(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_execution(d, bundle=VALID_BUNDLE_WITH_CODE)
patches = d / "patches"
patches.mkdir()
(patches / "h-main.patch").write_text("")
result = validate_execution(d)
assert result["status"] == "fail"
assert any("empty" in e for e in result["errors"])
def test_missing_experiment_plan(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "experiment_plan.yaml").unlink()
result = validate_execution(d)
assert result["status"] == "fail"
assert any("experiment_plan" in e for e in result["errors"])
def test_principles_not_a_list(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "principle_updates.json").write_text(json.dumps({"not": "a list"}))
result = validate_execution(d)
assert result["status"] == "fail"
assert any("list" in e for e in result["errors"])
def test_principle_missing_id(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "principle_updates.json").write_text(json.dumps([{"statement": "no id"}]))
result = validate_execution(d)
assert result["status"] == "fail"
assert any("id" in e for e in result["errors"])
def test_missing_output_file_referenced_in_plan(self, tmp_path: Path) -> None:
"""Plan references output files that don't exist."""
d = tmp_path / "iter-1"
_setup_execution(d)
plan_with_output = {
"metadata": {"iteration": 1, "bundle_ref": "runs/iter-1/bundle.yaml"},
"arms": [{"arm_id": "h-main", "conditions": [
{"name": "baseline", "cmd": "echo test",
"output": str(d / "results" / "baseline.json")},
]}],
}
(d / "experiment_plan.yaml").write_text(yaml.safe_dump(plan_with_output))
result = validate_execution(d)
assert result["status"] == "fail"
assert any("output file" in e for e in result["errors"])
def test_output_file_exists_passes(self, tmp_path: Path) -> None:
"""Plan references output files that exist — should pass."""
d = tmp_path / "iter-1"
_setup_execution(d)
results_dir = d / "results"
results_dir.mkdir()
(results_dir / "baseline.json").write_text('{"metric": 42}')
plan_with_output = {
"metadata": {"iteration": 1, "bundle_ref": "runs/iter-1/bundle.yaml"},
"arms": [{"arm_id": "h-main", "conditions": [
{"name": "baseline", "cmd": "echo test",
"output": str(results_dir / "baseline.json")},
]}],
}
(d / "experiment_plan.yaml").write_text(yaml.safe_dump(plan_with_output))
result = validate_execution(d)
assert result["status"] == "pass"
def test_no_output_field_skips_check(self, tmp_path: Path) -> None:
"""Conditions without output field — no check needed."""
d = tmp_path / "iter-1"
_setup_execution(d)
result = validate_execution(d)
assert result["status"] == "pass"
def test_missing_input_file_referenced_in_plan(self, tmp_path: Path) -> None:
"""Plan references input files that don't exist."""
d = tmp_path / "iter-1"
_setup_execution(d)
plan_with_inputs = {
"metadata": {"iteration": 1, "bundle_ref": "runs/iter-1/bundle.yaml"},
"arms": [{"arm_id": "h-main", "conditions": [
{"name": "baseline", "cmd": "echo test",
"inputs": [str(d / "inputs" / "workload.yaml")]},
]}],
}
(d / "experiment_plan.yaml").write_text(yaml.safe_dump(plan_with_inputs))
result = validate_execution(d)
assert result["status"] == "fail"
assert any("input file" in e for e in result["errors"])
def test_input_file_exists_passes(self, tmp_path: Path) -> None:
"""Plan references input files that exist — should pass."""
d = tmp_path / "iter-1"
_setup_execution(d)
inputs_dir = d / "inputs"
inputs_dir.mkdir()
(inputs_dir / "workload.yaml").write_text("rate: 80")
plan_with_inputs = {
"metadata": {"iteration": 1, "bundle_ref": "runs/iter-1/bundle.yaml"},
"arms": [{"arm_id": "h-main", "conditions": [
{"name": "baseline", "cmd": "echo test",
"inputs": [str(inputs_dir / "workload.yaml")]},
]}],
}
(d / "experiment_plan.yaml").write_text(yaml.safe_dump(plan_with_inputs))
result = validate_execution(d)
assert result["status"] == "pass"
def test_relative_input_path_resolved(self, tmp_path: Path) -> None:
"""Relative input paths are resolved against iter_dir."""
d = tmp_path / "iter-1"
_setup_execution(d)
inputs_dir = d / "inputs"
inputs_dir.mkdir()
(inputs_dir / "config.json").write_text("{}")
plan_with_inputs = {
"metadata": {"iteration": 1, "bundle_ref": "runs/iter-1/bundle.yaml"},
"arms": [{"arm_id": "h-main", "conditions": [
{"name": "baseline", "cmd": "echo test",
"inputs": ["inputs/config.json"]},
]}],
}
(d / "experiment_plan.yaml").write_text(yaml.safe_dump(plan_with_inputs))
result = validate_execution(d)
assert result["status"] == "pass"
def test_input_check_runs_despite_other_errors(self, tmp_path: Path) -> None:
"""Input file check runs even when other validation errors exist."""
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "findings.json").unlink() # cause a prior error
plan_with_inputs = {
"metadata": {"iteration": 1, "bundle_ref": "runs/iter-1/bundle.yaml"},
"arms": [{"arm_id": "h-main", "conditions": [
{"name": "baseline", "cmd": "echo test",
"inputs": [str(d / "inputs" / "missing.yaml")]},
]}],
}
(d / "experiment_plan.yaml").write_text(yaml.safe_dump(plan_with_inputs))
result = validate_execution(d)
assert result["status"] == "fail"
assert any("input file" in e for e in result["errors"])
assert any("findings" in e for e in result["errors"])
def test_unexpected_file_at_root(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "workload.yaml").write_text("rate: 80")
result = validate_execution(d)
assert result["status"] == "fail"
assert any("unexpected file" in e for e in result["errors"])
class TestCheckUnexpectedFiles:
def test_known_files_no_errors(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
d.mkdir()
(d / "problem.md").write_text("content")
(d / "bundle.yaml").write_text("content")
assert _check_unexpected_files(d) == []
def test_unknown_file_produces_error(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
d.mkdir()
(d / "problem.md").write_text("content")
(d / "stray_probe.json").write_text("{}")
errors = _check_unexpected_files(d)
assert len(errors) == 1
assert "unexpected file" in errors[0]
assert "stray_probe.json" in errors[0]
def test_subdirectories_ignored(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
d.mkdir()
(d / "results").mkdir()
(d / "inputs").mkdir()
assert _check_unexpected_files(d) == []
# ─── #199 v2 — required_iter_root ────────────────────────────────────────
#
# Sister field to iter_root_extensions: campaigns can declare files that
# MUST exist at the iter root after EXECUTE_ANALYZE completes. Missing
# entries fail validate_execution. Mirrors the #187 / #200 pattern of
# turning silent omissions into structured errors.
class TestRequiredIterRoot:
"""#199 v2: campaign.validation.required_iter_root makes campaign-
specific iter-root files mandatory at validate_execution time. The
validator fails with a clear ``required iter-root file missing: X``
error so operators see what the campaign promised to produce."""
def test_missing_required_file_fails_execution(
self, tmp_path: Path,
) -> None:
d = tmp_path / "iter-1"
_setup_execution(d)
# No analysis_summary.json on disk.
campaign = {
"validation": {
"required_iter_root": ["analysis_summary.json"],
# Required files are also implicitly allowed (so a
# campaign doesn't have to list them in both blocks).
},
}
result = validate_execution(d, campaign=campaign)
assert result["status"] == "fail"
assert any(
"required iter-root file missing" in e
and "analysis_summary.json" in e
for e in result["errors"]
), result["errors"]
def test_present_required_file_passes(self, tmp_path: Path) -> None:
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "analysis_summary.json").write_text("{}")
campaign = {
"validation": {
"required_iter_root": ["analysis_summary.json"],
},
}
result = validate_execution(d, campaign=campaign)
assert result["status"] == "pass", result
def test_required_file_implicitly_allowed_at_iter_root(
self, tmp_path: Path,
) -> None:
"""A required file should NOT need to be listed in
iter_root_extensions to avoid the unexpected-file rejection.
Required ⊆ allowed — the validator merges them automatically."""
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "probe_report.md").write_text("# Probe report\n")
campaign = {
"validation": {
"required_iter_root": ["probe_report.md"],
# Note: iter_root_extensions intentionally omitted.
},
}
result = validate_execution(d, campaign=campaign)
assert result["status"] == "pass", result
# Negative: the unexpected-file error must not have fired.
if result.get("errors"):
assert not any(
"unexpected file" in e and "probe_report.md" in e
for e in result["errors"]
), result["errors"]
def test_missing_required_listed_alongside_other_errors(
self, tmp_path: Path,
) -> None:
"""Required-file check runs even when other errors exist —
validation collects all errors so the operator sees the full
picture in one pass."""
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "findings.json").unlink() # primary error
campaign = {
"validation": {
"required_iter_root": ["analysis_summary.json"],
},
}
result = validate_execution(d, campaign=campaign)
assert result["status"] == "fail"
joined = " | ".join(result["errors"])
assert "findings.json" in joined
assert "analysis_summary.json" in joined
def test_no_required_block_keeps_default_behavior(
self, tmp_path: Path,
) -> None:
"""Campaigns without required_iter_root behave exactly as
before this PR (backward-compat)."""
d = tmp_path / "iter-1"
_setup_execution(d)
# No analysis_summary.json on disk; no required_iter_root either.
result = validate_execution(d, campaign={})
assert result["status"] == "pass", result
def test_required_combined_with_extensions(
self, tmp_path: Path,
) -> None:
"""A campaign declares both required and optional iter-root
files; only the required one is enforced for presence."""
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "analysis_summary.json").write_text("{}") # required, present
# manifest.json is "extensions" (optional) and absent — no error.
campaign = {
"validation": {
"required_iter_root": ["analysis_summary.json"],
"iter_root_extensions": ["manifest.json"],
},
}
result = validate_execution(d, campaign=campaign)
assert result["status"] == "pass", result
def test_required_file_at_design_time_is_allowed_not_required(
self, tmp_path: Path,
) -> None:
"""validate_design merges required ⊆ allowed (so a campaign that
writes a required file during DESIGN doesn't get rejected by the
unexpected-file check), but does NOT enforce required-presence
at design time — most required artifacts are EXECUTE-phase
outputs (e.g. probe_report.md is written during EXECUTE for
paper-* campaigns).
Pins both invariants:
(a) present-during-design → no "unexpected file" rejection
(b) absent-during-design → still passes design (no required-presence enforcement)
"""
campaign = {
"validation": {"required_iter_root": ["probe_report.md"]},
}
# (a) Present during DESIGN — required ⊆ allowed must let it through.
d1 = tmp_path / "iter-1"
_setup_design(d1)
(d1 / "probe_report.md").write_text("# Probe report\n")
result = validate_design(d1, campaign=campaign)
assert result["status"] == "pass", result
# (b) Absent during DESIGN — must still pass (only validate_execution
# enforces required-presence).
d2 = tmp_path / "iter-2"
_setup_design(d2)
result = validate_design(d2, campaign=campaign)
assert result["status"] == "pass", result
def test_required_overlapping_known_root_file_still_enforced(
self, tmp_path: Path,
) -> None:
"""A campaign may declare a file already in _KNOWN_ROOT_FILES
(e.g. findings.json) as required. The required-presence check
must still fire when the file is missing, even though the
unexpected-file check would never have flagged it.
"""
d = tmp_path / "iter-1"
_setup_execution(d)
(d / "findings.json").unlink() # in _KNOWN_ROOT_FILES, now absent.
campaign = {
"validation": {"required_iter_root": ["findings.json"]},
}
result = validate_execution(d, campaign=campaign)
assert result["status"] == "fail"
assert any(
"required iter-root file missing" in e and "findings.json" in e
for e in result["errors"]
), result["errors"]
def test_schema_accepts_required_iter_root(self) -> None:
"""The campaign.schema.yaml must accept the new field — without
a schema entry, jsonschema validation in nous run would reject
the campaign before the validator ever sees it."""
from orchestrator.validate import _load_yaml_schema
import jsonschema
schema = _load_yaml_schema("campaign.schema.yaml")
campaign = {
"research_question": "Does X work?",
"run_id": "demo",
"target_system": {"name": "T", "description": "d"},
"prompts": {"methodology_layer": "p"},
"validation": {
"required_iter_root": ["probe_report.md"],
"iter_root_extensions": ["analysis_summary.json"],
},
}
# Should not raise.
jsonschema.validate(campaign, schema)