"""gui/web_gui 的 import 冒烟测试。 老版本会真实启动 HTTP 服务并请求 /api/config,pytest 运行时会卡住。 重写为只验证模块能正常加载、关键属性存在;启动服务的端到端验证留给手动测试。 """ from __future__ import annotations def test_web_gui_module_importable(): """模块能 import,不抛异常。""" import gui.web_gui as wg # 关键符号存在 assert hasattr(wg, "main"), "gui.web_gui 应导出 main()" assert callable(wg.main) def test_web_gui_helper_functions(): """模块级 helper 应可调用。""" import gui.web_gui as wg assert callable(wg.read_config) assert callable(wg.find_adb_executable) assert callable(wg.list_adb_devices) # _wg_log 是项目里 print→logger 改造引入的内部 helper assert callable(wg._wg_log) def test_web_gui_log_helper_does_not_raise(): """_wg_log 不应抛异常。""" import gui.web_gui as wg wg._wg_log("[smoke] info") wg._wg_log("[smoke] warn", level="WARNING") wg._wg_log("[smoke] error", level="ERROR") def test_cleanup_orphan_processes_filters_by_owned_pid(monkeypatch): import gui.web_gui as wg runner = wg.ProcRunner() runner._owned_run_cli_pids = {111} monkeypatch.setattr( runner, "_list_project_run_cli_processes", lambda: [ (111, "python bin/run_cli.py --device-id A"), (222, "python bin/run_cli.py --device-id A"), ], ) killed: list[list[str]] = [] def _fake_run(cmd, **kwargs): # noqa: ARG001 killed.append(list(cmd)) class _Result: returncode = 0 return _Result() monkeypatch.setattr(wg.subprocess, "run", _fake_run) count = runner._cleanup_orphan_run_cli_processes("") assert count == 0 assert killed == []