Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
71 lines
2.4 KiB
Python
71 lines
2.4 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
|
|
|
|
|
|
def test_maybe_append_minute_report_persists_source(tmp_path, monkeypatch) -> None:
|
|
_reset_events()
|
|
youtube_neko._studio_minute_reports.clear() # noqa: SLF001
|
|
youtube_neko._studio_minute_last_at.clear() # noqa: SLF001
|
|
monkeypatch.setattr(youtube_neko, "_neko_root", lambda: tmp_path)
|
|
now = time.time()
|
|
youtube_neko.ingest_studio_telemetry(
|
|
{
|
|
"neko_instance_id": 3,
|
|
"url": "https://studio.youtube.com/video/abc/livestreaming",
|
|
"live_status": "live",
|
|
"health": "excellent",
|
|
"viewer_count": 12,
|
|
"source": "cdp",
|
|
"received_at": now,
|
|
}
|
|
)
|
|
rows = youtube_neko.list_studio_minute_reports(3, limit=5)
|
|
assert rows and rows[0]["on_air"] is True
|
|
assert rows[0].get("source") == "cdp"
|
|
disk = tmp_path / "studio_minute" / "3.jsonl"
|
|
assert disk.is_file()
|