|
10 | 10 | import httpx |
11 | 11 | import pytest |
12 | 12 |
|
| 13 | +from astrbot.core import updator as core_updator |
13 | 14 | from astrbot.core.star.updator import PluginUpdator |
14 | 15 | from astrbot.core.updator import AstrBotUpdator |
15 | 16 | from astrbot.core.utils import io as io_utils |
@@ -80,6 +81,60 @@ def raise_for_status(self) -> None: |
80 | 81 | ) |
81 | 82 |
|
82 | 83 |
|
| 84 | +def test_astrbot_updator_exec_reboot_spawns_new_console_on_windows( |
| 85 | + monkeypatch: pytest.MonkeyPatch, |
| 86 | +): |
| 87 | + popen_calls = [] |
| 88 | + exit_codes = [] |
| 89 | + execv_calls = [] |
| 90 | + |
| 91 | + def fake_popen(args, creationflags=0): |
| 92 | + popen_calls.append((args, creationflags)) |
| 93 | + return SimpleNamespace(pid=1234) |
| 94 | + |
| 95 | + def fake_exit(code): |
| 96 | + exit_codes.append(code) |
| 97 | + raise SystemExit(code) |
| 98 | + |
| 99 | + def fake_execv(*args): |
| 100 | + execv_calls.append(args) |
| 101 | + |
| 102 | + monkeypatch.setattr(core_updator.os, "name", "nt") |
| 103 | + monkeypatch.setattr(core_updator.sys, "frozen", False, raising=False) |
| 104 | + monkeypatch.setattr( |
| 105 | + core_updator.subprocess, "CREATE_NEW_CONSOLE", 0x00000010, raising=False |
| 106 | + ) |
| 107 | + monkeypatch.setattr(core_updator.subprocess, "Popen", fake_popen) |
| 108 | + monkeypatch.setattr(core_updator.os, "_exit", fake_exit) |
| 109 | + monkeypatch.setattr(core_updator.os, "execv", fake_execv) |
| 110 | + |
| 111 | + with pytest.raises(SystemExit) as exc_info: |
| 112 | + AstrBotUpdator._exec_reboot( |
| 113 | + r"C:\Python312\python.exe", |
| 114 | + [ |
| 115 | + r"C:\Python312\python.exe", |
| 116 | + "main.py", |
| 117 | + "--webui-dir", |
| 118 | + r"C:\AstrBot WebUI\dist", |
| 119 | + ], |
| 120 | + ) |
| 121 | + |
| 122 | + assert exc_info.value.code == 0 |
| 123 | + assert popen_calls == [ |
| 124 | + ( |
| 125 | + [ |
| 126 | + r"C:\Python312\python.exe", |
| 127 | + "main.py", |
| 128 | + "--webui-dir", |
| 129 | + r"C:\AstrBot WebUI\dist", |
| 130 | + ], |
| 131 | + core_updator.subprocess.CREATE_NEW_CONSOLE, |
| 132 | + ) |
| 133 | + ] |
| 134 | + assert exit_codes == [0] |
| 135 | + assert execv_calls == [] |
| 136 | + |
| 137 | + |
83 | 138 | @dataclass |
84 | 139 | class _FakeAsyncClientState: |
85 | 140 | json_payload: object = field(default_factory=list) |
|
0 commit comments