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
16 changes: 12 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,16 @@ jobs:
with:
architecture: ${{ matrix.target == 'x86_64-apple-darwin' && 'x64' || '' }}

- name: Install Chromium
run: pnpm --filter vite-task-tools rebuild @playwright/browser-chromium
- name: Install runtime binaries
run: |
if [[ '${{ matrix.target }}' == 'x86_64-apple-darwin' ]]; then
# Bun normally prefers the native arm64 binary under Rosetta, but
# this job needs x64 Bun so the x64 preload dylib can be injected.
PATH="$(dirname "$(command -v node)"):$PNPM_HOME:/usr/bin:/bin" \
pnpm --filter vite-task-tools rebuild --pending
else
pnpm --filter vite-task-tools rebuild --pending
fi

- name: Install Chromium system dependencies
if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }}
Expand Down Expand Up @@ -267,9 +275,9 @@ jobs:
- uses: oxc-project/setup-node@4c588e9266bd930b6ddc34307df0659ed511d187 # v1.3.1
if: matrix.mode == 'ignored'

- name: Install Chromium
- name: Install runtime binaries
if: matrix.mode == 'ignored'
run: pnpm --filter vite-task-tools rebuild @playwright/browser-chromium
run: pnpm --filter vite-task-tools rebuild --pending

- name: Run ignored tests
if: matrix.mode == 'ignored'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- **Fixed** An issue where Bun tasks on macOS did not rerun when files they read, wrote, or listed changed ([#532](https://github.com/voidzero-dev/vite-task/issues/532), [#542](https://github.com/voidzero-dev/vite-task/pull/542)).
- **Improved** Windows file-access tracking now uses sparse temporary backing files where supported, avoiding upfront allocation of the full backing file on disk ([#524](https://github.com/voidzero-dev/vite-task/pull/524)).
- **Fixed** Automatic file-access tracking on Linux now works in containers and Kubernetes runners with limited `/dev/shm` space ([#353](https://github.com/voidzero-dev/vite-task/issues/353), [#523](https://github.com/voidzero-dev/vite-task/pull/523)).
- **Fixed** Windows automatic input tracking now records executable image reads when process creation performs the lookup inside `NtCreateUserProcess` ([#518](https://github.com/voidzero-dev/vite-task/pull/518)).
Expand Down
21 changes: 19 additions & 2 deletions crates/fspy/tests/node_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ fn track_script(
})
}

// Deno does not distribute a musl runtime, so only its generated cases are
// excluded there. Node remains covered by the same tests on musl.
// Bun's Linux runtime uses direct syscalls, which require universal seccomp
// tracing instead of preload interception. Deno does not distribute a musl
// runtime. Node remains covered on every target.
#[test_case("node")]
#[ignore = "requires node"]
#[cfg_attr(not(target_os = "linux"), test_case("bun"))]
#[cfg_attr(not(target_os = "linux"), ignore = "requires node")]
#[cfg_attr(not(target_env = "musl"), test_case("deno"))]
#[cfg_attr(not(target_env = "musl"), ignore = "requires node")]
fn read_sync(runtime: &str) -> anyhow::Result<()> {
Expand All @@ -67,6 +70,8 @@ fn read_sync(runtime: &str) -> anyhow::Result<()> {

#[test_case("node")]
#[ignore = "requires node"]
#[cfg_attr(not(target_os = "linux"), test_case("bun"))]
#[cfg_attr(not(target_os = "linux"), ignore = "requires node")]
#[cfg_attr(not(target_env = "musl"), test_case("deno"))]
#[cfg_attr(not(target_env = "musl"), ignore = "requires node")]
fn exist_sync(runtime: &str) -> anyhow::Result<()> {
Expand All @@ -77,6 +82,8 @@ fn exist_sync(runtime: &str) -> anyhow::Result<()> {

#[test_case("node")]
#[ignore = "requires node"]
#[cfg_attr(not(target_os = "linux"), test_case("bun"))]
#[cfg_attr(not(target_os = "linux"), ignore = "requires node")]
#[cfg_attr(not(target_env = "musl"), test_case("deno"))]
#[cfg_attr(not(target_env = "musl"), ignore = "requires node")]
fn stat_sync(runtime: &str) -> anyhow::Result<()> {
Expand All @@ -87,6 +94,8 @@ fn stat_sync(runtime: &str) -> anyhow::Result<()> {

#[test_case("node")]
#[ignore = "requires node"]
#[cfg_attr(not(target_os = "linux"), test_case("bun"))]
#[cfg_attr(not(target_os = "linux"), ignore = "requires node")]
#[cfg_attr(not(target_env = "musl"), test_case("deno"))]
#[cfg_attr(not(target_env = "musl"), ignore = "requires node")]
fn create_read_stream(runtime: &str) -> anyhow::Result<()> {
Expand All @@ -101,6 +110,8 @@ fn create_read_stream(runtime: &str) -> anyhow::Result<()> {

#[test_case("node")]
#[ignore = "requires node"]
#[cfg_attr(not(target_os = "linux"), test_case("bun"))]
#[cfg_attr(not(target_os = "linux"), ignore = "requires node")]
#[cfg_attr(not(target_env = "musl"), test_case("deno"))]
#[cfg_attr(not(target_env = "musl"), ignore = "requires node")]
fn create_write_stream(runtime: &str) -> anyhow::Result<()> {
Expand All @@ -117,6 +128,8 @@ fn create_write_stream(runtime: &str) -> anyhow::Result<()> {

#[test_case("node")]
#[ignore = "requires node"]
#[cfg_attr(not(target_os = "linux"), test_case("bun"))]
#[cfg_attr(not(target_os = "linux"), ignore = "requires node")]
#[cfg_attr(not(target_env = "musl"), test_case("deno"))]
#[cfg_attr(not(target_env = "musl"), ignore = "requires node")]
fn write_sync(runtime: &str) -> anyhow::Result<()> {
Expand All @@ -133,6 +146,8 @@ fn write_sync(runtime: &str) -> anyhow::Result<()> {

#[test_case("node")]
#[ignore = "requires node"]
#[cfg_attr(not(target_os = "linux"), test_case("bun"))]
#[cfg_attr(not(target_os = "linux"), ignore = "requires node")]
#[cfg_attr(not(target_env = "musl"), test_case("deno"))]
#[cfg_attr(not(target_env = "musl"), ignore = "requires node")]
fn read_dir_sync(runtime: &str) -> anyhow::Result<()> {
Expand All @@ -143,6 +158,8 @@ fn read_dir_sync(runtime: &str) -> anyhow::Result<()> {

#[test_case("node")]
#[ignore = "requires node"]
#[cfg_attr(not(target_os = "linux"), test_case("bun"))]
#[cfg_attr(not(target_os = "linux"), ignore = "requires node")]
#[cfg_attr(not(target_env = "musl"), test_case("deno"))]
#[cfg_attr(not(target_env = "musl"), ignore = "requires node")]
fn subprocess(runtime: &str) -> anyhow::Result<()> {
Expand Down
16 changes: 15 additions & 1 deletion crates/fspy_preload_unix/src/interceptions/dirent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ unsafe extern "C" fn scandir(

#[cfg(target_os = "macos")]
mod macos_only {
use super::{AccessMode, c_char, c_int, c_void, handle_open, intercept};
use super::{AccessMode, Fd, c_char, c_int, c_void, handle_open, intercept};

intercept!(scandir_b: unsafe extern "C" fn (
dirname: *const c_char,
namelist: *mut c_void,
Expand All @@ -44,6 +45,19 @@ mod macos_only {
// SAFETY: calling the original libc scandir_b() with the same arguments forwarded from the interposed function
unsafe { scandir_b::original()(dirname, namelist, select, compar) }
}

intercept!(__getdirentries64: unsafe extern "C" fn(c_int, *mut u8, usize, *mut i64) -> isize);
unsafe extern "C" fn __getdirentries64(
fd: c_int,
buf: *mut u8,
buf_len: usize,
basep: *mut i64,
) -> isize {
// SAFETY: fd is a valid file descriptor provided by the caller of __getdirentries64
unsafe { handle_open(Fd(fd), AccessMode::READ_DIR) };
// SAFETY: calling the original libc __getdirentries64() with the same arguments forwarded from the interposed function
unsafe { __getdirentries64::original()(fd, buf, buf_len, basep) }
}
}

intercept!(getdirentries(64): unsafe extern "C" fn (fd: c_int, buf: *mut c_char, nbytes: c_int, basep: *mut c_long) -> c_int);
Expand Down
39 changes: 39 additions & 0 deletions crates/fspy_preload_unix/src/interceptions/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,45 @@ unsafe extern "C" fn openat(
}
}

#[cfg(target_os = "macos")]
intercept!(open_nocancel: unsafe extern "C" fn(*const c_char, c_int, ...) -> c_int);
#[cfg(target_os = "macos")]
unsafe extern "C" fn open_nocancel(path: *const c_char, flags: c_int, mut args: ...) -> c_int {
// SAFETY: path is a valid C string pointer provided by the caller of open$NOCANCEL
unsafe { handle_open(path, OpenFlags(flags)) };
if has_mode_arg(flags) {
// SAFETY: O_CREAT requires a mode argument, matching the open$NOCANCEL contract
let mode: Mode = unsafe { args.next_arg() };
// SAFETY: calling the original libc open$NOCANCEL() with the same arguments forwarded from the interposed function
unsafe { open_nocancel::original()(path, flags, mode) }
} else {
// SAFETY: calling the original libc open$NOCANCEL() with the same arguments forwarded from the interposed function
unsafe { open_nocancel::original()(path, flags) }
}
}

#[cfg(target_os = "macos")]
intercept!(openat_nocancel: unsafe extern "C" fn(c_int, *const c_char, c_int, ...) -> c_int);
#[cfg(target_os = "macos")]
unsafe extern "C" fn openat_nocancel(
dirfd: c_int,
path: *const c_char,
flags: c_int,
mut args: ...
) -> c_int {
// SAFETY: dirfd and path are valid arguments provided by the caller of openat$NOCANCEL
unsafe { handle_open(PathAt(dirfd, path), OpenFlags(flags)) };
if has_mode_arg(flags) {
// SAFETY: O_CREAT requires a mode argument, matching the openat$NOCANCEL contract
let mode: Mode = unsafe { args.next_arg() };
// SAFETY: calling the original libc openat$NOCANCEL() with the same arguments forwarded from the interposed function
unsafe { openat_nocancel::original()(dirfd, path, flags, mode) }
} else {
// SAFETY: calling the original libc openat$NOCANCEL() with the same arguments forwarded from the interposed function
unsafe { openat_nocancel::original()(dirfd, path, flags) }
}
}

intercept!(fopen(64): unsafe extern "C" fn(path: *const c_char, mode: *const c_char) -> *mut FILE);
unsafe extern "C" fn fopen(path: *const c_char, mode: *const c_char) -> *mut libc::FILE {
// SAFETY: path and mode are valid C string pointers provided by the caller of the interposed function
Expand Down
16 changes: 16 additions & 0 deletions crates/fspy_preload_unix/src/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ unsafe extern "C" {
nbytes: c_int,
basep: *mut c_long,
) -> c_int;

#[cfg(target_os = "macos")]
#[link_name = "open$NOCANCEL"]
pub unsafe fn open_nocancel(path: *const c_char, flags: c_int, ...) -> c_int;

#[cfg(target_os = "macos")]
#[link_name = "openat$NOCANCEL"]
pub unsafe fn openat_nocancel(dirfd: c_int, path: *const c_char, flags: c_int, ...) -> c_int;

#[cfg(target_os = "macos")]
pub unsafe fn __getdirentries64(
fd: c_int,
buf: *mut u8,
buf_len: usize,
basep: *mut i64,
) -> isize;
}
1 change: 1 addition & 0 deletions packages/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@playwright/browser-chromium": "catalog:",
"@vitest/browser-playwright": "catalog:",
"@voidzero-dev/vite-task-client": "workspace:*",
"bun": "catalog:",
"cross-env": "catalog:",
"deno": "catalog:",
"oxfmt": "catalog:",
Expand Down
Loading
Loading