Spaces:
Building
Building
File size: 979 Bytes
414dc55 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | """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)
|