重构物流客服模块并完善会话接待工作台
- 拆分应用工厂、业务服务与路由,保留原有 HTTP/SSE 和存储入口 - 分离页面资源,重排客服工作台并完善响应式导航、草稿和附件交互 - 整理维护脚本、请求示例和贡献指南,移除启动脚本中的密钥配置 - 上传文件改为仅本地保留,补充隔离的后端与前端回归验证 验证:46 项 Python 测试通过,含 14 个已有子测试;12 个 Node 前端场景通过。
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
"""Exercise the Windows startup entry point without installing or serving anything."""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import venv
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
@unittest.skipUnless(os.name == "nt", "Windows batch entry point")
|
||||
class StartupInterpreterTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.directory.cleanup)
|
||||
self.sandbox = Path(self.directory.name)
|
||||
self.repository = self.sandbox / "project with spaces & sign"
|
||||
self.repository.mkdir()
|
||||
shutil.copy2(ROOT / "start.bat", self.repository / "start.bat")
|
||||
self.commands = self.sandbox / "commands"
|
||||
self.commands.mkdir()
|
||||
self.other_directory = self.sandbox / "elsewhere"
|
||||
self.other_directory.mkdir()
|
||||
self.system_directory = Path(os.environ["SystemRoot"]) / "System32"
|
||||
self.environment = os.environ.copy()
|
||||
for name in ("VIRTUAL_ENV", "PYTHONHOME", "PYTHONPATH", "PYLAUNCHER_DRYRUN"):
|
||||
self.environment.pop(name, None)
|
||||
self.environment["PYTHONUTF8"] = "1"
|
||||
self.environment["PATH"] = os.pathsep.join(
|
||||
str(path) for path in (
|
||||
self.commands, Path(sys.executable).parent, self.system_directory,
|
||||
)
|
||||
)
|
||||
|
||||
def create_environment(self, directory):
|
||||
venv.EnvBuilder(with_pip=False).create(directory)
|
||||
return directory / "Scripts" / "python.exe"
|
||||
|
||||
def create_failed_candidate(self, destination):
|
||||
# A real signed Windows executable that rejects Python's command-line flags.
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(self.system_directory / "where.exe", destination)
|
||||
|
||||
def diagnose(self):
|
||||
executable = os.environ.get("COMSPEC", str(self.system_directory / "cmd.exe"))
|
||||
command = (
|
||||
subprocess.list2cmdline([executable])
|
||||
+ ' /d /v:off /c ""'
|
||||
+ str(self.repository / "start.bat")
|
||||
+ '" --check-python"'
|
||||
)
|
||||
return subprocess.run(
|
||||
command,
|
||||
cwd=self.other_directory,
|
||||
env=self.environment,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
timeout=15,
|
||||
)
|
||||
|
||||
def assert_selected(self, expected):
|
||||
result = self.diagnose()
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertEqual(
|
||||
os.path.normcase(str(Path(result.stdout.strip()).resolve())),
|
||||
os.path.normcase(str(expected.resolve())),
|
||||
)
|
||||
return result
|
||||
|
||||
def test_active_environment_precedes_project_environment(self):
|
||||
active = self.sandbox / "active env ! & sign"
|
||||
expected = self.create_environment(active)
|
||||
self.create_environment(self.repository / ".venv")
|
||||
self.environment["VIRTUAL_ENV"] = str(active)
|
||||
self.assert_selected(expected)
|
||||
|
||||
def test_project_environment_is_used_when_no_environment_is_active(self):
|
||||
expected = self.create_environment(self.repository / ".venv")
|
||||
self.assert_selected(expected)
|
||||
|
||||
def test_failed_active_environment_falls_back_to_project_environment(self):
|
||||
active = self.sandbox / "failed active environment"
|
||||
self.create_failed_candidate(active / "Scripts" / "python.exe")
|
||||
expected = self.create_environment(self.repository / ".venv")
|
||||
self.environment["VIRTUAL_ENV"] = str(active)
|
||||
self.assert_selected(expected)
|
||||
|
||||
def test_failed_project_environment_falls_back_to_path_python(self):
|
||||
self.create_failed_candidate(self.repository / ".venv" / "Scripts" / "python.exe")
|
||||
self.create_failed_candidate(self.commands / "py.exe")
|
||||
self.assert_selected(Path(sys.executable))
|
||||
|
||||
def test_failed_launcher_falls_back_to_path_python_without_launcher_flags(self):
|
||||
self.create_failed_candidate(self.commands / "py.exe")
|
||||
self.assert_selected(Path(sys.executable))
|
||||
|
||||
def test_no_working_interpreter_reports_failure_without_pausing(self):
|
||||
self.create_failed_candidate(self.commands / "py.exe")
|
||||
self.create_failed_candidate(self.commands / "python.exe")
|
||||
self.environment["PATH"] = os.pathsep.join(
|
||||
(str(self.commands), str(self.system_directory))
|
||||
)
|
||||
result = self.diagnose()
|
||||
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
|
||||
self.assertIn("No working Python 3 interpreter", result.stdout)
|
||||
|
||||
def test_diagnostic_mode_leaves_no_application_files(self):
|
||||
self.create_failed_candidate(self.commands / "py.exe")
|
||||
self.environment.pop("DEEPSEEK_API_KEY", None)
|
||||
self.assert_selected(Path(sys.executable))
|
||||
self.assertEqual({path.name for path in self.repository.iterdir()}, {"start.bat"})
|
||||
self.assertEqual(list(self.other_directory.iterdir()), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user