Repository navigation
perf(hooks): run only the Rust tests a branch's changes reach on pre-push - #1119
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a173b1835
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const top = root | ||
| ? realpathSync(root) | ||
| : run('git', ['rev-parse', '--show-toplevel'], process.cwd()).trim(); |
There was a problem hiding this comment.
Resolve the repository root independently of hook Git variables
When pushing from a linked worktree, the hook's inherited GIT_DIR makes this call return the current directory rather than the worktree root. Staged's test-selected recipe runs from apps/staged, so the selector subsequently looks for apps/staged/apps/staged/src-tauri/src and exits with ENOENT, blocking pushes that run Staged's Rust checks. I reproduced this by invoking the selector from apps/staged with an absolute GIT_DIR and an explicit changed path. Derive the root from the script's location, or otherwise account for the inherited Git environment, before constructing repository-relative paths.
Useful? React with 👍 / 👎.
…push The pre-push hook ran every Rust test whenever a branch touched crates/ or apps/staged/. The src-tauri lib suite (about 3,300 tests) took 10 to 20 minutes in the hook on a loaded machine, and it set how long a push took. scripts/selected-tests.mjs now picks the tests for the hook's two Rust test jobs from the branch's changes, the same changes scripts/unchanged looks at: - crates-test: `cargo test -p` for the changed workspace crates and the crates that depend on them. - Staged's ci-local (new `test-selected` recipe): `cargo test --workspace` filtered to the src-tauri top-level modules the branch changes, the modules that name them (`crate::module`) or a changed crate, and the modules that quote a changed file's name (`include_str!`). stagedctl changes run stagedctl's tests. The build stays `--workspace`, so it reuses the full run's artifacts. Manifests, lockfiles, build.rs, tauri.conf.json, capabilities/, lib.rs, main.rs, the toolchain, bin/ and the hook files run every test, as does a src-tauri file that no module quotes or a missing merge-base. The script prints what it picked and why. `PRE_PUSH_ALL_TESTS=1 git push` runs everything, and `just ci` and CI are unchanged. Clippy, formatting and the frontend checks still run in full. vitest's `related` mode can't build this config's import graph: the unit project has no Svelte plugin and fails to parse .svelte files. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
…t picks them Addresses the four findings in the review of 65d6ea2. lib.rs's tests were never selected. They were named `tests::…` from the crate root, where no `<module>::` filter reaches, so a push that changed `store` ran the tests of 50 modules but not the 12 in lib.rs that open and reset the store. They are now in src/lib_tests.rs, declared as `#[cfg(test)] mod lib_tests;`, and the script reads that file as a module like any other. It names `crate::store` and `crate::app_lifecycle`, so a change to either selects `lib_tests::`. A dry run for store/mod.rs lists lib_tests among its 51 modules, and the 12 tests pass under their new names. Nothing else has that shape today. main.rs has no tests, src-tauri has no tests/ directory, and all 3,269 names the staged_lib test binary lists start with a top-level module the script knows. stagedctl's tests and the crates' tests run by package, not by name. So that it stays true, the script now runs every test, and says why, when lib.rs or main.rs defines a test or src-tauri/tests exists. Feature unification: measured, and the commands are unchanged. `-p` enables only the features the selected packages ask for, so the first run of a selection compiles some dependencies again beside the copies the `--workspace` build made. Each measurement used `cargo test --no-run -v` in an empty, private target directory, with 6 jobs on a machine at load 60 to 330, after a full build: - crates (full build 181 s, 251 packages): `-p pm` compiled 19 packages in 4 s, `-p acp-client -p builderbot-actions` 37 in 31 s, `-p summarize` 65 in 10 s. The selected crates are in those counts. - Staged (full build 352 s, 464 packages): `-p stagedctl --lib --bins --tests` compiled 50 packages in 25 s, stagedctl included. A second run of each selection compiled nothing, and so did a full build afterwards: the two sets of artifacts sit side by side. `--workspace --exclude` is no way around it. Cargo's unit graph is identical for `--exclude` and `-p`, and with `-v` the `--exclude` form compiled the same 19 packages for pm and the same 50 for stagedctl, after which `-p` compiled none. Test-name filters can't pick a package either. The cost is under a minute, once per selection and lockfile, against the 10 to 20 minutes of tests a selective push skips, so the script keeps `-p` and its comments record these numbers. scripts/selected-tests.test.mjs is a table-driven `node --test` suite of 45 cases. It runs the script with `--dry-run -- PATH...` and reads the commands it prints: a store change (store, modules that name it, lib_tests), a crate change in both modes (the crate, its dependents, the modules that use them), a quoted fixture, stagedctl, each file that runs every test, files nothing quotes, and PRE_PUSH_ALL_TESTS. Cases assert that a few names are selected or left out, not whole lists. `just app staged test-selection` runs it. `ci-rust-test` depends on it, so `just ci` and Staged's "Rust test" job run it, and the hook's `ci-local` runs it before `test-selected`. Staged CI and scripts/unchanged now watch scripts/selected-tests*.mjs, so editing the script or its tests runs them. Noticed, not changed: - lib_tests is selected by the modules its own file names. A lib.rs test that reaches another module only through a lib.rs function is not selected when that module changes. - crates/acp-client's real_bridge test compiles apps/staged/src-tauri/src/note_done/rules.rs by `#[path]`. A change to that file runs no crate tests in the hook, and crates-ci.yml doesn't watch it either. Verified here: the 45 node tests, the 12 lib_tests, and the 291 tests of web_server, control_server and workspace_setup, which read lib.rs's text. Not run on this machine, which was at load 100 to 350: the rest of the Staged suite, the crates' tests and clippy. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
Addresses the review of the branch after 768e482. Its three verified gaps were all the same shape: a test reads a file that its own crate or module doesn't own, and a change to that file didn't run the test. What a crate or module reads. scripts/selected-tests.mjs now resolves the paths a Rust source names: a string with `../` in it, taken from the source file's directory (`include_str!`, `include_bytes!`, `#[path]`) and from the crate's (a path handed to std::fs), and a string joined to `CARGO_MANIFEST_DIR`. A path that is a directory reads every file under it. The app's modules also keep the older check, a file's name quoted as the end of a string, which covers paths joined at run time. 1. stagedctl. Its src/ and tests/ are read like a module's sources, by resolved path, so a change to any of the files it embeds runs `cargo test -p stagedctl`. Matching by name would run it for every control.rs, notes.rs or sessions.rs in the app. A file that only stagedctl embeds no longer runs every test, and a file a module also quotes no longer hides stagedctl. Dry runs: control_server.rs now prints the stagedctl command beside its eight modules, resources/stagedctl/guide.md prints session_commands, lib_tests and stagedctl, and tagTemplates.ts prints stagedctl alone. The hook never asked the script about tagTemplates.ts, and neither did CI. `ci-local`'s rust_paths and the `rust` filter in staged-ci.yml list the frontend files the Rust build embeds, but not the ones only Rust tests read, so a push or a PR that changed just such a file skipped every Rust check. There are four: tagTemplates.ts (stagedctl), sessionModalHelpers.ts (session_runner, read at run time), noteDone.cases.json (note_done) and workspaceLifecycle.svelte.ts (workspace_setup). Both lists now name them. 2. Tests that scan every source file. No names are hardcoded: a module whose source joins `CARGO_MANIFEST_DIR` to a directory is selected for any change under that directory. Today that is blox and web_server, for src/. The whole top-level module is selected, not the guard's submodule: its path can't be derived reliably through `#[path]`, and a walker may be a helper that sibling tests call. That is 109 tests by attribute count (2 in blox, 107 in web_server) on every push that touches src/. A directory read selects the reader but does not place the file, so a file in src/ or resources/ that nothing names still runs every test. The other tests that read files by path, which I searched for with CARGO_MANIFEST_DIR, `../` strings, include_dir!, file!() and current_dir: session_commands (pikchr/grammar.md and stagedctl/guide.md, by a constant), remote_staged_mcp (staged-mcp.cjs), session_runner (sessionModalHelpers.ts), web_server (note_transfer's answers.json), store (its migrations, by include_dir!), stagedctl's help_pins (its own fixture) and acp-client's real_bridge (staged-mcp.cjs). All are selected now; only the frontend file and real_bridge's two were not before. 3. `lib_tests::` is added to every non-empty selection of the app's modules. 4. A src-tauri/src/bin directory runs every test, like src-tauri/tests. 5. acp-client. Crates are read the same way, so nothing is mapped by hand: a change to note_done/rules.rs, which real_bridge.rs compiles by `#[path]`, or to resources/remote/staged-mcp.cjs, which it runs, now tests acp-client and builderbot-actions, which depends on it. Both paths are in crates-ci.yml and in the `crates` area of scripts/unchanged, so the hook and CI get as far as asking. No other crate reads outside itself. The guard on lib.rs and main.rs now errs toward running everything: any attribute with "test" in its name counts (`#[rstest]`, `#[test_case(…)]`), and an inline module under any `cfg` that mentions `test`, with other attributes before `mod`. Line comments are removed first, which was one line, so prose about `#[test]` no longer turns every push into a full run. A block comment still does. Tests. scripts/selected-tests.test.mjs goes from 45 to 95 cases: - The cases against this repository gain the discriminating ones the review named (pikchr_subsession for crate dependents, branch_teardown for a group import, stagedctl's client.rs selecting control_server, a run-everything file after a module change) and one for each scenario above. tag_commands.rs and timeline.rs no longer tell quoting apart, since web_server and blox are now selected for any src/ change, so that case is prs/context.rs, which workspace_setup quotes without naming `crate::prs`. - `--root DIR` makes the script take DIR as the repository. The tests write a small tree to a temporary directory from a table in the test file (four crates, an app with a module per way of being selected, a stagedctl) and write a case's own files over it. It covers what this repository must not contain: tests in lib.rs in seven spellings and in main.rs, tests/ and src/bin, and each kind of read in isolation, with whole selections asserted. It is a table and not committed files so that no stray Cargo.toml or .rs sits where cargo, Renovate or the app's own source scans would find it. - `--outside-reads` prints the files each crate or module reads outside its crate. Two tests hold crates-ci.yml, scripts/unchanged, staged-ci.yml's `rust` filter and `ci-local`'s rust_paths to that list, so a new embed of a frontend file fails until the lists name it. Mutation check. A scratch harness broke one rule at a time in a copy of the script and ran the suite against it (SELECTED_TESTS_SCRIPT points the tests at another copy). 39 mutations, and each failed at least one test: - The six the review found surviving: crate dependents not followed in staged-rust (3 tests fail), the quote check off for files inside a module (2), `use crate::{…}` groups not parsed (2), the lib.rs/main.rs/tests guard off (10), module quoting of stagedctl files dropped (2), and the run-everything trigger checked on the first path only (1, and 1 for the crates mode's). - stagedctl: not run for a file it embeds, not run for a directory it walks, its tests/ not read, an embedded file not counted as placed, its command tied to its own changes again. - Walkers: not selected, counted as placing a file, directories never detected, CARGO_MANIFEST_DIR joins not read in each of their three forms, `"../"` alone read as a directory. - lib_tests not added. src/bin not checked, tests/ not checked, main.rs not checked, test attributes or inline modules not looked for, each of the two patterns put back as it was, comments not removed. - Crates: readers not selected, walkers not selected, a reader's dependents not followed, relative paths resolved from only the file's directory or only the crate's, a crate's file matched by name in the app, a module that embeds a crate's file not selected. - `--outside-reads`: paths that don't exist kept, a crate's own paths kept, directories left out. The harness is not committed. Noticed, not changed: - Staged CI doesn't watch scripts/unchanged or crates-ci.yml, which the path-list tests now read. Editing one of them alone can leave a list short until the next PR that runs Staged's Rust tests. - A PR that changes only one of the four frontend files above now runs Staged's Rust jobs in CI, and clippy and the selected tests in the hook. - A change to stagedctl's src/main.rs or src/lib.rs also selects git, project_transfer, session_runner and store, whose test data quotes "src/main.rs". The same accident for the root crates' files is gone, since those are matched by path, but stagedctl's files are still matched by name, as before. - A path the script can't resolve is still missed for stagedctl and the crates: one with a space in it, one built from several `join`s, or one held in a constant. The app's modules have the name check for the last. - builderbot-actions is tested for a rules.rs change only because it depends on acp-client, whose library that file is not part of. Verified here: the 95 node tests (`just app staged test-selection`), the mutation runs above, a dry run of each scenario in the review, the `crates` pattern of scripts/unchanged and rust_paths against the new paths with `grep -E`, and prettier on the two scripts. Not run: any Rust test, clippy or build. No Rust source changes, and the machine was at load 50 to 90. The workflows were not run either; I checked their edits by reading them and through the path-list tests. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
…llow Applies the five optional suggestions from the review of 61d9af2, which judged the branch ready to push. None of them changes what today's tree selects, except that stagedctl's files select fewer modules. 1. Paths the script can't resolve. `--unresolved-reads` prints, as `NAME<tab>FILE:LINE`, each place where a crate, a module of the app or stagedctl builds a path the script can't follow: a `CARGO_MANIFEST_DIR` that the script's pattern for it does not consume (kept in a variable, joined to a constant, followed by `.parent()`), and a `read_dir("src")` that counts on the directory cargo runs the tests in. A test pins that list, by module and file, to the two it finds today: the constants that session_commands joins for the Pikchr grammar and the stagedctl guide, which the module quotes by name and so is selected for. Crates have none. A new one fails `test-selection` in the PR that adds it. The message lists the lines, shows the forms the script resolves, and says to add the line to KNOWN_UNRESOLVED when its tests are selected another way. The working-directory pin is `read_dir` of a relative literal only, and not when the directory is the unit's own (a crate reading its own `tests/fixtures`), which selects it already. `fs::read*` and `File::open` of a bare literal are not pinned: in a module of the app the name check covers the file, and in a crate or stagedctl the path stays inside it, so a pin would only fail on code that is selected correctly. Line comments don't count. 2. stagedctl's files are matched to the app's modules by resolved path, as the root crates' files are, not by name. Only control_server reads them, client.rs and commands.rs, both by `../../crates/stagedctl/src/…`. I compared the old and new selection for all 16 files of stagedctl. Five differ: main.rs no longer selects git, project_transfer, session_runner and store; lib.rs no longer selects eight modules; commands.rs keeps control_server and drops blox, doctor, web_server and workspace_setup; notes/tests.rs and projects/tests.rs drop blox. `cargo test -p stagedctl` still runs for every one of them. 3. A `#[path]` attribute in lib.rs or main.rs, `cfg_attr(…, path = …)` included, runs every test: such a module's tests are named as declared, and the script takes a module's name from where its file is. 4. An argument after `--` that starts with `-`, is absolute, or is `.`, `..` or starts with `./` or `../` is a usage error (exit 2), named in the message. `-- PATH --dry-run` used to print a selection and then start the tests. Paths that don't exist are still accepted. 5. `--outside-reads` prints a directory with its trailing slash, and the two tests that hold the path lists to its output check a path two levels under a directory, so `dir/**` and `dir/` cover it, and `dir` or `dir/*` do not. Tests. scripts/selected-tests.test.mjs goes from 95 to 113 cases: - This repository: stagedctl's commands.rs selects control_server and not the four modules that quote the name; its main.rs and lib.rs select none of git, store, session_runner and project_transfer, with stagedctl's tests running in all three; and the two pins of item 1. - The fixture: a module whose test data quotes "src/main.rs", "lib.rs" and "client.rs", which must not be selected for stagedctl's files or a crate's; `#[path]` in lib.rs in two spellings and in main.rs, and one in a comment, which selects as usual; `--unresolved-reads` over each shape that is and is not followed, in a module, a crate and stagedctl, with line numbers. - Six usage errors, `--dry-run` after `--` among them. Each also has `--dry-run` before the `--`, so a script that lets one through starts nothing. - A directory read, taken from the fixture's `--outside-reads`, against lists written in the test: covered when listed as `dir/**` or `dir/`, uncovered when unlisted, listed as a file, or listed one level deep. Mutation check, with the uncommitted harness as before: 30 mutations of the final script, each run against the final suite, and each failed at least one test. - Item 1 (12): mentions never reported, resolved ones reported too, `read_dir` never reported, the own-directory exemption removed, comments counted, `read_dir("../x")` and an absolute one reported, `&"x"` not seen, line numbers off by one, the option printing the other report, stagedctl not scanned, crates not scanned. - Item 2 (3): stagedctl matched by name again (5 tests fail), never matched to a module, its own tests not run for its change. - Item 3 (5): the guard off, on lib.rs only, on main.rs only, `cfg_attr` not seen, a comment counted. - Item 4 (8): no validation, each of the three conditions dropped, `./`, `../` and `.` each let through, and a warning in place of the exit. - Item 5 (2): the slash dropped, directories left out. Dry runs, all with the options before `--`. In a scratch copy of the tree (`git archive` of HEAD plus the two scripts), with `cargo` stubbed for everything but `metadata`: - Each of the review's three shapes, added to pikchr_validation.rs, is reported and fails the pin with the message above. `.join("..").join(…)` is not reported and still selects the module, as the review found. - A module that walks `../src/lib/features/tags` prints the directory with its slash. The list test fails with the lists as they are, fails with the directory in the workflow filter only, passes with `apps/staged/src/lib/features/tags/**` in the filter and `…/tags/` in rust_paths, and fails with `tags/*`. - `#[path]` added to lib.rs runs every test, and in a comment does not. - `staged-rust -- …/pikchr_validation.rs --dry-run`, the review's form, exits 2 and the stub is never called. So do `./…`, `../…`, an absolute path and `-p`. A deleted path and `.github/…` are accepted. Against this tree: the 16 stagedctl files above, and a store, crate and guide.md change in both modes, whose output is identical to the old script's. Noticed, not changed: - A path relative to another directory but without `./`, such as `-- src-tauri/src/store/mod.rs` from apps/staged, is still accepted and still answers "web_server and lib_tests". Its form is that of a deleted repo-relative path. - Other ways to read a directory from the working directory, such as `Path::new("src").read_dir()` or a walker crate, are not reported. They look the same as the path strings in test data. - A `CARGO_MANIFEST_DIR` in a block comment counts as a mention. lib.rs and main.rs are not scanned: they are no module, and a change to them runs every test. Verified here: the 113 node tests (`node --test scripts/selected-tests.test.mjs`, which is what `just app staged test-selection` runs), the mutation and dry runs above, and prettier on the two scripts. Not run: any Rust test, clippy or build, `just ci`, the hook itself, or the workflows. Only the two scripts change, and the machine was at load 30 to 90. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
…hain Fixes the one finding in the review of 7a1dd43. scripts/selected-tests.test.mjs writes a small repository to a temporary directory and runs scripts/selected-tests.mjs on it with `--root`. The script runs `cargo metadata` there. The tree had no rust-toolchain.toml, so rustup chose its default toolchain, and where no default is set it stops with "rustup could not choose a version of cargo to run". 30 of the 113 tests then fail. The pre-push hook runs this suite (`test-selection`) before the selected tests, so on such a machine every push that reaches the Rust checks would fail. The fixture now includes this repository's rust-toolchain.toml, read from disk when the tests start, so cargo in the fixture is the pinned one however rustup is set up. Nothing else changes. Which machines were exposed: - One whose only Rust is the one bin/ installs. Hermit's rustup package sets CARGO_HOME and nothing else (its manifest and `hermit env` both show this), so rustup's home is ~/.rustup, and the shims only install the toolchains that a rust-toolchain.toml asks for. They never set a default. - Not this machine: its ~/.rustup has `stable` as the default. - Not Staged CI, as far as I can tell without running it. The "Rust test" job gets `cargo` from the same hermit shim (cashapp/activate-hermit, then `just ci-rust-test`, which runs `test-selection`). RUSTUP_HOME is unset there too, so rustup uses the runner's ~/.rustup, which GitHub's ubuntu image creates with `--default-toolchain=stable` (install-rust.sh in actions/runner-images, read today). The fixture's `cargo metadata` would have run on the image's stable, not the pinned 1.99.1, and passed. That rested on the image and not on anything in this repository. The branch is not pushed, so the suite has never run in CI. What I ran, at load 45 to 90: - A RUSTUP_HOME with no default: a temporary directory holding a symlink to ~/.rustup/toolchains and a settings.toml without `default_toolchain`. In it, `cargo --version` fails from /tmp and prints 1.99.1 from the repository. - Before the change, `node --test scripts/selected-tests.test.mjs`: 113 of 113 pass in the normal setup, and 83 pass and 30 fail with that RUSTUP_HOME, each failure with the rustup message above. - After the change: 113 of 113 with that RUSTUP_HOME, and 113 of 113 in the normal setup through `just app staged test-selection`. - prettier --check on the test file. Not run: any Rust test, clippy or build, the hook itself, or the workflow. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
…rom git The pre-push hook's selected Rust tests failed on every push from a linked git worktree, which is what a Staged workspace is. Git exports GIT_DIR to a hook that runs in a linked worktree. With GIT_DIR set and no GIT_WORK_TREE, `git rev-parse --show-toplevel` answers with the current directory. The hook runs `just app staged ci-local`, whose recipes run in apps/staged, so both scripts took apps/staged as the repository root. - scripts/selected-tests.mjs looked for apps/staged/apps/staged/src-tauri. `staged-rust` exited 2 with `spawnSync cargo ENOENT`, because the working directory it gave cargo doesn't exist. In `crates` mode from that directory a changed crate file was "in no crate" and every crate was tested. - scripts/unchanged, which `ci-local` calls to decide whether to skip the Rust checks, has the same problem on main. It compared the branch against a tree where almost every tracked file looks deleted, so the Rust checks were never skipped. Nothing was skipped wrongly, only run needlessly. Both now take the repository to be the parent of the directory they are in. `--root DIR` still overrides it in selected-tests.mjs. Not affected before: CI and plain clones, where GIT_DIR is unset, and the hook's crates-test job, which lefthook runs from the repository root. Checked before this commit, from apps/staged with GIT_DIR set to this worktree's git directory and `cargo` stubbed for everything but `metadata`: - `selected-tests.mjs staged-rust`: was exit 2, now exit 0 with cargo started in apps/staged/src-tauri. - `staged-rust --dry-run -- …/store/mod.rs`: was `ENOENT: scandir`, now selects 52 of 70 modules. - `crates --dry-run -- crates/pm/src/lib.rs`: was "testing every crate", now `cargo test -p pm`. - `node --test scripts/selected-tests.test.mjs`: 113 of 113 pass. Without GIT_DIR the old and new scripts print the same selection. `prettier --check` passes on the script and `bash -n` on scripts/unchanged. Not done: no test covers this. The suite passes with and without the change, because every test runs the script from the repository root. A dry run from apps/staged with GIT_DIR set would catch it. The hook itself has not been run end to end on this branch. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
7a173b1 to
5f08445
Compare
Summary
The pre-push hook ran every Rust test whenever a branch touched
crates/orapps/staged/. The src-tauri lib suite (about 3,300 tests) took 10 to 20 minutes in the hook on a loaded machine. The hook now runs only the Rust tests the branch's changes reach.scripts/selected-tests.mjspicks the tests for the hook's two Rust test jobs from the same changesscripts/unchangedlooks at:cargo test -pfor the changed workspace crates and the crates that depend on them.ci-local(newtest-selectedrecipe):cargo test --workspacefiltered to the src-tauri top-level modules the branch changes, the modules that name them (crate::module) or a changed crate, and the modules that read a changed file (include_str!,#[path],CARGO_MANIFEST_DIRjoins, quoted file names). stagedctl's tests run for its own changes and for files it embeds.Every test still runs when the selection can't be trusted: manifests, lockfiles,
build.rs,tauri.conf.json,capabilities/,lib.rs,main.rs, the toolchain,bin/, the hook files, a src-tauri file nothing reads, or a missing merge-base. The script prints what it picked and why.PRE_PUSH_ALL_TESTS=1 git pushruns everything.just ciand CI still run the full suites. Clippy, formatting and the frontend checks still run in full in the hook.Other changes
lib.rs's tests move tosrc/lib_tests.rs, so a module filter can reach them. They are added to every non-empty selection of the app's modules.scripts/selected-tests.test.mjsis anode --testsuite of 113 cases, run against this repository and against a fixture tree written to a temporary directory.just app staged test-selectionruns it.ci-rust-testand the hook'sci-localdepend on it.crates-ci.yml,staged-ci.yml,scripts/unchangedandci-localto the files Rust tests read outside their own crate. Four frontend files that only Rust tests read were missing from the Staged lists and are now in them, so a PR that changes only one of them runs Staged's Rust jobs.test-selectionin the PR that adds it.scripts/selected-tests.mjsandscripts/unchangedtake the repository to be the parent of their own directory.git rev-parse --show-toplevelanswers with the current directory inside a hook in a linked worktree, which madescripts/unchangednever skip the Rust checks there.Testing
node --test scripts/selected-tests.test.mjs: 113 of 113 pass, also with aRUSTUP_HOMEthat has no default toolchain.lib_testspass, as do the 291 tests ofweb_server,control_serverandworkspace_setup, which readlib.rs's text.Known gaps
joins or with a space in it is still missed for stagedctl and the crates.lib.rstest that reaches another module only through alib.rsfunction is selected by the moduleslib_tests.rsnames, not by that module.scripts/unchangedorcrates-ci.yml, which the path-list tests read.🤖 Generated with Claude Code