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
44 changes: 44 additions & 0 deletions .github/workflows/rrx-windows-acceptance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: RRX Windows acceptance

on:
push:
branches: ["rrx/integrate-607-610-20260921"]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: rrx-windows-${{ github.ref }}
cancel-in-progress: false

jobs:
windows-acceptance:
runs-on: windows-2022
timeout-minutes: 45
env:
CARGO_TERM_COLOR: never
CARGO_BUILD_JOBS: "2"
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
fetch-depth: 0
persist-credentials: false
- name: Prepare standard Rust toolchain
shell: pwsh
run: |
rustup toolchain install stable --profile minimal --component rustfmt
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
rustup override set stable
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
rustc --version
cargo --version
git rev-parse HEAD
- name: Formatting
run: cargo fmt --all -- --check
- name: Complete default Runner regression
run: cargo test --locked -p webcodex-runner -- --test-threads=1
- name: Explicit shell and validation stdin isolation
run: cargo test --locked -p webcodex-runner job_stdin_isolated -- --ignored --test-threads=1
- name: Startup summary contracts
run: cargo test --locked -p webcodex --lib semantic_navigation -- --test-threads=1
4 changes: 4 additions & 0 deletions crates/webcodex-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ windows-sys = { version = "0.61.2", features = [
"Win32_Foundation",
"Win32_Globalization",
"Win32_Storage_FileSystem",
"Win32_System_IO",
"Win32_System_Pipes",
"Win32_System_Threading",
] }

Expand All @@ -51,5 +53,7 @@ windows-sys = { version = "0.61.2", features = [
[target.'cfg(windows)'.dev-dependencies]
windows-sys = { version = "0.61.2", features = [
"Win32_Foundation",
"Win32_Security",
"Win32_System_Pipes",
"Win32_System_Threading",
] }
39 changes: 39 additions & 0 deletions crates/webcodex-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4699,8 +4699,11 @@ impl JobManager {
.map(|(key, value)| (key.as_str(), value.as_str())),
);
}
// Raw Shell Jobs and validation steps have no stdin payload.
// Preserve the Runner parent-liveness pipe for the Runner alone.
command
.current_dir(&cwd_path)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
commands.push_back(command);
Expand Down Expand Up @@ -5734,7 +5737,43 @@ fn handle_one_poll(
.map_err(PollError::from_submit)
}

#[cfg(windows)]
fn isolate_inherited_standard_pipes() -> std::io::Result<()> {
use std::os::windows::io::AsRawHandle;
use windows_sys::Win32::Foundation::{
SetHandleInformation, HANDLE_FLAG_INHERIT, INVALID_HANDLE_VALUE,
};
use windows_sys::Win32::Storage::FileSystem::{GetFileType, FILE_TYPE_PIPE};

// Parent leases and capture pipes belong to this process. Explicit child
// stdio is prepared separately by Command; unrelated inheritable copies
// must not keep the Desktop's readers alive after this Runner exits.
for handle in [
std::io::stdin().as_raw_handle(),
std::io::stdout().as_raw_handle(),
std::io::stderr().as_raw_handle(),
] {
if handle.is_null() || handle == INVALID_HANDLE_VALUE {
continue;
}
// SAFETY: standard handles are borrowed from this process, never closed
// or retargeted here. Only the inheritance bit of actual pipes changes.
if unsafe { GetFileType(handle) } == FILE_TYPE_PIPE
&& unsafe { SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0) } == 0
{
return Err(std::io::Error::last_os_error());
}
}
Ok(())
}

fn main() {
// Run before threads, providers, or the detached internal mode can spawn.
#[cfg(windows)]
if let Err(error) = isolate_inherited_standard_pipes() {
eprintln!("webcodex-runner cannot isolate parent standard pipes: {error}");
std::process::exit(1);
}
if let Some(code) =
webcodex_runner::detached_job::maybe_run_internal_mode(std::env::args().skip(1))
{
Expand Down
4 changes: 4 additions & 0 deletions crates/webcodex-runner/src/main_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::*;

#[cfg(windows)]
#[path = "main_tests/stdio_inheritance.rs"]
mod stdio_inheritance;
use crate::webcodex_runner::config::validate_shell_config;
use crate::webcodex_runner::run_shell_with_profiles;
use crate::webcodex_runner::{
Expand Down
14 changes: 11 additions & 3 deletions crates/webcodex-runner/src/main_tests/file_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ fn runner_file_read_range_output_obeys_max_bytes() {
#[test]
fn runner_file_read_range_rejects_serialized_envelope_expansion_before_stdout() {
for (name, byte, len) in [
("nul.txt", 0x00, 48 * 1024),
// NUL is a reserved Windows device name even with a .txt suffix.
// Exercise NUL bytes in an ordinary file, not the device namespace.
("nul-bytes.txt", 0x00, 48 * 1024),
("quote.txt", b'\"', 140 * 1024),
("backslash.txt", b'\\', 140 * 1024),
("control.txt", 0x01, 48 * 1024),
] {
let tmp = tempfile::tempdir().unwrap();
let policy = project_policy(tmp.path());
std::fs::write(tmp.path().join(name), vec![byte; len]).unwrap();
let fixture = vec![byte; len];
std::fs::write(tmp.path().join(name), &fixture).unwrap();
assert_eq!(std::fs::read(tmp.path().join(name)).unwrap(), fixture);
let out = handle_file_request(
&policy,
&file_read_request(tmp.path(), name, Some(1), Some(1), Some(512 * 1024)),
Expand All @@ -146,7 +150,11 @@ fn runner_file_read_range_rejects_serialized_envelope_expansion_before_stdout()
out.exit_code.is_none(),
"unexpected success for {name}: {out:?}"
);
assert_eq!(out.error.as_deref(), Some("range output too large"));
assert_eq!(
out.error.as_deref(),
Some("range output too large"),
"unexpected range result for {name}"
);
assert!(
out.stdout.is_none(),
"oversized envelope reached stdout for {name}"
Expand Down
131 changes: 131 additions & 0 deletions crates/webcodex-runner/src/main_tests/stdio_inheritance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//! Real Windows pipe inheritance, isolated from the test harness's own stdio.
use super::*;
use std::io::Read;
use std::process::{Command, Stdio};
use std::sync::mpsc;
use webcodex_process::ManagedChild;

const TEST_NAME: &str =
"tests::stdio_inheritance::standard_pipes_do_not_leak_to_unrelated_descendants";
const MODE: &str = "WEBCODEX_STDIO_INHERITANCE_FIXTURE";
const READY: &str = "WEBCODEX_STDIO_INHERITANCE_READY";

fn fixture_command(mode: &str) -> Command {
let mut command = Command::new(std::env::current_exe().unwrap());
command.args(["--exact", TEST_NAME, "--nocapture"]);
command.env(MODE, mode);
command
}

#[test]
fn standard_pipes_do_not_leak_to_unrelated_descendants() {
match std::env::var(MODE).as_deref() {
Ok("descendant") => {
std::fs::write(std::env::var_os(READY).unwrap(), b"ready").unwrap();
// The outer ManagedChild owns this whole fixture tree. It terminates
// the still-live descendant only after checking capture EOF.
std::thread::sleep(Duration::from_secs(60));
return;
}
Ok("explicit-inherit") => {
println!("EXPLICIT_CHILD_STDOUT");
eprintln!("EXPLICIT_CHILD_STDERR");
return;
}
Ok("worker") => {
isolate_inherited_standard_pipes().unwrap();
println!("PARENT_STDOUT_PRESERVED");
eprintln!("PARENT_STDERR_PRESERVED");
let status = fixture_command("explicit-inherit")
.stdin(Stdio::null())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.unwrap();
assert!(status.success());
let ready = PathBuf::from(std::env::var_os(READY).unwrap());
// Deliberately outlive the direct worker. The external ManagedChild
// owns and reaps both; dropping this Child does not kill it early.
#[allow(clippy::zombie_processes)]
let _descendant = fixture_command("descendant")
.env(READY, &ready)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.unwrap();
let deadline = Instant::now() + Duration::from_secs(15);
while !ready.is_file() {
assert!(Instant::now() < deadline, "descendant did not start");
std::thread::sleep(Duration::from_millis(10));
}
return;
}
Ok(other) => panic!("unexpected fixture mode: {other}"),
Err(_) => {}
}

let temp = tempfile::tempdir().unwrap();
let mut command = fixture_command("worker");
command
.env(READY, temp.path().join("ready"))
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
let mut worker = ManagedChild::spawn(&mut command).unwrap();
let stdout = worker.child_mut().stdout.take().unwrap();
let stderr = worker.child_mut().stderr.take().unwrap();
let (tx, rx) = mpsc::channel();
let stdout_tx = tx.clone();
let stdout_reader = std::thread::spawn(move || {
let mut bytes = Vec::new();
let result = std::io::BufReader::new(stdout).read_to_end(&mut bytes);
let _ = stdout_tx.send(("stdout", result, bytes));
});
let stderr_reader = std::thread::spawn(move || {
let mut bytes = Vec::new();
let result = std::io::BufReader::new(stderr).read_to_end(&mut bytes);
let _ = tx.send(("stderr", result, bytes));
});
let validation = (|| -> Result<(), String> {
let deadline = Instant::now() + Duration::from_secs(20);
let status = loop {
if let Some(status) = worker.try_wait().map_err(|e| e.to_string())? {
break status;
}
if Instant::now() >= deadline {
return Err("stdio worker did not exit".into());
}
std::thread::sleep(Duration::from_millis(10));
};
if !status.success() {
return Err(format!("stdio worker failed: {status}"));
}
if worker.try_tree_exit().map_err(|e| e.to_string())? {
return Err("descendant exited before the pipe inheritance assertion".into());
}
for _ in 0..2 {
let (stream, read, bytes) = rx
.recv_timeout(Duration::from_secs(2))
.map_err(|_| "capture pipe stayed open after the direct worker exited")?;
read.map_err(|e| e.to_string())?;
let text = String::from_utf8(bytes).map_err(|e| e.to_string())?;
let expected = if stream == "stdout" {
["PARENT_STDOUT_PRESERVED", "EXPLICIT_CHILD_STDOUT"]
} else {
["PARENT_STDERR_PRESERVED", "EXPLICIT_CHILD_STDERR"]
};
if !expected.iter().all(|marker| text.contains(marker)) {
return Err(format!("explicit {stream} output was lost"));
}
}
Ok(())
})();
// Cleanup occurs before asserting the result, including the regression's
// failure path. No unrelated process or numeric process-tree lookup is used.
worker.terminate_tree().unwrap();
assert!(worker.wait_tree_exit(Duration::from_secs(5)).unwrap());
stdout_reader.join().unwrap();
stderr_reader.join().unwrap();
validation.unwrap();
}
Loading
Loading