mirror of
https://github.com/openai/codex.git
synced 2026-05-28 15:00:16 +00:00
## Why We want the agent graph store to be passed down the stack as a real dependency, the same way we already treat the thread store. This will let us inject the agent graph store as a real dependency and support implementations other than the local SQLite-backed one. Right now most code instantiates a state DB and an agent graph store just-in-time. Ideally, we would not depend on the state DB directly but only read through the higher-level interfaces. This change makes the dependency boundaries explicit and moves state DB initialization to process bootstrap instead of hiding it inside local store implementations. ## What changed - `ThreadManager` now requires a `StateDbHandle` and an `AgentGraphStore` at construction time instead of treating them as optional internals. - The local store constructors no longer lazily initialize SQLite. Callers now initialize the state DB once per process and use that shared handle to build: - `LocalThreadStore` - `LocalAgentGraphStore` - App bootstraps (`app-server`, `mcp-server`, `prompt_debug`, and the thread-manager sample) now initialize the state DB up front and inject the resulting handle down the stack. - `app-server` now consistently uses its process-scoped state DB handle instead of reopening SQLite or trying to recover it from loaded threads. - Device-key storage now reuses the shared state DB handle instead of maintaining its own lazy opener. - The thread archive / descendant traversal paths now use the injected `AgentGraphStore` instead of reaching through local thread-store-specific state. ## Verification - `cargo check -p codex-core -p codex-thread-store -p codex-app-server -p codex-mcp-server -p codex-thread-manager-sample --tests` - `cargo test -p codex-thread-store` - `cargo test -p codex-core thread_manager_accepts_separate_agent_graph_store_and_thread_store -- --nocapture` - `cargo test -p codex-app-server thread_archive_archives_spawned_descendants -- --nocapture`
128 lines
4.2 KiB
Rust
128 lines
4.2 KiB
Rust
//! Test-only helpers exposed for cross-crate integration tests.
|
|
//!
|
|
//! Production code should not depend on this module.
|
|
//! We prefer this to using a crate feature to avoid building multiple
|
|
//! permutations of the crate.
|
|
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
|
|
use codex_exec_server::EnvironmentManager;
|
|
use codex_login::AuthManager;
|
|
use codex_login::CodexAuth;
|
|
use codex_model_provider::create_model_provider;
|
|
use codex_model_provider_info::ModelProviderInfo;
|
|
use codex_models_manager::bundled_models_response;
|
|
use codex_models_manager::collaboration_mode_presets;
|
|
use codex_models_manager::manager::SharedModelsManager;
|
|
use codex_models_manager::test_support::construct_model_info_offline_for_tests;
|
|
use codex_models_manager::test_support::get_model_offline_for_tests;
|
|
use codex_protocol::config_types::CollaborationModeMask;
|
|
use codex_protocol::openai_models::ModelInfo;
|
|
use codex_protocol::openai_models::ModelPreset;
|
|
use once_cell::sync::Lazy;
|
|
|
|
use crate::ThreadManager;
|
|
use crate::config::Config;
|
|
use crate::thread_manager;
|
|
use crate::unified_exec;
|
|
|
|
static TEST_MODEL_PRESETS: Lazy<Vec<ModelPreset>> = Lazy::new(|| {
|
|
let mut response = bundled_models_response()
|
|
.unwrap_or_else(|err| panic!("bundled models.json should parse: {err}"));
|
|
response.models.sort_by(|a, b| a.priority.cmp(&b.priority));
|
|
let mut presets: Vec<ModelPreset> = response.models.into_iter().map(Into::into).collect();
|
|
ModelPreset::mark_default_by_picker_visibility(&mut presets);
|
|
presets
|
|
});
|
|
|
|
pub fn set_thread_manager_test_mode(enabled: bool) {
|
|
thread_manager::set_thread_manager_test_mode_for_tests(enabled);
|
|
}
|
|
|
|
pub fn set_deterministic_process_ids(enabled: bool) {
|
|
unified_exec::set_deterministic_process_ids_for_tests(enabled);
|
|
}
|
|
|
|
pub fn auth_manager_from_auth(auth: CodexAuth) -> Arc<AuthManager> {
|
|
AuthManager::from_auth_for_testing(auth)
|
|
}
|
|
|
|
pub fn auth_manager_from_auth_with_home(auth: CodexAuth, codex_home: PathBuf) -> Arc<AuthManager> {
|
|
AuthManager::from_auth_for_testing_with_home(auth, codex_home)
|
|
}
|
|
|
|
pub async fn thread_manager_with_models_provider(
|
|
auth: CodexAuth,
|
|
provider: ModelProviderInfo,
|
|
) -> ThreadManager {
|
|
ThreadManager::with_models_provider_for_tests(auth, provider).await
|
|
}
|
|
|
|
pub async fn thread_manager_with_models_provider_and_home(
|
|
auth: CodexAuth,
|
|
provider: ModelProviderInfo,
|
|
codex_home: PathBuf,
|
|
environment_manager: Arc<EnvironmentManager>,
|
|
) -> ThreadManager {
|
|
ThreadManager::with_models_provider_and_home_for_tests(
|
|
auth,
|
|
provider,
|
|
codex_home,
|
|
environment_manager,
|
|
)
|
|
.await
|
|
}
|
|
|
|
pub async fn start_thread_with_user_shell_override(
|
|
thread_manager: &ThreadManager,
|
|
config: Config,
|
|
user_shell_override: crate::shell::Shell,
|
|
) -> codex_protocol::error::Result<crate::NewThread> {
|
|
thread_manager
|
|
.start_thread_with_user_shell_override_for_tests(config, user_shell_override)
|
|
.await
|
|
}
|
|
|
|
pub async fn resume_thread_from_rollout_with_user_shell_override(
|
|
thread_manager: &ThreadManager,
|
|
config: Config,
|
|
rollout_path: PathBuf,
|
|
auth_manager: Arc<AuthManager>,
|
|
user_shell_override: crate::shell::Shell,
|
|
) -> codex_protocol::error::Result<crate::NewThread> {
|
|
thread_manager
|
|
.resume_thread_from_rollout_with_user_shell_override_for_tests(
|
|
config,
|
|
rollout_path,
|
|
auth_manager,
|
|
user_shell_override,
|
|
)
|
|
.await
|
|
}
|
|
|
|
pub fn models_manager_with_provider(
|
|
codex_home: PathBuf,
|
|
auth_manager: Arc<AuthManager>,
|
|
provider: ModelProviderInfo,
|
|
) -> SharedModelsManager {
|
|
let provider = create_model_provider(provider, Some(auth_manager));
|
|
provider.models_manager(codex_home, /*config_model_catalog*/ None)
|
|
}
|
|
|
|
pub fn get_model_offline(model: Option<&str>) -> String {
|
|
get_model_offline_for_tests(model)
|
|
}
|
|
|
|
pub fn construct_model_info_offline(model: &str, config: &Config) -> ModelInfo {
|
|
construct_model_info_offline_for_tests(model, &config.to_models_manager_config())
|
|
}
|
|
|
|
pub fn all_model_presets() -> &'static Vec<ModelPreset> {
|
|
&TEST_MODEL_PRESETS
|
|
}
|
|
|
|
pub fn builtin_collaboration_mode_presets() -> Vec<CollaborationModeMask> {
|
|
collaboration_mode_presets::builtin_collaboration_mode_presets()
|
|
}
|