mirror of
https://github.com/openai/codex.git
synced 2026-06-01 19:02:59 +00:00
**Stack position:** [5 of 7] ## Summary This PR adds `Op::ThreadSettings`, a queued settings-only update mechanism for changing stored thread settings without starting a new turn. It also removes the legacy `Op::OverrideTurnContext` in the same layer, so reviewers can see the replacement and deletion together. ## Changes - Add `Op::ThreadSettings` for settings-only queued updates. - Emit `ThreadSettingsApplied` with the effective thread settings snapshot after core applies an update. - Route settings-only updates through the same submission queue as user input. - Migrate remaining `OverrideTurnContext` tests and callers to the queued `Op::ThreadSettings` path. - Delete `Op::OverrideTurnContext` from the core protocol and submission loop. This stack addresses #20656 and #22090. ## Stack 1. [1 of 7] [Add thread settings to UserInput](https://github.com/openai/codex/pull/23080) 2. [2 of 7] [Remove UserInputWithTurnContext](https://github.com/openai/codex/pull/23081) 3. [3 of 7] [Remove UserTurn](https://github.com/openai/codex/pull/23075) 4. [4 of 7] [Placeholder for OverrideTurnContext cleanup](https://github.com/openai/codex/pull/23087) 5. [5 of 7] [Replace OverrideTurnContext with ThreadSettings](https://github.com/openai/codex/pull/22508) (this PR) 6. [6 of 7] [Add app-server thread settings API](https://github.com/openai/codex/pull/22509) 7. [7 of 7] [Sync TUI thread settings](https://github.com/openai/codex/pull/22510)
118 lines
3.7 KiB
Rust
118 lines
3.7 KiB
Rust
use anyhow::Result;
|
|
use codex_core::config::Constrained;
|
|
use codex_protocol::config_types::CollaborationMode;
|
|
use codex_protocol::config_types::ModeKind;
|
|
use codex_protocol::config_types::Settings;
|
|
use codex_protocol::protocol::AskForApproval;
|
|
use codex_protocol::protocol::EventMsg;
|
|
use codex_protocol::protocol::Op;
|
|
use core_test_support::responses::start_mock_server;
|
|
use core_test_support::skip_if_no_network;
|
|
use core_test_support::test_codex::test_codex;
|
|
use core_test_support::wait_for_event;
|
|
use tempfile::TempDir;
|
|
|
|
fn collab_mode_with_instructions(instructions: Option<&str>) -> CollaborationMode {
|
|
CollaborationMode {
|
|
mode: ModeKind::Default,
|
|
settings: Settings {
|
|
model: "gpt-5.4".to_string(),
|
|
reasoning_effort: None,
|
|
developer_instructions: instructions.map(str::to_string),
|
|
},
|
|
}
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn thread_settings_update_without_user_turn_does_not_record_permissions_update() -> Result<()>
|
|
{
|
|
skip_if_no_network!(Ok(()));
|
|
|
|
let server = start_mock_server().await;
|
|
let mut builder = test_codex().with_config(|config| {
|
|
config.permissions.approval_policy = Constrained::allow_any(AskForApproval::OnRequest);
|
|
});
|
|
let test = builder.build(&server).await?;
|
|
|
|
core_test_support::submit_thread_settings(
|
|
&test.codex,
|
|
codex_protocol::protocol::ThreadSettingsOverrides {
|
|
approval_policy: Some(AskForApproval::Never),
|
|
..Default::default()
|
|
},
|
|
)
|
|
.await?;
|
|
|
|
test.codex.submit(Op::Shutdown).await?;
|
|
wait_for_event(&test.codex, |ev| matches!(ev, EventMsg::ShutdownComplete)).await;
|
|
|
|
let rollout_path = test.codex.rollout_path().expect("rollout path");
|
|
assert!(
|
|
!rollout_path.exists(),
|
|
"did not expect a rollout before a new user turn"
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn thread_settings_update_without_user_turn_does_not_record_environment_update() -> Result<()>
|
|
{
|
|
skip_if_no_network!(Ok(()));
|
|
|
|
let server = start_mock_server().await;
|
|
let test = test_codex().build(&server).await?;
|
|
let new_cwd = TempDir::new()?;
|
|
|
|
core_test_support::submit_thread_settings(
|
|
&test.codex,
|
|
codex_protocol::protocol::ThreadSettingsOverrides {
|
|
cwd: Some(new_cwd.path().to_path_buf()),
|
|
..Default::default()
|
|
},
|
|
)
|
|
.await?;
|
|
|
|
test.codex.submit(Op::Shutdown).await?;
|
|
wait_for_event(&test.codex, |ev| matches!(ev, EventMsg::ShutdownComplete)).await;
|
|
|
|
let rollout_path = test.codex.rollout_path().expect("rollout path");
|
|
assert!(
|
|
!rollout_path.exists(),
|
|
"did not expect a rollout before a new user turn"
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn thread_settings_update_without_user_turn_does_not_record_collaboration_update()
|
|
-> Result<()> {
|
|
skip_if_no_network!(Ok(()));
|
|
|
|
let server = start_mock_server().await;
|
|
let test = test_codex().build(&server).await?;
|
|
let collab_text = "override collaboration instructions";
|
|
let collaboration_mode = collab_mode_with_instructions(Some(collab_text));
|
|
|
|
core_test_support::submit_thread_settings(
|
|
&test.codex,
|
|
codex_protocol::protocol::ThreadSettingsOverrides {
|
|
collaboration_mode: Some(collaboration_mode),
|
|
..Default::default()
|
|
},
|
|
)
|
|
.await?;
|
|
|
|
test.codex.submit(Op::Shutdown).await?;
|
|
wait_for_event(&test.codex, |ev| matches!(ev, EventMsg::ShutdownComplete)).await;
|
|
|
|
let rollout_path = test.codex.rollout_path().expect("rollout path");
|
|
assert!(
|
|
!rollout_path.exists(),
|
|
"did not expect a rollout before a new user turn"
|
|
);
|
|
|
|
Ok(())
|
|
}
|