feat: msgspec schemas for jsonl decoding (#37)

This commit is contained in:
banteg
2026-01-04 03:41:07 +04:00
committed by GitHub
parent 30fe5cef43
commit a0c16c325e
33 changed files with 2235 additions and 1148 deletions
+44
View File
@@ -0,0 +1,44 @@
from __future__ import annotations
import json
from pathlib import Path
import pytest
from takopi.schemas import codex as codex_schema
def _fixture_path(name: str) -> Path:
return Path(__file__).parent / "fixtures" / name
def _decode_fixture(name: str) -> list[str]:
path = _fixture_path(name)
errors: list[str] = []
for lineno, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
if not line.strip():
continue
try:
json.loads(line)
except Exception as exc:
errors.append(f"line {lineno}: invalid JSON ({exc})")
continue
try:
codex_schema.decode_event(line)
except Exception as exc:
errors.append(f"line {lineno}: {exc.__class__.__name__}: {exc}")
return errors
@pytest.mark.parametrize(
"fixture",
[
"codex_exec_json_all_formats.jsonl",
],
)
def test_codex_schema_parses_fixture(fixture: str) -> None:
errors = _decode_fixture(fixture)
assert not errors, f"{fixture} had {len(errors)} errors: " + "; ".join(errors[:5])