1
0

fix: send world state snapshot on WS client connect (#390)

Co-authored-by: Kimi Agent <kimi@timmy.local>
Co-committed-by: Kimi Agent <kimi@timmy.local>
This commit is contained in:
2026-03-19 01:28:57 -04:00
committed by hermes
parent 858264be0d
commit f9d8509c15
2 changed files with 51 additions and 10 deletions

View File

@@ -219,3 +219,29 @@ def test_world_ws_endpoint_accepts_connection(client):
"""WebSocket endpoint at /api/world/ws accepts connections."""
with client.websocket_connect("/api/world/ws"):
pass # Connection accepted — just close it
def test_world_ws_sends_snapshot_on_connect(client, tmp_path):
"""WebSocket sends a world_state snapshot immediately on connect."""
f = tmp_path / "presence.json"
f.write_text(
json.dumps(
{
"version": 1,
"liveness": "2026-03-19T02:00:00Z",
"mood": "exploring",
"current_focus": "testing",
"active_threads": [],
"recent_events": [],
"concerns": [],
}
)
)
with patch("dashboard.routes.world.PRESENCE_FILE", f):
with client.websocket_connect("/api/world/ws") as ws:
msg = json.loads(ws.receive_text())
assert msg["type"] == "world_state"
assert msg["timmyState"]["mood"] == "exploring"
assert msg["timmyState"]["activity"] == "testing"
assert "updatedAt" in msg