Skip to content

Core: compile testkits in every debug build instead of behind a feature - #1960

Merged
gemcoder21 merged 1 commit into
mainfrom
testkit-debug-gate
Nov 19, 2026
Merged

gemcoder21 merged 1 commit into
mainfrom
testkit-debug-gate

Conversation

@gemcoder21

Copy link
Copy Markdown
Contributor

Why

Tests turned on other crates' testkit features through their dev-dependencies (about 140 manifest lines across 57 crates). A feature changes how a crate compiles, so every crate under a test was compiled twice: once for cargo build and once for cargo test. Cargo keeps both copies. The first cargo test after a cargo build, and the second of the two after every edit to a shared crate such as primitives, recompiled all 41 workspace crates under gemstone.

What changes

  • Testkits are declared #[cfg(any(test, debug_assertions))] (29 gates) and the 27 testkit features are gone. Debug builds and tests compile every crate the same way and share one set of artifacts.
  • Release builds leave the testkits out, so the App Store, Play and F-Droid libraries and the backend images carry no mock. Debug app builds compile them, and the linker drops what nothing calls.
  • just lint runs clippy a second time in release, where testkits do not exist, so production code that calls a mock fails lint and Core CI.
  • A crate consumes another crate's mocks through a plain dependency. core/skills/tests.md, core/skills/development-commands.md and docs/ARCHITECTURE.md § 10 describe the rule.

Measured

gemstone, fresh target dir, RUSTC_WRAPPER off, same machine, nothing else running:

Scenario main this PR Change
First cargo test -p gemstone --lib after cargo build -p gemstone --lib 40.4 s, 41 crates 24.4 s, 1 crate −40%
cargo build after cargo test, after an edit to primitives 9.2 s, 41 crates 4.3 s, 1 crate −53%
cargo test after cargo build, after an edit to primitives 11.5 s, 41 crates 5.2 s, 1 crate −55%
Edit primitives, then test and build (both steps) 19.2 s 14.1 s −27%
target/debug size after the run 7.1 GB 5.6 GB −21%
Cold cargo build -p gemstone --lib 39.9 s 38.9 s same

With nothing edited, switching between build and test was already instant on main (0.3 s), so the gain shows after edits and in fresh worktrees. CI jobs do not alternate build and test, so CI time does not change; the release clippy pass adds to the lint job, which runs alongside the longer unit-test job.

Checks

  • The test list of every one of the 87 test binaries is identical to main's, for the workspace run CI uses (5,193 tests) and with --all-features (5,576).
  • just test passes (5,190 passed, 3 ignored).
  • just lint (debug and release) and just build-integration-tests pass.

Notes

The companion PR for just test <crate> edits the same manifests' [dev-dependencies]; whichever lands second needs a one-line rebase in those files.

Tests turned on other crates' testkit features through their dev-dependencies, so every crate under a test compiled one way for cargo test and another for cargo build, and Cargo kept both copies. The first cargo test after a cargo build, and the second of the two after every edit to a shared crate, recompiled all 41 workspace crates under gemstone.

Testkits are now declared #[cfg(any(test, debug_assertions))] and the testkit features are gone, so debug builds and tests compile every crate the same way and share one set of artifacts. Release builds leave the testkits out, so the apps and the backend images carry no mock. just lint runs clippy a second time in release, where testkits do not exist, so production code that calls a mock fails it. core/skills/tests.md, core/skills/development-commands.md and docs/ARCHITECTURE.md describe the new rule.

Measured on gemstone in a fresh target dir: the first cargo test after cargo build went from 40.4 s (41 crates) to 24.4 s (1 crate), the second command after an edit to primitives from 9.2-11.5 s to 4.3-5.2 s, and target/debug from 7.1 GB to 5.6 GB. The test list of every one of the 87 test binaries is identical to main's, both for the workspace run CI uses (5,193 tests) and with all features (5,576); just test passes 5,190 with 3 ignored; just lint in debug and release and just build-integration-tests pass.
@gemcoder21
gemcoder21 merged commit a44a987 into main Nov 19, 2026
7 checks passed
@gemcoder21
gemcoder21 deleted the testkit-debug-gate branch November 19, 2026 00:31
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