Repository navigation
ci(tests): cut the pytest matrix to 9 jobs and run the suite under pytest-xdist - #813
Conversation
…test-xdist The test.yml matrix keeps all five Python versions on ubuntu (the ruleset's required checks) and runs macOS and Windows on the oldest and newest Python only, 9 jobs instead of 15. No test is gated on a Python version, so every OS-specific test still runs on the OS it targets. The 100% coverage gate runs on ubuntu py3.14, where coverage's sys.monitoring core costs almost nothing; the other jobs pass --no-cov, dropping the ctrace overhead on 3.10-3.13 (211s vs 157s locally). pytest-xdist 3.8.0 is pinned in the dev extra and the pre-push pytest hook. CI runs `-n auto`; the hook keeps the full suite (the delivery skills use it as the one full local run) and runs `-n 4`, 157s to 87s locally. Refs #787
…st loadfile
Under pytest-xdist the suite flaked on wall-clock limits, not on behaviour.
Fix the causes instead of tuning worker counts:
- Raise subprocess hang guards in tests (timeout=10/15/30, the
run_handshake deadline of 5s, the post-kill proc.wait of 2s) to 60s.
The terminate grace waits (timeout=2, escalating to kill) stay as they are.
- Load a Hypothesis profile with deadline=None from the root conftest.
- Keep the ReDoS wall-clock guards with a 2s budget (10s for the node
check, which includes node startup), and grow inputs so quadratic and
exponential backtracking still blow the budget.
- Run xdist with --dist loadfile in CI and the pre-push hook so
module-scoped fixtures (the wheel build, the MCP server spawns) run once
per module. The hook uses -n auto capped at 4 workers.
- Define the coverage job once via a `cov: true` matrix property and a
single pytest step; required check names are unchanged.
- Require the pytest-xdist mirror between pyproject and the pytest hook.
Local pre-push hook timings (10-core Mac, full suite at 100% coverage):
before: serial 157s; -n 4 87s; -n auto timed out two 10s subprocess tests
after: -n auto --maxprocesses 4 --dist loadfile 68.8s and 69.9s
(two back-to-back runs, 5050 passed); --dist load 90.6s
Refs #787
… server reads The ReDoS guards now take inputs on which a regressed matcher fails the 2.0s budget by a wide margin, measured against deliberately vulnerable variants (macOS, single process): - status markers, "[DONE] " x 16_000: real 0.017s; per-marker line rescan 35.0s (x 8_000: real 0.011s, rescan 9.6s). - next_action keys, 6_000 repetitions for all three inputs: real 0.070s; per-key skill-key rescan 6.2s, per-key brace walk to the end 18.4s (at the old 4_000/3_000: rescan 2.4s, barely over the budget). - _blank_string_values, n=28: real <0.0001s; backslash-ambiguous exponential pattern 22.3s (n=26: 5.0s). - JS blankStringValues, n=31: exponential pattern 21.6s against the 10s budget (n=34 extrapolates to minutes before the post-hoc check fails). The MCP initialize e2e tests and the tools/list contract fixture read responses through the installer's stdout reader thread with a 60s deadline instead of a bare readline, tear down through the installer's _terminate, and send stderr to DEVNULL instead of an undrained pipe, so a stalled server fails the test instead of hanging the xdist worker.
…CP read helpers - JS blankStringValues guard back at n=34, with the node child killed at 30s and reported as "ReDoS: node did not finish in 30s", so a vulnerable pattern fails fast on any machine and a fast runner cannot slip under the 10s budget. Real matcher: 0.04s; backslash-ambiguous pattern fails at the 30s timeout. - MCP initialize e2e tests share one 60s deadline per test across reads, fail with the request id and deadline on a stall, and fail on any stdout line that is not the awaited response. - tools/list contract read names the request id on a stall. - Both spawn the server with inherited stderr, so a crash traceback shows in pytest's captured output without an undrained pipe. - next_action guard inputs 6_000 -> 9_000 and trailing-space guard 40_000 -> 60_000 (macOS, single process): next_action real 0.099s for all three inputs, per-key skill-key rescan 9.1s, per-key brace walk 70.9s; trailing space real 0.010s, ambiguous line-end tail 9.8s.
install_external_skill read the lock for its fail-fast check outside _lock_guard. On Windows that open read handle made a concurrent install's os.replace onto external-skills.lock.json fail with WinError 5. The fail-fast read now takes the guard, still before any fetch. The other readers (_merge_into_lock, _find_record via _locate_verified) already run under the guard.
…and MCP read guards - test.yml sets SUMO_QA_REQUIRE_TREESITTER=1 and tests/test_repo_map_imports.py asserts TREESITTER_AVAILABLE under it, so a broken tree-sitter wheel on one OS or Python fails the job instead of silently skipping the tree-sitter tests there. - Trailing-space guard input 60_000 -> 150_000 (macOS, single process): real matcher 0.026s; quadratic ' +\n' scan 9.27s against the 2.0s budget (60_000: 1.48s, under the budget). - The Python _blank_string_values exponential guard runs the call in a child killed at 30s and reports the child's own timing, so a regression fails with a ReDoS message instead of blocking the xdist worker. A backslash-ambiguous pattern fails with "took 20.0s"; the real matcher passes in 0.05s. - The tools/list contract read fails on non-protocol stdout lines, as the e2e initialize test does; the e2e tests drop the response id asserts the id-filtering reader makes unfalsifiable.
… guard The install fail-fast pre-check took the guard unconditionally, creating .sumo-qa and its guard file (in $HOME for a global install) before a fetch that could fail, and waiting behind another install with nothing to read. It now takes the guard only when a lock file exists, and reads it there. Execute's unlocked attempt (no lock folder) still read the lock through _find_record, so a lock created by a concurrent install could be held open while that install replaced it (fatal on Windows). The lock is now read only under the guard and passed into verification; an unlocked attempt has no lock to read and is discarded for a locked retry if one appears. Tests assert every lock read happens under the guard and that a failed install leaves no .sumo-qa behind.
The ReDoS guard for _blank_string_values spawns python -c importing sumo_qa.conformance, which imports the mutated knowledge_loaders, so under mutmut its child would crash the trampoline. It moves to its own module carrying the mutmut-subprocess-spawning marker and an --ignore entry, so the validator module keeps its mutation kills. The exclusion guard missed this shape: a -c body importing a sumo_qa module that is not itself mutated. It now flags such a body when a static walk of src/'s imports reaches a mutated module from it.
…ies in the mutmut hazard classifier
…folder is refused on every Python
Finish proof, head 5c5f87bCI: 27 of 27 checks pass on 5c5f87b (9 pytest jobs). Mutation gate: run 37058420037 on this head, success. Open review threads: 0. Per-file review (sumo-qa-reviewing-before-merge, each changed file's full post-change content vs main): SAFE for all 25 files. One low note, not a code defect: /code-review (high): 4 rounds plus a comment-only round (03ea8be, 5c5f87b: the mutmut hazard classifier's comments now match its rule, history sentence removed). Final delta: clean. Behaviour ledger (finish-pr 4.7):
Acceptance criteria (#787): all 6 met, evidence per row above (numbers are in the PR body's "How it was verified" table). Integration (finish-pr-batch 5.5) with #811, #813, #814, #816 and #818 merged in drain order on a throwaway branch off main: full suite 5323 passed, 100% coverage; live MCP routing reaches the routed skill through dispatch; tools/list unset/full equal main (48), core 40; no conflicts except #811 vs #813 (one import block in |
🤖 I have created a release *beep* *boop* --- ## [0.70.1](v0.70.0...v0.70.1) (2026-10-02) ### Bug Fixes * **skills:** stop downstream skills leaking announce lines and approach labels ([#816](#816)) ([f21f376](f21f376)) ### Tests * **conformance:** add a live-host first-hop harness that scores real host tool selection ([#814](#814)) ([6e1cac7](6e1cac7)) ### Continuous Integration * **tests:** cut the pytest matrix to 9 jobs and run the suite under pytest-xdist ([#813](#813)) ([7a84f9b](7a84f9b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: release-please[bot] <release-please[bot]@users.noreply.github.com>
## Summary Slice 1 of #515. Every MCP tool now has one `ToolMeta` entry (group, core, open_world, integration) in `src/sumo_qa/tool_registry.py`, and the `core` and `full` profiles are derived from it. `SUMO_QA_MCP_PROFILE=core|full` selects the profile before tools are listed; unset or empty means `full`, so the default `tools/list` is byte-identical to `main`. Any other value stops the server, installer and doctor with one clean line. A configured profile also survives the documented update flow: re-running the installer keeps each host entry's `env` (and `envFile` where the host reads it), and `sumo-qa-doctor --host <host>` probes the entry the way that host launches it, with that entry's profile. ## Related issue Closes #806 ## Changes - `tool_registry.py`: the registry, `resolve_profile`, `resolve_profile_or_exit`, `profile_tool_names`. Core is 40 of 48 tools: every workflow skill tool, the knowledge and test-data loaders, analysis and evidence/reporting tools. Out of core: 4 specialist tools and the 4 external-skill search/check/install/execute tools. - `server.py`: resolves the profile before registration and removes non-profile tools in registration order; a registered tool without metadata warns and is served under `full` only, and `test_tool_registry.py` fails on it. - `installer.py`: a bad profile exits cleanly before any host config is written. A refresh keeps the existing entry's `env` in `claude_desktop_config.json`, `.vscode/mcp.json` and Claude Code's user registry, and `envFile` in the first two; the registry is re-registered with `claude mcp add-json` (string env values only; `claude mcp add -e` fallback for a CLI without `add-json`, warning on keys it cannot pass; the removed entry is restored if the add fails). `REQUIRED_TOOL_NAMES` is derived lazily per profile, so importing the installer never exits. - `doctor.py`: `--host claude-code|claude-desktop|vscode` probes that host's `sumo-qa` entry with its `env`, expands `${...}` the way that host does, requires every tool of the entry's profile, and reports an invalid profile, an unlaunchable command or an unexpandable VS Code placeholder as a check result instead of crashing. Claude Desktop does not inherit the doctor shell's profile; the Claude Code CLI and VS Code keep it. - Snapshot fixture gains `core_tools`; the regen script writes it and refuses to pin a tool without metadata. - `tests/conftest.py`: clears `SUMO_QA_MCP_PROFILE` in `pytest_configure`, and runs doctor and installer test modules in a temp HOME so nothing reads the real `~/.claude.json`. - Docs: `CONFIGURATION.md` (Tool profiles, refresh and doctor behaviour per host), `INSTALL.md`, `TOOLS.md`, `DEVELOPMENT.md`. ## How it was verified - CI green on ec7a49d across the full matrix (pytest on macOS, Ubuntu and Windows, py3.10 to 3.14; mypy; ruff; install and handshake jobs). Mutation gate run 37062233685 on ec7a49d: success. - Real install from the built wheel (b1d571f; later commits change one test assertion and one doc paragraph), 13 of 13 acceptance rows met, driven by a real `claude -p` (haiku) host with only the built sumo-qa attached plus JSON-RPC cross-checks: profiles are `core` and `full` only; the metadata test goes red when a `ToolMeta` is removed; `core` is 40 tools with the external and open-world ones absent; `full` and the default equal `origin/main`'s names and input schemas; `bogus` exits 1 with `sumo-qa: SUMO_QA_MCP_PROFILE='bogus' is not a valid MCP tool profile; expected one of: core, full`; order is stable; the installer keeps `env`/`envFile` for VS Code and Claude Desktop; `claude mcp get` shows the env kept for Claude Code; the doctor judges 40 required tools for `core` entries on all three hosts; VS Code `${workspaceFolder}` resolves. The router plus `load_classifications` return byte-identical results to `main`. - Snapshot regenerated into a temp path at the head: identical to the committed fixture, and its `required_tools` and `schemas` equal `origin/main`'s. - Targeted modules (registry, tools-list contract, doctor, installer, server, skill resources) with `SUMO_QA_MCP_PROFILE=core` exported and a temp HOME: 298 passed, 0 skipped, including the round trip through the real `claude` CLI. - Integration check with #813, #814 and #816: full suite 5291 passed at 100% on the merged tip, live MCP routing and tool surface correct; one import-block conflict in `tests/test_tools_list_contract.py` with #813. Review: per-file sumo-qa review plus `/code-review` (high) over several rounds, and a final per-file pass at the head with every file SAFE. The two Codex threads (installer refresh dropping the profile env; doctor probing with the ambient env) are fixed and resolved. ## Decisions recorded here (not changed) - Under `core`, the external-skill workflow is listed but its search/check/install/execute tools are absent; the actionable activation path is #807. - `ToolMeta.integration` and `open_world` stay: #515's spec lists both as registry metadata. - The doctor does not read a VS Code `envFile`; a profile set only there is probed as the shell's profile (documented in `CONFIGURATION.md`). - Low review notes left as is: the skill-reference regex can over-match a hyphen-suffixed token; the doctor test compares stderr exactly; the regen script keeps a local `PROFILE_ENV` literal so it runs without an installed package; the conftest pop is not restored after the session; `_required_tool_names_for` ignores its argument (only caller passes the env's profile). ## Checklist - [x] PR title follows Conventional Commits - [x] Tests pass locally and lint/type checks are green - [x] Added or updated tests covering the change - [x] Updated the relevant docs in this same PR - [x] No breaking changes (default profile is unchanged)
Summary
Cuts CI and pre-push test time while keeping platform coverage, the 100% coverage gate and the mutation gate. The suite now runs in parallel under pytest-xdist; the parallel flakiness that exposed (tight subprocess hang guards, a 200ms Hypothesis deadline, wall-clock ReDoS budgets, readline hangs, module fixtures duplicated per worker, an unguarded provenance-lock read) is fixed at the root rather than by tuning worker counts.
Related issue
Closes #787
Changes
test.yml: all 5 Pythons on ubuntu; macOS and Windows on 3.10 and 3.14 only (15 to 9 jobs). Required check names unchanged (pytest (ubuntu-latest · py3.1x)). The coverage gate runs once, onubuntu-latest · py3.14with thetreesitterextra (acov: truematrix property); every other job runspytest -n auto --dist loadfile --no-cov. Every job setsSUMO_QA_REQUIRE_TREESITTER=1, so a tree-sitter import failure fails that job (tests/test_repo_map_imports.py) instead of silently skipping the tree-sitter tests.pytesthook: still the full suite at 100% (the delivery skills' one full local run), nowpytest -n auto --maxprocesses 4 --dist loadfile.pytest-xdist==3.8.0pinned in the dev extra and the hook, enforced bytest_toolchain_pin_lockstep.py(REQUIRED_MIRRORSgains the row).--changed-onlyreports nothing in scope), so thefiles:regex was left as is.deadline=None(rootconftest.py); ReDoS guards resized so each still fails a deliberately quadratic or exponential variant by 3x or more while the real matcher stays under 0.1s; the JS guard runs node with a 30s child timeout; MCP read helpers in two tests use the installer's reader with one shared deadline, inherited stderr and a stray-stdout check.src/sumo_qa/external_skills.py: the provenance lock is read only under its guard, both in the install pre-check (only when a lock already exists, so a failed fetch leaves no.sumo-qabehind) and inexecute. On Windows an open read handle made a concurrent install'sos.replaceonto the lock fail. The pre-check probes withos.stat, so an unsearchable lock folder is refused with the typed lock error on every Python._blank_string_valuesReDoS guard moved totests/test_conformance_redos_subprocess.py(runs in a child killed at 30s) and is excluded from mutmut with themutmut-subprocess-spawningmarker;conformanceis not a mutated module. The mutmut hazard classifier now follows a-cbody's imports throughsrc/(from sumo_qa import conformancereachesknowledge_loaders) and keeps the conservativesumo_qa.<mutated>substring check for dynamic imports.docs/DEVELOPMENT.md: the hooks no longer claim to mirrortest.ymlexactly; the mutmut guard section describes the-cimport walk and that nosumo_qa.<sub>entry point is exempt.How it was verified
test.ymlrunwindows · py3.11444s)src/change-n auto --maxprocesses 4 --dist loadfile)--dist loadvsloadfile, same machine5066 passed,Required test coverage of 100% reached.pytest (ubuntu-latest · py3.14)installs.[dev,vertex,treesitter], setsSUMO_QA_REQUIRE_TREESITTER=1and printsRequired test coverage of 100% reached.test_route_qa_runners.pycmd.exe branch) on windows 3.10/3.14; POSIX-only tests on ubuntu and macOS; no macOS-only tests; no test is gated on a Python version.src/sumo_qa/installer.pyPATH split on":"instead ofos.pathsep), run 37057716159: both windows pytest jobs failed (5 tests intests/test_installer_host_aware_claude_desktop.py) and every ubuntu and macOS job passed, so the reduced matrix still catches it. scratch: Windows-only regression check for #813 (do not merge) #817 was closed unmerged and its branch deleted.actionlintontest.yml: clean.Review: per-file sumo-qa review plus
/code-review(high), 4 rounds and a comment-only fix round; the merge-boundary per-file pass found every file SAFE.Notes and decisions
36857043731; the serial local run is 157s with the treesitter extra (without it 213 tests skip and coverage stops at 93%).--dist loadfilerather thanloadgroup(measured faster here); the suite-widedeadline=None; the repeated 60s literal; the duplicated MCP read helper in the two tests;scripts/regen_tools_list_snapshot.pystill reads with a blocking, id-blind readline (pre-existing, not run in parallel).Checklist