Support initial Codex time context overrides

This commit is contained in:
raju
2026-05-13 21:37:21 -07:00
parent b4ecb42966
commit 50e02cbeb3
19 changed files with 289 additions and 14 deletions
+8
View File
@@ -7043,6 +7043,8 @@ async fn test_precedence_fixture_with_o3_profile() -> std::io::Result<()> {
experimental_thread_store: ThreadStoreConfig::Local,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
guardian_policy_config: None,
include_permissions_instructions: true,
include_apps_instructions: true,
@@ -7463,6 +7465,8 @@ async fn test_precedence_fixture_with_gpt3_profile() -> std::io::Result<()> {
experimental_thread_store: ThreadStoreConfig::Local,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
guardian_policy_config: None,
include_permissions_instructions: true,
include_apps_instructions: true,
@@ -7621,6 +7625,8 @@ async fn test_precedence_fixture_with_zdr_profile() -> std::io::Result<()> {
experimental_thread_store: ThreadStoreConfig::Local,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
guardian_policy_config: None,
include_permissions_instructions: true,
include_apps_instructions: true,
@@ -7764,6 +7770,8 @@ async fn test_precedence_fixture_with_gpt5_profile() -> std::io::Result<()> {
experimental_thread_store: ThreadStoreConfig::Local,
base_instructions: None,
developer_instructions: None,
current_date: None,
timezone: None,
guardian_policy_config: None,
include_permissions_instructions: true,
include_apps_instructions: true,
+14
View File
@@ -449,6 +449,14 @@ pub struct Config {
/// Developer instructions override injected as a separate message.
pub developer_instructions: Option<String>,
/// Optional current date override shown in the model-visible environment
/// context for this session.
pub current_date: Option<String>,
/// Optional timezone override shown in the model-visible environment
/// context for this session.
pub timezone: Option<String>,
/// Guardian-specific policy config override from requirements.toml or config.toml.
/// This is inserted into the fixed guardian prompt template under the
/// `# Policy Configuration` section rather than replacing the whole
@@ -1867,6 +1875,8 @@ pub struct ConfigOverrides {
pub zsh_path: Option<PathBuf>,
pub base_instructions: Option<String>,
pub developer_instructions: Option<String>,
pub current_date: Option<String>,
pub timezone: Option<String>,
pub personality: Option<Personality>,
pub compact_prompt: Option<String>,
pub include_apply_patch_tool: Option<bool>,
@@ -2142,6 +2152,8 @@ impl Config {
zsh_path: zsh_path_override,
base_instructions,
developer_instructions,
current_date,
timezone,
personality,
compact_prompt,
include_apply_patch_tool: include_apply_patch_tool_override,
@@ -2999,6 +3011,8 @@ impl Config {
base_instructions,
personality,
developer_instructions,
current_date,
timezone,
compact_prompt,
commit_attribution,
include_permissions_instructions,
+2 -2
View File
@@ -620,8 +620,8 @@ impl Codex {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: environment_selections.to_selections(),
+29 -10
View File
@@ -2581,8 +2581,8 @@ async fn set_rate_limits_retains_previous_credits() {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: Vec::new(),
@@ -2687,8 +2687,8 @@ async fn set_rate_limits_updates_plan_type_when_present() {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: Vec::new(),
@@ -3146,6 +3146,25 @@ async fn session_configuration_apply_updates_environment_context_overrides() {
assert_eq!(updated.timezone.as_deref(), Some("America/Los_Angeles"));
}
#[tokio::test]
async fn turn_context_uses_initial_environment_context_overrides() {
let (_session, turn_context, _rx) = make_session_and_context_with_auth_and_config_and_rx(
CodexAuth::from_api_key("Test API Key"),
Vec::new(),
|config| {
config.current_date = Some("2026-05-13".to_string());
config.timezone = Some("America/Los_Angeles".to_string());
},
)
.await;
assert_eq!(turn_context.current_date.as_deref(), Some("2026-05-13"));
assert_eq!(
turn_context.timezone.as_deref(),
Some("America/Los_Angeles")
);
}
pub(crate) async fn make_session_configuration_for_tests() -> SessionConfiguration {
let codex_home = tempfile::tempdir().expect("create temp dir");
let config = build_test_config(codex_home.path()).await;
@@ -3182,8 +3201,8 @@ pub(crate) async fn make_session_configuration_for_tests() -> SessionConfigurati
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: Vec::new(),
@@ -3710,8 +3729,8 @@ async fn session_new_fails_when_zsh_fork_enabled_without_zsh_path() {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: Vec::new(),
@@ -3821,8 +3840,8 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
active_permission_profile: config.permissions.active_permission_profile(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&config),
cwd: config.cwd.clone(),
current_date: None,
timezone: None,
current_date: config.current_date.clone(),
timezone: config.timezone.clone(),
codex_home: config.codex_home.clone(),
thread_name: None,
environments: default_environments,