clean up test

This commit is contained in:
Owen Lin
2026-05-08 13:43:10 -07:00
parent 3cc96a5aac
commit 908a829b64
2 changed files with 48 additions and 90 deletions
+15 -20
View File
@@ -223,6 +223,16 @@ fn test_session_telemetry_without_metadata() -> SessionTelemetry {
.with_metrics_without_metadata_tags(metrics)
}
fn local_thread_store_for_test(
config: &Config,
state_db_access: crate::StateDbAccess,
) -> Arc<dyn codex_thread_store::ThreadStore> {
Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config),
state_db_access,
))
}
fn find_metric<'a>(resource_metrics: &'a ResourceMetrics, name: &str) -> &'a Metric {
for scope_metrics in resource_metrics.scope_metrics() {
for metric in scope_metrics.metrics() {
@@ -3729,10 +3739,7 @@ async fn session_new_fails_when_zsh_fork_enabled_without_zsh_path() {
AgentControl::default(),
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
crate::StateDbAccess::none(),
)),
local_thread_store_for_test(config.as_ref(), crate::StateDbAccess::none()),
codex_rollout_trace::ThreadTraceContext::disabled(),
/*attestation_provider*/ None,
crate::StateDbAccess::none(),
@@ -3880,10 +3887,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
network_approval: Arc::clone(&network_approval),
state_db_access: crate::StateDbAccess::none(),
live_thread: None,
thread_store: Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
crate::StateDbAccess::none(),
)),
thread_store: local_thread_store_for_test(config.as_ref(), crate::StateDbAccess::none()),
attestation_provider: None,
model_client: ModelClient::new(
Some(auth_manager.clone()),
@@ -4069,10 +4073,7 @@ async fn make_session_with_config_and_rx(
AgentControl::default(),
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
crate::StateDbAccess::none(),
)),
local_thread_store_for_test(config.as_ref(), crate::StateDbAccess::none()),
codex_rollout_trace::ThreadTraceContext::disabled(),
/*attestation_provider*/ None,
crate::StateDbAccess::none(),
@@ -4183,10 +4184,7 @@ async fn make_session_with_history_source_and_agent_control_and_rx(
agent_control,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
state_db_access.clone(),
)),
local_thread_store_for_test(config.as_ref(), state_db_access.clone()),
codex_rollout_trace::ThreadTraceContext::disabled(),
/*attestation_provider*/ None,
state_db_access,
@@ -5606,10 +5604,7 @@ where
network_approval: Arc::clone(&network_approval),
state_db_access: state_db_access.clone(),
live_thread: None,
thread_store: Arc::new(codex_thread_store::LocalThreadStore::new(
codex_thread_store::LocalThreadStoreConfig::from_config(config.as_ref()),
state_db_access,
)),
thread_store: local_thread_store_for_test(config.as_ref(), state_db_access),
attestation_provider: None,
model_client: ModelClient::new(
Some(Arc::clone(&auth_manager)),
+33 -70
View File
@@ -32,6 +32,25 @@ use wiremock::MockServer;
const TEST_INSTALLATION_ID: &str = "11111111-1111-4111-8111-111111111111";
fn thread_manager_for_test(
config: &Config,
auth_manager: Arc<AuthManager>,
state_db_access: StateDbAccess,
installation_id: String,
) -> ThreadManager {
ThreadManager::new(
config,
auth_manager,
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store_from_config(config, state_db_access.clone()),
state_db_access,
installation_id,
/*attestation_provider*/ None,
)
}
fn user_msg(text: &str) -> ResponseItem {
ResponseItem::Message {
id: None,
@@ -486,17 +505,11 @@ async fn resume_and_fork_do_not_restore_thread_environments_from_rollout() {
let auth_manager =
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let state_db_access = StateDbAccess::none();
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager.clone(),
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store_from_config(&config, state_db_access.clone()),
state_db_access,
StateDbAccess::none(),
TEST_INSTALLATION_ID.to_string(),
/*attestation_provider*/ None,
);
let selected_cwd =
AbsolutePathBuf::try_from(config.cwd.as_path().join("selected")).expect("absolute path");
@@ -604,17 +617,11 @@ async fn explicit_installation_id_skips_codex_home_file() {
let installation_id = uuid::Uuid::new_v4().to_string();
let state_db = init_state_db(&config, /*metrics*/ None).await;
let state_db_access = StateDbAccess::new(state_db.clone());
let thread_store = thread_store_from_config(&config, state_db_access.clone());
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager,
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store,
state_db_access,
installation_id.clone(),
/*attestation_provider*/ None,
);
let thread = manager
@@ -643,17 +650,11 @@ async fn resume_active_thread_from_rollout_returns_running_thread() {
let auth_manager =
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let state_db_access = StateDbAccess::none();
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager.clone(),
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store_from_config(&config, state_db_access.clone()),
state_db_access,
StateDbAccess::none(),
TEST_INSTALLATION_ID.to_string(),
/*attestation_provider*/ None,
);
let source = manager
@@ -700,17 +701,11 @@ async fn resume_stopped_thread_from_rollout_spawns_new_thread() {
let auth_manager =
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let state_db_access = StateDbAccess::none();
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager.clone(),
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store_from_config(&config, state_db_access.clone()),
state_db_access,
StateDbAccess::none(),
TEST_INSTALLATION_ID.to_string(),
/*attestation_provider*/ None,
);
let source = manager
@@ -764,17 +759,11 @@ async fn resume_stopped_thread_from_rollout_preserves_thread_source() {
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let state_db = init_state_db(&config, /*metrics*/ None).await;
let state_db_access = StateDbAccess::new(state_db.clone());
let thread_store = thread_store_from_config(&config, state_db_access.clone());
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager.clone(),
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store,
state_db_access,
TEST_INSTALLATION_ID.to_string(),
/*attestation_provider*/ None,
);
let source = manager
@@ -957,17 +946,11 @@ async fn new_uses_active_provider_for_model_refresh() {
let auth_manager =
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let state_db_access = StateDbAccess::none();
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager,
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store_from_config(&config, state_db_access.clone()),
state_db_access,
StateDbAccess::none(),
TEST_INSTALLATION_ID.to_string(),
/*attestation_provider*/ None,
);
let _ = manager.list_models(RefreshStrategy::Online).await;
@@ -1174,16 +1157,11 @@ async fn interrupted_fork_snapshot_does_not_synthesize_turn_id_for_legacy_histor
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let state_db = init_state_db(&config, /*metrics*/ None).await;
let state_db_access = StateDbAccess::new(state_db.clone());
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager.clone(),
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store_from_config(&config, state_db_access.clone()),
state_db_access,
TEST_INSTALLATION_ID.to_string(),
/*attestation_provider*/ None,
);
let source = manager
@@ -1282,16 +1260,11 @@ async fn interrupted_fork_snapshot_preserves_explicit_turn_id() {
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let state_db = init_state_db(&config, /*metrics*/ None).await;
let state_db_access = StateDbAccess::new(state_db.clone());
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager.clone(),
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store_from_config(&config, state_db_access.clone()),
state_db_access,
TEST_INSTALLATION_ID.to_string(),
/*attestation_provider*/ None,
);
let source = manager
@@ -1379,16 +1352,11 @@ async fn interrupted_fork_snapshot_uses_persisted_mid_turn_history_without_live_
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let state_db = init_state_db(&config, /*metrics*/ None).await;
let state_db_access = StateDbAccess::new(state_db.clone());
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager.clone(),
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store_from_config(&config, state_db_access.clone()),
state_db_access,
TEST_INSTALLATION_ID.to_string(),
/*attestation_provider*/ None,
);
let source = manager
@@ -1522,16 +1490,11 @@ async fn resumed_thread_keeps_paused_goal_paused() -> anyhow::Result<()> {
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let state_db = init_state_db(&config, /*metrics*/ None).await;
let state_db_access = StateDbAccess::new(state_db.clone());
let manager = ThreadManager::new(
let manager = thread_manager_for_test(
&config,
auth_manager.clone(),
SessionSource::Exec,
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
/*analytics_events_client*/ None,
thread_store_from_config(&config, state_db_access.clone()),
state_db_access,
TEST_INSTALLATION_ID.to_string(),
/*attestation_provider*/ None,
);
let source = manager