mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Preserve environment configuration ownership (#38678)
## Why Environment attachments can either inherit configuration from their thread or provide their own. Later thread setting updates must refresh inherited configuration without overwriting attachment-owned permissions and capability roots. ## What changed - Resolve each attachment's configuration when it is selected and retain whether it came from the thread or the attachment owner. - Apply subsequent thread configuration updates only to thread-owned attachments, while preserving ownership across snapshots and child threads. - Keep the resolved configuration with the environment selection so runtime consumers use a single canonical value. ## Testing - Extend remote-environment coverage to verify that thread-owned permissions follow thread updates while owner-provided read-only permissions remain in effect. - Cover configuration inheritance, attachment replacement, and owner-configured capability roots. GitOrigin-RevId: fe70c4be5f151432b69bf4b141e316faa89036ae
This commit is contained in:
1 parent
233739e76a
commit
22bf16a37e
23 files changed
+343
-192
No files matched your search
@@ -2298,7 +2298,7 @@ async fn spawn_agent_reapplies_runtime_sandbox_after_role_config() {
|
||||
else {
|
||||
panic!("parent environment should be ready");
|
||||
};
|
||||
environment.config.permission_profile =
|
||||
environment.config_mut().permission_profile =
|
||||
PermissionProfileSnapshot::legacy(expected_permission_profile.clone());
|
||||
assert_ne!(
|
||||
role_config.permissions.effective_permission_profile(),
|
||||
@@ -4572,7 +4572,7 @@ async fn build_agent_resume_config_clears_base_instructions() {
|
||||
else {
|
||||
panic!("parent environment should be ready");
|
||||
};
|
||||
environment.config.permission_profile =
|
||||
environment.config_mut().permission_profile =
|
||||
PermissionProfileSnapshot::legacy(environment_permission_profile.clone());
|
||||
|
||||
let config =
|
||||
|
||||
@@ -101,8 +101,10 @@ impl ShellCommandHandler {
|
||||
.shell
|
||||
.as_ref()
|
||||
.unwrap_or(session_shell.as_ref());
|
||||
let use_login_shell =
|
||||
Self::resolve_use_login_shell(params.login, turn_environment.config.allow_login_shell)?;
|
||||
let use_login_shell = Self::resolve_use_login_shell(
|
||||
params.login,
|
||||
turn_environment.config().allow_login_shell,
|
||||
)?;
|
||||
let command = Self::base_command(shell, ¶ms.command, use_login_shell);
|
||||
|
||||
let mut env = create_env(
|
||||
|
||||
@@ -6,6 +6,7 @@ use codex_protocol::models::ShellCommandToolCallParams;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::config::PermissionProfileSnapshot;
|
||||
use crate::environment_selection::EnvironmentConfigOrigin;
|
||||
use crate::exec_env::CODEX_PERMISSION_PROFILE_ENV_VAR;
|
||||
use crate::exec_env::create_env;
|
||||
use crate::exec_env::inject_permission_profile_env;
|
||||
@@ -109,8 +110,16 @@ async fn shell_command_handler_to_exec_params_uses_selected_environment() {
|
||||
environment_id: "selected-environment".to_string(),
|
||||
cwd: PathUri::from_abs_path(&selected_cwd),
|
||||
workspace_roots: Vec::new(),
|
||||
config: EnvironmentConfigState::FromThread,
|
||||
config: EnvironmentConfigState::Ready(EnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: PermissionProfileSnapshot::active(
|
||||
permission_profile,
|
||||
active_permission_profile.clone(),
|
||||
),
|
||||
selected_capability_roots: Vec::new(),
|
||||
}),
|
||||
},
|
||||
EnvironmentConfigOrigin::Thread,
|
||||
Arc::clone(
|
||||
&turn_context
|
||||
.environments
|
||||
@@ -119,14 +128,6 @@ async fn shell_command_handler_to_exec_params_uses_selected_environment() {
|
||||
.environment,
|
||||
),
|
||||
Some(selected_shell),
|
||||
EnvironmentConfig {
|
||||
allow_login_shell: true,
|
||||
permission_profile: PermissionProfileSnapshot::active(
|
||||
permission_profile,
|
||||
active_permission_profile.clone(),
|
||||
),
|
||||
selected_capability_roots: Vec::new(),
|
||||
},
|
||||
);
|
||||
let mut expected_env = create_env(
|
||||
&turn_context.config.permissions.shell_environment_policy,
|
||||
@@ -210,7 +211,7 @@ async fn shell_command_handler_defaults_to_non_login_when_disallowed() {
|
||||
.primary()
|
||||
.expect("primary environment")
|
||||
.clone();
|
||||
turn_environment.config.allow_login_shell = false;
|
||||
turn_environment.config_mut().allow_login_shell = false;
|
||||
let cwd = turn_environment
|
||||
.cwd()
|
||||
.to_abs_path()
|
||||
|
||||
@@ -233,7 +233,7 @@ impl ExecCommandHandler {
|
||||
&args,
|
||||
shell,
|
||||
&shell_mode,
|
||||
turn_environment.config.allow_login_shell,
|
||||
turn_environment.config().allow_login_shell,
|
||||
)
|
||||
.map_err(FunctionCallError::RespondToModel)?;
|
||||
let command = resolved_command.command;
|
||||
|
||||
@@ -183,7 +183,7 @@ async fn exec_command_rejects_login_when_selected_environment_disallows_it() {
|
||||
else {
|
||||
panic!("primary environment should be ready");
|
||||
};
|
||||
environment.config.allow_login_shell = false;
|
||||
environment.config_mut().allow_login_shell = false;
|
||||
|
||||
let turn = Arc::new(turn);
|
||||
let invocation = ToolInvocation {
|
||||
|
||||
@@ -290,9 +290,9 @@ mod tests {
|
||||
selection.workspace_roots.clear();
|
||||
turn.environments.environments[0] = TurnEnvironmentState::Ready(TurnEnvironment::new(
|
||||
selection,
|
||||
current.config_origin,
|
||||
current.environment,
|
||||
current.shell,
|
||||
current.config,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ mod tests {
|
||||
else {
|
||||
panic!("primary environment should be ready");
|
||||
};
|
||||
environment.config.permission_profile =
|
||||
environment.config_mut().permission_profile =
|
||||
PermissionProfileSnapshot::legacy(PermissionProfile::read_only());
|
||||
let turn = Arc::new(turn);
|
||||
|
||||
@@ -430,7 +430,7 @@ mod tests {
|
||||
else {
|
||||
panic!("primary environment should be ready");
|
||||
};
|
||||
environment.config.permission_profile =
|
||||
environment.config_mut().permission_profile =
|
||||
PermissionProfileSnapshot::legacy(PermissionProfile::Disabled);
|
||||
let turn = Arc::new(turn);
|
||||
|
||||
@@ -467,7 +467,7 @@ mod tests {
|
||||
else {
|
||||
panic!("primary environment should be ready");
|
||||
};
|
||||
environment.config.permission_profile =
|
||||
environment.config_mut().permission_profile =
|
||||
PermissionProfileSnapshot::legacy(PermissionProfile::Disabled);
|
||||
let turn = Arc::new(turn);
|
||||
|
||||
|
||||
Reference in new issue
Block a user