Defer plugin manifest loading until marketplace entries are selected (#61686)

## Why

Marketplace listings read plugin manifests for entries later discarded by policy, product visibility, or duplicate selection across project scopes. This causes unnecessary reads and can emit parse warnings for plugins that never appear in the listing.

## What changed

Separate marketplace entry validation from plugin manifest loading. Apply marketplace policy, visibility, and path and plugin ID deduplication before loading metadata, preserving first-source and first-scope precedence.

## Testing

Add a regression test covering repeated marketplace paths and shadowed plugin IDs across scopes. Verify that the selected malformed manifest is read once, the discarded manifest is never read, and the visible plugin IDs and local versions are preserved.

GitOrigin-RevId: 00b1d50593fb6546aafdc2089e6fccec1b4e5f42
This commit is contained in:
Charlie Marsh
2026-11-15 20:28:25 +00:00
committed by copyberry
parent 5cb38e7984
commit 87fccdc1bc
4 changed files with 330 additions and 170 deletions
@@ -387,6 +387,99 @@ path = {:?}
assert_eq!(blocked_outcome.marketplaces, Vec::new());
}
#[tracing_test::traced_test]
#[tokio::test]
async fn list_marketplaces_skips_manifests_for_discarded_rows_without_changing_precedence() {
let tmp = TempDir::new().unwrap();
let shared = tmp.path().join("a-shared");
let repo = tmp.path().join("b-repo");
write_file(
&shared.join(".agents/plugins/marketplace.json"),
r#"{
"name": "team",
"plugins": [
{"name": "shared", "source": "./shared"},
{"name": "shadowed", "source": "./shadowed", "policy": {"products": []}}
]
}"#,
);
write_file(&shared.join("shared/.codex-plugin/plugin.json"), "{");
write_file(
&repo.join(".agents/plugins/marketplace.json"),
r#"{
"name": "team",
"plugins": [
{"name": "shadowed", "source": "./shadowed"},
{"name": "repo-only", "source": "./repo-only"}
]
}"#,
);
write_file(&repo.join("shadowed/.codex-plugin/plugin.json"), "{");
write_plugin_with_version(&repo, "repo-only", "repo-only", Some("2.0.0"));
write_file(
&tmp.path().join(CONFIG_TOML_FILE),
&format!(
r#"
[features]
plugins = true
[marketplaces.team]
source_type = "local"
source = {shared:?}
"#
),
);
let config = load_config(tmp.path(), &repo).await;
let context = PluginMarketplaceContext {
global_config: config.clone(),
scopes: vec![
PluginMarketplaceScope {
cwd: Some(AbsolutePathBuf::try_from(shared).unwrap()),
config: config.clone(),
},
PluginMarketplaceScope {
cwd: Some(AbsolutePathBuf::try_from(repo).unwrap()),
config,
},
],
load_errors: Vec::new(),
};
let result = test_plugins_manager(tmp.path().to_path_buf())
.list_marketplaces_for_context(&context, /*include_openai_curated*/ false)
.unwrap();
assert_eq!(result.errors, Vec::new());
assert_eq!(
result
.marketplaces
.iter()
.filter(|marketplace| marketplace.name == "team")
.flat_map(|marketplace| &marketplace.plugins)
.map(|plugin| (plugin.id.as_str(), plugin.local_version.as_deref()))
.collect::<Vec<_>>(),
vec![("shared@team", None), ("repo-only@team", Some("2.0.0"))],
);
logs_assert(|lines| {
let reads = lines
.iter()
.filter(|line| {
line.contains("failed to parse plugin manifest") && line.contains("a-shared")
})
.count();
let shadowed_reads = lines
.iter()
.filter(|line| {
line.contains("failed to parse plugin manifest") && line.contains("b-repo")
})
.count();
(reads == 1 && shadowed_reads == 0)
.then_some(())
.ok_or_else(|| {
format!("expected one shared and zero shadowed manifest reads, got {reads} and {shadowed_reads}")
})
});
}
fn write_auth_projection_plugin(codex_home: &Path, name: &str, include_app: bool) {
let plugin_root = codex_home
.join("plugins/cache")