Tighten http/youtubei live probes, classify Studio encoder_lost vs waiting, and keep dy/dylive public live counts aligned via edge assign_lives. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
2.4 KiB
Python
55 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
from app import youtube_neko
|
|
|
|
|
|
def test_preferred_neko_public_base_colocated(monkeypatch) -> None:
|
|
monkeypatch.setattr(youtube_neko, "_physical_dual_edge", lambda: False)
|
|
monkeypatch.setattr(youtube_neko, "_public_base", lambda: "https://dylive.nomadro.com")
|
|
assert youtube_neko.preferred_neko_public_base() == "https://dylive.nomadro.com"
|
|
|
|
|
|
def test_preferred_neko_public_base_cn_first(monkeypatch) -> None:
|
|
monkeypatch.setattr(youtube_neko, "_physical_dual_edge", lambda: True)
|
|
monkeypatch.setattr(youtube_neko, "cn_edge_usable", lambda: True)
|
|
monkeypatch.setattr(youtube_neko, "_public_base", lambda: "https://dy.nomadro.com")
|
|
monkeypatch.delenv("DY_NEKO_CN_PUBLIC_BASE", raising=False)
|
|
assert youtube_neko.preferred_neko_public_base() == "https://dy.nomadro.cn"
|
|
|
|
|
|
def test_preferred_neko_public_base_vps_fallback(monkeypatch) -> None:
|
|
monkeypatch.setattr(youtube_neko, "_physical_dual_edge", lambda: True)
|
|
monkeypatch.setattr(youtube_neko, "cn_edge_usable", lambda: False)
|
|
monkeypatch.setattr(youtube_neko, "_public_base", lambda: "https://dy.nomadro.com")
|
|
monkeypatch.delenv("DY_NEKO_CN_PUBLIC_BASE", raising=False)
|
|
assert youtube_neko.preferred_neko_public_base() == "https://dy.nomadro.com"
|
|
|
|
|
|
def test_compose_service_lines_has_studio_live_env(tmp_path, monkeypatch) -> None:
|
|
assets = youtube_neko._asset_root() # noqa: SLF001
|
|
monkeypatch.setattr(youtube_neko, "_detect_public_ip", lambda: "1.2.3.4")
|
|
monkeypatch.setattr(youtube_neko, "_neko_browser_proxy_value", lambda: "http://host.docker.internal:7890")
|
|
profile = tmp_path / "p"
|
|
profile.mkdir()
|
|
idf = tmp_path / "id.txt"
|
|
idf.write_text("ops-1\n", encoding="utf-8")
|
|
lines = youtube_neko.compose_service_lines(
|
|
service_key="opsneko1",
|
|
container_name="douyinweb-ops-neko-1",
|
|
instance_id_label="ops-1",
|
|
http_port=18200,
|
|
mux=62300,
|
|
udp="62500-62509",
|
|
profile=profile,
|
|
instance_id_file=idf,
|
|
http_bind="0.0.0.0",
|
|
)
|
|
blob = "\n".join(lines)
|
|
assert "NEKO_LIVE_OPS_EXTENSION" in blob
|
|
assert "NEKO_TAMPERMONKEY_REPAIR" in blob
|
|
assert "studio.youtube.com" in blob
|
|
assert "host.docker.internal:7890" in blob
|
|
assert str(assets / "tampermonkey-seed") in blob or "tampermonkey-seed" in blob
|
|
assert "opsneko1:" in blob
|