"""FastAPI test app that registers the AFI fixture.""" from __future__ import annotations from fastapi import FastAPI from mizan_fastapi import ( Channel, MizanError, mizan_exception_handler, mizan_validation_handler, register_channel, router as mizan_router, ) from fixture import ( CHAT_CHANNEL, USER_ALERTS_CHANNEL, ChatClientMessage, ChatParams, ChatServerMessage, UserAlertsServerMessage, register_fixture, ) class ChatChannel(Channel): """All three slots declared; the room keys the fan-out.""" Params = ChatParams ClientMessage = ChatClientMessage ServerMessage = ChatServerMessage def group(self, params: ChatParams | None = None) -> str: return f"chat:{params.room_id}" if params else "chat" class UserAlertsChannel(Channel): """Push-only: no params, nothing travels up.""" ServerMessage = UserAlertsServerMessage def make_app() -> FastAPI: """Build a fresh FastAPI app with the AFI fixture registered.""" register_fixture() register_channel(ChatChannel, CHAT_CHANNEL) register_channel(UserAlertsChannel, USER_ALERTS_CHANNEL) app = FastAPI() app.include_router(mizan_router, prefix="/api/mizan") app.add_exception_handler(MizanError, mizan_exception_handler) from fastapi.exceptions import RequestValidationError app.add_exception_handler(RequestValidationError, mizan_validation_handler) return app