Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 70 additions & 9 deletions codex-rs/core/tests/common/test_codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use codex_model_provider_info::built_in_model_providers;
use codex_models_manager::bundled_models_response;
use codex_models_manager::collaboration_mode_presets::CollaborationModesConfig;
use codex_protocol::config_types::ServiceTier;
use codex_protocol::models::PermissionProfile;
use codex_protocol::openai_models::ModelsResponse;
use codex_protocol::protocol::AskForApproval;
use codex_protocol::protocol::EventMsg;
Expand Down Expand Up @@ -591,10 +592,19 @@ impl TestCodex {
}

pub async fn submit_turn(&self, prompt: &str) -> Result<()> {
self.submit_turn_with_policies(
self.submit_turn_with_permission_profile(prompt, PermissionProfile::Disabled)
.await
}

pub async fn submit_turn_with_permission_profile(
&self,
prompt: &str,
permission_profile: PermissionProfile,
) -> Result<()> {
self.submit_turn_with_approval_and_permission_profile(
prompt,
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
permission_profile,
)
.await
}
Expand All @@ -613,10 +623,10 @@ impl TestCodex {
prompt: &str,
service_tier: Option<ServiceTier>,
) -> Result<()> {
self.submit_turn_with_context(
self.submit_turn_with_permission_profile_context(
prompt,
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
Some(service_tier),
/*environments*/ None,
)
Expand All @@ -629,10 +639,30 @@ impl TestCodex {
approval_policy: AskForApproval,
sandbox_policy: SandboxPolicy,
) -> Result<()> {
let permission_profile = PermissionProfile::from_legacy_sandbox_policy_for_cwd(
&sandbox_policy,
self.config.cwd.as_path(),
);
self.submit_turn_with_context(
prompt,
approval_policy,
sandbox_policy,
permission_profile,
/*service_tier*/ None,
/*environments*/ None,
)
.await
}

pub async fn submit_turn_with_approval_and_permission_profile(
&self,
prompt: &str,
approval_policy: AskForApproval,
permission_profile: PermissionProfile,
) -> Result<()> {
self.submit_turn_with_permission_profile_context(
prompt,
approval_policy,
permission_profile,
/*service_tier*/ None,
/*environments*/ None,
)
Expand All @@ -644,24 +674,45 @@ impl TestCodex {
prompt: &str,
environments: Option<Vec<TurnEnvironmentSelection>>,
) -> Result<()> {
self.submit_turn_with_context(
self.submit_turn_with_permission_profile_context(
prompt,
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
/*service_tier*/ None,
environments,
)
.await
}

async fn submit_turn_with_permission_profile_context(
&self,
prompt: &str,
approval_policy: AskForApproval,
permission_profile: PermissionProfile,
service_tier: Option<Option<ServiceTier>>,
environments: Option<Vec<TurnEnvironmentSelection>>,
) -> Result<()> {
self.submit_turn_with_context(
prompt,
approval_policy,
permission_profile,
service_tier,
environments,
)
.await
}

async fn submit_turn_with_context(
&self,
prompt: &str,
approval_policy: AskForApproval,
sandbox_policy: SandboxPolicy,
permission_profile: PermissionProfile,
service_tier: Option<Option<ServiceTier>>,
environments: Option<Vec<TurnEnvironmentSelection>>,
) -> Result<()> {
let sandbox_policy = permission_profile
.to_legacy_sandbox_policy(self.config.cwd.as_path())
.unwrap_or_else(|_| SandboxPolicy::new_read_only_policy());
let session_model = self.session_configured.model.clone();
self.codex
.submit(Op::UserTurn {
Expand All @@ -675,7 +726,7 @@ impl TestCodex {
approval_policy,
approvals_reviewer: None,
sandbox_policy,
permission_profile: None,
permission_profile: Some(permission_profile),
model: session_model,
effort: None,
summary: None,
Expand Down Expand Up @@ -835,6 +886,16 @@ impl TestCodexHarness {
.await
}

pub async fn submit_with_permission_profile(
&self,
prompt: &str,
permission_profile: PermissionProfile,
) -> Result<()> {
self.test
.submit_turn_with_permission_profile(prompt, permission_profile)
.await
}

pub async fn request_bodies(&self) -> Vec<Value> {
let path_matcher = path_regex(".*/responses$");
self.server
Expand Down
6 changes: 3 additions & 3 deletions codex-rs/core/tests/suite/openai_file_mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use anyhow::Result;
use codex_core::config::Config;
use codex_features::Feature;
use codex_login::CodexAuth;
use codex_protocol::models::PermissionProfile;
use codex_protocol::protocol::AskForApproval;
use codex_protocol::protocol::SandboxPolicy;
use core_test_support::apps_test_server::AppsTestServer;
use core_test_support::apps_test_server::DOCUMENT_EXTRACT_TEXT_RESOURCE_URI;
use core_test_support::responses::ev_assistant_message;
Expand Down Expand Up @@ -169,10 +169,10 @@ async fn codex_apps_file_params_upload_local_paths_before_mcp_tool_call() -> Res
let test = builder.build(&server).await?;
tokio::fs::write(test.cwd.path().join("report.txt"), b"hello world").await?;

test.submit_turn_with_policies(
test.submit_turn_with_approval_and_permission_profile(
"Extract the report text with the app tool.",
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;

Expand Down
34 changes: 17 additions & 17 deletions codex-rs/core/tests/suite/search_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use codex_protocol::dynamic_tools::DynamicToolCallOutputContentItem;
use codex_protocol::dynamic_tools::DynamicToolResponse;
use codex_protocol::dynamic_tools::DynamicToolSpec;
use codex_protocol::models::FunctionCallOutputPayload;
use codex_protocol::models::PermissionProfile;
use codex_protocol::protocol::AskForApproval;
use codex_protocol::protocol::EventMsg;
use codex_protocol::protocol::McpInvocation;
use codex_protocol::protocol::Op;
use codex_protocol::protocol::SandboxPolicy;
use codex_protocol::user_input::UserInput;
use core_test_support::apps_test_server::AppsTestServer;
use core_test_support::apps_test_server::CALENDAR_CREATE_EVENT_MCP_APP_RESOURCE_URI;
Expand Down Expand Up @@ -157,10 +157,10 @@ async fn search_tool_enabled_by_default_adds_tool_search() -> Result<()> {
let mut builder = configured_builder(apps_server.chatgpt_base_url.clone());
let test = builder.build(&server).await?;

test.submit_turn_with_policies(
test.submit_turn_with_approval_and_permission_profile(
"list tools",
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;

Expand Down Expand Up @@ -221,10 +221,10 @@ async fn always_defer_feature_hides_small_app_tool_sets() -> Result<()> {
});
let test = builder.build(&server).await?;

test.submit_turn_with_policies(
test.submit_turn_with_approval_and_permission_profile(
"list tools",
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;

Expand Down Expand Up @@ -265,10 +265,10 @@ async fn tool_search_disabled_exposes_apps_tools_directly() -> Result<()> {
});
let test = builder.build(&server).await?;

test.submit_turn_with_policies(
test.submit_turn_with_approval_and_permission_profile(
"list tools",
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;

Expand Down Expand Up @@ -311,10 +311,10 @@ async fn search_tool_is_hidden_for_api_key_auth() -> Result<()> {
.with_config(move |config| configure_apps(config, apps_server.chatgpt_base_url.as_str()));
let test = builder.build(&server).await?;

test.submit_turn_with_policies(
test.submit_turn_with_approval_and_permission_profile(
"list tools",
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;

Expand Down Expand Up @@ -347,10 +347,10 @@ async fn search_tool_adds_discovery_instructions_to_tool_description() -> Result
let mut builder = configured_builder(apps_server.chatgpt_base_url.clone());
let test = builder.build(&server).await?;

test.submit_turn_with_policies(
test.submit_turn_with_approval_and_permission_profile(
"list tools",
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;

Expand Down Expand Up @@ -389,10 +389,10 @@ async fn search_tool_hides_apps_tools_without_search() -> Result<()> {
let mut builder = configured_builder(apps_server.chatgpt_base_url.clone());
let test = builder.build(&server).await?;

test.submit_turn_with_policies(
test.submit_turn_with_approval_and_permission_profile(
"hello tools",
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;

Expand Down Expand Up @@ -425,10 +425,10 @@ async fn explicit_app_mentions_expose_apps_tools_without_search() -> Result<()>
let mut builder = configured_builder(apps_server.chatgpt_base_url.clone());
let test = builder.build(&server).await?;

test.submit_turn_with_policies(
test.submit_turn_with_approval_and_permission_profile(
"Use [$calendar](app://calendar) and then call tools.",
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;

Expand Down Expand Up @@ -978,10 +978,10 @@ async fn tool_search_indexes_only_enabled_non_app_mcp_tools() -> Result<()> {
});
let test = builder.build(&server).await?;

test.submit_turn_with_policies(
test.submit_turn_with_approval_and_permission_profile(
"Find the rmcp echo and image tools.",
AskForApproval::Never,
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;

Expand Down
Loading
Loading