refactor(reservation): 拆出回退成功后的锁定期 + 完成日志(530→467,-63 行)
enter_lock_period_and_log_success:进入锁定期 + 写运行日志 + 行为日志 + 状态文件 + 完成日志,把回退成功后的所有善后动作集中处理。 新增 3 个单元测试,1343 → 1346 用例全过。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
30a66e955c
commit
c4b6a8e5f0
3 files changed
+154
-81
No files matched your search
@@ -856,3 +856,50 @@ def test_decide_retry_seek_correction_up_direction():
|
||||
target = {}
|
||||
h._decide_retry_seek(a, target, 5, 5, 2) # 2 < 5
|
||||
assert target["_seek_direction_hint"] == "up"
|
||||
|
||||
|
||||
# ---- enter_lock_period_and_log_success ---- #
|
||||
|
||||
def test_enter_lock_period_sets_focus_and_pending():
|
||||
a = MagicMock()
|
||||
focus_ref = [0.0]
|
||||
pending_ref = [False]
|
||||
write_cb = MagicMock()
|
||||
h.enter_lock_period_and_log_success(
|
||||
a, target={"pos_seen": 5}, target_room_title="标题", target_room_title_raw="raw",
|
||||
target_content="内容", target_value=99.9,
|
||||
ft=1700000100.0, now_ts=1700000050.0, poll_before=10.0,
|
||||
start_time=time.time(), reservation_focus_until_ts_ref=focus_ref,
|
||||
reservation_after_action_pending_ref=pending_ref,
|
||||
write_state_callback=write_cb, now_ts_func=lambda: 1700000050.0,
|
||||
)
|
||||
assert focus_ref[0] == 1700000110.0 # ft + poll_before
|
||||
assert pending_ref[0] is True
|
||||
write_cb.assert_called_once()
|
||||
|
||||
|
||||
def test_enter_lock_period_appends_to_empty_refs():
|
||||
a = MagicMock()
|
||||
focus_ref = []
|
||||
pending_ref = []
|
||||
h.enter_lock_period_and_log_success(
|
||||
a, target={}, target_room_title="", target_room_title_raw="", target_content="",
|
||||
target_value=0.0, ft=1700000100.0, now_ts=0, poll_before=10.0,
|
||||
start_time=time.time(), reservation_focus_until_ts_ref=focus_ref,
|
||||
reservation_after_action_pending_ref=pending_ref,
|
||||
write_state_callback=MagicMock(), now_ts_func=lambda: 0,
|
||||
)
|
||||
assert focus_ref == [1700000110.0]
|
||||
assert pending_ref == [True]
|
||||
|
||||
|
||||
def test_enter_lock_period_swallows_log_exception():
|
||||
a = MagicMock()
|
||||
a._log_kv.side_effect = RuntimeError("boom")
|
||||
h.enter_lock_period_and_log_success(
|
||||
a, target={}, target_room_title="", target_room_title_raw="", target_content="",
|
||||
target_value=0.0, ft=0, now_ts=0, poll_before=0,
|
||||
start_time=time.time(), reservation_focus_until_ts_ref=[0.0],
|
||||
reservation_after_action_pending_ref=[False],
|
||||
write_state_callback=MagicMock(), now_ts_func=lambda: 0,
|
||||
)
|
||||
Reference in new issue
Block a user