"""JSON Schema validation tests against the generated vector suite.""" from __future__ import annotations import copy import pytest from fpcf import schemas from fpcf.errors import ConformanceError from helpers import assert_all, valid_single_ops def test_all_valid_operation_vectors_pass_schema(vectors_dir, manifest): ops = assert_all( valid_single_ops(vectors_dir, manifest), "vector suite must contain valid single-operation vectors", ) for entry, op in ops: schemas.validate_operation(op) # must not raise def test_missing_type_is_rejected(vectors_dir, manifest): _, op = valid_single_ops(vectors_dir, manifest)[0] bad = copy.deepcopy(op) del bad["type"] with pytest.raises(ConformanceError): schemas.validate_operation(bad) def test_unknown_type_is_rejected(vectors_dir, manifest): _, op = valid_single_ops(vectors_dir, manifest)[0] bad = copy.deepcopy(op) bad["type"] = "bogus/not-a-real-operation" with pytest.raises(ConformanceError): schemas.validate_operation(bad) def test_non_object_body_is_rejected(vectors_dir, manifest): _, op = valid_single_ops(vectors_dir, manifest)[0] bad = copy.deepcopy(op) bad["body"] = "not an object" with pytest.raises(ConformanceError): schemas.validate_operation(bad) def test_schema_errors_carry_codes(vectors_dir, manifest): _, op = valid_single_ops(vectors_dir, manifest)[0] bad = copy.deepcopy(op) del bad["type"] try: schemas.validate_operation(bad) except ConformanceError as exc: assert isinstance(exc.code, str) and exc.code.startswith("ERR_") else: # pragma: no cover - defensive pytest.fail("expected ConformanceError")