46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
"""Contract tests for article-input.schema.json evaluated against all 20 reference units."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import jsonschema
|
|
|
|
from src.runtime.core.config import create_schema_registry, load_schema
|
|
|
|
|
|
def test_article_input_schema_against_all_20_reference_units():
|
|
schema = load_schema("article-input.schema.json")
|
|
registry = create_schema_registry()
|
|
validator = jsonschema.Draft202012Validator(schema, registry=registry)
|
|
|
|
ref_dir = Path("evals/reference_20")
|
|
article_files = sorted(ref_dir.glob("article_*.json"))
|
|
assert len(article_files) == 20, f"Expected 20 reference unit files, found {len(article_files)}"
|
|
|
|
for art_file in article_files:
|
|
data = json.loads(art_file.read_text(encoding="utf-8"))
|
|
errors = list(validator.iter_errors(data))
|
|
assert len(errors) == 0, (
|
|
f"Article {art_file.name} failed contract validation: {[e.message for e in errors]}"
|
|
)
|
|
|
|
|
|
def test_article_input_rejects_batch_wrapper():
|
|
schema = load_schema("article-input.schema.json")
|
|
registry = create_schema_registry()
|
|
validator = jsonschema.Draft202012Validator(schema, registry=registry)
|
|
|
|
# Batch wrapper containing "articles" key must fail contract validation
|
|
batch_data = {
|
|
"articles": [
|
|
{"source_url": "https://example.com/1"},
|
|
{"source_url": "https://example.com/2"},
|
|
]
|
|
}
|
|
errors = list(validator.iter_errors(batch_data))
|
|
assert len(errors) > 0, (
|
|
"Batch wrapper containing 'articles' key must be rejected by contract schema"
|
|
)
|