test: cover proxy listener recovery

This commit is contained in:
efrazer-oai
2026-06-23 19:52:02 -07:00
parent 737502a6f6
commit a451f04774
+68
View File
@@ -28,3 +28,71 @@ foo = "bar"
Ok(())
}
#[cfg(unix)]
#[test]
fn proxy_ensure_listener_recovers_a_stale_socket_and_reuses_the_listener() -> Result<()> {
use std::os::unix::net::UnixListener;
let codex_home = TempDir::new()?;
let socket_dir = codex_home.path().join("app-server-control");
let socket_path = socket_dir.join("app-server-control.sock");
std::fs::create_dir_all(&socket_dir)?;
let stale_listener = UnixListener::bind(&socket_path)?;
drop(stale_listener);
let mut first_proxy = codex_command(codex_home.path())?;
first_proxy
.args(["app-server", "proxy", "--ensure-listener"])
.assert()
.success();
let pid_file = codex_home.path().join("app-server-daemon/app-server.pid");
let first_pid_record = std::fs::read_to_string(&pid_file)?;
let mut second_proxy = codex_command(codex_home.path())?;
second_proxy
.args(["app-server", "proxy", "--ensure-listener"])
.assert()
.success();
let second_pid_record = std::fs::read_to_string(pid_file)?;
let mut stop = codex_command(codex_home.path())?;
stop.args(["app-server", "daemon", "stop"])
.assert()
.success();
assert_eq!(first_pid_record, second_pid_record);
Ok(())
}
#[cfg(unix)]
#[test]
fn proxy_ensure_listener_rejects_a_non_default_socket() -> Result<()> {
let codex_home = TempDir::new()?;
let other_socket = codex_home.path().join("other.sock");
let mut proxy = codex_command(codex_home.path())?;
let output = proxy
.args([
"app-server",
"proxy",
"--ensure-listener",
"--sock",
other_socket.to_str().expect("temp path should be UTF-8"),
])
.output()?;
let mut stop = codex_command(codex_home.path())?;
stop.args(["app-server", "daemon", "stop"])
.assert()
.success();
assert!(!output.status.success());
assert!(
String::from_utf8_lossy(&output.stderr)
.contains("--ensure-listener only supports the CODEX_HOME socket")
);
Ok(())
}