feat(streaming): add StreamTokenRequest/Response schemas

This commit is contained in:
pyr0ball 2026-04-24 10:19:18 -07:00
parent 0996ea8c7a
commit 2547f80893
2 changed files with 44 additions and 0 deletions

View file

@ -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=<token> to receive
SSE chunks directly from the coordinator.
"""
stream_url: str
token: str
expires_in_s: int

View file

@ -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