Skip to content
Closed
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
14 changes: 14 additions & 0 deletions codex-rs/core/tests/common/test_codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use wiremock::Match;
use wiremock::matchers::path_regex;

type ConfigMutator = dyn FnOnce(&mut Config) + Send;
type PreConfigHook = dyn FnOnce(&Path) + Send + 'static;
type PreBuildHook = dyn FnOnce(&Path) + Send + 'static;

/// A collection of different ways the model can output an apply_patch call
Expand All @@ -56,6 +57,7 @@ pub enum ShellModelOutput {
pub struct TestCodexBuilder {
config_mutators: Vec<Box<ConfigMutator>>,
auth: CodexAuth,
pre_config_hooks: Vec<Box<PreConfigHook>>,
pre_build_hooks: Vec<Box<PreBuildHook>>,
home: Option<Arc<TempDir>>,
}
Expand Down Expand Up @@ -89,6 +91,14 @@ impl TestCodexBuilder {
self
}

pub fn with_pre_config_hook<F>(mut self, hook: F) -> Self
where
F: FnOnce(&Path) + Send + 'static,
{
self.pre_config_hooks.push(Box::new(hook));
self
}

pub fn with_home(mut self, home: Arc<TempDir>) -> Self {
self.home = Some(home);
self
Expand Down Expand Up @@ -208,6 +218,9 @@ impl TestCodexBuilder {
..built_in_model_providers()["openai"].clone()
};
let cwd = Arc::new(TempDir::new()?);
for hook in self.pre_config_hooks.drain(..) {
hook(home.path());
}
let mut config = load_default_config_for_test(home).await;
config.cwd = cwd.path().to_path_buf();
config.model_provider = model_provider;
Expand Down Expand Up @@ -446,6 +459,7 @@ pub fn test_codex() -> TestCodexBuilder {
TestCodexBuilder {
config_mutators: vec![],
auth: CodexAuth::from_api_key("dummy"),
pre_config_hooks: vec![],
pre_build_hooks: vec![],
home: None,
}
Expand Down
2 changes: 1 addition & 1 deletion codex-rs/core/tests/suite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ mod unstable_features_warning;
mod user_notification;
mod user_shell_cmd;
mod view_image;
mod web_search_cached;
mod web_search;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use core_test_support::test_codex::test_codex;
use pretty_assertions::assert_eq;
use serde_json::Value;

const CONFIG_TOML: &str = "config.toml";

fn sse_completed(id: &str) -> String {
load_sse_fixture_with_id("../fixtures/completed_template.json", id)
}
Expand Down Expand Up @@ -86,3 +88,40 @@ async fn web_search_mode_takes_precedence_over_legacy_flags_in_request_body() {
"web_search mode should win over legacy web_search_request"
);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn danger_full_access_config_defaults_web_search_to_live() {
skip_if_no_network!();

let server = start_mock_server().await;
let sse = sse_completed("resp-1");
let resp_mock = responses::mount_sse_once(&server, sse).await;

let mut builder = test_codex()
.with_model("gpt-5-codex")
.with_config(|config| {
config.features.disable(Feature::WebSearchCached);
config.features.disable(Feature::WebSearchRequest);
})
.with_pre_config_hook(|home| {
let config_path = home.join(CONFIG_TOML);
std::fs::write(config_path, "sandbox_mode = \"danger-full-access\"\n")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you set this value in with_config?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with_config applies mutations after the config is loaded, but web_search_mode is determined at config load time. so we have to apply the config change before it's loaded.

.expect("seed config.toml");
});
let test = builder
.build(&server)
.await
.expect("create test Codex conversation");

test.submit_turn("hello danger full access web search")
.await
.expect("submit turn");

let body = resp_mock.single_request().body_json();
let tool = find_web_search_tool(&body);
assert_eq!(
tool.get("external_web_access").and_then(Value::as_bool),
Some(true),
"danger-full-access should default web_search to live"
);
}
Loading