feat(api): parse endpoints pass EventBus into store writes

- api.parse_837 / parse_835: pass request.app.state.event_bus into store.add()
- conftest: autouse fixture wires a fresh EventBus onto app.state for every
  test, since TestClient does not invoke the FastAPI lifespan handler
  unless used as a context manager
- test_pubsub: split get_event_bus coverage into a raises-when-missing test
  and a returns-attached-bus test, both save/restore app.state.event_bus
  around the assertion so the autouse fixture's bus is preserved

Phase 2 complete: db init moved to lifespan, EventBus is the process-wide
publish point, and the two ingest endpoints publish claim_written /
remittance_written / activity_recorded events on every store.add().
This commit is contained in:
Tyler
2026-06-20 15:51:18 -06:00
parent 8d02ed3204
commit 8bcb23c78d
3 changed files with 49 additions and 12 deletions
+15 -3
View File
@@ -19,10 +19,22 @@ import pytest
@pytest.fixture(autouse=True)
def _auto_init_db(tmp_path, monkeypatch):
"""Point CYCLONE_DB_URL at a per-test SQLite file and init the schema."""
"""Point CYCLONE_DB_URL at a per-test SQLite file and init the schema.
Also wires a fresh ``EventBus`` onto ``app.state`` because ``TestClient``
does not invoke the FastAPI lifespan handler unless used as a context
manager. The bus is reset between tests so subscribers don't leak.
"""
monkeypatch.setenv("CYCLONE_DB_URL", f"sqlite:///{tmp_path}/test.db")
from cyclone import db
from cyclone.api import app
from cyclone.pubsub import EventBus
db._reset_for_tests()
db.init_db()
yield
db._reset_for_tests()
app.state.event_bus = EventBus()
try:
yield
finally:
app.state.event_bus = None
db._reset_for_tests()