Skip to content

#890 feat: route the commit hook's unit tests by the staged paths - #892

Merged
gregoryfoster merged 2 commits into
mainfrom
feat/890-test-speed
Nov 26, 2026
Merged

gregoryfoster merged 2 commits into
mainfrom
feat/890-test-speed

Conversation

@gregoryfoster

Copy link
Copy Markdown
Member

Refs #890. The issue stays open for the -m integration profile, deferred so it wouldn't share the test DB with the parallel #882 work.

Why

The pre-commit unit hook ran the whole unit tier on every commit, docs-only included: 707–805 s here. The profile (posted on #890) shows 87% of that is dbt-duckdb fixture builds. The other ~3,600 tests take about 86 s.

What

  • Routed hook (scripts/commit_tests.py, the pytest hook's new entry). It reads the staged set (git diff --cached --no-renames -z, deletions included):
    • nothing staged (a manual run, or CI's --all-files) → the whole unit tier;
    • only docs/** or *.md → only the test modules that name a doc (text match, plus a one-hop helper import);
    • anything else → the unit tier without dbt, plus dbt when a staged path is in the unit dbt modules' import closure, under src/core/ingestion/ or tests/core/ingestion/, or is pyproject.toml, uv.lock or tests/conftest.py.
    • scripts/pre-ship.sh still runs everything before a push.
  • pytest.mark.dbt on every test that builds. An autouse guard in the root conftest swaps the mapping package's dbtRunner for one that fails any unmarked test (tests/test_dbt_marker_guard.py).
  • Partial parse in the mapping fixture. Builds share one duckdb path and one target, so dbt partial-parses after the first build. Each build keeps its own store: the staging models are views over that store's paths, and test_build_cache.py pins that a later build doesn't change an earlier build's views.
  • Docs.
    • TESTING.md § Which tests run when: integration is opt-in, the hook's routing, the marker, and no xdist on this 2-vCPU host.
    • The mapping and applier tier sections move whole to docs/TESTING_INGESTION.md (TESTING.md was over budget at 10,045 tokens and is now ~9,400).
    • AGENTS.md's TESTING.md line names the integration rule at the same length.
    • Design doc: docs/plans/2026-11-26-commit-hook-test-routing-design.md.

No version bump: dev tooling and tests only.

Measured (this VM, 2 vCPUs, other worktrees' suites often running alongside)

Before After
Hook pytest, docs-only commit whole tier (707–805 s) doc-reading modules: 898 tests, 24 s
Hook pytest, code change out of dbt's reach whole tier fast tier: 3,865 tests, 124 s
Hook pytest, change in dbt's reach whole tier whole tier, dbt ~15% faster (A/B on two modules: 113 s → 94–99 s)
Real commit, docs-only (all hooks) >10 min 100 s
Real commit, this PR's code commit (whole tier, routed) — 697 s

The docs-only commit isn't yet "seconds". Its remaining ~70 s is the other always_run hooks: pytest-vendored 15 s, bats-vendored 16 s, vitest 16 s and bats 23 s. tests/test_vendored_subset.py pins those as always_run for the #755 refresh knob, so routing them belongs in a follow-up.

Verification

  • Red first: test_commit_tests.py (module missing), test_dbt_marker_guard.py (DID NOT RAISE, marker unregistered), and test_build_cache.py (no shared target).
  • The dbt tier on its own (131 tests, 517 s) and the fast tier (3,865 tests, 124 s) both pass. The fast run doubles as the guard's sweep: an unmarked dbt test would have failed it.
  • Both commits went through the real hook: the code commit routed to the whole tier, the docs commit to the doc readers.
  • Integration: only tests/scripts/test_curation_overlay_seam.py and tests/core/ingestion/mapping/test_real_snapshot.py, the integration modules whose marker changed. The full -m integration suite did not run.
  • scripts/pre-ship.sh: the vendored gate passed (3,996 unit tests, 334 vitest). The a11y step ran, because tests/conftest.py is in the admin scope list. The first run's browser tier failed with a deadlock and FK violations in its truncate-and-seed, the shared test DB in use elsewhere. A re-run with nothing else on the DB passed (lxml 203, browser 53).
  • test_curation_overlay_seam: 1 passed. test_real_snapshot: 8 skipped by name (no landed store in a worktree).

🤖 Generated with Claude Code

gregoryfoster and others added 2 commits November 26, 2026 01:32
…reak

The unit tier was ~12 min a commit, 87% of it dbt-duckdb fixture builds
(profile on #890). `scripts/commit_tests.py` now picks the pytest the
`pytest` hook runs from the staged set:

- nothing staged (a manual run, CI) -> the whole unit tier;
- docs/** or *.md only -> the test modules that name a doc (~25 s);
- otherwise the unit tier without `dbt`, which a staged path adds back when
  it is in the dbt modules' import closure, under src/core/ingestion/ or
  tests/core/ingestion/, or is pyproject.toml, uv.lock or tests/conftest.py.

pre-ship.sh still runs the whole tier before every push.

`pytest.mark.dbt` marks every test that builds; an autouse guard in the
root conftest fails an unmarked one, so none slips into the fast path.
The mapping fixture's builds share one duckdb path and target, so dbt
partial-parses after the first (~15% off the dbt tier); each keeps its
own store, because the staging views read its paths (test_build_cache).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/plans/2026-11-26-commit-hook-test-routing-design.md records the
profile, the routed hook, the dbt marker and partial parse, and what is out
of scope (the integration profile, dbt execution speed, xdist on this host).

docs/TESTING.md § Which tests run when: integration is opt-in (the whole
marker only on request; by default the modules mirroring the touched code),
the hook's routing, and the dbt marker. The mapping and applier tier
sections move whole to docs/TESTING_INGESTION.md for the budget (#444
rule); TESTING.md 10,045 -> ~9,400 tokens. AGENTS.md's TESTING.md index
line names the integration rule at the same length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gregoryfoster
gregoryfoster merged commit 37e7e9a into main Nov 26, 2026
1 check passed
@gregoryfoster
gregoryfoster deleted the feat/890-test-speed branch November 26, 2026 02:13
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.

1 participant