From 339cb55e2dc72000808c0e5af0f505655815922f Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Tue, 1 Dec 2026 10:57:09 -0600 Subject: [PATCH 1/3] test(e2e): cover vp run called from a cached task's script --- .../nested_run_in_script/package.json | 4 ++ .../fixtures/nested_run_in_script/release.mjs | 3 ++ .../nested_run_in_script/snapshots.toml | 28 ++++++++++++ .../snapshots/nested_run_in_script.md | 43 +++++++++++++++++++ .../fixtures/nested_run_in_script/src.txt | 1 + .../nested_run_in_script/vite-task.json | 12 ++++++ 6 files changed, 91 insertions(+) create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/package.json create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/release.mjs create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots.toml create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots/nested_run_in_script.md create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/src.txt create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/vite-task.json diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/package.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/package.json new file mode 100644 index 000000000..3579b1fd6 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/package.json @@ -0,0 +1,4 @@ +{ + "name": "nested-run-in-script", + "private": true +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/release.mjs b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/release.mjs new file mode 100644 index 000000000..9c82f6996 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/release.mjs @@ -0,0 +1,3 @@ +import { execFileSync } from "node:child_process"; + +execFileSync("vt", ["run", "build"], { stdio: "inherit" }); diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots.toml b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots.toml new file mode 100644 index 000000000..e343fcc42 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots.toml @@ -0,0 +1,28 @@ +[[e2e]] +name = "nested_run_in_script" +comment = """ +A cached task runs a script that calls `vt run build`, such as a release script. The outer run traces the script, and the inner run traces `build` itself. The inner run's spawn must not fail because it already runs under the outer run's tracing. +""" +steps = [ + { argv = [ + "vt", + "run", + "release", + ], comment = "inner build: cache miss" }, + { argv = [ + "vt", + "run", + "release", + ], comment = "inner build: cache hit" }, + { argv = [ + "vtt", + "write-file", + "src.txt", + "second build", + ], comment = "modify the inner build's input" }, + { argv = [ + "vt", + "run", + "release", + ], comment = "inner build: cache miss, prints the new content" }, +] diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots/nested_run_in_script.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots/nested_run_in_script.md new file mode 100644 index 000000000..28b357a63 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots/nested_run_in_script.md @@ -0,0 +1,43 @@ +# nested_run_in_script + +A cached task runs a script that calls `vt run build`, such as a release script. The outer run traces the script, and the inner run traces `build` itself. The inner run's spawn must not fail because it already runs under the outer run's tracing. + +## `vt run release` + +inner build: cache miss + +``` +$ node release.mjs +$ vtt print-file src.txt +first build +``` + +## `vt run release` + +inner build: cache hit + +``` +$ node release.mjs +$ vtt print-file src.txt ◉ cache hit, replaying +first build + +--- +vt run: cache hit. +``` + +## `vtt write-file src.txt 'second build'` + +modify the inner build's input + +``` +``` + +## `vt run release` + +inner build: cache miss, prints the new content + +``` +$ node release.mjs ○ cache miss: 'src.txt' modified, executing +$ vtt print-file src.txt ○ cache miss: 'src.txt' modified, executing +second build +``` diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/src.txt b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/src.txt new file mode 100644 index 000000000..828ebd872 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/src.txt @@ -0,0 +1 @@ +first build diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/vite-task.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/vite-task.json new file mode 100644 index 000000000..143936b01 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/vite-task.json @@ -0,0 +1,12 @@ +{ + "tasks": { + "build": { + "command": "vtt print-file src.txt", + "cache": true + }, + "release": { + "command": "node release.mjs", + "cache": true + } + } +} From 35b1ed4739c3a654dbaca5f553c0976d4c56a60e Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Tue, 1 Dec 2026 10:25:47 -0600 Subject: [PATCH 2/3] fix(fspy): let a nested vp run trace its own children --- crates/fspy_client_unix/src/lib.rs | 6 ++++++ crates/fspy_shared_unix/src/payload.rs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/crates/fspy_client_unix/src/lib.rs b/crates/fspy_client_unix/src/lib.rs index d51c90f10..234391144 100644 --- a/crates/fspy_client_unix/src/lib.rs +++ b/crates/fspy_client_unix/src/lib.rs @@ -119,6 +119,12 @@ impl<'a> Client<'a> { // SAFETY: raw_exec contains valid pointers to C strings and // null-terminated arrays, as provided by the caller. let mut exec = unsafe { raw_exec.to_exec(allocator) }; + if self.encoded_payload.is_overridden_in(&exec.envs) { + // A nested fspy session owns this child and traces it itself. + // This trace cannot see the child, so it must not be cached. + self.report_loss(); + return Ok((raw_exec, None)); + } let pre_exec = handle_exec(&mut exec, config, &self.encoded_payload, |path| { self.send(AccessMode::Read, path); })?; diff --git a/crates/fspy_shared_unix/src/payload.rs b/crates/fspy_shared_unix/src/payload.rs index 8276ba5ee..79103d00c 100644 --- a/crates/fspy_shared_unix/src/payload.rs +++ b/crates/fspy_shared_unix/src/payload.rs @@ -7,6 +7,8 @@ use fspy_shared::ipc::IpcStr; use fspy_shared::ipc::channel::ChannelConf; use wincode::{SchemaRead, SchemaWrite}; +use crate::exec::Env; + /// The payload as it travels between processes. /// /// A payload is a view: every path in it borrows from storage its producer @@ -53,6 +55,20 @@ pub struct EncodedPayload<'a> { pub encoded_string: &'a BStr, } +impl EncodedPayload<'_> { + /// Returns whether `envs` carries another tracer's payload. + /// + /// A traced process that runs its own fspy session (a nested `vp run`) + /// prepares each child for that inner session. Such an exec belongs to + /// the inner trace and must not be injected with this payload. + pub fn is_overridden_in(&self, envs: &[Env]) -> bool { + envs.iter().any(|(name, value)| { + name.as_slice() == PAYLOAD_ENV_NAME.as_bytes() + && value.as_deref() != Some(self.encoded_string.as_ref()) + }) + } +} + // Seals the view-only design: every field is an inert borrow of leaked // bytes. A retained allocator handle is interior-mutable and would fail // this assertion. From ca1819028e8b6bb98aaedd262a3146782377209d Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Tue, 1 Dec 2026 12:15:21 -0600 Subject: [PATCH 3/3] test(e2e): cover nested vp run calls joined with ; --- .../fixtures/nested_run_in_script/release.mjs | 3 - .../nested_run_in_script/snapshots.toml | 28 ---------- .../snapshots/nested_run_in_script.md | 43 -------------- .../fixtures/nested_run_in_script/src.txt | 1 - .../nested_run_in_script/vite-task.json | 12 ---- .../nested_run_in_sequence/compile.txt | 1 + .../fixtures/nested_run_in_sequence/lint.txt | 1 + .../package.json | 0 .../nested_run_in_sequence/snapshots.toml | 28 ++++++++++ .../snapshots/nested_run_in_sequence.md | 56 +++++++++++++++++++ .../nested_run_in_sequence/vite-task.json | 16 ++++++ 11 files changed, 102 insertions(+), 87 deletions(-) delete mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/release.mjs delete mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots.toml delete mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots/nested_run_in_script.md delete mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/src.txt delete mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/vite-task.json create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/compile.txt create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/lint.txt rename crates/vt_bin/tests/e2e_snapshots/fixtures/{nested_run_in_script => nested_run_in_sequence}/package.json (100%) create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/snapshots.toml create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/snapshots/nested_run_in_sequence.md create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/vite-task.json diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/release.mjs b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/release.mjs deleted file mode 100644 index 9c82f6996..000000000 --- a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/release.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import { execFileSync } from "node:child_process"; - -execFileSync("vt", ["run", "build"], { stdio: "inherit" }); diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots.toml b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots.toml deleted file mode 100644 index e343fcc42..000000000 --- a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots.toml +++ /dev/null @@ -1,28 +0,0 @@ -[[e2e]] -name = "nested_run_in_script" -comment = """ -A cached task runs a script that calls `vt run build`, such as a release script. The outer run traces the script, and the inner run traces `build` itself. The inner run's spawn must not fail because it already runs under the outer run's tracing. -""" -steps = [ - { argv = [ - "vt", - "run", - "release", - ], comment = "inner build: cache miss" }, - { argv = [ - "vt", - "run", - "release", - ], comment = "inner build: cache hit" }, - { argv = [ - "vtt", - "write-file", - "src.txt", - "second build", - ], comment = "modify the inner build's input" }, - { argv = [ - "vt", - "run", - "release", - ], comment = "inner build: cache miss, prints the new content" }, -] diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots/nested_run_in_script.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots/nested_run_in_script.md deleted file mode 100644 index 28b357a63..000000000 --- a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/snapshots/nested_run_in_script.md +++ /dev/null @@ -1,43 +0,0 @@ -# nested_run_in_script - -A cached task runs a script that calls `vt run build`, such as a release script. The outer run traces the script, and the inner run traces `build` itself. The inner run's spawn must not fail because it already runs under the outer run's tracing. - -## `vt run release` - -inner build: cache miss - -``` -$ node release.mjs -$ vtt print-file src.txt -first build -``` - -## `vt run release` - -inner build: cache hit - -``` -$ node release.mjs -$ vtt print-file src.txt ◉ cache hit, replaying -first build - ---- -vt run: cache hit. -``` - -## `vtt write-file src.txt 'second build'` - -modify the inner build's input - -``` -``` - -## `vt run release` - -inner build: cache miss, prints the new content - -``` -$ node release.mjs ○ cache miss: 'src.txt' modified, executing -$ vtt print-file src.txt ○ cache miss: 'src.txt' modified, executing -second build -``` diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/src.txt b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/src.txt deleted file mode 100644 index 828ebd872..000000000 --- a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/src.txt +++ /dev/null @@ -1 +0,0 @@ -first build diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/vite-task.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/vite-task.json deleted file mode 100644 index 143936b01..000000000 --- a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/vite-task.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "tasks": { - "build": { - "command": "vtt print-file src.txt", - "cache": true - }, - "release": { - "command": "node release.mjs", - "cache": true - } - } -} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/compile.txt b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/compile.txt new file mode 100644 index 000000000..7f6658be2 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/compile.txt @@ -0,0 +1 @@ +compile input diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/lint.txt b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/lint.txt new file mode 100644 index 000000000..b338c5b3d --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/lint.txt @@ -0,0 +1 @@ +lint input diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/package.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/package.json similarity index 100% rename from crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_script/package.json rename to crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/package.json diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/snapshots.toml b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/snapshots.toml new file mode 100644 index 000000000..591c67faa --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/snapshots.toml @@ -0,0 +1,28 @@ +[[e2e]] +name = "nested_run_in_sequence" +comment = """ +A cached task runs `vt run lint; vt run compile`. Unlike `&&`, `vt` doesn't split `;`, so a shell runs both nested `vt run` calls. The outer run traces the shell, and each inner run traces its own task. The inner runs' spawns must not fail because they already run under the outer run's tracing. +""" +steps = [ + { argv = [ + "vt", + "run", + "check", + ], comment = "inner tasks: cache miss" }, + { argv = [ + "vt", + "run", + "check", + ], comment = "inner tasks: cache hit" }, + { argv = [ + "vtt", + "write-file", + "compile.txt", + "changed compile input", + ], comment = "modify compile's input" }, + { argv = [ + "vt", + "run", + "check", + ], comment = "lint: cache hit; compile: cache miss, prints the new content" }, +] diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/snapshots/nested_run_in_sequence.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/snapshots/nested_run_in_sequence.md new file mode 100644 index 000000000..da8ad716a --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/snapshots/nested_run_in_sequence.md @@ -0,0 +1,56 @@ +# nested_run_in_sequence + +A cached task runs `vt run lint; vt run compile`. Unlike `&&`, `vt` doesn't split `;`, so a shell runs both nested `vt run` calls. The outer run traces the shell, and each inner run traces its own task. The inner runs' spawns must not fail because they already run under the outer run's tracing. + +## `vt run check` + +inner tasks: cache miss + +``` +$ vt run lint; vt run compile +$ vtt print-file lint.txt +lint input + +$ vtt print-file compile.txt +compile input +``` + +## `vt run check` + +inner tasks: cache hit + +``` +$ vt run lint; vt run compile +$ vtt print-file lint.txt ◉ cache hit, replaying +lint input + +--- +vt run: cache hit. +$ vtt print-file compile.txt ◉ cache hit, replaying +compile input + +--- +vt run: cache hit. +``` + +## `vtt write-file compile.txt 'changed compile input'` + +modify compile's input + +``` +``` + +## `vt run check` + +lint: cache hit; compile: cache miss, prints the new content + +``` +$ vt run lint; vt run compile ○ cache miss: 'compile.txt' modified, executing +$ vtt print-file lint.txt ◉ cache hit, replaying +lint input + +--- +vt run: cache hit. +$ vtt print-file compile.txt ○ cache miss: 'compile.txt' modified, executing +changed compile input +``` diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/vite-task.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/vite-task.json new file mode 100644 index 000000000..7b250cc78 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/nested_run_in_sequence/vite-task.json @@ -0,0 +1,16 @@ +{ + "tasks": { + "lint": { + "command": "vtt print-file lint.txt", + "cache": true + }, + "compile": { + "command": "vtt print-file compile.txt", + "cache": true + }, + "check": { + "command": "vt run lint; vt run compile", + "cache": true + } + } +}