Repository navigation
ci(unit): guard recurring bug shapes and run only the tests a PR can reach - #5653
Conversation
…folder grants Almost every recent fix shipped a regression test, yet CI caught almost none of the original bugs: each test guarded its own call site, and the next site with the same shape shipped untested. A ratchet now counts those shapes across src/gaia and the hub agents (subprocess and HTTP calls with no timeout, kill-by-image-name, broad excepts that pass or return a placeholder), so the counts can only go down. A four-process test found a real bug: folder grants saved by several GAIA processes at once lost 96-98 of 100, because the read-modify-write had no lock and a torn read "rebuilt" the file from empty. It is now locked and atomic. - Bound six runtime subprocess calls, with actionable errors when taskkill or the notification sink hangs. - test_unit.yml no longer cancels a started run on main: 73 of the last 100 were cancelled part-way, so main rarely got a result. - The flagship freeze and smoke test also run on PRs that change packaging or dependencies and weekly, so a new upstream wheel that drops data or a platform (amd#5420, amd#5481, amd#5546) surfaces before an RC.
… main and nightly Every PR ran all ~27k unit tests on Linux, Windows and macOS, including for a docs edit. Now util/select_tests.py picks the test files a change can reach, and a PR runs those. Windows and macOS run the subset of them that touches the operating system. The median PR runs about a quarter of the suite. Every push to main still runs the full suite on Linux, and the nightly run covers all three operating systems and rebuilds the coverage map the selection reads. The selection combines a nightly per-test coverage map with static rules for what coverage can't see: module-level imports, patch-target strings, files tests read, directory scans, conftest fixtures, and CLIs run in a child process. Deleted or renamed files and packaging or conftest changes run everything. Over ~1,150 recent commits it selected every bug fix's own regression test from the fix's source changes alone. - The email unit lane no longer re-runs ~90 connector and eval test files that need nothing it installs. - C++ benchmarks, which only warn, run on main instead of every PR.
|
Verdict: Approve with suggestions PRs will now run only the unit tests their change can reach; the full suite moves to main and a nightly run. The PR also adds a ratchet that stops new no-timeout calls, kill-by-name commands and swallowed exceptions, and fixes folder grants being lost when several GAIA processes saved at the same time. I found no blocking issues. I spot-checked the riskiest part, whether the selector picks the repo-wide scan tests for an ordinary source change. It does: a change to Small follow-ups worth doing:
Real-world evidenceN/A: no evidence bundle was produced for this run. The PR is mostly CI and tests. Its runtime edits only add timeouts and a file lock, and no user-facing surface changes. The verdict rests on static review, plus a local run of the selector against a few sample changes. 🔍 Technical details🟢 Minor
Strengths
|
…ore unrelated labels A process loading folder grants while another replaced the file could hit a Windows access-denied and start with none; the read now takes the same lock as the write. The nightly map's cache key now includes the run id, so a night with no new commits still saves a fresh map instead of tripping the staleness warning. Only the ready_for_ci label starts a freeze on a PR, so other labels no longer cancel and restart it. The grants concurrency test kills its workers if one hangs.
…tes it amd#5464 documented the desktop app's `~/.local/bin/gaia` shim in backticks, and the doc check's exemption for that shim only matched it followed by a space, so the TUI build went red on main and on every open PR. The shim wraps the Python CLI, so naming it is correct; the exemption now accepts any non-name character after it, the same boundary the check already uses for `bin/gaia`.
# Conflicts: # tui/test/hub_vocabulary_test.go
After merging main, the process-safety ratchet failed on four new calls with no timeout: three git calls in the scorecard gate and the build-time tiktoken download. A hung git now raises an actionable error instead of hanging the release gate (and is never read as "first adoption"), and a hung download fails the freeze naming the host to check. A cli_agent.py swallowed-exception site main removed is dropped from the allowlist so it can't return.
The coverage map is a nightly snapshot, and the selector trusted it even where it had no record, so a PR could leave out tests it actually reaches: a test added since the last nightly run, a source file the map never saw, every file once the map stopped refreshing, and code that GAIA itself runs in a child process (`python -m gaia.daemon`), which coverage can't see into. Each of those now falls back to following every import, as with no map at all, and a spawned module selects the tests that ran the file that spawns it. More tests run in those cases, never fewer.
|
The test selection could leave out tests a PR actually reaches wherever the nightly coverage map had no record. It now runs more tests in those cases, never fewer.
I also merged main, which needed two more fixes. The TUI doc-check conflict resolved to main's version, which already covered the same 🔍 Technical details
|
|
Test selection still skips tests that read a skill file by its full path. A PR that edits Next step: if a test names a non-Python file by any path, that file should select the test even when its basename is common ( 🔍 Technical details
|
A PR editing hub/skills/inbox-triage/SKILL.md skipped the two tests that check that exact file, so a wrong tools_required entry would pass the PR and fail on main. Only the last piece of a path counted, and SKILL.md is too common to mean anything alone; README.md was ignored outright. Coverage records only .py files, so the map couldn't help. Paths built with /, joinpath or os.path.join are now joined and matched whole. A non-Python name with no folder means every file of that name, however common.
They excused the flagship agent files for a test the email unit lane used to collect from tests/unit/eval. This PR removed that directory from the lane, so the entries excuse nothing and the path-coverage check failed.
Matching full paths fixed the inbox-triage case, but any data file a test reads without naming it (through a variable folder, a bare common name like SKILL.md, or a directory scan) still got a guessed, partial selection, and coverage can't help because it records only .py files. A changed non-Python file now selects precisely only when some string names that one file; otherwise the whole suite runs.
|
A data file now selects tests only when some test names that exact file. Otherwise the PR runs the full suite. Editing
|
|
Test selection still skips a test when it loads a script by file path and the change is to something that script imports or reads. The SKILL.md case is fixed, but editing Next step: treat a module a test loads by path ( 🔍 Technical details
|
Path-by-path rules kept missing tests that load a script by file path: editing eval/ci_lanes.json, util/eval_lane_matrix.py or a fixture that build_mailbox.py reads skipped the test that loads that script, because neither imports nor coverage follow what such a script imports or reads. Narrowing is now an allowlist. A PR runs a subset only when every changed file is a unit test, or modified .py code under src/gaia (or hub/agents when the map measured it) that has an entry in the coverage map. Everything else runs the full suite, as does a missing or stale map. About one in five recent merges would still get a narrowed run.
|
Unit tests are now narrowed only by an allowlist. A PR runs a subset only when every file it changes is a unit test, or modified Python under
|
Of the last 150 bug fixes, 147 shipped a regression test, yet CI caught only about 7 of those bugs before users or RC testing did. Each test guards the one call site that broke, and the next site with the same flaw ships untested. Meanwhile every PR ran all ~27k unit tests on three operating systems, even for a docs edit, and most main-branch runs were cancelled before they finished. This PR guards the recurring bug shapes everywhere, fixes a real bug the new tests found, and makes a PR run only the tests it can affect.
except Exceptionbodies that only pass or return a placeholder. Existing sites are grandfathered, new ones fail CI, and fixing one lowers the count.util/select_tests.pycombines a nightly per-test coverage map with static rules for what coverage can't see. Windows and macOS run the OS-touching subset of that. The median PR runs about a quarter of the suite. On ~1,150 recent commits, it selected every bug fix's own regression test from the fix's source changes alone.test_unit.ymlalready covers, and the warning-only C++ benchmarks run on main instead of every PR.Also unbreaks main's TUI build: #5464 documented the desktop app's
gaiashim in backticks, and the TUI doc check only exempted it before a space, so every PR's TUI checks went red. The shim is the Python CLI's, so the exemption now accepts any punctuation after it.Trade-offs to know: a Windows- or macOS-only bug outside the OS-touching subset surfaces at the nightly run, not on the PR, and PRs no longer upload partial coverage to Codecov. To run the full suite on a branch, dispatch
test_unit.ymlon it.Test plan
pytest tests/unit/test_select_tests.py tests/unit/test_process_safety_ratchet.py tests/unit/test_allowed_paths_concurrency.py: 26 + 33 + 1 passed; the concurrency test fails on the old code (96–98 of 100 grants lost)tests/unitlocally: 27,501 passed; 26 failures that fail identically on main in this environment (PATH-installedgaia, real wheel installs)python util/lint.py --allpasses, including the lane-coverage, path-coverage, trigger and ancestor-skip checks--cov-context=testrununit-test-map-*, and the next PR's "Select unit tests" summary reports a map-based selection🔍 Technical details
conftest.py; top-level fixtures by requested name, through fixture chains; autouse isolation fixtures (one hop); CLIs run withpython -m, whose lazy imports coverage can't see. A package__init__reaches everything below it when it changes, but the walk never continues through one.conftest.py, packaging or pytest config, the selector ortest_unit.yml, and any deleted or renamed file (git diff --no-renames). So does a selection over 70% of the suite.docs/reference/dev.mdx: code behind a cache or shared fixture is credited in coverage only to the first test that ran it.