refactor(fudai): 拆出 _handle_in_fudai_detail 入口诊断日志(1572→1556,-16 行)

log_entry_flags:进入 _handle_in_fudai_detail 时记录关键 flags 的诊断日志。

新增 2 个单元测试,1199 → 1201 用例全过。

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 03:38:23 +08:00
1 parent 1b4dc477fd
commit be95d9c279
3 files changed
+44 -17

No files matched your search

+1 -17
View File
@@ -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)
# 注意:点击参与抽奖后会自动关闭详情页,下次循环会跳过阶段检测直接查找福袋
# 检查连续参与失败次数,避免卡死
@@ -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:
+22
View File
@@ -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)