Skip to content

ci(tests): cut the pytest matrix to 9 jobs and run the suite under pytest-xdist - #813

Merged
sumithr merged 14 commits into
mainfrom
ci/issue-787-cut-ci-test-time
Oct 2, 2026
Merged

sumithr merged 14 commits into
mainfrom
ci/issue-787-cut-ci-test-time

Conversation

@sumithr

@sumithr sumithr commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

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, on ubuntu-latest · py3.14 with the treesitter extra (a cov: true matrix property); every other job runs pytest -n auto --dist loadfile --no-cov. Every job sets SUMO_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.
  • Pre-push pytest hook: still the full suite at 100% (the delivery skills' one full local run), now pytest -n auto --maxprocesses 4 --dist loadfile. pytest-xdist==3.8.0 pinned in the dev extra and the hook, enforced by test_toolchain_pin_lockstep.py (REQUIRED_MIRRORS gains the row).
  • Mutmut hook: unchanged. With a warm cache an unrelated test-only change costs 0.1 to 0.3s (--changed-only reports nothing in scope), so the files: regex was left as is.
  • Flake root causes: subprocess hang guards raised to 60s; a suite Hypothesis profile with deadline=None (root conftest.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-qa behind) and in execute. On Windows an open read handle made a concurrent install's os.replace onto the lock fail. The pre-check probes with os.stat, so an unsearchable lock folder is refused with the typed lock error on every Python.
  • The Python _blank_string_values ReDoS guard moved to tests/test_conformance_redos_subprocess.py (runs in a child killed at 30s) and is excluded from mutmut with the mutmut-subprocess-spawning marker; conformance is not a mutated module. The mutmut hazard classifier now follows a -c body's imports through src/ (from sumo_qa import conformance reaches knowledge_loaders) and keeps the conservative sumo_qa.<mutated> substring check for dynamic imports.
  • docs/DEVELOPMENT.md: the hooks no longer claim to mirror test.yml exactly; the mutmut guard section describes the -c import walk and that no sumo_qa.<sub> entry point is exempt.

How it was verified

Metric Before After
CI jobs per test.yml run 15 9
CI runner-minutes, one run 73.7 (run 37014740621, last green on main) 21.6 (run 37058370119, this head); 20.7 (run 37057234383, previous head)
CI wall-clock, first job start to last job end 466s (slowest windows · py3.11 444s) 208s (run 37058370119); 203s (run 37057234383)
Pre-push hook stage, test-only change 122.6 to 142.0s (042c013) 58.5 to 60.8s
Pre-push hook stage, src/ change 96.8s (042c013) 29.8 to 31.6s
Local full suite, coverage on (py3.14, treesitter) 157s serial 62 to 80s (-n auto --maxprocesses 4 --dist loadfile)
--dist load vs loadfile, same machine 90.6s vs 68.8 to 69.9s
  • Real pushes of this branch: pytest hook 61 to 65s, 5066 passed, Required test coverage of 100% reached.
  • CI coverage job pytest (ubuntu-latest · py3.14) installs .[dev,vertex,treesitter], sets SUMO_QA_REQUIRE_TREESITTER=1 and prints Required test coverage of 100% reached.
  • Every OS-specific test still runs on its OS: Windows-only (test_route_qa_runners.py cmd.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.
  • Windows-only regression on a scratch draft PR (scratch: Windows-only regression check for #813 (do not merge) #817, src/sumo_qa/installer.py PATH split on ":" instead of os.pathsep), run 37057716159: both windows pytest jobs failed (5 tests in tests/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.
  • Mutation gate on this head: run 37058420037, success.
  • actionlint on test.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

  • Issue figures have drifted since 2026-10-01: about 5,066 tests run (not 4,746); the before-run above replaces 36857043731; the serial local run is 157s with the treesitter extra (without it 213 tests skip and coverage stops at 93%).
  • Left as is: --dist loadfile rather than loadgroup (measured faster here); the suite-wide deadline=None; the repeated 60s literal; the duplicated MCP read helper in the two tests; scripts/regen_tools_list_snapshot.py still reads with a blocking, id-blind readline (pre-existing, not run in parallel).

Checklist

  • PR title follows Conventional Commits
  • Tests pass locally and lint/type checks are green
  • Added or updated tests covering the change
  • Updated the relevant docs in this same PR
  • No breaking changes

sumithr added 14 commits October 2, 2026 16:44
…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.
@sumithr

sumithr commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner Author

Finish proof, head 5c5f87b

CI: 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: src/sumo_qa/external_skills.py carries a user-visible fix (the provenance lock is read only under its guard; an unsearchable lock folder is refused before the fetch), and the ci(tests): ... squash title gives it no release-please changelog entry.

/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):

# expected behaviour real-surface call + input observed output Met
1 PR states before/after CI wall-clock, runner-minutes for one test.yml run, local pre-push time gh run view <id> --json jobs summed (ci_minutes.py) on main run 37014740621 vs this branch's run; pre-commit pre-push stage timed on a test-only and a src change, before (042c013) vs after CI: 15 jobs, 73.7 runner-min, wall 466s -> 9 jobs, 21.6 runner-min, wall 208s (head run 37058370119; previous head 20.7, 203s). Pre-push: test-only 122.6 to 142.0s -> 58.5 to 60.8s; src 96.8s -> 29.8 to 31.6s; real pushes of this branch: hook 61 to 65s (5066 passed, 100%) Met (PR body updated)
2 Every OS-specific test still runs on its OS scratch draft PR #817: installer.py PATH split on ":" instead of os.pathsep, test.yml run 37057716159 on the reduced matrix both windows jobs FAIL (5 failed, 5005 passed: test_iter_skips_empty_path_segments and 4 selector tests); all ubuntu/macOS pytest jobs pass; PR closed unmerged, branch deleted Met
3 Oldest and newest Python on every kept OS run 37057234383 job list ubuntu py3.10 to 3.14; macos py3.10, 3.14; windows py3.10, 3.14 Met
4 100% coverage gate on at least one job with treesitter run 37057234383, job pytest (ubuntu-latest · py3.14) log pip install -e ".[dev,vertex,treesitter]", SUMO_QA_REQUIRE_TREESITTER: 1, repo_map_treesitter.py 36 0 100%, Required test coverage of 100% reached. Total coverage: 100.00% Met
5 Mutation gate unchanged (same modules, same no-new-survivors rule) git diff origin/main...branch on mutation.yml, check_mutation_gate.py, mutmut-baseline.json, [tool.mutmut] no change to the workflow, checker, baseline or source_paths; one added --ignore=tests/test_conformance_redos_subprocess.py (a new subprocess-spawning test, marker mutmut-subprocess-spawning, same pattern as the existing ignores); mutation.yml run 37058420037 on the head: success Met
6 New tool pinned exactly, used by CI and the pre-commit hooks pyproject dev extra + .pre-commit-config.yaml diff; test.yml pytest-xdist==3.8.0 in the dev extra and the hook's additional_dependencies; hook entry pytest -n auto --maxprocesses 4 --dist loadfile; CI jobs run pytest -n auto --dist loadfile; lockstep row in test_toolchain_pin_lockstep.py Met
  • real_repo: this repo's real suite and CI.
  • real_surface: real GitHub Actions runs and real pre-push hook runs.
  • existing_flow: clean wheels of 5c5f87b and origin/main 042c013, scoped haiku claude -p (sumo-qa only, no host skills): "load the QA classifications" -> sumo_qa_load_classifications (2297 B) and "is playwright-e2e installed" -> sumo_qa_check_external_skill_installed give identical tool sequences and byte-identical results on both builds; repos stayed clean. The lock-present path is covered by the new tests in tests/test_external_skills_provenance.py, not this run.
  • evals: N/A, no eval input in the diff.

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 tests/test_tools_list_contract.py, resolved by keeping both imports; #811 is rebased after #813 merges).

@sumithr
sumithr merged commit 7a84f9b into main Oct 2, 2026
28 checks passed
@sumithr
sumithr deleted the ci/issue-787-cut-ci-test-time branch October 2, 2026 21:43
sumithr added a commit that referenced this pull request Oct 2, 2026
🤖 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>
sumithr added a commit that referenced this pull request Oct 2, 2026
## 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: cut CI and pre-push test time (matrix size, per-push suite runs)

1 participant