feat(provenance): govern source snapshots and data inputs

This commit is contained in:
Jens
2026-08-01 23:46:17 +02:00
parent cebeb5f3b4
commit 5b3c17b494
96 changed files with 20156 additions and 351 deletions
@@ -3,6 +3,8 @@ from __future__ import annotations
import importlib.util
from pathlib import Path
import pytest
SCRIPT = Path(__file__).parents[2] / "scripts" / "build_failure_driven_yolo_sampling.py"
SPEC = importlib.util.spec_from_file_location("failure_sampling", SCRIPT)
@@ -22,7 +24,7 @@ def test_dataset_validation_source_preserves_manifest_path(tmp_path: Path):
assert MODULE.dataset_validation_source(source) == "/data/source/internal-val.txt"
def test_sampling_repeats_only_failed_region_train_tiles() -> None:
def test_sampling_rejects_protected_test_and_background_feedback() -> None:
manifest = {
"samples": [
{"sample_slug": "train-fl", "split": "train", "region": "flanders"},
@@ -54,15 +56,10 @@ def test_sampling_repeats_only_failed_region_train_tiles() -> None:
},
"background": {"pure_empty_false_positives": 2},
}
paths, metadata = MODULE.build_sampling(
summary=summary, manifest=manifest, assessment=assessment, max_region_share=1.0
)
assert paths.count(str(Path("/tmp/fl-pos.png").resolve())) == 3
assert paths.count(str(Path("/tmp/fl-neg.png").resolve())) == 4
assert paths.count(str(Path("/tmp/wa-pos.png").resolve())) == 1
assert not any("protected" in path for path in paths)
assert metadata["protected_samples_in_training"] == []
assert metadata["weak_recall_regions"] == ["flanders"]
with pytest.raises(ValueError, match="protected test/background evidence"):
MODULE.build_sampling(
summary=summary, manifest=manifest, assessment=assessment, max_region_share=1.0
)
def test_sampling_can_use_calibration_before_test_is_opened() -> None:
@@ -171,7 +168,7 @@ def test_sampling_targets_failed_calibration_contexts_without_using_protected_ti
assert metadata["recall_dominant_regions"] == ["flanders"]
def test_recall_dominance_does_not_suppress_negatives_when_background_gate_failed() -> None:
def test_sampling_rejects_background_feedback_after_a_protected_background_opening() -> None:
manifest = {"samples": [
{"sample_slug": "positive", "split": "train", "region": "flanders", "context": "industrial"},
{"sample_slug": "negative", "split": "train", "region": "flanders", "context": "industrial-hard-negative"},
@@ -190,12 +187,10 @@ def test_recall_dominance_does_not_suppress_negatives_when_background_gate_faile
"background": {"pure_empty_false_positives": 1},
}
paths, metadata = MODULE.build_sampling(
summary=summary, manifest=manifest, assessment=assessment, max_region_share=1.0,
)
assert paths.count(str(Path("/tmp/negative.png").resolve())) == 4
assert metadata["recall_dominant_regions"] == []
with pytest.raises(ValueError, match="protected background evidence"):
MODULE.build_sampling(
summary=summary, manifest=manifest, assessment=assessment, max_region_share=1.0,
)
def test_region_cap_drops_only_repeats_and_preserves_every_unique_tile() -> None: