refactor(fudai): 拆出 just_recorded_reservation + skip_stage_diagnosis 早返回(2661→2602,-59 行)

把 run_once_basic 中两个互相独立的早返回块抽到 fudai_run_blocks:
- handle_just_recorded_reservation:刚记录预约后按 needswitch 决定是否上滑切换
- handle_skip_stage_diagnosis:跳过阶段检测标志触发时直接查找福袋

新增 7 个单元测试,1127 → 1134 用例全过。

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:56:49 +08:00
1 parent 41fc4ecbe0
commit 3473e2bd5e
3 files changed
+146 -62

No files matched your search

+57
View File
@@ -465,3 +465,60 @@ def test_clear_queue_swallows_log_exceptions():
# 应不抛错
fudai_run_blocks.maybe_clear_reservation_queue_on_first_run(a)
assert a.reservations == []
# ---- handle_just_recorded_reservation ---- #
def test_just_recorded_not_set_returns_false():
a = _make_analyser()
a._just_recorded_reservation = False
assert fudai_run_blocks.handle_just_recorded_reservation(a, time.time()) is False
def test_just_recorded_with_switch_swipes_up():
a = _make_analyser()
a._just_recorded_reservation = True
a.needswitch = True
assert fudai_run_blocks.handle_just_recorded_reservation(a, time.time()) is True
a.swipe_up_to_next_live.assert_called_once()
assert a._just_recorded_reservation is False
def test_just_recorded_no_switch_skips_swipe():
a = _make_analyser()
a._just_recorded_reservation = True
a.needswitch = False
assert fudai_run_blocks.handle_just_recorded_reservation(a, time.time()) is True
a.swipe_up_to_next_live.assert_not_called()
def test_just_recorded_swipe_failure_still_returns_true():
a = _make_analyser()
a._just_recorded_reservation = True
a.needswitch = True
a.swipe_up_to_next_live.side_effect = RuntimeError("boom")
assert fudai_run_blocks.handle_just_recorded_reservation(a, time.time()) is True
# ---- handle_skip_stage_diagnosis ---- #
def test_skip_stage_diag_not_set_returns_false():
a = _make_analyser()
a._skip_stage_diagnosis_and_find_fudai = False
assert fudai_run_blocks.handle_skip_stage_diagnosis(a, time.time()) is False
def test_skip_stage_diag_set_calls_handler_and_clears_flag():
a = _make_analyser()
a._skip_stage_diagnosis_and_find_fudai = True
a._handle_live_room_has_or_not_fudai = MagicMock()
assert fudai_run_blocks.handle_skip_stage_diagnosis(a, time.time()) is True
a._handle_live_room_has_or_not_fudai.assert_called_once()
assert a._skip_stage_diagnosis_and_find_fudai is False
def test_skip_stage_diag_handler_failure_still_returns_true():
a = _make_analyser()
a._skip_stage_diagnosis_and_find_fudai = True
a._handle_live_room_has_or_not_fudai = MagicMock(side_effect=RuntimeError("boom"))
assert fudai_run_blocks.handle_skip_stage_diagnosis(a, time.time()) is True