mirror of
https://github.com/openai/codex.git
synced 2026-11-21 22:50:37 +00:00
feat: gate unified exec zsh fork composition
This commit is contained in:
@@ -75,6 +75,7 @@ pub use tool_config::ZshForkConfig;
|
||||
pub use tool_config::request_user_input_available_modes;
|
||||
pub use tool_config::shell_command_backend_for_features;
|
||||
pub use tool_config::shell_type_for_model_and_features;
|
||||
pub use tool_config::unified_exec_uses_zsh_fork_for_features;
|
||||
pub use tool_definition::ToolDefinition;
|
||||
pub use tool_discovery::DiscoverablePluginInfo;
|
||||
pub use tool_discovery::DiscoverableTool;
|
||||
|
||||
@@ -41,6 +41,22 @@ pub fn shell_command_backend_for_features(features: &Features) -> ShellCommandBa
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether unified exec should launch local zsh commands through the
|
||||
/// zsh fork.
|
||||
///
|
||||
/// `unified_exec_zsh_fork` is only a composition gate. It does not enable
|
||||
/// either underlying shell mode on its own, so disabling `unified_exec` or
|
||||
/// `shell_zsh_fork` keeps those features independently off. This lets
|
||||
/// enterprise deployments opt into, or out of, unified exec and zsh-fork
|
||||
/// behavior separately; otherwise enabling the composition flag would silently
|
||||
/// activate a shell backend that the configured feature set left disabled.
|
||||
pub fn unified_exec_uses_zsh_fork_for_features(features: &Features) -> bool {
|
||||
features.enabled(Feature::ShellTool)
|
||||
&& features.enabled(Feature::UnifiedExec)
|
||||
&& features.enabled(Feature::ShellZshFork)
|
||||
&& features.enabled(Feature::UnifiedExecZshFork)
|
||||
}
|
||||
|
||||
pub fn shell_type_for_model_and_features(
|
||||
model_info: &ModelInfo,
|
||||
features: &Features,
|
||||
@@ -58,7 +74,9 @@ pub fn shell_type_for_model_and_features(
|
||||
|
||||
if !features.enabled(Feature::ShellTool) {
|
||||
ConfigShellToolType::Disabled
|
||||
} else if features.enabled(Feature::ShellZshFork) {
|
||||
} else if features.enabled(Feature::ShellZshFork)
|
||||
&& !unified_exec_uses_zsh_fork_for_features(features)
|
||||
{
|
||||
ConfigShellToolType::ShellCommand
|
||||
} else if unified_exec_enabled {
|
||||
if codex_utils_pty::conpty_supported() {
|
||||
@@ -85,13 +103,13 @@ pub struct ZshForkConfig {
|
||||
|
||||
impl UnifiedExecShellMode {
|
||||
pub fn for_session(
|
||||
shell_command_backend: ShellCommandBackendConfig,
|
||||
use_zsh_fork: bool,
|
||||
user_shell_type: ToolUserShellType,
|
||||
shell_zsh_path: Option<&PathBuf>,
|
||||
main_execve_wrapper_exe: Option<&PathBuf>,
|
||||
) -> Self {
|
||||
if cfg!(unix)
|
||||
&& shell_command_backend == ShellCommandBackendConfig::ZshFork
|
||||
&& use_zsh_fork
|
||||
&& matches!(user_shell_type, ToolUserShellType::Zsh)
|
||||
&& let (Some(shell_zsh_path), Some(main_execve_wrapper_exe)) =
|
||||
(shell_zsh_path, main_execve_wrapper_exe)
|
||||
|
||||
@@ -81,6 +81,12 @@ fn shell_type_is_derived_from_model_and_feature_gates() {
|
||||
ConfigShellToolType::ShellCommand
|
||||
);
|
||||
|
||||
features.enable(Feature::UnifiedExecZshFork);
|
||||
assert_eq!(
|
||||
shell_type_for_model_and_features(&model, &features),
|
||||
expected_unified_exec
|
||||
);
|
||||
|
||||
features.disable(Feature::ShellTool);
|
||||
assert_eq!(
|
||||
shell_type_for_model_and_features(&model, &features),
|
||||
@@ -109,6 +115,22 @@ fn shell_command_backend_requires_both_shell_tool_and_zsh_fork() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unified_exec_uses_zsh_fork_only_when_composition_and_dependencies_are_enabled() {
|
||||
let mut features = shell_features();
|
||||
assert_eq!(unified_exec_uses_zsh_fork_for_features(&features), false);
|
||||
|
||||
features.enable(Feature::UnifiedExec);
|
||||
features.enable(Feature::ShellZshFork);
|
||||
assert_eq!(unified_exec_uses_zsh_fork_for_features(&features), false);
|
||||
|
||||
features.enable(Feature::UnifiedExecZshFork);
|
||||
assert_eq!(unified_exec_uses_zsh_fork_for_features(&features), true);
|
||||
|
||||
features.disable(Feature::ShellTool);
|
||||
assert_eq!(unified_exec_uses_zsh_fork_for_features(&features), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn request_user_input_modes_follow_default_mode_feature() {
|
||||
let mut features = Features::with_defaults();
|
||||
@@ -131,7 +153,7 @@ fn unified_exec_shell_mode_uses_zsh_fork_only_when_all_inputs_match() {
|
||||
let shell = exe.clone();
|
||||
|
||||
let mode = UnifiedExecShellMode::for_session(
|
||||
ShellCommandBackendConfig::ZshFork,
|
||||
/*use_zsh_fork*/ true,
|
||||
ToolUserShellType::Zsh,
|
||||
Some(&shell),
|
||||
Some(&exe),
|
||||
@@ -144,7 +166,7 @@ fn unified_exec_shell_mode_uses_zsh_fork_only_when_all_inputs_match() {
|
||||
|
||||
assert_eq!(
|
||||
UnifiedExecShellMode::for_session(
|
||||
ShellCommandBackendConfig::Classic,
|
||||
/*use_zsh_fork*/ false,
|
||||
ToolUserShellType::Zsh,
|
||||
Some(&shell),
|
||||
Some(&exe),
|
||||
|
||||
Reference in New Issue
Block a user