mirror of
https://github.com/openai/codex.git
synced 2026-05-29 23:40:29 +00:00
This PR makes it possible to disable live web search via an enterprise config even if the user is running in `--yolo` mode (though cached web search will still be available). To do this, create `/etc/codex/requirements.toml` as follows: ```toml # "live" is not allowed; "disabled" is allowed even though not listed explicitly. allowed_web_search_modes = ["cached"] ``` Or set `requirements_toml_base64` MDM as explained on https://developers.openai.com/codex/security/#locations. ### Why - Enforce admin/MDM/`requirements.toml` constraints on web-search behavior, independent of user config and per-turn sandbox defaults. - Ensure per-turn config resolution and review-mode overrides never crash when constraints are present. ### What - Add `allowed_web_search_modes` to requirements parsing and surface it in app-server v2 `ConfigRequirements` (`allowedWebSearchModes`), with fixtures updated. - Define a requirements allowlist type (`WebSearchModeRequirement`) and normalize semantics: - `disabled` is always implicitly allowed (even if not listed). - An empty list is treated as `["disabled"]`. - Make `Config.web_search_mode` a `Constrained<WebSearchMode>` and apply requirements via `ConstrainedWithSource<WebSearchMode>`. - Update per-turn resolution (`resolve_web_search_mode_for_turn`) to: - Prefer `Live → Cached → Disabled` when `SandboxPolicy::DangerFullAccess` is active (subject to requirements), unless the user preference is explicitly `Disabled`. - Otherwise, honor the user’s preferred mode, falling back to an allowed mode when necessary. - Update TUI `/debug-config` and app-server mapping to display normalized `allowed_web_search_modes` (including implicit `disabled`). - Fix web-search integration tests to assert cached behavior under `SandboxPolicy::ReadOnly` (since `DangerFullAccess` legitimately prefers `live` when allowed).
181 lines
5.6 KiB
Rust
181 lines
5.6 KiB
Rust
#![allow(clippy::unwrap_used)]
|
|
|
|
use codex_core::features::Feature;
|
|
use codex_protocol::config_types::WebSearchMode;
|
|
use core_test_support::responses;
|
|
use core_test_support::responses::start_mock_server;
|
|
use core_test_support::skip_if_no_network;
|
|
use core_test_support::test_codex::test_codex;
|
|
|
|
#[allow(clippy::expect_used)]
|
|
fn tool_identifiers(body: &serde_json::Value) -> Vec<String> {
|
|
body["tools"]
|
|
.as_array()
|
|
.unwrap()
|
|
.iter()
|
|
.map(|tool| {
|
|
tool.get("name")
|
|
.and_then(|v| v.as_str())
|
|
.or_else(|| tool.get("type").and_then(|v| v.as_str()))
|
|
.map(std::string::ToString::to_string)
|
|
.expect("tool should have either name or type")
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
#[allow(clippy::expect_used)]
|
|
async fn collect_tool_identifiers_for_model(model: &str) -> Vec<String> {
|
|
let server = start_mock_server().await;
|
|
let sse = responses::sse(vec![
|
|
responses::ev_response_created(model),
|
|
responses::ev_completed(model),
|
|
]);
|
|
let resp_mock = responses::mount_sse_once(&server, sse).await;
|
|
|
|
let mut builder = test_codex()
|
|
.with_model(model)
|
|
// Keep tool expectations stable when the default web_search mode changes.
|
|
.with_config(|config| {
|
|
config
|
|
.web_search_mode
|
|
.set(WebSearchMode::Cached)
|
|
.expect("test web_search_mode should satisfy constraints");
|
|
config.features.enable(Feature::CollaborationModes);
|
|
});
|
|
let test = builder
|
|
.build(&server)
|
|
.await
|
|
.expect("create test Codex conversation");
|
|
|
|
test.submit_turn("hello tools").await.expect("submit turn");
|
|
|
|
let body = resp_mock.single_request().body_json();
|
|
tool_identifiers(&body)
|
|
}
|
|
|
|
fn expected_default_tools(shell_tool: &str, tail: &[&str]) -> Vec<String> {
|
|
let mut tools = if cfg!(windows) {
|
|
vec![shell_tool.to_string()]
|
|
} else {
|
|
vec!["exec_command".to_string(), "write_stdin".to_string()]
|
|
};
|
|
tools.extend(tail.iter().map(|tool| (*tool).to_string()));
|
|
tools
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn model_selects_expected_tools() {
|
|
skip_if_no_network!();
|
|
use pretty_assertions::assert_eq;
|
|
|
|
let codex_tools = collect_tool_identifiers_for_model("codex-mini-latest").await;
|
|
assert_eq!(
|
|
codex_tools,
|
|
expected_default_tools(
|
|
"local_shell",
|
|
&[
|
|
"list_mcp_resources",
|
|
"list_mcp_resource_templates",
|
|
"read_mcp_resource",
|
|
"update_plan",
|
|
"request_user_input",
|
|
"web_search",
|
|
"view_image",
|
|
],
|
|
),
|
|
"codex-mini-latest should expose the local shell tool",
|
|
);
|
|
|
|
let gpt5_codex_tools = collect_tool_identifiers_for_model("gpt-5-codex").await;
|
|
assert_eq!(
|
|
gpt5_codex_tools,
|
|
expected_default_tools(
|
|
"shell_command",
|
|
&[
|
|
"list_mcp_resources",
|
|
"list_mcp_resource_templates",
|
|
"read_mcp_resource",
|
|
"update_plan",
|
|
"request_user_input",
|
|
"apply_patch",
|
|
"web_search",
|
|
"view_image",
|
|
],
|
|
),
|
|
"gpt-5-codex should expose the apply_patch tool",
|
|
);
|
|
|
|
let gpt51_codex_tools = collect_tool_identifiers_for_model("gpt-5.1-codex").await;
|
|
assert_eq!(
|
|
gpt51_codex_tools,
|
|
expected_default_tools(
|
|
"shell_command",
|
|
&[
|
|
"list_mcp_resources",
|
|
"list_mcp_resource_templates",
|
|
"read_mcp_resource",
|
|
"update_plan",
|
|
"request_user_input",
|
|
"apply_patch",
|
|
"web_search",
|
|
"view_image",
|
|
],
|
|
),
|
|
"gpt-5.1-codex should expose the apply_patch tool",
|
|
);
|
|
|
|
let gpt5_tools = collect_tool_identifiers_for_model("gpt-5").await;
|
|
assert_eq!(
|
|
gpt5_tools,
|
|
expected_default_tools(
|
|
"shell",
|
|
&[
|
|
"list_mcp_resources",
|
|
"list_mcp_resource_templates",
|
|
"read_mcp_resource",
|
|
"update_plan",
|
|
"request_user_input",
|
|
"web_search",
|
|
"view_image",
|
|
],
|
|
),
|
|
"gpt-5 should expose the apply_patch tool",
|
|
);
|
|
|
|
let gpt51_tools = collect_tool_identifiers_for_model("gpt-5.1").await;
|
|
assert_eq!(
|
|
gpt51_tools,
|
|
expected_default_tools(
|
|
"shell_command",
|
|
&[
|
|
"list_mcp_resources",
|
|
"list_mcp_resource_templates",
|
|
"read_mcp_resource",
|
|
"update_plan",
|
|
"request_user_input",
|
|
"apply_patch",
|
|
"web_search",
|
|
"view_image",
|
|
],
|
|
),
|
|
"gpt-5.1 should expose the apply_patch tool",
|
|
);
|
|
let exp_tools = collect_tool_identifiers_for_model("exp-5.1").await;
|
|
assert_eq!(
|
|
exp_tools,
|
|
vec![
|
|
"exec_command".to_string(),
|
|
"write_stdin".to_string(),
|
|
"list_mcp_resources".to_string(),
|
|
"list_mcp_resource_templates".to_string(),
|
|
"read_mcp_resource".to_string(),
|
|
"update_plan".to_string(),
|
|
"request_user_input".to_string(),
|
|
"apply_patch".to_string(),
|
|
"web_search".to_string(),
|
|
"view_image".to_string()
|
|
],
|
|
"exp-5.1 should expose the apply_patch tool",
|
|
);
|
|
}
|