mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Merge branch 'main' into codex/refresh-turn-diff-environments
This commit is contained in:
@@ -658,6 +658,7 @@ impl TestCodexBuilder {
|
||||
Box::pin(
|
||||
thread_manager.start_thread_with_options(StartThreadOptions {
|
||||
config: config.clone(),
|
||||
allow_provider_model_fallback: false,
|
||||
initial_history: InitialHistory::New,
|
||||
session_source: None,
|
||||
thread_source: None,
|
||||
|
||||
@@ -10,6 +10,7 @@ use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
|
||||
use crate::test_codex::TestCodex;
|
||||
use crate::test_codex::TestCodexBuilder;
|
||||
use crate::test_codex::test_codex;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -19,12 +20,7 @@ pub struct ZshForkRuntime {
|
||||
}
|
||||
|
||||
impl ZshForkRuntime {
|
||||
fn apply_to_config(
|
||||
&self,
|
||||
config: &mut Config,
|
||||
approval_policy: AskForApproval,
|
||||
permission_profile: PermissionProfile,
|
||||
) {
|
||||
fn apply_to_config(&self, config: &mut Config, approval_policy: AskForApproval) {
|
||||
config
|
||||
.features
|
||||
.enable(Feature::ShellTool)
|
||||
@@ -37,10 +33,6 @@ impl ZshForkRuntime {
|
||||
config.main_execve_wrapper_exe = Some(self.main_execve_wrapper_exe.clone());
|
||||
config.permissions.allow_login_shell = false;
|
||||
config.permissions.approval_policy = Constrained::allow_any(approval_policy);
|
||||
config
|
||||
.permissions
|
||||
.set_permission_profile(permission_profile)
|
||||
.expect("set permission profile");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,10 +78,13 @@ pub async fn build_zsh_fork_test<F>(
|
||||
where
|
||||
F: FnOnce(&Path) + Send + 'static,
|
||||
{
|
||||
let mut builder = test_codex()
|
||||
let mut builder = zsh_fork_test_builder(runtime, approval_policy)
|
||||
.with_pre_build_hook(pre_build_hook)
|
||||
.with_config(move |config| {
|
||||
runtime.apply_to_config(config, approval_policy, permission_profile);
|
||||
config
|
||||
.permissions
|
||||
.set_permission_profile(permission_profile)
|
||||
.expect("set permission profile");
|
||||
});
|
||||
builder.build(server).await
|
||||
}
|
||||
@@ -104,10 +99,13 @@ pub async fn build_unified_exec_zsh_fork_test<F>(
|
||||
where
|
||||
F: FnOnce(&Path) + Send + 'static,
|
||||
{
|
||||
let mut builder = test_codex()
|
||||
let mut builder = zsh_fork_test_builder(runtime, approval_policy)
|
||||
.with_pre_build_hook(pre_build_hook)
|
||||
.with_config(move |config| {
|
||||
runtime.apply_to_config(config, approval_policy, permission_profile);
|
||||
config
|
||||
.permissions
|
||||
.set_permission_profile(permission_profile)
|
||||
.expect("set permission profile");
|
||||
config.use_experimental_unified_exec_tool = true;
|
||||
config
|
||||
.features
|
||||
@@ -121,6 +119,15 @@ where
|
||||
builder.build(server).await
|
||||
}
|
||||
|
||||
pub fn zsh_fork_test_builder(
|
||||
runtime: ZshForkRuntime,
|
||||
approval_policy: AskForApproval,
|
||||
) -> TestCodexBuilder {
|
||||
test_codex().with_config(move |config| {
|
||||
runtime.apply_to_config(config, approval_policy);
|
||||
})
|
||||
}
|
||||
|
||||
fn find_test_zsh_path() -> Result<Option<PathBuf>> {
|
||||
let repo_root = codex_utils_cargo_bin::repo_root()?;
|
||||
let dotslash_zsh = repo_root.join("codex-rs/app-server/tests/suite/zsh");
|
||||
|
||||
@@ -486,6 +486,7 @@ async fn loads_user_instructions_without_a_primary_environment() -> Result<()> {
|
||||
.thread_manager
|
||||
.start_thread_with_options(StartThreadOptions {
|
||||
config: test.config.clone(),
|
||||
allow_provider_model_fallback: false,
|
||||
initial_history: InitialHistory::New,
|
||||
session_source: None,
|
||||
thread_source: None,
|
||||
@@ -691,6 +692,7 @@ async fn multi_environment_thread_loads_every_project_and_keeps_creation_snapsho
|
||||
.thread_manager
|
||||
.start_thread_with_options(StartThreadOptions {
|
||||
config: test.config.clone(),
|
||||
allow_provider_model_fallback: false,
|
||||
initial_history: InitialHistory::New,
|
||||
session_source: None,
|
||||
thread_source: None,
|
||||
|
||||
@@ -10,6 +10,7 @@ use codex_features::Feature;
|
||||
use codex_protocol::approvals::NetworkApprovalProtocol;
|
||||
use codex_protocol::approvals::NetworkPolicyAmendment;
|
||||
use codex_protocol::approvals::NetworkPolicyRuleAction;
|
||||
use codex_protocol::models::BUILT_IN_PERMISSION_PROFILE_WORKSPACE;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::permissions::FileSystemAccessMode;
|
||||
use codex_protocol::permissions::FileSystemPath;
|
||||
@@ -47,6 +48,7 @@ use core_test_support::wait_for_event_with_timeout;
|
||||
use core_test_support::zsh_fork::build_zsh_fork_test;
|
||||
use core_test_support::zsh_fork::restrictive_workspace_write_profile;
|
||||
use core_test_support::zsh_fork::zsh_fork_runtime;
|
||||
use core_test_support::zsh_fork::zsh_fork_test_builder;
|
||||
use pretty_assertions::assert_eq;
|
||||
use regex_lite::Regex;
|
||||
use serde_json::Value;
|
||||
@@ -131,6 +133,8 @@ enum ActionKind {
|
||||
|
||||
const DEFAULT_UNIFIED_EXEC_JUSTIFICATION: &str =
|
||||
"Requires escalated permissions to bypass the sandbox in tests.";
|
||||
const WORKSPACE_PERMISSION_PROFILE_CONFIG: &str = r#"default_permissions = ":workspace"
|
||||
"#;
|
||||
|
||||
impl ActionKind {
|
||||
fn policy_src(&self) -> Option<&'static str> {
|
||||
@@ -640,6 +644,7 @@ enum ScenarioGroup {
|
||||
UnifiedExec,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
struct CommandResult {
|
||||
exit_code: Option<i64>,
|
||||
stdout: String,
|
||||
@@ -683,6 +688,52 @@ async fn submit_turn(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn submit_turn_preserving_active_permission_profile(
|
||||
test: &TestCodex,
|
||||
prompt: &str,
|
||||
approval_policy: AskForApproval,
|
||||
) -> Result<()> {
|
||||
let session_model = test.session_configured.model.clone();
|
||||
|
||||
test.codex
|
||||
.submit(Op::UserInput {
|
||||
items: vec![UserInput::Text {
|
||||
text: prompt.into(),
|
||||
text_elements: Vec::new(),
|
||||
}],
|
||||
final_output_json_schema: None,
|
||||
responsesapi_client_metadata: None,
|
||||
additional_context: Default::default(),
|
||||
thread_settings: codex_protocol::protocol::ThreadSettingsOverrides {
|
||||
environments: Some(local_selections(test.config.cwd.clone())),
|
||||
approval_policy: Some(approval_policy),
|
||||
approvals_reviewer: Some(ApprovalsReviewer::User),
|
||||
collaboration_mode: Some(codex_protocol::config_types::CollaborationMode {
|
||||
mode: codex_protocol::config_types::ModeKind::Default,
|
||||
settings: codex_protocol::config_types::Settings {
|
||||
model: session_model,
|
||||
reasoning_effort: None,
|
||||
developer_instructions: None,
|
||||
},
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn assert_active_workspace_permission_profile(test: &TestCodex) {
|
||||
assert_eq!(
|
||||
test.session_configured
|
||||
.active_permission_profile
|
||||
.as_ref()
|
||||
.map(|profile| profile.id.as_str()),
|
||||
Some(BUILT_IN_PERMISSION_PROFILE_WORKSPACE)
|
||||
);
|
||||
}
|
||||
|
||||
fn parse_result(item: &Value) -> CommandResult {
|
||||
let output_str = item
|
||||
.get("output")
|
||||
@@ -2696,6 +2747,325 @@ async fn matched_prefix_rule_runs_unsandboxed_under_zsh_fork() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Verifies that an allowlisted script retains the originating named profile
|
||||
/// when its shell tool call requests escalated, unsandboxed execution.
|
||||
///
|
||||
/// Tool owners use this pattern when a trusted wrapper must run outside the
|
||||
/// current sandbox, but then needs to launch child commands back inside the
|
||||
/// same sandbox with `codex sandbox -P`. The nested invocation must also pass
|
||||
/// `--include-managed-config` so it continues to honor enterprise requirements.
|
||||
/// The test proves both halves of that contract: the wrapper writes outside the
|
||||
/// `:workspace` sandbox, while its inherited profile name remains `:workspace`.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
#[cfg(unix)]
|
||||
async fn allowed_escalated_shell_command_inherits_active_permission_profile() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let home = Arc::new(TempDir::new()?);
|
||||
fs::write(
|
||||
home.path().join("config.toml"),
|
||||
WORKSPACE_PERMISSION_PROFILE_CONFIG,
|
||||
)?;
|
||||
|
||||
let script_dir = tempfile::tempdir_in(std::env::current_dir()?)?;
|
||||
let script_path = script_dir.path().join("print-permission-profile.sh");
|
||||
let outside_path = script_dir.path().join("unsandboxed-marker");
|
||||
fs::write(
|
||||
&script_path,
|
||||
format!(
|
||||
r#"#!/bin/sh
|
||||
# Print the inherited profile so the test can verify that it reached this script.
|
||||
printenv CODEX_PERMISSION_PROFILE
|
||||
touch {outside_path:?}
|
||||
"#
|
||||
),
|
||||
)?;
|
||||
|
||||
let rules_dir = home.path().join("rules");
|
||||
fs::create_dir_all(&rules_dir)?;
|
||||
let script_pattern = serde_json::to_string(&script_path.to_string_lossy())?;
|
||||
fs::write(
|
||||
rules_dir.join("default.rules"),
|
||||
format!(r#"prefix_rule(pattern=["/bin/sh", {script_pattern}], decision="allow")"#),
|
||||
)?;
|
||||
|
||||
let approval_policy = AskForApproval::OnRequest;
|
||||
let mut builder = test_codex().with_home(home).with_config(move |config| {
|
||||
config.permissions.approval_policy = Constrained::allow_any(approval_policy);
|
||||
});
|
||||
let test = builder.build(&server).await?;
|
||||
assert!(!outside_path.starts_with(test.config.cwd.as_path()));
|
||||
assert_active_workspace_permission_profile(&test);
|
||||
|
||||
let call_id = "allowed-escalated-shell-inherits-permission-profile";
|
||||
let command = format!("/bin/sh {script_path:?}");
|
||||
let event = shell_event(
|
||||
call_id,
|
||||
&command,
|
||||
/*timeout_ms*/ 5_000,
|
||||
SandboxPermissions::RequireEscalated,
|
||||
)?;
|
||||
let _ = mount_sse_once(
|
||||
&server,
|
||||
sse(vec![
|
||||
ev_response_created("resp-escalated-profile-1"),
|
||||
event,
|
||||
ev_completed("resp-escalated-profile-1"),
|
||||
]),
|
||||
)
|
||||
.await;
|
||||
let results = mount_sse_once(
|
||||
&server,
|
||||
sse(vec![
|
||||
ev_assistant_message("msg-escalated-profile-1", "done"),
|
||||
ev_completed("resp-escalated-profile-2"),
|
||||
]),
|
||||
)
|
||||
.await;
|
||||
|
||||
submit_turn_preserving_active_permission_profile(
|
||||
&test,
|
||||
"run the allowed script with escalated permissions",
|
||||
approval_policy,
|
||||
)
|
||||
.await?;
|
||||
|
||||
wait_for_completion_without_approval(&test).await;
|
||||
|
||||
let result = parse_result(&results.single_request().function_call_output(call_id));
|
||||
assert_eq!(
|
||||
result,
|
||||
CommandResult {
|
||||
exit_code: Some(0),
|
||||
stdout: format!("{BUILT_IN_PERMISSION_PROFILE_WORKSPACE}\n"),
|
||||
},
|
||||
"the unsandboxed script should inherit CODEX_PERMISSION_PROFILE from the shell command"
|
||||
);
|
||||
assert!(
|
||||
outside_path.exists(),
|
||||
"allowed escalated script should run outside the :workspace sandbox"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Verifies that zsh-fork applies an inner script's allow rule even when the
|
||||
/// model invokes an outer wrapper, and that the escalated script retains the
|
||||
/// named profile needed to reconstruct the original sandbox remotely without
|
||||
/// dropping managed enterprise requirements. The script treats the inherited
|
||||
/// environment value as untrusted and accepts only explicitly allowlisted
|
||||
/// profile names before passing one to `codex sandbox -P`.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
#[cfg(unix)]
|
||||
async fn zsh_fork_inner_allowed_script_inherits_active_permission_profile() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let Some(runtime) = zsh_fork_runtime("zsh-fork remote sandbox wrapper test")? else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
const HOST: &str = "builder.example.com";
|
||||
let approval_policy = AskForApproval::OnRequest;
|
||||
let script_dir = tempfile::tempdir_in(std::env::current_dir()?)?;
|
||||
let wrapper_path = script_dir.path().join("remote-bash");
|
||||
let remote_bash_path = script_dir.path().join("remote_bash.py");
|
||||
let outside_path = script_dir.path().join("remote-bash-unsandboxed-marker");
|
||||
let outside_path_literal = serde_json::to_string(&outside_path.to_string_lossy())?;
|
||||
fs::write(
|
||||
&remote_bash_path,
|
||||
format!(
|
||||
r#"#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
ALLOWED_HOSTS = ("builder.example.com",)
|
||||
ALLOWED_PROFILES = (":workspace",)
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Print an ssh command that recreates the current Codex sandbox remotely."
|
||||
)
|
||||
parser.add_argument("--host", required=True)
|
||||
try:
|
||||
separator = sys.argv.index("--")
|
||||
except ValueError:
|
||||
parser.error("the remote command must follow --")
|
||||
args = parser.parse_args(sys.argv[1:separator])
|
||||
args.command = sys.argv[separator + 1:]
|
||||
if not args.command:
|
||||
parser.error("the remote command must not be empty")
|
||||
if not re.fullmatch(r"[a-z0-9.-]+", args.host) or args.host not in ALLOWED_HOSTS:
|
||||
parser.error("host is not allowlisted")
|
||||
return args
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
profile_name = os.environ.get("CODEX_PERMISSION_PROFILE")
|
||||
if not profile_name:
|
||||
raise SystemExit("CODEX_PERMISSION_PROFILE must not be empty")
|
||||
if profile_name not in ALLOWED_PROFILES:
|
||||
raise SystemExit("CODEX_PERMISSION_PROFILE is not allowlisted")
|
||||
|
||||
shell_command = shlex.join(args.command)
|
||||
sandbox_command = shlex.join(
|
||||
[
|
||||
"codex",
|
||||
"sandbox",
|
||||
"-P",
|
||||
profile_name,
|
||||
"--include-managed-config",
|
||||
"--",
|
||||
"bash",
|
||||
"-lc",
|
||||
shell_command,
|
||||
]
|
||||
)
|
||||
print(shlex.join(["ssh", args.host, sandbox_command]))
|
||||
|
||||
# Test-only proof that this inner script was allowed to run unsandboxed.
|
||||
Path({outside_path_literal}).write_text("unsandboxed", encoding="utf-8")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"#
|
||||
),
|
||||
)?;
|
||||
let remote_bash_exec = shlex::try_join([remote_bash_path.to_string_lossy().as_ref()])?;
|
||||
fs::write(
|
||||
&wrapper_path,
|
||||
format!(
|
||||
r#"#!/usr/bin/env zsh
|
||||
exec {remote_bash_exec} "$@"
|
||||
"#
|
||||
),
|
||||
)?;
|
||||
for path in [&wrapper_path, &remote_bash_path] {
|
||||
let mut permissions = fs::metadata(path)?.permissions();
|
||||
permissions.set_mode(0o755);
|
||||
fs::set_permissions(path, permissions)?;
|
||||
}
|
||||
|
||||
let remote_bash_pattern = serde_json::to_string(&remote_bash_path.to_string_lossy())?;
|
||||
let rules = format!(r#"prefix_rule(pattern=[{remote_bash_pattern}], decision="allow")"#);
|
||||
let server = start_mock_server().await;
|
||||
let mut builder =
|
||||
zsh_fork_test_builder(runtime, approval_policy).with_pre_build_hook(move |home| {
|
||||
fs::write(
|
||||
home.join("config.toml"),
|
||||
WORKSPACE_PERMISSION_PROFILE_CONFIG,
|
||||
)
|
||||
.expect("write config");
|
||||
let rules_dir = home.join("rules");
|
||||
fs::create_dir_all(&rules_dir).expect("create rules dir");
|
||||
fs::write(rules_dir.join("default.rules"), rules).expect("write rules");
|
||||
});
|
||||
let test = builder.build(&server).await?;
|
||||
assert!(!outside_path.starts_with(test.config.cwd.as_path()));
|
||||
assert_active_workspace_permission_profile(&test);
|
||||
|
||||
let command = shlex::try_join([
|
||||
wrapper_path.to_string_lossy().as_ref(),
|
||||
"--host",
|
||||
HOST,
|
||||
"--",
|
||||
"printf",
|
||||
"%s",
|
||||
"hello world",
|
||||
])?;
|
||||
let call_id = "zsh-fork-remote-sandbox-wrapper";
|
||||
let event = shell_event(
|
||||
call_id,
|
||||
&command,
|
||||
/*timeout_ms*/ 30_000,
|
||||
SandboxPermissions::UseDefault,
|
||||
)?;
|
||||
let _ = mount_sse_once(
|
||||
&server,
|
||||
sse(vec![
|
||||
ev_response_created("resp-zsh-fork-remote-wrapper-1"),
|
||||
event,
|
||||
ev_completed("resp-zsh-fork-remote-wrapper-1"),
|
||||
]),
|
||||
)
|
||||
.await;
|
||||
let results = mount_sse_once(
|
||||
&server,
|
||||
sse(vec![
|
||||
ev_assistant_message("msg-zsh-fork-remote-wrapper-1", "done"),
|
||||
ev_completed("resp-zsh-fork-remote-wrapper-2"),
|
||||
]),
|
||||
)
|
||||
.await;
|
||||
|
||||
submit_turn_preserving_active_permission_profile(
|
||||
&test,
|
||||
"run the remote sandbox wrapper",
|
||||
approval_policy,
|
||||
)
|
||||
.await?;
|
||||
wait_for_completion_without_approval(&test).await;
|
||||
|
||||
let result = parse_result(&results.single_request().function_call_output(call_id));
|
||||
assert_eq!(
|
||||
result.exit_code.unwrap_or(0),
|
||||
0,
|
||||
"the inner remote_bash.py script should run successfully: {}",
|
||||
result.stdout
|
||||
);
|
||||
let ssh_argv = shlex::split(result.stdout.trim()).context("parse printed ssh command")?;
|
||||
assert_eq!(
|
||||
ssh_argv.len(),
|
||||
3,
|
||||
"expected ssh HOST LONG_COMMAND, got: {}",
|
||||
result.stdout
|
||||
);
|
||||
assert_eq!(
|
||||
ssh_argv[..2],
|
||||
["ssh", HOST],
|
||||
"remote_bash.py should target only the allowlisted host"
|
||||
);
|
||||
let sandbox_argv = shlex::split(&ssh_argv[2]).context("parse remote sandbox command")?;
|
||||
assert_eq!(
|
||||
sandbox_argv.len(),
|
||||
9,
|
||||
"expected codex sandbox ... bash -lc CMD"
|
||||
);
|
||||
assert_eq!(
|
||||
sandbox_argv[..8],
|
||||
[
|
||||
"codex",
|
||||
"sandbox",
|
||||
"-P",
|
||||
BUILT_IN_PERMISSION_PROFILE_WORKSPACE,
|
||||
"--include-managed-config",
|
||||
"--",
|
||||
"bash",
|
||||
"-lc",
|
||||
],
|
||||
"remote_bash.py should use the allowlisted inherited profile and managed configuration to reconstruct the Codex sandbox"
|
||||
);
|
||||
let command_argv = shlex::split(&sandbox_argv[8]).context("parse remote bash command")?;
|
||||
assert_eq!(
|
||||
command_argv,
|
||||
["printf", "%s", "hello world"],
|
||||
"remote_bash.py should preserve every argument after --"
|
||||
);
|
||||
assert!(
|
||||
outside_path.exists(),
|
||||
"the inner allowlisted script should run outside the :workspace sandbox"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
#[cfg(unix)]
|
||||
async fn invalid_requested_prefix_rule_falls_back_for_compound_command() -> Result<()> {
|
||||
|
||||
@@ -12,6 +12,7 @@ use codex_core::SleepFuture;
|
||||
use codex_core::TimeFuture;
|
||||
use codex_core::TimeProvider;
|
||||
use codex_core::config::CurrentTimeReminderConfig;
|
||||
use codex_features::CurrentTimeReminderDeliveryMode;
|
||||
use codex_features::CurrentTimeSource;
|
||||
use codex_features::Feature;
|
||||
use codex_model_provider_info::built_in_model_providers;
|
||||
@@ -39,6 +40,7 @@ use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
|
||||
const FIRST_REMINDER: &str = "It is 2026-06-17 17:34:15 UTC.";
|
||||
const EARLIER_REMINDER: &str = "It is 2026-06-17 17:33:15 UTC.";
|
||||
const SECOND_REMINDER: &str = "It is 2026-06-17 17:35:15 UTC.";
|
||||
const THIRD_REMINDER: &str = "It is 2026-06-17 17:36:15 UTC.";
|
||||
const FIRST_TIME_UNIX_SECONDS: i64 = 1_781_717_655;
|
||||
@@ -162,6 +164,107 @@ async fn current_time_reminders_follow_time_interval_and_persist_in_history() ->
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn zero_current_time_reminder_interval_delivers_when_time_moves_backward() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let responses = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![ev_response_created("resp-1"), ev_completed("resp-1")]),
|
||||
sse(vec![ev_response_created("resp-2"), ev_completed("resp-2")]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
let time_provider = Arc::new(TestTimeProvider::default());
|
||||
let test = test_codex()
|
||||
.with_config(|config| {
|
||||
enable_current_time_reminder(config, /*interval*/ 0, CurrentTimeSource::External)
|
||||
})
|
||||
.with_external_time_provider(time_provider.clone())
|
||||
.build(&server)
|
||||
.await?;
|
||||
|
||||
test.submit_turn("first turn").await?;
|
||||
time_provider
|
||||
.current_time
|
||||
.store(FIRST_TIME_UNIX_SECONDS - 60, Ordering::Relaxed);
|
||||
test.submit_turn("second turn").await?;
|
||||
|
||||
let requests = responses.requests();
|
||||
assert_eq!(requests.len(), 2);
|
||||
assert_eq!(current_time_reminders(&requests[0]), vec![FIRST_REMINDER]);
|
||||
assert_eq!(
|
||||
current_time_reminders(&requests[1]),
|
||||
vec![FIRST_REMINDER, EARLIER_REMINDER]
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn current_time_reminders_can_follow_only_user_or_tool_outputs() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let tool_args = json!({
|
||||
"command": "echo current time",
|
||||
"timeout_ms": 1_000,
|
||||
});
|
||||
let mut continue_response = ev_completed("resp-2");
|
||||
// Ask for another inference without recording a new user message or tool output.
|
||||
continue_response["response"]["end_turn"] = json!(false);
|
||||
let responses = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
ev_function_call(
|
||||
"current-time-tool-call",
|
||||
"shell_command",
|
||||
&serde_json::to_string(&tool_args)?,
|
||||
),
|
||||
ev_completed("resp-1"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_response_created("resp-2"),
|
||||
ev_assistant_message("msg-2", "continue"),
|
||||
continue_response,
|
||||
]),
|
||||
sse(vec![ev_response_created("resp-3"), ev_completed("resp-3")]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
let test = test_codex()
|
||||
.with_config(|config| {
|
||||
enable_current_time_reminder(config, /*interval*/ 0, CurrentTimeSource::External);
|
||||
config
|
||||
.current_time_reminder
|
||||
.as_mut()
|
||||
.expect("current-time reminder should be configured")
|
||||
.delivery_mode = CurrentTimeReminderDeliveryMode::AfterUserOrToolOutput;
|
||||
})
|
||||
.with_external_time_provider(Arc::new(TestTimeProvider::default()))
|
||||
.build(&server)
|
||||
.await?;
|
||||
|
||||
test.submit_turn_with_permission_profile("first turn", PermissionProfile::Disabled)
|
||||
.await?;
|
||||
|
||||
let requests = responses.requests();
|
||||
assert_eq!(requests.len(), 3);
|
||||
assert_eq!(current_time_reminders(&requests[0]), vec![FIRST_REMINDER]);
|
||||
assert_eq!(
|
||||
current_time_reminders(&requests[1]),
|
||||
vec![FIRST_REMINDER, SECOND_REMINDER]
|
||||
);
|
||||
assert_eq!(
|
||||
current_time_reminders(&requests[2]),
|
||||
vec![FIRST_REMINDER, SECOND_REMINDER]
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn system_time_source_adds_current_time_reminder() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
@@ -221,6 +324,11 @@ async fn current_time_reminder_is_refreshed_after_compaction() -> Result<()> {
|
||||
/*interval*/ 3_000,
|
||||
CurrentTimeSource::External,
|
||||
);
|
||||
config
|
||||
.current_time_reminder
|
||||
.as_mut()
|
||||
.expect("current-time reminder should be configured")
|
||||
.delivery_mode = CurrentTimeReminderDeliveryMode::AfterUserOrToolOutput;
|
||||
})
|
||||
.with_external_time_provider(Arc::new(TestTimeProvider::default()))
|
||||
.build(&server)
|
||||
|
||||
@@ -16,7 +16,7 @@ use core_test_support::test_codex::test_codex;
|
||||
use core_test_support::wait_for_mcp_server;
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn refresh_shuts_down_superseded_mcp_stdio_server() -> anyhow::Result<()> {
|
||||
async fn refresh_keeps_superseded_mcp_server_alive_for_in_flight_calls() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
@@ -84,7 +84,7 @@ async fn refresh_shuts_down_superseded_mcp_stdio_server() -> anyhow::Result<()>
|
||||
"sync",
|
||||
Some(serde_json::json!({
|
||||
"barrier": barrier,
|
||||
"sleep_after_ms": 30_000
|
||||
"sleep_after_ms": 300_000
|
||||
})),
|
||||
/*meta*/ None,
|
||||
)
|
||||
@@ -119,9 +119,16 @@ async fn refresh_shuts_down_superseded_mcp_stdio_server() -> anyhow::Result<()>
|
||||
|
||||
let replacement_pid = wait_for_pid_file(&pid_file).await?;
|
||||
assert_ne!(replacement_pid, superseded_pid);
|
||||
assert!(process_is_alive(&superseded_pid)?);
|
||||
long_call.abort();
|
||||
assert!(
|
||||
long_call
|
||||
.await
|
||||
.expect_err("call should be aborted")
|
||||
.is_cancelled()
|
||||
);
|
||||
wait_for_process_exit(&superseded_pid).await?;
|
||||
assert!(process_is_alive(&replacement_pid)?);
|
||||
assert!(long_call.await?.is_err());
|
||||
|
||||
fixture.codex.shutdown_and_wait().await?;
|
||||
wait_for_process_exit(&replacement_pid).await
|
||||
|
||||
@@ -75,6 +75,7 @@ async fn write_rollout_with_user_event(dir: &Path, thread_id: ThreadId) -> io::R
|
||||
model_provider: None,
|
||||
base_instructions: None,
|
||||
dynamic_tools: None,
|
||||
selected_capability_roots: Vec::new(),
|
||||
memory_mode: None,
|
||||
multi_agent_version: None,
|
||||
context_window: None,
|
||||
@@ -127,6 +128,7 @@ async fn write_rollout_with_meta_only(dir: &Path, thread_id: ThreadId) -> io::Re
|
||||
model_provider: None,
|
||||
base_instructions: None,
|
||||
dynamic_tools: None,
|
||||
selected_capability_roots: Vec::new(),
|
||||
memory_mode: None,
|
||||
multi_agent_version: None,
|
||||
context_window: None,
|
||||
|
||||
@@ -1059,7 +1059,11 @@ async fn remote_models_request_times_out_after_5s() -> Result<()> {
|
||||
let start = Instant::now();
|
||||
let model = timeout(
|
||||
Duration::from_secs(7),
|
||||
manager.get_default_model(&None, RefreshStrategy::OnlineIfUncached),
|
||||
manager.get_default_model(
|
||||
&None,
|
||||
/*allow_provider_model_fallback*/ false,
|
||||
RefreshStrategy::OnlineIfUncached,
|
||||
),
|
||||
)
|
||||
.await;
|
||||
let elapsed = start.elapsed();
|
||||
@@ -1127,7 +1131,11 @@ async fn remote_models_hide_picker_only_models() -> Result<()> {
|
||||
);
|
||||
|
||||
let selected = manager
|
||||
.get_default_model(&None, RefreshStrategy::OnlineIfUncached)
|
||||
.get_default_model(
|
||||
&None,
|
||||
/*allow_provider_model_fallback*/ false,
|
||||
RefreshStrategy::OnlineIfUncached,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(selected, bundled_default_model_slug());
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ use codex_config::types::McpServerTransportConfig;
|
||||
use codex_core::config::Config;
|
||||
use codex_exec_server::CreateDirectoryOptions;
|
||||
use codex_exec_server::Environment;
|
||||
use codex_exec_server::HttpRedirectPolicy;
|
||||
use codex_exec_server::HttpRequestParams;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_mcp::MCP_SANDBOX_STATE_META_CAPABILITY;
|
||||
@@ -2934,6 +2935,7 @@ async fn wait_for_remote_streamable_http_server(
|
||||
headers: Vec::new(),
|
||||
body: None,
|
||||
timeout_ms: Some(remaining.as_millis().clamp(1, 1_000) as u64),
|
||||
redirect_policy: HttpRedirectPolicy::Follow,
|
||||
request_id: "buffered-request".to_string(),
|
||||
stream_response: false,
|
||||
};
|
||||
|
||||
@@ -372,6 +372,7 @@ async fn backfill_scans_existing_rollouts() -> Result<()> {
|
||||
model_provider: None,
|
||||
base_instructions: None,
|
||||
dynamic_tools: None,
|
||||
selected_capability_roots: Vec::new(),
|
||||
memory_mode: None,
|
||||
multi_agent_version: None,
|
||||
context_window: None,
|
||||
|
||||
@@ -761,6 +761,7 @@ async fn subagent_stop_replaces_stop_and_skips_internal_subagents() -> Result<()
|
||||
.thread_manager
|
||||
.start_thread_with_options(StartThreadOptions {
|
||||
config: test.config.clone(),
|
||||
allow_provider_model_fallback: false,
|
||||
initial_history: InitialHistory::New,
|
||||
session_source: Some(SessionSource::SubAgent(SubAgentSource::Review)),
|
||||
thread_source: None,
|
||||
|
||||
Reference in New Issue
Block a user