Files
awoooi/apps/api/tests/test_aider_event_models.py
Your Name 5daae76147 feat(models): AiderEventIn + AiderBatchIn pydantic schemas
- Implement aider-watch v2 event schema with 7 event types
- Enforce timezone-aware timestamps via field_validator
- Batch schema supports up to 50 events per request
- Frozen + forbid extra fields (defensive engineering)
- Fix broken src.* imports in models package (incident.py, __init__.py)

Task A3 complete: 7/7 tests passing
2026-04-20 04:06:26 +08:00

58 lines
1.4 KiB
Python

# apps/api/tests/test_aider_event_models.py | 2026-04-20 @ Asia/Taipei
from datetime import datetime, timezone, timedelta
import pytest
from pydantic import ValidationError
from apps.api.src.models.aider import AiderEventIn, AiderBatchIn
TAIPEI = timezone(timedelta(hours=8))
def _base(t="session_start", payload=None):
return {
"ts": datetime(2026, 4, 20, 10, 0, tzinfo=TAIPEI).isoformat(),
"session_id": "01J7XYZABC",
"host": "ogt-mac",
"type": t,
"payload": payload or {},
}
def test_accepts_all_7_types():
for t in ("session_start", "file_edit", "error", "commit",
"silent_timeout", "session_end", "raw"):
ev = AiderEventIn(**_base(t=t))
assert ev.type == t
def test_rejects_unknown_type():
with pytest.raises(ValidationError):
AiderEventIn(**_base(t="bogus"))
def test_rejects_missing_session_id():
d = _base(); del d["session_id"]
with pytest.raises(ValidationError):
AiderEventIn(**d)
def test_rejects_missing_ts():
d = _base(); del d["ts"]
with pytest.raises(ValidationError):
AiderEventIn(**d)
def test_batch_max_50():
with pytest.raises(ValidationError):
AiderBatchIn(events=[_base() for _ in range(51)])
def test_batch_accepts_1():
b = AiderBatchIn(events=[_base()])
assert len(b.events) == 1
def test_host_default():
d = _base(); del d["host"]
ev = AiderEventIn(**d)
assert ev.host == "ogt-mac"