Reduce fudai detection overhead

This commit is contained in:
Your Name committed 2026-06-19 19:16:25 +08:00
1 parent 58c1856fad
commit b3d3f28ff3
4 files changed
+117 -161

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
from __future__ import annotations
class _FakeOperation:
def __init__(self, log_path):
self._screenshot_log_path = str(log_path)
self._screenshot_call_cache = []
def _get_screenshot_direct(self, _device_id, _path):
return True
def test_screenshot_trace_is_off_by_default(tmp_path, monkeypatch):
from douyin.core.underlying_operations_pkg.screenshot_pipeline import get_screenshot
monkeypatch.delenv("DOUYIN_SCREENSHOT_TRACE", raising=False)
op = _FakeOperation(tmp_path / "screenshot_calls.jsonl")
assert get_screenshot(op, "device1") is True
assert not (tmp_path / "screenshot_calls.jsonl").exists()
assert op._screenshot_call_cache == []
assert op._screenshot_trace_disabled_logged is True
def test_screenshot_trace_can_be_enabled_for_diagnostics(tmp_path, monkeypatch):
from douyin.core.underlying_operations_pkg.screenshot_pipeline import get_screenshot
monkeypatch.setenv("DOUYIN_SCREENSHOT_TRACE", "1")
op = _FakeOperation(tmp_path / "screenshot_calls.jsonl")
assert get_screenshot(op, "device1", path="pic") is True
lines = (tmp_path / "screenshot_calls.jsonl").read_text(encoding="utf-8").splitlines()
assert len(lines) == 2
assert '"phase": "start"' in lines[0]
assert '"phase": "end"' in lines[1]
assert len(op._screenshot_call_cache) == 2