mod common;
use agent_os_client::ExecOptions;
#[tokio::test]
async fn exec_command_line_paths() {
if !common::sidecar_available() {
eprintln!("skipping exec_command_line_paths: sidecar binary not built");
return;
}
let Some(os) = common::new_vm_with_commands().await else {
eprintln!("skipping exec_command_line_paths: coreutils wasm artifacts absent");
return;
};
let echo = os
.exec("echo hello world", ExecOptions::default())
.await
.expect("exec echo");
assert_eq!(echo.exit_code, 0, "echo exit (stderr: {:?})", echo.stderr);
assert_eq!(echo.stdout.trim_end(), "hello world", "echo stdout");
let missing = os
.exec("cat /no/such/file", ExecOptions::default())
.await
.expect("exec cat missing returns a result");
assert_ne!(
missing.exit_code, 0,
"cat of a missing file must report a non-zero exit code"
);
let chain = os
.exec("echo a && echo b", ExecOptions::default())
.await
.expect("exec && chain");
assert_eq!(chain.exit_code, 0, "chain exit (stderr: {:?})", chain.stderr);
assert_eq!(chain.stdout, "a\nb\n", "chain stdout");
let redirect = os
.exec("echo redirected > /tmp/exec_redirect.txt", ExecOptions::default())
.await
.expect("exec redirect");
assert_eq!(
redirect.exit_code, 0,
"redirect exit (stderr: {:?})",
redirect.stderr
);
let body = os
.read_file("/tmp/exec_redirect.txt")
.await
.expect("read redirected file");
assert_eq!(
String::from_utf8_lossy(&body).trim_end(),
"redirected",
"redirected file contents"
);
let quoted = os
.exec("echo 'a b'", ExecOptions::default())
.await
.expect("exec quoted");
assert_eq!(quoted.stdout.trim_end(), "a b", "quoted stdout");
assert!(
os.exec(" ", ExecOptions::default()).await.is_err(),
"empty command line must error"
);
}