diff --git a/CHANGELOG.md b/CHANGELOG.md index d9d39790c..faf60a633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog +- **Fixed** Deleting a file that a task reads, rewrites, and reports with `ignoreOutput` now makes `vp run` miss the cache when the read is still tracked, so the task recomputes its outputs ([#1025](https://github.com/voidzero-dev/vite-task/pull/1025)). - **Changed** When automatic file-access tracking cannot record everything a task did, the "Not cached" summary line now includes the specific reason (for example, that the tracking channel ran out of capacity or that installing the seccomp filter failed for a given executable) ([#1054](https://github.com/voidzero-dev/vite-task/pull/1054), [#1056](https://github.com/voidzero-dev/vite-task/pull/1056)). - **Changed** Invalid remote cache endpoint URLs in `cache.remote.url` or `VP_REMOTE_CACHE_URL` (such as missing schemes, non-`http`/`https` schemes, or missing hosts) now fail upfront during configuration and planning instead of warning per task during execution, and `vp run --help` now documents `VP_REMOTE_CACHE`, `VP_REMOTE_CACHE_URL`, and `VP_REMOTE_CACHE_HEADER_` ([#1048](https://github.com/voidzero-dev/vite-task/pull/1048)). - **Changed** Removed `NEXT_*`, `VERCEL`, `VERCEL_*`, `USE_OUTPUT_FOR_EDGE_FUNCTIONS`, `NOW_BUILDER`, `VC_MICROFRONTENDS_CONFIG_FILE_NAME`, `GITHUB_*`, `ACTIONS_ID_TOKEN_REQUEST_URL`, `DOCKER_*`, `BUILDKIT_*`, `COMPOSE_*`, and `*_TOKEN` from the default untracked environment variables passed to cached tasks. Tasks that need any of these variables should declare them explicitly in `cache.env` or `cache.untrackedEnv` ([#1044](https://github.com/voidzero-dev/vite-task/pull/1044)). diff --git a/crates/vt/src/session/cache/mod.rs b/crates/vt/src/session/cache/mod.rs index 49908b24f..f1f1f67d6 100644 --- a/crates/vt/src/session/cache/mod.rs +++ b/crates/vt/src/session/cache/mod.rs @@ -470,7 +470,7 @@ pub fn split_path(path: &str) -> (Option<&str>, &str) { /// its own cache warm across branch switches, and a cache from a different /// version is simply ignored (it lives in a directory this build never looks /// at) rather than aborting the run. Bumping the version starts a fresh cache. -const CACHE_SCHEMA_VERSION: u32 = 24; +const CACHE_SCHEMA_VERSION: u32 = 25; /// Name of the per-version subdirectory (e.g. `v14`) under the task-cache /// directory that holds the database and output archives for the current diff --git a/crates/vt/src/session/execute/cache_update.rs b/crates/vt/src/session/execute/cache_update.rs index 3eea2d3ef..52c258c5a 100644 --- a/crates/vt/src/session/execute/cache_update.rs +++ b/crates/vt/src/session/execute/cache_update.rs @@ -43,9 +43,6 @@ struct TrackingOutcome { /// archived as folders: all of them when `output_config.includes_auto`, /// otherwise those a positive output glob matches. empty_folders: FxHashSet, - /// What the task can rebuild, from every write, rename target and mkdir - /// fspy recorded before output exclusions and `ignoreOutput` paths are - /// applied, with the files under a renamed folder in place of the folder. rebuildable: Rebuildable, } @@ -207,9 +204,9 @@ pub(super) async fn update_cache( /// /// `path_reads` is gated on `input_config.includes_auto`, filtered by /// user-configured input negatives, and by tool-reported `ignoreInput` paths. -/// `rebuildable` takes every write, rename target and mkdir unfiltered, since -/// what the task can rebuild doesn't depend on what is archived, and expands -/// renamed folders into the files under them. `path_writes` and +/// `rebuildable` uses writes and mkdirs, including files under renamed +/// folders as writes. A write covered by `ignoreOutput` is left out of +/// `rebuildable` if it is still in `path_reads`. `path_writes` and /// `empty_folders` are its written files and empty folders filtered by /// user-configured output negatives and tool-reported `ignoreOutput` paths, /// which decide what is archived; `path_writes` is gated on @@ -230,17 +227,10 @@ fn observe_fspy( ) -> Option { #[cfg(fspy)] { - use super::tracked_accesses::TrackedPathAccesses; + use super::{rebuildable::files_written, tracked_accesses::TrackedPathAccesses}; path_accesses.map(|raw| { let tracked = TrackedPathAccesses::from_raw(raw, workspace_root, cache_root); - let mut rebuildable = Rebuildable::new( - tracked.path_writes, - tracked.rename_targets, - tracked.mkdirs, - workspace_root, - cache_root, - ); let filtered_path_reads: HashMap = // fspy can be attached for auto-output-only tasks. In that // mode reads must not become inferred inputs. @@ -259,6 +249,27 @@ fn observe_fspy( } else { HashMap::default() }; + let mut written = files_written( + tracked.path_writes, + tracked.rename_targets, + workspace_root, + cache_root, + ); + let mut mkdirs = tracked.mkdirs; + let required_writes = if ignored_output_rels.is_empty() { + FxHashSet::default() + } else { + written + .extract_if(|path| { + filtered_path_reads.contains_key(path) + && is_ignored(path, ignored_output_rels) + }) + .collect() + }; + for path in &required_writes { + mkdirs.remove(path); + } + let rebuildable = Rebuildable::from_written(written, mkdirs); let filter_outputs = |paths: &FxHashSet| { let Some(fspy) = fspy else { return FxHashSet::default(); @@ -275,10 +286,10 @@ fn observe_fspy( // Only fingerprints of the paths the task read ask about folders; // without them, the archive still takes the empty folders the // task made. - rebuildable = if filtered_path_reads.is_empty() { + let rebuildable = if filtered_path_reads.is_empty() { rebuildable.with_empty_folders(workspace_root, cache_root) } else { - rebuildable.with_folders(workspace_root, cache_root) + rebuildable.with_folders_excluding(workspace_root, cache_root, &required_writes) }; TrackingOutcome { path_reads: filtered_path_reads, diff --git a/crates/vt/src/session/execute/rebuildable.rs b/crates/vt/src/session/execute/rebuildable.rs index 67d743289..5f0431cb8 100644 --- a/crates/vt/src/session/execute/rebuildable.rs +++ b/crates/vt/src/session/execute/rebuildable.rs @@ -1,34 +1,34 @@ //! What a task can rebuild, so a later run may find it missing. //! -//! Inputs are fingerprinted as the task left them, so they include the files -//! a task read and then wrote, such as a tool's cache file. A clean checkout -//! (CI, a fresh clone) doesn't have those files yet, and running the task -//! would write them again, so a later run may find them missing. A file that -//! is there must still be as the task left it. +//! Inputs are fingerprinted as the task left them, including files it read +//! and then wrote. A rebuildable file may be missing on a later run, as on +//! a clean checkout. A file that is there must still match the fingerprint. //! -//! The same goes for an empty folder the task made (built-in ignored paths -//! such as `.DS_Store` aside), and for a folder that holds only what the task -//! can rebuild: every file (or symlink) in it is one the task wrote, and every -//! folder in it is rebuildable too. None of these is fingerprinted at all. A hit -//! restores the files and the empty folders, which are archived as folders, if -//! they're among the task's outputs, and the files recreate the folders holding -//! them; explicit output config can leave them out. Such folders are found after -//! the run by climbing from the written paths and the empty folders through -//! their parent folders inside the workspace, listing each one once in the real -//! file system. A written path or folder that is gone by then plays no part. A -//! listing of any other folder leaves out its entries that the task can rebuild, -//! which a later run may find missing too. +//! A folder is rebuildable when the task made it and it is empty, or when it +//! contains at least one entry and all entries are rebuildable. Both checks +//! skip built-in ignored entries such as `.DS_Store`. None of these is +//! fingerprinted at all. A hit restores the files and the empty folders, which +//! are archived as folders, if they're among the task's outputs, and the files +//! recreate the folders holding them; explicit output config can leave them +//! out. Such folders are found after the run by climbing from the written +//! paths and the empty folders through their parent folders inside the +//! workspace, listing each one once in the real file system. A written path or +//! folder that is gone by then plays no part. A listing of any other folder +//! leaves out its entries that the task can rebuild, which a later run may +//! find missing too. //! -//! The written paths are fspy's records before output exclusions and -//! tool-reported `ignoreOutput` paths are applied: those decide what is -//! archived, not what the task can rebuild. A rename target that is a folder -//! after the run, like Vite's `deps` folder renamed into place, stands for -//! writes of every file (and symlink) under it; the folder itself and the -//! folders in it don't count as written. The archive takes those files like -//! any written file. The rename's source, like Vite's `deps_temp_*` folder, -//! isn't recorded, but a path that is gone after the run and that the task -//! wrote in counts as written: the task made or removed it. It is -//! fingerprinted as missing, which a later run must match either way, so this +//! The written paths come from fspy. A file the task reads and writes is a +//! required input when `ignoreOutput` covers it and the read survives input +//! filtering. Its absence makes the next run miss. Output negative globs +//! only decide what is archived. +//! +//! A rename target that is a folder after the run, like Vite's `deps` folder +//! renamed into place, stands for writes of every file (and symlink) under +//! it. The folder itself and the folders in it don't count as written. +//! The archive takes those files like any written file. The rename's source, +//! like Vite's `deps_temp_*` folder, isn't recorded. A path that is gone after +//! the run counts as written if the task wrote in it. It is fingerprinted +//! as missing, which a later run must match either way, so this //! only tells it apart from a path the task looked for and didn't find. A //! write record on a path that is a folder, from opening it with write //! access, is ignored. A mkdir record counts only for a folder that is empty @@ -45,12 +45,12 @@ use vt_path::{AbsolutePath, RelativePath, RelativePathBuf}; use super::{fingerprint::PathFingerprint, ignored_paths::IgnoredDirEntries}; -/// The paths a task wrote, the empty folders it made, and the folders -/// holding only what it can rebuild, relative to the workspace root. +/// The rebuildable paths a task wrote, the empty folders it made, and the +/// folders holding only what it can rebuild, relative to the workspace root. #[derive(Debug, Default)] pub struct Rebuildable { written: FxHashSet, - /// The folders the task made, or tried to make, inside the workspace. + /// The folders the task made or tried to make, excluding required paths. mkdirs: FxHashSet, /// The `mkdirs` that are empty folders. empty_folders: FxHashSet, @@ -61,19 +61,17 @@ pub struct Rebuildable { } impl Rebuildable { - /// Takes the `written` paths and the `rename_targets` as written, with the - /// files under a renamed folder in place of the folder, by looking under - /// `workspace_root`, which must be done after the run, and the `mkdirs`. + /// Takes the rebuildable `written` paths and `mkdirs`. /// No folder is rebuildable, and none of the `mkdirs` is an empty folder, - /// until [`Self::with_folders`] or [`Self::with_empty_folders`] finds them. - pub fn new( + /// until [`Self::with_folders_excluding`] or [`Self::with_empty_folders`] finds them. + #[cfg_attr( + all(not(fspy), not(test)), + expect(dead_code, reason = "only called when processing fspy path accesses") + )] + pub(super) fn from_written( written: FxHashSet, - rename_targets: FxHashSet, mkdirs: FxHashSet, - workspace_root: &AbsolutePath, - cache_root: Option<&RelativePath>, ) -> Self { - let written = files_written(written, rename_targets, workspace_root, cache_root); let mut written_in = FxHashSet::default(); for path in &written { let mut dir = path.parent(); @@ -100,14 +98,19 @@ impl Rebuildable { /// the task made under `workspace_root`, which must be done after the run. /// Only fingerprints of the paths the task read ask about folders, so a /// run without such reads takes [`Self::with_empty_folders`] instead. + #[cfg_attr( + all(not(fspy), not(test)), + expect(dead_code, reason = "only called when processing fspy path accesses") + )] #[must_use] - pub fn with_folders( + pub(super) fn with_folders_excluding( mut self, workspace_root: &AbsolutePath, cache_root: Option<&RelativePath>, + required_writes: &FxHashSet, ) -> Self { (self.folders, self.empty_folders) = - find_folders(&self.written, &self.mkdirs, workspace_root, cache_root); + find_folders(&self.written, required_writes, &self.mkdirs, workspace_root, cache_root); self } @@ -129,8 +132,8 @@ impl Rebuildable { self } - /// The paths the task wrote or renamed a file to, and the files under the - /// folders it renamed. + /// The rebuildable paths the task wrote or renamed a file to, and the + /// rebuildable files under the folders it renamed. pub const fn written(&self) -> &FxHashSet { &self.written } @@ -141,12 +144,12 @@ impl Rebuildable { &self.empty_folders } - /// Whether a later run may find `path`, which a read found as - /// `fingerprint`, missing: the task wrote it, or it is gone after the run - /// and the task wrote in it. A write record on a folder, from opening it - /// with write access, is ignored. Only a written path that the read found - /// as a folder is stat'd under `workspace_root`, to tell a folder from a - /// link the task made to one. + /// Whether a later run may find the path missing. A rebuildable write + /// allows this. A post-run `NotFound` also allows it if the task has a + /// rebuildable write below the path. A write record on a folder, from + /// opening it with write access, is ignored. Only a written path that the + /// read found as a folder is stat'd under `workspace_root`, to tell a + /// folder from a link the task made to one. pub fn may_be_missing( &self, path: &RelativePath, @@ -195,7 +198,11 @@ impl Rebuildable { /// under it counts, folder entries are checked against the rebuildable /// folders, and the archive skips folders, so only a read of it has to tell /// (see [`Rebuildable::may_be_missing`]). -fn files_written( +#[cfg_attr( + all(not(fspy), not(test)), + expect(dead_code, reason = "only called when processing fspy path accesses") +)] +pub(super) fn files_written( mut written: FxHashSet, rename_targets: FxHashSet, workspace_root: &AbsolutePath, @@ -276,8 +283,11 @@ fn is_empty_folder( /// candidates too. Climbing stops at the first folder that isn't rebuildable, /// since no folder above it can be, and at the workspace root. A folder that /// is gone plays no part: its parent is decided by the entries it holds. +/// Required writes are skipped so a tracked directory link stays required +/// even if the task wrote through it. fn find_folders( written: &FxHashSet, + required_writes: &FxHashSet, mkdirs: &FxHashSet, workspace_root: &AbsolutePath, cache_root: Option<&RelativePath>, @@ -300,7 +310,8 @@ fn find_folders( empty_folders.insert(dir.to_relative_path_buf()); } } - let mut candidates: Vec<&RelativePath> = candidates.into_iter().collect(); + let mut candidates: Vec<&RelativePath> = + candidates.into_iter().filter(|dir| !required_writes.contains(*dir)).collect(); sort_deepest_first(&mut candidates); let mut folders = empty_folders.clone(); @@ -351,8 +362,7 @@ fn sort_deepest_first(dirs: &mut [&RelativePath]) { /// aside, which don't count, as in directory listing fingerprints. enum Holds { Nothing, - /// At least one entry, each a file (or symlink) the task wrote or a - /// rebuildable folder. + /// At least one entry, with every entry rebuildable. OnlyRebuildable, /// Anything else, or entries that can't be read or named. Other, @@ -415,3 +425,27 @@ fn is_rebuildable( ) -> bool { if is_dir { folders.contains(path) } else { written.contains(path) } } + +#[cfg(test)] +impl Rebuildable { + pub(super) fn new( + written: FxHashSet, + rename_targets: FxHashSet, + mkdirs: FxHashSet, + workspace_root: &AbsolutePath, + cache_root: Option<&RelativePath>, + ) -> Self { + Self::from_written( + files_written(written, rename_targets, workspace_root, cache_root), + mkdirs, + ) + } + + pub(super) fn with_folders( + self, + workspace_root: &AbsolutePath, + cache_root: Option<&RelativePath>, + ) -> Self { + self.with_folders_excluding(workspace_root, cache_root, &FxHashSet::default()) + } +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/ignored-cache.mjs b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/ignored-cache.mjs new file mode 100644 index 000000000..7ad904943 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/ignored-cache.mjs @@ -0,0 +1,14 @@ +import { mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; +import { ignoreInput, ignoreOutput } from '@voidzero-dev/vite-task-client'; + +const cacheDir = 'tool/cache'; +const statePath = `${cacheDir}/state.txt`; + +mkdirSync(cacheDir, { recursive: true }); +readdirSync('tool'); +readdirSync('.'); + +writeFileSync(statePath, 'seed'); +readFileSync(statePath, 'utf8'); +if (process.argv[2] !== 'input-negative') ignoreInput(cacheDir); +ignoreOutput(cacheDir); diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/package.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/package.json new file mode 100644 index 000000000..ba7cadc61 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/package.json @@ -0,0 +1,4 @@ +{ + "name": "ignore-output-rebuildable-inputs", + "private": true +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/read-link.mjs b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/read-link.mjs new file mode 100644 index 000000000..19746d21a --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/read-link.mjs @@ -0,0 +1,12 @@ +import { existsSync, mkdirSync, readdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'; +import { ignoreOutput } from '@voidzero-dev/vite-task-client'; + +const present = existsSync('alias'); +if (present) readdirSync('alias'); + +mkdirSync('real', { recursive: true }); +rmSync('alias', { recursive: true, force: true }); +symlinkSync('real', 'alias', 'junction'); +writeFileSync('alias/child.txt', 'output\n'); +ignoreOutput('alias'); +writeFileSync('result.txt', present ? 'present\n' : 'missing\n'); diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/read-state.mjs b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/read-state.mjs new file mode 100644 index 000000000..bc006d22e --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/read-state.mjs @@ -0,0 +1,10 @@ +import { existsSync, readFileSync, writeFileSync } from 'node:fs'; +import { ignoreOutput } from '@voidzero-dev/vite-task-client'; + +const state = existsSync('state.json') + ? JSON.parse(readFileSync('state.json', 'utf8')) + : { value: 'missing' }; + +ignoreOutput('state.json'); +writeFileSync('state.json', JSON.stringify(state) + '\n'); +writeFileSync('result.json', JSON.stringify({ read: state.value }) + '\n'); diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots.toml b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots.toml new file mode 100644 index 000000000..b71a7abce --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots.toml @@ -0,0 +1,151 @@ +[[e2e]] +name = "ignore_output_keeps_tracked_read_required" +ignore = true +steps = [ + [ + "vtt", + "write-file", + "state.json", + '{"value":"original"}', + ], + [ + "vt", + "run", + "read-state", + ], + [ + "vtt", + "rm", + "state.json", + "result.json", + ], + [ + "vt", + "run", + "read-state", + ], + [ + "vtt", + "print-file", + "result.json", + ], +] + +[[e2e]] +name = "ignore_output_keeps_required_directory_link" +comment = """ +The task lists a directory link, recreates it, and writes a file through it. Deleting the tracked link makes the task rerun. +""" +ignore = true +steps = [ + [ + "node", + "read-link.mjs", + ], + [ + "vt", + "run", + "read-link", + ], + [ + "vtt", + "rm", + "-r", + "alias", + "result.txt", + ], + [ + "vt", + "run", + "read-link", + ], + [ + "vtt", + "print-file", + "result.txt", + ], +] + +[[e2e]] +name = "ignore_output_keeps_ignored_input_cache_rebuildable" +comment = """ +The task reads and writes files under `tool/cache` and reports the cache folder with both `ignoreInput` and `ignoreOutput`. It lists `tool` and the workspace root. Removing `tool` simulates a clean checkout and removes an entry from the root listing. +""" +ignore = true +steps = [ + [ + "vt", + "run", + "ignore-cache", + ], + [ + "vtt", + "rm", + "-r", + "tool", + ], + [ + "vt", + "run", + "ignore-cache", + ], + [ + "vtt", + "stat-file", + "tool/cache", + ], +] + +[[e2e]] +name = "ignore_output_keeps_glob_excluded_input_cache_rebuildable" +comment = """ +The task reports only `ignoreOutput` for `tool/cache`. An input negative glob excludes the cache file it reads and writes, so `tool` can still be rebuilt. +""" +ignore = true +steps = [ + [ + "vt", + "run", + "exclude-cache-input", + ], + [ + "vtt", + "rm", + "-r", + "tool", + ], + [ + "vt", + "run", + "exclude-cache-input", + ], +] + +[[e2e]] +name = "ignore_output_keeps_write_only_file_out_of_listing" +comment = """ +The task lists the workspace and writes `scratch.txt` without reading it. It reports the file with `ignoreOutput`, so a hit leaves the file missing. +""" +ignore = true +steps = [ + [ + "vt", + "run", + "write-only", + ], + [ + "vtt", + "rm", + "scratch.txt", + ], + [ + "vt", + "run", + "write-only", + ], + [ + "vtt", + "stat-file", + "scratch.txt", + ], +] diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_glob_excluded_input_cache_rebuildable.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_glob_excluded_input_cache_rebuildable.md new file mode 100644 index 000000000..89ddf25ce --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_glob_excluded_input_cache_rebuildable.md @@ -0,0 +1,23 @@ +# ignore_output_keeps_glob_excluded_input_cache_rebuildable + +The task reports only `ignoreOutput` for `tool/cache`. An input negative glob excludes the cache file it reads and writes, so `tool` can still be rebuilt. + +## `vt run exclude-cache-input` + +``` +$ node ignored-cache.mjs input-negative +``` + +## `vtt rm -r tool` + +``` +``` + +## `vt run exclude-cache-input` + +``` +$ node ignored-cache.mjs input-negative ◉ cache hit, replaying + +--- +vt run: cache hit. +``` diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_ignored_input_cache_rebuildable.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_ignored_input_cache_rebuildable.md new file mode 100644 index 000000000..1f5454b04 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_ignored_input_cache_rebuildable.md @@ -0,0 +1,29 @@ +# ignore_output_keeps_ignored_input_cache_rebuildable + +The task reads and writes files under `tool/cache` and reports the cache folder with both `ignoreInput` and `ignoreOutput`. It lists `tool` and the workspace root. Removing `tool` simulates a clean checkout and removes an entry from the root listing. + +## `vt run ignore-cache` + +``` +$ node ignored-cache.mjs +``` + +## `vtt rm -r tool` + +``` +``` + +## `vt run ignore-cache` + +``` +$ node ignored-cache.mjs ◉ cache hit, replaying + +--- +vt run: cache hit. +``` + +## `vtt stat-file tool/cache` + +``` +tool/cache: missing +``` diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_required_directory_link.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_required_directory_link.md new file mode 100644 index 000000000..36d8ae214 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_required_directory_link.md @@ -0,0 +1,31 @@ +# ignore_output_keeps_required_directory_link + +The task lists a directory link, recreates it, and writes a file through it. Deleting the tracked link makes the task rerun. + +## `node read-link.mjs` + +``` +``` + +## `vt run read-link` + +``` +$ node read-link.mjs +``` + +## `vtt rm -r alias result.txt` + +``` +``` + +## `vt run read-link` + +``` +$ node read-link.mjs ○ cache miss: 'alias' removed from workspace root, executing +``` + +## `vtt print-file result.txt` + +``` +missing +``` diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_tracked_read_required.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_tracked_read_required.md new file mode 100644 index 000000000..7974974a1 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_tracked_read_required.md @@ -0,0 +1,29 @@ +# ignore_output_keeps_tracked_read_required + +## `vtt write-file state.json '{"value":"original"}'` + +``` +``` + +## `vt run read-state` + +``` +$ node read-state.mjs +``` + +## `vtt rm state.json result.json` + +``` +``` + +## `vt run read-state` + +``` +$ node read-state.mjs ○ cache miss: 'state.json' removed from workspace root, executing +``` + +## `vtt print-file result.json` + +``` +{"read":"missing"} +``` diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_write_only_file_out_of_listing.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_write_only_file_out_of_listing.md new file mode 100644 index 000000000..83bdcd337 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/snapshots/ignore_output_keeps_write_only_file_out_of_listing.md @@ -0,0 +1,29 @@ +# ignore_output_keeps_write_only_file_out_of_listing + +The task lists the workspace and writes `scratch.txt` without reading it. It reports the file with `ignoreOutput`, so a hit leaves the file missing. + +## `vt run write-only` + +``` +$ node write-only.mjs +``` + +## `vtt rm scratch.txt` + +``` +``` + +## `vt run write-only` + +``` +$ node write-only.mjs ◉ cache hit, replaying + +--- +vt run: cache hit. +``` + +## `vtt stat-file scratch.txt` + +``` +scratch.txt: missing +``` diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/vite-task.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/vite-task.json new file mode 100644 index 000000000..4324daf90 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/vite-task.json @@ -0,0 +1,26 @@ +{ + "tasks": { + "read-state": { + "command": "node read-state.mjs", + "cache": true + }, + "read-link": { + "command": "node read-link.mjs", + "cache": true + }, + "ignore-cache": { + "command": "node ignored-cache.mjs", + "cache": true + }, + "exclude-cache-input": { + "command": "node ignored-cache.mjs input-negative", + "cache": { + "input": [{ "auto": true }, "!tool/cache/state.txt"] + } + }, + "write-only": { + "command": "node write-only.mjs", + "cache": true + } + } +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/write-only.mjs b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/write-only.mjs new file mode 100644 index 000000000..94f7eff1d --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ignore_output_rebuildable_inputs/write-only.mjs @@ -0,0 +1,6 @@ +import { readdirSync, writeFileSync } from 'node:fs'; +import { ignoreOutput } from '@voidzero-dev/vite-task-client'; + +readdirSync('.'); +writeFileSync('scratch.txt', 'scratch\n'); +ignoreOutput('scratch.txt'); diff --git a/packages/vite-task-client/src/index.d.ts b/packages/vite-task-client/src/index.d.ts index 821d0f676..0ba14f2a7 100644 --- a/packages/vite-task-client/src/index.d.ts +++ b/packages/vite-task-client/src/index.d.ts @@ -10,6 +10,9 @@ export function ignoreInput(path: string): void; /** * Tell the runner to ignore writes under `path` when inferring cache outputs. * + * A file the task reads and writes remains a required input if its read is + * still tracked. Deleting or changing it causes a cache miss. + * * No-op when not running inside a runner. * * @param {string} path diff --git a/packages/vite-task-client/src/index.js b/packages/vite-task-client/src/index.js index 5bff8ec48..b9090c0d4 100644 --- a/packages/vite-task-client/src/index.js +++ b/packages/vite-task-client/src/index.js @@ -66,6 +66,9 @@ export function ignoreInput(path) { /** * Tell the runner to ignore writes under `path` when inferring cache outputs. * + * A file the task reads and writes remains a required input if its read is + * still tracked. Deleting or changing it causes a cache miss. + * * No-op when not running inside a runner. * * @param {string} path