use super::*;
const RUFF_CHECK: &str = "ruff check --isolated --select=F,E9 --output-format=json --exit-zero '/tmp/work/hello.py' 2>/dev/null";
#[test]
fn a_redirect_to_a_standard_stream_is_not_outside_the_workspace() {
for command in [
RUFF_CHECK,
"echo hi 2>/dev/null",
"echo hi >/dev/null 2>&1",
"echo hi > /dev/stderr",
"cat /dev/stdin > /tmp/work/out.txt",
"echo hi 2>/dev/fd/2",
] {
assert!(
!is_outside_workspace(command),
"a standard I/O device is not a workspace path: {command}"
);
}
let scan = command_risk_scan_json(&shell_ctx(RUFF_CHECK), None);
assert_eq!(scan["action"], "allow", "{scan}");
}
#[test]
fn other_absolute_paths_beside_a_discarded_stream_are_still_outside() {
for command in [
"ruff check '/etc/hello.py' 2>/dev/null",
"echo hi > /etc/harn-output 2>/dev/null",
"echo hi > /dev/sda",
"echo hi > /dev/fd/",
"cat /dev/nullx",
] {
assert!(
is_outside_workspace(command),
"an absolute path outside the roots must still be flagged: {command}"
);
}
}
#[cfg(windows)]
#[test]
fn native_windows_paths_do_not_inherit_posix_stream_exemptions() {
for context in [
ctx(&["cat", "/dev/null"]),
serde_json::json!({
"request": {
"mode": "shell",
"command": "Write-Output hi > /dev/null",
"cwd": "/tmp/work",
"shell": { "id": "pwsh", "platform": "windows" },
},
"workspace_roots": ["/tmp/work"],
}),
] {
let scan = command_risk_scan_json(&context, None);
assert!(
labels(&scan).contains(&"outside_workspace".to_string()),
"native Windows filesystem operands remain scoped: {scan}"
);
}
}