"""Load and save CaseFile artifacts as JSON. Sharing a case means sharing the generated artifact, not a seed: model generation is not bit-deterministic, so the JSON is the portable, reproducible unit. """ from __future__ import annotations from pathlib import Path from ..schemas.case import CaseFile from .paths import runtime_cases_dir, seed_case_path def save_case(case: CaseFile, path: Path) -> Path: path.parent.mkdir(parents=True, exist_ok=True) path.write_text(case.model_dump_json(indent=2), encoding="utf-8") return path def load_case(path: Path) -> CaseFile: return CaseFile.model_validate_json(path.read_text(encoding="utf-8")) def save_runtime_case(case: CaseFile) -> Path: return save_case(case, runtime_cases_dir() / f"{case.case_id}.json") def load_seed_case(name: str) -> CaseFile: path = seed_case_path(name) if not path.exists(): raise FileNotFoundError(f"seed case not found: {path}") return load_case(path)