Skip to content

The agent that grows with you

fix: computer-use doctor scans daemon units under XDG_CONFIG_HOME (review follow-up)

teknium1a731e7efa40b
diff --git a/tests/tools/test_computer_use_doctor_stale_units.py b/tests/tools/test_computer_use_doctor_stale_units.py
index 11725f73ccd..6c465554789 100644
--- a/tests/tools/test_computer_use_doctor_stale_units.py
+++ b/tests/tools/test_computer_use_doctor_stale_units.py
@@ -7,6 +7,7 @@ while every binary-level check stays green. Doctor is the only surface that can
"""
import json
+import os
from io import StringIO
from unittest.mock import MagicMock, patch
@@ -38,6 +39,8 @@ def _fake_health_report_proc() -> MagicMock:
def _run_doctor_json(monkeypatch, home):
monkeypatch.setenv("HOME", str(home))
+ if "XDG_CONFIG_HOME" in os.environ and not os.environ["XDG_CONFIG_HOME"].startswith(str(home)):
+ monkeypatch.delenv("XDG_CONFIG_HOME") # the host's own config dir must not leak into the scan
monkeypatch.setattr(doctor, "_read_cli_version", lambda binary, timeout=5.0: "cua-driver 0.28.2")
out = StringIO()
with patch("shutil.which", return_value="/fake/cua-driver"), \
@@ -61,6 +64,21 @@ def test_doctor_reports_pruned_unit_and_degrades(tmp_path, monkeypatch):
assert "packages/current/cua-driver" in unit_checks[0]["hint"]
+def test_doctor_scans_units_under_xdg_config_home(tmp_path, monkeypatch):
+ """Hosts that relocate ``~/.config`` via XDG_CONFIG_HOME keep their systemd user units there;
+ scanning only ``~/.config`` would give them the silent green doctor this fix exists to remove."""
+ cfg = tmp_path / "data" / "cfg"
+ unit_dir = cfg / "systemd" / "user"
+ unit_dir.mkdir(parents=True)
+ (unit_dir / "cua-driver.service").write_text(f"[Service]\nExecStart={_STALE} serve\n", encoding="utf-8")
+ monkeypatch.setenv("XDG_CONFIG_HOME", str(cfg))
+
+ code, report = _run_doctor_json(monkeypatch, tmp_path)
+
+ assert code == 1 and report["overall"] == "degraded"
+ assert [c for c in report["checks"] if c["name"] == "daemon unit (cua-driver.service)"]
+
+
def test_doctor_is_silent_for_current_and_live_release_references(tmp_path, monkeypatch):
live = tmp_path / ".cua-driver" / "packages" / "releases" / "0.28.2-x86_64-unknown-linux-gnu" / "cua-driver"
live.parent.mkdir(parents=True)
diff --git a/tools/computer_use/doctor.py b/tools/computer_use/doctor.py
index ebe3dc596c0..1efe3407aa4 100644
--- a/tools/computer_use/doctor.py
+++ b/tools/computer_use/doctor.py
@@ -293,8 +293,9 @@ def _stale_cua_exec_references(config_dir: Optional[str] = None) -> List[Tuple[s
after every upgrade while every binary-level check stays green (#114748). ``packages/current`` and
still-present release dirs are healthy by construction and never reported.
"""
+ # systemd --user and XDG autostart both honour $XDG_CONFIG_HOME; a host that sets it keeps its units there.
home = os.path.expanduser("~")
- base = config_dir or os.path.join(home, ".config")
+ base = config_dir or os.environ.get("XDG_CONFIG_HOME") or os.path.join(home, ".config")
findings: List[Tuple[str, str, str]] = []
sources = (("systemd user unit", os.path.join(base, "systemd", "user"), ".service", "ExecStart"),
("XDG autostart entry", os.path.join(base, "autostart"), ".desktop", "Exec"))