From 456be63c311a648fadca0cf2c430202b6d0a3ebb Mon Sep 17 00:00:00 2001 From: MatthewMckee4 Date: Sun, 1 Feb 2026 13:34:43 +0000 Subject: [PATCH] Add --no-cache flag to disable reading cache Add a new --no-cache flag that skips reading historical test durations from the karva cache when partitioning tests. This is useful when you want fresh partitioning without being influenced by previous run times. Closes #394 Co-Authored-By: Claude Opus 4.5 --- crates/karva/src/lib.rs | 6 +++++- crates/karva_benchmark/src/walltime.rs | 5 ++++- crates/karva_cli/src/lib.rs | 4 ++++ crates/karva_runner/src/orchestration.rs | 7 ++++++- docs/cli.md | 1 + 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/karva/src/lib.rs b/crates/karva/src/lib.rs index 358b2f7b..cb2cc095 100644 --- a/crates/karva/src/lib.rs +++ b/crates/karva/src/lib.rs @@ -103,6 +103,7 @@ pub(crate) fn test(args: TestCommand) -> Result { let sub_command = args.sub_command.clone(); let no_parallel = args.no_parallel.unwrap_or(false); + let no_cache = args.no_cache.unwrap_or(false); let num_workers = args.num_workers; let project_options_overrides = ProjectOptionsOverrides::new(config_file, args.into_options()); @@ -116,7 +117,10 @@ pub(crate) fn test(args: TestCommand) -> Result { num_workers.unwrap_or_else(|| karva_system::max_parallelism().get()) }; - let config = karva_runner::ParallelTestConfig { num_workers }; + let config = karva_runner::ParallelTestConfig { + num_workers, + no_cache, + }; let (shutdown_tx, shutdown_rx) = crossbeam_channel::unbounded(); diff --git a/crates/karva_benchmark/src/walltime.rs b/crates/karva_benchmark/src/walltime.rs index a66421b7..b3a3a70a 100644 --- a/crates/karva_benchmark/src/walltime.rs +++ b/crates/karva_benchmark/src/walltime.rs @@ -59,7 +59,10 @@ impl<'a> ProjectBenchmark<'a> { fn test_project(project: &ProjectDatabase) { let num_workers = karva_system::max_parallelism().get(); - let config = karva_runner::ParallelTestConfig { num_workers }; + let config = karva_runner::ParallelTestConfig { + num_workers, + no_cache: false, + }; let args = SubTestCommand { no_ignore: Some(true), diff --git a/crates/karva_cli/src/lib.rs b/crates/karva_cli/src/lib.rs index 560bccff..905b5541 100644 --- a/crates/karva_cli/src/lib.rs +++ b/crates/karva_cli/src/lib.rs @@ -160,6 +160,10 @@ pub struct TestCommand { /// Disable parallel execution #[clap(long, default_missing_value = "true", num_args=0..1)] pub no_parallel: Option, + + /// Disable reading the karva cache for test duration history + #[clap(long, default_missing_value = "true", num_args=0..1)] + pub no_cache: Option, } impl TestCommand { diff --git a/crates/karva_runner/src/orchestration.rs b/crates/karva_runner/src/orchestration.rs index 873281c8..06150cc6 100644 --- a/crates/karva_runner/src/orchestration.rs +++ b/crates/karva_runner/src/orchestration.rs @@ -117,6 +117,7 @@ impl WorkerManager { pub struct ParallelTestConfig { pub num_workers: usize, + pub no_cache: bool, } /// Spawn worker processes for each partition @@ -216,7 +217,11 @@ pub fn run_parallel_tests( let cache_dir = db.system().current_directory().join(CACHE_DIR); // Read durations from the most recent run to optimize partitioning - let previous_durations = read_recent_durations(&cache_dir).unwrap_or_default(); + let previous_durations = if config.no_cache { + std::collections::HashMap::new() + } else { + read_recent_durations(&cache_dir).unwrap_or_default() + }; if !previous_durations.is_empty() { tracing::debug!( diff --git a/docs/cli.md b/docs/cli.md index 45ed9425..dd55900c 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -47,6 +47,7 @@ karva test [OPTIONS] [PATH]...

May also be set with the KARVA_CONFIG_FILE environment variable.

--fail-fast

When set, the test will fail immediately if any test fails.

This only works when running tests in parallel.

--help, -h

Print help (see a summary with '-h')

+
--no-cache

Disable reading the karva cache for test duration history

--no-ignore

When set, .gitignore files will not be respected

--no-parallel

Disable parallel execution

--no-progress

When set, we will not show individual test case results during execution