diff --git a/codex-rs/core-plugins/src/lib.rs b/codex-rs/core-plugins/src/lib.rs index c27619b269..eeed69475c 100644 --- a/codex-rs/core-plugins/src/lib.rs +++ b/codex-rs/core-plugins/src/lib.rs @@ -43,6 +43,7 @@ pub use manager::PluginRemoteSyncError; pub use manager::PluginUninstallError; pub use manager::PluginsConfigInput; pub use manager::PluginsManager; +pub use manager::PluginsManagerDeps; pub use manager::RemotePluginSyncResult; pub use marketplace_upgrade::ConfiguredMarketplaceUpgradeError as PluginMarketplaceUpgradeError; pub use marketplace_upgrade::ConfiguredMarketplaceUpgradeOutcome as PluginMarketplaceUpgradeOutcome; diff --git a/codex-rs/core-plugins/src/manager.rs b/codex-rs/core-plugins/src/manager.rs index 5c9af9adff..870ac1f1e0 100644 --- a/codex-rs/core-plugins/src/manager.rs +++ b/codex-rs/core-plugins/src/manager.rs @@ -412,6 +412,26 @@ pub struct PluginsManager { analytics_events_client: RwLock>, } +/// Dependencies owned by one plugins manager. +#[derive(Clone)] +pub struct PluginsManagerDeps { + data_store: Arc, +} + +impl PluginsManagerDeps { + /// Creates dependencies backed by the local Codex Home layout. + pub fn from_codex_home(codex_home: PathBuf) -> Result { + Ok(Self::new(Arc::new(LocalPluginDataStore::from_codex_home( + codex_home, + )?))) + } + + /// Creates dependencies with an alternative mutable plugin data backend. + pub fn new(data_store: Arc) -> Self { + Self { data_store } + } +} + #[derive(Clone)] struct CachedPluginLoadOutcome { config_version: String, @@ -423,34 +443,24 @@ impl PluginsManager { Self::new_with_restriction_product(codex_home, Some(Product::Codex)) } - /// Creates a plugins manager with an alternative mutable plugin data backend. - pub fn new_with_data_store(codex_home: PathBuf, data_store: Arc) -> Self { - Self::new_with_restriction_product_and_data_store( - codex_home, - Some(Product::Codex), - data_store, - ) + /// Creates a plugins manager with injected dependencies. + pub fn new_with_deps(codex_home: PathBuf, deps: PluginsManagerDeps) -> Self { + Self::new_with_restriction_product_and_deps(codex_home, Some(Product::Codex), deps) } pub fn new_with_restriction_product( codex_home: PathBuf, restriction_product: Option, ) -> Self { - let data_store = Arc::new( - LocalPluginDataStore::from_codex_home(codex_home.clone()) - .unwrap_or_else(|err| panic!("plugin data root should be absolute: {err}")), - ); - Self::new_with_restriction_product_and_data_store( - codex_home, - restriction_product, - data_store, - ) + let deps = PluginsManagerDeps::from_codex_home(codex_home.clone()) + .unwrap_or_else(|err| panic!("plugin data root should be absolute: {err}")); + Self::new_with_restriction_product_and_deps(codex_home, restriction_product, deps) } - fn new_with_restriction_product_and_data_store( + fn new_with_restriction_product_and_deps( codex_home: PathBuf, restriction_product: Option, - data_store: Arc, + deps: PluginsManagerDeps, ) -> Self { // Product restrictions are enforced at marketplace admission time for a given CODEX_HOME: // listing, install, and curated refresh all consult this restriction context before new @@ -462,7 +472,7 @@ impl PluginsManager { Self { codex_home: codex_home.clone(), store: PluginStore::new(codex_home), - data_store, + data_store: deps.data_store, featured_plugin_ids_cache: RwLock::new(None), configured_marketplace_upgrade_state: RwLock::new( ConfiguredMarketplaceUpgradeState::default(), diff --git a/codex-rs/core-plugins/src/manager_tests.rs b/codex-rs/core-plugins/src/manager_tests.rs index 6ce6652dc8..aae789cdc5 100644 --- a/codex-rs/core-plugins/src/manager_tests.rs +++ b/codex-rs/core-plugins/src/manager_tests.rs @@ -3915,11 +3915,11 @@ async fn plugins_for_layer_stack_uses_injected_plugin_data_store() { /*remote_plugin_enabled*/ false, "https://chatgpt.com/backend-api/".to_string(), ); - let outcome = PluginsManager::new_with_data_store( + let outcome = PluginsManager::new_with_deps( codex_home.path().to_path_buf(), - Arc::new(FakePluginDataStore { + PluginsManagerDeps::new(Arc::new(FakePluginDataStore { root: data_root.clone(), - }), + })), ) .plugins_for_layer_stack(&stack, &config) .await;