Skip to content

chore: speed up pre-commit with staged-related Vitest - #696

Merged
rinchen merged 4 commits into
mainfrom
tests
Jul 20, 2026
Merged

chore: speed up pre-commit with staged-related Vitest#696
rinchen merged 4 commits into
mainfrom
tests

Conversation

@rinchen

@rinchen rinchen commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace full-suite pre-commit Vitest with staged-related selection via scripts/precommit-tests.mjs (pnpm run test:staged), including co-located sibling tests and project scoping.
  • Path-gate slower check:* scripts (flatpak, DB migrations, IPC, Reticulum modes/hubs/sidecar) and run ESLint only on staged JS/TS with cache; keep full typecheck and security scanners always on.
  • Document that green pre-commit ≠ green CI — PR tests.yaml still runs the full suite with coverage.

Test plan

  • Commit a docs-only change and confirm pre-commit skips Vitest / path-gated checks as expected
  • Commit a single src/main source change and confirm related Vitest runs (main project) instead of the full suite
  • Stage package.json or pnpm-lock.yaml and confirm pre-commit forces a full Vitest run
  • Run pnpm exec vitest run scripts/precommit-tests.test.mjs and confirm planner unit tests pass
  • Confirm CI tests.yaml still runs the full suite on the PR

Summary by CodeRabbit

  • New Features
    • Added test:staged to run Vitest for staged changes with an optimized skip/full/related strategy.
    • Improved pre-commit behavior to run staged-first checks (including staged ESLint with caching and path-gated scanners).
  • Documentation
    • Updated pre-commit vs CI/release guidance to clarify staged-only local checks and full-suite CI/release requirements.
  • Tests
    • Added automated tests for staged test planning/execution and for the pre-commit ESLint batching approach.
    • Added release-script tests enforcing full-suite and “no staged/related” rules.
  • Chores
    • Added .eslintcache to Git ignore.

- Add scripts/precommit-tests.mjs (test:staged): vitest related on staged
  files only, co-located sibling tests, project filtering, narrow force-full
  for vitest infra/deps (drop blanket src/shared|preload full suite).
- Path-gate flatpak/DB/IPC/reticulum catalog/sidecar checks and pnpm audit;
  run ESLint on staged JS/TS with --cache; keep full typecheck.
- Document that PR CI (tests.yaml) still runs the full suite with coverage.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6d56dcaa-9521-4743-956a-c9699bc31085

📥 Commits

Reviewing files that changed from the base of the PR and between 81e8f32 and 62f0281.

📒 Files selected for processing (1)
  • scripts/pre-commit.eslint-batch.test.mjs
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/pre-commit.eslint-batch.test.mjs

📝 Walkthrough

Walkthrough

The pre-commit hook now centralizes staged-file matching, runs staged ESLint and staged Vitest planning, and gates checks by changed paths. Release validation adds environment and policy scanners, requires workflow linters, and enforces the full Vitest suite. Documentation and tests describe and verify both flows.

Changes

Staged pre-commit validation

Layer / File(s) Summary
Staged hook checks
.githooks/pre-commit, .gitignore, scripts/pre-commit.eslint-batch.test.mjs
The hook centralizes staged-path matching, lints staged JS/TS files with ESLint caching, gates checks by path, delegates staged test execution, and ignores .eslintcache.
Vitest planning and execution
scripts/precommit-tests.mjs
The helper selects skip, related, or full-suite Vitest execution, maps projects, expands sibling tests, safely spawns the local Vitest CLI, and reads staged paths from a file or Git.
Script wiring and planner coverage
package.json, scripts/precommit-tests.test.mjs
Adds test:staged and tests full-suite, related-test, skip, project-selection, and argument-passing behavior.
Contributor and workflow documentation
AGENTS.md, docs/ci-cd.md, docs/development-environment.md
Documents staged checks, path-gated validation, sidecar conditions, staged testing, dependency audit gating, and full PR CI behavior.

Release validation gates

Layer / File(s) Summary
Release pre-flight checks
scripts/release.sh, docs/release-process.md
Release validation adds environment and policy scanners, requires actionlint and yamllint, and specifies unrestricted pnpm run test:run execution.
Release validation assertions
scripts/release.test.mjs
Tests enforce the full-suite command, required linters, required PNPM checks, and absence of staged or related Vitest commands.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant PreCommit as pre-commit hook
  participant ESLint
  participant Vitest as precommit-tests.mjs
  Developer->>PreCommit: Create commit with staged files
  PreCommit->>ESLint: Check staged JS/TS files
  PreCommit->>Vitest: Pass staged file list
  Vitest->>Vitest: Plan skip, related, or full execution
  Vitest-->>PreCommit: Return test status
  PreCommit-->>Developer: Accept or reject commit
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: speeding up pre-commit by switching to staged-related Vitest.
Docstring Coverage ✅ Passed Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tests

Comment @coderabbitai help to get the list of available commands.

- Always run full Vitest via `pnpm run test:run` (never staged/related/changed).
- Add scanners that pre-commit may path-gate (electron-security, i18n, XSS, etc.).
- Require actionlint and yamllint instead of soft-skipping when missing.
- Contract-test release.sh and document the release vs pre-commit gate.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.githooks/pre-commit:
- Around line 101-103: Update the ESLint batching command in the pre-commit hook
to preserve staged filenames containing spaces, quotes, and backslashes, and
prevent option-like filenames from being parsed as flags; use a null-delimited
or otherwise filename-safe input mechanism while retaining batching and the
existing ESLint failure handling. Add regression coverage for a staged pathname
containing spaces, ensuring the behavior works across Linux, macOS, and Windows.

In `@docs/ci-cd.md`:
- Line 237: Update the CI/CD checks bullet to state that the path-gated sidecar
stub check requires cargo to be available on PATH when sidecar paths are staged,
while preserving the existing check and locale conditions.

In `@scripts/precommit-tests.mjs`:
- Around line 187-194: Update runVitestArgv and its runRelatedTests call path to
avoid shell interpretation when passing staged filenames, using a shell-free
Vitest launcher while preserving argument boundaries on Windows. Add
Windows-focused coverage for staged paths containing spaces and command
metacharacters such as &, |, and %, verifying they are passed as literal
arguments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 85c98a88-8256-4402-b26c-cd4d794940e5

📥 Commits

Reviewing files that changed from the base of the PR and between 7559aef and b695daa.

📒 Files selected for processing (8)
  • .githooks/pre-commit
  • .gitignore
  • AGENTS.md
  • docs/ci-cd.md
  • docs/development-environment.md
  • package.json
  • scripts/precommit-tests.mjs
  • scripts/precommit-tests.test.mjs

Comment thread .githooks/pre-commit Outdated
Comment thread docs/ci-cd.md Outdated
Comment thread scripts/precommit-tests.mjs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/release.test.mjs`:
- Around line 12-33: Update the REQUIRED_PNPM_CHECKS array to include the
existing check:environment script, ensuring the release contract requires it
alongside the other check:* scanners and prevents release.sh from omitting it.
- Around line 44-46: Update the test identified by the “runs pnpm run test:run
for the full Vitest suite” case to assert the executable invocation in
scripts/release.sh rather than matching arbitrary comment or echo text. Anchor
the regex to the command’s execution context so removing the actual pnpm run
test:run call causes the test to fail.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 95738494-354b-4bb3-876e-979cbd3ca4fb

📥 Commits

Reviewing files that changed from the base of the PR and between b695daa and 28aec87.

📒 Files selected for processing (6)
  • AGENTS.md
  • docs/ci-cd.md
  • docs/development-environment.md
  • docs/release-process.md
  • scripts/release.sh
  • scripts/release.test.mjs
🚧 Files skipped from review as they are similar to previous changes (1)
  • AGENTS.md

Comment thread scripts/release.test.mjs
Comment thread scripts/release.test.mjs
- Batch staged ESLint with safe argv/`--` instead of xargs (spaces/option-like paths).
- Spawn Vitest via `node vitest.mjs` with `shell: false` so Windows metacharacters stay literal.
- Require `check:environment` in release pre-flight; tighten release.test invocation match.
- Document cargo PATH prerequisite for path-gated sidecar stub checks.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/pre-commit.eslint-batch.test.mjs`:
- Around line 13-16: Strengthen the test around the hook’s ESLint invocations so
every invocation uses the safe `-- "$@"` argument boundary and no xargs-based
batching remains, regardless of spacing or options. Update the assertions in the
`it('batches eslint with -- so spaced/option-like paths stay literal', ...)`
test to inspect all matching invocations rather than accepting a single safe
match.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b784e00f-6635-4415-940a-46107db3eb8d

📥 Commits

Reviewing files that changed from the base of the PR and between 28aec87 and 81e8f32.

📒 Files selected for processing (8)
  • .githooks/pre-commit
  • docs/ci-cd.md
  • docs/release-process.md
  • scripts/pre-commit.eslint-batch.test.mjs
  • scripts/precommit-tests.mjs
  • scripts/precommit-tests.test.mjs
  • scripts/release.sh
  • scripts/release.test.mjs
🚧 Files skipped from review as they are similar to previous changes (6)
  • scripts/release.test.mjs
  • scripts/precommit-tests.test.mjs
  • scripts/release.sh
  • .githooks/pre-commit
  • docs/ci-cd.md
  • docs/release-process.md

Comment thread scripts/pre-commit.eslint-batch.test.mjs
Require all `pnpm exec eslint` lines to end with `-- "$@"` and reject any
xargs-based eslint batching, so a second unsafe invocation cannot slip through.
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant