feat(sse,tui): bump spec pin to v0.28.0 + AffectUpdate event (v0.11.0)
Spec pin moved 55101e9 (v0.19.0) → da93ca7 (v0.28.0); vendored conversation-api-spec.md + conversation_api.contract.md re-snapshotted from Worldtree at the new SHA. The only material delta consumed in this bump is Worldtree #204's affect_update SSE event surface. Wire layer (sse_client.py): - New AffectUpdate dataclass: sse_id / status / turn_id / snapshot (snapshot is None for status="scheduled") - Added to Event union + _envelope_for_type dispatch branch - Without this, ratatoskr would crash on any persona-enabled turn from a v0.28.0 server (unknown SSE event type → ValueError) TUI layer (tui.py): - AffectUpdate routes through the v0.10.0 audit pipeline only — one debug-pane line per arrival with dominant_emotion + PAD for status="current", lightweight status+turn_id for status="scheduled" - No transcript / tools / thinking pane writes — the persona UX shape (Persona TabPane vs sticky header line) is deferred to a separate bump pending operator direction Tests: 2 new wire-layer tests for current+scheduled parsing + 2 new presenter audit tests for routing and audit-line shape. Not yet consumed: GET /agents/{id}/persona_state endpoint (step 2 of the integration plan).
This commit is contained in:
@@ -5,6 +5,7 @@ import pytest
|
||||
import respx
|
||||
|
||||
from ratatoskr.sse_client import (
|
||||
AffectUpdate,
|
||||
CancelAlreadyCompleted,
|
||||
Cancelled,
|
||||
CancelResult,
|
||||
@@ -877,3 +878,80 @@ class TestEmptyDataSkipped:
|
||||
assert exc_info.value.raw == "x" * 200
|
||||
# Exception message also only contains the truncated form
|
||||
assert "x" * 5000 not in str(exc_info.value)
|
||||
|
||||
|
||||
class TestAffectUpdate:
|
||||
"""Worldtree #204 / v0.28.0 — persona-state observability SSE event.
|
||||
|
||||
Two emissions per qualifying turn (persona-enabled agent, non-ephemeral
|
||||
session): `status: "current"` at turn start with full snapshot, then
|
||||
`status: "scheduled"` near turn end (lightweight, no snapshot).
|
||||
|
||||
See docs/conversation-api-spec.md § affect_update.
|
||||
"""
|
||||
|
||||
@respx.mock
|
||||
async def test_current_status_parsed_with_snapshot(self) -> None:
|
||||
"""current_status_parsed_with_snapshot [tracer]: status=current carries
|
||||
the full snapshot dict; AffectUpdate.snapshot is populated with the
|
||||
nested PAD / dominant_emotion / emotions_active fields.
|
||||
"""
|
||||
snapshot = {
|
||||
"agent_id": "mimir",
|
||||
"pad": {"pleasure": 0.52, "arousal": 0.47, "dominance": 0.50},
|
||||
"dominant_emotion": "curiosity",
|
||||
"emotions_active": [
|
||||
{"type": "curiosity", "intensity": 0.6, "decay_remaining_s": 202.7}
|
||||
],
|
||||
"baseline_pad": {"pleasure": 0.50, "arousal": 0.40, "dominance": 0.50},
|
||||
"mood_drift": {"valence_delta": 0.02, "arousal_delta": 0.07},
|
||||
"last_updated_at": "2026-05-25T22:30:18+00:00",
|
||||
}
|
||||
stream = _sse_chunk(
|
||||
"42:1",
|
||||
{
|
||||
"type": "affect_update",
|
||||
"status": "current",
|
||||
"turn_id": 42,
|
||||
"snapshot": snapshot,
|
||||
},
|
||||
) + _sse_chunk("42:2", _DONE_42_6)
|
||||
respx.post("https://w.example/sessions/s1/messages").mock(
|
||||
return_value=httpx.Response(
|
||||
200, headers={"content-type": "text/event-stream"}, content=stream
|
||||
)
|
||||
)
|
||||
async with httpx.AsyncClient(base_url="https://w.example") as client:
|
||||
events = [e async for e in stream_turn(client, "s1", "hi")]
|
||||
affect = events[0]
|
||||
assert isinstance(affect, AffectUpdate)
|
||||
assert affect.status == "current"
|
||||
assert affect.turn_id == 42
|
||||
assert affect.snapshot == snapshot
|
||||
assert affect.sse_id == SseId(42, 1)
|
||||
|
||||
@respx.mock
|
||||
async def test_scheduled_status_parsed_no_snapshot(self) -> None:
|
||||
"""scheduled_status_parsed_no_snapshot [trace]: status=scheduled carries
|
||||
no snapshot field; AffectUpdate.snapshot is None.
|
||||
"""
|
||||
stream = (
|
||||
_sse_chunk("42:1", {"type": "text", "content": "x"})
|
||||
+ _sse_chunk(
|
||||
"42:2",
|
||||
{"type": "affect_update", "status": "scheduled", "turn_id": 42},
|
||||
)
|
||||
+ _sse_chunk("42:3", _DONE_42_6)
|
||||
)
|
||||
respx.post("https://w.example/sessions/s1/messages").mock(
|
||||
return_value=httpx.Response(
|
||||
200, headers={"content-type": "text/event-stream"}, content=stream
|
||||
)
|
||||
)
|
||||
async with httpx.AsyncClient(base_url="https://w.example") as client:
|
||||
events = [e async for e in stream_turn(client, "s1", "hi")]
|
||||
affect = next(e for e in events if isinstance(e, AffectUpdate))
|
||||
assert affect.status == "scheduled"
|
||||
assert affect.turn_id == 42
|
||||
assert affect.snapshot is None
|
||||
assert affect.sse_id == SseId(42, 2)
|
||||
|
||||
Reference in New Issue
Block a user