unified-exec: launch remote commands without host sandbox

This commit is contained in:
Adam Perry
2026-06-13 02:41:45 +00:00
parent 35c88706ff
commit f89f19659a
8 changed files with 553 additions and 98 deletions

View File

@@ -225,6 +225,27 @@ mod tests {
);
}
#[test]
fn prefixes_windows_powershell_path_on_a_foreign_host() {
let shell = r"C:\Program Files\PowerShell\7\pwsh.exe";
let cmd = vec![
shell.to_string(),
"-NoProfile".to_string(),
"-Command".to_string(),
"Write-Host hi".to_string(),
];
assert_eq!(
prefix_powershell_script_with_utf8(&cmd),
vec![
shell.to_string(),
"-NoProfile".to_string(),
"-Command".to_string(),
format!("{UTF8_OUTPUT_PREFIX}Write-Host hi"),
]
);
}
#[test]
fn does_not_duplicate_utf8_prefix() {
let cmd = vec![

View File

@@ -38,6 +38,12 @@ impl DetectedShell {
pub fn detect_shell_type(shell_path: impl AsRef<std::path::Path>) -> Option<ShellType> {
let shell_path = shell_path.as_ref();
if let Some(path) = shell_path.as_os_str().to_str()
&& let Some(file_name) = path.rsplit(['/', '\\']).next()
&& file_name != path
{
return detect_shell_type(PathBuf::from(file_name));
}
match shell_path.as_os_str().to_str() {
Some("zsh") => Some(ShellType::Zsh),
Some("sh") => Some(ShellType::Sh),
@@ -347,6 +353,12 @@ mod tests {
detect_shell_type(PathBuf::from("pwsh.exe")),
Some(ShellType::PowerShell)
);
assert_eq!(
detect_shell_type(PathBuf::from(
r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
)),
Some(ShellType::PowerShell)
);
assert_eq!(
detect_shell_type(PathBuf::from("/usr/local/bin/pwsh")),
Some(ShellType::PowerShell)