Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/fspy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ tempfile = { workspace = true }
anyhow = { workspace = true }
csv-async = { workspace = true }
ctor = { workspace = true }
test-log = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "fs", "io-std"] }

[target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.dev-dependencies]
Expand Down
7 changes: 4 additions & 3 deletions crates/fspy/tests/node_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod test_utils;
use std::env::{current_dir, vars_os};

use fspy::{AccessMode, PathAccessIterable};
use test_log::test;
use test_utils::assert_contains;

async fn track_node_script(script: &str) -> anyhow::Result<PathAccessIterable> {
Expand All @@ -17,21 +18,21 @@ async fn track_node_script(script: &str) -> anyhow::Result<PathAccessIterable> {
Ok(termination.path_accesses)
}

#[tokio::test]
#[test(tokio::test)]
async fn read_sync() -> anyhow::Result<()> {
let accesses = track_node_script("try { fs.readFileSync('hello') } catch {}").await?;
assert_contains(&accesses, current_dir().unwrap().join("hello").as_path(), AccessMode::Read);
Ok(())
}

#[tokio::test]
#[test(tokio::test)]
async fn read_dir_sync() -> anyhow::Result<()> {
let accesses = track_node_script("try { fs.readdirSync('.') } catch {}").await?;
assert_contains(&accesses, &current_dir().unwrap(), AccessMode::ReadDir);
Ok(())
}

#[tokio::test]
#[test(tokio::test)]
async fn subprocess() -> anyhow::Result<()> {
let cmd = if cfg!(windows) {
r"'cmd', ['/c', 'type hello']"
Expand Down
9 changes: 5 additions & 4 deletions crates/fspy/tests/rust_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use std::{
};

use fspy::AccessMode;
use test_log::test;
use test_utils::assert_contains;

#[tokio::test]
#[test(tokio::test)]
async fn open_read() -> anyhow::Result<()> {
let accesses = track_child!({
let _ = File::open("hello");
Expand All @@ -21,7 +22,7 @@ async fn open_read() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[test(tokio::test)]
async fn open_write() -> anyhow::Result<()> {
let accesses = track_child!({
let path = format!("{}/hello", env!("CARGO_TARGET_TMPDIR"));
Expand All @@ -37,7 +38,7 @@ async fn open_write() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[test(tokio::test)]
async fn readdir() -> anyhow::Result<()> {
let accesses = track_child!({
let path = format!("{}/hello", env!("CARGO_TARGET_TMPDIR"));
Expand All @@ -53,7 +54,7 @@ async fn readdir() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[test(tokio::test)]
async fn subprocess() -> anyhow::Result<()> {
let accesses = track_child!({
let mut command = if cfg!(windows) {
Expand Down
9 changes: 5 additions & 4 deletions crates/fspy/tests/rust_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ mod test_utils;
use std::{env::current_dir, path::Path, process::Stdio};

use fspy::AccessMode;
use test_log::test;
use test_utils::assert_contains;
use tokio::fs::OpenOptions;

#[tokio::test]
#[test(tokio::test)]
async fn open_read() -> anyhow::Result<()> {
let accesses = track_child!({
tokio::runtime::Builder::new_current_thread().enable_io().build().unwrap().block_on(
Expand All @@ -21,7 +22,7 @@ async fn open_read() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[test(tokio::test)]
async fn open_write() -> anyhow::Result<()> {
let accesses = track_child!({
let path = format!("{}/hello", env!("CARGO_TARGET_TMPDIR"));
Expand All @@ -42,7 +43,7 @@ async fn open_write() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[test(tokio::test)]
async fn readdir() -> anyhow::Result<()> {
let accesses = track_child!({
let path = format!("{}/hello", env!("CARGO_TARGET_TMPDIR"));
Expand All @@ -63,7 +64,7 @@ async fn readdir() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
#[test(tokio::test)]
async fn subprocess() -> anyhow::Result<()> {
let accesses = track_child!({
tokio::runtime::Builder::new_current_thread().enable_io().build().unwrap().block_on(
Expand Down
21 changes: 11 additions & 10 deletions crates/fspy/tests/static_executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{

use fspy::PathAccessIterable;
use fspy_shared_unix::is_dynamically_linked_to_libc;
use test_log::test;

use crate::test_utils::assert_contains;

Expand Down Expand Up @@ -49,61 +50,61 @@ async fn track_test_bin(args: &[&str], cwd: Option<&str>) -> PathAccessIterable
termination.path_accesses
}

#[tokio::test]
#[test(tokio::test)]
async fn open_read() {
let accesses = track_test_bin(&["open_read", "/hello"], None).await;
assert_contains(&accesses, Path::new("/hello"), fspy::AccessMode::Read);
}

#[tokio::test]
#[test(tokio::test)]
async fn open_write() {
let accesses = track_test_bin(&["open_write", "/hello"], None).await;
assert_contains(&accesses, Path::new("/hello"), fspy::AccessMode::Write);
}

#[tokio::test]
#[test(tokio::test)]
async fn open_readwrite() {
let accesses = track_test_bin(&["open_readwrite", "/hello"], None).await;
assert_contains(&accesses, Path::new("/hello"), fspy::AccessMode::ReadWrite);
}

#[tokio::test]
#[test(tokio::test)]
async fn openat2_read() {
let accesses = track_test_bin(&["openat2_read", "/hello"], None).await;
assert_contains(&accesses, Path::new("/hello"), fspy::AccessMode::Read);
}

#[tokio::test]
#[test(tokio::test)]
async fn openat2_write() {
let accesses = track_test_bin(&["openat2_write", "/hello"], None).await;
assert_contains(&accesses, Path::new("/hello"), fspy::AccessMode::Write);
}

#[tokio::test]
#[test(tokio::test)]
async fn openat2_readwrite() {
let accesses = track_test_bin(&["openat2_readwrite", "/hello"], None).await;
assert_contains(&accesses, Path::new("/hello"), fspy::AccessMode::ReadWrite);
}

#[tokio::test]
#[test(tokio::test)]
async fn open_relative() {
let accesses = track_test_bin(&["open_read", "hello"], Some("/home")).await;
assert_contains(&accesses, Path::new("/home/hello"), fspy::AccessMode::Read);
}

#[tokio::test]
#[test(tokio::test)]
async fn readdir() {
let accesses = track_test_bin(&["readdir", "/home"], None).await;
assert_contains(&accesses, Path::new("/home"), fspy::AccessMode::ReadDir);
}

#[tokio::test]
#[test(tokio::test)]
async fn stat() {
let accesses = track_test_bin(&["stat", "/hello"], None).await;
assert_contains(&accesses, Path::new("/hello"), fspy::AccessMode::Read);
}

#[tokio::test]
#[test(tokio::test)]
async fn execve() {
let accesses = track_test_bin(&["execve", "/hello"], None).await;
assert_contains(&accesses, Path::new("/hello"), fspy::AccessMode::Read);
Expand Down
4 changes: 3 additions & 1 deletion crates/fspy/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ macro_rules! track_child {
#[allow(unused)]
pub async fn spawn_std(std_cmd: std::process::Command) -> anyhow::Result<PathAccessIterable> {
let mut command = fspy::Command::new(std_cmd.get_program());
command.args(std_cmd.get_args());
command
.args(std_cmd.get_args())
.envs(std_cmd.get_envs().filter_map(|(name, value)| Some((name, value?))));

let termination = command.spawn().await?.wait_handle.await?;
assert!(termination.status.success());
Expand Down
4 changes: 2 additions & 2 deletions crates/fspy_shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ allocator-api2 = { workspace = true }
bincode = { workspace = true }
bstr = { workspace = true }
bytemuck = { workspace = true, features = ["must_cast"] }
shared_memory = { workspace = true }
shared_memory = { workspace = true, features = ["logging"] }
thiserror = { workspace = true }
tracing = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
Expand All @@ -24,4 +24,4 @@ winsafe = { workspace = true }
assert2 = { workspace = true }
ctor = { workspace = true }
fspy_test_utils = { workspace = true }
shared_memory = { workspace = true }
shared_memory = { workspace = true, features = ["logging"] }
3 changes: 3 additions & 0 deletions crates/fspy_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub fn create_command(id: &str, arg: impl Encode) -> Command {
let arg_base64 = BASE64_STANDARD_NO_PAD.encode(&arg_bytes);
command.arg(id).arg(arg_base64);

// Set inherit environment explicitly, in case it needs to be converted to fspy::Command later
command.env_clear().envs(std::env::vars_os());

command
}

Expand Down