fix(gateway): probe Windows clients safely

This commit is contained in:
Xubin Ren
2026-08-17 20:56:10 +08:00
parent e84aa07bcc
commit 05acd79466
3 changed files with 37 additions and 26 deletions
+15
View File
@@ -18,6 +18,7 @@ from nanobot.gateway import (
GatewayStatus,
)
from nanobot.gateway.runtime import monitor_gateway_clients
from nanobot.process_runtime import process_is_running
class FakeProcess:
@@ -436,6 +437,20 @@ def test_start_background_uses_windows_process_group_flags(tmp_path, monkeypatch
assert "start_new_session" not in calls[0]["kwargs"]
def test_windows_process_probe_never_sends_ctrl_c(monkeypatch):
monkeypatch.setattr(
"nanobot.process_runtime._windows_process_identity",
lambda pid: "created-at" if pid == 12345 else None,
)
monkeypatch.setattr(
"nanobot.process_runtime.os.kill",
lambda *_args: pytest.fail("Windows process probes must not call os.kill(pid, 0)"),
)
assert process_is_running(12345, platform_name="Windows") is True
assert process_is_running(54321, platform_name="Windows") is False
def test_status_clears_stale_state(tmp_path, monkeypatch):
runtime = GatewayRuntime(paths=_paths(tmp_path), platform_name="Linux")
runtime.paths.run_dir.mkdir(parents=True)