refactor(fudai): 拆出 _handle_in_fudai_detail 详情为None早返回(3687→3663,-24 行)
handle_detail_is_none:detail==None 时清除任务数量标志 + 写完成日志 + 早返回。 新增 3 个单元测试,1068 → 1071 用例全过。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
18c6f7b025
commit
b6cd3ac8a3
3 files changed
+70
-26
No files matched your search
@@ -3304,32 +3304,8 @@ class fudai_analyse:
|
||||
step4_start = time.time()
|
||||
# 执行参与决策
|
||||
if detail is None:
|
||||
try:
|
||||
self._log_kv("参与", "详情数据为 None,无法执行参与决策")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 清除任务数量标志
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail完成(详情为None)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
)
|
||||
return
|
||||
if fudai_detail_blocks.handle_detail_is_none(self, start_time):
|
||||
return
|
||||
join_result = douyin_fudai_core.basic_join_decision(
|
||||
self, detail, (skip, skip_reason)
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
|
||||
@@ -68,3 +69,38 @@ def handle_too_many_consecutive_failures(
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
|
||||
|
||||
def handle_detail_is_none(analyser: Any, start_time: float) -> bool:
|
||||
"""步骤4 入口:detail 为 None 时清除任务数量标志并提前 return。
|
||||
|
||||
返回 True 表示已处理 None 分支,主流程应 return。
|
||||
"""
|
||||
try:
|
||||
analyser._log_kv("参与", "详情数据为 None,无法执行参与决策")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
analyser._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
elapsed = time.time() - start_time
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail完成(详情为None)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
@@ -61,3 +61,35 @@ def test_close_detail_failure_does_not_break():
|
||||
result = fudai_detail_blocks.handle_too_many_consecutive_failures(a)
|
||||
assert result is True
|
||||
a.swipe_up_to_next_live.assert_called_once()
|
||||
|
||||
|
||||
# ---- handle_detail_is_none ---- #
|
||||
|
||||
import time as _time
|
||||
|
||||
|
||||
def test_detail_is_none_returns_true_and_clears_task_count():
|
||||
a = MagicMock()
|
||||
a._log_kv = MagicMock()
|
||||
a._fudai_detail_task_count_from_stage = 5
|
||||
result = fudai_detail_blocks.handle_detail_is_none(a, _time.time() - 1.0)
|
||||
assert result is True
|
||||
assert a._fudai_detail_task_count_from_stage is None
|
||||
|
||||
|
||||
def test_detail_is_none_logs_completion():
|
||||
a = MagicMock()
|
||||
a._log_kv = MagicMock()
|
||||
fudai_detail_blocks.handle_detail_is_none(a, _time.time() - 0.5)
|
||||
# 至少调用了 3 次:详情为None / 清除标志 / 完成日志
|
||||
assert a._log_kv.call_count >= 2
|
||||
|
||||
|
||||
def test_detail_is_none_swallows_log_exceptions():
|
||||
"""_log_kv 抛错也不应传播"""
|
||||
a = MagicMock()
|
||||
a._log_kv.side_effect = RuntimeError("boom")
|
||||
a._fudai_detail_task_count_from_stage = 5
|
||||
# 应当不抛错
|
||||
result = fudai_detail_blocks.handle_detail_is_none(a, _time.time())
|
||||
assert result is True
|
||||
Reference in new issue
Block a user