Skip to content

Commit 9df6ce3

Browse files
committed
feat(run): check every input with vp run -v
The file check stops at the first changed file, so `'src/a.ts' modified` doesn't say whether reverting it is enough. With `-v`, every input of a miss is checked and the detailed summary lists every change, in dry runs too, and `--last-details` shows them afterwards. - A `FileCheck` (first file or all) follows `-v` from the session to the cache lookup. - The `cache.input` comparison and the search of the files the task read collect every change instead of stopping. The search stays parallel and unordered; a miss sorts its changes, so the output is stable. - An input that can't be checked fails the lookup only when nothing else changed, by the rule the tracked-env check already follows. Each change is its own result, so a folder entry whose name isn't a valid path doesn't hide the folder's other changes. - A listed folder reports every entry added or removed. With `-v`, a miss hashes every input instead of stopping at the first changed file. Without it, nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent af53a83 commit 9df6ce3

17 files changed

Lines changed: 527 additions & 135 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
- **Changed** A cache miss now lists every change to the command, the task's cache settings and the envs it depends on, instead of the first: when a task's `input` and `output` settings changed together, or a tracked env var and a file changed together, `vp run --verbose` and `vp run --last-details` show each change on its own line. Files are still checked only up to the first changed one. A summary saved by an earlier version can't be shown by `vp run --last-details` ([#961](https://github.com/voidzero-dev/vite-task/pull/961)).
3+
- **Changed** A cache miss now lists every change to the command, the task's cache settings and the envs it depends on, instead of the first: when a task's `input` and `output` settings changed together, or a tracked env var and a file changed together, `vp run --verbose` and `vp run --last-details` show each change on its own line. Without `-v`, files are checked only up to the first changed one; with `-v`, every input of a miss is checked, and every changed file is listed in path order. When the command, a setting or a `cache.env` var changed, only those changes are listed, since there's no cached run with the new ones to compare files with. A summary saved by an earlier version can't be shown by `vp run --last-details` ([#961](https://github.com/voidzero-dev/vite-task/pull/961), [#963](https://github.com/voidzero-dev/vite-task/pull/963)).
44
- **Added** `vp run --dry-run` shows what a run would do without running anything: each command's line with its cache status, and the summary, as a real run prints them. The cache is checked as in a real run, the remote cache included, and nothing is written: no cache entry, no downloaded or restored outputs, and no change to what `vp run --last-details` shows. With `-v`, the detailed summary shows why each command would miss. Like other `vp run` flags, `--dry-run` goes before the task name; after it, it's passed to the task ([#960](https://github.com/voidzero-dev/vite-task/pull/960)).
55
- **Changed** The helper files `vp run` writes to the system temp directory, such as the library that tracks file accesses and the JSON Schema that `vp run --json` points to, now share one folder that only the current user can write to, like `/tmp/vp_run-1000` on Linux, instead of a folder for each kind of file ([#974](https://github.com/voidzero-dev/vite-task/pull/974)).
66
- **Added** `vp run --json` prints every package and task in the workspace, with each task's `dependsOn` resolved to task IDs, as one JSON document for scripts, editors and coding agents. It runs nothing and, like `vp run` without a task, loads every package's config. It prints the same document from any directory in the workspace: indented in a terminal, on one line when captured. Its `$schema` field points to a JSON Schema that describes each field, which `vp run` writes to the system temp directory ([#948](https://github.com/voidzero-dev/vite-task/pull/948)).

‎crates/vt/src/cli/mod.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ pub struct RunFlags {
5757
#[clap(default_value = "false", long)]
5858
pub ignore_depends_on: bool,
5959

60-
/// Show full detailed summary after execution.
60+
/// Show full detailed summary after execution. A cache miss checks every
61+
/// input, so the summary lists every change.
6162
#[clap(default_value = "false", short = 'v', long)]
6263
pub verbose: bool,
6364

‎crates/vt/src/session/cache/mod.rs‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ pub enum CacheMiss {
153153
#[derive(Debug, Clone)]
154154
pub struct Comparison {
155155
/// Every difference found, sorted by kind, then by name or path, never
156-
/// empty. Command, config and env changes are complete. The file check
157-
/// stops at the first changed file it finds, so at most one file is
158-
/// listed.
156+
/// empty. Command, config and env changes are complete. Without `-v`, the
157+
/// file check stops at the first changed file it finds, so at most one
158+
/// file is listed.
159159
pub changes: Vec<Change>,
160160
}
161161

@@ -235,6 +235,15 @@ enum OrderName<'a> {
235235
Env(EnvName<&'a str>),
236236
}
237237

238+
/// How far a cache lookup checks a cached run's files.
239+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
240+
pub enum FileCheck {
241+
/// Stop at the first changed file, which is enough to know it's a miss.
242+
First,
243+
/// Check every file, so the miss lists every change (`vp run -v`).
244+
All,
245+
}
246+
238247
/// Where the cache records an env var.
239248
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
240249
pub enum EnvSource {
@@ -420,15 +429,18 @@ impl ExecutionCache {
420429
/// when `cancel_token` is cancelled.
421430
///
422431
/// A dry run (`RunKind::Dry`) writes nothing: a local hit isn't recorded,
423-
/// and a remote hit's archive isn't downloaded.
432+
/// and a remote hit's archive isn't downloaded. `file_check` says how many
433+
/// changed files a miss lists.
424434
#[tracing::instrument(level = "debug", skip_all)]
435+
#[expect(clippy::too_many_arguments, reason = "each argument is part of one lookup")]
425436
pub async fn try_hit(
426437
&self,
427438
cache_metadata: &CacheMetadata,
428439
globbed_inputs: &BTreeMap<RelativePathBuf, u64>,
429440
workspace_root: &AbsolutePath,
430441
cache_dir: &AbsolutePath,
431442
run_kind: RunKind,
443+
file_check: FileCheck,
432444
cancel_token: &CancellationToken,
433445
) -> anyhow::Result<Result<CacheHit, CacheMiss>> {
434446
let cache_key = CacheEntryKey::from_metadata(cache_metadata);
@@ -443,6 +455,7 @@ impl ExecutionCache {
443455
&input_negative_globs,
444456
workspace_root,
445457
run_kind,
458+
file_check,
446459
)
447460
.await?
448461
{
@@ -472,6 +485,7 @@ impl ExecutionCache {
472485
workspace_root,
473486
cache_dir,
474487
run_kind,
488+
file_check,
475489
cancel_token,
476490
)
477491
.await?
@@ -485,6 +499,7 @@ impl ExecutionCache {
485499
}))
486500
}
487501

502+
#[expect(clippy::too_many_arguments, reason = "forwarded from `try_hit`")]
488503
async fn try_hit_local(
489504
&self,
490505
cache_metadata: &CacheMetadata,
@@ -493,6 +508,7 @@ impl ExecutionCache {
493508
input_negative_globs: &PathGlobSet<'_>,
494509
workspace_root: &AbsolutePath,
495510
run_kind: RunKind,
511+
file_check: FileCheck,
496512
) -> anyhow::Result<Result<CacheEntryValue, CacheMiss>> {
497513
let execution_cache_key = &cache_metadata.execution_cache_key;
498514

@@ -503,6 +519,7 @@ impl ExecutionCache {
503519
globbed_inputs,
504520
input_negative_globs,
505521
workspace_root,
522+
file_check,
506523
)?;
507524
if !changes.is_empty() {
508525
return Ok(Err(CacheMiss::Changed(Comparison::new(changes))));
@@ -546,6 +563,7 @@ impl ExecutionCache {
546563
workspace_root: &AbsolutePath,
547564
cache_dir: &AbsolutePath,
548565
run_kind: RunKind,
566+
file_check: FileCheck,
549567
cancel_token: &CancellationToken,
550568
) -> anyhow::Result<Result<CacheEntryValue, CacheMiss>> {
551569
let fetched = self
@@ -558,6 +576,7 @@ impl ExecutionCache {
558576
globbed_inputs,
559577
input_negative_globs,
560578
workspace_root,
579+
file_check,
561580
)
562581
};
563582
let Restore { value: cache_value, blob_id } =

‎crates/vt/src/session/cache/remote.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ mod tests {
509509

510510
use super::*;
511511
use crate::session::{
512-
cache::InputChangeKind,
512+
cache::{FileCheck, InputChangeKind},
513513
execute::{
514514
fingerprint::{PostRunFingerprint, TrackedEnvQuery},
515515
pipe::{OutputKind, StdOutput},
@@ -608,6 +608,7 @@ mod tests {
608608
&globbed_inputs,
609609
&PathGlobSet::default(),
610610
&workspace_root,
611+
FileCheck::First,
611612
)
612613
}
613614
}

‎crates/vt/src/session/cache/validation.rs‎

Lines changed: 141 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,42 @@ use vt_glob::path::PathGlobSet;
88
use vt_path::{AbsolutePath, RelativePathBuf};
99
use vt_plan::cache_metadata::SpawnFingerprint;
1010

11-
use super::{CacheEntryKey, CacheEntryValue, Change, EnvMismatch, EnvSource, InputChangeKind};
11+
use super::{
12+
CacheEntryKey, CacheEntryValue, Change, EnvMismatch, EnvSource, FileCheck, InputChangeKind,
13+
};
1214

1315
impl CacheEntryValue {
1416
/// Compare the entry with the current execution: explicit inputs, then
1517
/// inferred inputs, and tracked environment values against
1618
/// `unfiltered_envs`, the execution's `CacheMetadata::unfiltered_envs`.
1719
/// `input_negative_globs`, compiled from the entry key's input config,
18-
/// leave entries out of listings. Returns every env change and the first
19-
/// changed file found, or nothing when the entry is valid.
20+
/// leave entries out of listings. Returns every env change and, with
21+
/// [`FileCheck::First`], the first changed file found, or with
22+
/// [`FileCheck::All`], every changed file. Nothing when the entry is valid.
2023
///
2124
/// # Errors
2225
///
2326
/// Propagates errors from post-run fingerprint validation. Once a file
24-
/// changed, the entry misses whatever the envs are, so an error comparing
25-
/// them only leaves the env changes out.
27+
/// changed, the entry misses whatever else changed, so an error checking
28+
/// the other files or the envs only leaves their changes out.
2629
pub(crate) fn validate(
2730
&self,
2831
unfiltered_envs: &FxHashMap<EnvName<Arc<OsStr>>, Arc<OsStr>>,
2932
globbed_inputs: &BTreeMap<RelativePathBuf, u64>,
3033
input_negative_globs: &PathGlobSet<'_>,
3134
workspace_root: &AbsolutePath,
35+
file_check: FileCheck,
3236
) -> anyhow::Result<Vec<Change>> {
33-
let mut changes: Vec<Change> =
34-
detect_globbed_input_change(&self.globbed_inputs, globbed_inputs).into_iter().collect();
35-
if changes.is_empty() {
36-
changes.extend(
37-
self.post_run_fingerprint
38-
.first_input_change(workspace_root, input_negative_globs)?,
37+
// Without `-v`, the first changed file is enough to know it's a miss.
38+
let limit = if file_check == FileCheck::First { 1 } else { usize::MAX };
39+
let mut changes = globbed_input_changes(&self.globbed_inputs, globbed_inputs, limit);
40+
if changes.is_empty() || file_check == FileCheck::All {
41+
let input_changes = self.post_run_fingerprint.input_changes(
42+
workspace_root,
43+
input_negative_globs,
44+
file_check,
3945
);
46+
add_checked(&mut changes, input_changes, "inferred inputs")?;
4047
}
4148
let env_changes = self.post_run_fingerprint.env_changes(unfiltered_envs);
4249
add_checked(&mut changes, env_changes, "tracked envs")?;
@@ -118,46 +125,52 @@ fn spawn_changes(old: &SpawnFingerprint, new: &SpawnFingerprint) -> Vec<Change>
118125
changes
119126
}
120127

121-
/// Compare stored and current globbed inputs, returning the first changed path.
122-
/// Both maps are `BTreeMap` so we iterate them in sorted lockstep.
123-
fn detect_globbed_input_change(
128+
/// Compare stored and current globbed inputs, returning the first `limit`
129+
/// changed paths, in path order. Both maps are `BTreeMap` so we iterate them
130+
/// in sorted lockstep.
131+
fn globbed_input_changes(
124132
stored: &BTreeMap<RelativePathBuf, u64>,
125133
current: &BTreeMap<RelativePathBuf, u64>,
126-
) -> Option<Change> {
134+
limit: usize,
135+
) -> Vec<Change> {
136+
let mut changes = Vec::new();
127137
let mut stored_iter = stored.iter();
128138
let mut current_iter = current.iter();
129139
let mut s = stored_iter.next();
130140
let mut c = current_iter.next();
141+
let change = |kind, path: &RelativePathBuf| Change::File { kind, path: path.clone() };
131142

132-
loop {
143+
while changes.len() < limit {
133144
match (s, c) {
134-
(None, None) => return None,
145+
(None, None) => break,
135146
(Some((sp, _)), None) => {
136-
return Some(Change::File { kind: InputChangeKind::Removed, path: sp.clone() });
147+
changes.push(change(InputChangeKind::Removed, sp));
148+
s = stored_iter.next();
137149
}
138150
(None, Some((cp, _))) => {
139-
return Some(Change::File { kind: InputChangeKind::Added, path: cp.clone() });
151+
changes.push(change(InputChangeKind::Added, cp));
152+
c = current_iter.next();
140153
}
141154
(Some((sp, sh)), Some((cp, ch))) => match sp.cmp(cp) {
142155
std::cmp::Ordering::Equal => {
143156
if sh != ch {
144-
return Some(Change::File {
145-
kind: InputChangeKind::ContentModified,
146-
path: sp.clone(),
147-
});
157+
changes.push(change(InputChangeKind::ContentModified, sp));
148158
}
149159
s = stored_iter.next();
150160
c = current_iter.next();
151161
}
152162
std::cmp::Ordering::Less => {
153-
return Some(Change::File { kind: InputChangeKind::Removed, path: sp.clone() });
163+
changes.push(change(InputChangeKind::Removed, sp));
164+
s = stored_iter.next();
154165
}
155166
std::cmp::Ordering::Greater => {
156-
return Some(Change::File { kind: InputChangeKind::Added, path: cp.clone() });
167+
changes.push(change(InputChangeKind::Added, cp));
168+
c = current_iter.next();
157169
}
158170
},
159171
}
160172
}
173+
changes
161174
}
162175

163176
#[cfg(test)]
@@ -204,7 +217,13 @@ mod tests {
204217
)]);
205218
let workspace_root = vt_path::current_dir().unwrap();
206219
let validate = |inputs| {
207-
value.validate(&unfiltered_envs, &inputs, &PathGlobSet::default(), &workspace_root)
220+
value.validate(
221+
&unfiltered_envs,
222+
&inputs,
223+
&PathGlobSet::default(),
224+
&workspace_root,
225+
FileCheck::First,
226+
)
208227
};
209228

210229
assert!(validate(BTreeMap::from([(path.clone(), 1)])).is_err());
@@ -238,7 +257,13 @@ mod tests {
238257
]);
239258
let workspace_root = vt_path::current_dir().unwrap();
240259
let changes = value
241-
.validate(&unfiltered_envs, &BTreeMap::new(), &PathGlobSet::default(), &workspace_root)
260+
.validate(
261+
&unfiltered_envs,
262+
&BTreeMap::new(),
263+
&PathGlobSet::default(),
264+
&workspace_root,
265+
FileCheck::First,
266+
)
242267
.unwrap();
243268
assert_eq!(
244269
changes,
@@ -248,4 +273,93 @@ mod tests {
248273
}]
249274
);
250275
}
276+
277+
/// Without `-v`, the file check stops at the first changed explicit
278+
/// input; with it, every one is listed in path order.
279+
#[test]
280+
fn every_changed_explicit_input_is_listed_when_checking_all() {
281+
let rel = |path| RelativePathBuf::new(path).unwrap();
282+
let value = CacheEntryValue {
283+
post_run_fingerprint: PostRunFingerprint::default(),
284+
std_outputs: Arc::new([]),
285+
duration: Duration::ZERO,
286+
globbed_inputs: BTreeMap::from([(rel("a.txt"), 1), (rel("b.txt"), 1)]),
287+
output_archive: None,
288+
};
289+
let current = BTreeMap::from([(rel("a.txt"), 2), (rel("c.txt"), 1)]);
290+
let workspace_root = vt_path::current_dir().unwrap();
291+
let validate = |file_check| {
292+
value
293+
.validate(
294+
&FxHashMap::default(),
295+
&current,
296+
&PathGlobSet::default(),
297+
&workspace_root,
298+
file_check,
299+
)
300+
.unwrap()
301+
};
302+
let file = |kind, path| Change::File { kind, path: rel(path) };
303+
304+
assert_eq!(validate(FileCheck::First), [file(InputChangeKind::ContentModified, "a.txt")]);
305+
assert_eq!(
306+
validate(FileCheck::All),
307+
[
308+
file(InputChangeKind::ContentModified, "a.txt"),
309+
file(InputChangeKind::Removed, "b.txt"),
310+
file(InputChangeKind::Added, "c.txt"),
311+
]
312+
);
313+
}
314+
315+
/// With `-v`, a listed folder that gains a valid entry and one whose name
316+
/// isn't a valid path keeps the valid one: it's a miss, not a failed
317+
/// lookup. Only Unix allows a `\` in a file name, so only Unix can test it.
318+
#[cfg(unix)]
319+
#[test]
320+
fn folder_entry_that_cannot_be_named_keeps_the_others() {
321+
use crate::session::execute::fingerprint::{DirListing, InferredInput, PathFingerprint};
322+
323+
let tmp = tempfile::TempDir::new().unwrap();
324+
let workspace_root = vt_path::AbsolutePathBuf::new(tmp.path().to_path_buf()).unwrap();
325+
std::fs::create_dir(workspace_root.join("dir").as_path()).unwrap();
326+
std::fs::write(workspace_root.join("dir/a.txt").as_path(), "x").unwrap();
327+
std::fs::write(workspace_root.join("dir/a\\b").as_path(), "x").unwrap();
328+
let rel = |path| RelativePathBuf::new(path).unwrap();
329+
let listing = DirListing {
330+
entries: BTreeMap::new(),
331+
ignored_entries: std::collections::BTreeSet::new(),
332+
};
333+
let value = CacheEntryValue {
334+
post_run_fingerprint: PostRunFingerprint {
335+
inferred_inputs: crate::collections::HashMap::from_iter([(
336+
rel("dir"),
337+
InferredInput {
338+
fingerprint: PathFingerprint::Folder(Some(listing)),
339+
may_be_missing: false,
340+
},
341+
)]),
342+
..PostRunFingerprint::default()
343+
},
344+
std_outputs: Arc::new([]),
345+
duration: Duration::ZERO,
346+
globbed_inputs: BTreeMap::new(),
347+
output_archive: None,
348+
};
349+
let validate = |file_check| {
350+
value.validate(
351+
&FxHashMap::default(),
352+
&BTreeMap::new(),
353+
&PathGlobSet::default(),
354+
&workspace_root,
355+
file_check,
356+
)
357+
};
358+
359+
let changes = validate(FileCheck::All).unwrap();
360+
assert_eq!(
361+
changes,
362+
[Change::File { kind: InputChangeKind::Added, path: rel("dir/a.txt") }]
363+
);
364+
}
251365
}

0 commit comments

Comments
 (0)