diff --git a/douyin/core/fudai_modules/live_room_handlers.py b/douyin/core/fudai_modules/live_room_handlers.py index 9a237d1..2b1d390 100644 --- a/douyin/core/fudai_modules/live_room_handlers.py +++ b/douyin/core/fudai_modules/live_room_handlers.py @@ -145,6 +145,12 @@ def handle_live_room_has_or_not_fudai(self: "fudai_analyse") -> None: room_pos_ref: List[int] = [0] opened = douyin_flow_control.find_and_open_fudai_detail(self, room_pos_ref) if not opened: + try: + self._current_fudai_content = "" + self._last_fudai_detail_tuple = None + self._fudai_detail_first_read = False + except Exception: + pass try: need_switch_config = bool(getattr(self, "needswitch", True)) except Exception: diff --git a/douyin/handlers/douyin_swipe_handler.py b/douyin/handlers/douyin_swipe_handler.py index 1337525..01c3da4 100644 --- a/douyin/handlers/douyin_swipe_handler.py +++ b/douyin/handlers/douyin_swipe_handler.py @@ -177,6 +177,7 @@ class SwipeHandler: try: analyser._fudai_detail_first_read = False analyser._last_fudai_detail_tuple = None + analyser._current_fudai_content = "" except Exception: pass diff --git a/tests/test_handlers.py b/tests/test_handlers.py index d34f824..3037d42 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -119,6 +119,30 @@ class TestSwipeHandler: assert int(getattr(a, "room_pos", 0) or 0) == 5 assert bool(getattr(a, "_record_title_before_swipe_up", False)) is False + def test_swipe_up_clears_fudai_content_cache(self): + """切换直播间后不应把上一房福袋内容带到下一房映射表。""" + from douyin.handlers.douyin_swipe_handler import SwipeHandler + + class _A: + pass + + a = _A() + a.reservation_focus_until_ts = 0.0 + a._skip_record_title_during_seek = True + a.room_pos = 1 + a.device_id = "MOCK" + a._log_kv = MagicMock(return_value=None) + a._current_fudai_content = "上一房福袋" + a._last_fudai_detail_tuple = ("old",) + a._fudai_detail_first_read = True + + with patch("douyin.handlers.douyin_swipe_ops.swipe_up_switch_live"): + SwipeHandler.swipe_up_to_next_live(a) + + assert a._current_fudai_content == "" + assert a._last_fudai_detail_tuple is None + assert a._fudai_detail_first_read is False + def test_reset_to_top_keep_mapping_does_not_clear_map(self): """回顶后应保留运行时映射表。""" from douyin.handlers.douyin_swipe_handler import SwipeHandler diff --git a/tests/test_record_title_mapping.py b/tests/test_record_title_mapping.py index 1266f9e..b66d883 100644 --- a/tests/test_record_title_mapping.py +++ b/tests/test_record_title_mapping.py @@ -152,3 +152,24 @@ def test_pending_reservation_target_not_overwritten_after_failed_seek(): assert a._room_pos_to_title_map[2]["fudai_content"] == "新款小型电动车" messages = [call.args[1] for call in a._log_kv.call_args_list if len(call.args) > 1] assert any("跳过映射表覆盖" in msg for msg in messages) + + +def test_no_fudai_room_mapping_does_not_inherit_previous_fudai_content(): + from douyin.reservation.douyin_reservation_handler_pkg import record_title as mod + + a = _mk_analyser() + a.room_pos = 5 + a.current_room_title = "新直播间" + a.current_room_title_raw = "新直播间" + a._room_title_identified_positions = {5} + a._current_fudai_content = "" + a._last_fudai_detail_tuple = None + + with patch.object(mod, "_dump_room_pos_map_to_state", return_value=None): + consumed = mod.record_room_title_and_pos(a) + + assert consumed is False + info = a._room_pos_to_title_map[5] + assert info["has_fudai"] is False + assert info["fudai_content"] == "" + assert info["fudai_detail"] is None