From 8a97fc4e2043832cb12b93ab0ee6125f58bcfa3c Mon Sep 17 00:00:00 2001 From: Aaron Reisman Date: Thu, 5 Nov 2026 12:40:24 +0700 Subject: [PATCH 1/3] fix(fspy): bundle an Oils master build with four osh fixes On macOS, fspy runs tracked `/bin/sh` and `/bin/bash` commands under the bundled Oils shell. Oils 0.38.0 differs from the real shells in four cases that change task results: errexit after a compound command with a redirect, `$?` in the EXIT trap, a bare `exit` in the EXIT trap, and `$BASH`. The fixes are in Oils master but not in a release, so this pins the wan9chi/oils-for-unix-build release for master commit d114978c. The new shell_semantics tests run each case under a tracked shell. They fail with 0.38.0 and pass with this build on macOS, and they pass with the real shells on Linux. --- CHANGELOG.md | 1 + crates/fspy/build.rs | 12 ++--- crates/fspy/tests/shell_semantics.rs | 73 ++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 crates/fspy/tests/shell_semantics.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 037f94a9f..342c7496f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog +- **Fixed** On macOS, task commands that use `sh` or `bash` now behave as they do on Linux in four cases. A `while read` loop with a redirect under `set -e` no longer exits the script. An `EXIT` trap now sees the exit status in `$?`, and a bare `exit` in the trap keeps that status, so a failed task is no longer reported as successful. `$BASH` is now set when the command runs as `bash`. The bundled shell is updated to an Oils build from master that has these fixes ([#???](https://github.com/voidzero-dev/vite-task/pull/???)). - **Fixed** Tasks that read the task cache folder, `node_modules/.vite/task-cache`, now hit the cache. `vp run` changes that folder after every run, and tools such as Parcel and Gatsby read it once they rebuild with their own cache in place, so from then on those tasks missed every time with a reason like `'node_modules/.vite/task-cache/v20/last-summary.json' modified` ([#937](https://github.com/voidzero-dev/vite-task/pull/937)). - **Changed** Tasks that write a file they also read are now cached, instead of being reported as `not cached because it modified its inputs`. For example, `tsc --incremental` reads and rewrites `tsconfig.tsbuildinfo`: the next run is a cache hit if the file is as `tsc` left it, or if it is missing, as on a fresh clone, in which case the hit restores it ([#913](https://github.com/voidzero-dev/vite-task/pull/913)). - **Fixed** A cache hit restores the symbolic links a task's `output` globs match as links, instead of dropping them, so a replayed output that links a directory, such as a bundler's `node_modules/` link, is complete ([#885](https://github.com/voidzero-dev/vite-task/pull/885)). diff --git a/crates/fspy/build.rs b/crates/fspy/build.rs index d6d6982b9..9710c2e18 100644 --- a/crates/fspy/build.rs +++ b/crates/fspy/build.rs @@ -72,13 +72,13 @@ const MACOS_BINARY_DOWNLOADS: &[(&str, &[BinaryDownload])] = &[ ( "aarch64", &[ - // https://github.com/wan9chi/oils-for-unix-build/releases/tag/oils-for-unix-0.38.0 + // https://github.com/wan9chi/oils-for-unix-build/releases/tag/oils-for-unix-0.38.0-git-d114978ca467143f171a835cbcbe8ab6ccc009a7 BinaryDownload { name: "oils_for_unix", env_var: "FSPY_MACOS_ARTIFACT_OILS_FOR_UNIX", - url: "https://github.com/wan9chi/oils-for-unix-build/releases/download/oils-for-unix-0.38.0/oils-for-unix-0.38.0-darwin-arm64.tar.gz", + url: "https://github.com/wan9chi/oils-for-unix-build/releases/download/oils-for-unix-0.38.0-git-d114978ca467143f171a835cbcbe8ab6ccc009a7/oils-for-unix-0.38.0-git-d114978ca467143f171a835cbcbe8ab6ccc009a7-darwin-arm64.tar.gz", path_in_targz: "oils-for-unix", - expected_sha256: "b6e9d77aa6b22692f6132ca03346a8e166f1f57d966712f0ffff14c89412df15", + expected_sha256: "ac12f48c03f18edd39f509b9a12e162ba38702a4c6461fd3f1650b2d67406467", }, // https://github.com/uutils/coreutils/releases/tag/0.4.0 BinaryDownload { @@ -93,13 +93,13 @@ const MACOS_BINARY_DOWNLOADS: &[(&str, &[BinaryDownload])] = &[ ( "x86_64", &[ - // https://github.com/wan9chi/oils-for-unix-build/releases/tag/oils-for-unix-0.38.0 + // https://github.com/wan9chi/oils-for-unix-build/releases/tag/oils-for-unix-0.38.0-git-d114978ca467143f171a835cbcbe8ab6ccc009a7 BinaryDownload { name: "oils_for_unix", env_var: "FSPY_MACOS_ARTIFACT_OILS_FOR_UNIX", - url: "https://github.com/wan9chi/oils-for-unix-build/releases/download/oils-for-unix-0.38.0/oils-for-unix-0.38.0-darwin-x86_64.tar.gz", + url: "https://github.com/wan9chi/oils-for-unix-build/releases/download/oils-for-unix-0.38.0-git-d114978ca467143f171a835cbcbe8ab6ccc009a7/oils-for-unix-0.38.0-git-d114978ca467143f171a835cbcbe8ab6ccc009a7-darwin-x86_64.tar.gz", path_in_targz: "oils-for-unix", - expected_sha256: "1a41a729538fd3663809c70f72179503345ea717b956607771ba766574ab6382", + expected_sha256: "0193ef17d601b0e3c190e20c8a6144a5f9c62f65794aae4a1d7db7d873dd8149", }, // https://github.com/uutils/coreutils/releases/tag/0.4.0 BinaryDownload { diff --git a/crates/fspy/tests/shell_semantics.rs b/crates/fspy/tests/shell_semantics.rs new file mode 100644 index 000000000..da18c569a --- /dev/null +++ b/crates/fspy/tests/shell_semantics.rs @@ -0,0 +1,73 @@ +//! Shell behavior that tracked tasks depend on. On macOS, fspy runs the +//! bundled Oils shell in place of `/bin/sh` and `/bin/bash`, so these tests +//! check that it behaves like the real shells, which run on Linux. +#![cfg(unix)] +mod test_utils; + +use std::process::{Command, Stdio}; + +use test_log::test; + +/// Runs `script` with `shell -c` and returns its exit code and stdout. +fn run(shell: &str, script: &str) -> (Option, String) { + let output = Command::new(shell) + .arg("-c") + .arg(script) + .stdin(Stdio::null()) + .output() + .expect("failed to run the shell"); + (output.status.code(), String::from_utf8(output.stdout).expect("stdout is not UTF-8")) +} + +/// Under `set -e`, a loop with a redirect must not exit when its last +/// `test ... && ...` fails. +#[test(tokio::test)] +async fn errexit_ignores_status_of_compound_command_with_redirect() -> anyhow::Result<()> { + track_fn!((), |(): ()| { + let script = "set -e +found=0 +while read -r line; do + test \"$line\" = key && found=1 +done < anyhow::Result<()> { + track_fn!((), |(): ()| { + let script = "trap 'st=$?; trap - EXIT; true; exit $st' EXIT; exit 7"; + assert_eq!(run("/bin/sh", script), (Some(7), String::new())); + }) + .await?; + Ok(()) +} + +/// A bare `exit` in an EXIT trap keeps the status from before the trap. +#[test(tokio::test)] +async fn bare_exit_in_exit_trap_keeps_status() -> anyhow::Result<()> { + track_fn!((), |(): ()| { + assert_eq!(run("/bin/sh", "trap exit EXIT; exit 3"), (Some(3), String::new())); + }) + .await?; + Ok(()) +} + +/// `$BASH` is set when the shell runs as `bash`. +#[test(tokio::test)] +async fn bash_variable_is_set() -> anyhow::Result<()> { + track_fn!((), |(): ()| { + let (code, stdout) = run("/bin/bash", "echo \"$BASH\""); + assert_eq!(code, Some(0)); + assert_ne!(stdout.trim(), "", "$BASH is empty"); + }) + .await?; + Ok(()) +} From 36cabc60d0c7d18d9c500ab7efe65a65469ba3ab Mon Sep 17 00:00:00 2001 From: Aaron Reisman Date: Thu, 5 Nov 2026 12:40:55 +0700 Subject: [PATCH 2/3] docs(changelog): link #939 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 342c7496f..ea96d9fa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -- **Fixed** On macOS, task commands that use `sh` or `bash` now behave as they do on Linux in four cases. A `while read` loop with a redirect under `set -e` no longer exits the script. An `EXIT` trap now sees the exit status in `$?`, and a bare `exit` in the trap keeps that status, so a failed task is no longer reported as successful. `$BASH` is now set when the command runs as `bash`. The bundled shell is updated to an Oils build from master that has these fixes ([#???](https://github.com/voidzero-dev/vite-task/pull/???)). +- **Fixed** On macOS, task commands that use `sh` or `bash` now behave as they do on Linux in four cases. A `while read` loop with a redirect under `set -e` no longer exits the script. An `EXIT` trap now sees the exit status in `$?`, and a bare `exit` in the trap keeps that status, so a failed task is no longer reported as successful. `$BASH` is now set when the command runs as `bash`. The bundled shell is updated to an Oils build from master that has these fixes ([#939](https://github.com/voidzero-dev/vite-task/pull/939)). - **Fixed** Tasks that read the task cache folder, `node_modules/.vite/task-cache`, now hit the cache. `vp run` changes that folder after every run, and tools such as Parcel and Gatsby read it once they rebuild with their own cache in place, so from then on those tasks missed every time with a reason like `'node_modules/.vite/task-cache/v20/last-summary.json' modified` ([#937](https://github.com/voidzero-dev/vite-task/pull/937)). - **Changed** Tasks that write a file they also read are now cached, instead of being reported as `not cached because it modified its inputs`. For example, `tsc --incremental` reads and rewrites `tsconfig.tsbuildinfo`: the next run is a cache hit if the file is as `tsc` left it, or if it is missing, as on a fresh clone, in which case the hit restores it ([#913](https://github.com/voidzero-dev/vite-task/pull/913)). - **Fixed** A cache hit restores the symbolic links a task's `output` globs match as links, instead of dropping them, so a replayed output that links a directory, such as a bundler's `node_modules/` link, is complete ([#885](https://github.com/voidzero-dev/vite-task/pull/885)). From faded9fb8e0c5189aea0ff261c56c224dbdcc836 Mon Sep 17 00:00:00 2001 From: Aaron Reisman Date: Thu, 5 Nov 2026 12:43:06 +0700 Subject: [PATCH 3/3] test(fspy): drop shell tests that Oils' spec tests already cover --- crates/fspy/tests/shell_semantics.rs | 73 ---------------------------- 1 file changed, 73 deletions(-) delete mode 100644 crates/fspy/tests/shell_semantics.rs diff --git a/crates/fspy/tests/shell_semantics.rs b/crates/fspy/tests/shell_semantics.rs deleted file mode 100644 index da18c569a..000000000 --- a/crates/fspy/tests/shell_semantics.rs +++ /dev/null @@ -1,73 +0,0 @@ -//! Shell behavior that tracked tasks depend on. On macOS, fspy runs the -//! bundled Oils shell in place of `/bin/sh` and `/bin/bash`, so these tests -//! check that it behaves like the real shells, which run on Linux. -#![cfg(unix)] -mod test_utils; - -use std::process::{Command, Stdio}; - -use test_log::test; - -/// Runs `script` with `shell -c` and returns its exit code and stdout. -fn run(shell: &str, script: &str) -> (Option, String) { - let output = Command::new(shell) - .arg("-c") - .arg(script) - .stdin(Stdio::null()) - .output() - .expect("failed to run the shell"); - (output.status.code(), String::from_utf8(output.stdout).expect("stdout is not UTF-8")) -} - -/// Under `set -e`, a loop with a redirect must not exit when its last -/// `test ... && ...` fails. -#[test(tokio::test)] -async fn errexit_ignores_status_of_compound_command_with_redirect() -> anyhow::Result<()> { - track_fn!((), |(): ()| { - let script = "set -e -found=0 -while read -r line; do - test \"$line\" = key && found=1 -done < anyhow::Result<()> { - track_fn!((), |(): ()| { - let script = "trap 'st=$?; trap - EXIT; true; exit $st' EXIT; exit 7"; - assert_eq!(run("/bin/sh", script), (Some(7), String::new())); - }) - .await?; - Ok(()) -} - -/// A bare `exit` in an EXIT trap keeps the status from before the trap. -#[test(tokio::test)] -async fn bare_exit_in_exit_trap_keeps_status() -> anyhow::Result<()> { - track_fn!((), |(): ()| { - assert_eq!(run("/bin/sh", "trap exit EXIT; exit 3"), (Some(3), String::new())); - }) - .await?; - Ok(()) -} - -/// `$BASH` is set when the shell runs as `bash`. -#[test(tokio::test)] -async fn bash_variable_is_set() -> anyhow::Result<()> { - track_fn!((), |(): ()| { - let (code, stdout) = run("/bin/bash", "echo \"$BASH\""); - assert_eq!(code, Some(0)); - assert_ne!(stdout.trim(), "", "$BASH is empty"); - }) - .await?; - Ok(()) -}