Remove skip-neko-wait on stale telemetry; require new livestreaming heartbeats for 25s after slot switch. Add youtube_live_confirmed to relay status and unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
from app import youtube_neko
|
|
|
|
|
|
def _reset_events() -> None:
|
|
youtube_neko._studio_events.clear() # noqa: SLF001
|
|
|
|
|
|
def test_payload_stream_confirmed_live_status() -> None:
|
|
assert youtube_neko._payload_stream_confirmed({"live_status": "live"}) is True
|
|
assert youtube_neko._payload_stream_confirmed({"health": "excellent"}) is True
|
|
assert youtube_neko._payload_stream_confirmed({"live_status": "waiting"}) is False
|
|
|
|
|
|
def test_latest_live_studio_event_since_ts() -> None:
|
|
_reset_events()
|
|
now = time.time()
|
|
youtube_neko.ingest_studio_telemetry(
|
|
{
|
|
"url": "https://studio.youtube.com/channel/abc/livestreaming",
|
|
"live_status": "waiting",
|
|
"received_at": now - 10,
|
|
}
|
|
)
|
|
assert youtube_neko.latest_live_studio_event(max_age_sec=60.0, since_ts=now) is None
|
|
youtube_neko.ingest_studio_telemetry(
|
|
{
|
|
"url": "https://studio.youtube.com/channel/abc/livestreaming",
|
|
"live_status": "live",
|
|
"received_at": now + 1,
|
|
}
|
|
)
|
|
ev = youtube_neko.latest_live_studio_event(max_age_sec=60.0, since_ts=now)
|
|
assert ev is not None
|
|
assert youtube_neko.youtube_live_confirmed(max_age_sec=60.0, since_ts=now)["live"] is True
|
|
|
|
|
|
def test_youtube_live_confirmed_no_event() -> None:
|
|
_reset_events()
|
|
out = youtube_neko.youtube_live_confirmed(max_age_sec=30.0)
|
|
assert out["ok"] is False
|
|
assert out["live"] is False
|