test: add scenario eval runner, recorded fixtures, and baseline comparison
This commit is contained in:
parent
3dc1af5f0c
commit
0664cc2d27
38 changed files with 6986 additions and 5 deletions
32
eval/recording/storage.py
Normal file
32
eval/recording/storage.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"""Persist raw and redacted cassette stores."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from recording.model import RecordedInteraction
|
||||
from recording.redaction import redact_cassette
|
||||
|
||||
|
||||
def write_cassettes(
|
||||
fixture_root: Path,
|
||||
scenario_key: str,
|
||||
recordings: dict[str, list[RecordedInteraction]],
|
||||
) -> tuple[Path, Path]:
|
||||
"""Write ignored raw data first, then separately mapped safe cassettes."""
|
||||
raw_root = fixture_root / "raw" / scenario_key
|
||||
redacted_root = fixture_root / scenario_key
|
||||
raw_root.mkdir(parents=True, exist_ok=True)
|
||||
redacted_root.mkdir(parents=True, exist_ok=True)
|
||||
for service, interactions in recordings.items():
|
||||
raw_payload = [interaction.as_dict() for interaction in interactions]
|
||||
_write_json(raw_root / f"{service}.json", raw_payload)
|
||||
redacted_payload = redact_cassette(raw_payload)
|
||||
_write_json(redacted_root / f"{service}.json", redacted_payload)
|
||||
return raw_root, redacted_root
|
||||
|
||||
|
||||
def _write_json(path: Path, payload: object) -> None:
|
||||
path.write_text(
|
||||
json.dumps(payload, ensure_ascii=True, indent=2, sort_keys=True) + "\n",
|
||||
encoding="ascii",
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue