mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
## Why The managed app-server daemon and automatic TUI attachment were limited to Unix, so Windows users could not share a background server across Codex sessions. ## What changed - Enable daemon lifecycle commands, `codex agents` startup, and AF_UNIX daemon discovery on Windows. - Require Windows daemons to start non-elevated and verify the discovered socket directory and peer before connecting. - Preflight detached process support, preserve path-based environment settings, and keep daemon processes out of the launching project's working directory. - Fall back to an embedded server when an implicitly discovered daemon cannot connect, while preserving errors for explicit remote endpoints and bypassing daemon reuse when `CODEX_EXEC_SERVER_URL` is set. ## Testing Add coverage for Windows launch restrictions and socket validation, implicit connection fallback, executor selection, daemon discovery, and the agents dashboard startup result. GitOrigin-RevId: e7fd63cf8690bcca8b5155266416f31f2f792aa2
86 lines
3.2 KiB
Rust
86 lines
3.2 KiB
Rust
//! Implicit daemon discovery is opportunistic; explicit endpoints remain authoritative.
|
|
|
|
use super::*;
|
|
use crate::legacy_core::config::ConfigBuilder;
|
|
use pretty_assertions::assert_eq;
|
|
use tempfile::TempDir;
|
|
|
|
#[cfg(windows)]
|
|
#[tokio::test]
|
|
async fn daemon_connection_rejects_unprotected_socket_before_handshake() -> color_eyre::Result<()> {
|
|
let home = TempDir::new()?;
|
|
let parent = home.path().join("control");
|
|
std::fs::create_dir(&parent)?;
|
|
let socket_path = AbsolutePathBuf::from_absolute_path_checked(parent.join("server.sock"))?;
|
|
let mut listener = codex_uds::UnixListener::bind(socket_path.as_path()).await?;
|
|
let target = AppServerTarget::LocalDaemon {
|
|
endpoint: RemoteAppServerEndpoint::UnixSocket { socket_path },
|
|
};
|
|
tokio::select! {
|
|
result = app_server_connection::connect(&target) => assert!(result.is_err()),
|
|
_ = listener.accept() => panic!("unprotected listener must not receive a connection"),
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn daemon_startup_falls_back_only_for_implicit_endpoints() -> color_eyre::Result<()> {
|
|
for scenario in ["missing socket", "failed handshake", "explicit endpoint"] {
|
|
let home = TempDir::new()?;
|
|
let config = ConfigBuilder::default()
|
|
.codex_home(home.path().to_path_buf())
|
|
.build()
|
|
.await?;
|
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?;
|
|
let endpoint = if scenario == "missing socket" {
|
|
RemoteAppServerEndpoint::UnixSocket {
|
|
socket_path: AbsolutePathBuf::from_absolute_path_checked(
|
|
home.path().join("gone.sock"),
|
|
)?,
|
|
}
|
|
} else {
|
|
RemoteAppServerEndpoint::WebSocket {
|
|
websocket_url: format!("ws://{}", listener.local_addr()?),
|
|
auth_token: None,
|
|
}
|
|
};
|
|
let reject_handshake = tokio::spawn(async move {
|
|
let _ = listener.accept().await;
|
|
});
|
|
let mut target = if scenario == "explicit endpoint" {
|
|
AppServerTarget::Remote { endpoint }
|
|
} else {
|
|
AppServerTarget::LocalDaemon { endpoint }
|
|
};
|
|
let original_target = target.clone();
|
|
let mut state_db = None;
|
|
let result = start_app_server(
|
|
&mut target,
|
|
Arg0DispatchPaths::default(),
|
|
config,
|
|
Vec::new(),
|
|
LoaderOverrides::default(),
|
|
/*strict_config*/ false,
|
|
CloudConfigBundleLoader::default(),
|
|
codex_feedback::CodexFeedback::new(),
|
|
/*log_db*/ None,
|
|
&mut state_db,
|
|
Arc::new(EnvironmentManager::default_for_tests()),
|
|
)
|
|
.await;
|
|
reject_handshake.abort();
|
|
if scenario == "explicit endpoint" {
|
|
assert!(result.is_err());
|
|
assert_eq!(target, original_target);
|
|
assert!(state_db.is_none());
|
|
} else {
|
|
let server = AppServerSession::new(result?, target.thread_params_mode());
|
|
assert!(server.uses_embedded_app_server());
|
|
assert_eq!(target, AppServerTarget::Embedded);
|
|
assert!(state_db.is_some());
|
|
server.shutdown().await?;
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|