use std::process::{Command, Stdio};
use std::time::Duration;
use std::{env, fs, thread};
#[test]
fn test_end_to_end_daemon_telemetry() {
let is_win = cfg!(target_os = "windows");
let (prog, arg, script) = if is_win {
(
"powershell",
"-Command",
"echo 'secret=sk-ant-admin123' > dummy_secret.env; Start-Sleep -Seconds 5",
)
} else {
(
"sh",
"-c",
"echo 'secret=sk-ant-admin123' > dummy_secret.env; sleep 5",
)
};
let mut dummy_proc = Command::new(prog)
.arg(arg)
.arg(script)
.spawn()
.expect("failed to spawn dummy target");
let dummy_pid = dummy_proc.id();
let sandspy_exe = env!("CARGO_BIN_EXE_sandspy");
let mut sandspy_proc = Command::new(sandspy_exe)
.arg("watch")
.arg("--pid")
.arg(dummy_pid.to_string())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("failed to spawn sandspy daemon");
let _ = dummy_proc.wait().unwrap();
thread::sleep(Duration::from_secs(3));
let _ = sandspy_proc.kill();
let _ = sandspy_proc.wait();
assert!(
fs::metadata("dummy_secret.env").is_ok(),
"Dummy script failed to create file"
);
let _ = fs::remove_file("dummy_secret.env");
}