From fc7d1e1cd605bb1f64bab549f814a3674b22076f Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Wed, 18 Nov 2026 20:22:49 +0000 Subject: [PATCH 1/2] test(compat): make GNU parity fixtures portable --- .../bashkit/tests/integration/spec_runner.rs | 13 +++++++++---- .../bashkit/tests/spec_cases/bash/fmt.test.sh | 14 +++++++++++--- .../bashkit/tests/spec_cases/bash/jobs.test.sh | 2 +- .../tests/spec_cases/bash/script-exec.test.sh | 16 ++++++++-------- .../bash/subprocess-isolation.test.sh | 8 ++++---- scripts/update-spec-expected.sh | 18 ++++++++++-------- 6 files changed, 43 insertions(+), 28 deletions(-) diff --git a/crates/bashkit/tests/integration/spec_runner.rs b/crates/bashkit/tests/integration/spec_runner.rs index 9758fc086..ee84a54b6 100644 --- a/crates/bashkit/tests/integration/spec_runner.rs +++ b/crates/bashkit/tests/integration/spec_runner.rs @@ -264,18 +264,23 @@ async fn run_spec_test_paused_time(test: &SpecTest) -> TestResult { /// Run a spec test against real bash for comparison pub fn run_real_bash(script: &str) -> (String, i32) { - // Important decision: host bash comparison is untrusted spec input. Run it - // from a private temp directory, and remap hard-coded /tmp paths there, so - // redirects cannot clobber host or repo files while stdout parity remains /tmp-based. + // Run the host comparison from a private directory and remap fixture paths + // under /tmp. Scripts that assume Bashkit's synthetic root must opt out of + // the host comparison. let sandbox = tempfile::tempdir().expect("Failed to create bash comparison tempdir"); let sandbox_tmp = sandbox.path().to_string_lossy(); let sandbox_tmp_prefix = format!("{sandbox_tmp}/"); - let rewritten_script = script.replace("/tmp/", &sandbox_tmp_prefix); + // Match the interpreter's initial file creation mask. + let rewritten_script = format!( + "umask 022\n{}", + script.replace("/tmp/", &sandbox_tmp_prefix) + ); let output = Command::new("bash") .arg("-c") .arg(&rewritten_script) .current_dir(sandbox.path()) .env("TMPDIR", sandbox.path()) + .env_remove("BASH_ENV") // A bashkit script is a top-level shell; drop the test runner's own // SHLVL so real bash starts at 1 too. .env_remove("SHLVL") diff --git a/crates/bashkit/tests/spec_cases/bash/fmt.test.sh b/crates/bashkit/tests/spec_cases/bash/fmt.test.sh index 880c2ae45..1dcd5067f 100644 --- a/crates/bashkit/tests/spec_cases/bash/fmt.test.sh +++ b/crates/bashkit/tests/spec_cases/bash/fmt.test.sh @@ -110,9 +110,17 @@ rc=1 ### end ### fmt_goal_over_width -LC_ALL=C fmt -w 20 -g 30 &1; echo "rc=$?" -### expect -fmt: invalid width: '30': Numerical result out of range +# GNU coreutils versions use different errno messages for this bound. +diagnostic=$(LC_ALL=C fmt -w 20 -g 30 &1) +rc=$? +case "$diagnostic" in + *": Numerical result out of range"|*": Value too large for defined data type") + diagnostic=${diagnostic%: *} + ;; +esac +printf '%s\nrc=%s\n' "$diagnostic" "$rc" +### expect +fmt: invalid width: '30' rc=1 ### end diff --git a/crates/bashkit/tests/spec_cases/bash/jobs.test.sh b/crates/bashkit/tests/spec_cases/bash/jobs.test.sh index 9d7fa0b4c..6c90efa6d 100644 --- a/crates/bashkit/tests/spec_cases/bash/jobs.test.sh +++ b/crates/bashkit/tests/spec_cases/bash/jobs.test.sh @@ -84,7 +84,7 @@ code=1 ### jobs_list_running sleep 2 & sleep 3 & true & -sleep 0.1 +wait %3 jobs jobs -p | wc -l kill %1 %2 diff --git a/crates/bashkit/tests/spec_cases/bash/script-exec.test.sh b/crates/bashkit/tests/spec_cases/bash/script-exec.test.sh index 8f1254721..410df1295 100644 --- a/crates/bashkit/tests/spec_cases/bash/script-exec.test.sh +++ b/crates/bashkit/tests/spec_cases/bash/script-exec.test.sh @@ -94,11 +94,11 @@ inner ### script_exec_path_search # $PATH search finds executable -mkdir -p /usr/local/bin +mkdir -p /tmp/bin echo '#!/bin/bash -echo found via path' > /usr/local/bin/myutil -chmod +x /usr/local/bin/myutil -PATH=/usr/local/bin +echo found via path' > /tmp/bin/myutil +chmod +x /tmp/bin/myutil +PATH=/tmp/bin myutil ### expect found via path @@ -131,14 +131,14 @@ got: test input ### script_exec_pipe_stdin_path_search # Piped stdin works for PATH-based script execution -mkdir -p /usr/local/bin -cat > /usr/local/bin/my-tool <<'SCRIPT' +mkdir -p /tmp/bin +cat > /tmp/bin/my-tool <<'SCRIPT' #!/usr/bin/env bash input="$(cat)" echo "received: ${input}" SCRIPT -chmod +x /usr/local/bin/my-tool -export PATH="/usr/local/bin:${PATH}" +chmod +x /tmp/bin/my-tool +export PATH="/tmp/bin:${PATH}" echo "data" | my-tool ### expect received: data diff --git a/crates/bashkit/tests/spec_cases/bash/subprocess-isolation.test.sh b/crates/bashkit/tests/spec_cases/bash/subprocess-isolation.test.sh index 641f1423d..c8a69a3cc 100644 --- a/crates/bashkit/tests/spec_cases/bash/subprocess-isolation.test.sh +++ b/crates/bashkit/tests/spec_cases/bash/subprocess-isolation.test.sh @@ -128,15 +128,15 @@ parent still: parent not_exported="hidden" export VISIBLE="yes" -mkdir -p /usr/local/bin -cat > /usr/local/bin/check-isolation <<'SCRIPT' +mkdir -p /tmp/bin +cat > /tmp/bin/check-isolation <<'SCRIPT' #!/usr/bin/env bash echo "visible=${VISIBLE:-unset}" echo "hidden=${not_exported:-unset}" SCRIPT -chmod +x /usr/local/bin/check-isolation +chmod +x /tmp/bin/check-isolation -PATH="/usr/local/bin:${PATH}" check-isolation +PATH="/tmp/bin:${PATH}" check-isolation ### expect visible=yes hidden=unset diff --git a/scripts/update-spec-expected.sh b/scripts/update-spec-expected.sh index 9e1db4064..54c9f0a3c 100755 --- a/scripts/update-spec-expected.sh +++ b/scripts/update-spec-expected.sh @@ -58,21 +58,24 @@ done cd "$ROOT_DIR" +if ! command -v bc >/dev/null; then + echo "Strict Bash parity requires GNU bc on PATH." >&2 + exit 1 +fi + echo "Checking spec tests against real bash..." echo "" +test_args=(--test integration -- spec_tests:: --ignored) if $VERBOSE; then - cargo test --test integration -- spec_tests:: --ignored --nocapture 2>&1 -else - cargo test --test integration -- spec_tests:: --ignored 2>&1 + test_args+=(--nocapture) fi -exit_code=$? - -if [[ $exit_code -eq 0 ]]; then +if cargo test "${test_args[@]}" 2>&1; then echo "" echo "All non-excluded tests match real bash." else + exit_code=$? echo "" echo "Some tests have differences from real bash." echo "" @@ -81,6 +84,5 @@ else echo " 2. Add '### bash_diff: reason' if the difference is intentional" echo "" echo "Run with --verbose to see all comparisons." + exit "$exit_code" fi - -exit $exit_code From acf756a993460a41da653008888e327174166d05 Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Wed, 18 Nov 2026 20:26:48 +0000 Subject: [PATCH 2/2] test(compat): preserve Bash oracle line numbers --- crates/bashkit/tests/integration/spec_runner.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/bashkit/tests/integration/spec_runner.rs b/crates/bashkit/tests/integration/spec_runner.rs index ee84a54b6..e102aadfb 100644 --- a/crates/bashkit/tests/integration/spec_runner.rs +++ b/crates/bashkit/tests/integration/spec_runner.rs @@ -270,17 +270,18 @@ pub fn run_real_bash(script: &str) -> (String, i32) { let sandbox = tempfile::tempdir().expect("Failed to create bash comparison tempdir"); let sandbox_tmp = sandbox.path().to_string_lossy(); let sandbox_tmp_prefix = format!("{sandbox_tmp}/"); - // Match the interpreter's initial file creation mask. - let rewritten_script = format!( - "umask 022\n{}", - script.replace("/tmp/", &sandbox_tmp_prefix) - ); + let rewritten_script = script.replace("/tmp/", &sandbox_tmp_prefix); + // Set the initial mask outside the fixture so its line numbers stay intact. + let oracle_env = + tempfile::NamedTempFile::new().expect("Failed to create Bash oracle init file"); + fs::write(oracle_env.path(), "umask 022\nunset BASH_ENV\n") + .expect("Failed to write Bash oracle init file"); let output = Command::new("bash") .arg("-c") .arg(&rewritten_script) .current_dir(sandbox.path()) .env("TMPDIR", sandbox.path()) - .env_remove("BASH_ENV") + .env("BASH_ENV", oracle_env.path()) // A bashkit script is a top-level shell; drop the test runner's own // SHLVL so real bash starts at 1 too. .env_remove("SHLVL")