Skip to content

The agent that grows with you

fix(bot-desktop): stop() also removes the idle check's output file

kshitijk4poored5384a11e80
diff --git a/tests/tools/test_bot_desktop_idle.py b/tests/tools/test_bot_desktop_idle.py
index 27081a6fd55..498776e4cec 100644
--- a/tests/tools/test_bot_desktop_idle.py
+++ b/tests/tools/test_bot_desktop_idle.py
@@ -183,3 +183,23 @@ def test_a_stale_idle_check_never_writes_into_the_replacement_screens_log(tmp_pa
_spawn(monkeypatch, tmp_path)
stale.write(b"idle-watch changed while the idle stop waited; kept\n")
assert log.read_bytes() == b""
+
+
+def test_stop_leaves_no_idle_check_output_behind(tmp_path, monkeypatch):
+ """``idle-watch.out`` is the launcher's idle check output: it belongs to the stopped screen like its pid."""
+ sd = tmp_path / "bd"
+ sd.mkdir()
+ monkeypatch.setattr(runtime, "state_dir", lambda: sd)
+ proc = subprocess.Popen(["sleep", "60"], start_new_session=True)
+ try:
+ (sd / "launcher.pid").write_text(f"{proc.pid} {runtime._create_time(proc.pid)}", encoding="utf-8")
+ for name in ("env", "activity", "idle-watch.out"):
+ (sd / name).write_text("300\n", encoding="utf-8")
+ assert runtime._stop_locked(sd) is True
+ proc.wait(5)
+ assert sorted(p.name for p in sd.iterdir()) == []
+ finally:
+ if proc.poll() is None:
+ proc.kill()
+ proc.wait()
diff --git a/tests/tools/test_bot_desktop_idle_self_stop.py b/tests/tools/test_bot_desktop_idle_self_stop.py
index 7c77a1d8cfb..98412f2a841 100644
--- a/tests/tools/test_bot_desktop_idle_self_stop.py
+++ b/tests/tools/test_bot_desktop_idle_self_stop.py
@@ -88,8 +88,9 @@ def abandoned_screen(tmp_path):
def test_an_abandoned_screen_stops_itself_after_the_idle_window(abandoned_screen):
sd, launcher = abandoned_screen(idle_stop_minutes=0.02) # 1.2 s
- # stop() deletes launcher.pid/env after the group is gone, so both are part of "stopped".
- wait_until(lambda: not _alive(launcher) and not (sd / "launcher.pid").exists() and not (sd / "env").exists(),
+ # stop() deletes its runtime files after the group is gone, so they are part of "stopped".
+ files = ("launcher.pid", "env", "activity", "idle-watch.out")
+ wait_until(lambda: not _alive(launcher) and not any((sd / name).exists() for name in files),
timeout=30, what="the abandoned screen to be stopped the way stop() does")
diff --git a/tools/bot_desktop/runtime.py b/tools/bot_desktop/runtime.py
index cd8cd265a0f..f4dcd254b71 100644
--- a/tools/bot_desktop/runtime.py
+++ b/tools/bot_desktop/runtime.py
@@ -889,6 +889,6 @@ def _stop_locked(sd: Path) -> bool:
return reaped
# The launcher runs in its own session; killing the group takes Xvnc, dbus and Xfce with it.
_kill_group_then_wait(pid, pid, grace=5.0)
- for name in ("launcher.pid", "env", "activity"):
+ for name in ("launcher.pid", "env", "activity", "idle-watch.out"):
(sd / name).unlink(missing_ok=True)
return True