# trimtest > trimtest is a Rust CLI that runs only the tests a code change can reach. It builds a dependency graph per language (and, optionally, per-test coverage recordings), selects the affected tests, and runs them with each project's native runner. Notes for agents: - Selection is conservative: when trimtest cannot trace a change it runs the whole suite instead of guessing. - Exit codes: 0 passed or nothing selected, 1 a test failed, 2 trimtest itself failed, 3 selection is uncertain (run the full suite). - In pull requests use `trimtest run --base origin/`; it needs no recorded map. Keep a scheduled full run as a safety net. - A green subset is not a green suite: run `trimtest run --full` (or rely on the scheduled full run) before calling work finished. - Every page is also available as plain markdown by appending `.md` to its URL. - The trimtest.toml JSON Schema is at https://trimtest.dev/schema/trimtest.schema.json. --- # Quick start > Install trimtest, record a baseline, edit a file, and run only the tests that change reaches. ```bash cd your-repo trimtest init # writes a commented trimtest.toml and adds .trimtest/ to .gitignore trimtest detect # which projects were found, and how many tests each tracks trimtest record --coverage # run the suite once and learn what each test executes ``` `record --coverage` runs every test file on its own under the ecosystem's coverage tool (see the [requirements](/start/install/#requirements-per-language)). Use `trimtest record --run` for the static tier only: it runs everything once and records the baseline only if the run is green. Now change some code: ```bash trimtest select # which tests that change reaches, and why trimtest run # run just those with each project's native runner trimtest explain tests/test_core.py # why a test was, or was not, selected ``` `select` diffs the working tree against the recorded baseline, so uncommitted edits work. Its output names the reason for every selected test: ```text pytest: 1 of 1 tests selected tests/test_a.py [test changed] ``` ## In CI In a pull request you do not need a recording at all. Compare against the base branch: ```bash trimtest run --base origin/main ``` See [GitHub Actions](/guides/github-actions/) for a complete workflow, and keep a scheduled full run (`trimtest run --full`) as the safety net. ## Next - [How it works](/concepts/how-it-works/) and the [safety rules](/concepts/safety-rules/) - [`trimtest.toml`](/reference/config/) for ignores, runner prefixes, timeouts and project overrides - [For AI agents](/agents/for-ai-agents/) if an agent will be running trimtest --- # Install > Install a prebuilt trimtest binary, cargo install it, or build it from source, and see which tools each language needs. ```bash # prebuilt binary (Linux and macOS, x86_64 and arm64): verifies the checksum, installs to ~/.local/bin curl -fsSL https://raw.githubusercontent.com/RabinApps/trimtest/main/install.sh | sh # TRIMTEST_VERSION=v0.1.0 pins a release; TRIMTEST_INSTALL_DIR=/usr/local/bin changes the target # Windows (PowerShell): verifies the checksum, installs to %LOCALAPPDATA%\trimtest\bin irm https://raw.githubusercontent.com/RabinApps/trimtest/main/install.ps1 | iex # from crates.io (needs a stable Rust toolchain) cargo install trimtest # latest main, or a checkout cargo install --git https://github.com/RabinApps/trimtest trimtest cargo install --path crates/trimtest-cli ``` Binaries and checksums are also on the [releases page](https://github.com/RabinApps/trimtest/releases). The installer refuses to install when the checksum does not match. Check it worked: ```bash trimtest --version ``` ## Requirements per language trimtest drives your project's own runner and coverage tools; it installs none of them. | Ecosystem | Needed for selection | Needed for `record --coverage` | |---|---|---| | Python | `pytest` | `coverage` | | JS/TS | Node + Jest, Vitest or Playwright | same (V8 coverage, nothing extra) | | Rust | `cargo` | `cargo-llvm-cov` and `rustup component add llvm-tools-preview` | | Java/Kotlin | JDK + Gradle (or `./gradlew`) or Maven (or `./mvnw`) | same; JaCoCo is fetched by the build | | Go, Swift, Dart/Flutter, Zig | the language's own toolchain | no recorded tier | | SQL / PostgreSQL | `psql` (and `pg_prove` with pgTAP), plus a reachable database through the `PG*` variables | no recorded tier | Linux, macOS and Windows. On Windows use the PowerShell installer, `cargo binstall`, Scoop or winget; see the [Windows guide](/guides/windows/). --- # For AI agents > How an AI coding agent should use trimtest safely, with an AGENTS.md snippet, a Claude Code skill, exit-code handling and the machine-readable surfaces. If an AI agent edits code in a repository that uses trimtest, this page is the contract: when to trust a selection, what the exit codes mean, and how to fall back to the full suite. ## Machine-readable access to these docs | URL | What it is | |---|---| | [`/llms.txt`](/llms.txt) | index of the docs with a short description of each page | | [`/llms-full.txt`](/llms-full.txt) | every page concatenated as markdown | | `.md` | that page as plain markdown, for example `/start/quick-start.md` | | [`/schema/trimtest.schema.json`](/schema/trimtest.schema.json) | JSON Schema for `trimtest.toml` | | [`/skill/SKILL.md`](/skill/SKILL.md) | a Claude Code skill that wraps the rules below | ## The rules 1. **Select, then run.** After a change, `trimtest run` runs only the tests the change can reach. In a pull request or a fresh clone use `trimtest run --base origin/`; it needs no recorded map. 2. **Read the exit code** ([reference](/reference/exit-codes/)): - `0` passed (or nothing was selected): proceed. - `1` a test failed: fix it, then run again. Failed tests always run first next time. - `2` trimtest itself failed: read the message, run `trimtest check`. - `3` selection is uncertain: **run the full suite** with `trimtest run --full`. 3. **Trust the conservatism, not a green subset alone.** trimtest runs everything when it cannot trace a change. A green subset means the selected tests passed, not that the whole suite would. Before declaring a task done, or before merging, make sure the project's scheduled full run (or `trimtest run --full`) is green. 4. **Do not skip the nightly full run** or remove it from CI to save time. 5. **Set a timeout** so a hung runner cannot stall you: `trimtest run --timeout 600 --total-timeout 1800`. 6. **Never edit `.trimtest/`** by hand. It is a cache; delete it and run `trimtest record` if it looks wrong. ## Reading a selection ```bash trimtest select --json # structured: changed files, unobserved changes, selected tests with reasons trimtest select --paths # just the test paths, one per line trimtest explain tests/test_core.py # why one test was, or was not, selected ``` The [JSON shape](/reference/json-output/) is stable; new fields may be added. A non-empty `unobserved` list means a changed file is not known to reach any test, so consider `trimtest run --strict` or a full run. ## When a test you expected is missing 1. `trimtest explain ` prints every reason and the evidence tier. 2. If a dependency is invisible to imports (reflection, string-based access), record coverage: `trimtest record --coverage`. 3. For suites with no import link (end-to-end), add a `[map]` entry to `trimtest.toml`. ## Drop-in `AGENTS.md` snippet Paste this into the `AGENTS.md` (or `CLAUDE.md`) of a repository that uses trimtest: ````markdown ## Running tests This repo uses [trimtest](https://trimtest.dev) to run only the tests a change can reach. - After a change: `trimtest run` (or `trimtest run --base origin/main` on a branch or fresh clone). - Exit codes: 0 pass, 1 test failed (fix and rerun), 2 trimtest error (`trimtest check`), 3 selection uncertain (run `trimtest run --full`). - `trimtest explain ` says why a test was or was not selected. `trimtest select --json` is machine-readable. - A green subset is not a green suite: run `trimtest run --full` before you call a task finished or open a PR, and never remove the scheduled full run from CI. - Use `--timeout 600 --total-timeout 1800` for long suites. Do not edit `.trimtest/`. - Docs for agents: https://trimtest.dev/llms.txt ```` ## Claude Code skill Save [`/skill/SKILL.md`](/skill/SKILL.md) as `.claude/skills/trimtest/SKILL.md` in a repository (or in `~/.claude/skills/trimtest/` for every repository) and Claude Code will use these rules whenever it runs tests. --- # How it works > How trimtest fingerprints files, builds a reverse dependency graph and selects the tests a change reaches. 1. **`trimtest record`** snapshots every file by a *semantic fingerprint* (the token stream without comments and whitespace, where a grammar exists) and caches each file's imports in `.trimtest/map.json`. 2. **`trimtest select`** diffs the tree against that map, so uncommitted edits and stale branches work. It walks the *reverse* dependency graph from every changed file and prints the tests it reaches, with a reason chain. `--base ` compares against git instead and needs no map. 3. **`trimtest run`** selects, then invokes each project's native runner with a filter. Because the fingerprint ignores comments and formatting, reformatting a file or editing a comment selects nothing. ## What counts as a reason Every selected test carries one or more reasons, and `trimtest explain` prints all of them: | Reason | Meaning | |---|---| | `test changed` | the test file itself changed | | `new test` | the test file did not exist when the baseline was recorded | | `a.py -> tests/test_a.py` | a changed file is imported (directly or transitively) by the test | | `executes a.py (recorded)` | a recording shows the test ran code in the changed file | | `failed last run` | the test failed last time, so it always runs again first | | a full-run reason | a [safety rule](/concepts/safety-rules/) selected the whole project, and the reason says which | ## Evidence tiers Each selected test also records the *tier* of its evidence: `static` (import graph), `recorded` (coverage measurement), `rule` (configuration) or `full` (the whole suite was selected). See [Static vs recorded tier](/concepts/tiers/). ## Non-code files Fixtures and data files select tests whose source mentions the file name. ## When trimtest cannot tell It never guesses. See [Safety rules](/concepts/safety-rules/) for the cases where the whole suite runs instead. --- # Static vs recorded tier > The static import graph, the recorded coverage tier, which languages have which, and what falling back to the static graph means. ## Static tier The static tier uses only the import graph. It needs no recording and works with `--base `. It is precise where imports are explicit (Dart, Go, TS/JS, Rust, Python), module-level for Swift, and conservative around dynamic features (reflection, dependency injection, `eval`, macros, named Zig modules, Playwright E2E). ## Recorded tier `trimtest record --coverage` runs every test file on its own under the ecosystem's coverage tooling and stores the files it actually executed: `coverage.py` for pytest, V8 coverage for Jest and Vitest, `cargo llvm-cov` for Rust, JaCoCo for Java and Kotlin. `select` and `run` then use those measurements for any test with a valid recording (`--tier static` ignores them). Recordings: - catch dependencies the import graph cannot see (`importlib.import_module`, `await import(variable)`, reflection, service loaders, DI-created classes), - skip imports that never executed (for example type-only imports erased by the compiler), - are ignored if the test file changed since, if the coverage tool version changed, or if you compare against another `--base`; those tests fall back to the static graph. Re-recording keeps every recording whose test file and executed files are unchanged and re-measures the rest (`--remeasure` forces everything). `record` baselines the tree *after* the run, so files tests create, like `Cargo.lock`, are not seen as changes. ## Which languages have which | | static | recorded (`--coverage`) | function-level | |---|---|---|---| | Python (pytest) | yes | yes | yes | | JS/TS (Jest, Vitest) | yes | yes | yes (by function name) | | Playwright | yes (`[map]` for E2E) | yes (Chromium JS coverage; only adds to the static graph) | no | | Rust | yes | yes (`cargo llvm-cov`) | yes | | Java (Gradle, Maven) | yes | yes (JaCoCo) | yes (by method signature) | | Kotlin (Gradle, Maven) | yes | yes (JaCoCo) | yes (by function signature) | | Go | yes | yes (`go test -coverprofile`) | yes | | Dart, Flutter | yes | yes (`dart test --coverage`, `flutter test --coverage`) | yes | | Swift (SwiftPM) | yes | yes (`swift test --enable-code-coverage`) | yes | | Objective-C (SwiftPM targets) | yes | yes (same tool, file-level) | no | | Zig | yes | no | no | | Python (unittest, nose2, behave) | yes | yes (coverage.py) | yes | | Mocha, `node:test` | yes | yes (V8 coverage) | yes (by function name) | | Bun, Deno, Cypress, WebdriverIO | yes (`[map]` for E2E) | no | no | | Flutter Patrol | yes | no (needs a device) | no | | Maestro, Detox, Android instrumented | yes | no (needs a device) | no | | Ruby (RSpec, Minitest) | yes | no | no | | PHP (PHPUnit, Pest) | yes | no | no | | .NET (xUnit, NUnit, MSTest) | yes | no | no | | Elixir (ExUnit) | yes | no | no | | SQL / PostgreSQL (pgTAP, psql scripts) | yes | no | no | ## What "falls back to the static graph" means Zig has no recorded tier, so it uses the static graph; so does any other language where `record --coverage` has no support. They do **not** run every test: the graph decides, and the safety rules still apply. Go, Swift and Dart resolve imports at compile time, so the static graph is already exact there, before any recording. Statement-less files such as Go constants never appear in coverage output, which would make recordings *less* safe, so they are deliberately not recorded. ## Tests that start other processes Tests that spawn child processes (Rust `Command::new`/`CARGO_BIN_EXE_*`, Python `subprocess`/`os.system`, JVM `ProcessBuilder`) cannot be measured through their children. `record --coverage` records them as depending on every file of the project, so they run on any change. Node children inherit the V8 coverage environment, so Jest and Vitest are measured normally. --- # Safety rules and when everything runs > The cases where trimtest runs the whole suite for a project instead of guessing which tests a change affects. trimtest runs the whole suite (per project) instead of guessing when it cannot trace a change: - **No baseline recorded yet.** - **A full-run trigger changed:** a lockfile, a build config, or a file matched by `[full_run] extra`. - **A tracked path git reports is not a source file trimtest parses:** a submodule bump, an ignored path. - **`--strict` or `on_unobserved = "full"`** and a change that no test is known to reach. - **A tracked file was deleted that no test is known to depend on.** It can still break the build, for example a Cargo `[[bench]]` target. A project with no tests runs nothing. ## Always-run tests - New tests and tests that failed last time always run, ahead of the rest. - When a run is narrowed (`--project`, `--shard`) the failures from the parts you did not run are kept for next time. ## Unobserved changes A changed file that nothing is known to depend on is reported as `unobserved`. By default that is a warning; set `on_unobserved = "full"` (or pass `--strict`) to run everything instead. Under the default, such a change selects nothing by itself, so it can under-select: `select --json` reports it as `uncertain`, and `select --exit-code` exits `3` when nothing else is selected. ## Why it is built this way A missed failure costs far more than a slightly larger test run. Every rule above favours running more. The [soundness bench](/trust/soundness/) mutates real open-source projects to check that this holds. --- # Function-level selection > How Python and Jest/Vitest recordings select tests by the functions they executed, not just by file. With a `--coverage` recording, Python and JS/TS tests are selected at *function* level: an edit to a function a test never executed selects nothing. ## Python The recording keeps which function bodies ran (coverage.py line data mapped to each function's body). Files are split into units: functions and methods, class headers, and module-level statements, each with its own comment-insensitive hash. A changed file selects a test only if: - a function it executed changed or was removed, - a changed module-level name (`LIMIT = 5`) or class header is mentioned by code that test ran, here or in an importer (`from m import *` always counts), - a class header changed and the test ran one of its methods, or - import-time code with no bound name changed (imports, bare calls, `if` and `try` blocks). An unrelated function edit, an unexecuted function, or an edit to an `if __name__ == "__main__":` block selects nothing. Name matching is by identifier, not by call graph, so it errs toward selecting. Dynamic access by string (`getattr(mod, "LIMIT")`) is not seen. ## Jest and Vitest V8 coverage has no usable line numbers (offsets refer to transformed code), but it lists every function by name with a call count. Files are split into units the same way (functions, `const f = () => ..`, class methods, class headers, other statements) and a unit counts as executed when a function with its name was called. This is conservative by construction: - same-named functions (`run` in two classes) share a verdict, - a unit the runtime never listed counts as executed, - if none of a file's functions are recognised (names mangled by a transform) the file stays file-level, - `export default`, destructuring declarations, imports and re-exports, and any statement with no bound name are treated as "any change counts"; `export * from` makes every changed name relevant. TypeScript types are tracked by name like any other declaration. Verified on Vitest 2 and Jest 29. Vitest is measured with `--pool=threads` because forked workers are killed before they flush V8 coverage. ## Other languages Rust and Java/Kotlin recordings are file-level: a changed file selects every test that executed it. --- # Python (pytest) > How trimtest selects pytest tests, records coverage with coverage.py, and what it needs. | | | |---|---| | Runner | pytest | | Static graph | tree-sitter imports, the package `__init__` chain, `conftest.py` scoping | | Recorded tier | yes, with `coverage` installed; function-level | | Runner prefix | `[runner] python = "uv run"` (detected from lockfiles otherwise) | ## Static graph Imports are parsed with tree-sitter. A package's `__init__.py` chain counts as a dependency, and a changed `conftest.py` selects the tests it scopes. Use `import_roots = [dirs]` in [`trimtest.toml`](/reference/config/) for extra import roots (a `src/` layout, for example). A pyproject, `setup.py` or `pytest.ini` marks a project; workspace members (uv, PDM) are part of their parent. ## Recording ```bash pip install coverage trimtest record --coverage ``` Each test file runs on its own under coverage.py, with `-p no:xdist` so workers do not hide executions. A project's `.coveragerc` is honoured (only its `concurrency` setting is kept, so the recording stays measurable). Selection is then [function-level](/concepts/function-level/). Coverage runs in the same environment as the tests: with a `uv.lock` or `poetry.lock` the command becomes `uv run python -m coverage ...` / `poetry run python -m coverage ...` — or, when the project keeps its environment in `.venv` (or points `UV_PROJECT_ENVIRONMENT` at one), that interpreter directly — so `coverage` has to be installed in that environment rather than on the system interpreter (`uv pip install coverage`, `poetry add --group dev coverage`). Otherwise the recording comes out empty and trimtest falls back to selecting every test. ## Things to know - Tests that start other processes (`subprocess`, `os.system`, `asyncio.create_subprocess_*`, `ProcessPoolExecutor`, `os.fork`, `pty`) cannot be measured through their children, so they run on any change. - Decorator and default-parameter changes count as a change to the function they belong to. - `getattr(mod, "NAME")` and other access by string is not seen by name matching. --- # JavaScript and TypeScript > How trimtest handles Jest, Vitest and Playwright, tsconfig paths, workspaces and package exports. | | | |---|---| | Runners | Jest, Vitest, Playwright | | Static graph | `import`, `require`, `import()`, `jest.mock`, tsconfig `paths`, barrel files | | Recorded tier | Jest and Vitest, function-level by name; Playwright (Chromium), file-level, adds to the static graph | | Runner prefix | `[runner] js`, `jest`, `vitest` or `playwright` (detected from lockfiles otherwise) | ## Static graph Beyond plain imports, trimtest follows tsconfig `paths`, barrel re-exports, npm/pnpm/yarn **workspace packages** (by package name, including the `exports` map with its `./sub` keys and `*` patterns), and `package.json` `imports` aliases such as `#internal/*`. ## Recording `record --coverage` sets `NODE_V8_COVERAGE` and runs each test file alone. Node children inherit it, so tests that spawn Node processes are measured normally. Vitest runs with `--pool=threads` because forked workers are killed before they flush coverage. Selection is [function-level by name](/concepts/function-level/). Verified on Vitest 2 and Jest 29. If your config overrides the pool (Vitest `poolMatchGlobs`, for example) the recording is not trusted and those tests use the static graph. ## Playwright Playwright tests are selected from the static graph, and file paths are regex-escaped when passed to the runner (so `e2e/[id].spec.ts` works). E2E suites usually have no import link to the code under test: map them yourself in [`trimtest.toml`](/reference/config/): ```toml [map] "api/**" = ["web/e2e/**"] ``` ### Recorded tier (Chromium) `record --coverage` runs each spec file alone (`--workers=1`) with a small trimtest hook loaded into the Playwright worker (through `NODE_OPTIONS`, so your config is never replaced). The hook starts Chromium's `page.coverage.startJSCoverage({ resetOnNavigation: false })` on every page of every context, and when the page or context closes it writes the scripts that ran. trimtest maps those scripts to repository files: inline and `.map` source maps are read, and `webpack://`, `webpack-internal://`, `turbopack://`, `/@fs/` and `/src/x.ts?t=...` style URLs are rewritten to repo-relative paths. Selection is file-level. Browser coverage only ever **adds** to what the static graph and `[map]` already say. The recording of a spec is the files its pages executed plus everything the spec statically depends on, so: - A script the page never loaded does not select the spec (editing `public/unused.js`), while one it ran does. - Node-side code the spec imports (page objects, fixtures, helpers), backend and SSR code, CSS, HTML and environment or `webServer` config are invisible to browser coverage. Their static edges and your `[map]` rules keep selecting the spec exactly as before. A loaded HTML document is recorded as a file the spec used. - A first-party script that cannot be traced to a repository file (a bundle with no source map, a `blob:` or `data:` script) makes the spec depend on every file of the project, and so do web or service workers the page started (their scripts are not part of the page's measurement). - A spec is left on the static graph when it never opens a page, when any of its projects is not Chromium (the coverage API is Chromium-only), when it calls `page.coverage.startJSCoverage` itself, or when collecting fails, including a popup the app closes by itself (`window.close()`) before the spec ends. Source maps are only as good as your dev server or build: use the dev server (Vite, webpack, Next) or build with `sourcemap: true`. If a source map's `sources` name a file that is not in the repository, the script counts as untraceable. `sourceMappingURL`s that point at an http server are fetched while the web server is still up. ## Things to know - A lockfile or build config change forces a full run of that project. - `.vue`, `.svelte` and `.astro` files are tracked; their script blocks are parsed for imports. --- # Rust > How trimtest selects cargo tests, records per-test coverage with cargo llvm-cov, and what stays attached. | | | |---|---| | Runner | `cargo test` | | Static graph | `mod`, `use`, `crate::` paths, workspace crate names, inline `#[cfg(test)]` tests | | Recorded tier | yes, with `cargo-llvm-cov`; file-level | ## Recording ```bash cargo install cargo-llvm-cov rustup component add llvm-tools-preview trimtest record --coverage ``` Each integration test (`tests/*.rs`) and each file with inline `#[cfg(test)]` tests runs alone under `cargo llvm-cov`. Inline files filter by module path, so they run that file's tests plus any whose module path matches. Rust has no reflection, so the gain is narrowing, not catching hidden dependencies: a test that imports a module but never runs the code that uses `heavy.rs` is not selected when `heavy.rs` changes. ## What stays attached Coverage cannot vouch for everything, so these stay attached to the tests that statically depend on them: - constants and statics, `macro_rules!`, and `include_str!` users, - files declaring `struct`, `enum`, `trait`, `type`, `impl` or derives, which have no executable line of their own, - proc-macro crates and every crate that depends on one, - everything under `tests/`, `benches/` and `examples/` (llvm-cov leaves those out). Deleting a file that no test depends on runs the whole project, because it can still break the build (a Cargo `[[bench]]` target, for example). ## Things to know - Tests that use `Command::new` or `CARGO_BIN_EXE_*` start other processes, so they run on any change. - Doctest-only units cannot be measured; recording continues past them. --- # Java and Kotlin > How trimtest runs Gradle and Maven tests, records coverage with JaCoCo, and which files stay attached. | | | |---|---| | Runners | Gradle (or `./gradlew`), Maven (or `./mvnw`) | | Static graph | `import`, wildcard imports, same-package references | | Recorded tier | yes, with JaCoCo (fetched by the build); function-level (by method signature) | ## Recording Each test class runs alone under JaCoCo and the executed source files are kept. - **Gradle:** an init script (`-I`, so nothing in your build files changes) applies the `jacoco` plugin to every `java` project and makes the report cover **all modules' classes**, since a test may exercise its dependencies. - **Maven:** the `jacoco-maven-plugin` goals are invoked directly. For multi-module builds one shared exec file collects the whole reactor (`-pl -am`) and a report is produced per module, so a test executing code in a dependency module is still seen. **Vacuous passes.** A Maven reactor build (`-pl -am`, or a root pom with ``) must let modules without a matching test pass, so surefire exits 0 even when the selected test ran nowhere (an abstract class, a renamed class). After such a run trimtest looks for a fresh `surefire-reports/TEST-.xml` (or `failsafe-reports`) with at least one test for every selected class, and prints `trimtest: uncertain: selected test(s) ran no tests: ...` with exit code 3 when it is missing. A suite whose tests were all skipped still counts as having run. Gradle needs no check: `--tests` matching nothing fails the build. This catches reflection, `Class.forName`, service loaders and DI-created classes that the import graph cannot see. Verified with a multi-module Gradle 8 build (Java and Kotlin) and Maven builds on JDK 17. ## Function-level selection With a JaCoCo recording, an edit to a method or function that the test never ran does not select it. Units are keyed by signature (`Svc.used(int)`, Kotlin `Svc.used(Int)`), so overloads stay apart. Everything else in a type (fields and property initializers, `init` and static blocks, constructor parameters, supertypes, enum entries, and the set of members) is its header: a change there selects the tests that ran any method of the type or that mention the changed name. For Kotlin, a function's range is its whole declaration, so default-argument expressions and expression bodies count. Secondary constructors and custom property accessors are functions. Top-level properties, imports and every `inline` or `reified` function always count, because JaCoCo credits inlined code to the caller's file. A Kotlin file whose class body starts on the declaration line (`class A { val x = 1 }`) does not parse cleanly with the grammar trimtest uses and stays at file level. ## What stays attached JaCoCo cannot vouch for compile-time constants (`static final`, `const val`), `inline` code, statement-less classes (interfaces, annotations, abstract and sealed types, enums) or test helpers (only main classes are measured). Those files stay attached to every test that statically depends on them, as do classes a test mocks by name. Build files (`pom.xml`, `build.gradle*`, `settings.gradle*`, version catalogs, `buildSrc/`, `.mvn/`, wrapper properties) force a full run of the project. ## Gradle file watching trimtest passes `-Dorg.gradle.vfs.watch=false` to every Gradle command it builds. Gradle's file watcher can miss an edit made shortly after a build, so `compileJava` comes back `UP-TO-DATE` and the selected test runs against stale classes and passes. Gradle before 6.5 ignores the property. ## Limits - Android modules (no `java` plugin) fall back to the static graph. - Only the default `test` source set is recorded for Gradle; other source sets (`integrationTest`, `jvmTest`) use the static graph. - Tests that use `ProcessBuilder` or `Runtime.exec` run on any change. --- # SQL and PostgreSQL > How trimtest selects pgTAP and plain psql test scripts for SQL and PostgreSQL projects. trimtest runs SQL tests in two forms and selects them from the static graph only (no recorded tier). The [safety rules](/concepts/safety-rules/) apply: what it cannot trace runs more tests, never fewer. | Form | How it is recognised | Command | |---|---|---| | pgTAP | the script calls `plan()`, `no_plan()`, `runtests()` or `finish()` | `pg_prove ` | | Plain script | any other test script | `psql -X -q -v ON_ERROR_STOP=1 -f `, one process per file | A script is a **test** when its name ends in `_test.sql`, `_tests.sql` or `.test.sql`, starts with `test_`, sits in a `test/`, `tests/` or `t/` directory (not under `fixtures/`, `data/`, `helpers/`, `support/`, `lib/` and similar, and not called `setup*`, `teardown*` or `schema*`), or is a pgTAP script. Add [`[tests]`](/reference/config/) globs for other conventions. ## Detection The directory above the `test/`, `tests/` or `t/` folder is the project root, and `pg_prove` and `psql` run there. A project is detected when a script in such a folder is a pgTAP test or has a test-looking name. A plain script in `tests/` with neither only counts when no other project (Python, Ruby, ...) shares its root, because those repositories keep SQL fixtures there. Force a project with: ```toml [[project]] kind = "sql" dir = "db" ``` ## The database trimtest never creates, migrates or drops a database. Tests run against whatever the usual `PG*` variables (`PGHOST`, `PGPORT`, `PGDATABASE`, `PGUSER`, `PGPASSWORD`, `PGSERVICE`) or a `~/.pgpass` entry describe, exactly as if you had typed the command. A failed connection makes `psql` or `pg_prove` exit non-zero, so those tests count as failed. To run inside a container, prefix the commands: ```toml [runner] sql = "docker compose exec -T db" ``` ## What selects what A file **provides** the objects it creates, alters, drops or writes to: `create table users`, `alter function f`, `insert into items`, `create index .. on t`, `comment on` and `grant .. on`. It **depends on** every identifier it mentions, including names inside strings and function bodies (`has_table('users')`). Tests that name `users` are selected when a file providing `users` changes, and so are tests of files that reference it in turn (a foreign key or a view over the table). - `\i path` and `\ir path` are file edges. `\i` is relative to the project root (where psql runs), `\ir` to the including file. - `COPY .. FROM 'file'` and `\copy .. from 'file'` with a literal path make the script depend on that file. - Comments and whitespace do not count as a change. Strings, quoted identifiers, dollar-quoted bodies (`$$ .. $$`), psql meta-command lines and `/*+ hint */` comments do. - A script that runs as `begin; .. rollback;` (the pgTAP idiom) leaves nothing behind, so other files do not depend on its objects. Temp objects are never providers, and a test that does not roll back still provides what it creates. - A new test always runs. ## What runs everything - `migrations/`, `migrate/`, `db/migrate/`, `deploy/`, `revert/` and `verify/` (sqitch) below the project root. - `sqitch.plan`, `sqitch.conf`, `.proverc`, `pg_prove.conf`, `.psqlrc`, `schema.sql` and `structure.sql`. ## What makes a file depend on everything Anything the static graph cannot see makes the file depend on every non-test file of the project, so a change anywhere selects what uses it: `EXECUTE` of built SQL (`EXECUTE format(..)`, but not `GRANT EXECUTE` or `EXECUTE FUNCTION` in a trigger), `\gexec`, and a variable used as an include path (`\i :file`). ## Limits - Static only. A name used only through `search_path` tricks, a role-dependent default, or an extension's own objects is not traced; the same name in two files links the test to both. - A SQL file read by another project's tests (a seed loaded by a Python test) still selects those tests: they are matched by file name as for any data file. - Results come from the exit status. A failing `pg_prove` run marks every file in that command as failed. --- # Go, Swift, Dart and Zig > How trimtest selects tests for Go, SwiftPM, Dart/Flutter and Zig projects. The static tier selects tests here from the import graph, and the [safety rules](/concepts/safety-rules/) still apply. Go, Swift and Dart/Flutter also have a recorded tier (`record --coverage`); Zig does not. ## Go Runner: `go test`. A package is its directory, and imports are resolved against the module path, including `go.work` workspaces and `replace` directives. Go resolves imports at compile time, so the static graph is exact. With `record --coverage` (`go test -coverprofile`), selection is function-level: an edit to a function or method the test never ran selects nothing. Types, `var`/`const`/`import`, `init` and added or removed methods always count. Verified end to end against real `go test`. ## Swift Runner: `swift test` (SwiftPM). Static selection is module-level, from the SwiftPM target layout. With `record --coverage`, each test file runs with `swift test --enable-code-coverage` and is selected by the functions it executed. Xcode projects (`*.xcodeproj`) are a separate adapter, described below. **Objective-C** sits beside Swift in the same adapter: the `.m`, `.mm`, `.h`, `.c`, `.cpp`, `.hpp` and `.modulemap` files of a SwiftPM target are tracked, and an XCTest class written in Objective-C is a test when it is in a test target and has a `- (void)testX` method (or is a `*Tests : XCTestCase` class). Edges come from `@import Module;`, `#import ` (the module), `#import "path.h"` (the including file's directory, then any owned header that ends in that path, which is how a dependency's public headers are found) and `#import "Module-Swift.h"` (the Swift half of a module). A Swift file that imports an Objective-C target already reaches all of its files. Comments and formatting do not count as a change; strings, macros and the line structure of preprocessor directives do (joining the next line onto a `#define` is a change). A test run uses `--filter Target.Class` for each `@implementation`. With `record --coverage`, Objective-C tests are recorded like Swift ones but tracked per file, not per function. Not covered: bridging headers of SwiftPM app targets, and Carthage layouts. Verified end to end against real `swift test`; a runner that hangs is killed by [`--timeout`](/guides/timeouts/) along with the `xctest` it started in its own session. ### Xcode projects Runner: `xcodebuild test`. Each `Foo.xcodeproj` is its own project (`xcode@Foo.xcodeproj`), read from `project.pbxproj`: the targets, the files each one builds (build phases, resources, and Xcode 16 synchronised folders with their exception lists), and how targets relate. A unit or UI test bundle (`bundle.unit-test`, `bundle.ui-testing`) holds the tests; XCTest and Swift Testing in Swift and XCTest in Objective-C are recognised the same way as in SwiftPM. Selection is target-level, like SwiftPM's. A test file depends on every file of its own target and of everything that target is built after, hosted by (`TEST_HOST`, `BUNDLE_LOADER`), drives (`TEST_TARGET_NAME`) or links, so an edit to any of those selects the test bundle's tests. A source file reaches the tests through the modules and headers it is imported from. A file that no target builds cannot affect a test and selects nothing. Comments and formatting do not count; the Swift and Objective-C fingerprints are the SwiftPM ones. These run the whole project, because they change how targets build and cannot be traced to a file: `project.pbxproj` (adding a file to a target is such a change), `*.xcconfig`, `*.xctestplan`, `*.xcscheme`, `Info.plist`, `*.entitlements`, `Podfile.lock`, `Package.resolved`, and anything inside a local Swift package the project uses. A test is run through a shared scheme whose test action (or test plan) lists its bundle, as `xcodebuild test -project Foo.xcodeproj -scheme S -destination ... -only-testing:Bundle/Class`, one command per scheme. A test that no shared scheme runs is reported as unrunnable instead of being dropped: share the scheme (Product > Scheme > Manage Schemes > Shared). With a CocoaPods `Podfile` and a workspace of the same name, the workspace is built instead. The destination is this Mac for macOS targets and the newest installed simulator (a booted one first) for iOS, tvOS, watchOS and visionOS; set `TRIMTEST_XCODE_DESTINATION` (for example `platform=iOS Simulator,name=iPhone 16`) to choose one. `[runner] xcode = "..."` prefixes the command. Runs pass `-collect-test-diagnostics never`: after a failing test `xcodebuild` otherwise spends up to ten minutes collecting simulator diagnostics (`simctl diagnose`), and a failing test is the normal result of a run that found a change's effect. Set `TRIMTEST_XCODE_DIAGNOSTICS=on-failure` to restore it, or empty to pass nothing. With `record --coverage` each test file runs with `-enableCodeCoverage YES` and the result bundle is read with `xccov`: selection is function-level for Swift and file-level for Objective-C. Verified end to end against real `xcodebuild` (Xcode 27) on a macOS app with a hosted test bundle; iOS simulator destinations, UI tests and CocoaPods workspaces are built from the same code but were not run here. The bundled `xcodeshop` bench project (2 frameworks, a host app, 3 test bundles) had zero misses over 12 mutations, a delete, a rename and a broken `project.pbxproj`, static and recorded. Not covered: cross-project references (a target that depends on another `.xcodeproj`), XCFramework or binary targets, and run-script phases that generate sources. ## Dart and Flutter Runners: `flutter test` or `dart test`. Edges come from `import`, `export` and `part` directives and `package:` URIs, including `package:` imports of path dependencies and pub workspace members. Plain `integration_test/` files are not run by trimtest. Files calling `patrolTest(` (or in `patrol_test/`) are Patrol tests, run with `patrol test --target ` on a device and selected from the static graph only; `android/`, `ios/`, `macos/`, `linux/`, `windows/`, `web/` and `.patrol.env` run everything. `[[project]] kind` accepts `patrol`, `maestro`, `detox`, `android-instrumented`, `dotnet`, `elixir`, `ruby`, `php` and `sql` to force these adapters. With `record --coverage` (`flutter test --coverage`, `dart test --coverage`) selection is function-level: a `testWidgets` test that never builds a widget or calls a method is not selected when that code changes. Files with `part`/`part of` (including generated `.g.dart` and `.freezed.dart`) stay file-level. Non-Dart inputs are handled conservatively: - Assets, fonts and shaders declared under `flutter:` in `pubspec.yaml`, any `.arb` file, `pubspec.yaml`, `pubspec.lock`, `build.yaml`, `l10n.yaml`, `dart_test.yaml` and `analysis_options.yaml` run every test of the package when they change, because Flutter loads them by name at run time. - A file a Dart source names with a string literal (a golden given to `matchesGoldenFile`, a fixture opened with `File('test/fixtures/in.json')`) selects the tests that import that source, and a recorded test that ran it. A golden named by an expression selects the test that uses it for any change beside it. Verified end to end against real `flutter test` and `dart test` (Flutter 3.50 / Dart 3.14), and benchmarked on the Flutter team's `compass_app` (see [soundness](/trust/soundness/)). ## Zig Runner: `zig build test`. Edges come from `@import("x.zig")`, and inline `test` blocks count as tests. Named modules are not followed, so those changes are conservative. Covered by unit tests and `--dry-run` so far. --- # GitHub Actions > A copy-paste GitHub Actions workflow that runs only affected tests on pull requests and everything on main and nightly. Pull requests run only the affected tests; `main` and a nightly schedule run everything as the safety net. ```yaml name: tests on: pull_request: push: branches: [main] schedule: - cron: "0 3 * * *" jobs: test: runs-on: ubuntu-latest steps: # The base ref must be in the history, so fetch it all. - uses: actions/checkout@v6 with: { fetch-depth: 0 } # Installs the latest release to ~/.local/bin. Pin it with TRIMTEST_VERSION=v0.1.0. - name: Install trimtest run: | curl -fsSL https://raw.githubusercontent.com/RabinApps/trimtest/main/install.sh | sh echo "$HOME/.local/bin" >> "$GITHUB_PATH" # ...your toolchain setup here (actions/setup-python, actions/setup-node, ...)... - name: Affected tests (pull request) if: github.event_name == 'pull_request' run: trimtest run --base origin/${{ github.base_ref }} --timeout 900 - name: Full run (main and nightly) if: github.event_name != 'pull_request' run: trimtest run --full --timeout 1800 ``` ## Notes - **`fetch-depth: 0`** is required: `--base origin/` compares against git, so the base commit must exist. - **`--base` needs no recorded map**, so there is nothing to cache between runs. Recordings from `record --coverage` are tied to the commit they were made at and are ignored (with a warning) against another `--base`. - **Keep the nightly full run.** It is the safety net behind every selection. - **Always set a timeout.** See [Timeouts](/guides/timeouts/). - To split a large suite across jobs see [Sharding](/guides/sharding/), and for what the exit codes mean see [Exit codes](/reference/exit-codes/). ## Skipping the job when nothing is affected Run `select` first and gate later jobs on its output: ```yaml select: runs-on: ubuntu-latest outputs: any: ${{ steps.sel.outputs.any }} count: ${{ steps.sel.outputs.count }} steps: - uses: actions/checkout@v6 with: { fetch-depth: 0 } - run: curl -fsSL https://raw.githubusercontent.com/RabinApps/trimtest/main/install.sh | sh - id: sel run: ~/.local/bin/trimtest select --base origin/${{ github.base_ref }} --format github test: needs: select if: needs.select.outputs.any == 'true' # ... ``` `--format github` appends `any`, `count` and a `matrix` of `{adapter, cwd, command}` to `$GITHUB_OUTPUT`. --- # Sharding > Split the affected tests across CI jobs with --shard, or fan out per-command with the GitHub matrix output. ## `--shard i/n` `--shard 2/4` runs shard 2 of 4. Each selected test goes to a shard by a stable hash of its path, so the shards are roughly (not exactly) equal and together cover every selected test exactly once. A shard with nothing to run exits 0. ```yaml test: runs-on: ubuntu-latest strategy: fail-fast: false matrix: shard: [1, 2, 3, 4] steps: - uses: actions/checkout@v6 with: { fetch-depth: 0 } - run: curl -fsSL https://raw.githubusercontent.com/RabinApps/trimtest/main/install.sh | sh - run: ~/.local/bin/trimtest run --base origin/${{ github.base_ref }} --shard ${{ matrix.shard }}/4 ``` ## Narrowing by project `--project pytest@api` (repeatable; alias `--only`) runs only projects whose name contains that text. Names look like `@`; `trimtest detect` lists them. ## Failures from the other shards A narrowed run (`--shard` or `--project`) only knows about its own part, so it keeps the failures recorded for the rest and does not clear them. ## Matrix of commands `trimtest select --format github` writes a `matrix` output of `{adapter, cwd, command}` entries, one per runner command, so a job can fan out over the exact commands trimtest would run: ```yaml strategy: matrix: ${{ fromJSON(needs.select.outputs.matrix) }} steps: - run: ${{ matrix.command }} working-directory: ${{ matrix.cwd }} ``` --- # Monorepos > How trimtest finds projects in a monorepo, how nested projects and workspace members work, and how to override detection. trimtest walks the repository for project markers (a `pyproject.toml`, `package.json`, `Cargo.toml`, `go.mod`, `pubspec.yaml`, `Package.swift`, `build.zig`, `pom.xml`, `build.gradle*`, ...) and treats each as a project with its own adapter, runner and baseline. ```bash trimtest detect # which projects were found, and how many tests each tracks trimtest check # validate trimtest.toml and list what would be detected ``` ## Nested projects and workspace members A project nested under another is its own project **unless** it is a workspace member of it: npm, pnpm and yarn workspaces, `go.work` and `replace`, uv and PDM workspaces, and Cargo and Gradle or Maven modules. Members are part of their parent, so a change in one member can select tests in another. A project with no tests runs no commands, so a nested example package does not make a runner fail with "no tests ran". ## Controlling detection ```toml # trimtest.toml max_depth = 8 # how deep project markers are searched (default 6) ignore = ["vendor/**", "examples/**"] [[project]] # force a project the markers cannot find kind = "python" dir = "svc" ``` Use `tests = [globs]` to add files that are tests but do not follow the runner's naming convention, and `import_roots = [dirs]` for extra Python import roots. ## Suites with no import link End-to-end suites often depend on code they never import. Map the changed paths to the tests yourself: ```toml [map] "api/**" = ["web/e2e/**"] ``` ## Running one part ```bash trimtest run --project pytest@api ``` --- # Timeouts > Kill a hung test runner and everything it started with --timeout and --total-timeout. A hung runner can stall CI for hours, and some runners start children in their own session (`swift test` starts `xctest` that way). trimtest kills the runner **and every descendant**, not just the process it started. ## Per command ```bash trimtest run --timeout 600 ``` ```toml # trimtest.toml timeout = 600 ``` A runner command that runs longer than 600 seconds is killed with everything it started. Its tests count as failed, are remembered, and run first next time. The flag overrides the config key; `0` or unset means no limit. ## Whole run ```bash trimtest run --total-timeout 1800 ``` ```toml total_timeout = 1800 ``` After 1800 seconds in total the command in flight is killed and the remaining commands are **not started**; their tests count as failed too. Each command gets whichever limit is smaller: the per-command `timeout` or what is left of the whole-run budget. The flag overrides the config key; `0` or unset means no limit. ## Exit code A timeout is a test failure, so the run exits `1` and prints which command was killed. ## `record` `trimtest record --timeout ` (or `timeout` in `trimtest.toml`) applies the same limit to every command that `record` runs, including the per-test measurements of `--coverage`. A measurement that times out is killed with everything it started and is not recorded: that test keeps using the static graph (which selects at least as much), and `record` carries on. --- # Windows > Installing and running trimtest natively on Windows 10 and 11 (x64 and arm64), what it handles, and what to know about shims, line endings and long paths. trimtest runs natively on Windows 10 and 11, x86_64 and arm64. Windows is supported alongside Linux and macOS: the test suite runs on Windows in CI on every push, and the [soundness bench](/trust/soundness/) has been run there (9 repositories, 10 mutations each) with no misses observed (`bench/RESULTS.md` in the repository). WSL also works and behaves exactly like Linux. ## Install ```powershell # prebuilt binary: verifies the checksum, installs to %LOCALAPPDATA%\trimtest\bin and adds it to your PATH irm https://raw.githubusercontent.com/RabinApps/trimtest/main/install.ps1 | iex # $env:TRIMTEST_VERSION = "v0.1.0" pins a release; $env:TRIMTEST_INSTALL_DIR changes the target cargo install trimtest # from crates.io (needs the Rust toolchain and MSVC build tools) cargo binstall trimtest # prebuilt, if you use cargo-binstall scoop install trimtest # once the Scoop bucket is published winget install RabinApps.trimtest # once the winget package is published ``` The zip archives and checksums are also on the [releases page](https://github.com/RabinApps/trimtest/releases). Open a new terminal after installing so the updated PATH is picked up. PowerShell, `cmd.exe` and Git Bash all work. ## What trimtest does differently on Windows - **Runners that are `.cmd` or `.bat` files.** `npx`, `pnpm`, `yarn`, `mvn`, `gradle`, `flutter` and `dart` are batch shims on Windows. trimtest looks programs up on `PATH` with `PATHEXT`, so these work without any configuration. `./gradlew` and `./mvnw` resolve to `gradlew.bat` and `mvnw.cmd` in the project. A project with only the `.bat` or `.cmd` wrapper is detected as having a wrapper. - **Python.** `python3` is not normally present on Windows. trimtest uses the first of `python3`, `python` and `py` that actually runs (it skips the Microsoft Store stub that merely opens the Store). To force one, set `[runner] python = "py -3 -m"` or a path in [`trimtest.toml`](/reference/config/). - **Paths.** Repository paths inside trimtest are always `/`-separated, whatever the OS. Reports from coverage tools (`C:\repo\a.py`, `file:///C:/repo/a.js`, UNC paths, `\\?\` prefixes, a different drive-letter case) are mapped back to the same repo-relative file. Backslashes in `trimtest.toml` paths and in `tsconfig.json`, `package.json`, `go.work` and `pubspec.yaml` are accepted. - **Line endings.** A checkout with `core.autocrlf=true` (CRLF) selects exactly what an LF checkout does: line endings are normalised before files are fingerprinted, so a map recorded on one machine is valid on the other. - **Timeouts.** `--timeout` and `--total-timeout` kill the whole process tree using a Windows Job Object, so a hung runner's children go with it. ## Things to know - **Long paths.** Deep `node_modules` or `target` trees can exceed 260 characters. Enable them once: `git config --system core.longpaths true`, and turn on Windows long path support (registry key `LongPathsEnabled`, or Group Policy). - **Antivirus and indexers.** Real-time scanners can briefly lock `.trimtest\map.json`. trimtest retries the write for about a second; exclude `.trimtest\` from scanning if you still see failures. - **Symlinks and junctions.** Not required. You do not need Developer Mode. - **Arguments through `.cmd` shims.** Windows batch files re-parse their arguments. trimtest passes test names through the shim unchanged, but a test path containing `%`, `^` or `"` can be rejected by Windows itself; rename the test file in that case. - **Gradle and captured output.** Gradle's background daemon inherits the pipe a program's output is captured through and keeps it open after trimtest has finished. Anything that waits for the pipe to close (a script that reads trimtest's output to the end, or `trimtest run | tee log`) can then appear to hang. Run `gradle --stop` afterwards, or set `org.gradle.daemon=false` in `gradle.properties` for CI. Plain terminal use and GitHub Actions steps are not affected. - **Untested toolchains.** Swift on Windows, Flutter/Dart and Zig have not been run on Windows. They use the same resolution rules and should work, but are not verified. ## GitHub Actions on Windows ```yaml jobs: test: runs-on: windows-latest steps: - uses: actions/checkout@v6 with: { fetch-depth: 0 } - name: Install trimtest run: irm https://raw.githubusercontent.com/RabinApps/trimtest/main/install.ps1 | iex # ...your toolchain setup here... - run: trimtest run --base origin/${{ github.base_ref }} --timeout 900 ``` `install.ps1` adds trimtest to the PATH of the current step, so later lines in the same step can call it; use `echo "$env:LOCALAPPDATA\trimtest\bin" >> $env:GITHUB_PATH` to make it available to later steps. --- # Troubleshooting > Common trimtest problems and fixes, from everything running to ignored recordings and stale Gradle builds. ## Everything runs when I changed one file That is deliberate when trimtest cannot trace the change. Run `trimtest select` and read the reason. The usual causes: no baseline yet, a lockfile or build config changed, a deleted file nothing depends on, or `--strict`. See [Safety rules](/concepts/safety-rules/). ## `record --run` says "tests failed; baseline not recorded" `record --run` only records a baseline from a green run. Fix the failing tests, or use `record --coverage --lenient` to tolerate units that cannot be measured. ## A test I expected is not selected ```bash trimtest explain tests/test_core.py ``` prints every reason and the evidence tier, or says why nothing selected it. If a dependency is invisible to the import graph (reflection, string-based imports), record coverage so it is measured: `trimtest record --coverage`. For suites with no import link at all, add a `[map]` entry. ## My recording is ignored A recording is ignored, and the test uses the static graph, when the test file changed since it was made, when the coverage tool version changed, or when you compare against another `--base` (a warning says so). Re-record with `trimtest record --coverage`. ## Exit code 3 Selection is uncertain: a selected test cannot be run by the runner. Run the full suite (`trimtest run --full`) and check which test was skipped in the warning above the summary. `trimtest select --exit-code` also exits `3` when nothing is selected but a changed file is not known to affect any test. ## The baseline looks old trimtest warns when the recorded baseline is far behind `HEAD`. Re-baseline with `trimtest record --update-if-green` (runs the affected tests and re-records only if they pass). ## Validate the config ```bash trimtest check ``` Errors name the file and the key. Unknown keys are errors, and top-level keys must come before the first `[table]`. ## Gradle runs stale classes trimtest already passes `-Dorg.gradle.vfs.watch=false`. If you run Gradle yourself right after an edit and tests pass when they should fail, that is Gradle's file watcher; see [Java and Kotlin](/languages/jvm/#gradle-file-watching). ## Windows Supported natively; see the [Windows guide](/guides/windows/). Common problems: a `.cmd` shim rejecting an argument, paths over 260 characters (`git config --system core.longpaths true`), or antivirus locking `.trimtest\map.json`. WSL also works and behaves like Linux. --- # CLI reference > Every trimtest command and flag, generated from the binary's own --help output. This page is generated from `trimtest --help` (version 0.1.1). See also [exit codes](/reference/exit-codes/) and [`trimtest.toml`](/reference/config/). ## trimtest ```text Run only the tests a change can reach, across languages. Usage: trimtest [OPTIONS] Commands: check Validate trimtest.toml and report what would be detected init Create trimtest.toml and ignore .trimtest/ schema Print the JSON Schema of trimtest.toml (for editors and agents) detect List detected test projects and how many tests each tracks record Record the current tree as the baseline (optionally after a full green run) select Print the tests affected by the current changes run Select, then run the affected tests with each project's native runner explain Say why a test was (or was not) selected in the last run help Print this message or the help of the given subcommand(s) Options: --root Repository root (default: current directory) --verbose Print more: the changed files and per-test timing --quiet Print less: only the summary lines -h, --help Print help -V, --version Print version ``` ## trimtest check ```text Validate trimtest.toml and report what would be detected Usage: trimtest check [OPTIONS] Options: --root Repository root (default: current directory) --verbose Print more: the changed files and per-test timing --quiet Print less: only the summary lines -h, --help Print help ``` ## trimtest init ```text Create trimtest.toml and ignore .trimtest/ Usage: trimtest init [OPTIONS] Options: --root Repository root (default: current directory) --verbose Print more: the changed files and per-test timing --quiet Print less: only the summary lines -h, --help Print help ``` ## trimtest schema ```text Print the JSON Schema of trimtest.toml (for editors and agents) Usage: trimtest schema [OPTIONS] Options: --root Repository root (default: current directory) --verbose Print more: the changed files and per-test timing --quiet Print less: only the summary lines -h, --help Print help ``` ## trimtest detect ```text List detected test projects and how many tests each tracks Usage: trimtest detect [OPTIONS] Options: --root Repository root (default: current directory) --verbose Print more: the changed files and per-test timing --quiet Print less: only the summary lines -h, --help Print help ``` ## trimtest record ```text Record the current tree as the baseline (optionally after a full green run) Usage: trimtest record [OPTIONS] Options: --root Repository root (default: current directory) --run Run the full test suites first and only record when they pass --coverage Also measure what each test executes (per-test coverage) for precise selection. Implies running every test unit individually; fails if any test fails --verbose Print more: the changed files and per-test timing --lenient With --coverage: keep going when a test unit fails when run alone (order-dependent tests, for example). Those units are not measured and keep using the static graph --quiet Print less: only the summary lines --remeasure Measure every test again instead of keeping recordings that are still valid --update-if-green Run the affected tests first and re-record only if they all pass --timeout Kill a runner command (and everything it started) after this many seconds. A test whose measurement times out is not recorded and keeps using the static graph. Overrides `timeout` in trimtest.toml; 0 means no limit -h, --help Print help ``` ## trimtest select ```text Print the tests affected by the current changes Usage: trimtest select [OPTIONS] Options: --base Compare against a git ref instead of the recorded map --root Repository root (default: current directory) --full Select everything --verbose Print more: the changed files and per-test timing --json --quiet Print less: only the summary lines --paths Print only test paths, one per line (for scripting) --tier Possible values: - auto: Use recorded coverage where a valid recording exists, else the static graph - static: Ignore recordings; import graph only [default: auto] --format Possible values: - text - json - github: Append `any`, `count` and a `matrix` of {adapter, cwd, command} to `$GITHUB_OUTPUT` (and print the text form) [default: text] --exit-code Exit 1 when any test is selected; else 3 when the selection is uncertain (a selected test cannot be run, or a changed file is not known to affect any test); else 0. Like `git diff --exit-code` --project Only these projects (substring of the name shown by `detect`, e.g. `pytest@api`); repeatable --shard Run only shard `i` of `n` (e.g. `2/4`): selected tests are split by a stable hash of their path --strict Run everything when a changed file is not known to affect any test (also `on_unobserved = "full"`) -h, --help Print help (see a summary with '-h') ``` ## trimtest run ```text Select, then run the affected tests with each project's native runner Usage: trimtest run [OPTIONS] Options: --base --root Repository root (default: current directory) --full --verbose Print more: the changed files and per-test timing --dry-run Print the commands without running them --quiet Print less: only the summary lines --timeout Kill a runner command after this many seconds, with everything it started; its tests count as failed. Overrides `timeout` in trimtest.toml; 0 means no limit --total-timeout Stop the whole run after this many seconds: the command in flight is killed, the rest are not started, and their tests count as failed. Overrides `total_timeout`; 0 means no limit --tier Possible values: - auto: Use recorded coverage where a valid recording exists, else the static graph - static: Ignore recordings; import graph only [default: auto] --project Only these projects (substring of the name shown by `detect`, e.g. `pytest@api`); repeatable --shard Run only shard `i` of `n` (e.g. `2/4`): selected tests are split by a stable hash of their path --strict Run everything when a changed file is not known to affect any test (also `on_unobserved = "full"`) -h, --help Print help (see a summary with '-h') ``` ## trimtest explain ```text Say why a test was (or was not) selected in the last run Usage: trimtest explain [OPTIONS] Arguments: Options: --root Repository root (default: current directory) --verbose Print more: the changed files and per-test timing --quiet Print less: only the summary lines -h, --help Print help ``` --- # trimtest.toml > Every trimtest.toml key, with its type, default and effect, plus the JSON Schema for editors and agents. `trimtest init` writes a commented `trimtest.toml`. All keys are optional, unknown keys are errors, and top-level keys must come before the first `[table]`. Validate with `trimtest check`; errors name the file and the key. A JSON Schema is published at [`/schema/trimtest.schema.json`](/schema/trimtest.schema.json). For editors with the Even Better TOML extension, add `#:schema https://trimtest.dev/schema/trimtest.schema.json` as the first line of the file. | Key | Meaning | |---|---| | `ignore = [globs]` | files that are never tracked | | `tests = [globs]` | extra files that are tests | | `import_roots = [dirs]` | extra Python import roots | | `respect_gitignore = false` | also track gitignored files | | `on_unobserved = "full"` | what to do with a changed file no test is known to reach: `"warn"` (the default) lists it and runs only the selected tests, `"full"` runs everything | | `timeout = secs` | kill a runner command that runs longer (and its descendants); its tests count as failed. `run --timeout` overrides; 0 = no limit | | `total_timeout = secs` | stop the whole run after this long: the running command is killed (with its descendants), the rest are not started, and their tests count as failed. `run --total-timeout` overrides; 0 = no limit | | `max_depth = n` | how deep project markers are searched (default 6) | | `[full_run] extra = [globs]` | files that force a full run | | `[map] "api/**" = ["web/e2e/**"]` | changed glob → test globs (suites with no import link) | | `[runner] python = "uv run"` | command prefix per runner (`python`, `js`, `jest`, `vitest`, `playwright`, `sql`, ...); detected from lockfiles otherwise | | `[[project]] kind = "python"`, `dir = "svc"` | force a project the markers cannot find | ## Example ```toml #:schema https://trimtest.dev/schema/trimtest.schema.json ignore = ["vendor/**", "examples/**"] on_unobserved = "full" timeout = 600 total_timeout = 1800 [full_run] extra = ["config/*.yml"] [map] "api/**" = ["web/e2e/**"] [runner] python = "uv run" ``` ## Notes - A project nested under another is its own project unless it is a workspace member of it; see [Monorepos](/guides/monorepos/). - Globs are validated when the config loads. --- # Exit codes > What each trimtest exit code means and what a script or agent should do with it. | Code | Meaning | What to do | |---|---|---| | 0 | everything selected ran and passed, or nothing was selected | proceed | | 1 | a test failed (for `select --exit-code`: something was selected) | fix the failing tests | | 2 | trimtest itself failed: bad config, no project found, git error | read the message; run `trimtest check` | | 3 | selection is uncertain: a selected test cannot be run by the runner (for `select --exit-code`: also a changed file no test is known to reach) | run the full suite: `trimtest run --full` | Precedence: `1` outranks `3`. A run where a test failed exits `1` even if another selected test could not run, and `select --exit-code` exits `1` whenever something is selected. A runner command killed by [`--timeout`](/guides/timeouts/) counts as a test failure, so it exits `1`. ## `select --exit-code` `trimtest select --exit-code` does not run tests, so use it to gate a step. It exits: - `1` when something is selected (even if the selection is also uncertain); - `3` when nothing is selected but the selection is uncertain: a selected test cannot be run, or a changed file is not known to affect any test (see [`on_unobserved`](/reference/config/)); - `0` when nothing is selected and nothing is in doubt. ```bash trimtest select --base origin/main --exit-code >/dev/null case $? in 0) echo "no tests affected" ;; 1) echo "tests are affected" ;; 3) echo "cannot tell: run everything" ;; *) echo "trimtest failed" ;; esac ``` `select --json` always carries `uncertain` (a boolean) and `uncertain_reasons` (a list of strings), whatever the exit code. In text and `--paths` output the reasons go to stderr as `trimtest: uncertain: ...`. --- # JSON and machine-readable output > The shape of trimtest select --json, --paths and --format github, for scripts and AI agents. ## `select --json` ```bash trimtest select --json ``` ```json { "baseline": "map e6161e595f", "changed": ["tests/test_a.py", "util.py"], "unobserved": [], "adapters": [ { "adapter": "pytest", "full": null, "total_tests": 1, "selected": [ { "test": "tests/test_a.py", "reason": "test changed", "rank": 1, "reasons": ["test changed", "util.py -> tests/test_a.py"], "tier": "static" } ] } ] } ``` | Field | Meaning | |---|---| | `baseline` | what the change was measured against: `map ` for a recorded baseline, or the git ref with `--base` | | `changed` | files that changed since the baseline | | `unobserved` | changed files no test is known to reach | | `adapters[].adapter` | the runner adapter, such as `pytest`, `vitest`, `cargo`, `maven` | | `adapters[].full` | `null`, or the reason the whole project was selected | | `adapters[].total_tests` | how many tests the project tracks | | `adapters[].selected[].test` | the test file | | `adapters[].selected[].reason` | the primary reason | | `adapters[].selected[].reasons` | every reason; `trimtest explain` prints these | | `adapters[].selected[].rank` | run order; lower runs first (`failed last run` is 0) | | `adapters[].selected[].tier` | `static`, `recorded`, `rule` or `full` | Fields may be added in later versions; do not rely on their absence. ## `select --paths` One selected test path per line, for scripting: ```bash trimtest select --paths | xargs -n1 echo ``` ## `select --format github` Appends these to `$GITHUB_OUTPUT` (and prints them when it is unset): ```text any=true count=1 matrix={"include":[{"adapter":"pytest","command":"python3 -m pytest tests/test_a.py","cwd":"."}]} ``` `any` is `true` when something would run, `count` is the number of tests (the whole project's count for a full run), and `matrix` has one entry per runner command. Projects with no tests are left out. ## `explain` ```bash trimtest explain tests/test_a.py ``` ```text tests/test_a.py was SELECTED by pytest (static evidence): - test changed - util.py -> tests/test_a.py ``` Pass a source file instead of a test to see which tests it reaches. --- # Supported and unsupported > Which languages and runners trimtest supports on which tier, and what is not supported. | | static | recorded (`--coverage`) | function-level | |---|---|---|---| | Python (pytest) | yes | yes | yes | | JS/TS (Jest, Vitest) | yes | yes | yes (by function name) | | Playwright | yes (`[map]` for E2E) | yes (Chromium JS coverage; only adds to the static graph) | no | | Rust | yes | yes (`cargo llvm-cov`) | yes | | Java (Gradle, Maven) | yes | yes (JaCoCo) | yes (by method signature) | | Kotlin (Gradle, Maven) | yes | yes (JaCoCo) | yes (by function signature) | | Go | yes | yes (`go test -coverprofile`) | yes | | Dart, Flutter | yes | yes (`dart test --coverage`, `flutter test --coverage`) | yes | | Swift (SwiftPM) | yes | yes (`swift test --enable-code-coverage`) | yes | | Objective-C (SwiftPM targets) | yes | yes (same tool, file-level) | no | | Swift, Objective-C (Xcode projects) | yes | yes (`xcodebuild -enableCodeCoverage`, `xccov`) | yes | | Zig | yes | no | no | | Python (unittest, nose2, behave) | yes | yes (coverage.py) | yes | | Mocha, `node:test` | yes | yes (V8 coverage) | yes (by function name) | | Bun, Deno, Cypress, WebdriverIO | yes (`[map]` for E2E) | no | no | | Flutter Patrol | yes | no (needs a device) | no | | Maestro, Detox, Android instrumented | yes | no (needs a device) | no | | Ruby (RSpec, Minitest) | yes | no | no | | PHP (PHPUnit, Pest) | yes | no | no | | .NET (xUnit, NUnit, MSTest) | yes | no | no | | Elixir (ExUnit) | yes | no | no | | SQL / PostgreSQL (pgTAP, psql scripts) | yes | no | no | ## Maturity Every row above is covered by tests. How far each was exercised against the real tool differs, so treat the newest ones with matching care: | Maturity | Runners | |---|---| | Stable: run against the real tool and benchmarked on real repositories with zero misses | pytest, Jest, Vitest, `go test`, `cargo test`, Gradle and Maven (Java, Kotlin), `dart test`, `flutter test` (including a real Flutter app), SwiftPM, Playwright (Chromium) | | Beta: run against the real tool and benchmarked with zero misses, but on one small repository each (12 to 24 mutations) | Mocha, `node:test`, Deno, Python unittest, Ruby (RSpec), PHP (PHPUnit), .NET (xUnit), Elixir (ExUnit). Bun was benched on a repository with a single source file, so that run says little. nose2, behave and Minitest ran against the real tool but were not benched | | Experimental: not run against a real runner here (they need a device or browser, or the runner was unavailable), covered by unit and injected-recording tests only | Flutter Patrol, Maestro, Detox, Android instrumented, Cypress, WebdriverIO, Pest, NUnit, MSTest, Zig, SQL (pgTAP, psql), Objective-C (SwiftPM; needs macOS, not run here), Xcode projects (run on macOS only; iOS simulators, UI tests and CocoaPods not run here) | Experimental runners are still sound by construction: with no recording they are never trimmed below their static graph, and config, lock files and native projects run everything. What they lack is proof against real projects, so check the selection on your own repository with `trimtest select` and `--dry-run` before relying on it in CI. ## Verified against real tools `go test`, `swift test`, pytest with coverage.py, Jest 29, Vitest, Playwright (real Chromium), `cargo test` with `cargo llvm-cov`, Gradle 8 and Maven 3 with JaCoCo, Dart 3 and Flutter 3 (static and recorded), Mocha, `node:test`, Bun, Deno, behave, nose2, RSpec, Minitest, PHPUnit, xUnit and ExUnit. `patrol_cli` was only checked for how it parses the arguments trimtest builds. Zig is covered by unit tests and `--dry-run` so far. ## Platforms Linux, macOS and Windows 10/11 (x86_64 and arm64) are supported. The test suite runs on all three in CI on every push, and the soundness bench reports zero misses on each, over a smaller set of repositories on Windows. See the [Windows guide](/guides/windows/). ## Not supported - Xcode projects that reference targets of another `.xcodeproj`, and binary or XCFramework targets. - Android-specific test runners and Android Gradle modules (they fall back to the static graph). - Recorded tier for Zig, and for Playwright projects that run Firefox or WebKit (Chromium only). Recordings are tied to the coverage tool version and the commit they were made at; against another `--base` they are ignored with a warning. --- # Soundness and the bench > How trimtest measures whether selection ever misses a failure, and the zero-miss results on real open-source projects. A selection tool is only useful if it never hides a failure the full suite would catch. The bench (`bench/bench.py`) checks that on real projects. ## Method For each repository it records a baseline, then injects **one small fault at a time** into a non-test source file (operator swaps such as `==`/`!=`, `+`/`-`, `true`/`false`, `&&`/`||`) and compares `trimtest run --full` with `trimtest run` (the selected subset). It also injects structural faults: a deleted file, a renamed file, a broken config and a changed build directory. - A **miss** is a fault the full suite catches and the subset does not. - Faults the full suite does not catch say nothing about selection and are reported as *survived*. - A miss is re-run once; a result that flips is reported as `UNSTABLE`, not a miss. - The harness requires the full suite to pass on the unmodified tree before injecting anything. Run it yourself: ```bash python3 bench/bench.py [--coverage] [--mutations N] [--seed S] ``` ## Results **No misses observed in the final runs across the 13 open-source repositories and one bundled fixture** in the table below (Go, Rust, Python, TypeScript/Vitest, JavaScript/Jest, Java/Maven, Dart/Flutter and Swift/Objective-C). The other runners (Kotlin, Mocha, Deno, Ruby, PHP, .NET, Elixir and more) are benched on one small repository each; see the [support matrix](/reference/support-matrix/), on both the static and the recorded tier. | Repo | Language / runner | Tier | Mean tests selected | |---|---|---|---| | go-chi/chi | Go | static | 100% of library mutations | | dtolnay/semver | Rust (cargo) | static | about 75% | | pallets/click | Python / pytest | static → recorded | 87% → 32% | | unjs/ufo | TS / Vitest | static → recorded | about 92% → 42% | | sirupsen/logrus | Go | static | 65% | | dart-lang/core (collection) | Dart | static | 79% | | unjs/pathe | TS / Vitest | recorded | 65% | | BurntSushi/aho-corasick | Rust | recorded (cargo-llvm-cov) | 59% | | apache/commons-codec | Java / Maven | recorded (JaCoCo) | 12% (87 test classes) | | pallets/jinja | Python / pytest | recorded | 35% | | kentcdodds/kcd-scripts | JS / Jest | recorded | 33% | | apple/swift-algorithms | Swift (SwiftPM) | static | 100% (module-level) | | bundled xcodeshop (3 test bundles) | Swift + Objective-C / `xcodebuild test` | static → recorded | 60% → 30% | | flutter/samples (compass_app) | Dart / Flutter (`flutter test`) | static → recorded | 12% → 9% (25 test files) | The static tier is sound but saves little on tightly coupled code; **recording is where the savings come from**. The best case is commons-codec, many small independent classes, at 12% of tests selected on average. ## Caveats - Samples are small (12–15 faults per repository, one repository per tier per language). No misses observed is encouraging, not a proof. Simple operator mutations under-represent faults that only show in rarely run paths. - Single machine; selection percentages vary by seed. - The full write-up, including every fix the bench led to, is in [`bench/RESULTS.md`](https://github.com/RabinApps/trimtest/blob/main/bench/RESULTS.md). --- # Limits > What trimtest cannot see, where it deliberately over-selects, and why a scheduled full run still matters. trimtest is conservative, not omniscient. Know where it can be wrong or wasteful. ## Always keep a full run Keep a scheduled full run (`trimtest run --full`) as a safety net. Selection is evidence-based, and some evidence is weak: the static graph cannot see reflection, dependency injection, `eval`, macros, named Zig modules or Playwright end-to-end links. ## Unobserved files only warn by default If a changed file is one that no test is known to reach, `trimtest select` and `trimtest run` report it as `unobserved` and, unless you pass `--strict` or set `on_unobserved = "full"`, only print a warning: those tests are not added and no full run is triggered. That is the default because most such files (docs, scripts, examples) are genuinely untested, but it means an edit to a file linked to tests only in a way trimtest cannot see (reflection, generated code, a file read by name) will not be caught by the selection. In CI, use `--strict` so an unobserved change runs everything. See [safety rules](/concepts/safety-rules/#unobserved-changes). ## Ignored and gitignored paths Files matched by `ignore` globs are never traced: they are not part of the dependency graph and select no tests. Their content is fingerprinted when the map is recorded (up to 20,000 files; beyond that nothing is stored and every map-based `select` reports `(ignored paths too many to track)`), so against the map baseline an edit, addition or deletion of one is reported as `unobserved` (and `--strict` or `on_unobserved = "full"` runs everything). Files that are gitignored (when `respect_gitignore` is on) and directories such as `node_modules`, `target`, build output and virtualenvs are not hashed at all, since they are large and are not source: an edit there is invisible to the map baseline. With a git baseline, changes under those paths are reported as `unobserved`. `select --verbose` does not list this blind spot yet. ## Where it errs toward running more - Hub modules: when one module imports everything, most changes reach most tests, so the static tier can select 75–100% of a tightly coupled project. - Name-based function matching (Python identifiers, JS function names) shares a verdict between same-named functions. - Files coverage cannot vouch for (constants, statement-less files, macros, mocked or abstract classes) stay attached to every test that statically depends on them. - Tests that start other processes run on any change. ## What it cannot see - Access by string: `getattr(mod, "NAME")`, dynamic `require(variable)` without a recording. - Behaviour driven by files it does not parse (databases, remote services, environment). - Anything in a file type it does not track unless a test's source mentions the file name. Flutter assets declared in `pubspec.yaml` and `.arb` files are the exception: they run every test of the package. - Playwright browser coverage sees only JavaScript that ran in Chromium pages. Backend and SSR code, stylesheets, markup a server renders, environment variables and `webServer` config are invisible to it, so a Playwright recording never replaces the static graph or `[map]` (it only adds files); route those through `[map]`. Web workers and service workers started by the page are not measured either, so such a spec depends on every project file. Scripts from a CDN or another origin are treated as third-party code and ignored. - Computed loads in a test (`require(x)`, `import('./' + x)`, `` import(`./${x}`) ``, `jest.requireActual(x)`, `vi.mock(x)`, `require.context`; Python `importlib.import_module(x)`, `__import__(x)`, `runpy`, `exec(x)`, `pkgutil.iter_modules`; Java/Kotlin `Class.forName(x)`, `loadClass(x)`, `ServiceLoader`; Go `plugin.Open`) cannot be traced, so that test depends on every non-test file of its project and is selected for any change there. Only test files and only non-literal arguments count: `require('./a')` and `import_module('pkg.a')` stay precise. Loads in non-test code (a plugin loader in the library itself) are still not traced by name; recording (`--coverage`) sees them. - Frameworks without a recording (Ruby, PHP, .NET, Elixir, SQL, Bun, Deno, Cypress, WebdriverIO, Patrol, Maestro, Detox, Android instrumented) are never trimmed below their static graph. Their config, lock files and native projects run everything, and dynamic loading (computed `require`/`import`, reflection, `eval`, Rails autoload, framework apps) makes a test depend on every project file. - Patrol, Maestro and Android instrumented tests are reported as unrunnable (exit code 3) when no `adb` device or booted simulator is found; that is a warning, not proof nothing can run (Patrol can fall back to Chrome). Detox follows relative imports only. App code that no Maestro flow or Detox test imports is "unobserved": link it with `[map]` or set `on_unobserved = "full"`. - Python: unittest and nose2 see only `test*.py`; a hyphenated test name runs `unittest discover` (nose2: its whole directory). unittest is chosen only without a pytest marker and with a `TestCase` present. - Mocha with `spec` in `.mocharc` still runs the whole configured set, and flags that live only in `package.json` scripts are not carried over (put them in `.mocharc`). - .NET: namespace-level granularity inside a project; only `.csproj` references are traced; a change in a referenced project selects every dependent test. PHP test files are recognised by `Test.php`, `Tests.php` or `_test.php` (use `[tests]` for others) and run one process per file. Pest was not run against a real install. ## Granularity File-level, except tests with a `--coverage` recording in Python, Jest/Vitest, Rust, Java, Kotlin, Go, Dart/Flutter and Swift (function-level). Files with `#if` (Swift), build constraints, `//line` directives or cgo (Go), `part` directives (Dart) and files that do not parse stay at file level. ## Platform Linux, macOS and Windows are supported. The soundness bench (`bench/RESULTS.md`) has been run on all three with no misses observed: most runs are on Linux and macOS, and Windows has its own section (9 repositories, 10 mutations each, from the `bench-windows` workflow), which is a smaller sample. Windows results are copied into `RESULTS.md` by hand after each run, so they can lag the current binary. See the [Windows guide](/guides/windows/). ## Measuring it The [soundness bench](/trust/soundness/) mutates real projects and counts misses. Zero misses so far is encouraging, not a proof. ## What CI proves Every adapter has selection tests that run everywhere with no tool installed: they build a small repository, record, edit, and assert exactly which tests are selected. Separate end-to-end tests drive the real test runner (jest, gradle, dart, psql and so on). Those skip themselves when the tool is missing, so a green run alone does not say the real tool was exercised. CI sets `TRIMTEST_REQUIRE_TOOLS` in the jobs that provision a tool, which turns a missing tool into a failure rather than a skip. The real-runner tests are enforced for: - **Python** (pytest and coverage.py), **Rust** (`cargo llvm-cov`), **Jest** and **Playwright** on Linux, and Python, Rust, Jest, **Maven** and **Gradle** on Windows; - **Go**, **Ruby** (minitest and RSpec), **PHP** (PHPUnit), **.NET** (xunit) and **Elixir** (`mix test`), each in its own Linux job. Not enforced, so their real-runner tests run only where a contributor has the tool: Dart, Flutter and Patrol, SwiftPM and Xcode, Mocha, `node:test`, Bun, Deno, nose2, behave, and the PostgreSQL adapters (`psql`, pgTAP). Those adapters are covered by the selection tests and by the [soundness bench](/trust/soundness/), not by a mandatory real-tool run in CI. See `CONTRIBUTING.md` in the repository for how to run them yourself. --- # Changelog > What changed in each trimtest release. ## Unreleased - The documentation moved to https://trimtest.dev. `trimtest init` now writes `#:schema https://trimtest.dev/schema/trimtest.schema.json` (the old `trimtest.rabinapps.com` schema URL in config files made by 0.1.1 keeps working only while that domain redirects; replace it with the new one). `robots.txt` names the AI crawlers and agents it allows. ## 0.1.1 - 2026-12-02 - Release assets: the per-archive `.sha256` files that `install.sh` and `install.ps1` download were never uploaded, so both installers failed on 0.1.0, and `SHA256SUMS` was missing the newline after each Windows entry. Both are fixed, and the release workflow now verifies `SHA256SUMS` before publishing (also on manual dry runs). The code is identical to 0.1.0; use 0.1.1. ## 0.1.0 - 2026-12-01 First release. - Xcode: test runs pass `-collect-test-diagnostics never`. On an iOS Simulator a failing test made `xcodebuild` collect diagnostics for up to ten minutes (a 6 s failing run took 200 s or more, which looked like a hang); `TRIMTEST_XCODE_DIAGNOSTICS` overrides it. Bench: a guarded runner (`attempt_timeout`) is reset and retried once, and a run it gives up on is reported as inconclusive instead of caught. - Bench: `xcodeshop`, a bundled Xcode project (two frameworks, a host app, three test bundles, one Objective-C test class; macOS only) with zero misses, static and recorded. Repos can now declare a required `tool` and `macos`, and are skipped with a reason when the machine lacks them. - New adapter: Xcode projects (`*.xcodeproj`). `project.pbxproj` is read for targets, the files each builds (build phases and Xcode 16 synchronised folders with their exceptions), target dependencies, test hosts and test bundles; a test depends on every target it is built after, hosted by or links, and an edit reaches the tests of those bundles. Tests run with `xcodebuild test -scheme S -destination D -only-testing:Bundle/Class` through a shared scheme or test plan (a test no scheme runs is reported unrunnable); `TRIMTEST_XCODE_DESTINATION` picks the destination and `[runner] xcode` prefixes the command. `record --coverage` uses `-enableCodeCoverage` and `xccov`: function-level for Swift, file-level for Objective-C. `project.pbxproj`, xcconfig, test plans, schemes, `Info.plist`, entitlements, `Podfile.lock`, `Package.resolved` and local Swift packages run everything. Verified against real `xcodebuild` (Xcode 27, macOS app with a hosted test bundle); iOS simulators, UI tests and CocoaPods were not run. - Objective-C beside Swift in SwiftPM packages (same `swiftpm` adapter). XCTest classes written in `.m`/`.mm` are recognised as tests; `@import`, `#import `, `#import "path.h"` (by directory and by header-path suffix) and `Module-Swift.h` become edges between targets, so an Objective-C-only target that uses another target is no longer invisible to selection; `.modulemap`, `.hh`, `.cxx` and `.hxx` are tracked. C-family files now have a comment-aware fingerprint (they were hashed byte for byte): comments and formatting select nothing, while strings, macros and the line structure of preprocessor directives count. Test runs filter by `@implementation` class and `record --coverage` records Objective-C tests (file-level). Static tests only: no Swift toolchain was available, so `swift test` on Objective-C targets has not been run, and Xcode projects are supported by their own adapter (see the entry above). - New adapter: SQL / PostgreSQL. pgTAP scripts run with `pg_prove`, plain scripts with `psql -X -v ON_ERROR_STOP=1 -f`, against the database the `PG*` variables describe (trimtest never creates one). Static tier only: a file provides the objects it creates, alters or writes to and depends on every name it mentions, so `alter table users` selects the tests that reference `users`; `\i`/`\ir` includes are file edges; `EXECUTE`, `\gexec` and `\i :variable` make a file depend on every non-test file. Comments and whitespace do not count, dollar-quoted bodies, strings and psql meta-commands do. Migrations, `sqitch.plan` and `schema.sql` run everything. `[[project]] kind = "sql"` forces a project; `[runner] sql = "..."` prefixes the commands (`docker compose exec -T db`). Verified against real `psql` and `pg_prove` (PostgreSQL 16, pgTAP 1.3.2); a `begin; .. rollback;` test provides nothing, so pgTAP tests that all create the extension do not select one another. - A file an adapter owns can now also be declared shared data (`Adapter::shares_data`, true for `.sql`), so other projects' tests that name it (a Python test loading `db/seed.sql`) are still selected by the "mentions this file" rule. - Fix: `[runner]` keys for Ruby and PHP were reported as unused by `trimtest check`. - Fix: a test that loads code through a computed path was not traced in Jest, Vitest, Playwright, pytest, Java/Kotlin and Go, so editing the loaded file could select nothing. Such a test now depends on every non-test file of its project (one shared rule in `select::scan`, spec `trimtest:any`); literal loads stay precise. `require('./x/' + n)` and template literals with `${}` count as computed, as do `jest.requireActual`/`jest.mock`/`vi.mock` and `require.context`. - Fix (found by benching jshttp/negotiator and ai/nanoid): in the JS runners `require('..')` / `import '..'` of the project root resolved to nothing, so a source file reached only through the package entry was "unobserved" and selected no test; it now resolves to `index.*` (or, for a directory with a `package.json` and no index, to every file below it). A JS test that starts child processes (`child_process`, `execa`, workers, ...) now depends on every non-test file in the static tier, as the recorded tier already did, because the script it runs is not in the import graph. - New runners, all static unless noted: Flutter Patrol (`patrol test --target`, separate from `flutter test`), Maestro, Detox and Android instrumented (`androidTest`, no longer handed to `gradle test`); Mocha and `node:test` (recorded through V8 coverage), Bun, Deno, Cypress and WebdriverIO; Python unittest, nose2 and behave (recorded through coverage.py); Ruby (RSpec, Minitest), PHP (PHPUnit, Pest), .NET (xUnit, NUnit, MSTest via `dotnet test`) and Elixir (ExUnit via `mix test`). Config, lock files and native projects run everything; dynamic loading makes a test depend on every project file, so more tests run, never fewer. New `[[project]] kind` values: `patrol`, `maestro`, `detox`, `android-instrumented`, `dotnet`, `elixir`, `ruby`, `php`. - `bin/`, `obj/` (next to a `.csproj`) and `_build/`, `deps/` (next to `mix.exs`) are skipped as build output. - Recorded tier for Playwright (`record --coverage`, Chromium), file-level. A hook loaded into the Playwright worker collects Chromium JS coverage for every page, and trimtest maps the scripts to repository files through source maps (inline, `.map` files, `webpack://`, `/@fs/`, `?t=` URLs). It only adds to the static graph and `[map]`: editing a script the page never loaded selects nothing, editing one it ran selects the spec, and backend, CSS, HTML, config and spec-imported code keep their static edges. Untraceable first-party scripts and web/service workers make the spec depend on every project file; non-Chromium specs and specs that never open a page stay on the static graph. - Fix: `include` globs under `optimizeDeps`, `coverage` and similar keys of `vite.config.*` / `vitest.config.*` were read as Vitest test files, so every source file became a "test" and failed when run alone under `record --coverage`. - Flutter: edits to assets, fonts and shaders declared in `pubspec.yaml`, and to any `.arb` file, now run every test of the package instead of being reported as unobserved. Goldens and fixtures a Dart source names by string literal select the tests that use them. - A test with a recording that ran a file reading a changed data file (`include_str!`, `go:embed`, a Dart `File('x.csv')`) is now selected; before, the recording replaced the static edge and the edit was skipped. - Flutter recorded tier: files outside `lib/` that the coverage report never lists (fakes under `testing/`) now count as executed by every test that depends on them; before, an edit to one selected nothing. - Dart/Flutter is verified against real `flutter test` with `testWidgets`, and benchmarked on `compass_app` (`bench/bench.py compass`); the bench no longer mutates `integration_test/`. - Recorded tier for Go (`record --coverage` via `go test -coverprofile`), file-level. - Recorded tier for Dart (`dart test --coverage`) and Flutter (`flutter test --coverage`), file-level. - Recorded tier for Swift (`record --coverage` via `swift test --enable-code-coverage`), file-level. - Function-level selection for Go: an edit to a function or method no test ran no longer selects that test. Types (fields, embedded types, the declared method set), `var`/`const`/`import`, every `init`, functions with no statements and added or removed methods still do. Files with build constraints, `//line` directives or cgo stay at file level. - Function-level selection for Swift: an edit to a function, initializer, subscript or computed property no test ran no longer selects that test. Stored properties and observers, enum cases, imports, top-level declarations and added or removed members still do. Files with `#if` stay at file level. - `bench/bench.py --test-timeout SECONDS`: kill a mutant that loops forever instead of waiting out the run. - Function-level selection for Rust: an edit to a function or method no test ran no longer selects that test. Constants, structs, macros, `use`/`mod` lines and added or removed methods still do. - Function-level selection for Dart and Flutter: an edit to a function or method no test ran no longer selects that test. Fields, constants, imports and added or removed members still do. - Function-level selection for Java: an edit to a method no test ran no longer selects that test. Field, initializer, signature and import changes still do. - Function-level selection for Kotlin (Gradle, Maven, JaCoCo): an edit to a function, secondary constructor or custom property accessor no test ran no longer selects that test, default arguments and expression bodies included. Property initializers, `init` blocks, primary-constructor parameters, supertypes, enum entries, imports, top-level properties, added or removed members and every `inline`/`reified` function (JaCoCo credits inlined code to the caller) still do. Files that do not parse, including classes whose body starts on the same line as the declaration, stay at file level. - Maven projects that already run the JaCoCo agent in their own build, or inherit it from a parent pom (commons-codec), are now measured. A second injected agent crashed the JVM, so every test unit silently fell back to the static graph. - Fixed Java fingerprints: a `/*` inside a comment (for example `'/*'` in Javadoc) was read as a nested comment and hid every later edit in the file, so those edits selected nothing. Kotlin still nests comments. - Fixed a panic fingerprinting Java, Kotlin, Rust, Go or Zig files with non-ASCII text inside a block comment. - Static selection for Python (pytest), JS/TS (Jest, Vitest, Playwright), Rust, Go, Dart/Flutter, Java/Kotlin (Gradle, Maven), Swift (SwiftPM) and Zig, from a semantic-fingerprint baseline or `--base `. - Recorded tier (`record --coverage`) for Python (function-level), Jest/Vitest (function-level), Rust (`cargo llvm-cov`) and Java/Kotlin (JaCoCo). - Safety rules: full runs for lockfile/build-config changes, untraceable changes, deleted files nothing depends on, and `--strict`; failed tests always rerun. - `run --timeout` and `--total-timeout` (kills the runner and everything it started), `--shard`, `--project`, `--format github`, `explain`, `check`, exit codes 0/1/2/3. - Soundness bench over real projects: zero misses on both tiers (`bench/RESULTS.md`). - Linux and macOS (x86_64, arm64) and Windows 10/11 (x86_64, arm64): native process-tree kill, `.cmd`/`.bat` shim and `python`/`py` resolution, CRLF-insensitive fingerprints, Windows path mapping for every coverage tool, a PowerShell installer, and zip releases (also via cargo-binstall; Scoop and winget manifests are in `packaging/`). --- # Blog > News and release announcements from trimtest. import BlogList from '../../../components/BlogList.astro'; News and release announcements. trimtest is a Rust CLI that runs only the tests a change can reach. --- # trimtest 0.1: run only the tests a change can reach > The first release of trimtest, a Rust CLI that selects the tests a code change can reach, across Python, JS/TS, Rust, Go, Dart, Java/Kotlin, Swift and more. What it does, how to install it, how far to trust it, and what is still early. [← Blog](/blog/) *December 2, 2026 · trimtest v0.1.1* trimtest is out. It looks at what you changed and runs only the tests that change can reach, with each project's own runner. A pull request that touches one file runs the tests for that file, not the whole suite. ## What it does - **Static selection, zero setup.** trimtest parses your code with tree-sitter, builds an import graph per language, and walks it backwards from the changed files to the tests. Edits that do not change code (comments, formatting) select nothing. - **A recorded tier when you want precision.** `trimtest record --coverage` records per-test coverage with each ecosystem's own tool (coverage.py, V8, `cargo llvm-cov`, JaCoCo, Dart and Flutter coverage, Chromium for Playwright) and selects at function level instead. - **It runs more, never fewer.** When trimtest cannot trace a change (a lockfile, a build config, a test that loads code through a computed path, a parse error), it runs everything for that project. Failed tests always rerun. - **Your runner, not ours.** `trimtest run` calls pytest, Jest, Vitest, Playwright, `cargo test`, `go test`, Gradle, Maven, SwiftPM and the rest with their own filters. Exit codes are plain: 0 passed or nothing selected, 1 a test failed, 2 trimtest failed, 3 selection is uncertain. It covers Python, JS/TS, Rust, Go, Dart/Flutter, Java, Kotlin, Swift, Ruby, PHP, .NET, Elixir, Zig and SQL. The [support matrix](/reference/support-matrix/) says which runners are stable, which are beta, and which are experimental. ## Install ```bash # Linux and macOS (x86_64, arm64): verifies the checksum, installs to ~/.local/bin curl -fsSL https://raw.githubusercontent.com/RabinApps/trimtest/main/install.sh | sh # Windows (PowerShell) irm https://raw.githubusercontent.com/RabinApps/trimtest/main/install.ps1 | iex # anywhere with Rust cargo install trimtest # Windows with Scoop scoop bucket add rabinapps https://github.com/RabinApps/scoop-bucket scoop install trimtest ``` A winget package is pending review. Prebuilt archives and checksums are on the [release page](https://github.com/RabinApps/trimtest/releases/tag/v0.1.1). ## Try it in a minute ```bash cd your-repo trimtest detect # what it found trimtest record # take a baseline (after a green run) # edit a file trimtest select # the tests that change can reach, and why trimtest run # run just those with the native runner ``` In a pull request, `trimtest run --base origin/main` needs no recorded map. Keep a scheduled full run as a safety net: a green subset is not a green suite. The [quick start](/start/quick-start/) and the [GitHub Actions guide](/guides/github-actions/) have the details. ## How far to trust it Soundness comes first: the rule is that trimtest may run too many tests but must never skip one it should have run. To check that, the repository ships a mutation benchmark (`bench/bench.py`). It injects one small fault at a time into a real project's source and compares the full suite with the selected subset. A *miss* is a fault the full suite catches and the subset does not. The target is zero. Before this release I re-ran it on the released binary, on repositories that exercise the parsers and the coverage readers: nine runs across Go, Rust, Python, TypeScript and Java, static and recorded, 6 mutations each (4 for the Maven run), seed 1. | Repository | Runner | Tier | Test units | Faults the full suite caught | Missed by trimtest | Mean tests selected | |---|---|---|---|---|---|---| | go-chi/chi | Go | static | 35 | 3 of 6 | **0** | 74% | | dtolnay/semver | cargo | static | 6 | 4 of 6 | **0** | 83% | | pallets/click | pytest | static | 43 | 5 of 6 | **0** | 100% | | pallets/click | pytest | recorded | 43 | 5 of 6 | **0** | 40% | | unjs/ufo | Vitest | static | 13 | 6 of 6 | **0** | 95% | | unjs/ufo | Vitest | recorded | 13 | 6 of 6 | **0** | 37% | | unjs/pathe | Vitest | recorded | 4 | 6 of 6 | **0** | 71% | | pallets/jinja | pytest | recorded | 24 | 4 of 6 | **0** | 31% | | apache/commons-codec | Maven | recorded (JaCoCo) | 90 | 4 of 4 | **0** | 10% | Zero misses in all nine runs. The recorded tier is where the savings are: on commons-codec a change typically runs a tenth of the suite. The static tier is more cautious, since an import graph cannot tell which tests a shared module really affects. The samples are small, a handful of mutations per repository, and several runners have been benched on a single repository only. Treat the stable runners as ready for pull-request use alongside a scheduled full run, the beta and experimental ones as something to try and report on. The [soundness page](/trust/soundness/) and [limits](/trust/limits/) list what has and has not been checked. ## What is next Wider benching (more repositories per runner, the Bun and Deno recorded tiers, Playwright recorded), more runners, and whatever you find. If trimtest skips a test it should have run, that is the most useful bug report there is: [open an issue](https://github.com/RabinApps/trimtest/issues/new/choose) with the diff and the test it missed. trimtest is free and Apache-2.0. If it saves your CI time, you can [support it](/project/support/). --- # Support and sponsors > trimtest is free and Apache-2.0. How to support it, become a sponsor, and who sponsors it. trimtest is free, Apache-2.0, and built by one developer, with no ads and no telemetry. Donations and sponsors pay for CI runners, test hardware and development time. ## Support trimtest | Where | What | | --- | --- | | [GitHub Sponsors](https://github.com/sponsors/RabinApps) | Monthly or one-time, with tiers | | [PayPal](https://www.paypal.com/donate/?hosted_button_id=YEJ37WF4Q3HPC) | One-time donation | | [Buy Me a Coffee](https://buymeacoffee.com/rabinapps) | One-time ($1 to $50+) or $1/month | ## Become a sponsor Companies can sponsor trimtest and have their logo and a link shown on this site and in the README. Pick a company tier on [GitHub Sponsors](https://github.com/sponsors/RabinApps), or email [support@rabinapps.com](mailto:support@rabinapps.com?subject=trimtest%20sponsorship) with your company name, link and logo. Sponsorship supports the project; it does not buy influence over the roadmap or over what trimtest selects. ## Sponsors trimtest is sponsored by [SupDesk](https://supdesk.app), the feedback and support console for solo founders, devs and small teams. ## Just using trimtest? Telling people helps as much as money. Star the [repository](https://github.com/RabinApps/trimtest), and [report what you find](https://github.com/RabinApps/trimtest/issues/new/choose): a missed test is the most useful bug report there is. ## More from Rabin Apps - [kinhin](https://kinhin.dev): ephemeral, autoscaling CI runners, plus store screenshots and launch videos built from files in your repo. - [SupDesk](https://supdesk.app/en): the feedback and support console for solo founders, devs and small teams.