refactor(fudai): 拆出截图重试块(2822→2783,-39 行)

把 run_once_basic 中 '截图 + 重试 + 失败诊断日志' 的 45 行块抽到
fudai_run_blocks.take_screenshot_with_retries:
- 失败时自动写入完整诊断日志(含 reservation flags / room_pos 等)
- 返回 (ok, elapsed);ok=False 时主流程直接 return

新增 4 个单元测试覆盖:首次成功 / 二次成功 / 全失败写诊断 / get_screenshot 抛错。
1119 → 1123 用例全过。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
CodexandClaude Opus 4.7 committed 2026-05-22 02:49:36 +08:00
1 parent 6cf3ce9a72
commit e6da24c2a6
3 files changed
+104 -42

No files matched your search

+39
View File
@@ -384,3 +384,42 @@ def test_in_live_room_logs_completion():
if len(c.args) >= 2 and "run_once_basic完成(处理直播间)" in c.args[1]
]
assert len(completion) == 1
# ---- take_screenshot_with_retries ---- #
def test_screenshot_success_first_try():
a = _make_analyser()
a.operation.get_screenshot.return_value = True
ok, elapsed = fudai_run_blocks.take_screenshot_with_retries(a, time.time())
assert ok is True
assert elapsed >= 0
def test_screenshot_success_second_try():
a = _make_analyser()
a.operation.get_screenshot.side_effect = [False, True]
ok, _ = fudai_run_blocks.take_screenshot_with_retries(a, time.time(), max_retries=3)
assert ok is True
# 重试一次,所以 delay 被调用一次
assert a.operation.delay.call_count == 1
def test_screenshot_all_retries_fail_logs_error():
a = _make_analyser()
a.operation.get_screenshot.return_value = False
ok, _ = fudai_run_blocks.take_screenshot_with_retries(a, time.time(), max_retries=3)
assert ok is False
# 应记录"获取截图失败(多次重试后仍失败)"
failure_logs = [
c for c in a._log_kv.call_args_list
if len(c.args) >= 2 and "获取截图失败" in c.args[1]
]
assert len(failure_logs) == 1
def test_screenshot_get_screenshot_exception_treated_as_false():
a = _make_analyser()
a.operation.get_screenshot.side_effect = RuntimeError("adb fail")
ok, _ = fudai_run_blocks.take_screenshot_with_retries(a, time.time(), max_retries=2)
assert ok is False