"""instance_live_push_lib 单元测试."""
from __future__ import annotations

import json

from lib.instance.instance_live_push_lib import InstanceLivePush


def test_tick_increments_version_and_connect_event() -> None:
    push = InstanceLivePush()
    v1 = push.tick("test")
    v2 = push.tick("test")
    assert v1 == 1
    assert v2 == 2
    gen = push.iter_sse()
    first = next(gen)
    assert first.startswith("event: live")
    data = json.loads(first.split("data: ", 1)[1].strip())
    assert data["live_version"] == 2
    push.stop()
