"""Pin the SSE parser in nexus_api. Run: python tests/test_nexus_api.py"""
from nexusos_cli.nexus_api import iter_chunks

# A realistic /chat/stream frame: two token chunks, a meta block, then done.
lines = [
    'data: "Hello"', "",
    'data: " world"', "",
    "event: meta", 'data: {"model":"mistral"}', "",
    "event: done", "data: {}", "",
]
out = list(iter_chunks(lines))
assert out == [
    ("chunk", "Hello"),
    ("chunk", " world"),
    ("meta", '{"model":"mistral"}'),
    ("done", "{}"),
], out
# error frame surfaces as its own kind, not a chunk
assert list(iter_chunks(["event: error", 'data: {"detail":"boom"}'])) == [
    ("error", '{"detail":"boom"}')
]
print("ok")
