mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
Preserve foreign cwd URIs for turn-input contributors (#37342)
## Why Converting each environment's working directory to a host-native path caused turn-input contributors to omit environments with foreign path formats. ## What changed - Expose `TurnInputEnvironment.cwd` as a `PathUri`. - Pass every turn environment to contributors without host-path conversion. ## Testing Added an integration test that submits a foreign working-directory URI and verifies the contributor receives the environment unchanged. GitOrigin-RevId: a122526be47f5331614381e9c6e4b85087a96bed
This commit is contained in:
1 parent
29dce2db43
commit
bcea6447ee
5 files changed
+93
-11
No files matched your search
Generated
+1
@@ -3097,6 +3097,7 @@ dependencies = [
|
|||||||
"codex-protocol",
|
"codex-protocol",
|
||||||
"codex-tools",
|
"codex-tools",
|
||||||
"codex-utils-absolute-path",
|
"codex-utils-absolute-path",
|
||||||
|
"codex-utils-path-uri",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
@@ -884,14 +884,10 @@ async fn build_extension_turn_input_items(
|
|||||||
.environments
|
.environments
|
||||||
.turn_environments()
|
.turn_environments()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(index, environment)| {
|
.map(|(index, environment)| TurnInputEnvironment {
|
||||||
// TODO(anp): Migrate extension turn-input environments to PathUri so foreign cwd
|
environment_id: environment.environment_id.clone(),
|
||||||
// values are not omitted from extension context.
|
cwd: environment.cwd().clone(),
|
||||||
Some(TurnInputEnvironment {
|
is_primary: index == 0,
|
||||||
environment_id: environment.environment_id.clone(),
|
|
||||||
cwd: environment.cwd().to_abs_path().ok()?.into_path_buf(),
|
|
||||||
is_primary: index == 0,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
use core_test_support::test_codex::local_selections;
|
use core_test_support::test_codex::local_selections;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use codex_config::types::Personality;
|
use codex_config::types::Personality;
|
||||||
use codex_core::config::Config;
|
use codex_core::config::Config;
|
||||||
use codex_exec_server::LOCAL_ENVIRONMENT_ID;
|
use codex_exec_server::LOCAL_ENVIRONMENT_ID;
|
||||||
|
use codex_extension_api::ContextualUserFragment;
|
||||||
|
use codex_extension_api::ExtensionData;
|
||||||
|
use codex_extension_api::ExtensionFuture;
|
||||||
|
use codex_extension_api::ExtensionMetrics;
|
||||||
use codex_extension_api::ExtensionRegistry;
|
use codex_extension_api::ExtensionRegistry;
|
||||||
use codex_extension_api::ExtensionRegistryBuilder;
|
use codex_extension_api::ExtensionRegistryBuilder;
|
||||||
|
use codex_extension_api::TurnInputContext;
|
||||||
|
use codex_extension_api::TurnInputContributor;
|
||||||
|
use codex_extension_api::TurnInputEnvironment;
|
||||||
use codex_features::Feature;
|
use codex_features::Feature;
|
||||||
use codex_protocol::models::PermissionProfile;
|
use codex_protocol::models::PermissionProfile;
|
||||||
use codex_protocol::protocol::AskForApproval;
|
use codex_protocol::protocol::AskForApproval;
|
||||||
@@ -35,10 +43,32 @@ use core_test_support::skip_if_no_network;
|
|||||||
use core_test_support::test_codex::test_codex;
|
use core_test_support::test_codex::test_codex;
|
||||||
use core_test_support::test_codex::turn_permission_fields;
|
use core_test_support::test_codex::turn_permission_fields;
|
||||||
use core_test_support::wait_for_event;
|
use core_test_support::wait_for_event;
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
const PRETURN_CONTEXT_DIFF_CWD: &str = "PRETURN_CONTEXT_DIFF_CWD";
|
const PRETURN_CONTEXT_DIFF_CWD: &str = "PRETURN_CONTEXT_DIFF_CWD";
|
||||||
|
|
||||||
|
struct RecordingTurnInputContributor(Arc<Mutex<Vec<TurnInputEnvironment>>>);
|
||||||
|
|
||||||
|
impl TurnInputContributor for RecordingTurnInputContributor {
|
||||||
|
fn contribute<'a>(
|
||||||
|
&'a self,
|
||||||
|
input: TurnInputContext,
|
||||||
|
_extension_metrics: Option<Arc<dyn ExtensionMetrics>>,
|
||||||
|
_session_store: &'a ExtensionData,
|
||||||
|
_thread_store: &'a ExtensionData,
|
||||||
|
_turn_store: &'a ExtensionData,
|
||||||
|
) -> ExtensionFuture<'a, Vec<Box<dyn ContextualUserFragment + Send>>> {
|
||||||
|
Box::pin(async move {
|
||||||
|
self.0
|
||||||
|
.lock()
|
||||||
|
.expect("recorded environments lock")
|
||||||
|
.extend(input.environments);
|
||||||
|
Vec::new()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn skills_extensions() -> Arc<ExtensionRegistry<Config>> {
|
fn skills_extensions() -> Arc<ExtensionRegistry<Config>> {
|
||||||
let mut extensions = ExtensionRegistryBuilder::<Config>::new();
|
let mut extensions = ExtensionRegistryBuilder::<Config>::new();
|
||||||
install(&mut extensions, |config: &Config| SkillsExtensionConfig {
|
install(&mut extensions, |config: &Config| SkillsExtensionConfig {
|
||||||
@@ -98,6 +128,61 @@ fn format_environment_context_subagents_snapshot(subagents: &[&str]) -> String {
|
|||||||
context_snapshot::format_response_items_snapshot(items.as_slice(), &context_snapshot_options())
|
context_snapshot::format_response_items_snapshot(items.as_slice(), &context_snapshot_options())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn turn_input_contributors_receive_foreign_environment_cwds() -> Result<()> {
|
||||||
|
skip_if_no_network!(Ok(()));
|
||||||
|
|
||||||
|
let server = start_mock_server().await;
|
||||||
|
let response_mock = mount_sse_once(
|
||||||
|
&server,
|
||||||
|
sse(vec![
|
||||||
|
ev_response_created("resp-1"),
|
||||||
|
ev_assistant_message("msg-1", "done"),
|
||||||
|
ev_completed("resp-1"),
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let recorded_environments = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
let mut extensions = ExtensionRegistryBuilder::<Config>::new();
|
||||||
|
extensions.turn_input_contributor(Arc::new(RecordingTurnInputContributor(Arc::clone(
|
||||||
|
&recorded_environments,
|
||||||
|
))));
|
||||||
|
let mut builder = test_codex()
|
||||||
|
.with_extensions(Arc::new(extensions.build()))
|
||||||
|
.with_config(|config| config.project_doc_max_bytes = 0);
|
||||||
|
let test = builder.build_with_auto_env(&server).await?;
|
||||||
|
let mut selection = test.executor_environment().selection().clone();
|
||||||
|
let environment_id = selection.environment_id.clone();
|
||||||
|
let cwd = PathUri::parse(if cfg!(windows) {
|
||||||
|
"file:///workspace"
|
||||||
|
} else {
|
||||||
|
"file:///C:/workspace"
|
||||||
|
})?;
|
||||||
|
assert!(cwd.to_abs_path().is_err());
|
||||||
|
selection.cwd = cwd.clone();
|
||||||
|
selection.workspace_roots = Vec::new();
|
||||||
|
|
||||||
|
test.submit_turn_with_environments("inspect the foreign environment", Some(vec![selection]))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let _request = response_mock.single_request();
|
||||||
|
let recorded_environments = recorded_environments
|
||||||
|
.lock()
|
||||||
|
.expect("recorded environments lock")
|
||||||
|
.iter()
|
||||||
|
.map(|environment| {
|
||||||
|
(
|
||||||
|
environment.environment_id.clone(),
|
||||||
|
environment.cwd.clone(),
|
||||||
|
environment.is_primary,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
assert_eq!(recorded_environments, vec![(environment_id, cwd, true)]);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn model_visible_environment_context_preserves_foreign_workspace_roots() -> Result<()> {
|
async fn model_visible_environment_context_preserves_foreign_workspace_roots() -> Result<()> {
|
||||||
skip_if_no_network!(Ok(()));
|
skip_if_no_network!(Ok(()));
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ codex-mcp = { workspace = true }
|
|||||||
codex-protocol = { workspace = true }
|
codex-protocol = { workspace = true }
|
||||||
codex-tools = { workspace = true }
|
codex-tools = { workspace = true }
|
||||||
codex-utils-absolute-path = { workspace = true }
|
codex-utils-absolute-path = { workspace = true }
|
||||||
|
codex-utils-path-uri = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use codex_protocol::user_input::UserInput;
|
use codex_protocol::user_input::UserInput;
|
||||||
|
use codex_utils_path_uri::PathUri;
|
||||||
|
|
||||||
/// Host-owned turn environment summary visible to turn-input contributors.
|
/// Host-owned turn environment summary visible to turn-input contributors.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -8,7 +7,7 @@ pub struct TurnInputEnvironment {
|
|||||||
/// Stable host environment id used to route executor-scoped capabilities.
|
/// Stable host environment id used to route executor-scoped capabilities.
|
||||||
pub environment_id: String,
|
pub environment_id: String,
|
||||||
/// Effective working directory for this turn in the environment.
|
/// Effective working directory for this turn in the environment.
|
||||||
pub cwd: PathBuf,
|
pub cwd: PathUri,
|
||||||
/// Whether this is the primary environment for the turn.
|
/// Whether this is the primary environment for the turn.
|
||||||
pub is_primary: bool,
|
pub is_primary: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user