Merge 5ffef47eb7 into sapling-pr-archive-bolinfest

This commit is contained in:
Michael Bolin
2026-06-23 14:52:19 -07:00
committed by GitHub
54 changed files with 1094 additions and 638 deletions
+9 -1
View File
@@ -11,7 +11,15 @@ Docker container is built and initialized via ./scripts/test-remote-env.sh
On x86-64 Linux, run Wine exec with
`bazel test //codex-rs/core:core-all-wine-exec-test --test_output=errors`.
Temporary blockers belong beside the test in `skip_if_wine_exec!` calls.
Local execution targets the host OS, Docker targets Linux, and Wine exec targets
Windows. Choose the skip macro by what the test depends on:
- `skip_if_target_windows!`: Windows target behavior.
- `skip_if_host_windows!`: Windows host constraints.
- `skip_if_remote!`: Local-only test behavior.
- `skip_if_no_remote_env!`: Remote-only test behavior.
- `skip_if_wine_exec!`: Wine-specific runner debt.
You can list devboxes via `applied_devbox ls`, pick the one with `codex` in the name.
Connect to devbox via `ssh <devbox_name>`.
+1
View File
@@ -3606,6 +3606,7 @@ dependencies = [
"codex-config",
"codex-protocol",
"codex-utils-absolute-path",
"codex-utils-path-uri",
"codex-utils-plugins",
"pretty_assertions",
"thiserror 2.0.18",
+2 -1
View File
@@ -209,6 +209,7 @@
"type": "string"
},
"path": {
"description": "Absolute path for the root in the selected environment.",
"type": "string"
},
"type": {
@@ -6833,4 +6834,4 @@
}
],
"title": "ClientRequest"
}
}
@@ -7042,9 +7042,10 @@
"environmentId": {
"type": "string"
},
"path": {
"type": "string"
},
"path": {
"description": "Absolute path for the root in the selected environment.",
"type": "string"
},
"type": {
"enum": [
"environment"
@@ -20689,4 +20690,4 @@
},
"title": "CodexAppServerProtocol",
"type": "object"
}
}
@@ -1169,6 +1169,7 @@
"type": "string"
},
"path": {
"description": "Absolute path for the root in the selected environment.",
"type": "string"
},
"type": {
@@ -18467,4 +18468,4 @@
},
"title": "CodexAppServerProtocolV2",
"type": "object"
}
}
@@ -73,6 +73,7 @@
"type": "string"
},
"path": {
"description": "Absolute path for the root in the selected environment.",
"type": "string"
},
"type": {
@@ -387,4 +388,4 @@
},
"title": "ThreadStartParams",
"type": "object"
}
}
@@ -5,4 +5,8 @@
/**
* Location used to resolve a selected capability root.
*/
export type CapabilityRootLocation = { "type": "environment", environmentId: string, path: string, };
export type CapabilityRootLocation = { "type": "environment", environmentId: string,
/**
* Absolute path for the root in the selected environment.
*/
path: string, };
+1 -2
View File
@@ -137,7 +137,7 @@ Example with notification opt-out:
## API Overview
- `thread/start` — create a new thread; emits `thread/started` (including the current `thread.status`) and auto-subscribes you to turn/item events for that thread. When the request includes a `cwd` and the resolved sandbox is `workspace-write` or full access, app-server also marks that project as trusted in the user `config.toml`. Pass `sessionStartSource: "clear"` when starting a replacement thread after clearing the current session so `SessionStart` hooks receive `source: "clear"` instead of the default `"startup"`. Experimental `runtimeWorkspaceRoots` replaces the thread-scoped runtime workspace roots used to materialize `:workspace_roots`; paths must be absolute. For permissions, prefer experimental `permissions` profile selection by id; the legacy `sandbox` shorthand is still accepted but cannot be combined with `permissions`. Experimental `multiAgentMode` selects the initial thread mode and defaults to `explicitRequestOnly` when omitted; use `none` to keep multi-agent tools available without injecting mode instructions. Experimental `environments` selects the sticky execution environments for turns on the thread; omit it to use the server default, pass `[]` to disable environments, or pass explicit environment ids with per-environment `cwd`. Experimental `selectedCapabilityRoots` selects environment-owned plugin or standalone-skill roots. Skills found below those roots are listed and read through the owning environment. Stdio MCP servers declared by selected plugins are also started in that environment; HTTP MCP declarations remain inactive.
- `thread/start` — create a new thread; emits `thread/started` (including the current `thread.status`) and auto-subscribes you to turn/item events for that thread. When the request includes a `cwd` and the resolved sandbox is `workspace-write` or full access, app-server also marks that project as trusted in the user `config.toml`. Pass `sessionStartSource: "clear"` when starting a replacement thread after clearing the current session so `SessionStart` hooks receive `source: "clear"` instead of the default `"startup"`. Experimental `runtimeWorkspaceRoots` replaces the thread-scoped runtime workspace roots used to materialize `:workspace_roots`; paths must be absolute. For permissions, prefer experimental `permissions` profile selection by id; the legacy `sandbox` shorthand is still accepted but cannot be combined with `permissions`. Experimental `multiAgentMode` selects the initial thread mode and defaults to `explicitRequestOnly` when omitted; use `none` to keep multi-agent tools available without injecting mode instructions. Experimental `environments` selects the sticky execution environments for turns on the thread; omit it to use the server default, pass `[]` to disable environments, or pass explicit environment ids with per-environment `cwd`. Experimental `selectedCapabilityRoots` selects environment-owned plugin or standalone-skill roots using environment-native absolute paths. Skills found below those roots are listed and read through the owning environment. Stdio MCP servers declared by selected plugins are also started in that environment; HTTP MCP declarations remain inactive.
- `thread/resume` — reopen an existing thread by id so subsequent `turn/start` calls append to it. Accepts the same permission override rules as `thread/start`. Multi-agent mode restores the last effective mode from rollout history when available; clients can select another mode on the first `turn/start`.
- `thread/fork` — fork an existing thread into a new thread id by copying the stored history; if the source thread is currently mid-turn, the fork records the same interruption marker as `turn/interrupt` instead of inheriting an unmarked partial turn suffix. The returned `thread.forkedFromId` points at the source thread when known. Accepts `ephemeral: true` for an in-memory temporary fork, emits `thread/started` (including the current `thread.status`), and auto-subscribes you to turn/item events for the new thread. Experimental clients can pass `excludeTurns: true` when they plan to page fork history via `thread/turns/list` instead of receiving the full turn array immediately. Accepts the same permission override rules as `thread/start`.
- `thread/start`, `thread/resume`, and `thread/fork` responses include the legacy `sandbox` compatibility projection. `instructionSources` lists loaded instruction files using each source environment's native absolute path syntax, including files loaded from remote environments. Experimental clients can read `runtimeWorkspaceRoots` for the thread-scoped runtime roots and `activePermissionProfile` for the named or implicit built-in profile identity/provenance when known. Their experimental `multiAgentMode` field, and the corresponding thread setting, report the thread's current mode. Turn construction separately determines whether that mode is applicable to the selected model and runtime configuration.
@@ -267,7 +267,6 @@ Start a fresh thread when you need a new Codex conversation.
"location": {
"type": "environment",
"environmentId": "workspace",
// Opaque to app-server; interpreted in the selected environment.
"path": "/opt/cca/plugins/github"
}
}
@@ -13,6 +13,7 @@ use codex_app_server_protocol::ThreadStartParams;
use codex_app_server_protocol::ThreadStartResponse;
use codex_app_server_protocol::TurnStartParams;
use codex_app_server_protocol::UserInput;
use codex_utils_path_uri::PathUri;
use core_test_support::responses;
use core_test_support::stdio_server_bin;
use pretty_assertions::assert_eq;
@@ -92,7 +93,7 @@ args = ["exec-server", "--listen", "stdio"]
id: "executor-demo@1".to_string(),
location: CapabilityRootLocation::Environment {
environment_id: EXECUTOR_ID.to_string(),
path: plugin.path().to_string_lossy().into_owned(),
path: PathUri::from_host_native_path(plugin.path())?,
},
}]),
)
@@ -11,6 +11,7 @@ use codex_app_server_protocol::ThreadStartParams;
use codex_app_server_protocol::ThreadStartResponse;
use codex_app_server_protocol::TurnStartParams;
use codex_app_server_protocol::UserInput;
use codex_utils_path_uri::PathUri;
use core_test_support::responses;
use tempfile::TempDir;
use tokio::time::timeout;
@@ -90,7 +91,7 @@ stream_max_retries = 0
id: "demo-plugin@1".to_string(),
location: CapabilityRootLocation::Environment {
environment_id: "local".to_string(),
path: plugin_dir.path().to_string_lossy().into_owned(),
path: PathUri::from_host_native_path(plugin_dir.path())?,
},
}]),
..Default::default()
@@ -25,7 +25,7 @@ use codex_app_server_protocol::UserInput as V2UserInput;
use codex_core::config::set_project_trust_level;
use codex_protocol::config_types::TrustLevel;
use codex_utils_absolute_path::AbsolutePathBuf;
use core_test_support::skip_if_windows;
use core_test_support::skip_if_host_windows;
use pretty_assertions::assert_eq;
use serde::Serialize;
use tempfile::TempDir;
@@ -651,7 +651,7 @@ async fn config_batch_write_toggles_user_hook() -> Result<()> {
#[tokio::test]
async fn config_batch_write_updates_hook_trust_for_loaded_session() -> Result<()> {
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let responses = vec![
create_final_assistant_message_sse_response("Warmup")?,
@@ -902,7 +902,7 @@ command = "python3 {hook_script_path}"
#[tokio::test]
async fn config_batch_write_disables_hook_for_loaded_session() -> Result<()> {
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let responses = vec![
create_final_assistant_message_sse_response("Warmup")?,
+74 -7
View File
@@ -514,6 +514,11 @@ mod tests {
use codex_exec_server::LOCAL_ENVIRONMENT_ID;
use codex_plugin::PluginProvider;
use codex_plugin::ResolvedPlugin;
use codex_plugin::manifest::PluginManifest as GenericPluginManifest;
use codex_plugin::manifest::PluginManifestHooks;
use codex_plugin::manifest::PluginManifestInterface;
use codex_plugin::manifest::PluginManifestMcpServers;
use codex_plugin::manifest::PluginManifestPaths;
use codex_protocol::capabilities::CapabilityRootLocation;
use codex_protocol::capabilities::SelectedCapabilityRoot;
use codex_utils_absolute_path::AbsolutePathBuf;
@@ -779,14 +784,16 @@ mod tests {
"composerIcon": "./assets/icon.svg"
}"#,
);
let host_manifest = load_plugin_manifest(&plugin_root).expect("host manifest");
let plugin_root =
AbsolutePathBuf::from_absolute_path_checked(plugin_root).expect("absolute plugin root");
let plugin_root_uri = PathUri::from_abs_path(&plugin_root);
let provider =
ExecutorPluginProvider::new(Arc::new(EnvironmentManager::default_for_tests()));
let selected_root = SelectedCapabilityRoot {
id: "selected-demo".to_string(),
location: CapabilityRootLocation::Environment {
environment_id: LOCAL_ENVIRONMENT_ID.to_string(),
path: plugin_root.to_string_lossy().into_owned(),
path: plugin_root_uri.clone(),
},
};
@@ -795,17 +802,77 @@ mod tests {
.await
.expect("resolve executor plugin")
.expect("plugin descriptor");
let plugin_root =
AbsolutePathBuf::from_absolute_path_checked(plugin_root).expect("absolute plugin root");
let manifest_path = plugin_root_uri
.join(".codex-plugin/plugin.json")
.expect("manifest URI");
let manifest_contents =
fs::read_to_string(plugin_root.join(".codex-plugin/plugin.json")).expect("manifest");
let expected_manifest =
super::parse_plugin_manifest_uri(&plugin_root_uri, &manifest_path, &manifest_contents)
.expect("URI manifest");
let expected_plugin = ResolvedPlugin::from_environment(
"selected-demo".to_string(),
LOCAL_ENVIRONMENT_ID.to_string(),
plugin_root.clone(),
plugin_root.join(".codex-plugin/plugin.json"),
host_manifest,
plugin_root_uri,
manifest_path,
expected_manifest,
)
.expect("valid expected descriptor");
assert_eq!(executor_plugin, expected_plugin);
}
#[test]
fn uri_manifest_resolves_resources_below_foreign_root() {
let plugin_root =
PathUri::parse("file:///C:/plugins/demo-plugin").expect("plugin root URI");
let manifest_path = plugin_root
.join(".codex-plugin/plugin.json")
.expect("manifest URI");
let manifest = super::parse_plugin_manifest_uri(
&plugin_root,
&manifest_path,
r#"{
"name": "demo-plugin",
"skills": "./skills",
"mcpServers": "./.mcp.json",
"apps": "./apps",
"hooks": "./hooks.json",
"interface": {
"displayName": "Demo Plugin",
"composerIcon": "./assets/icon.svg"
}
}"#,
)
.expect("URI manifest");
assert_eq!(
manifest,
GenericPluginManifest {
name: "demo-plugin".to_string(),
version: None,
description: None,
keywords: Vec::new(),
paths: PluginManifestPaths {
skills: vec![plugin_root.join("skills").expect("skills URI")],
mcp_servers: Some(PluginManifestMcpServers::Path(
plugin_root.join(".mcp.json").expect("MCP URI"),
)),
apps: Some(plugin_root.join("apps").expect("apps URI")),
hooks: Some(PluginManifestHooks::Paths(vec![
plugin_root.join("hooks.json").expect("hooks URI"),
])),
},
interface: Some(PluginManifestInterface {
display_name: Some("Demo Plugin".to_string()),
composer_icon: Some(
plugin_root
.join("assets/icon.svg")
.expect("composer icon URI"),
),
..PluginManifestInterface::default()
}),
}
);
}
}
+35 -47
View File
@@ -1,4 +1,4 @@
use crate::manifest::parse_plugin_manifest;
use crate::manifest::parse_plugin_manifest_uri;
use codex_exec_server::EnvironmentManager;
use codex_exec_server::ExecutorFileSystem;
use codex_plugin::PluginProvider;
@@ -6,23 +6,16 @@ use codex_plugin::ResolvedPlugin;
use codex_plugin::ResolvedPluginError;
use codex_protocol::capabilities::CapabilityRootLocation;
use codex_protocol::capabilities::SelectedCapabilityRoot;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use codex_utils_path_uri::PathUriParseError;
use codex_utils_plugins::DISCOVERABLE_PLUGIN_MANIFEST_PATHS;
use std::io;
use std::path::PathBuf;
use std::sync::Arc;
use thiserror::Error;
/// Failure to resolve an environment-owned capability root as a plugin package.
#[derive(Debug, Error)]
pub enum ExecutorPluginProviderError {
#[error("selected capability root `{root_id}` has invalid path `{path}`: {message}")]
InvalidRootPath {
root_id: String,
path: String,
message: String,
},
#[error(
"selected capability root `{root_id}` references unavailable environment `{environment_id}`"
)]
@@ -33,33 +26,40 @@ pub enum ExecutorPluginProviderError {
#[error("failed to inspect selected capability root `{root_id}` at {path}: {source}")]
InspectRoot {
root_id: String,
path: AbsolutePathBuf,
path: PathUri,
#[source]
source: io::Error,
},
#[error("selected capability root `{root_id}` path {path} is not a directory")]
RootNotDirectory {
RootNotDirectory { root_id: String, path: PathUri },
#[error(
"failed to resolve plugin manifest path `{relative_path}` below selected capability root `{root_id}` at {root}: {source}"
)]
InvalidManifestPath {
root_id: String,
path: AbsolutePathBuf,
root: PathUri,
relative_path: &'static str,
#[source]
source: PathUriParseError,
},
#[error("failed to inspect plugin manifest for `{root_id}` at {path}: {source}")]
InspectManifest {
root_id: String,
path: AbsolutePathBuf,
path: PathUri,
#[source]
source: io::Error,
},
#[error("failed to read plugin manifest for `{root_id}` at {path}: {source}")]
ReadManifest {
root_id: String,
path: AbsolutePathBuf,
path: PathUri,
#[source]
source: io::Error,
},
#[error("failed to parse plugin manifest for `{root_id}` at {path}: {source}")]
ParseManifest {
root_id: String,
path: AbsolutePathBuf,
path: PathUri,
#[source]
source: serde_json::Error,
},
@@ -110,7 +110,7 @@ impl ExecutorPluginProvider {
selected_root: &SelectedCapabilityRoot,
) -> Result<Option<ResolvedExecutorPlugin>, ExecutorPluginProviderError> {
let root_id = &selected_root.id;
let plugin_root = selected_plugin_root(selected_root)?;
let plugin_root = selected_plugin_root(selected_root);
let CapabilityRootLocation::Environment { environment_id, .. } = &selected_root.location;
let environment = self
.environment_manager
@@ -142,38 +142,20 @@ impl PluginProvider for ExecutorPluginProvider {
}
}
fn selected_plugin_root(
selected_root: &SelectedCapabilityRoot,
) -> Result<AbsolutePathBuf, ExecutorPluginProviderError> {
let root_id = &selected_root.id;
fn selected_plugin_root(selected_root: &SelectedCapabilityRoot) -> PathUri {
let CapabilityRootLocation::Environment { path, .. } = &selected_root.location;
let plugin_root = PathBuf::from(path);
if !plugin_root.is_absolute() {
return Err(ExecutorPluginProviderError::InvalidRootPath {
root_id: root_id.clone(),
path: path.clone(),
message: "executor path must be absolute".to_string(),
});
}
AbsolutePathBuf::from_absolute_path_checked(plugin_root).map_err(|err| {
ExecutorPluginProviderError::InvalidRootPath {
root_id: root_id.clone(),
path: path.clone(),
message: err.to_string(),
}
})
path.clone()
}
async fn resolve_plugin_root(
selected_root: &SelectedCapabilityRoot,
plugin_root: AbsolutePathBuf,
plugin_root: PathUri,
file_system: &dyn ExecutorFileSystem,
) -> Result<Option<ResolvedPlugin>, ExecutorPluginProviderError> {
let root_id = &selected_root.id;
let CapabilityRootLocation::Environment { environment_id, .. } = &selected_root.location;
let root_uri = PathUri::from_abs_path(&plugin_root);
let root_metadata = file_system
.get_metadata(&root_uri, /*sandbox*/ None)
.get_metadata(&plugin_root, /*sandbox*/ None)
.await
.map_err(|source| ExecutorPluginProviderError::InspectRoot {
root_id: root_id.clone(),
@@ -189,14 +171,20 @@ async fn resolve_plugin_root(
let mut manifest_path = None;
for relative_path in DISCOVERABLE_PLUGIN_MANIFEST_PATHS {
let candidate = plugin_root.join(relative_path);
let candidate_uri = PathUri::from_abs_path(&candidate);
let candidate_uri = plugin_root.join(relative_path).map_err(|source| {
ExecutorPluginProviderError::InvalidManifestPath {
root_id: root_id.clone(),
root: plugin_root.clone(),
relative_path,
source,
}
})?;
match file_system
.get_metadata(&candidate_uri, /*sandbox*/ None)
.await
{
Ok(metadata) if metadata.is_file => {
manifest_path = Some((candidate, candidate_uri));
manifest_path = Some(candidate_uri);
break;
}
Ok(_) => {}
@@ -204,13 +192,13 @@ async fn resolve_plugin_root(
Err(source) => {
return Err(ExecutorPluginProviderError::InspectManifest {
root_id: root_id.clone(),
path: candidate,
path: candidate_uri,
source,
});
}
}
}
let Some((manifest_path, manifest_uri)) = manifest_path else {
let Some(manifest_uri) = manifest_path else {
return Ok(None);
};
let contents = file_system
@@ -218,14 +206,14 @@ async fn resolve_plugin_root(
.await
.map_err(|source| ExecutorPluginProviderError::ReadManifest {
root_id: root_id.clone(),
path: manifest_path.clone(),
path: manifest_uri.clone(),
source,
})?;
let manifest =
parse_plugin_manifest(&plugin_root, &manifest_path, &contents).map_err(|source| {
parse_plugin_manifest_uri(&plugin_root, &manifest_uri, &contents).map_err(|source| {
ExecutorPluginProviderError::ParseManifest {
root_id: root_id.clone(),
path: manifest_path.clone(),
path: manifest_uri.clone(),
source,
}
})?;
@@ -234,7 +222,7 @@ async fn resolve_plugin_root(
root_id.clone(),
environment_id.clone(),
plugin_root,
manifest_path,
manifest_uri,
manifest,
)
.map_err(|source| ExecutorPluginProviderError::ConstructDescriptor {
+74 -46
View File
@@ -1,7 +1,7 @@
use super::ExecutorPluginProvider;
use super::ExecutorPluginProviderError;
use super::resolve_plugin_root;
use crate::manifest::parse_plugin_manifest;
use crate::manifest::parse_plugin_manifest_uri;
use codex_exec_server::CopyOptions;
use codex_exec_server::CreateDirectoryOptions;
use codex_exec_server::EnvironmentManager;
@@ -18,7 +18,6 @@ use codex_plugin::PluginProvider;
use codex_plugin::ResolvedPlugin;
use codex_protocol::capabilities::CapabilityRootLocation;
use codex_protocol::capabilities::SelectedCapabilityRoot;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
use std::fs;
@@ -43,13 +42,13 @@ const MANIFEST_CONTENTS: &str = r#"{
#[derive(Debug, PartialEq, Eq)]
enum FileSystemCall {
Metadata(AbsolutePathBuf),
Read(AbsolutePathBuf),
Metadata(PathUri),
Read(PathUri),
}
struct SyntheticPluginFileSystem {
plugin_root: AbsolutePathBuf,
manifest_path: AbsolutePathBuf,
plugin_root: PathUri,
manifest_path: PathUri,
calls: Mutex<Vec<FileSystemCall>>,
}
@@ -77,12 +76,11 @@ impl ExecutorFileSystem for SyntheticPluginFileSystem {
_sandbox: Option<&'a FileSystemSandboxContext>,
) -> ExecutorFileSystemFuture<'a, Vec<u8>> {
Box::pin(async move {
let path = path.to_abs_path()?;
self.calls
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.push(FileSystemCall::Read(path.clone()));
if path == self.manifest_path {
if path == &self.manifest_path {
Ok(MANIFEST_CONTENTS.as_bytes().to_vec())
} else {
Err(io::Error::new(io::ErrorKind::NotFound, "not found"))
@@ -122,14 +120,13 @@ impl ExecutorFileSystem for SyntheticPluginFileSystem {
_sandbox: Option<&'a FileSystemSandboxContext>,
) -> ExecutorFileSystemFuture<'a, FileMetadata> {
Box::pin(async move {
let path = path.to_abs_path()?;
self.calls
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.push(FileSystemCall::Metadata(path.clone()));
let (is_directory, is_file) = if path == self.plugin_root {
let (is_directory, is_file) = if path == &self.plugin_root {
(true, false)
} else if path == self.manifest_path {
} else if path == &self.manifest_path {
(false, true)
} else {
return Err(io::Error::new(io::ErrorKind::NotFound, "not found"));
@@ -185,7 +182,17 @@ fn selected_root(id: &str, environment_id: &str, path: &Path) -> SelectedCapabil
id: id.to_string(),
location: CapabilityRootLocation::Environment {
environment_id: environment_id.to_string(),
path: path.to_string_lossy().into_owned(),
path: PathUri::from_host_native_path(path).expect("path URI"),
},
}
}
fn selected_root_uri(id: &str, environment_id: &str, path: PathUri) -> SelectedCapabilityRoot {
SelectedCapabilityRoot {
id: id.to_string(),
location: CapabilityRootLocation::Environment {
environment_id: environment_id.to_string(),
path,
},
}
}
@@ -195,22 +202,20 @@ async fn plugin_root_resolution_uses_supplied_executor_file_system() {
let temp_dir = tempdir().expect("tempdir");
let plugin_root = temp_dir.path().join("executor-only-plugin");
assert!(!plugin_root.exists());
let plugin_root =
AbsolutePathBuf::from_absolute_path_checked(plugin_root).expect("absolute plugin root");
let manifest_path = plugin_root.join(".codex-plugin/plugin.json");
let parsed_manifest = parse_plugin_manifest(
plugin_root.as_path(),
manifest_path.as_path(),
MANIFEST_CONTENTS,
)
.expect("parse manifest");
let plugin_root = PathUri::from_host_native_path(&plugin_root).expect("plugin root URI");
let manifest_path = plugin_root
.join(".codex-plugin/plugin.json")
.expect("manifest URI");
let parsed_manifest =
parse_plugin_manifest_uri(&plugin_root, &manifest_path, MANIFEST_CONTENTS)
.expect("parse manifest");
let file_system = SyntheticPluginFileSystem {
plugin_root: plugin_root.clone(),
manifest_path: manifest_path.clone(),
calls: Mutex::new(Vec::new()),
};
let resolved = resolve_plugin_root(
&selected_root("selected-demo", "executor-test", plugin_root.as_path()),
&selected_root_uri("selected-demo", "executor-test", plugin_root.clone()),
plugin_root.clone(),
&file_system,
)
@@ -243,6 +248,51 @@ async fn plugin_root_resolution_uses_supplied_executor_file_system() {
);
}
#[tokio::test]
async fn plugin_root_resolution_accepts_foreign_executor_file_uri() {
let plugin_root = PathUri::parse("file:///C:/plugins/foo").expect("Windows plugin root URI");
let manifest_path = plugin_root
.join(".codex-plugin/plugin.json")
.expect("manifest URI");
let parsed_manifest =
parse_plugin_manifest_uri(&plugin_root, &manifest_path, MANIFEST_CONTENTS)
.expect("parse manifest");
let file_system = SyntheticPluginFileSystem {
plugin_root: plugin_root.clone(),
manifest_path: manifest_path.clone(),
calls: Mutex::new(Vec::new()),
};
let selected_root = selected_root_uri("selected-demo", "executor-test", plugin_root.clone());
let resolved = resolve_plugin_root(&selected_root, plugin_root.clone(), &file_system)
.await
.expect("resolve executor plugin");
assert_eq!(
resolved,
Some(
ResolvedPlugin::from_environment(
"selected-demo".to_string(),
"executor-test".to_string(),
plugin_root.clone(),
manifest_path.clone(),
parsed_manifest,
)
.expect("valid expected descriptor")
)
);
assert_eq!(
*file_system
.calls
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner),
vec![
FileSystemCall::Metadata(plugin_root),
FileSystemCall::Metadata(manifest_path.clone()),
FileSystemCall::Read(manifest_path),
]
);
}
#[tokio::test]
async fn standalone_capability_root_is_not_a_plugin() {
let temp_dir = tempdir().expect("tempdir");
@@ -292,8 +342,8 @@ async fn malformed_preferred_manifest_does_not_fall_through_to_alternate() {
MANIFEST_CONTENTS,
);
let expected_path =
AbsolutePathBuf::from_absolute_path_checked(plugin_root.join(".codex-plugin/plugin.json"))
.expect("absolute manifest path");
PathUri::from_host_native_path(plugin_root.join(".codex-plugin/plugin.json"))
.expect("manifest URI");
let provider = ExecutorPluginProvider::new(Arc::new(EnvironmentManager::default_for_tests()));
let err = provider
@@ -318,25 +368,3 @@ async fn malformed_preferred_manifest_does_not_fall_through_to_alternate() {
("selected-demo".to_string(), expected_path)
);
}
#[tokio::test]
async fn executor_root_must_be_an_explicit_absolute_path() {
let provider = ExecutorPluginProvider::new(Arc::new(EnvironmentManager::default_for_tests()));
let selected_root = SelectedCapabilityRoot {
id: "selected-demo".to_string(),
location: CapabilityRootLocation::Environment {
environment_id: LOCAL_ENVIRONMENT_ID.to_string(),
path: "~/plugins/demo".to_string(),
},
};
let err = provider
.resolve(&selected_root)
.await
.expect_err("home-relative executor path should fail");
assert_eq!(
err.to_string(),
"selected capability root `selected-demo` has invalid path `~/plugins/demo`: executor path must be absolute"
);
}
+10 -2
View File
@@ -5,8 +5,16 @@ This crate implements the business logic for Codex. It is designed to be used by
## Wine-exec integration tests
On x86-64 Linux, run the shared suite against the Windows exec server with
`bazel test //codex-rs/core:core-all-wine-exec-test`. Temporary blockers use a
source-local `skip_if_wine_exec!` call and reason.
`bazel test //codex-rs/core:core-all-wine-exec-test`.
Local execution targets the host OS, Docker targets Linux, and Wine exec targets
Windows. Choose the skip macro by what the test depends on:
- `skip_if_target_windows!`: Windows target behavior.
- `skip_if_host_windows!`: Windows host constraints.
- `skip_if_remote!`: Local-only test behavior.
- `skip_if_no_remote_env!`: Remote-only test behavior.
- `skip_if_wine_exec!`: Wine-specific runner debt.
## Dependencies
+107
View File
@@ -0,0 +1,107 @@
use super::session::Session;
use super::turn_context::TurnContext;
use codex_protocol::config_types::AutoCompactTokenLimitScope;
#[derive(Debug)]
pub(crate) struct ContextWindowTokenStatus {
// Full active context usage, independent of the configured auto-compact scope.
pub(crate) active_context_tokens: i64,
// Usage counted against `model_auto_compact_token_limit` for the current scope.
pub(crate) auto_compact_scope_tokens: i64,
pub(crate) auto_compact_scope_limit: i64,
pub(crate) full_context_window_limit: Option<i64>,
pub(crate) tokens_until_compaction: i64,
pub(crate) auto_compact_window_prefill_tokens: Option<i64>,
pub(crate) full_context_window_limit_reached: bool,
pub(crate) token_limit_reached: bool,
pub(crate) context_remaining_tokens: Option<i64>,
}
struct BodyAfterPrefixWindowStatus {
full_context_window_limit: Option<i64>,
auto_compact_window_prefill_tokens: Option<i64>,
has_context_remaining_limit: bool,
}
pub(crate) async fn context_window_token_status(
sess: &Session,
turn_context: &TurnContext,
) -> ContextWindowTokenStatus {
let active_context_tokens = sess.get_total_token_usage().await;
let (auto_compact_scope_tokens, auto_compact_scope_limit, body_window) =
match turn_context.config.model_auto_compact_token_limit_scope {
AutoCompactTokenLimitScope::Total => (
active_context_tokens,
turn_context
.model_info
.auto_compact_token_limit()
.unwrap_or(i64::MAX),
None,
),
AutoCompactTokenLimitScope::BodyAfterPrefix => {
let window = sess.auto_compact_window_snapshot().await;
let baseline = window.prefill_input_tokens.unwrap_or(active_context_tokens);
let scope_limit = turn_context
.config
.model_auto_compact_token_limit
.or_else(|| turn_context.model_info.auto_compact_token_limit());
let full_context_window_limit = turn_context.model_context_window();
(
active_context_tokens.saturating_sub(baseline),
scope_limit.unwrap_or(i64::MAX),
Some(BodyAfterPrefixWindowStatus {
full_context_window_limit,
auto_compact_window_prefill_tokens: window.prefill_input_tokens,
has_context_remaining_limit: scope_limit.is_some()
|| full_context_window_limit.is_some(),
}),
)
}
};
let full_context_window_limit = body_window
.as_ref()
.and_then(|window| window.full_context_window_limit);
let auto_compact_window_prefill_tokens = body_window
.as_ref()
.and_then(|window| window.auto_compact_window_prefill_tokens);
let full_context_window_limit_reached =
full_context_window_limit.is_some_and(|full_context_window_limit| {
active_context_tokens >= full_context_window_limit
});
let token_limit_reached =
auto_compact_scope_tokens >= auto_compact_scope_limit || full_context_window_limit_reached;
let full_context_remaining = full_context_window_limit.map_or(i64::MAX, |limit| {
limit.saturating_sub(active_context_tokens)
});
let tokens_until_compaction = auto_compact_scope_limit
.saturating_sub(auto_compact_scope_tokens)
.min(full_context_remaining)
.max(0);
let context_remaining_tokens = match body_window {
Some(body_window) => body_window
.has_context_remaining_limit
.then_some(tokens_until_compaction),
None => turn_context
.model_context_window()
.map(|limit| limit.saturating_sub(active_context_tokens).max(0)),
};
ContextWindowTokenStatus {
active_context_tokens,
auto_compact_scope_tokens,
auto_compact_scope_limit,
full_context_window_limit,
tokens_until_compaction,
auto_compact_window_prefill_tokens,
full_context_window_limit_reached,
token_limit_reached,
context_remaining_tokens,
}
}
+1
View File
@@ -211,6 +211,7 @@ use codex_protocol::exec_output::StreamOutput;
mod code_mode_warning;
mod config_lock;
pub(crate) mod context_window;
mod handlers;
mod inject;
mod input_queue;
+9 -77
View File
@@ -293,8 +293,11 @@ pub(crate) async fn run_turn(
let (has_pending_input, token_status, estimated_token_count) = async {
let has_pending_input =
sess.input_queue.has_pending_input(&sess.active_turn).await;
let token_status =
auto_compact_token_status(sess.as_ref(), turn_context.as_ref()).await;
let token_status = super::context_window::context_window_token_status(
sess.as_ref(),
turn_context.as_ref(),
)
.await;
let estimated_token_count =
sess.get_estimated_token_count(turn_context.as_ref()).await;
(has_pending_input, token_status, estimated_token_count)
@@ -321,21 +324,10 @@ pub(crate) async fn run_turn(
"post sampling token usage"
);
let tokens_after_sampling = token_status.active_context_tokens;
let full_context_remaining = token_status
.full_context_window_limit
.map_or(i64::MAX, |limit| {
limit.saturating_sub(tokens_after_sampling)
});
let tokens_until_compaction = token_status
.auto_compact_scope_limit
.saturating_sub(token_status.auto_compact_scope_tokens)
.min(full_context_remaining)
.max(0);
super::token_budget::maybe_record(
sess.as_ref(),
turn_context.as_ref(),
tokens_until_compaction,
token_status.tokens_until_compaction,
)
.await;
@@ -801,68 +793,6 @@ async fn track_turn_resolved_config_analytics(
});
}
#[derive(Debug)]
struct AutoCompactTokenStatus {
// Full active context usage, independent of the configured auto-compact scope.
active_context_tokens: i64,
// Usage counted against `model_auto_compact_token_limit` for the current scope.
auto_compact_scope_tokens: i64,
auto_compact_scope_limit: i64,
full_context_window_limit: Option<i64>,
auto_compact_window_prefill_tokens: Option<i64>,
full_context_window_limit_reached: bool,
token_limit_reached: bool,
}
async fn auto_compact_token_status(
sess: &Session,
turn_context: &TurnContext,
) -> AutoCompactTokenStatus {
let active_context_tokens = sess.get_total_token_usage().await;
let mut auto_compact_window_prefill_tokens = None;
let (auto_compact_scope_tokens, auto_compact_scope_limit, full_context_window_limit) =
match turn_context.config.model_auto_compact_token_limit_scope {
AutoCompactTokenLimitScope::Total => (
active_context_tokens,
turn_context
.model_info
.auto_compact_token_limit()
.unwrap_or(i64::MAX),
None,
),
AutoCompactTokenLimitScope::BodyAfterPrefix => {
let window = sess.auto_compact_window_snapshot().await;
auto_compact_window_prefill_tokens = window.prefill_input_tokens;
let baseline = window.prefill_input_tokens.unwrap_or(active_context_tokens);
(
active_context_tokens.saturating_sub(baseline),
turn_context
.config
.model_auto_compact_token_limit
.or_else(|| turn_context.model_info.auto_compact_token_limit())
.unwrap_or(i64::MAX),
turn_context.model_context_window(),
)
}
};
let full_context_window_limit_reached =
full_context_window_limit.is_some_and(|full_context_window_limit| {
active_context_tokens >= full_context_window_limit
});
let token_limit_reached =
auto_compact_scope_tokens >= auto_compact_scope_limit || full_context_window_limit_reached;
AutoCompactTokenStatus {
active_context_tokens,
auto_compact_scope_tokens,
auto_compact_scope_limit,
full_context_window_limit,
auto_compact_window_prefill_tokens,
full_context_window_limit_reached,
token_limit_reached,
}
}
#[instrument(level = "trace", skip_all)]
async fn run_pre_sampling_compact(
sess: &Arc<Session>,
@@ -878,7 +808,9 @@ async fn run_pre_sampling_compact(
}
maybe_run_previous_model_inline_compact(sess, turn_context, client_session).await?;
let token_status = auto_compact_token_status(sess.as_ref(), turn_context.as_ref()).await;
let token_status =
super::context_window::context_window_token_status(sess.as_ref(), turn_context.as_ref())
.await;
// Compact if the configured auto-compaction budget or usable context window is exhausted.
if token_status.token_limit_reached {
let step_context = sess.capture_step_context(Arc::clone(turn_context)).await;
+1 -1
View File
@@ -453,7 +453,7 @@ async fn start_thread_seeds_extension_data_for_mcp_and_lifecycle_contributors()
id: id.to_string(),
location: CapabilityRootLocation::Environment {
environment_id: environment_id.to_string(),
path: format!("/plugins/{id}"),
path: PathUri::parse(&format!("file:///plugins/{id}")).expect("plugin root URI"),
},
}]);
init
@@ -75,19 +75,15 @@ impl ToolExecutor<ToolInvocation> for GetContextRemainingHandler {
));
}
let Some(model_context_window) = invocation.turn.model_context_window() else {
return Ok(boxed_tool_output(GetContextRemainingOutput::new(
/*tokens_left*/ None,
)));
};
let active_context_tokens = invocation.session.get_total_token_usage().await.max(0);
let tokens_left = model_context_window
.saturating_sub(active_context_tokens)
.max(0);
let token_status = crate::session::context_window::context_window_token_status(
invocation.session.as_ref(),
invocation.turn.as_ref(),
)
.await;
Ok(boxed_tool_output(GetContextRemainingOutput::new(Some(
tokens_left,
))))
Ok(boxed_tool_output(GetContextRemainingOutput::new(
token_status.context_remaining_tokens,
)))
})
}
}
+3 -7
View File
@@ -23,7 +23,7 @@ use codex_sandboxing::SandboxType;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_output_truncation::TruncationPolicy;
use codex_utils_output_truncation::approx_token_count;
use core_test_support::get_remote_test_env;
use core_test_support::skip_if_no_remote_env;
use core_test_support::skip_if_sandbox;
use core_test_support::test_codex::test_env as remote_test_env;
use pretty_assertions::assert_eq;
@@ -836,9 +836,7 @@ async fn completed_pipe_commands_preserve_exit_code() -> anyhow::Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_uses_remote_exec_server_when_configured() -> anyhow::Result<()> {
skip_if_sandbox!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let remote_test_env = remote_test_env().await?;
let (_, turn) = make_session_and_context().await;
@@ -888,9 +886,7 @@ async fn unified_exec_uses_remote_exec_server_when_configured() -> anyhow::Resul
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn remote_exec_server_rejects_inherited_fd_launches() -> anyhow::Result<()> {
skip_if_sandbox!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let remote_test_env = remote_test_env().await?;
let (_, mut turn) = make_session_and_context().await;
+66 -21
View File
@@ -36,9 +36,15 @@ mod test_environment;
pub mod tracing;
pub mod zsh_fork;
pub use test_environment::TestEnvironment;
pub use test_environment::get_remote_test_env;
pub use test_environment::test_environment;
pub(crate) use test_environment::TestEnvironment;
pub use test_environment::TestTargetOs;
pub use test_environment::is_remote_test_environment;
#[doc(hidden)]
pub use test_environment::is_wine_exec_test_environment;
#[doc(hidden)]
pub use test_environment::test_docker_container_name;
pub(crate) use test_environment::test_environment;
pub use test_environment::test_target_os;
static TEST_ARG0_PATH_ENTRY: OnceLock<Option<Arg0PathEntryGuard>> = OnceLock::new();
@@ -574,21 +580,18 @@ macro_rules! skip_if_no_network {
}
// Exported so the public skip macros can expand in downstream test crates.
// Call `skip_if_remote!` or `skip_if_wine_exec!` instead.
#[macro_export]
#[doc(hidden)]
macro_rules! skip_if_test_environment {
($pattern:pat, $reason:expr $(,)?) => {{
let environment = $crate::test_environment();
if ::std::matches!(&environment, $pattern) {
eprintln!("Skipping test in {environment:?}: {}", $reason);
macro_rules! skip_if_test_condition {
($condition:expr, $environment:expr, $reason:expr $(,)?) => {{
if $condition {
eprintln!("Skipping test in {}: {}", $environment, $reason);
return;
}
}};
($return_value:expr, $pattern:pat, $reason:expr $(,)?) => {{
let environment = $crate::test_environment();
if ::std::matches!(&environment, $pattern) {
eprintln!("Skipping test in {environment:?}: {}", $reason);
($return_value:expr, $condition:expr, $environment:expr, $reason:expr $(,)?) => {{
if $condition {
eprintln!("Skipping test in {}: {}", $environment, $reason);
return $return_value;
}
}};
@@ -597,29 +600,71 @@ macro_rules! skip_if_test_environment {
#[macro_export]
macro_rules! skip_if_remote {
($reason:expr $(,)?) => {{
$crate::skip_if_test_environment!(
$crate::TestEnvironment::Docker { .. } | $crate::TestEnvironment::WineExec,
$crate::skip_if_test_condition!(
$crate::is_remote_test_environment(),
"a remote test environment",
$reason,
);
}};
($return_value:expr, $reason:expr $(,)?) => {{
$crate::skip_if_test_environment!(
$crate::skip_if_test_condition!(
$return_value,
$crate::TestEnvironment::Docker { .. } | $crate::TestEnvironment::WineExec,
$crate::is_remote_test_environment(),
"a remote test environment",
$reason,
);
}};
}
#[macro_export]
macro_rules! skip_if_no_remote_env {
() => {{
if !$crate::is_remote_test_environment() {
eprintln!("Skipping test because it requires a remote test environment.");
return;
}
}};
($return_value:expr $(,)?) => {{
if !$crate::is_remote_test_environment() {
eprintln!("Skipping test because it requires a remote test environment.");
return $return_value;
}
}};
}
#[macro_export]
macro_rules! skip_if_wine_exec {
($reason:expr $(,)?) => {{
$crate::skip_if_test_environment!($crate::TestEnvironment::WineExec, $reason);
$crate::skip_if_test_condition!(
$crate::is_wine_exec_test_environment(),
"the Wine-exec test environment",
$reason,
);
}};
($return_value:expr, $reason:expr $(,)?) => {{
$crate::skip_if_test_environment!(
$crate::skip_if_test_condition!(
$return_value,
$crate::TestEnvironment::WineExec,
$crate::is_wine_exec_test_environment(),
"the Wine-exec test environment",
$reason,
);
}};
}
#[macro_export]
macro_rules! skip_if_target_windows {
($reason:expr $(,)?) => {{
$crate::skip_if_test_condition!(
$crate::test_target_os() == $crate::TestTargetOs::Windows,
"a Windows target environment",
$reason,
);
}};
($return_value:expr, $reason:expr $(,)?) => {{
$crate::skip_if_test_condition!(
$return_value,
$crate::test_target_os() == $crate::TestTargetOs::Windows,
"a Windows target environment",
$reason,
);
}};
@@ -662,7 +707,7 @@ macro_rules! codex_linux_sandbox_exe_or_skip {
}
#[macro_export]
macro_rules! skip_if_windows {
macro_rules! skip_if_host_windows {
($return_value:expr $(,)?) => {{
if cfg!(target_os = "windows") {
println!("Skipping test because it cannot execute on Windows.");
+16 -7
View File
@@ -59,13 +59,13 @@ use wiremock::MockServer;
use crate::TempDirExt;
use crate::TestEnvironment;
use crate::get_remote_test_env;
use crate::load_default_config_for_test;
use crate::load_default_config_for_test_with_cloud_config_bundle;
use crate::responses::WebSocketTestServer;
use crate::responses::output_value_to_text;
use crate::responses::start_mock_server;
use crate::streaming_sse::StreamingSseServer;
use crate::test_environment;
use crate::wait_for_event_match;
use crate::wait_for_event_with_timeout;
use wiremock::Match;
@@ -163,8 +163,8 @@ impl Drop for TestEnv {
}
pub async fn test_env() -> Result<TestEnv> {
match get_remote_test_env() {
Some(remote_env) => {
match test_environment() {
remote_env @ (TestEnvironment::Docker { .. } | TestEnvironment::WineExec) => {
let websocket_url = remote_exec_server_url()?;
let environment =
codex_exec_server::Environment::create_for_tests(Some(websocket_url.clone()))?;
@@ -202,7 +202,7 @@ pub async fn test_env() -> Result<TestEnv> {
remote_container_name: remote_env.docker_container_name().map(str::to_owned),
})
}
None => TestEnv::local().await,
TestEnvironment::Local => TestEnv::local().await,
}
}
@@ -405,7 +405,16 @@ impl TestCodexBuilder {
.await
}
pub async fn build_with_remote_env(
/// Builds a test runtime using the execution environment selected by the test process.
///
/// With no remote test configuration, or with `CODEX_TEST_ENVIRONMENT=local`, this uses a
/// temporary local environment just like [`Self::build`]. `CODEX_TEST_ENVIRONMENT=docker` or
/// `CODEX_TEST_ENVIRONMENT=wine-exec` selects the remote exec server configured by
/// `CODEX_TEST_REMOTE_EXEC_SERVER_URL`; the legacy `CODEX_TEST_REMOTE_ENV` Docker-container
/// configuration does the same. Only the automatically selected environment is registered.
/// Use [`Self::build_with_remote_and_local_env`] when a remote test also needs the local
/// environment to be selectable explicitly.
pub async fn build_with_auto_env(
&mut self,
server: &wiremock::MockServer,
) -> anyhow::Result<TestCodex> {
@@ -961,9 +970,9 @@ impl TestCodexHarness {
Ok(Self { server, test })
}
pub async fn with_remote_env_builder(mut builder: TestCodexBuilder) -> Result<Self> {
pub async fn with_auto_env_builder(mut builder: TestCodexBuilder) -> Result<Self> {
let server = start_mock_server().await;
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
Ok(Self { server, test })
}
+64 -12
View File
@@ -9,25 +9,61 @@ pub const TEST_ENVIRONMENT_ENV_VAR: &str = "CODEX_TEST_ENVIRONMENT";
pub const LEGACY_REMOTE_ENV_ENV_VAR: &str = "CODEX_TEST_REMOTE_ENV";
pub const DOCKER_CONTAINER_ENV_VAR: &str = "CODEX_TEST_REMOTE_ENV_CONTAINER_NAME";
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TestTargetOs {
Linux,
MacOs,
Windows,
}
impl TestTargetOs {
const fn host() -> Self {
if cfg!(target_os = "macos") {
Self::MacOs
} else if cfg!(target_os = "windows") {
Self::Windows
} else if cfg!(target_os = "linux") {
Self::Linux
} else {
unreachable!()
}
}
const fn path_convention(self) -> PathConvention {
match self {
Self::Linux | Self::MacOs => PathConvention::Posix,
Self::Windows => PathConvention::Windows,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum TestEnvironment {
pub(crate) enum TestEnvironment {
Local,
Docker { container_name: String },
WineExec,
}
impl TestEnvironment {
pub fn is_remote(&self) -> bool {
pub(crate) fn is_remote(&self) -> bool {
!matches!(self, Self::Local)
}
pub fn docker_container_name(&self) -> Option<&str> {
pub(crate) fn docker_container_name(&self) -> Option<&str> {
match self {
Self::Docker { container_name } => Some(container_name),
Self::Local | Self::WineExec => None,
}
}
pub(crate) const fn target_os(&self) -> TestTargetOs {
match self {
Self::Local => TestTargetOs::host(),
Self::Docker { .. } => TestTargetOs::Linux,
Self::WineExec => TestTargetOs::Windows,
}
}
pub(crate) fn remote_cwd(&self, instance_id: &str) -> Result<Option<LegacyAppPathString>> {
let path_uri = match self {
Self::Local => return Ok(None),
@@ -47,15 +83,11 @@ impl TestEnvironment {
}
pub(crate) fn path_convention(&self) -> PathConvention {
match self {
Self::Local => PathConvention::native(),
Self::Docker { .. } => PathConvention::Posix,
Self::WineExec => PathConvention::Windows,
}
self.target_os().path_convention()
}
}
pub fn test_environment() -> TestEnvironment {
pub(crate) fn test_environment() -> TestEnvironment {
let environment = parse_test_environment(
std::env::var_os(TEST_ENVIRONMENT_ENV_VAR).as_deref(),
std::env::var_os(LEGACY_REMOTE_ENV_ENV_VAR).as_deref(),
@@ -70,9 +102,29 @@ pub fn test_environment() -> TestEnvironment {
environment
}
pub fn get_remote_test_env() -> Option<TestEnvironment> {
let environment = test_environment();
environment.is_remote().then_some(environment)
/// Returns the operating system used by the selected test execution environment.
pub fn test_target_os() -> TestTargetOs {
test_environment().target_os()
}
/// Returns whether the selected test execution environment is remote.
pub fn is_remote_test_environment() -> bool {
test_environment().is_remote()
}
/// Returns the selected Docker test container, when the harness requires direct access to it.
#[doc(hidden)]
pub fn test_docker_container_name() -> Option<String> {
match test_environment() {
TestEnvironment::Docker { container_name } => Some(container_name),
TestEnvironment::Local | TestEnvironment::WineExec => None,
}
}
/// Returns whether the Wine-backed executor is selected.
#[doc(hidden)]
pub fn is_wine_exec_test_environment() -> bool {
matches!(test_environment(), TestEnvironment::WineExec)
}
fn parse_test_environment(
@@ -116,3 +116,30 @@ fn rejects_invalid_or_incomplete_configuration() {
))
);
}
#[test]
fn derives_target_operating_system_and_placement() {
#[cfg(target_os = "linux")]
let expected_local_target_os = TestTargetOs::Linux;
#[cfg(target_os = "macos")]
let expected_local_target_os = TestTargetOs::MacOs;
#[cfg(target_os = "windows")]
let expected_local_target_os = TestTargetOs::Windows;
let environments = [
TestEnvironment::Local,
TestEnvironment::Docker {
container_name: "container-1".to_string(),
},
TestEnvironment::WineExec,
];
assert_eq!(
environments.map(|environment| (environment.target_os(), environment.is_remote())),
[
(expected_local_target_os, false),
(TestTargetOs::Linux, true),
(TestTargetOs::Windows, true),
]
);
}
+6 -8
View File
@@ -16,7 +16,6 @@ use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use core_test_support::PathBufExt;
use core_test_support::create_directory_symlink;
use core_test_support::get_remote_test_env;
use core_test_support::load_default_config_for_test;
use core_test_support::responses;
use core_test_support::responses::ev_completed;
@@ -25,6 +24,7 @@ use core_test_support::responses::mount_sse_once;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_no_remote_env;
use core_test_support::test_codex::RecordingUserInstructionsProvider;
use core_test_support::test_codex::TestCodexBuilder;
use core_test_support::test_codex::test_codex;
@@ -57,7 +57,7 @@ async fn agents_instructions(mut builder: TestCodexBuilder) -> Result<String> {
)
.await;
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
test.submit_turn("hello").await?;
let request = resp_mock.single_request();
@@ -372,7 +372,7 @@ async fn selected_environment_sources_match_model_visible_instructions() -> Resu
.await?;
Ok::<(), anyhow::Error>(())
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let project_agents = test.config.cwd.join("AGENTS.md");
let global_agents = global_agents.abs();
@@ -430,7 +430,7 @@ async fn loads_user_instructions_without_a_primary_environment() -> Result<()> {
.await?;
Ok(())
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
assert_eq!(provider.load_count(), 1);
let no_environment_thread = test
@@ -515,7 +515,7 @@ async fn fresh_thread_composes_global_before_project_and_reports_sources() -> Re
.await?;
Ok(())
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let project_source = test.config.cwd.join(GLOBAL_AGENTS_FILENAME);
let creation_sources = vec![
PathUri::from_abs_path(&global_source),
@@ -597,9 +597,7 @@ async fn fresh_thread_composes_global_before_project_and_reports_sources() -> Re
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn multi_environment_thread_loads_every_project_and_keeps_creation_snapshot() -> Result<()> {
skip_if_no_network!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let server = responses::start_mock_server().await;
let response_mock = responses::mount_sse_sequence(
+6 -8
View File
@@ -38,7 +38,6 @@ use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use core_test_support::PathBufExt;
use core_test_support::assert_regex_match;
use core_test_support::get_remote_test_env;
use core_test_support::responses::ev_assistant_message;
use core_test_support::responses::ev_completed;
use core_test_support::responses::ev_function_call;
@@ -48,8 +47,9 @@ use core_test_support::responses::mount_sse_sequence;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_no_remote_env;
use core_test_support::skip_if_remote;
use core_test_support::skip_if_wine_exec;
use core_test_support::skip_if_target_windows;
use core_test_support::test_codex::TestCodexBuilder;
use core_test_support::test_codex::TestCodexHarness;
use core_test_support::test_codex::local;
@@ -74,7 +74,7 @@ async fn apply_patch_harness_with(
let builder = configure(test_codex());
// Box harness construction so apply_patch_cli tests do not inline the
// full test-thread startup path into each test future.
Box::pin(TestCodexHarness::with_remote_env_builder(builder)).await
Box::pin(TestCodexHarness::with_auto_env_builder(builder)).await
}
async fn submit_without_wait(harness: &TestCodexHarness, prompt: &str) -> Result<()> {
@@ -911,7 +911,7 @@ async fn apply_patch_cli_preserves_existing_hard_link_outside_workspace() -> Res
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn apply_patch_cli_rejects_move_path_traversal_outside_workspace() -> Result<()> {
// TODO(anp): Remove after apply-patch fixtures use target-native paths.
skip_if_wine_exec!(Ok(()), "asserts POSIX workspace traversal behavior");
skip_if_target_windows!(Ok(()), "asserts POSIX workspace traversal behavior");
skip_if_no_network!(Ok(()));
let harness = apply_patch_harness().await?;
@@ -1568,14 +1568,12 @@ async fn apply_patch_emits_turn_diff_event_with_unified_diff() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn apply_patch_turn_diff_tracks_local_and_remote_environment_paths() -> Result<()> {
// TODO(anp): Remove after shared-cwd helpers use target-native paths.
skip_if_wine_exec!(
skip_if_target_windows!(
Ok(()),
"requires a cwd valid in local POSIX and remote Windows environments"
);
skip_if_no_network!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let server = start_mock_server().await;
let mut builder = test_codex();
+2 -2
View File
@@ -38,8 +38,8 @@ use core_test_support::responses::mount_sse_once;
use core_test_support::responses::mount_sse_sequence;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_host_windows;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_windows;
use core_test_support::streaming_sse::StreamingSseChunk;
use core_test_support::streaming_sse::start_streaming_sse_server;
use core_test_support::test_codex::test_codex;
@@ -4012,7 +4012,7 @@ async fn post_tool_use_spills_large_feedback_message() -> Result<()> {
#[tokio::test]
async fn post_tool_use_blocks_when_exec_session_completes_via_write_stdin() -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let server = start_mock_server().await;
let start_call_id = "posttooluse-exec-session-start";
@@ -22,7 +22,6 @@ use codex_protocol::user_input::UserInput;
use codex_utils_path_uri::PathUri;
use core_test_support::PathBufExt;
use core_test_support::PathExt;
use core_test_support::get_remote_test_env;
use core_test_support::managed_network_requirements_loader;
use core_test_support::responses::ResponseMock;
use core_test_support::responses::ev_assistant_message;
@@ -32,10 +31,11 @@ use core_test_support::responses::ev_response_created;
use core_test_support::responses::mount_sse_sequence;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_host_windows;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_no_remote_env;
use core_test_support::skip_if_sandbox;
use core_test_support::skip_if_windows;
use core_test_support::skip_if_wine_exec;
use core_test_support::skip_if_target_windows;
use core_test_support::test_codex::TestCodex;
use core_test_support::test_codex::local;
use core_test_support::test_codex::test_codex;
@@ -58,13 +58,11 @@ const NETWORK_TEST_TARGET: &str = "http://codex-network-test.invalid:80";
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn approved_network_host_for_one_environment_still_prompts_in_another() -> Result<()> {
skip_if_wine_exec!(Ok(()), "uses the POSIX/Python network fixture");
skip_if_target_windows!(Ok(()), "uses the POSIX/Python network fixture");
skip_if_host_windows!(Ok(()));
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let server = start_mock_server().await;
let test = managed_network_unified_exec_test(&server).await?;
+1 -1
View File
@@ -199,7 +199,7 @@ async fn codex_apps_file_params_upload_environment_files_before_mcp_tool_call()
.await?;
Ok(())
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let mock = run_extract_turn(&test, &server).await?;
let requests = mock.requests();
+41 -63
View File
@@ -34,8 +34,7 @@ use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use core_test_support::PathBufExt;
use core_test_support::PathExt;
use core_test_support::TestEnvironment;
use core_test_support::get_remote_test_env;
use core_test_support::TestTargetOs;
use core_test_support::responses::ev_apply_patch_custom_tool_call;
use core_test_support::responses::ev_assistant_message;
use core_test_support::responses::ev_completed;
@@ -47,11 +46,14 @@ use core_test_support::responses::mount_sse_sequence;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_wine_exec;
use core_test_support::skip_if_no_remote_env;
use core_test_support::skip_if_target_windows;
use core_test_support::test_codex::TestCodex;
use core_test_support::test_codex::local;
use core_test_support::test_codex::test_codex;
use core_test_support::test_codex::test_env;
use core_test_support::test_docker_container_name;
use core_test_support::test_target_os;
use core_test_support::wait_for_event;
use core_test_support::wait_for_event_match;
use futures::SinkExt;
@@ -167,9 +169,7 @@ async fn wait_for_completion_without_patch_approval(test: &TestCodex) {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn remote_test_env_can_connect_and_use_filesystem() -> Result<()> {
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let test_env = test_env().await?;
let file_system = test_env.environment().get_filesystem();
@@ -202,9 +202,7 @@ async fn remote_test_env_can_connect_and_use_filesystem() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn remote_test_env_exposes_target_shell_to_model() -> Result<()> {
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let server = start_mock_server().await;
let response_mock = mount_sse_once(
@@ -216,7 +214,7 @@ async fn remote_test_env_exposes_target_shell_to_model() -> Result<()> {
]),
)
.await;
let test = test_codex().build_with_remote_env(&server).await?;
let test = test_codex().build_with_auto_env(&server).await?;
test.submit_turn("report remote environment").await?;
@@ -228,10 +226,10 @@ async fn remote_test_env_exposes_target_shell_to_model() -> Result<()> {
.context("environment context should be model visible")?;
// TODO(anp): Assert Wine-exec exposes a `C:\\...` cwd after model-visible paths preserve
// target-native spelling instead of the Linux orchestrator's `/C:/...` representation.
let expected_shell = match core_test_support::test_environment() {
TestEnvironment::Docker { .. } => "<shell>bash</shell>",
TestEnvironment::WineExec => "<shell>powershell</shell>",
TestEnvironment::Local => unreachable!("test requires a remote environment"),
let expected_shell = match test_target_os() {
TestTargetOs::Linux => "<shell>bash</shell>",
TestTargetOs::Windows => "<shell>powershell</shell>",
TestTargetOs::MacOs => unreachable!("remote test targets do not run macOS"),
};
assert_eq!(
environment_context
@@ -248,16 +246,18 @@ async fn remote_test_env_exposes_target_shell_to_model() -> Result<()> {
async fn explicit_remote_shell_runs_in_remote_cwd() -> Result<()> {
const CALL_ID: &str = "remote-explicit-shell";
let (shell, command) = match core_test_support::test_environment() {
TestEnvironment::Docker { .. } => (
skip_if_no_remote_env!(Ok(()));
let (shell, command) = match test_target_os() {
TestTargetOs::Linux => (
"bash",
r#"case "$PWD" in /tmp/codex-core-test-cwd-*) ;; *) echo "unexpected cwd: $PWD" >&2; exit 1 ;; esac"#,
),
TestEnvironment::WineExec => (
TestTargetOs::Windows => (
"powershell",
r#"$cwd = (Get-Location).Path; if ($cwd -notlike 'C:\codex-core-test-cwd-*') { Write-Error "unexpected cwd: $cwd"; exit 1 }"#,
),
TestEnvironment::Local => return Ok(()),
TestTargetOs::MacOs => unreachable!("remote test targets do not run macOS"),
};
let server = start_mock_server().await;
@@ -274,7 +274,7 @@ async fn explicit_remote_shell_runs_in_remote_cwd() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let response_mock = mount_sse_sequence(
&server,
vec![
@@ -771,12 +771,10 @@ fn assert_normalized_path_rejected(error: &std::io::Error) {
}
fn remote_exec(script: &str) -> Result<()> {
let remote_env = get_remote_test_env().context("remote env should be configured")?;
let container_name = remote_env
.docker_container_name()
let container_name = test_docker_container_name()
.context("test requires direct access to the Docker container")?;
let output = Command::new("docker")
.args(["exec", container_name, "sh", "-lc", script])
.args(["exec", container_name.as_str(), "sh", "-lc", script])
.output()?;
assert!(
output.status.success(),
@@ -823,10 +821,8 @@ async fn exec_command_routing_output(
async fn exec_command_routes_to_selected_remote_environment() -> Result<()> {
skip_if_no_network!(Ok(()));
// TODO(anp): Remove after remote path fixtures use target-native paths.
skip_if_wine_exec!(Ok(()), "requires the Docker-backed POSIX executor");
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_target_windows!(Ok(()), "requires the Docker-backed POSIX executor");
skip_if_no_remote_env!(Ok(()));
let server = start_mock_server().await;
let test = unified_exec_test(&server).await?;
@@ -900,10 +896,8 @@ async fn exec_command_routes_to_selected_remote_environment() -> Result<()> {
async fn remote_request_permissions_grant_unblocks_later_remote_exec() -> Result<()> {
skip_if_no_network!(Ok(()));
// TODO(anp): Remove after remote path fixtures use target-native paths.
skip_if_wine_exec!(Ok(()), "requires the Docker-backed POSIX executor");
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_target_windows!(Ok(()), "requires the Docker-backed POSIX executor");
skip_if_no_remote_env!(Ok(()));
let server = start_mock_server().await;
let mut builder = test_codex().with_config(|config| {
@@ -1107,10 +1101,8 @@ async fn remote_request_permissions_grant_unblocks_later_remote_exec() -> Result
async fn apply_patch_freeform_routes_to_selected_remote_environment() -> Result<()> {
skip_if_no_network!(Ok(()));
// TODO(anp): Remove after remote path fixtures use target-native paths.
skip_if_wine_exec!(Ok(()), "requires the Docker-backed POSIX executor");
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_target_windows!(Ok(()), "requires the Docker-backed POSIX executor");
skip_if_no_remote_env!(Ok(()));
let server = start_mock_server().await;
let mut builder = test_codex();
@@ -1195,10 +1187,8 @@ async fn apply_patch_freeform_routes_to_selected_remote_environment() -> Result<
async fn apply_patch_approvals_are_remembered_per_environment() -> Result<()> {
skip_if_no_network!(Ok(()));
// TODO(anp): Remove after remote path fixtures use target-native paths.
skip_if_wine_exec!(Ok(()), "requires the Docker-backed POSIX executor");
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_target_windows!(Ok(()), "requires the Docker-backed POSIX executor");
skip_if_no_remote_env!(Ok(()));
let server = start_mock_server().await;
let mut builder = test_codex().with_config(|config| {
@@ -1386,10 +1376,8 @@ async fn apply_patch_intercepted_exec_command_routes_to_selected_remote_environm
{
skip_if_no_network!(Ok(()));
// TODO(anp): Remove after remote path fixtures use target-native paths.
skip_if_wine_exec!(Ok(()), "requires the Docker-backed POSIX executor");
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_target_windows!(Ok(()), "requires the Docker-backed POSIX executor");
skip_if_no_remote_env!(Ok(()));
let server = start_mock_server().await;
let test = unified_exec_test(&server).await?;
@@ -1482,11 +1470,9 @@ async fn apply_patch_intercepted_exec_command_routes_to_selected_remote_environm
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn remote_test_env_sandboxed_read_allows_readable_root() -> Result<()> {
// TODO(anp): Remove after remote sandbox fixtures use target-native paths.
skip_if_wine_exec!(Ok(()), "requires the Docker-backed POSIX executor");
skip_if_target_windows!(Ok(()), "requires the Docker-backed POSIX executor");
skip_if_no_network!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let test_env = test_env().await?;
let file_system = test_env.environment().get_filesystem();
@@ -1532,11 +1518,9 @@ async fn remote_test_env_sandboxed_read_allows_readable_root() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn remote_test_env_sandboxed_read_rejects_symlink_parent_dotdot_escape() -> Result<()> {
skip_if_wine_exec!(Ok(()), "tests POSIX symlink and parent traversal semantics");
skip_if_target_windows!(Ok(()), "tests POSIX symlink and parent traversal semantics");
skip_if_no_network!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let test_env = test_env().await?;
let file_system = test_env.environment().get_filesystem();
@@ -1568,11 +1552,9 @@ async fn remote_test_env_sandboxed_read_rejects_symlink_parent_dotdot_escape() -
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn remote_test_env_remove_removes_symlink_not_target() -> Result<()> {
skip_if_wine_exec!(Ok(()), "tests POSIX symlink removal semantics");
skip_if_target_windows!(Ok(()), "tests POSIX symlink removal semantics");
skip_if_no_network!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let test_env = test_env().await?;
let file_system = test_env.environment().get_filesystem();
@@ -1642,11 +1624,9 @@ async fn remote_test_env_remove_removes_symlink_not_target() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn remote_test_env_copy_preserves_symlink_source() -> Result<()> {
skip_if_wine_exec!(Ok(()), "tests POSIX symlink copy semantics");
skip_if_target_windows!(Ok(()), "tests POSIX symlink copy semantics");
skip_if_no_network!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let test_env = test_env().await?;
let file_system = test_env.environment().get_filesystem();
@@ -1678,14 +1658,12 @@ async fn remote_test_env_copy_preserves_symlink_source() -> Result<()> {
)
.await?;
let remote_env = get_remote_test_env().context("remote env should be configured")?;
let container_name = remote_env
.docker_container_name()
let container_name = test_docker_container_name()
.context("test requires direct access to the Docker container")?;
let link_target = Command::new("docker")
.args([
"exec",
container_name,
container_name.as_str(),
"readlink",
copied_symlink
.to_str()
+25 -27
View File
@@ -48,17 +48,19 @@ use codex_protocol::user_input::UserInput;
use codex_utils_cargo_bin::cargo_bin;
use codex_utils_path_uri::PathUri;
use core_test_support::assert_regex_match;
use core_test_support::is_remote_test_environment;
use core_test_support::responses;
use core_test_support::responses::mount_models_once;
use core_test_support::responses::mount_sse_once;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_no_remote_env;
use core_test_support::skip_if_wine_exec;
use core_test_support::stdio_server_bin;
use core_test_support::test_codex::TestCodex;
use core_test_support::test_codex::test_codex;
use core_test_support::test_codex::turn_permission_fields;
use core_test_support::test_environment;
use core_test_support::test_docker_container_name;
use core_test_support::wait_for_event;
use core_test_support::wait_for_mcp_server;
use image::DynamicImage;
@@ -165,7 +167,7 @@ enum McpCallEvent {
const REMOTE_MCP_ENVIRONMENT: &str = "remote";
fn remote_aware_environment_id() -> String {
if test_environment().is_remote() {
if is_remote_test_environment() {
REMOTE_MCP_ENVIRONMENT.to_string()
} else {
codex_config::DEFAULT_MCP_SERVER_ENVIRONMENT_ID.to_string()
@@ -181,8 +183,7 @@ fn remote_aware_environment_id() -> String {
/// container and return that in-container path instead.
fn remote_aware_stdio_server_bin() -> anyhow::Result<String> {
let bin = stdio_server_bin()?;
let environment = test_environment();
let Some(container_name) = environment.docker_container_name() else {
let Some(container_name) = test_docker_container_name() else {
return Ok(bin);
};
@@ -195,7 +196,7 @@ fn remote_aware_stdio_server_bin() -> anyhow::Result<String> {
// path instead of the host build artifact path.
// Several remote-aware MCP tests can run in parallel; give each copied
// binary its own path so one test cannot replace another test's executable.
copy_binary_to_remote_env(container_name, Path::new(&bin), "test_stdio_server")
copy_binary_to_remote_env(&container_name, Path::new(&bin), "test_stdio_server")
}
/// Builds a collision-resistant in-container path for copied test binaries.
@@ -506,7 +507,7 @@ fn assert_cwd_tool_output(structured: &Value, expected_cwd: &Path) {
.and_then(Value::as_str)
.expect("cwd tool should return a string cwd");
if test_environment().is_remote() {
if is_remote_test_environment() {
assert_eq!(
structured,
&json!({
@@ -602,7 +603,7 @@ async fn stdio_server_round_trip() -> anyhow::Result<()> {
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -781,7 +782,7 @@ async fn stdio_server_uses_configured_cwd_before_runtime_fallback() -> anyhow::R
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -907,7 +908,7 @@ async fn stdio_mcp_tool_call_includes_sandbox_state_meta() -> anyhow::Result<()>
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1001,7 +1002,7 @@ async fn stdio_mcp_parallel_tool_calls_default_false_runs_serially() -> anyhow::
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1142,7 +1143,7 @@ async fn stdio_mcp_read_only_tool_calls_run_concurrently_without_server_opt_in()
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1231,7 +1232,7 @@ async fn stdio_mcp_parallel_tool_calls_opt_in_runs_concurrently() -> anyhow::Res
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1322,7 +1323,7 @@ async fn stdio_image_responses_round_trip() -> anyhow::Result<()> {
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1476,7 +1477,7 @@ async fn stdio_image_responses_resize_large_image() -> anyhow::Result<()> {
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1564,7 +1565,7 @@ async fn stdio_image_responses_preserve_original_detail_metadata() -> anyhow::Re
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1710,7 +1711,7 @@ async fn stdio_image_responses_are_sanitized_for_text_only_model() -> anyhow::Re
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1818,7 +1819,7 @@ async fn stdio_server_propagates_whitelisted_env_vars() -> anyhow::Result<()> {
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1943,7 +1944,7 @@ async fn stdio_server_propagates_explicit_local_env_var_source() -> anyhow::Resu
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -1986,9 +1987,7 @@ async fn remote_stdio_env_var_source_does_not_copy_local_env() -> anyhow::Result
"requires a Windows test_stdio_server in the Wine-exec environment"
);
skip_if_no_network!(Ok(()));
if !test_environment().is_remote() {
return Ok(());
}
skip_if_no_remote_env!(Ok(()));
let server = responses::start_mock_server().await;
let call_id = "call-remote-source";
@@ -2041,7 +2040,7 @@ async fn remote_stdio_env_var_source_does_not_copy_local_env() -> anyhow::Result
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -2225,7 +2224,7 @@ async fn streamable_http_tool_call_round_trip() -> anyhow::Result<()> {
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
wait_for_mcp_server(&fixture.codex, server_name).await?;
@@ -2412,7 +2411,7 @@ async fn streamable_http_with_oauth_round_trip_impl() -> anyhow::Result<()> {
},
);
})
.build_with_remote_env(&server)
.build_with_auto_env(&server)
.await?;
// Phase 5: wait for MCP startup before the turn is submitted, which keeps
// failures tied to server startup/discovery.
@@ -2501,11 +2500,10 @@ async fn start_streamable_http_test_server(
}
};
let environment = test_environment();
if let Some(container_name) = environment.docker_container_name() {
if let Some(container_name) = test_docker_container_name() {
return Ok(Some(
start_remote_streamable_http_test_server(
container_name,
&container_name,
&rmcp_http_server_bin,
expected_env_value,
expected_token,
+3 -3
View File
@@ -8,8 +8,8 @@ use core_test_support::responses::ev_function_call;
use core_test_support::responses::ev_response_created;
use core_test_support::responses::mount_sse_sequence;
use core_test_support::responses::sse;
use core_test_support::skip_if_host_windows;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_windows;
use core_test_support::test_codex::TestCodexBuilder;
use core_test_support::test_codex::TestCodexHarness;
use core_test_support::test_codex::test_codex;
@@ -181,7 +181,7 @@ async fn multi_line_output_with_login() -> anyhow::Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn pipe_output_with_login() -> anyhow::Result<()> {
skip_if_no_network!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let harness = shell_command_harness_with(|builder| builder.with_model("gpt-5.4")).await?;
@@ -204,7 +204,7 @@ async fn pipe_output_with_login() -> anyhow::Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn pipe_output_without_login() -> anyhow::Result<()> {
skip_if_no_network!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let harness = shell_command_harness_with(|builder| builder.with_model("gpt-5.4")).await?;
@@ -11,7 +11,7 @@ use core_test_support::responses::mount_sse_sequence;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_wine_exec;
use core_test_support::skip_if_target_windows;
use core_test_support::test_codex::test_codex;
use pretty_assertions::assert_eq;
use regex_lite::Regex;
@@ -236,7 +236,7 @@ M {file_name}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn apply_patch_custom_tool_call_reports_failure_output() -> Result<()> {
// TODO(anp): Remove after apply-patch assertions use target-native paths.
skip_if_wine_exec!(Ok(()), "asserts POSIX apply_patch failure text");
skip_if_target_windows!(Ok(()), "asserts POSIX apply_patch failure text");
skip_if_no_network!(Ok(()));
let harness = apply_patch_harness().await?;
+3 -3
View File
@@ -17,7 +17,7 @@ use core_test_support::responses::mount_sse_once;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_wine_exec;
use core_test_support::skip_if_target_windows;
use core_test_support::test_codex::local_selections;
use core_test_support::test_codex::test_codex;
use core_test_support::test_codex::turn_permission_fields;
@@ -49,7 +49,7 @@ async fn write_repo_skill(
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn user_turn_includes_skill_instructions() -> Result<()> {
// TODO(anp): Remove after skill-path helpers use target-native paths.
skip_if_wine_exec!(Ok(()), "requires native cross-OS skill paths");
skip_if_target_windows!(Ok(()), "requires native cross-OS skill paths");
skip_if_no_network!(Ok(()));
let server = start_mock_server().await;
@@ -57,7 +57,7 @@ async fn user_turn_includes_skill_instructions() -> Result<()> {
let mut builder = test_codex().with_workspace_setup(move |cwd, fs| async move {
write_repo_skill(cwd, fs, "demo", "demo skill", skill_body).await
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let skill_path = test
.config
+145
View File
@@ -4,6 +4,7 @@ use codex_config::types::McpServerTransportConfig;
use codex_core::config::TokenBudgetConfig;
use codex_features::Feature;
use codex_model_provider_info::built_in_model_providers;
use codex_protocol::config_types::AutoCompactTokenLimitScope;
use codex_protocol::protocol::CONTEXT_WINDOW_CLOSE_TAG;
use codex_protocol::protocol::CONTEXT_WINDOW_OPEN_TAG;
use codex_protocol::protocol::EventMsg;
@@ -79,6 +80,22 @@ fn tool_names(request: &ResponsesRequest) -> Vec<String> {
.collect()
}
fn ev_completed_with_usage(id: &str, input_tokens: i64, output_tokens: i64) -> Value {
json!({
"type": "response.completed",
"response": {
"id": id,
"usage": {
"input_tokens": input_tokens,
"input_tokens_details": null,
"output_tokens": output_tokens,
"output_tokens_details": null,
"total_tokens": input_tokens + output_tokens
}
}
})
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn token_budget_context_is_only_emitted_with_full_context() -> Result<()> {
skip_if_no_network!(Ok(()));
@@ -264,6 +281,70 @@ async fn token_budget_reminder_emits_after_crossing_compaction_threshold() -> Re
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn token_budget_reminder_uses_body_after_prefix_window() -> Result<()> {
skip_if_no_network!(Ok(()));
let server = start_mock_server().await;
let responses = mount_sse_sequence(
&server,
vec![
sse(vec![
ev_response_created("resp-1"),
ev_completed_with_tokens("resp-1", /*total_tokens*/ 8_000),
]),
sse(vec![
ev_response_created("resp-2"),
ev_completed_with_tokens("resp-2", /*total_tokens*/ 8_600),
]),
sse(vec![ev_response_created("resp-3"), ev_completed("resp-3")]),
],
)
.await;
let test = test_codex()
.with_config(|config| {
config.model_context_window = Some(10_000);
config.model_auto_compact_token_limit = Some(1_000);
config.model_auto_compact_token_limit_scope =
AutoCompactTokenLimitScope::BodyAfterPrefix;
config.token_budget = Some(TokenBudgetConfig {
reminder_threshold_tokens: Some(600),
..TokenBudgetConfig::default()
});
config
.features
.enable(Feature::TokenBudget)
.expect("test config should allow token budget");
})
.build(&server)
.await?;
test.submit_turn("establish prefix").await?;
test.submit_turn("grow body").await?;
test.submit_turn("observe reminder").await?;
let requests = responses.requests();
assert_eq!(requests.len(), 3);
let reminder = "Your context window is nearly exhausted (only 400 tokens remaining) and will be automatically reset for you soon. Once reset, message items in current context window will be cleared in the new window, but notes and history items will be persistent across windows.";
assert!(
requests[1]
.message_input_texts("developer")
.into_iter()
.all(|text| text != reminder),
"first-window prefix should not count against the body-after-prefix reminder threshold"
);
assert_eq!(
requests[2]
.message_input_texts("developer")
.into_iter()
.filter(|text| text == reminder)
.count(),
1
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_context_remaining_returns_token_budget_remaining_fragment() -> Result<()> {
skip_if_no_network!(Ok(()));
@@ -327,6 +408,70 @@ async fn get_context_remaining_returns_token_budget_remaining_fragment() -> Resu
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_context_remaining_uses_body_after_prefix_window() -> Result<()> {
skip_if_no_network!(Ok(()));
let server = start_mock_server().await;
let call_id = "remaining-call";
let responses = mount_sse_sequence(
&server,
vec![
sse(vec![
ev_response_created("resp-1"),
ev_assistant_message("msg-1", "noted"),
ev_completed_with_usage(
"resp-1", /*input_tokens*/ 2_000, /*output_tokens*/ 500,
),
]),
sse(vec![
ev_response_created("resp-2"),
ev_function_call(call_id, "get_context_remaining", "{}"),
ev_completed_with_tokens("resp-2", /*total_tokens*/ 2_500),
]),
sse(vec![
ev_response_created("resp-3"),
ev_assistant_message("msg-3", "done"),
ev_completed("resp-3"),
]),
],
)
.await;
let test = test_codex()
.with_config(|config| {
config.model_context_window = Some(10_000);
config.model_auto_compact_token_limit = Some(7_000);
config.model_auto_compact_token_limit_scope =
AutoCompactTokenLimitScope::BodyAfterPrefix;
config
.features
.enable(Feature::TokenBudget)
.expect("test config should allow token budget");
})
.build(&server)
.await?;
test.submit_turn("spend some tokens").await?;
test.submit_turn("check remaining context").await?;
let requests = responses.requests();
assert_eq!(requests.len(), 3);
assert!(
tool_names(&requests[1])
.iter()
.any(|name| name == "get_context_remaining"),
"get_context_remaining should be exposed when token budget is enabled"
);
let remaining_context = "You have 6500 tokens left in this context window.".to_string();
assert_eq!(
requests[2].function_call_output_content_and_success(call_id),
Some((Some(remaining_context), None))
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_context_remaining_returns_unknown_when_window_is_unavailable() -> Result<()> {
skip_if_no_network!(Ok(()));
+60 -81
View File
@@ -31,9 +31,10 @@ use core_test_support::responses::ev_response_created;
use core_test_support::responses::mount_sse_sequence;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_host_windows;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_sandbox;
use core_test_support::skip_if_windows;
use core_test_support::skip_if_target_windows;
use core_test_support::skip_if_wine_exec;
use core_test_support::test_codex::TestCodex;
use core_test_support::test_codex::TestCodexHarness;
@@ -244,7 +245,7 @@ async fn create_workspace_directory(
async fn unified_exec_intercepts_apply_patch_exec_command() -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let builder = test_codex().with_config(|config| {
config.use_experimental_unified_exec_tool = true;
@@ -386,13 +387,12 @@ async fn unified_exec_intercepts_apply_patch_exec_command() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_emits_exec_command_begin_event() -> Result<()> {
// TODO(anp): Remove after unified-exec fixtures use target-native commands.
skip_if_wine_exec!(
skip_if_target_windows!(
Ok(()),
"uses a POSIX command and does not assert successful execution"
);
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -403,7 +403,7 @@ async fn unified_exec_emits_exec_command_begin_event() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let cwd = test.config.cwd.to_path_buf();
let call_id = "uexec-begin-event";
@@ -450,13 +450,12 @@ async fn unified_exec_emits_exec_command_begin_event() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_resolves_relative_workdir() -> Result<()> {
// TODO(anp): Remove after workdir helpers use target-native paths.
skip_if_wine_exec!(
skip_if_target_windows!(
Ok(()),
"does not assert successful native-Windows workdir execution"
);
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -467,7 +466,7 @@ async fn unified_exec_resolves_relative_workdir() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let workdir_rel = std::path::PathBuf::from("uexec_relative_workdir");
let workdir = create_workspace_directory(&test, &workdir_rel).await?;
@@ -524,7 +523,7 @@ async fn unified_exec_resolves_relative_workdir() -> Result<()> {
async fn unified_exec_respects_workdir_override() -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let server = start_mock_server().await;
@@ -535,7 +534,7 @@ async fn unified_exec_respects_workdir_override() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let workdir = create_workspace_directory(&test, "uexec_workdir_test").await?;
@@ -588,10 +587,9 @@ async fn unified_exec_respects_workdir_override() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_emits_exec_command_end_event() -> Result<()> {
// TODO(anp): Remove after unified-exec fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses a POSIX-only command fixture");
skip_if_target_windows!(Ok(()), "uses a POSIX-only command fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -602,7 +600,7 @@ async fn unified_exec_emits_exec_command_end_event() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let call_id = "uexec-end-event";
let args = json!({
@@ -663,10 +661,9 @@ async fn unified_exec_emits_exec_command_end_event() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_emits_output_delta_for_exec_command() -> Result<()> {
// TODO(anp): Remove after unified-exec fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses a POSIX-only command fixture");
skip_if_target_windows!(Ok(()), "uses a POSIX-only command fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -677,7 +674,7 @@ async fn unified_exec_emits_output_delta_for_exec_command() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let call_id = "uexec-delta-1";
let args = json!({
@@ -723,10 +720,9 @@ async fn unified_exec_emits_output_delta_for_exec_command() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_full_lifecycle_with_background_end_event() -> Result<()> {
// TODO(anp): Remove after unified-exec fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses a POSIX-only command fixture");
skip_if_target_windows!(Ok(()), "uses a POSIX-only command fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -737,7 +733,7 @@ async fn unified_exec_full_lifecycle_with_background_end_event() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let call_id = "uexec-full-lifecycle";
// This timing force the long-standing PTY
@@ -820,10 +816,9 @@ async fn unified_exec_full_lifecycle_with_background_end_event() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_network_denial_emits_failed_background_end_event() -> Result<()> {
// TODO(anp): Remove after network-denial fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses the POSIX/Python network-denial fixture");
skip_if_target_windows!(Ok(()), "uses the POSIX/Python network-denial fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
let (test, sandbox_policy) = unified_exec_network_denial_test(&server).await?;
@@ -865,10 +860,9 @@ async fn unified_exec_network_denial_emits_failed_background_end_event() -> Resu
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_short_lived_network_denial_emits_failed_end_event() -> Result<()> {
// TODO(anp): Remove after network-denial fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses the POSIX/Python network-denial fixture");
skip_if_target_windows!(Ok(()), "uses the POSIX/Python network-denial fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
let (test, sandbox_policy) = unified_exec_network_denial_test(&server).await?;
@@ -950,7 +944,7 @@ allow_local_binding = true
.set_permission_profile(permission_profile_for_config)
.expect("set permission profile");
});
let test = builder.build_with_remote_env(server).await?;
let test = builder.build_with_auto_env(server).await?;
assert!(
test.config.permissions.network.is_some(),
"expected managed network proxy config to be present"
@@ -1020,10 +1014,9 @@ async fn wait_for_unified_exec_end(
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_emits_terminal_interaction_for_write_stdin() -> Result<()> {
// TODO(anp): Remove after unified-exec interactive fixtures support Windows/ConPTY.
skip_if_wine_exec!(Ok(()), "uses POSIX interactive-process and EOF semantics");
skip_if_target_windows!(Ok(()), "uses POSIX interactive-process and EOF semantics");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1034,7 +1027,7 @@ async fn unified_exec_emits_terminal_interaction_for_write_stdin() -> Result<()>
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let open_call_id = "uexec-open";
let open_args = json!({
@@ -1105,10 +1098,9 @@ async fn unified_exec_emits_terminal_interaction_for_write_stdin() -> Result<()>
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_terminal_interaction_captures_delayed_output() -> Result<()> {
// TODO(anp): Remove after timing fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses a POSIX sleep/echo timing fixture");
skip_if_target_windows!(Ok(()), "uses a POSIX sleep/echo timing fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1119,7 +1111,7 @@ async fn unified_exec_terminal_interaction_captures_delayed_output() -> Result<(
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let open_call_id = "uexec-delayed-open";
let open_args = json!({
@@ -1287,7 +1279,7 @@ async fn unified_exec_terminal_interaction_captures_delayed_output() -> Result<(
async fn unified_exec_emits_one_begin_and_one_end_event() -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1298,7 +1290,7 @@ async fn unified_exec_emits_one_begin_and_one_end_event() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let open_call_id = "uexec-open-session";
let open_args = json!({
@@ -1409,10 +1401,9 @@ async fn unified_exec_emits_one_begin_and_one_end_event() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn exec_command_reports_chunk_and_exit_metadata() -> Result<()> {
// TODO(anp): Remove after unified-exec fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses a POSIX-only command fixture");
skip_if_target_windows!(Ok(()), "uses a POSIX-only command fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1422,7 +1413,7 @@ async fn exec_command_reports_chunk_and_exit_metadata() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let call_id = "uexec-metadata";
let args = serde_json::json!({
@@ -1504,10 +1495,9 @@ async fn exec_command_reports_chunk_and_exit_metadata() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn exec_command_clamps_model_requested_max_output_tokens_to_policy() -> Result<()> {
// TODO(anp): Remove after unified-exec fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses a POSIX-only command fixture");
skip_if_target_windows!(Ok(()), "uses a POSIX-only command fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1519,7 +1509,7 @@ async fn exec_command_clamps_model_requested_max_output_tokens_to_policy() -> Re
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let call_id = "uexec-clamped-max-output";
let args = serde_json::json!({
@@ -1568,10 +1558,9 @@ async fn exec_command_clamps_model_requested_max_output_tokens_to_policy() -> Re
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn write_stdin_clamps_model_requested_max_output_tokens_to_policy() -> Result<()> {
// TODO(anp): Remove after unified-exec interactive fixtures support Windows/ConPTY.
skip_if_wine_exec!(Ok(()), "uses POSIX read/while and Unix TTY semantics");
skip_if_target_windows!(Ok(()), "uses POSIX read/while and Unix TTY semantics");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1583,7 +1572,7 @@ async fn write_stdin_clamps_model_requested_max_output_tokens_to_policy() -> Res
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let start_call_id = "uexec-stdin-clamp-start";
let start_args = serde_json::json!({
@@ -1659,10 +1648,9 @@ async fn write_stdin_clamps_model_requested_max_output_tokens_to_policy() -> Res
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_defaults_to_pipe() -> Result<()> {
// TODO(anp): Remove after unified-exec interactive fixtures support Windows/ConPTY.
skip_if_wine_exec!(Ok(()), "requires Python/Unix PTY support in the target");
skip_if_target_windows!(Ok(()), "requires Python/Unix PTY support in the target");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1672,7 +1660,7 @@ async fn unified_exec_defaults_to_pipe() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let call_id = "uexec-default-pipe";
let args = serde_json::json!({
@@ -1730,10 +1718,9 @@ async fn unified_exec_defaults_to_pipe() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_can_enable_tty() -> Result<()> {
// TODO(anp): Remove after unified-exec interactive fixtures support Windows/ConPTY.
skip_if_wine_exec!(Ok(()), "requires Python/Unix PTY support in the target");
skip_if_target_windows!(Ok(()), "requires Python/Unix PTY support in the target");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1743,7 +1730,7 @@ async fn unified_exec_can_enable_tty() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let call_id = "uexec-tty-enabled";
let args = serde_json::json!({
@@ -1798,10 +1785,9 @@ async fn unified_exec_can_enable_tty() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_respects_early_exit_notifications() -> Result<()> {
// TODO(anp): Remove after unified-exec fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses a POSIX-only command fixture");
skip_if_target_windows!(Ok(()), "uses a POSIX-only command fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1811,7 +1797,7 @@ async fn unified_exec_respects_early_exit_notifications() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let call_id = "uexec-early-exit";
let args = serde_json::json!({
@@ -1883,10 +1869,9 @@ async fn unified_exec_respects_early_exit_notifications() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn write_stdin_returns_exit_metadata_and_clears_session() -> Result<()> {
// TODO(anp): Remove after unified-exec interactive fixtures support Windows/ConPTY.
skip_if_wine_exec!(Ok(()), "uses POSIX interactive-process and EOF semantics");
skip_if_target_windows!(Ok(()), "uses POSIX interactive-process and EOF semantics");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -1896,7 +1881,7 @@ async fn write_stdin_returns_exit_metadata_and_clears_session() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let start_call_id = "uexec-cat-start";
let send_call_id = "uexec-cat-send";
@@ -2037,8 +2022,8 @@ async fn write_stdin_returns_exit_metadata_and_clears_session() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn write_stdin_ctrl_c_interrupts_non_tty_session() -> Result<()> {
// TODO(anp): Add a Wine-exec test for explicit interrupt handling on Windows.
skip_if_wine_exec!(Ok(()), "asserts Unix SIGINT and trap semantics");
// TODO(anp): Add a target-Windows test for explicit interrupt handling.
skip_if_target_windows!(Ok(()), "asserts Unix SIGINT and trap semantics");
assert_write_stdin_ctrl_c_interrupts_non_tty_session(
"trap",
"trap 'echo INT-TRAP; exit 42' INT; echo READY; while true; do sleep 30; done",
@@ -2050,8 +2035,8 @@ async fn write_stdin_ctrl_c_interrupts_non_tty_session() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn write_stdin_ctrl_c_default_interrupt_reports_130_for_non_tty_session() -> Result<()> {
// TODO(anp): Add a Wine-exec test for Windows Ctrl+C termination and exit reporting.
skip_if_wine_exec!(Ok(()), "asserts Unix SIGINT and exit-code semantics");
// TODO(anp): Add a target-Windows test for Ctrl+C termination and exit reporting.
skip_if_target_windows!(Ok(()), "asserts Unix SIGINT and exit-code semantics");
assert_write_stdin_ctrl_c_interrupts_non_tty_session(
"default",
"echo READY; exec sleep 30",
@@ -2069,7 +2054,6 @@ async fn assert_write_stdin_ctrl_c_interrupts_non_tty_session(
) -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -2079,7 +2063,7 @@ async fn assert_write_stdin_ctrl_c_interrupts_non_tty_session(
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let start_call_id = format!("uexec-non-tty-interrupt-{test_name}-start");
let interrupt_call_id = format!("uexec-non-tty-interrupt-{test_name}");
@@ -2197,7 +2181,7 @@ async fn write_stdin_ctrl_c_reports_unsupported_interrupt_to_model_on_windows()
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let start_call_id = "uexec-windows-interrupt-start";
let interrupt_call_id = "uexec-windows-interrupt";
@@ -2286,10 +2270,9 @@ async fn write_stdin_ctrl_c_reports_unsupported_interrupt_to_model_on_windows()
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_emits_end_event_when_session_dies_via_stdin() -> Result<()> {
// TODO(anp): Remove after unified-exec interactive fixtures support Windows/ConPTY.
skip_if_wine_exec!(Ok(()), "uses POSIX interactive-process and EOF semantics");
skip_if_target_windows!(Ok(()), "uses POSIX interactive-process and EOF semantics");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -2300,7 +2283,7 @@ async fn unified_exec_emits_end_event_when_session_dies_via_stdin() -> Result<()
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let start_call_id = "uexec-end-on-exit-start";
let start_args = serde_json::json!({
@@ -2381,7 +2364,7 @@ async fn unified_exec_emits_end_event_when_session_dies_via_stdin() -> Result<()
async fn unified_exec_keeps_long_running_session_after_turn_end() -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let server = start_mock_server().await;
@@ -2491,7 +2474,7 @@ async fn unified_exec_keeps_long_running_session_after_turn_end() -> Result<()>
async fn unified_exec_interrupt_preserves_long_running_session() -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let server = start_mock_server().await;
@@ -2588,10 +2571,9 @@ async fn unified_exec_interrupt_preserves_long_running_session() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_reuses_session_via_stdin() -> Result<()> {
// TODO(anp): Remove after unified-exec interactive fixtures support Windows/ConPTY.
skip_if_wine_exec!(Ok(()), "uses POSIX interactive-process and EOF semantics");
skip_if_target_windows!(Ok(()), "uses POSIX interactive-process and EOF semantics");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -2601,7 +2583,7 @@ async fn unified_exec_reuses_session_via_stdin() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let first_call_id = "uexec-start";
let first_args = serde_json::json!({
@@ -2688,10 +2670,9 @@ async fn unified_exec_reuses_session_via_stdin() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_streams_after_lagged_output() -> Result<()> {
// TODO(anp): Remove after output fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "requires Python/Unix PTY support in the target");
skip_if_target_windows!(Ok(()), "requires Python/Unix PTY support in the target");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -2702,7 +2683,7 @@ async fn unified_exec_streams_after_lagged_output() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let script = r#"python3 - <<'PY'
import sys
@@ -2806,10 +2787,9 @@ PY
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn unified_exec_timeout_and_followup_poll() -> Result<()> {
// TODO(anp): Remove after unified-exec fixtures use target-native commands.
skip_if_wine_exec!(Ok(()), "uses a POSIX-only command fixture");
skip_if_target_windows!(Ok(()), "uses a POSIX-only command fixture");
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -2819,7 +2799,7 @@ async fn unified_exec_timeout_and_followup_poll() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let first_call_id = "uexec-timeout";
let first_args = serde_json::json!({
@@ -2897,13 +2877,12 @@ async fn unified_exec_timeout_and_followup_poll() -> Result<()> {
#[cfg(not(target_arch = "arm"))]
async fn unified_exec_formats_large_output_summary() -> Result<()> {
// TODO(anp): Remove after output fixtures use target-native commands.
skip_if_wine_exec!(
skip_if_target_windows!(
Ok(()),
"requires Python and POSIX heredoc support in the target"
);
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
let server = start_mock_server().await;
@@ -2913,7 +2892,7 @@ async fn unified_exec_formats_large_output_summary() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let script = r#"python3 - <<'PY'
import sys
@@ -2974,7 +2953,7 @@ PY
async fn unified_exec_runs_under_sandbox() -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let server = start_mock_server().await;
@@ -3360,7 +3339,7 @@ async fn unified_exec_runs_on_all_platforms() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let call_id = "uexec";
let args = serde_json::json!({
@@ -3408,7 +3387,7 @@ async fn unified_exec_runs_on_all_platforms() -> Result<()> {
async fn unified_exec_prunes_exited_sessions_first() -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
skip_if_windows!(Ok(()));
skip_if_host_windows!(Ok(()));
let server = start_mock_server().await;
@@ -3419,7 +3398,7 @@ async fn unified_exec_prunes_exited_sessions_first() -> Result<()> {
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
const MAX_SESSIONS_FOR_TEST: i32 = 64;
const FILLER_SESSIONS: i32 = MAX_SESSIONS_FOR_TEST - 1;
+21 -18
View File
@@ -30,7 +30,7 @@ use codex_protocol::protocol::TurnEnvironmentSelection;
use codex_protocol::user_input::UserInput;
use codex_utils_path_uri::PathUri;
use core_test_support::PathExt;
use core_test_support::get_remote_test_env;
use core_test_support::is_remote_test_environment;
use core_test_support::responses;
use core_test_support::responses::ev_assistant_message;
use core_test_support::responses::ev_completed;
@@ -41,10 +41,12 @@ use core_test_support::responses::mount_sse_sequence;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_no_remote_env;
use core_test_support::test_codex::TestCodex;
use core_test_support::test_codex::local;
use core_test_support::test_codex::test_codex;
use core_test_support::test_codex::turn_permission_fields;
use core_test_support::test_target_os;
use core_test_support::wait_for_event_with_timeout;
use image::DynamicImage;
use image::GenericImageView;
@@ -180,7 +182,7 @@ async fn assert_user_turn_local_image_resizes_to(
let server = start_mock_server().await;
let mut builder = test_codex();
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -280,7 +282,7 @@ async fn view_image_tool_attaches_local_image() -> anyhow::Result<()> {
let server = start_mock_server().await;
let mut builder = test_codex();
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -570,9 +572,7 @@ async fn view_image_tool_applies_local_sandbox_read_denies() -> anyhow::Result<(
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()> {
skip_if_no_network!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
};
skip_if_no_remote_env!(Ok(()));
let server = start_mock_server().await;
let mut builder = test_codex();
@@ -679,7 +679,7 @@ async fn view_image_tool_can_preserve_original_resolution_when_requested_on_gpt5
let server = start_mock_server().await;
let mut builder = test_codex().with_model("gpt-5.3-codex");
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -770,7 +770,7 @@ async fn view_image_tool_errors_clearly_for_unsupported_detail_values() -> anyho
let server = start_mock_server().await;
let mut builder = test_codex().with_model("gpt-5.3-codex");
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -848,7 +848,7 @@ async fn view_image_tool_treats_null_detail_as_omitted() -> anyhow::Result<()> {
let server = start_mock_server().await;
let mut builder = test_codex().with_model("gpt-5.3-codex");
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -938,7 +938,7 @@ async fn view_image_tool_resizes_when_model_lacks_original_detail_support() -> a
let server = start_mock_server().await;
let mut builder = test_codex().with_model("gpt-5.2");
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -1032,7 +1032,7 @@ async fn view_image_tool_does_not_force_original_resolution_with_capability_only
let server = start_mock_server().await;
let mut builder = test_codex().with_model("gpt-5.3-codex");
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -1123,7 +1123,7 @@ async fn view_image_tool_errors_when_path_is_directory() -> anyhow::Result<()> {
let server = start_mock_server().await;
let mut builder = test_codex();
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -1193,7 +1193,7 @@ async fn view_image_tool_turns_invalid_image_into_placeholder() -> anyhow::Resul
let server = start_mock_server().await;
let mut builder = test_codex();
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -1255,13 +1255,16 @@ async fn view_image_tool_turns_invalid_image_into_placeholder() -> anyhow::Resul
async fn view_image_tool_errors_when_file_missing() -> anyhow::Result<()> {
skip_if_no_network!(Ok(()));
let remote_test_env = get_remote_test_env();
println!("view_image missing-file test exec-server environment: {remote_test_env:?}");
println!(
"view_image missing-file test target: {:?}, remote: {}",
test_target_os(),
is_remote_test_environment()
);
let server = start_mock_server().await;
let mut builder = test_codex();
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
@@ -1401,7 +1404,7 @@ async fn view_image_tool_returns_unsupported_message_for_text_only_model() -> an
.with_config(|config| {
config.model = Some(model_slug.to_string());
});
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex { codex, .. } = &test;
let rel_path = "assets/example.png";
@@ -1488,7 +1491,7 @@ async fn replaces_invalid_local_image_after_bad_request() -> anyhow::Result<()>
let completion_mock = responses::mount_sse_once(&server, success_response).await;
let mut builder = test_codex();
let test = builder.build_with_remote_env(&server).await?;
let test = builder.build_with_auto_env(&server).await?;
let TestCodex {
codex,
session_configured,
+3 -3
View File
@@ -340,9 +340,9 @@ Params:
## Filesystem RPCs
Filesystem methods use canonical `file:` URIs and return JSON-RPC errors for
invalid or unavailable paths. For compatibility, requests also accept native
absolute path strings and normalize them to `file:` URIs:
Filesystem methods require valid `file:` URI strings and return JSON-RPC errors
for invalid or unavailable paths. Native absolute path strings are rejected;
callers must convert them to `file:` URIs before sending requests:
- `fs/readFile`
- `fs/open`, `fs/readBlock`, and `fs/close` (internal transport for
+24 -29
View File
@@ -591,38 +591,33 @@ mod tests {
}
#[test]
fn filesystem_protocol_accepts_legacy_absolute_paths_and_serializes_path_uris() {
let legacy_path = std::env::current_dir()
fn filesystem_protocol_rejects_native_absolute_paths() {
let native_path = std::env::current_dir()
.expect("current directory")
.join("legacy-file.txt");
let legacy_cwd = std::env::current_dir().expect("current directory");
let native_sandbox = FileSystemSandboxContext::from_permission_profile_with_cwd(
PermissionProfile::default(),
PathUri::from_host_native_path(&legacy_cwd).expect("cwd URI"),
);
let mut legacy_sandbox =
serde_json::to_value(&native_sandbox).expect("sandbox should serialize");
legacy_sandbox["cwd"] = serde_json::json!(legacy_cwd.to_string_lossy());
let params: FsReadFileParams = serde_json::from_value(serde_json::json!({
"path": legacy_path.to_string_lossy(),
"sandbox": legacy_sandbox,
}))
.expect("legacy absolute path should deserialize");
let expected_sandbox = native_sandbox;
let expected = FsReadFileParams {
path: PathUri::from_host_native_path(legacy_path).expect("path URI"),
sandbox: Some(expected_sandbox.clone()),
};
.join("native-file.txt");
let native_cwd = std::env::current_dir().expect("current directory");
assert_eq!(params, expected);
assert_eq!(
serde_json::to_value(params).expect("params should serialize"),
serde_json::json!({
"path": expected.path.to_string(),
"sandbox": serde_json::to_value(expected_sandbox)
.expect("sandbox should serialize"),
})
serde_json::from_value::<FsReadFileParams>(serde_json::json!({
"path": native_path.to_string_lossy(),
"sandbox": null,
}))
.expect_err("native absolute path should not deserialize as a URI");
let sandbox = FileSystemSandboxContext::from_permission_profile_with_cwd(
PermissionProfile::default(),
PathUri::from_host_native_path(&native_cwd).expect("cwd URI"),
);
let mut native_path_sandbox =
serde_json::to_value(sandbox).expect("sandbox should serialize");
native_path_sandbox["cwd"] = serde_json::json!(native_cwd.to_string_lossy());
serde_json::from_value::<FsReadFileParams>(serde_json::json!({
"path": PathUri::from_host_native_path(native_path)
.expect("path URI")
.to_string(),
"sandbox": native_path_sandbox,
}))
.expect_err("native absolute sandbox cwd should not deserialize as a URI");
}
#[test]
+5 -4
View File
@@ -12,6 +12,7 @@ use codex_exec_server::ReadResponse;
use codex_exec_server::TerminateResponse;
use codex_exec_server::WriteResponse;
use codex_exec_server::WriteStatus;
use codex_utils_path_uri::PathUri;
use common::exec_server::exec_server;
use pretty_assertions::assert_eq;
@@ -46,7 +47,7 @@ async fn exec_server_starts_process_over_websocket() -> anyhow::Result<()> {
serde_json::json!({
"processId": "proc-1",
"argv": ["true"],
"cwd": std::env::current_dir()?,
"cwd": PathUri::from_host_native_path(std::env::current_dir()?)?,
"env": {},
"tty": false,
"pipeStdin": false,
@@ -113,7 +114,7 @@ async fn exec_server_defaults_omitted_pipe_stdin_to_closed_stdin() -> anyhow::Re
"-c",
"sleep 0.3; if IFS= read -r line; then printf 'read:%s\\n' \"$line\"; else printf 'eof\\n'; fi"
],
"cwd": std::env::current_dir()?,
"cwd": PathUri::from_host_native_path(std::env::current_dir()?)?,
"env": {},
"tty": false,
"arg0": null
@@ -207,7 +208,7 @@ async fn exec_server_dedupes_retried_process_write_ids() -> anyhow::Result<()> {
"-c",
"IFS= read -r first; printf 'line:%s\\n' \"$first\"; IFS= read -r second; printf 'line:%s\\n' \"$second\""
],
"cwd": std::env::current_dir()?,
"cwd": PathUri::from_host_native_path(std::env::current_dir()?)?,
"env": {},
"tty": false,
"pipeStdin": true,
@@ -341,7 +342,7 @@ async fn exec_server_resumes_detached_session_without_killing_processes() -> any
serde_json::json!({
"processId": "proc-resume",
"argv": ["/bin/sh", "-c", "sleep 5"],
"cwd": std::env::current_dir()?,
"cwd": PathUri::from_host_native_path(std::env::current_dir()?)?,
"env": {},
"tty": false,
"pipeStdin": false,
@@ -8,9 +8,10 @@ use codex_plugin::PluginResourceLocator;
use codex_plugin::ResolvedPlugin;
use codex_plugin::ResolvedPluginLocation;
use codex_plugin::manifest::PluginManifestMcpServers;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use codex_utils_path_uri::PathUriParseError;
use std::io;
use std::path::PathBuf;
use thiserror::Error;
const DEFAULT_MCP_CONFIG_FILE: &str = ".mcp.json";
@@ -25,14 +26,24 @@ pub(super) enum ExecutorPluginMcpProviderError {
#[error("failed to read MCP config for selected plugin `{plugin_id}` at `{path}`: {source}")]
ReadConfig {
plugin_id: String,
path: AbsolutePathBuf,
path: PathUri,
#[source]
source: io::Error,
},
#[error(
"failed to resolve MCP config path `{relative_path}` below selected plugin `{plugin_id}` at `{root}`: {source}"
)]
InvalidConfigPath {
plugin_id: String,
root: PathUri,
relative_path: &'static str,
#[source]
source: PathUriParseError,
},
#[error("failed to parse MCP config for selected plugin `{plugin_id}` at `{path}`: {source}")]
ParseConfig {
plugin_id: String,
path: AbsolutePathBuf,
path: PathUri,
#[source]
source: serde_json::Error,
},
@@ -52,7 +63,7 @@ impl ExecutorPluginMcpProvider {
async fn load_from_file_system(
plugin: &ResolvedPlugin,
plugin_root: &AbsolutePathBuf,
plugin_root: &PathUri,
file_system: &dyn ExecutorFileSystem,
) -> Result<Vec<(String, McpServerConfig)>, ExecutorPluginMcpProviderError> {
let ResolvedPluginLocation::Environment { environment_id, .. } = plugin.location();
@@ -61,10 +72,9 @@ async fn load_from_file_system(
Some(PluginManifestMcpServers::Path(PluginResourceLocator::Environment {
path, ..
})) => {
let config_uri = PathUri::from_abs_path(path);
(
file_system
.read_file_text(&config_uri, /*sandbox*/ None)
.read_file_text(path, /*sandbox*/ None)
.await
.map_err(|source| ExecutorPluginMcpProviderError::ReadConfig {
plugin_id: plugin_id.to_string(),
@@ -74,15 +84,21 @@ async fn load_from_file_system(
path.clone(),
)
}
Some(PluginManifestMcpServers::Object(object_config)) => (
object_config.clone(),
plugin_root.join(".codex-plugin/plugin.json"),
),
Some(PluginManifestMcpServers::Object(object_config)) => {
let PluginResourceLocator::Environment { path, .. } = plugin.manifest_path();
(object_config.clone(), path.clone())
}
None => {
let config_path = plugin_root.join(DEFAULT_MCP_CONFIG_FILE);
let config_uri = PathUri::from_abs_path(&config_path);
let config_path = plugin_root
.join(DEFAULT_MCP_CONFIG_FILE)
.map_err(|source| ExecutorPluginMcpProviderError::InvalidConfigPath {
plugin_id: plugin_id.to_string(),
root: plugin_root.clone(),
relative_path: DEFAULT_MCP_CONFIG_FILE,
source,
})?;
let contents = match file_system
.read_file_text(&config_uri, /*sandbox*/ None)
.read_file_text(&config_path, /*sandbox*/ None)
.await
{
Ok(contents) => contents,
@@ -100,8 +116,9 @@ async fn load_from_file_system(
(contents, config_path)
}
};
let plugin_root_path = PathBuf::from(plugin_root.inferred_native_path_string());
let parsed = parse_plugin_mcp_config(
plugin_root.as_path(),
plugin_root_path.as_path(),
&contents,
PluginMcpServerPlacement::Environment { environment_id },
)
@@ -156,7 +156,8 @@ async fn reads_declared_config_only_through_executor_file_system() {
reads: Mutex::new(Vec::new()),
};
let servers = load_from_file_system(&plugin, &plugin_root, &file_system)
let plugin_root_uri = PathUri::from_abs_path(&plugin_root);
let servers = load_from_file_system(&plugin, &plugin_root_uri, &file_system)
.await
.expect("load executor MCP config");
@@ -210,7 +211,8 @@ async fn reads_manifest_object_config_without_executor_file_system_access() {
reads: Mutex::new(Vec::new()),
};
let servers = load_from_file_system(&plugin, &plugin_root, &file_system)
let plugin_root_uri = PathUri::from_abs_path(&plugin_root);
let servers = load_from_file_system(&plugin, &plugin_root_uri, &file_system)
.await
.expect("load manifest object executor MCP config");
@@ -259,7 +261,8 @@ async fn missing_default_config_is_empty() {
reads: Mutex::new(Vec::new()),
};
let servers = load_from_file_system(&plugin, &plugin_root, &file_system)
let plugin_root_uri = PathUri::from_abs_path(&plugin_root);
let servers = load_from_file_system(&plugin, &plugin_root_uri, &file_system)
.await
.expect("missing default config should be ignored");
@@ -283,7 +286,8 @@ async fn malformed_declared_config_is_an_error() {
reads: Mutex::new(Vec::new()),
};
let err = load_from_file_system(&plugin, &plugin_root, &file_system)
let plugin_root_uri = PathUri::from_abs_path(&plugin_root);
let err = load_from_file_system(&plugin, &plugin_root_uri, &file_system)
.await
.expect_err("malformed declared config should fail");
@@ -297,20 +301,70 @@ async fn malformed_declared_config_is_an_error() {
};
assert_eq!(
(plugin_id, path),
("selected-root".to_string(), config_path.clone())
(
"selected-root".to_string(),
PathUri::from_abs_path(&config_path)
)
);
assert_eq!(reads(&file_system), vec![config_path]);
}
#[tokio::test]
async fn malformed_manifest_object_config_reports_actual_manifest_path() {
let temp_dir = tempfile::tempdir().expect("tempdir");
let plugin_root = AbsolutePathBuf::from_absolute_path_checked(temp_dir.path().join("plugin"))
.expect("absolute plugin root");
let plugin = resolved_plugin(
&plugin_root,
Some(PluginManifestMcpServers::Object("{not-json".to_string())),
);
let file_system = SyntheticExecutorFileSystem {
config_path: plugin_root.join(DEFAULT_MCP_CONFIG_FILE),
config_contents: None,
reads: Mutex::new(Vec::new()),
};
let plugin_root_uri = PathUri::from_abs_path(&plugin_root);
let err = load_from_file_system(&plugin, &plugin_root_uri, &file_system)
.await
.expect_err("malformed manifest object config should fail");
let ExecutorPluginMcpProviderError::ParseConfig {
plugin_id,
path,
source: _,
} = err
else {
panic!("expected parse error");
};
assert_eq!(
(plugin_id, path),
(
"selected-root".to_string(),
PathUri::from_abs_path(&plugin_root.join(".claude-plugin/plugin.json"))
)
);
assert_eq!(reads(&file_system), Vec::new());
}
fn resolved_plugin(
plugin_root: &AbsolutePathBuf,
mcp_servers: Option<PluginManifestMcpServers<AbsolutePathBuf>>,
) -> ResolvedPlugin {
let plugin_root_uri = PathUri::from_abs_path(plugin_root);
let mcp_servers = mcp_servers.map(|mcp_servers| match mcp_servers {
PluginManifestMcpServers::Path(path) => {
PluginManifestMcpServers::Path(PathUri::from_abs_path(&path))
}
PluginManifestMcpServers::Object(config) => PluginManifestMcpServers::Object(config),
});
ResolvedPlugin::from_environment(
"selected-root".to_string(),
"executor-test".to_string(),
plugin_root.clone(),
plugin_root.join(".codex-plugin/plugin.json"),
plugin_root_uri.clone(),
plugin_root_uri
.join(".claude-plugin/plugin.json")
.expect("manifest URI"),
PluginManifest {
name: "demo-plugin".to_string(),
version: None,
@@ -9,6 +9,7 @@ use codex_extension_api::McpServerContribution;
use codex_extension_api::McpServerContributionContext;
use codex_protocol::capabilities::CapabilityRootLocation;
use codex_protocol::capabilities::SelectedCapabilityRoot;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
use std::sync::Arc;
@@ -59,7 +60,7 @@ command = "expected-command"
.build()
.await?;
let contributions = selected_plugin_contributions(&config, plugin_root.path()).await;
let contributions = selected_plugin_contributions(&config, plugin_root.path()).await?;
assert_eq!(
contributions,
@@ -93,7 +94,7 @@ command = "expected-command"
async fn selected_plugin_contributions(
config: &Config,
plugin_root: &std::path::Path,
) -> Vec<ContributionSummary> {
) -> Result<Vec<ContributionSummary>, Box<dyn std::error::Error>> {
let mut builder = ExtensionRegistryBuilder::new();
codex_mcp_extension::install_executor_plugins(
&mut builder,
@@ -105,12 +106,12 @@ async fn selected_plugin_contributions(
id: "selected-root".to_string(),
location: CapabilityRootLocation::Environment {
environment_id: LOCAL_ENVIRONMENT_ID.to_string(),
path: plugin_root.to_string_lossy().into_owned(),
path: PathUri::from_host_native_path(plugin_root)?,
},
}]);
codex_mcp_extension::initialize_executor_plugin_thread_data(&mut thread_init);
registry.mcp_server_contributors()[0]
Ok(registry.mcp_server_contributors()[0]
.contribute(McpServerContributionContext::for_thread(
config,
&thread_init,
@@ -135,5 +136,5 @@ async fn selected_plugin_contributions(
panic!("expected selected plugin contribution")
}
})
.collect()
.collect())
}
+2 -10
View File
@@ -1,4 +1,3 @@
use std::path::PathBuf;
use std::sync::Arc;
use codex_core_skills::SkillMetadata;
@@ -197,13 +196,6 @@ fn catalog_entry_from_skill(
entry
}
fn executor_absolute_path(path: &str) -> std::io::Result<AbsolutePathBuf> {
let path = PathBuf::from(path);
if !path.is_absolute() {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"executor path must be absolute",
));
}
AbsolutePathBuf::from_absolute_path_checked(path)
fn executor_absolute_path(path: &PathUri) -> std::io::Result<AbsolutePathBuf> {
path.to_abs_path()
}
@@ -222,7 +222,6 @@ async fn skill_loading_and_reads_use_the_supplied_executor_file_system() {
#[tokio::test]
async fn selected_root_id_distinguishes_identical_executor_paths() {
let test_root = create_local_skill_root("root-identity").expect("create local skill root");
let root_path = test_root.to_string_lossy().into_owned();
let canonical_root = AbsolutePathBuf::from_absolute_path_checked(&test_root)
.expect("absolute skill root")
.canonicalize()
@@ -242,7 +241,7 @@ async fn selected_root_id_distinguishes_identical_executor_paths() {
id: id.to_string(),
location: CapabilityRootLocation::Environment {
environment_id: "local".to_string(),
path: root_path.clone(),
path: PathUri::from_host_native_path(&test_root).expect("skill root URI"),
},
})
.collect(),
@@ -48,6 +48,7 @@ use codex_skills_extension::provider::SkillProviderFuture;
use codex_skills_extension::provider::SkillReadRequest;
use codex_skills_extension::provider::SkillSearchRequest;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
type TestResult = Result<(), Box<dyn std::error::Error>>;
@@ -171,7 +172,7 @@ async fn selected_executor_catalog_is_context_and_selected_entrypoint_is_turn_in
id: "lint-fix".to_string(),
location: CapabilityRootLocation::Environment {
environment_id: "env-1".to_string(),
path: "/skills/lint-fix".to_string(),
path: PathUri::parse("file:///skills/lint-fix").expect("skill root URI"),
},
}]);
let session_source = SessionSource::Cli;
@@ -494,7 +495,7 @@ async fn root_qualified_locator_selects_only_the_matching_executor_skill() -> Te
id: id.to_string(),
location: CapabilityRootLocation::Environment {
environment_id: "env-1".to_string(),
path: path.to_string(),
path: PathUri::parse(&format!("file://{path}")).expect("skill root URI"),
},
})
.collect::<Vec<_>>(),
+1
View File
@@ -16,6 +16,7 @@ workspace = true
codex-config = { workspace = true }
codex-protocol = { workspace = true }
codex-utils-absolute-path = { workspace = true }
codex-utils-path-uri = { workspace = true }
codex-utils-plugins = { workspace = true }
thiserror = { workspace = true }
+12 -15
View File
@@ -1,6 +1,6 @@
use crate::manifest::PluginManifest;
use codex_protocol::capabilities::SelectedCapabilityRoot;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use std::error::Error as StdError;
use std::future::Future;
use thiserror::Error;
@@ -11,8 +11,8 @@ pub enum PluginResourceLocator {
Environment {
/// Environment whose filesystem owns the resource.
environment_id: String,
/// Absolute resource path within that filesystem.
path: AbsolutePathBuf,
/// Resource URI within that filesystem.
path: PathUri,
},
}
@@ -22,8 +22,8 @@ pub enum ResolvedPluginLocation {
Environment {
/// Environment whose filesystem owns the package.
environment_id: String,
/// Absolute package root within that filesystem.
root: AbsolutePathBuf,
/// Package root URI within that filesystem.
root: PathUri,
},
}
@@ -40,10 +40,7 @@ pub struct ResolvedPlugin {
#[derive(Clone, Debug, Error, PartialEq, Eq)]
pub enum ResolvedPluginError {
#[error("plugin resource path `{path}` is outside package root `{root}`")]
ResourceOutsideRoot {
root: AbsolutePathBuf,
path: AbsolutePathBuf,
},
ResourceOutsideRoot { root: PathUri, path: PathUri },
}
impl ResolvedPlugin {
@@ -51,9 +48,9 @@ impl ResolvedPlugin {
pub fn from_environment(
selected_root_id: String,
environment_id: String,
root: AbsolutePathBuf,
manifest_path: AbsolutePathBuf,
manifest: PluginManifest<AbsolutePathBuf>,
root: PathUri,
manifest_path: PathUri,
manifest: PluginManifest<PathUri>,
) -> Result<Self, ResolvedPluginError> {
let manifest_path = environment_resource(&environment_id, &root, manifest_path)?;
let manifest = manifest
@@ -92,10 +89,10 @@ impl ResolvedPlugin {
fn environment_resource(
environment_id: &str,
root: &AbsolutePathBuf,
path: AbsolutePathBuf,
root: &PathUri,
path: PathUri,
) -> Result<PluginResourceLocator, ResolvedPluginError> {
if !path.as_path().starts_with(root.as_path()) {
if !path.starts_with(root) {
return Err(ResolvedPluginError::ResourceOutsideRoot {
root: root.clone(),
path,
+30 -24
View File
@@ -7,22 +7,28 @@ use crate::manifest::PluginManifestInterface;
use crate::manifest::PluginManifestMcpServers;
use crate::manifest::PluginManifestPaths;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
fn absolute(path: impl AsRef<std::path::Path>) -> AbsolutePathBuf {
AbsolutePathBuf::from_absolute_path_checked(path.as_ref()).expect("absolute test path")
}
fn resource(environment_id: &str, path: AbsolutePathBuf) -> PluginResourceLocator {
fn path_uri(path: &AbsolutePathBuf) -> PathUri {
PathUri::from_abs_path(path)
}
fn resource(environment_id: &str, path: &AbsolutePathBuf) -> PluginResourceLocator {
PluginResourceLocator::Environment {
environment_id: environment_id.to_string(),
path,
path: path_uri(path),
}
}
#[test]
fn environment_descriptor_binds_every_manifest_resource() {
let root = absolute(std::env::current_dir().expect("cwd").join("plugin-root"));
let root_uri = path_uri(&root);
let manifest_path = root.join(".codex-plugin/plugin.json");
let skills = root.join("skills");
let mcp_servers = root.join(".mcp.json");
@@ -37,15 +43,15 @@ fn environment_descriptor_binds_every_manifest_resource() {
description: None,
keywords: Vec::new(),
paths: PluginManifestPaths {
skills: vec![skills.clone()],
mcp_servers: Some(PluginManifestMcpServers::Path(mcp_servers.clone())),
apps: Some(apps.clone()),
hooks: Some(PluginManifestHooks::Paths(vec![hooks.clone()])),
skills: vec![path_uri(&skills)],
mcp_servers: Some(PluginManifestMcpServers::Path(path_uri(&mcp_servers))),
apps: Some(path_uri(&apps)),
hooks: Some(PluginManifestHooks::Paths(vec![path_uri(&hooks)])),
},
interface: Some(PluginManifestInterface {
composer_icon: Some(composer_icon.clone()),
logo: Some(logo.clone()),
screenshots: vec![screenshot.clone()],
composer_icon: Some(path_uri(&composer_icon)),
logo: Some(path_uri(&logo)),
screenshots: vec![path_uri(&screenshot)],
..PluginManifestInterface::default()
}),
};
@@ -53,15 +59,15 @@ fn environment_descriptor_binds_every_manifest_resource() {
let plugin = ResolvedPlugin::from_environment(
"selected-demo".to_string(),
"executor-1".to_string(),
root,
manifest_path.clone(),
root_uri,
path_uri(&manifest_path),
manifest,
)
.expect("valid descriptor");
assert_eq!(
plugin.manifest_path(),
&resource("executor-1", manifest_path)
&resource("executor-1", &manifest_path)
);
assert_eq!(
plugin.manifest(),
@@ -71,21 +77,21 @@ fn environment_descriptor_binds_every_manifest_resource() {
description: None,
keywords: Vec::new(),
paths: PluginManifestPaths {
skills: vec![resource("executor-1", skills)],
skills: vec![resource("executor-1", &skills)],
mcp_servers: Some(PluginManifestMcpServers::Path(resource(
"executor-1",
mcp_servers,
&mcp_servers,
))),
apps: Some(resource("executor-1", apps)),
apps: Some(resource("executor-1", &apps)),
hooks: Some(PluginManifestHooks::Paths(vec![resource(
"executor-1",
hooks,
&hooks
)])),
},
interface: Some(PluginManifestInterface {
composer_icon: Some(resource("executor-1", composer_icon)),
logo: Some(resource("executor-1", logo)),
screenshots: vec![resource("executor-1", screenshot)],
composer_icon: Some(resource("executor-1", &composer_icon)),
logo: Some(resource("executor-1", &logo)),
screenshots: vec![resource("executor-1", &screenshot)],
..PluginManifestInterface::default()
}),
}
@@ -104,7 +110,7 @@ fn environment_descriptor_rejects_resources_outside_package_root() {
keywords: Vec::new(),
paths: PluginManifestPaths {
skills: Vec::new(),
mcp_servers: Some(PluginManifestMcpServers::Path(outside.clone())),
mcp_servers: Some(PluginManifestMcpServers::Path(path_uri(&outside))),
apps: None,
hooks: None,
},
@@ -114,8 +120,8 @@ fn environment_descriptor_rejects_resources_outside_package_root() {
let err = ResolvedPlugin::from_environment(
"selected-demo".to_string(),
"executor-1".to_string(),
root.clone(),
root.join(".codex-plugin/plugin.json"),
path_uri(&root),
path_uri(&root.join(".codex-plugin/plugin.json")),
manifest,
)
.expect_err("outside resource should fail");
@@ -123,8 +129,8 @@ fn environment_descriptor_rejects_resources_outside_package_root() {
assert_eq!(
err,
ResolvedPluginError::ResourceOutsideRoot {
root,
path: outside,
root: path_uri(&root),
path: path_uri(&outside),
}
);
}
+22 -1
View File
@@ -1,3 +1,5 @@
use codex_utils_path_uri::LegacyAppPathString;
use codex_utils_path_uri::PathUri;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
@@ -25,6 +27,25 @@ pub enum CapabilityRootLocation {
#[serde(rename = "environmentId")]
#[ts(rename = "environmentId")]
environment_id: String,
path: String,
/// Absolute path for the root in the selected environment.
#[serde(deserialize_with = "deserialize_path_uri_from_api_path")]
#[schemars(with = "String")]
#[ts(type = "string")]
path: PathUri,
},
}
fn deserialize_path_uri_from_api_path<'de, D>(deserializer: D) -> Result<PathUri, D::Error>
where
D: serde::Deserializer<'de>,
{
let path = LegacyAppPathString::deserialize(deserializer)?;
if let Ok(path_uri) = PathUri::parse(path.as_str()) {
return Ok(path_uri);
}
path.try_into().map_err(serde::de::Error::custom)
}
#[cfg(test)]
#[path = "capabilities_tests.rs"]
mod tests;
@@ -0,0 +1,30 @@
use super::CapabilityRootLocation;
use super::SelectedCapabilityRoot;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
#[test]
fn environment_capability_root_accepts_foreign_file_uri() {
let selected_root = serde_json::from_str::<SelectedCapabilityRoot>(
r#"{
"id": "selected-demo",
"location": {
"type": "environment",
"environmentId": "executor-test",
"path": "file:///C:/plugins/demo"
}
}"#,
)
.expect("file URI should deserialize");
assert_eq!(
selected_root,
SelectedCapabilityRoot {
id: "selected-demo".to_string(),
location: CapabilityRootLocation::Environment {
environment_id: "executor-test".to_string(),
path: PathUri::parse("file:///C:/plugins/demo").expect("path URI"),
},
}
);
}
+7 -34
View File
@@ -45,13 +45,9 @@ const BAD_PATH_URI_PREFIX: &str = "file:///%00/bad/path/";
/// are not resolved.
///
/// Serde represents a `PathUri` as its canonical URI string. Deserialization
/// also accepts an absolute native path for compatibility with fields that
/// previously used [`AbsolutePathBuf`]; relative paths are rejected. Valid
/// `file:` strings round-trip through their canonical URL form, including
/// encoded non-UTF-8 path bytes, but conversion to a native path remains
/// host-dependent as described by [RFC 8089].
/// accepts only valid `file:` URI strings. These strings round-trip through
/// their canonical URL form, including encoded non-UTF-8 path bytes.
///
/// [RFC 8089]: https://www.rfc-editor.org/rfc/rfc8089.html
/// [VS Code resources]: https://github.com/microsoft/vscode/blob/main/src/vs/base/common/resources.ts
#[derive(Clone, Debug, PartialEq, Eq, Hash, TS)]
#[ts(type = "string")]
@@ -250,10 +246,10 @@ impl PathUri {
/// Returns true when this URI is lexically equal to or below `base`.
///
/// Containment is computed using URI authority and path-segment boundaries,
/// without consulting the host filesystem. Percent-encoded path separators
/// fail closed because native path conversion may interpret them as segment
/// boundaries. Opaque fallback URIs created by [`Self::from_abs_path`] only
/// contain themselves.
/// without consulting the host filesystem. Percent-encoded native path
/// separators fail closed because native path conversion may interpret them
/// as segment boundaries. Opaque fallback URIs created by
/// [`Self::from_abs_path`] only contain themselves.
pub fn starts_with(&self, base: &Self) -> bool {
if self == base {
return true;
@@ -478,30 +474,7 @@ impl<'de> Deserialize<'de> for PathUri {
D: Deserializer<'de>,
{
let value = String::deserialize(deserializer)?;
let unsupported_scheme = match Url::parse(&value) {
Ok(url) => match Self::try_from(url) {
Ok(uri) => return Ok(uri),
// `Url` parses a Windows drive prefix such as `C:\` as the
// scheme `c`. Give any unsupported URI one chance to satisfy
// the native absolute-path invariant before reporting it.
Err(error @ PathUriParseError::UnsupportedScheme(_)) => Some(error),
Err(error) => return Err(serde::de::Error::custom(error)),
},
Err(url::ParseError::RelativeUrlWithoutBase) => None,
Err(error) => {
return Err(serde::de::Error::custom(PathUriParseError::InvalidUri(
error,
)));
}
};
let path = AbsolutePathBuf::from_absolute_path_checked(value).map_err(|path_error| {
serde::de::Error::custom(
unsupported_scheme
.map_or_else(|| path_error.to_string(), |error| error.to_string()),
)
})?;
Ok(Self::from_abs_path(&path))
Self::parse(&value).map_err(serde::de::Error::custom)
}
}
+6 -9
View File
@@ -1,5 +1,4 @@
use super::*;
use codex_utils_absolute_path::AbsolutePathBufGuard;
use pretty_assertions::assert_eq;
#[cfg(windows)]
use std::ffi::OsString;
@@ -418,14 +417,14 @@ fn path_uri_serializes_as_a_string() {
}
#[test]
fn path_uri_deserializes_legacy_absolute_paths() {
fn path_uri_rejects_native_absolute_paths_during_deserialization() {
let path = AbsolutePathBuf::current_dir()
.expect("current directory")
.join("workspace/src");
let json = serde_json::to_string(&path).expect("absolute path should serialize");
let uri: PathUri = serde_json::from_str(&json).expect("legacy absolute path should parse");
assert_eq!(uri, PathUri::from_abs_path(&path));
serde_json::from_str::<PathUri>(&json)
.expect_err("native absolute path should not deserialize as a URI");
}
#[test]
@@ -437,13 +436,11 @@ fn path_uri_rejects_relative_native_paths() {
}
#[test]
fn path_uri_rejects_legacy_relative_paths_with_absolute_path_guard() {
let base = AbsolutePathBuf::current_dir().expect("current directory");
let _guard = AbsolutePathBufGuard::new(base.as_path());
fn path_uri_rejects_relative_strings_during_deserialization() {
let error = serde_json::from_str::<PathUri>(r#""src/lib.rs""#)
.expect_err("legacy relative path should be rejected");
.expect_err("relative path should be rejected");
assert!(error.to_string().contains("path is not absolute"));
assert!(error.to_string().contains("relative URL without a base"));
}
#[test]