diff --git a/artifacts/webui_checks/20260601_port8003/summary.json b/artifacts/webui_checks/20260601_port8003/summary.json new file mode 100644 index 0000000..e74b37a --- /dev/null +++ b/artifacts/webui_checks/20260601_port8003/summary.json @@ -0,0 +1,15 @@ +{ + "console_errors": [ + { + "type": "error", + "text": "Failed to load resource: the server responded with a status of 422 (Unprocessable Entity)" + } + ], + "page_errors": [], + "screenshots": [ + "artifacts\\webui_checks\\20260601_port8003\\mobile_main.png" + ], + "checks": { + "has_unhandled_error": false + } +} \ No newline at end of file diff --git a/gui/components/mapping_table.py b/gui/components/mapping_table.py index b976f85..0b1b7ca 100644 --- a/gui/components/mapping_table.py +++ b/gui/components/mapping_table.py @@ -6,6 +6,8 @@ from tkinter import ttk from typing import Any, List from datetime import datetime +from douyin.core import path_config + try: from . import mapping_utils except Exception: @@ -174,11 +176,11 @@ def create_mapping_tab(root: tk.Tk, notebook: ttk.Notebook, cfg: dict) -> ttk.Fr # 读取预约队列与映射表(使用 mapping_utils 模块以实现模块化) try: + base_dir = path_config.get_project_root() + except Exception: base_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", "..") ) - except Exception: - base_dir = os.getcwd() # 尝试通过工具模块加载 reservations 信息 reservations_data = {} @@ -190,8 +192,7 @@ def create_mapping_tab(root: tk.Tk, notebook: ttk.Notebook, cfg: dict) -> ttk.Fr possible_paths = [ os.path.join(base_dir, "douyin", "core", "state", "room_pos_map.json"), - os.path.join(base_dir, "douyin", "core", "state", "reservations.json"), - os.path.join(os.getcwd(), "douyin", "core", "state", "room_pos_map.json"), + path_config.get_reservations_path(), ] found = False diff --git a/gui/components/mapping_utils.py b/gui/components/mapping_utils.py index 6cb8cb7..60eeb1b 100644 --- a/gui/components/mapping_utils.py +++ b/gui/components/mapping_utils.py @@ -3,21 +3,21 @@ import os from datetime import datetime from typing import Any, Dict, List, Tuple +from douyin.core import path_config + def load_reservations(base_dir: str | None = None) -> Dict[int, Any]: """加载 reservations.json 并返回以 pos_seen 为键的映射字典。""" if not base_dir: try: - base_dir = os.path.abspath( - os.path.join(os.path.dirname(__file__), "..", "..") - ) + base_dir = path_config.get_project_root() except Exception: - base_dir = os.getcwd() + base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) reservations_data: Dict[int, Any] = {} reservations_paths = [ + path_config.get_reservations_path(), os.path.join(base_dir, "douyin", "core", "state", "reservations.json"), - os.path.join(os.getcwd(), "douyin", "core", "state", "reservations.json"), ] for res_path in reservations_paths: try: diff --git a/tests/test_gui_components.py b/tests/test_gui_components.py index b7c140f..be24422 100644 --- a/tests/test_gui_components.py +++ b/tests/test_gui_components.py @@ -128,6 +128,25 @@ class TestMappingUtils: assert callable(parse_entries) + def test_load_reservations_prefers_path_config(self): + import inspect + from gui.components import mapping_utils + + src = inspect.getsource(mapping_utils.load_reservations) + assert "path_config.get_reservations_path()" in src + assert "os.getcwd()" not in src + + +class TestMappingTablePaths: + def test_mapping_table_no_cwd_fallback(self): + import inspect + from gui.components import mapping_table + + src = inspect.getsource(mapping_table.create_mapping_tab) + assert "path_config.get_project_root()" in src + assert "path_config.get_reservations_path()" in src + assert "os.getcwd()" not in src + class TestGuiComponentsModules: """gui/components 模块存在性测试。""" diff --git a/tests/test_runtime_path_anchors.py b/tests/test_runtime_path_anchors.py index 831b289..5282924 100644 --- a/tests/test_runtime_path_anchors.py +++ b/tests/test_runtime_path_anchors.py @@ -166,3 +166,16 @@ class TestPathConfigAnchorsToProjectRoot: actions = os.path.normpath(path_config.get_actions_log_path()) assert actions.endswith(os.path.join("logs", "actions.log")) + + +class TestGuiMappingPaths: + def test_mapping_table_no_getcwd_anchor(self): + src = _read("gui", "components", "mapping_table.py") + assert "os.getcwd()" not in src + assert "path_config.get_project_root()" in src + assert "path_config.get_reservations_path()" in src + + def test_mapping_utils_no_getcwd_anchor(self): + src = _read("gui", "components", "mapping_utils.py") + assert "os.getcwd()" not in src + assert "path_config.get_reservations_path()" in src