"""Contract tests for repair-operations.schema.json.""" from __future__ import annotations import jsonschema from src.runtime.core.config import create_schema_registry, load_schema def test_repair_operations_schema_valid(): schema = load_schema("repair-operations.schema.json") registry = create_schema_registry() validator = jsonschema.Draft202012Validator(schema, registry=registry) valid_repairs = [ { "target_candidate_id": "blk_001", "original_fragment": "São Paulo F.C.", "replacement_fragment": "São Paulo FC", "category": "punctuation_corruption", "rationale": "Normalize acronym dots.", }, { "target_candidate_id": "blk_002", "original_fragment": "artigo com espacos", "replacement_fragment": "artigo com espacos", "category": "spacing", "rationale": "Collapse multiple spaces.", }, ] errors = list(validator.iter_errors(valid_repairs)) assert len(errors) == 0, f"Schema errors: {[e.message for e in errors]}" def test_repair_operations_rejects_unapproved_category(): schema = load_schema("repair-operations.schema.json") registry = create_schema_registry() validator = jsonschema.Draft202012Validator(schema, registry=registry) invalid_repairs = [ { "target_candidate_id": "blk_001", "original_fragment": "old", "replacement_fragment": "new", "category": "editorial_rephrasing", # Unapproved category "rationale": "Rewriting paragraph style.", } ] errors = list(validator.iter_errors(invalid_repairs)) assert len(errors) > 0