feat(tooling): run the unit tests that mention a changed file in ci:prepush
User description
Summary
ci:prepush ran policy scripts only and never executed a unit test. A push that changed .github/workflows/tauri-build.yml therefore passed the local gate while tests/unit/workflowPolicy.test.ts still held the old expectations, and the failure only showed up in the hosted Quality Gate on both Node versions (PR #1208).
This adds a "Related unit tests" step to the local admission gate.
What changes
scripts/ci-prepush-related-tests.mjsselects the unit test files that were changed plus every unit test that mentions a changed source, workflow, script or config file. It searches withgit grepfor the path, the extension-less import path (TypeScript) and the basename (workflows, scripts, config), so a test that reads a workflow from disk is found too. A pure import graph such asvitest relatedwould not find those.- The selected files run as an explicit list (
vitest run <files>), never as a suite. End-to-end specs are never selected. - At most 8 files run locally. A larger set is reported as
DEFERRED_TO_REQUIRED_CIwith the count, and missing change evidence is reported as deferred as well. Nothing is skipped silently. - The step is routed by the existing admission registry (
relatedTests) and runs before the TypeScript check. - Ambiguous change evidence (for example a new branch) is reported as
DEFERRED_TO_REQUIRED_CIinstead of presenting a meaningless selection. - The pre-push hook started the whole local gate with the default 120 s child bound, so any run that took longer was sent SIGTERM mid-step and failed with a bare
FAIL. That is why a full-range typecheck of a new branch failed after about two minutes. The gate now has its own finite bound (25 minutes), the typecheck and the related-test run have theirs (10 and 8 minutes), and a test requires the gate bound to exceed the sum of the two heavy steps. - A failing typecheck or related-test run now prints how it ended (exit status, signal, timed out or interrupted), because the SIGTERM was undiagnosable before.
- The related tests run without any
GIT_*variable. Run from the pre-push hook,signing.test.tsfailed because git hands its variables to its children, while the same tests pass from a normal shell; this was reproduced withGIT_DIRset. - Test selection mirrors the Vitest include list exactly (
.testand.spec,.tsand.tsx, minustests/e2e/), accepts JSON sources such assrc-tauri/tauri.conf.json, and drops bare generic names such aspackage.json.
Tests
tests/unit/tooling/ciPrepushRelatedTests.test.tscovers needle derivation, selection, ordering, deleted tests, excluded end-to-end specs, the limit boundary (8 runs, 9 defers) and registry routing.- One regression test pins the incident: changing
tauri-build.ymlselectsworkflowPolicy.test.tsandreleaseSecurityGate.test.ts. pnpm run ci:prepushran the new step on this change: 3 related test files, 60 tests passed. The pre-push hook then caught a real README test-count drift introduced by the added test, which is fixed in the same PR.- Tests pin that all three bounds are finite and above the 120 s default, that the gate bound exceeds the sum of its heavy steps, and that every
GIT_*variable is removed from the test environment.
Scope
Local tooling only. The required hosted CI, its checks and the merge rules are unchanged. No release, tag or deployment is involved.
Summary by Sourcery
Run relevant unit tests in the pre-push gate and make deferred checks and local failures explicit.
New Features:
- Run up to eight unit tests related to changed source, workflow, script, and configuration files during the pre-push admission gate.
- Report oversized or unavailable test selections as deferred to required CI instead of silently skipping them.
Bug Fixes:
- Prevent pre-push checks from inheriting GIT_* variables that can break tests using temporary Git repositories.
- Avoid premature termination of longer local checks and provide actionable failure details when checks exit, time out, or are interrupted.
Enhancements:
- Route related-test admission through the existing check registry and align selection with the Vitest unit-test scope.
- Update user-facing CI guidance, changelog entries, and test-count metrics for the expanded local gate.
Documentation:
- Document related unit-test selection, deferral behavior, exclusions, environment isolation, and local check timeouts.
Tests:
- Add coverage for test classification, related-file matching, workflow and configuration regressions, selection limits, deferrals, environment cleanup, timeout bounds, and registry routing.
Summary by cubic
Runs the unit tests that mention a changed file in ci:prepush, so a changed workflow or script no longer reaches hosted CI with stale test expectations in the tests that read it.
What changes
- Selects changed test files plus every unit test that references a changed source, workflow, script, or config file, via
git grepon the path, extension-less import, and basename. Selection mirrors the Vitest include list, so chosen files are always runnable. - Up to 8 files run as an explicit
vitest runlist; larger sets, missing or ambiguous change evidence, and excluded files are reported as deferred to required CI, never skipped silently. - Changes that select nothing by design are documented: root
package.jsonandtsconfig*.json, bareindex/types/constants/utilsnames, and JSON underlocales/,public/,community-templates/,docs/,reports/, andtests/. - The related-test run strips
GIT_*variables the pre-push hook passes on, which broke tests that run git in disposable repositories. - The typecheck, related-test run, and whole gate get bounded timeouts above the 120 s default child bound; a dead child now reports its exit status and signal, so failures are diagnosable.
CodeAnt-AI Description
Run relevant unit tests before a push and clearly report checks deferred to CI
What Changed
- The pre-push gate runs changed unit tests and tests that mention changed source, workflow, script, or configuration files, up to 8 files.
- When too many tests match or change evidence is unavailable, the gate reports that required CI must run them instead of silently skipping them.
- Longer-running local checks have bounded timeouts and report whether they failed, timed out, or were interrupted.
Impact
✅ Stale workflow and source expectations caught before push
✅ Deferred unit tests clearly identified for required CI
✅ Clearer reports when local checks time out or fail
💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
@codeant-ai ask: Your question here
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
@codeant-ai ask: Can you suggest a safer alternative to storing this secret?
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
@codeant-ai: Your feedback here
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
@codeant-ai: Do not flag unused imports.
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
@codeant-ai: review
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit
- New Features
- Pre-push checks now run up to eight unit tests related to changed files. If more than eight tests match—or the changes can’t be determined reliably—the tests are deferred to CI.
- Local checks now have defined time limits, with clearer reporting when a check fails or times out.
- Documentation
- Updated CI guidance to explain related-test selection and deferral behavior.
- Updated reported test totals to 8,735+ tests across 657 files.