mirror of
https://github.com/openai/codex.git
synced 2026-11-10 21:00:47 +00:00
Restore turn-local cwd override for selected environments
Apply turn-level cwd overrides to the primary selected environment only for the active turn so runtime cwd, environment context diffs, and app-server turn-start behavior stay aligned without rewriting stored sticky environment selections. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -3302,8 +3302,8 @@ async fn session_update_settings_does_not_rewrite_sticky_environment_cwds() {
|
||||
|
||||
assert_eq!(session_cwd, updated_cwd);
|
||||
assert_eq!(config.cwd, turn_context.cwd);
|
||||
assert_eq!(next_turn.cwd, turn_context.cwd);
|
||||
assert_eq!(next_turn.config.cwd, turn_context.cwd);
|
||||
assert_eq!(next_turn.cwd, updated_cwd);
|
||||
assert_eq!(next_turn.config.cwd, updated_cwd);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -4421,11 +4421,11 @@ async fn turn_environments_set_primary_environment() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn default_turn_uses_stored_thread_environments() {
|
||||
async fn default_turn_overlays_session_cwd_onto_stored_thread_environments() {
|
||||
let (session, _turn_context, _rx) = make_session_and_context_with_rx().await;
|
||||
let session_cwd = session.get_config().await.cwd.clone();
|
||||
let selected_cwd =
|
||||
AbsolutePathBuf::try_from(session.get_config().await.cwd.as_path().join("selected"))
|
||||
.expect("absolute path");
|
||||
AbsolutePathBuf::try_from(session_cwd.as_path().join("selected")).expect("absolute path");
|
||||
|
||||
{
|
||||
let mut state = session.state.lock().await;
|
||||
@@ -4446,8 +4446,8 @@ async fn default_turn_uses_stored_thread_environments() {
|
||||
&turn_environment.environment,
|
||||
&turn_environments[0].environment
|
||||
));
|
||||
assert_eq!(turn_context.cwd, selected_cwd);
|
||||
assert_eq!(turn_context.config.cwd, selected_cwd);
|
||||
assert_eq!(turn_context.cwd, session_cwd);
|
||||
assert_eq!(turn_context.config.cwd, session_cwd);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -564,10 +564,16 @@ impl Session {
|
||||
let mut state = self.state.lock().await;
|
||||
match state.session_configuration.clone().apply(&updates) {
|
||||
Ok(next) => {
|
||||
let effective_environments = updates
|
||||
let mut effective_environments = updates
|
||||
.environments
|
||||
.clone()
|
||||
.unwrap_or_else(|| next.environments.clone());
|
||||
if updates.environments.is_none() {
|
||||
Self::overlay_runtime_cwd_on_primary_environment(
|
||||
&mut effective_environments,
|
||||
&next.cwd,
|
||||
);
|
||||
}
|
||||
let turn_environments =
|
||||
self.resolve_turn_environments(&effective_environments)?;
|
||||
let previous_cwd = state.session_configuration.cwd.clone();
|
||||
@@ -753,14 +759,18 @@ impl Session {
|
||||
let state = self.state.lock().await;
|
||||
state.session_configuration.clone()
|
||||
};
|
||||
let turn_environments =
|
||||
match self.resolve_turn_environments(&session_configuration.environments) {
|
||||
Ok(turn_environments) => turn_environments,
|
||||
Err(err) => {
|
||||
warn!("failed to resolve stored session environments: {err}");
|
||||
Vec::new()
|
||||
}
|
||||
};
|
||||
let mut effective_environments = session_configuration.environments.clone();
|
||||
Self::overlay_runtime_cwd_on_primary_environment(
|
||||
&mut effective_environments,
|
||||
&session_configuration.cwd,
|
||||
);
|
||||
let turn_environments = match self.resolve_turn_environments(&effective_environments) {
|
||||
Ok(turn_environments) => turn_environments,
|
||||
Err(err) => {
|
||||
warn!("failed to resolve stored session environments: {err}");
|
||||
Vec::new()
|
||||
}
|
||||
};
|
||||
|
||||
self.new_turn_from_configuration(
|
||||
sub_id,
|
||||
@@ -770,4 +780,15 @@ impl Session {
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
fn overlay_runtime_cwd_on_primary_environment(
|
||||
environments: &mut [TurnEnvironmentSelection],
|
||||
runtime_cwd: &AbsolutePathBuf,
|
||||
) {
|
||||
if let Some(turn_environment) = environments.first_mut()
|
||||
&& turn_environment.cwd != *runtime_cwd
|
||||
{
|
||||
turn_environment.cwd = runtime_cwd.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user