mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
feat: add shell snapshot for shell command (#7786)
This commit is contained in:
committed by
GitHub
Unverified
parent
b2280d6205
commit
29381ba5c2
@@ -257,7 +257,7 @@ mod tests {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::process::Command as StdCommand;
|
||||
use std::sync::Arc;
|
||||
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
@@ -293,53 +293,6 @@ mod tests {
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn wrap_command_with_snapshot_wraps_bash_shell() {
|
||||
let snapshot_path = PathBuf::from("/tmp/snapshot.sh");
|
||||
let shell = Shell {
|
||||
shell_type: ShellType::Bash,
|
||||
shell_path: PathBuf::from("/bin/bash"),
|
||||
shell_snapshot: Some(Arc::new(ShellSnapshot {
|
||||
path: snapshot_path.clone(),
|
||||
})),
|
||||
};
|
||||
let original_command = vec![
|
||||
"bash".to_string(),
|
||||
"-lc".to_string(),
|
||||
"echo hello".to_string(),
|
||||
];
|
||||
|
||||
let wrapped = shell.wrap_command_with_snapshot(&original_command);
|
||||
|
||||
let mut expected = shell.derive_exec_args(". \"$0\" && exec \"$@\"", false);
|
||||
expected.push(snapshot_path.to_string_lossy().to_string());
|
||||
expected.extend_from_slice(&original_command);
|
||||
|
||||
assert_eq!(wrapped, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrap_command_with_snapshot_preserves_cmd_shell() {
|
||||
let snapshot_path = PathBuf::from("C:\\snapshot.cmd");
|
||||
let shell = Shell {
|
||||
shell_type: ShellType::Cmd,
|
||||
shell_path: PathBuf::from("cmd"),
|
||||
shell_snapshot: Some(Arc::new(ShellSnapshot {
|
||||
path: snapshot_path,
|
||||
})),
|
||||
};
|
||||
let original_command = vec![
|
||||
"cmd".to_string(),
|
||||
"/c".to_string(),
|
||||
"echo hello".to_string(),
|
||||
];
|
||||
|
||||
let wrapped = shell.wrap_command_with_snapshot(&original_command);
|
||||
|
||||
assert_eq!(wrapped, original_command);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn try_new_creates_and_deletes_snapshot_file() -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user