49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""Contract tests for hygiene-response.schema.json."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import jsonschema
|
|
|
|
from src.runtime.core.config import create_schema_registry, load_schema
|
|
|
|
|
|
def test_hygiene_response_schema_valid():
|
|
schema = load_schema("hygiene-response.schema.json")
|
|
registry = create_schema_registry()
|
|
validator = jsonschema.Draft202012Validator(schema, registry=registry)
|
|
|
|
valid_response = {
|
|
"title_candidate_id": "title_meta",
|
|
"subtitle_candidate_id": "subtitle_meta",
|
|
"author_candidate_id": "author_trafilatura",
|
|
"kept_block_ids": ["trafilatura_blk_001", "trafilatura_blk_002"],
|
|
"kept_link_ids": [],
|
|
"kept_image_ids": [],
|
|
"repairs": [
|
|
{
|
|
"target_candidate_id": "trafilatura_blk_001",
|
|
"original_fragment": "River Plate empató",
|
|
"replacement_fragment": "River Plate empató",
|
|
"category": "encoding",
|
|
"rationale": "Fix moji-bake encoding artifact.",
|
|
}
|
|
],
|
|
"removal_reasons": {"trafilatura_blk_003": "advertisement"},
|
|
}
|
|
|
|
errors = list(validator.iter_errors(valid_response))
|
|
assert len(errors) == 0, f"Schema errors: {[e.message for e in errors]}"
|
|
|
|
|
|
def test_hygiene_response_schema_missing_required():
|
|
schema = load_schema("hygiene-response.schema.json")
|
|
registry = create_schema_registry()
|
|
validator = jsonschema.Draft202012Validator(schema, registry=registry)
|
|
|
|
invalid_response = {
|
|
"kept_block_ids": ["blk_01"]
|
|
# Missing title_candidate_id, repairs, etc.
|
|
}
|
|
errors = list(validator.iter_errors(invalid_response))
|
|
assert len(errors) > 0
|