Skip to content

Add integration tests for hook skip behavior#1428

Merged
j178 merged 1 commit intoj178:masterfrom
shaanmajid:test/no-git-diff-on-skipped-hooks
Jan 22, 2026
Merged

Add integration tests for hook skip behavior#1428
j178 merged 1 commit intoj178:masterfrom
shaanmajid:test/no-git-diff-on-skipped-hooks

Conversation

@shaanmajid
Copy link
Collaborator

@shaanmajid shaanmajid commented Jan 20, 2026

Add integration tests verifying that prek correctly identifies and reports skipped hooks in various scenarios.

Tests cover:

  • All hooks skipped due to no matching files
  • Dry run mode skipping all hooks
  • Mixed scenarios with both executed and skipped hooks
  • Skipped hooks across different priority groups

Includes regression test for #1335: verifies that git diff is not called to check for file modifications when all hooks in a priority group are skipped. Confirmed that test correctly fails without the fix.

Refs: #1327, #1335

@shaanmajid shaanmajid force-pushed the test/no-git-diff-on-skipped-hooks branch from 28de9a0 to 4df3cfb Compare January 20, 2026 18:00
@github-actions
Copy link

github-actions bot commented Jan 20, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (22.5 MiB → 22.5 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 71.9KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 60.0KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 55.1KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 35.1KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.8KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 30.0KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 21.6KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.3KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.3KiB         prek prek::hooks::meta_hooks::check_hooks_apply::{{closure}}
 0.1%   0.2% 18.3KiB         prek prek::hooks::meta_hooks::check_hooks_apply::{{closure}}
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
 0.1%   0.2% 17.7KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
36.6%  91.6%  8.2MiB              And 19789 smaller methods. Use -n N to show more.
40.0% 100.0%  9.0MiB              .text section size, the file size is 22.5MiB

Base Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 71.9KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 60.0KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 55.1KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.3KiB         prek prek::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.5% 42.7KiB         prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 35.1KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.8KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 30.0KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.2% 21.6KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.3KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.3KiB         prek prek::hooks::meta_hooks::check_hooks_apply::{{closure}}
 0.1%   0.2% 18.3KiB         prek prek::hooks::meta_hooks::check_hooks_apply::{{closure}}
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
 0.1%   0.2% 17.7KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
36.6%  91.6%  8.2MiB              And 19789 smaller methods. Use -n N to show more.
40.0% 100.0%  9.0MiB              .text section size, the file size is 22.5MiB

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.74%. Comparing base (edcf3d8) to head (6364002).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1428   +/-   ##
=======================================
  Coverage   90.74%   90.74%           
=======================================
  Files          82       82           
  Lines       16776    16776           
=======================================
  Hits        15224    15224           
  Misses       1552     1552           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shaanmajid shaanmajid force-pushed the test/no-git-diff-on-skipped-hooks branch 3 times, most recently from f08b056 to 4be2e42 Compare January 20, 2026 19:24
@shaanmajid shaanmajid changed the title test: add regression tests for skipped hooks behavior Add integration tests for hook skip behavior Jan 20, 2026
@shaanmajid shaanmajid marked this pull request as ready for review January 20, 2026 19:30

/// Skipped hooks across different priority groups (serial vs parallel).
#[test]
fn skipped_hooks_across_priority_groups() -> Result<()> {
Copy link
Owner

Choose a reason for hiding this comment

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

I don’t get what this test is about, nothing here seems parallel to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. I tried to actually add parallel hook testing but it didn't go great... it was pretty difficult/flaky to test, so I abandoned it.

I updated this to just test that priority groups work properly.

@shaanmajid
Copy link
Collaborator Author

shaanmajid commented Jan 21, 2026

Also consolidated two tests, and considerably simplified the regression test and made it cross-platform (removed #[cfg(unix)] gate) by switching to a tracing-based approach instead of the hacky approach I used prior.

@shaanmajid shaanmajid force-pushed the test/no-git-diff-on-skipped-hooks branch from 4be2e42 to aa878fa Compare January 21, 2026 16:06
Add integration tests verifying that prek correctly identifies and
reports skipped hooks in various scenarios.

Tests cover:
- All hooks skipped due to no matching files
- Dry run mode skipping all hooks
- Mixed scenarios with both executed and skipped hooks
- Skipped hooks across multiple priority groups

Includes regression test for j178#1335: verifies that `git diff` is only
called once (initial baseline) when all hooks skip, not once per
priority group. Uses tracing output to count `get_diff` calls.

Refs: j178#1327, j178#1335
@shaanmajid shaanmajid force-pushed the test/no-git-diff-on-skipped-hooks branch from aa878fa to 6364002 Compare January 21, 2026 16:16
@j178 j178 added the internal Internal changes label Jan 22, 2026
@j178
Copy link
Owner

j178 commented Jan 22, 2026

Thanks!

@j178 j178 merged commit 41e2b73 into j178:master Jan 22, 2026
22 checks passed
@shaanmajid shaanmajid deleted the test/no-git-diff-on-skipped-hooks branch January 22, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Internal changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants