import json
from pathlib import Path

from m3m_disease.inference import ALLOWED_OUTPUT_STATUSES


def test_public_contract_schemas_are_valid_json_and_draft_2020_12():
    root = Path(__file__).resolve().parents[1]
    schemas = sorted((root / "schemas").glob("*.json"))
    assert {path.name for path in schemas} == {
        "capture-manifest.schema.json",
        "dataset-manifest.schema.json",
        "inference-receipt.schema.json",
        "label-manifest.schema.json",
        "model-card.schema.json",
        "model.schema.json",
        "run-manifest.schema.json",
        "split-receipt.schema.json",
    }
    for path in schemas:
        value = json.loads(path.read_text(encoding="utf-8"))
        assert value["$schema"].endswith("2020-12/schema")
        assert value["type"] == "object"


def test_inference_schema_statuses_match_runtime_exactly():
    root = Path(__file__).resolve().parents[1]
    schema = json.loads((root / "schemas" / "inference-receipt.schema.json").read_text(encoding="utf-8"))
    assert schema["properties"]["status"]["enum"] == list(ALLOWED_OUTPUT_STATUSES)
