From be95d9c2790ff888bebfe41617c1a96a0fc602cf Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 03:38:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8B=86=E5=87=BA=20=5Fhand?= =?UTF-8?q?le=5Fin=5Ffudai=5Fdetail=20=E5=85=A5=E5=8F=A3=E8=AF=8A=E6=96=AD?= =?UTF-8?q?=E6=97=A5=E5=BF=97=EF=BC=881572=E2=86=921556=EF=BC=8C-16=20?= =?UTF-8?q?=E8=A1=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit log_entry_flags:进入 _handle_in_fudai_detail 时记录关键 flags 的诊断日志。 新增 2 个单元测试,1199 → 1201 用例全过。 Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 18 +-------------- .../core/fudai_modules/fudai_detail_blocks.py | 21 ++++++++++++++++++ tests/test_fudai_detail_blocks.py | 22 +++++++++++++++++++ 3 files changed, 44 insertions(+), 17 deletions(-) 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)