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
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Decision: check out LF on every host. Tests parse shell fixtures, spec cases,
# workflow files and snapshot payloads byte for byte, and a Windows checkout
# with core.autocrlf rewrote them to CRLF (found by the Windows nightly).
* text=auto eol=lf

# Snapshot fixtures are byte-exact binary formats; never convert them.
crates/bashkit/tests/fixtures/snapshots/** binary
58 changes: 58 additions & 0 deletions .github/workflows/windows-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Decision: bashkit's VFS is `/`-separated on every host (TM-ESC-033), but
# Windows-only path bugs (#2425, #2933) are invisible to Linux CI and to the
# Linux fuzzers, because the Linux host separator already is `/`. PR CI runs
# only targeted Windows filters (`windows_containment`, adoption suites) to
# stay fast. This nightly job runs the bashkit lib and integration suites and
# the proptest security suite on windows-latest, so the rest of the code is
# exercised there too. Tests that compare against host Unix tools (bash, GNU
# coreutils, jq, rg, sqlite3) skip their oracle step off unix.
#
# It also runs on PRs that edit this file, so a change here is trial-run
# before it lands.
name: Windows nightly

on:
schedule:
# 5 AM UTC daily (after nightly at 4 AM)
- cron: '0 5 * * *'
workflow_dispatch:
pull_request:
paths:
- .github/workflows/windows-nightly.yml

permissions:
contents: read

concurrency:
group: windows-nightly-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
windows-tests:
name: Windows full test suite
runs-on: windows-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@9522411a9bce8484da960823fc2f46e52f981f71 # 1.100.0

- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
with:
shared-key: windows-nightly

- name: Library tests
run: cargo test -p bashkit --lib --features http_client,realfs

- name: Integration tests
run: cargo test -p bashkit --test integration --features http_client,realfs

- name: Property-based security tests
run: cargo test -p bashkit --test proptest_security -- --test-threads=1
4 changes: 3 additions & 1 deletion crates/bashkit/clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
# turn `/a` + `b` into `/a\b`. That broke `/dev/stderr` redirects (#2933) and
# printed mixed separators (#2425); Linux CI and fuzzing cannot see it because
# the host separator there is already `/`. Build VFS paths with
# `crate::fs::vfs_join` instead. Code that really handles host paths (RealFs,
# `crate::fs::vfs_join` instead, and ask `has_root()`, not `is_absolute()`,
# whether a VFS path is absolute. Code that really handles host paths (RealFs,
# host mounts, test temp dirs) opts out with a scoped
# `#[allow(clippy::disallowed_methods)]` and a reason.
disallowed-methods = [
{ path = "std::path::Path::join", reason = "joins with the host separator (`\\` on Windows); use crate::fs::vfs_join for VFS paths" },
{ path = "std::path::PathBuf::push", reason = "joins with the host separator (`\\` on Windows); use crate::fs::vfs_join for VFS paths" },
{ path = "std::path::PathBuf::set_file_name", reason = "joins with the host separator (`\\` on Windows); build VFS paths with crate::fs::vfs_join" },
{ path = "std::path::Path::with_file_name", reason = "joins with the host separator (`\\` on Windows); build VFS paths with crate::fs::vfs_join" },
{ path = "std::path::Path::is_absolute", reason = "false for `/etc/x` on Windows (no drive prefix); VFS paths ask `has_root()`" },
]
1 change: 0 additions & 1 deletion crates/bashkit/src/builtins/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@ fn validate_tar_for_extraction(
// and this arm never fired (issue #2425's class). The
// `starts_with(extract_base)` arm below still blocked the write.
if entry.has_root()
|| entry.is_absolute()
|| entry
.components()
.any(|component| matches!(component, std::path::Component::ParentDir))
Expand Down
4 changes: 2 additions & 2 deletions crates/bashkit/src/builtins/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Builtin for Cat {
raw.try_extend_from_slice(&input.read_to_end().await?)?;
}
} else {
let path = if Path::new(file).is_absolute() {
let path = if Path::new(file).has_root() {
file.clone()
} else {
vfs_join(ctx.cwd, file).to_string_lossy().into_owned()
Expand Down Expand Up @@ -166,7 +166,7 @@ async fn stream_plain(
}
ok
} else {
let path = if Path::new(file).is_absolute() {
let path = if Path::new(file).has_root() {
file.clone()
} else {
vfs_join(ctx.cwd, file).to_string_lossy().into_owned()
Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/git/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl GitClient {

// Add files
for path_str in paths {
let path = if Path::new(path_str).is_absolute() {
let path = if Path::new(path_str).has_root() {
PathBuf::from(path_str)
} else {
vfs_join(repo_path, path_str)
Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/grep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ async fn try_indexed_search(
let mut path_leases = budgeted_vec(ctx)?;
for m in &results.matches {
ctx.consume_budget_work(1)?;
let candidate = if m.path.is_absolute() {
let candidate = if m.path.has_root() {
crate::fs::normalize_path(&m.path)
} else {
crate::fs::normalize_path(&vfs_join(root, &m.path))
Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ pub enum ExecutionPlan {
/// ```
pub fn resolve_path(cwd: &Path, path_str: &str) -> PathBuf {
let path = Path::new(path_str);
let joined = if path.is_absolute() {
let joined = if path.has_root() {
path.to_path_buf()
} else {
vfs_join(cwd, path)
Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ async fn follow_readlink_symlinks(
return None;
}
let link_parent = current.parent().unwrap_or_else(|| Path::new("/"));
let mut next = if target.is_absolute() {
let mut next = if target.has_root() {
target
} else {
vfs_join(link_parent, target)
Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ async fn open_vfs_file(path: &Path, mode: FileMode, fs: &Arc<dyn FileSystem>) ->
/// Resolve a Python path string against cwd if relative.
fn resolve_python_path(path_str: &str, cwd: &Path) -> PathBuf {
let p = Path::new(path_str);
if p.is_absolute() {
if p.has_root() {
p.to_owned()
} else {
vfs_join(cwd, p)
Expand Down
4 changes: 2 additions & 2 deletions crates/bashkit/src/builtins/rg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3704,7 +3704,7 @@ async fn resolve_rg_symlink_target(
containment_root: &Path,
) -> Option<(PathBuf, crate::fs::Metadata)> {
let target = fs.read_link(link_path).await.ok()?;
let resolved = if target.is_absolute() {
let resolved = if target.has_root() {
crate::fs::normalize_path(&target)
} else {
crate::fs::normalize_path(&vfs_join(
Expand Down Expand Up @@ -4219,7 +4219,7 @@ async fn try_indexed_search(
let mut ignore: Option<RgIndexIgnore<'_>> = None;
let uses_ignore = opts.uses_ignore_files() && !explicit_file_root;
for m in &results.matches {
let candidate = if m.path.is_absolute() {
let candidate = if m.path.has_root() {
crate::fs::normalize_path(&m.path)
} else {
crate::fs::normalize_path(&vfs_join(&root, &m.path))
Expand Down
4 changes: 2 additions & 2 deletions crates/bashkit/src/builtins/shuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Builtin for Shuf {
None => ctx.stdin.map(ToString::to_string).unwrap_or_default(),
Some(s) if s == "-" => ctx.stdin.map(ToString::to_string).unwrap_or_default(),
Some(file) => {
let path = if Path::new(file).is_absolute() {
let path = if Path::new(file).has_root() {
file.clone()
} else {
vfs_join(ctx.cwd, file).to_string_lossy().into_owned()
Expand Down Expand Up @@ -122,7 +122,7 @@ impl Builtin for Shuf {
};

if let Some(path) = output_path {
let resolved = if path.is_absolute() {
let resolved = if path.has_root() {
path.clone()
} else {
vfs_join(ctx.cwd, &path)
Expand Down
6 changes: 1 addition & 5 deletions crates/bashkit/src/builtins/sqlite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,11 +840,7 @@ async fn run_statements(
Ok(DotOutcome::Configured) => {}
Ok(DotOutcome::Quit) => return Ok(()),
Ok(DotOutcome::Read(p)) => {
let abs = if p.is_absolute() {
p
} else {
vfs_join(cwd, &p)
};
let abs = if p.has_root() { p } else { vfs_join(cwd, &p) };
let bytes = fs
.read_file(&abs)
.await
Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Builtin for Bracket {
/// Resolve a file path against cwd (relative paths become absolute)
fn resolve_file_path(cwd: &Path, arg: &str) -> PathBuf {
let p = Path::new(arg);
if p.is_absolute() {
if p.has_root() {
p.to_path_buf()
} else {
vfs_join(cwd, p)
Expand Down
4 changes: 2 additions & 2 deletions crates/bashkit/src/builtins/textrev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn read_input(ctx: &Context<'_>) -> std::result::Result<String, Box<ExecRe
raw.push_str(stdin);
}
} else {
let path = if Path::new(file).is_absolute() {
let path = if Path::new(file).has_root() {
file.to_string()
} else {
vfs_join(ctx.cwd, file).to_string_lossy().to_string()
Expand Down Expand Up @@ -153,7 +153,7 @@ async fn read_tac_file(
if file == "-" {
return Ok(ctx.stdin.map(ToString::to_string).unwrap_or_default());
}
let path = if Path::new(file).is_absolute() {
let path = if Path::new(file).has_root() {
file.to_string()
} else {
vfs_join(ctx.cwd, file).to_string_lossy().into_owned()
Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ fn extract_path(args: &[Value], cwd: &Path) -> Option<PathBuf> {
match args.first()? {
Value::String(s) => {
let p = Path::new(s.as_ref());
if p.is_absolute() {
if p.has_root() {
Some(p.to_owned())
} else {
Some(vfs_join(cwd, p))
Expand Down
4 changes: 3 additions & 1 deletion crates/bashkit/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ impl CommandOutput {
.await??;
}
Destination::Discard => {}
Destination::Closed => return Err(std::io::Error::from_raw_os_error(9).into()),
// Fixed text, not `from_raw_os_error(9)`: errno 9 is EBADF only on
// unix (Windows renders a host message), and bash prints no errno.
Destination::Closed => return Err(std::io::Error::other("Bad file descriptor").into()),
Destination::Pipe(pipe) => self.budget.run(pipe.write_bounded(bytes)).await??,
Destination::Capture(capture) => {
let mut capture = capture.lock().unwrap_or_else(|e| e.into_inner());
Expand Down
4 changes: 3 additions & 1 deletion crates/bashkit/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ impl<'a> Execution<'a> {
let session_cancel = self.bash.cancellation_token();
let output_file = match self.output_file {
Some((path, max_bytes)) => {
if !path.is_absolute() {
// `has_root`, not `is_absolute`: a VFS path like `/tmp/out.log`
// has no drive prefix, so `is_absolute` is false on Windows.
if !path.has_root() {
return Err(crate::Error::Execution(format!(
"output file must be an absolute path: {}",
path.display()
Expand Down
4 changes: 2 additions & 2 deletions crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6067,7 +6067,7 @@ impl Interpreter {
// Unary operators
let resolve = |p: &str| -> std::path::PathBuf {
let path = std::path::Path::new(p);
let joined = if path.is_absolute() {
let joined = if path.has_root() {
path.to_path_buf()
} else {
crate::fs::vfs_join(&self.cwd, path)
Expand Down Expand Up @@ -12941,7 +12941,7 @@ impl Interpreter {
/// Resolve a path relative to cwd, normalizing `.` and `..` components.
fn resolve_path(&self, path: &str) -> PathBuf {
let p = Path::new(path);
let joined = if p.is_absolute() {
let joined = if p.has_root() {
p.to_path_buf()
} else {
crate::fs::vfs_join(&self.cwd, p)
Expand Down
1 change: 1 addition & 0 deletions crates/bashkit/tests/integration/archive_bzip2_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn tar_with_entry(name: &str, content: &[u8]) -> Vec<u8> {
}

#[tokio::test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
async fn bashkit_tar_bzip2_output_is_readable_by_system_tar() {
let mut bash = Bash::new();
let setup = bash
Expand Down
2 changes: 2 additions & 0 deletions crates/bashkit/tests/integration/arithmetic_resource_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async fn arithmetic_dollar_siblings_share_expansion_fuel() {
}

#[tokio::test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
async fn arithmetic_dollar_subscripts_match_bash_within_limits() {
let expr = nested_array_expansion(4, false);
// NOTE: subscript stays portable on purpose: macOS ships bash 3.2 with no
Expand Down Expand Up @@ -229,6 +230,7 @@ async fn arithmetic_array_key_size_boundary() {
}

#[tokio::test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
async fn arithmetic_array_keys_match_modern_bash() {
let version = std::process::Command::new("bash")
.args(["--noprofile", "--norc", "-c", "echo ${BASH_VERSINFO[0]}"])
Expand Down
1 change: 1 addition & 0 deletions crates/bashkit/tests/integration/backtick_quote_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bashkit::{Bash, CommandPlacement, ExecutionLimits};
use std::sync::{Arc, Mutex};

#[tokio::test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
async fn backticks_after_quotes_match_bash() {
let cases = [
r#"printf '[%s]\n' 'x'`printf '1 2'`; echo tail"#,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ mod finding_nested_cmd_subst_stack_overflow {
}

#[tokio::test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
async fn moderate_substitutions_match_real_bash() {
for template in [
"echo $(BODY)",
Expand Down
3 changes: 3 additions & 0 deletions crates/bashkit/tests/integration/byte_stream_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ async fn command_substitution_drops_nuls_at_text_boundary() {
}

#[tokio::test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
async fn binary_pipeline_matches_real_bash_byte_for_byte() {
let script = "printf 'AAHDqf/+QgB/' | base64 -d | head -c 8 | cat";
let expected = Command::new("bash").args(["-c", script]).output().unwrap();
Expand Down Expand Up @@ -189,6 +190,7 @@ async fn iconv_repairs_cp_export_and_writes_real_bytes() {
}

#[tokio::test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
async fn iconv_matches_real_iconv_byte_for_byte() {
// Skip where the host has no iconv; CI runners ship glibc's.
if Command::new("iconv").arg("-l").output().is_err() {
Expand Down Expand Up @@ -218,6 +220,7 @@ async fn iconv_matches_real_iconv_byte_for_byte() {

#[cfg(feature = "iconv_charsets")]
#[tokio::test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
async fn iconv_code_pages_match_real_iconv() {
if Command::new("iconv").arg("-l").output().is_err() {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ async fn competitor_regressions_stay_green_without_network() {
}

#[test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
fn competitor_real_bash_oracles_match_locked_expectations() {
let bash = host_program("bash");
let bash_major = bash_major(&bash);
Expand Down
1 change: 1 addition & 0 deletions crates/bashkit/tests/integration/curl_data_compat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ async fn differential_real_curl_matches_mixed_post_data() {
}

#[tokio::test]
#[cfg_attr(not(unix), ignore = "compares against host Unix bash/tools")]
async fn differential_real_curl_matches_get_query_aggregation() {
let expected = run_real_curl(&[
"-G",
Expand Down
21 changes: 5 additions & 16 deletions crates/bashkit/tests/integration/custom_fs_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,10 @@ impl MinimalFs {
}

fn normalize_path(path: &Path) -> PathBuf {
let mut result = PathBuf::new();
for component in path.components() {
match component {
std::path::Component::RootDir => result.push("/"),
std::path::Component::Normal(name) => result.push(name),
std::path::Component::ParentDir => {
result.pop();
}
_ => {}
}
}
if result.as_os_str().is_empty() {
result.push("/");
}
result
// bashkit's normalizer joins with `/` on every host; a `PathBuf::push`
// rebuild keyed entries as `/data\nested` on Windows and broke the
// `/`-prefix scan in `read_dir`.
bashkit::normalize_path(path)
}
}

Expand Down Expand Up @@ -82,7 +71,7 @@ impl FileSystem for MinimalFs {
if recursive {
let mut current = PathBuf::new();
for component in path.components() {
current.push(component);
current = bashkit::vfs_join(&current, component);
let mut files = self.files.write().unwrap();
files.entry(current.clone()).or_default();
}
Expand Down
Loading
Loading