Repository navigation
test(cli): hold every gaia command to a contract, from the parser - #7342
Conversation
In rc18 a cloud-only user had a 5 GB local model downloaded and loaded behind their back by the start-up warm-up, by Memory > Run Inference and by a scheduled run. Each bug fired only from one starting state, and every test had been written from a PC that was already set up. tests/fixtures/fake_lemonade.py is a model server that answers like Lemonade over real HTTP and writes down every request. The matrix crosses five starting states with three entry points and asserts what reached the server: no local chat model touched on a cloud setup, nothing downloaded unasked, and the local default used where that is right. Three cells fail on the open fixes for amd#7217 and amd#7218. Two fail on a bug the matrix found: a scheduled run ignores a cloud model picked in the app (amd#7329). All five are strict expected failures.
The unit job does not install the flagship package, so the start-up warm-up cells failed there with ModuleNotFoundError. They now skip when the package is absent, and test_gaia_agent.yml, the lane that installs it, runs the matrix so the column is still enforced.
installer/headless/fake_model_server.py already answers like Lemonade and logs every request, so the fixture now starts that server and reads its log instead of carrying a second one. It plays a PC whose only downloaded models are the ones a state names, and refuses a model that is not downloaded, so a request for one is counted as the download it would be on a user's PC.
rc18 shipped CLI bugs a table could have caught: `gaia download --list` exited 0 with the model server down and listed every model as missing, `gaia prompt` printed its answer twice, and `gaia talk --index` and `gaia api start` sent requests to the default server instead of the one --base-url named. The test reads every command from the CLI's own parser and runs each as a subprocess: none may end in a traceback; a command that takes --base-url (or is one of a few listed invocations) is also run against two recording servers and then with none, and must send every request to the named server, print the answer once, and exit non-zero with a reason when the server is down. A new command, or a new --base-url flag, is covered with no edit. It runs in its own workflow, CLI Contract, on changes to src/gaia.
The matrix's fixture starts installer/headless/fake_model_server.py, so a change to that file has to run the lane that runs the matrix.
…ssue The table's first run in CI (155 cases, under three minutes) found 13 failures. Nine are the tracebacks the frozen walk also found (amd#7333, amd#7334, amd#7335, amd#7336). Three are new: `gaia api start` exits 0 after failing to reach the model server (amd#7344), and `gaia chat` and `gaia -p` send their embedder, health and hardware calls to the default server despite --base-url (amd#7345). Each is a strict expected failure. `gaia gateway install` is taken out of the --base-url rule: its flag is the gateway's address, not the model server's.
…to kalin/ci-cli-contract
|
Verdict: Approve with suggestions This is a solid harness. It reads every command from the CLI's own parser, runs each one for real against a fake model server that records its requests, and lists each known failure as a strict xfail that names its issue, so a fix can't land quietly. It changes only tests and CI. I found no bugs, and everything it references exists on this branch: the fake server's flags and Two small, optional suggestions:
🔍 Technical details
|
…to kalin/ci-cli-contract
…bug cells The fake server logs a stderr line per request into a pipe nobody read, so it stalled once the pipe filled: after 77 requests on Windows, ~700 on Linux. It now logs to a file in its own folder, and a test drives 200 KB of log through it. A known-bug cell now only passes as expected on an assertion failure, so a broken import or a renamed entry point fails loudly instead of reading as the bug. The scheduled run's refused load is the request the cell judges, so that refusal no longer ends the run before the assertion. The server is registered for teardown as soon as it starts.
…whole tree A daemon a command starts now gets GAIA_DAEMON_EXIT_WITH_PID set to the test process, so it exits with the run even where the instance.json cleanup misses it; before, the variable was only forwarded if CI happened to set it, which it did not. A child that exited between the listing and the kill raised and skipped the rest of the tree, leaving the parent running past the wait. Each process is now killed on its own.
…d#7346) `gaia api start` printed that it couldn't reach the model server and then exited 0, so a script or service manager starting it read the failure as success. It now exits 1 after the same error message, matching the other commands that run this check. Closes amd#7344 ## Test plan - [x] `python -m pytest tests/unit/api tests/unit/cli` passes (652 passed, 2 skipped) - [ ] `python -m pytest tests/unit/ -x` passes in CI. The runner was missing the `responses` test dependency, so the full suite could not be collected here. - [ ] `python util/lint.py --all` passes in CI. Here, Import Validation and Tool Descriptions fail the same way on clean `main`, and every other check passes. - [ ] With no model server running: `gaia api start --port 8099 --base-url http://127.0.0.1:1/api/v1; echo $?` prints the error and then `1` <details> <summary>🔍 Technical details</summary> - `handle_api_command` in `src/gaia/cli.py` ran `return` when `initialize_lemonade_for_agent` failed. It now calls `sys.exit(1)`, as the other callers of that helper already do. - New test `test_start_exits_nonzero_when_the_model_server_is_unreachable` in `tests/unit/api/test_api_frozen.py` stubs the helper to fail. It asserts exit code 1 and checks that uvicorn never starts. - Once this lands, the strict expected failure for `api start` in the CLI contract table (amd#7342) can be removed. That table isn't on `main` yet. </details> --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Kalin Ovtcharov <[email protected]>
|
This turns red as soon as it meets current main: While there, please keep a timeout from flipping a known-bug cell: a command that is killed at the 25 s limit produces no traceback and no stray request, so its strict xfail reports an unexpected pass and fails the run, on a job that runs for every merge-queue group. 🔍 Technical details
|
# Conflicts: # .github/workflows/test_gaia_agent.yml
… as a fix gaia api start now exits non-zero with the model server down (amd#7346), so its strict known-bug cell would pass unexpectedly and fail the run. A command stopped at the time limit prints no traceback and sends no stray request, so a known-bug cell that timed out used to count as fixed. It now fails, naming the issue it never reached, and the xfail is pinned to AssertionError so that failure cannot be absorbed as the bug itself.
|
Done in a60dde4: the fixed Locally ( 🔍 Technical details
|
…7542) The CLI contract test from amd#7342 misses the rc18 bug it was written to catch. With the health check removed again, `gaia download --list` retries each model against the dead server, is stopped at the 25 s limit, and the test skips the exit-code check and passes. Now a command that finishes with the server up must also finish with it down. Servers that are still running at the limit in both runs stay exempt. ## Test plan - [x] Removed the health check from `download --list`: `test_model_server_contract[download --list]` fails with this change and passed without it - [x] Clean main: `pytest tests/integration/test_cli_contract.py -n 4` gives 150 passed, 10 xfailed. The 2 local failures (`agent status`, `agent health`) come from stale editable installs on the test PC, as noted on amd#7342 - [x] Probe of all 12 model-server commands: every one that exits with the server up also exits with it down, so no existing cell turns red - [ ] CLI Contract workflow green
rc18 shipped four CLI bugs that one table could have caught:
gaia download --listexited 0 with the model server down and listed every model as "not downloaded",gaia promptprinted its answer twice, andgaia talk --indexandgaia api startsent requests to the default server instead of the one--base-urlnamed. This adds that table. It reads every command from the CLI's own parser and runs each one for real, so a command or a--base-urlflag added tomorrow is covered with no edit.What every command is held to:
--base-url, plus a short list of flag variants the walk cannot reach (download --list,prompt,llm,-p):--base-url X, every request goes to X and none to the server the environment names;What its first run found (155 cases, under three minutes in the new workflow):
gaia api start, model server downgaia chat --base-url X,gaia -p ... --base-url Xschedule show / remove / pause / resume / run <unknown>connectors connect <unknown>mcp engineering,mcp code-indexgateway authwith no terminalAll twelve are strict expected failures naming the issue, so each fix has to delete its line.
Stacked on #7331 (it uses that PR's
tests/fixtures/fake_lemonade.py); the commits before "test(cli): ..." are that PR.Test plan
python -m pytest tests/integration/test_cli_contract.py -k "download or prompt" -qpasses locallyKNOWN_BUGSline and the workflow fails with that command's own output in the message🔍 Technical details
python -m gaia.cli ...in a throwaway home with stdin closed and a 25 s limit; one still running then (a server, a prompt) is ended with its children. A daemon a command starts in that home is stopped after the run.kill,uninstall,init,daemon,lemonade embedded,eval,test,telegram,slack), each with the reason inNEVER_STARTED; a test fails if that table names a command that no longer exists.gaia gateway installis outside the--base-urlrule: its flag is the gateway's address, not the model server's.src/gaiachanges.