refactor(paths): remove cwd-based mapping path fallbacks
This commit is contained in:
1 parent
37f736c158
commit
de21921d03
5 files changed
+57
-9
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 模块存在性测试。"""
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user