keep reservation after coupon popup during direct attend
This commit is contained in:
1 parent
2b12ddbec3
commit
e41796d43a
2 files changed
+57
No files matched your search
@@ -203,6 +203,15 @@ def _reset_direct_attend_failure_count(analyser: Any, item: Dict[str, Any]) -> N
|
||||
pass
|
||||
|
||||
|
||||
def _coupon_guard_closed_during_direct_attend(analyser: Any, since_ts: float) -> bool:
|
||||
"""Return True if fudai finder just closed a coupon popup during direct attend."""
|
||||
try:
|
||||
last_ts = float(getattr(analyser, "_last_coupon_guard_back_ts", 0.0) or 0.0)
|
||||
except Exception:
|
||||
return False
|
||||
return last_ts > 0 and last_ts >= float(since_ts or 0.0)
|
||||
|
||||
|
||||
def _write_reservations_state_if_possible(analyser: Any, reason: str) -> None:
|
||||
try:
|
||||
state_path = getattr(analyser, "_reservations_state_path", "") or path_config.get_reservations_path()
|
||||
@@ -660,6 +669,27 @@ def handle_reservation_direct_attend(analyser: Any) -> None:
|
||||
pass
|
||||
|
||||
if not opened:
|
||||
if _coupon_guard_closed_during_direct_attend(analyser, open_start_ts):
|
||||
_log_direct_attend_marker(
|
||||
analyser,
|
||||
"recoverable",
|
||||
reason="coupon_popup_closed_before_fudai_click",
|
||||
future_ts=int(future_ts),
|
||||
remain_seconds=(
|
||||
int(max(0, future_ts - time.time())) if future_ts > 0 else 0
|
||||
),
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 预约直参期间关闭了优惠券弹窗,保留预约并等待下一轮稳定重试",
|
||||
reason="coupon_popup_closed_before_fudai_click",
|
||||
future_ts=int(future_ts),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
_clear_direct_attend_flags(analyser)
|
||||
return
|
||||
_log_direct_attend_marker(analyser, "fallback", reason="fudai_icon_not_found")
|
||||
failure_count = _record_direct_attend_failure(
|
||||
analyser,
|
||||
|
||||
@@ -229,6 +229,33 @@ def test_direct_attend_icon_not_found_does_not_enter_detail_handler():
|
||||
assert marker_logs
|
||||
|
||||
|
||||
def test_direct_attend_keeps_reservation_after_coupon_guard_close():
|
||||
from douyin.reservation.douyin_reservation_handler_pkg.direct_attend import (
|
||||
handle_reservation_direct_attend,
|
||||
)
|
||||
|
||||
analyser = _mk_analyser()
|
||||
analyser._current_attending_reservation_fudai = True
|
||||
analyser.reservation_direct_attend_max_failures = 1
|
||||
|
||||
def _finder(_analyser, *_args, **_kwargs):
|
||||
_analyser._last_coupon_guard_back_ts = time.time()
|
||||
return False
|
||||
|
||||
with patch(
|
||||
"douyin.core.douyin_flow_control.find_and_open_fudai_detail",
|
||||
side_effect=_finder,
|
||||
):
|
||||
handle_reservation_direct_attend(analyser)
|
||||
|
||||
analyser._handle_in_fudai_detail.assert_not_called()
|
||||
assert analyser.reservation_after_action_pending is False
|
||||
assert analyser._current_attending_reservation_fudai is False
|
||||
assert analyser.reservations
|
||||
assert not hasattr(analyser, "_reservation_direct_attend_failures")
|
||||
assert _has_log_reason(analyser, "coupon_popup_closed_before_fudai_click")
|
||||
|
||||
|
||||
def test_direct_attend_empty_reservations_clears_flags_without_detail_handler():
|
||||
from douyin.reservation.douyin_reservation_handler_pkg.direct_attend import (
|
||||
handle_reservation_direct_attend,
|
||||
|
||||
Reference in new issue
Block a user