polish plugin storage deps seam

This commit is contained in:
starr-openai
2026-06-03 10:52:23 -07:00
parent b611fd3101
commit 15efda4129
3 changed files with 33 additions and 22 deletions
+1
View File
@@ -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;
+29 -19
View File
@@ -412,6 +412,26 @@ pub struct PluginsManager {
analytics_events_client: RwLock<Option<AnalyticsEventsClient>>,
}
/// Dependencies owned by one plugins manager.
#[derive(Clone)]
pub struct PluginsManagerDeps {
data_store: Arc<dyn PluginDataStore>,
}
impl PluginsManagerDeps {
/// Creates dependencies backed by the local Codex Home layout.
pub fn from_codex_home(codex_home: PathBuf) -> Result<Self, PluginStoreError> {
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<dyn PluginDataStore>) -> 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<dyn PluginDataStore>) -> 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<Product>,
) -> 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<Product>,
data_store: Arc<dyn PluginDataStore>,
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(),
+3 -3
View File
@@ -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;