Clear runtime state at fudai startup
This commit is contained in:
1 parent
d4931b6820
commit
f129206df7
2 files changed
+136
-10
No files matched your search
@@ -13,6 +13,7 @@ import os
|
||||
import json
|
||||
import tempfile
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -201,6 +202,55 @@ class TestFudaiDetectionDefaults:
|
||||
assert analyser.pixel_detect_shopping_redpacket_enabled is True
|
||||
assert analyser.ocr_shopping_redpacket_enabled is False
|
||||
|
||||
def test_apply_defaults_clears_runtime_reservation_and_mapping_state(self, tmp_path, monkeypatch):
|
||||
from douyin.core import path_config
|
||||
from douyin.core.fudai_modules.init_helpers import apply_fudai_defaults
|
||||
|
||||
state_dir = tmp_path / "state"
|
||||
state_dir.mkdir()
|
||||
reservations_path = state_dir / "reservations.json"
|
||||
reservations_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"reason": "old_run",
|
||||
"room_pos": 9,
|
||||
"reservations": [
|
||||
{
|
||||
"future_ts": 9999999999.0,
|
||||
"content": "old",
|
||||
"pos_seen": 9,
|
||||
}
|
||||
],
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
for name, content in {
|
||||
"room_pos_map.json": '{"9": {"title": "old"}}',
|
||||
"room_pos_map.csv": "pos,title\n9,old\n",
|
||||
"room_pos_map.md": "| pos | title |\n| 9 | old |\n",
|
||||
}.items():
|
||||
(state_dir / name).write_text(content, encoding="utf-8")
|
||||
|
||||
monkeypatch.setattr(path_config, "get_reservations_path", lambda: str(reservations_path))
|
||||
|
||||
analyser = SimpleNamespace(
|
||||
_run_id="unit_run",
|
||||
_log_kv=MagicMock(return_value=None),
|
||||
)
|
||||
apply_fudai_defaults(analyser)
|
||||
|
||||
reservations = json.loads(reservations_path.read_text(encoding="utf-8"))
|
||||
assert reservations["reason"] == "startup_clear"
|
||||
assert reservations["reservations"] == []
|
||||
|
||||
room_map = json.loads((state_dir / "room_pos_map.json").read_text(encoding="utf-8"))
|
||||
assert room_map.get("_meta", {}).get("reason") == "startup_clear"
|
||||
assert [key for key in room_map.keys() if not str(key).startswith("_")] == []
|
||||
assert (state_dir / "room_pos_map.csv").read_text(encoding="utf-8").strip() == "pos,title,title_raw,has_fudai,fudai_content"
|
||||
assert "暂无映射" in (state_dir / "room_pos_map.md").read_text(encoding="utf-8")
|
||||
|
||||
def test_config_loader_defaults_shopping_redpacket_detection_enabled(self):
|
||||
from douyin.utils.douyin_config import ConfigManager
|
||||
|
||||
|
||||
Reference in new issue
Block a user