test(ci): isolate cross-platform gateway lifecycle

This commit is contained in:
Xubin Ren
2026-08-17 20:56:10 +08:00
parent ed4740638b
commit ddd3b78ed1
2 changed files with 14 additions and 2 deletions
+7 -1
View File
@@ -2523,9 +2523,15 @@ def test_webui_foreground_attaches_to_existing_managed_gateway(monkeypatch, tmp_
def __init__(self, **kwargs) -> None: def __init__(self, **kwargs) -> None:
seen["runtime_kwargs"] = kwargs seen["runtime_kwargs"] = kwargs
self.paths = kwargs["paths"] self.paths = kwargs["paths"]
self.status_calls = 0
def status(self): def status(self):
return SimpleNamespace(running=True) self.status_calls += 1
# The command checks during config refresh and once more before
# delegating to the attach helper.
# If that helper is not patched as intended, make its polling loop
# terminate instead of hanging the Windows test worker forever.
return SimpleNamespace(running=self.status_calls <= 2)
def start_background(self, options): def start_background(self, options):
return SimpleNamespace( return SimpleNamespace(
+7 -1
View File
@@ -276,6 +276,8 @@ def test_restart_does_not_detach_a_foreground_gateway(tmp_path, monkeypatch):
def test_last_interactive_client_stops_an_on_demand_gateway(tmp_path, monkeypatch): def test_last_interactive_client_stops_an_on_demand_gateway(tmp_path, monkeypatch):
runtime = GatewayRuntime(paths=_paths(tmp_path), platform_name="Linux") runtime = GatewayRuntime(paths=_paths(tmp_path), platform_name="Linux")
monkeypatch.setattr(runtime, "_process_identity", lambda pid: pid)
monkeypatch.setattr(runtime, "_is_pid_running", lambda _pid: True)
stopped: list[int] = [] stopped: list[int] = []
def stop(*, timeout_s: int): def stop(*, timeout_s: int):
@@ -327,6 +329,8 @@ def test_on_demand_lifetime_is_recorded_before_the_gateway_spawns(tmp_path, monk
def test_explicit_background_gateway_survives_the_last_client(tmp_path, monkeypatch): def test_explicit_background_gateway_survives_the_last_client(tmp_path, monkeypatch):
runtime = GatewayRuntime(paths=_paths(tmp_path), platform_name="Linux") runtime = GatewayRuntime(paths=_paths(tmp_path), platform_name="Linux")
monkeypatch.setattr(runtime, "_process_identity", lambda pid: pid)
monkeypatch.setattr(runtime, "_is_pid_running", lambda _pid: True)
stopped: list[int] = [] stopped: list[int] = []
monkeypatch.setattr( monkeypatch.setattr(
runtime, runtime,
@@ -346,6 +350,8 @@ def test_explicit_background_gateway_survives_the_last_client(tmp_path, monkeypa
def test_failed_last_client_shutdown_remains_retryable(tmp_path, monkeypatch): def test_failed_last_client_shutdown_remains_retryable(tmp_path, monkeypatch):
runtime = GatewayRuntime(paths=_paths(tmp_path), platform_name="Linux") runtime = GatewayRuntime(paths=_paths(tmp_path), platform_name="Linux")
monkeypatch.setattr(runtime, "_process_identity", lambda pid: pid)
monkeypatch.setattr(runtime, "_is_pid_running", lambda _pid: True)
monkeypatch.setattr( monkeypatch.setattr(
runtime, runtime,
"stop", "stop",
@@ -466,7 +472,7 @@ def test_posix_process_identity_includes_start_time_and_accepts_legacy_state(
monkeypatch, monkeypatch,
): ):
runtime = GatewayRuntime(paths=_paths(tmp_path), platform_name="Linux") runtime = GatewayRuntime(paths=_paths(tmp_path), platform_name="Linux")
monkeypatch.setattr("nanobot.process_runtime.os.getpgid", lambda _pid: 42) monkeypatch.setattr("nanobot.process_runtime.os.getpgid", lambda _pid: 42, raising=False)
monkeypatch.setattr(runtime, "_posix_process_started_at", lambda _pid: "987654") monkeypatch.setattr(runtime, "_posix_process_started_at", lambda _pid: "987654")
assert runtime.process_identity(12345) == "42:987654" assert runtime.process_identity(12345) == "42:987654"