Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/fspy_client_unix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})?;
Expand Down
16 changes: 16 additions & 0 deletions crates/fspy_shared_unix/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use bstr::BStr;
use fspy_shared::ipc::{AccessChannelConf, IpcStr};
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
Expand Down Expand Up @@ -51,6 +53,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<A: Allocator>(&self, envs: &[Env<A>]) -> 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
compile input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint input
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "nested-run-in-script",
"private": true
}
Original file line number Diff line number Diff line change
@@ -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" },
]
Original file line number Diff line number Diff line change
@@ -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
```
Original file line number Diff line number Diff line change
@@ -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
}
}
}