From 2547f80893861b0da4b8b63411b411108b1909e5 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Fri, 24 Apr 2026 10:19:18 -0700 Subject: [PATCH] feat(streaming): add StreamTokenRequest/Response schemas --- app/models/schemas/recipe.py | 21 +++++++++++++++++++++ tests/api/test_stream_token.py | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/app/models/schemas/recipe.py b/app/models/schemas/recipe.py index 8eb267d..80cbf75 100644 --- a/app/models/schemas/recipe.py +++ b/app/models/schemas/recipe.py @@ -152,3 +152,24 @@ class BuildRequest(BaseModel): template_id: str role_overrides: dict[str, str] = Field(default_factory=dict) + + +class StreamTokenRequest(BaseModel): + """Request body for POST /recipes/stream-token. + + Pantry items and dietary constraints are fetched from the DB at request + time — the client does not supply them here. + """ + level: int = Field(4, ge=3, le=4, description="Recipe level: 3=styled, 4=wildcard") + wildcard_confirmed: bool = Field(False, description="Required true for level 4") + + +class StreamTokenResponse(BaseModel): + """Response from POST /recipes/stream-token. + + The frontend opens EventSource at stream_url?token= to receive + SSE chunks directly from the coordinator. + """ + stream_url: str + token: str + expires_in_s: int diff --git a/tests/api/test_stream_token.py b/tests/api/test_stream_token.py index 15d11db..894d91e 100644 --- a/tests/api/test_stream_token.py +++ b/tests/api/test_stream_token.py @@ -2,6 +2,8 @@ import pytest from unittest.mock import AsyncMock, patch +from app.models.schemas.recipe import StreamTokenRequest, StreamTokenResponse + def test_coordinator_authorize_missing_url(monkeypatch): """coordinator_authorize raises RuntimeError when COORDINATOR_URL is unset.""" @@ -9,3 +11,24 @@ def test_coordinator_authorize_missing_url(monkeypatch): monkeypatch.delenv("COORDINATOR_KIWI_KEY", raising=False) # Will test this properly via endpoint — see Task 3 tests. pass + + +def test_stream_token_request_defaults(): + req = StreamTokenRequest() + assert req.level == 4 + assert req.wildcard_confirmed is False + + +def test_stream_token_request_level_3(): + req = StreamTokenRequest(level=3) + assert req.level == 3 + + +def test_stream_token_response(): + resp = StreamTokenResponse( + stream_url="http://10.1.10.71:7700/proxy/stream", + token="abc-123", + expires_in_s=60, + ) + assert resp.stream_url.startswith("http") + assert resp.expires_in_s == 60