refactor(fudai): 拆出 IN_LIVE_ROOM + RECOMMEND_PAGE stage 处理(2915→2822,-93 行)

把 run_once_basic 中两个 stage 分支抽到 fudai_run_blocks:
- handle_in_live_room_stage:等待福袋加载(如刚切换)+ 查找福袋
- handle_recommend_page_stage:点击直播页 + 进入直播间(连点两次)

新增 5 个单元测试覆盖:刚切换 / 未切换 / 点击失败回退 / 完成日志。
1114 → 1119 用例全过。

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:46:21 +08:00
1 parent 992db1e161
commit 6cf3ce9a72
3 files changed
+164 -95

No files matched your search

+66
View File
@@ -318,3 +318,69 @@ def test_live_closed_swipes_to_next_and_logs_completion():
if len(c.args) >= 2 and "run_once_basic完成(直播结束)" in c.args[1]
]
assert len(completion) == 1
# ---- handle_recommend_page_stage ---- #
def _make_recommend_analyser():
a = _make_analyser()
a.resolution_ratio_x = 1080
a.resolution_ratio_y = 2400
a.FOLLOW_TAB_CLICK_DELAY = 0.5
a.ENTER_LIVE_CLICK_DELAY = 0.6
a.ENTER_LIVE_FINAL_DELAY = 1.0
a.RETURN_STEP_DELAY_SECONDS = 0.8
return a
def test_recommend_page_clicks_live_tab_and_enter_live_twice():
a = _make_recommend_analyser()
fudai_run_blocks.handle_recommend_page_stage(a, "RECOMMEND_PAGE", "")
# 点击次数:直播页 1 + 直播间 2 = 3
assert a.operation.click.call_count == 3
def test_recommend_page_handles_click_failure():
a = _make_recommend_analyser()
a.operation.click.side_effect = RuntimeError("boom")
fudai_run_blocks.handle_recommend_page_stage(a, "RECOMMEND_PAGE", "")
# 异常时 fallback 调用 click_back
a.operation.click_back.assert_called_once()
# ---- handle_in_live_room_stage ---- #
def test_in_live_room_no_just_switched_calls_handler():
a = _make_analyser()
a._just_switched_room = False
a._handle_live_room_has_or_not_fudai = MagicMock()
fudai_run_blocks.handle_in_live_room_stage(a, "IN_LIVE_ROOM", time.time())
a._handle_live_room_has_or_not_fudai.assert_called_once()
# 不应该调用 delay(没切换不需要等加载)
a.operation.delay.assert_not_called()
def test_in_live_room_just_switched_waits_for_load():
a = _make_analyser()
a._just_switched_room = True
a.switch_room_wait_after_stage_diag_seconds = 5.0
a._handle_live_room_has_or_not_fudai = MagicMock()
fudai_run_blocks.handle_in_live_room_stage(a, "IN_LIVE_ROOM", time.time())
# 应当 delay(5.0)
delays = [c.args[0] for c in a.operation.delay.call_args_list]
assert 5.0 in delays
# 标志已清除
assert a._just_switched_room is False
a._handle_live_room_has_or_not_fudai.assert_called_once()
def test_in_live_room_logs_completion():
a = _make_analyser()
a._just_switched_room = False
a._handle_live_room_has_or_not_fudai = MagicMock()
fudai_run_blocks.handle_in_live_room_stage(a, "LIVE_OR_UNKNOWN", time.time())
completion = [
c for c in a._log_kv.call_args_list
if len(c.args) >= 2 and "run_once_basic完成(处理直播间)" in c.args[1]
]
assert len(completion) == 1