test(telegram): isolate HOME so the pid test can't clobber a live adapter - #2895
test(telegram): isolate HOME so the pid test can't clobber a live adapter#2895itomek wants to merge 2 commits into
Conversation
…/telegram.pid test_background_writes_pid wrote and unconditionally os.remove()'d the developer's real ~/.gaia/telegram.pid. Running the unit suite while a live 'gaia telegram start' adapter was up destroyed its pid file, breaking 'gaia telegram stop'/'status'. Redirect '~' at tmp_path via os.path.expanduser, matching the isolation in test_mcp_init.py and test_cli_config.py, and drop the destructive finally cleanup. Fixes #2892
…ently regress
Asserting via expanduser("~") meant removing the monkeypatch would leave a
green test that writes to the developer's real home again. Assert against
tmp_path/.gaia/telegram.pid instead, so dropping the isolation fails the test.
|
Verdict: Approve ✅ This is a clean, well-motivated test hardening. Real-world evidenceN/A — test-only change (single file under 🔍 Technical detailsScope: Correctness — verified against the adapter. The adapter builds its pid path as Good call replacing the old cleanup. The previous Minor, non-blocking observations (no change requested):
Strengths:
|
Running the unit suite used to silently destroy
~/.gaia/telegram.pidon the developer's own machine.test_background_writes_pidcalled the real adapter, let it write the real pid file, thenos.remove()d it unconditionally in afinallyblock — so if agaia telegram startadapter happened to be running,gaia telegram stop/statusquietly stopped working and the only symptom was a green test run. The test now writes into atmp_pathsandbox, and a live adapter's pid file survives the suite untouched.The assertion deliberately targets
tmp_path/.gaia/telegram.pidrather thanexpanduser("~"): if the isolation is ever removed, the test fails loudly instead of passing while writing to the real home.Closes #2892
Sibling of #2891 (same leak class, in the
gaia inittests) — separate file, no dependency, so this is not stacked on it.Evidence — the same test in three variants, each run with a sentinel value planted in a real
~/.gaia/telegram.pid:~/.gaia/telegram.pidmain)The middle row is the fix; the bottom row is why the fix can't silently rot.
Test plan
pytest tests/unit/test_telegram_background.pypassesecho SENTINEL > ~/.gaia/telegram.pidplanted first, the file still readsSENTINELafter that runpytest tests/unit/— 9186 passed; the 11 failures are pre-existing (identical set onmainwith this change stashed: CLI-binary-on-path, hub installer, wheel-packaging, and the known missing-API-key case)python util/lint.py --all— no findings against this file;black/isortcleanCommands used for the evidence table
The "isolation removed" variant deletes the
monkeypatch.setattr(os.path, "expanduser", ...)line and expects a FAILING test.