Repository navigation
test(unit): stop the unit suite from killing and replacing the real daemon - #4301
Conversation
…aemon Running `pytest tests/unit` could tree-kill the developer's live GAIA daemon and leave an orphaned test daemon registered in ~/.gaia/host in its place. The email wiring tests reached the real `start_or_attach()`; with the unit network guard in place the real daemon failed its liveness probe, was treated as hung and terminated, and a new `python -m gaia.daemon` was spawned. - Point GAIA_DAEMON_HOME at a per-session tmp dir for all unit tests. - Refuse `_spawn_and_wait` in unit tests and fail the test at teardown, so a caller that wraps the error (the email router returns 503) cannot hide it. - Mock `acquire_handle` in the email wiring tests and assert the 503 the mocked daemon produces instead of "not 404".
|
Verdict: Approve This stops The part that makes this actually work rather than look like it works is the teardown check. The email route turns a daemon failure into a 503, so a raise alone would have been swallowed and the old No blocking issues. Two small suggestions below, both optional. Real-world evidenceN/A — tests-only change, no runtime surface. No I verified the change by reading the code rather than running it: 🔍 Technical detailsStrengths
🟢 Minor: the guard check is indirect (
(Asserting it raises directly isn't an option here — that would populate 🟢 Minor: second assertion is true by construction (
Checked and clear
|
**Stacked on amd#4192. Land after amd#4301**, which stops unit tests from spawning real daemons. With this PR a daemon starts GAIA's Lemonade Server in the real `~/.gaia`, so a test-spawned one would start and stop the developer's server. Until that merges, this diff includes its commit; review only the last commit here. After a reboot, GAIA's own Lemonade Server is stopped, and every entry point said "Lemonade not running" until you re-ran `gaia init`. Now the daemon starts it when the daemon comes up, and again whenever a GAIA command finds it stopped. Agents, the TUI's first-launch check (`gaia init --check`) and the Agent UI just work after a restart. The daemon is careful about what it stops. `gaia daemon stop` stops the server only if that daemon started it, so one started by `gaia init`, by hand, or by another daemon (a second one used for testing, say) keeps running. It never kills a server that is slow to answer (it may be loading a large model) and never replaces one running a different version: it reports both and points at `gaia init`. With `LEMONADE_BASE_URL` set it leaves Lemonade alone, and it never installs anything. A daemon from before this change doesn't have the new endpoint. Instead of a bare 404, clients get "restart it with `gaia daemon restart`" (host API bumped to 1.2). ## Test plan - [x] `pytest tests/unit/test_daemon_lemonade.py tests/unit/test_daemon_clock_wiring.py tests/unit/test_init_command.py tests/unit/test_daemon_agents_routes.py`; `go test ./internal/gaiainit/ ./internal/daemon/` - [x] With `GAIA_HOME`, `GAIA_DAEMON_HOME` and `GAIA_CONFIG_DIR` in a scratch dir and the server stopped: `gaia init --check` has a new daemon start it and prints READY (1.4 s); `gaia daemon stop` then stops it - [x] Server started with `gaia lemonade embedded start`, then `gaia daemon start` / `gaia daemon stop`: the server keeps running - [x] Server stopped: `LemonadeManager.ensure_ready()` gets it started through the daemon, loads Gemma and returns True - [ ] Windows and Linux: reboot, then launch `gaia-tui` without running `gaia init`; it should go straight to chat <details> <summary>Terminal output: the reboot case on Apple Silicon (GAIA set up, no daemon or server running)</summary> ``` $ gaia daemon status GAIA daemon: not running $ gaia lemonade embedded status Running: no $ time gaia init --check --profile minimal READY: profile 'minimal' is already set up (exit 0, 1 s) $ gaia lemonade embedded status Running: yes on http://localhost:59768/api/v1 (pid 88967) $ time gaia daemon stop ✅ GAIA daemon stopped (pid 88966) (5 s) $ gaia lemonade embedded status Running: no ``` </details> --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
The Agent UI ignored `GAIA_HOME` and always saved Document Library uploads and chat attachments under the real `~/.gaia`. So a run of the document and file router tests left files in the developer's own GAIA home, and those files could change the next run's results. Both folders now live under `$GAIA_HOME` (default is still `~/.gaia`). The router tests run under a fake home and fail if anything lands in `<home>/.gaia`. A `GAIA_HOME` set to your home directory or one of its parents is now rejected, because the server deletes files in `<GAIA_HOME>/documents` as its own, and there that would be your real Documents folder. Merge amd#4343 first. It fixes three reindex tests in `test_documents_router` that fail on `main` right now because they call real RAG indexing without Lemonade. I checked this branch with amd#4343's changes applied: both router files pass (89 passed, 1 skipped). This PR edits different lines of that file, so the two won't conflict. It also adds nothing to the unit conftest that amd#4301 changes. ## Test plan - [x] `pytest tests/unit/chat/ui/test_gaia_home_storage.py`: fails on `main` (4 failed, 2 errors), passes here (6 passed) - [x] `pytest tests/unit/chat/ui tests/integration/test_files_router.py tests/integration/test_documents_router.py`: 1127 passed. The only failures are the 3 reindex tests that amd#4343 fixes - [x] Same two router files with amd#4343's test changes applied: 89 passed, 1 skipped - [x] Same run with `GAIA_HOME` unset and a fake `HOME`: default `~/.gaia` layout unchanged - [x] black, isort and pylint on the changed files (the one pylint warning in `documents.py` is already on `main`) Fixes amd#4347 --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
Running
pytest tests/unitcould kill a developer's running GAIA daemon and leave an orphaned test daemon registered in~/.gaia/hostin its place, which knocked any TUI session using the real daemon off discovery. The email wiring tests reached the real daemon client. The unit network guard made the live daemon fail its liveness probe, so the client treated it as hung, tree-killed it and spawned a new one. After this change, unit tests use a throwaway daemon home, and any test that tries to spawn a real daemon fails with a message saying which boundary to mock.Test plan
pytest tests/unit -n 8: no newgaia.daemonprocess appears (ps aux | grep gaia.daemon), and~/.gaia/host/instance.jsonandsidecars.jsonare unchangedpytest tests/unit/test_email_sidecar_server_wiring.py tests/unit/test_unit_daemon_isolation.pypassesacquire_handlemock from the wiring tests makes them fail with "Unit test tried to spawn a real GAIA daemon"🔍 Technical details
tests/unit/conftest.py: a session-scoped autouse fixture setsGAIA_DAEMON_HOMEto a tmp dir (the only host-dir overridegaia.daemon.pathshonours). A per-test autouse fixture replacesgaia.daemon.client._spawn_and_wait, the one placepython -m gaia.daemonis spawned. It raises, and it also fails the test at teardown, because the email router turns a spawn error into a 503 that the old!= 404assertion accepted.test_email_sidecar_server_wiring.pynow mocksdaemon_client.acquire_handleand asserts== 503, which proves each route is mounted and reaches the daemon boundary.GAIA_DAEMON_HOME.GAIA_HOMEset locally) and reproduce on unmodifiedmain(43 there).