Files
kyle 9662966b45 toolkit: no thread panic in http_fetch, no casts, exact egress-proxy form
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
2026-09-23 16:13:43 -07:00

43 lines
1.5 KiB
Rust

//! `toolkit egress-proxy` takes exactly `--socket <path> --allow <list>`: with anything after
//! them it is not the proxy, and exits 2 at once rather than listening (M3b review). Do not edit.
use std::process::{Command, Stdio};
use std::time::{Duration, Instant};
#[test]
fn trailing_arguments_are_not_the_proxy_form() {
let dir = std::env::temp_dir().join(format!("tk-egress-form-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let socket = dir.join("egress.sock");
let mut child = Command::new(env!("CARGO_BIN_EXE_toolkit"))
.args([
"egress-proxy",
"--socket",
socket.to_str().unwrap(),
"--allow",
"example.com",
"extra",
])
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.unwrap();
let until = Instant::now() + Duration::from_secs(3);
let status = loop {
if let Some(status) = child.try_wait().unwrap() {
break status;
}
if Instant::now() > until {
let _ = child.kill();
let _ = child.wait();
panic!("it is listening: trailing arguments were accepted");
}
std::thread::sleep(Duration::from_millis(20));
};
assert_eq!(status.code(), Some(2));
assert!(!socket.exists(), "no socket was made");
let _ = std::fs::remove_dir_all(&dir);
}