fix(gateway): handle Windows stop fallback

This commit is contained in:
xcao
2026-07-04 21:25:46 +08:00
committed by Xubin Ren
parent c579551bb1
commit 58b5bb9204
2 changed files with 56 additions and 3 deletions
+41
View File
@@ -1,4 +1,6 @@
import json
import signal
import subprocess
from pathlib import Path
from nanobot.gateway import GatewayRuntime, GatewayRuntimePaths, GatewayStartOptions
@@ -168,3 +170,42 @@ def test_stop_keeps_state_when_process_survives_timeout(tmp_path, monkeypatch):
assert result.status.running is True
assert result.status.reason == "stop_timeout"
assert runtime.paths.state_path.exists()
def test_terminate_windows_falls_back_when_ctrl_break_is_rejected(tmp_path, monkeypatch):
taskkill_calls: list[dict] = []
def fake_run(command, **kwargs):
taskkill_calls.append({"command": command, "kwargs": kwargs})
runtime = GatewayRuntime(
paths=_paths(tmp_path),
platform_name="Windows",
subprocess_run=fake_run,
sleep=lambda _seconds: None,
)
monkeypatch.setattr(signal, "CTRL_BREAK_EVENT", 1, raising=False)
def fake_kill(_pid, _signal):
raise OSError(87, "The parameter is incorrect")
monkeypatch.setattr("nanobot.gateway.runtime.os.kill", fake_kill)
def fake_wait_for_exit(_pid, _timeout_s):
# Simulate a process that only exits after the taskkill fallback runs.
return bool(taskkill_calls)
monkeypatch.setattr(runtime, "_wait_for_exit", fake_wait_for_exit)
assert runtime._terminate_windows(12345, timeout_s=20) is True
assert taskkill_calls == [
{
"command": ["taskkill", "/PID", "12345", "/T"],
"kwargs": {
"check": False,
"stdout": subprocess.DEVNULL,
"stderr": subprocess.DEVNULL,
},
}
]