diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index d9718f0..ac32567 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1237,23 +1237,7 @@ class fudai_analyse: def _handle_in_fudai_detail(self) -> None: """已经在福袋详情页:只跑详情识别 + 是否参与的基础逻辑。""" start_time = time.time() - try: - self._log_kv( - "诊断", - "进入 _handle_in_fudai_detail:记录当前关键 flags", - reservation_after_action_pending=bool( - getattr(self, "reservation_after_action_pending", False) - ), - reservation_focus_until_ts=float( - getattr(self, "reservation_focus_until_ts", 0.0) or 0.0 - ), - waiting_for_lottery=bool( - getattr(self, "_waiting_for_lottery_result", False) - ), - room_pos=int(getattr(self, "room_pos", 0) or 0), - ) - except Exception: - pass + fudai_detail_blocks.log_entry_flags(self) # 注意:点击参与抽奖后会自动关闭详情页,下次循环会跳过阶段检测直接查找福袋 # 检查连续参与失败次数,避免卡死 diff --git a/douyin/core/fudai_modules/fudai_detail_blocks.py b/douyin/core/fudai_modules/fudai_detail_blocks.py index b4beb09..855504b 100644 --- a/douyin/core/fudai_modules/fudai_detail_blocks.py +++ b/douyin/core/fudai_modules/fudai_detail_blocks.py @@ -397,6 +397,27 @@ def handle_second_open_attend(analyser: Any, start_time: float, step1_start: flo return False +def log_entry_flags(analyser: Any) -> None: + """记录进入 _handle_in_fudai_detail 时的关键 flags 诊断日志。""" + try: + analyser._log_kv( + "诊断", + "进入 _handle_in_fudai_detail:记录当前关键 flags", + reservation_after_action_pending=bool( + getattr(analyser, "reservation_after_action_pending", False) + ), + reservation_focus_until_ts=float( + getattr(analyser, "reservation_focus_until_ts", 0.0) or 0.0 + ), + waiting_for_lottery=bool( + getattr(analyser, "_waiting_for_lottery_result", False) + ), + room_pos=int(getattr(analyser, "room_pos", 0) or 0), + ) + except Exception: + pass + + def handle_too_many_consecutive_failures( analyser: Any, max_consecutive_failures: int = 5 ) -> bool: diff --git a/tests/test_fudai_detail_blocks.py b/tests/test_fudai_detail_blocks.py index 8ad60ab..8217cd0 100644 --- a/tests/test_fudai_detail_blocks.py +++ b/tests/test_fudai_detail_blocks.py @@ -701,3 +701,25 @@ def test_attend_success_swallows_exception(): ) # remain_seconds=0,应该返回 False assert result is False + + +# ---- log_entry_flags ---- # + +def test_log_entry_flags_writes_one_line(): + a = MagicMock() + a.reservation_after_action_pending = True + a.reservation_focus_until_ts = 12345.6 + a._waiting_for_lottery_result = False + a.room_pos = 7 + fudai_detail_blocks.log_entry_flags(a) + assert a._log_kv.call_count == 1 + args, kwargs = a._log_kv.call_args + assert args[0] == "诊断" + assert kwargs["room_pos"] == 7 + assert kwargs["reservation_after_action_pending"] is True + + +def test_log_entry_flags_swallows_exception(): + a = MagicMock() + a._log_kv.side_effect = RuntimeError("boom") + fudai_detail_blocks.log_entry_flags(a)