Merge remote-tracking branch 'origin/main' into cconger/code-mode-host-skeleton

# Conflicts:
#	codex-rs/Cargo.toml
This commit is contained in:
Channing Conger
2026-06-11 13:06:39 -07:00
306 changed files with 12135 additions and 4250 deletions
+72 -7
View File
@@ -6,6 +6,7 @@ use std::path::PathBuf;
use std::process::Command;
use std::sync::Arc;
use std::sync::atomic::AtomicU64;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::time::Duration;
@@ -26,7 +27,10 @@ use codex_exec_server::CreateDirectoryOptions;
use codex_exec_server::ExecutorFileSystem;
use codex_exec_server::RemoveOptions;
use codex_extension_api::ExtensionRegistry;
use codex_extension_api::LoadUserInstructionsFuture;
use codex_extension_api::UserInstructionsProvider;
use codex_extension_api::empty_extension_registry;
use codex_home::CodexHomeUserInstructionsProvider;
use codex_login::CodexAuth;
use codex_model_provider_info::ModelProviderInfo;
use codex_model_provider_info::built_in_model_providers;
@@ -45,6 +49,7 @@ use codex_protocol::protocol::TurnEnvironmentSelection;
use codex_protocol::protocol::TurnEnvironmentSelections;
use codex_protocol::user_input::UserInput;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use futures::future::BoxFuture;
use serde_json::Value;
use tempfile::TempDir;
@@ -73,6 +78,31 @@ const REMOTE_EXEC_SERVER_URL_ENV_VAR: &str = "CODEX_TEST_REMOTE_EXEC_SERVER_URL"
static REMOTE_TEST_INSTANCE_COUNTER: AtomicU64 = AtomicU64::new(0);
const SUBMIT_TURN_COMPLETE_TIMEOUT: Duration = Duration::from_secs(30);
pub struct RecordingUserInstructionsProvider {
inner: Arc<dyn UserInstructionsProvider>,
load_count: AtomicUsize,
}
impl RecordingUserInstructionsProvider {
pub fn new(inner: Arc<dyn UserInstructionsProvider>) -> Self {
Self {
inner,
load_count: AtomicUsize::new(0),
}
}
pub fn load_count(&self) -> usize {
self.load_count.load(Ordering::SeqCst)
}
}
impl UserInstructionsProvider for RecordingUserInstructionsProvider {
fn load_user_instructions(&self) -> LoadUserInstructionsFuture<'_> {
self.load_count.fetch_add(1, Ordering::SeqCst);
self.inner.load_user_instructions()
}
}
pub fn local(cwd: AbsolutePathBuf) -> TurnEnvironmentSelection {
TurnEnvironmentSelection {
environment_id: codex_exec_server::LOCAL_ENVIRONMENT_ID.to_string(),
@@ -137,10 +167,11 @@ pub async fn test_env() -> Result<TestEnv> {
let environment =
codex_exec_server::Environment::create_for_tests(Some(websocket_url.clone()))?;
let cwd = remote_aware_cwd_path();
let cwd_uri = PathUri::from_path(&cwd)?;
environment
.get_filesystem()
.create_directory(
&cwd,
&cwd_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -233,6 +264,7 @@ pub struct TestCodexBuilder {
user_shell_override: Option<Shell>,
exec_server_url: Option<String>,
extensions: Arc<ExtensionRegistry<Config>>,
user_instructions_provider: Option<Arc<dyn UserInstructionsProvider>>,
}
impl TestCodexBuilder {
@@ -322,6 +354,14 @@ impl TestCodexBuilder {
self
}
pub fn with_user_instructions_provider(
mut self,
provider: Arc<dyn UserInstructionsProvider>,
) -> Self {
self.user_instructions_provider = Some(provider);
self
}
pub fn with_windows_cmd_shell(self) -> Self {
if cfg!(windows) {
self.with_user_shell(get_shell_by_model_provided_path(&PathBuf::from("cmd.exe")))
@@ -510,12 +550,19 @@ impl TestCodexBuilder {
let state_db = codex_core::init_state_db(&config).await;
let thread_store = thread_store_from_config(&config, state_db.clone());
let installation_id = resolve_installation_id(&config.codex_home).await?;
let user_instructions_provider =
self.user_instructions_provider.clone().unwrap_or_else(|| {
Arc::new(CodexHomeUserInstructionsProvider::new(
config.codex_home.clone(),
))
});
let thread_manager = ThreadManager::new(
&config,
codex_core::test_support::auth_manager_from_auth(auth.clone()),
SessionSource::Exec,
Arc::clone(&environment_manager),
Arc::clone(&self.extensions),
user_instructions_provider,
/*analytics_events_client*/ None,
thread_store,
state_db.clone(),
@@ -919,35 +966,45 @@ impl TestCodexHarness {
) -> Result<()> {
let abs_path = self.path_abs(rel);
if let Some(parent) = abs_path.parent() {
let parent_uri = PathUri::from_path(&parent)?;
self.test
.fs()
.create_directory(
&parent,
&parent_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
.await?;
}
let abs_path_uri = PathUri::from_path(&abs_path)?;
self.test
.fs()
.write_file(&abs_path, contents.as_ref().to_vec(), /*sandbox*/ None)
.write_file(
&abs_path_uri,
contents.as_ref().to_vec(),
/*sandbox*/ None,
)
.await?;
Ok(())
}
pub async fn read_file_text(&self, rel: impl AsRef<Path>) -> Result<String> {
let path = self.path_abs(rel);
let path_uri = PathUri::from_path(&path)?;
Ok(self
.test
.fs()
.read_file_text(&self.path_abs(rel), /*sandbox*/ None)
.read_file_text(&path_uri, /*sandbox*/ None)
.await?)
}
pub async fn create_dir_all(&self, rel: impl AsRef<Path>) -> Result<()> {
let path = self.path_abs(rel);
let path_uri = PathUri::from_path(&path)?;
self.test
.fs()
.create_directory(
&self.path_abs(rel),
&path_uri,
CreateDirectoryOptions { recursive: true },
/*sandbox*/ None,
)
@@ -960,10 +1017,11 @@ impl TestCodexHarness {
}
pub async fn remove_abs_path(&self, path: &AbsolutePathBuf) -> Result<()> {
let path_uri = PathUri::from_abs_path(path)?;
self.test
.fs()
.remove(
path,
&path_uri,
RemoveOptions {
recursive: false,
force: true,
@@ -975,7 +1033,13 @@ impl TestCodexHarness {
}
pub async fn abs_path_exists(&self, path: &AbsolutePathBuf) -> Result<bool> {
match self.test.fs().get_metadata(path, /*sandbox*/ None).await {
let path_uri = PathUri::from_abs_path(path)?;
match self
.test
.fs()
.get_metadata(&path_uri, /*sandbox*/ None)
.await
{
Ok(_) => Ok(true),
Err(err) if err.kind() == ErrorKind::NotFound => Ok(false),
Err(err) => Err(err.into()),
@@ -1096,6 +1160,7 @@ pub fn test_codex() -> TestCodexBuilder {
user_shell_override: None,
exec_server_url: None,
extensions: empty_extension_registry(),
user_instructions_provider: None,
}
}