mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +00:00
[codex] [1/4] Add recommended plugin endpoint cache (#28399)
Summary - Add authenticated parsing for `/ps/plugins/suggested?scope=GLOBAL`, including remote plugin and connector app identities. - Validate, deduplicate, sort, and cap endpoint candidates before caching them by backend and account identity. - Deduplicate concurrent cache misses and warm recommendations from the existing remote-installed-plugin refresh path used at startup and after account changes. - Keep endpoint results model-invisible in this PR; failures and responses without `enabled: true` resolve to legacy mode. Stack - 1/3. Follow-up: #28400 generalizes plugin suggestion presentation without activating endpoint recommendations. - Final activation: #27704. Validation - `just test -p codex-core-plugins recommended_plugins` - `just fix -p codex-core-plugins` - `just fmt` - `git diff --check`
This commit is contained in:
1 parent
bd2a786326
commit
7e735b59ce
6 files changed
+695
-11
No files matched your search
@@ -76,3 +76,206 @@ fn directory_plugin(id: &str, name: &str) -> RemotePluginDirectoryItem {
|
||||
},
|
||||
}
|
||||
}
|
||||
fn item(name: &str, display_name: &str) -> RecommendedPluginItem {
|
||||
RecommendedPluginItem {
|
||||
id: format!("plugin_{name}"),
|
||||
name: name.to_string(),
|
||||
status: None,
|
||||
installation_policy: None,
|
||||
release: RecommendedPluginRelease {
|
||||
display_name: display_name.to_string(),
|
||||
app_ids: Vec::new(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recommended_plugins_enabled_flag_selects_endpoint_or_legacy_mode() {
|
||||
let disabled: RecommendedPluginsResponse = serde_json::from_value(serde_json::json!({
|
||||
"enabled": false,
|
||||
"plugins": [{"id": "plugin_github", "name": "github", "release": {"display_name": "GitHub"}}]
|
||||
}))
|
||||
.expect("response should deserialize");
|
||||
assert_eq!(
|
||||
recommended_plugins_mode(disabled),
|
||||
RecommendedPluginsMode::Legacy
|
||||
);
|
||||
|
||||
for response in [
|
||||
serde_json::json!({"plugins": []}),
|
||||
serde_json::json!({"enabled": null, "plugins": []}),
|
||||
] {
|
||||
let response: RecommendedPluginsResponse =
|
||||
serde_json::from_value(response).expect("response should deserialize");
|
||||
assert_eq!(
|
||||
recommended_plugins_mode(response),
|
||||
RecommendedPluginsMode::Legacy
|
||||
);
|
||||
}
|
||||
|
||||
let enabled: RecommendedPluginsResponse = serde_json::from_value(serde_json::json!({
|
||||
"enabled": true,
|
||||
"plugins": []
|
||||
}))
|
||||
.expect("response should deserialize");
|
||||
assert_eq!(
|
||||
recommended_plugins_mode(enabled),
|
||||
RecommendedPluginsMode::Endpoint {
|
||||
plugins: Vec::new()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recommended_plugins_require_remote_install_identity() {
|
||||
let response = serde_json::from_value::<RecommendedPluginsResponse>(serde_json::json!({
|
||||
"enabled": true,
|
||||
"plugins": [{
|
||||
"name": "github",
|
||||
"release": {"display_name": "GitHub"}
|
||||
}]
|
||||
}));
|
||||
|
||||
assert!(response.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recommended_plugins_are_validated_deduplicated_sorted_and_capped() {
|
||||
let mut plugins = (0..=52)
|
||||
.rev()
|
||||
.map(|index| item(&format!("plugin-{index:02}"), &format!("Plugin {index:02}")))
|
||||
.collect::<Vec<_>>();
|
||||
plugins.push(item("plugin-00", "Duplicate"));
|
||||
plugins.push(item("not/a/plugin", "Invalid"));
|
||||
plugins.push(RecommendedPluginItem {
|
||||
id: "plugin_disabled".to_string(),
|
||||
name: "disabled".to_string(),
|
||||
status: Some(PluginAvailability::DisabledByAdmin),
|
||||
installation_policy: Some(PluginInstallPolicy::Available),
|
||||
release: RecommendedPluginRelease {
|
||||
display_name: "Disabled".to_string(),
|
||||
app_ids: Vec::new(),
|
||||
},
|
||||
});
|
||||
plugins.push(RecommendedPluginItem {
|
||||
id: "plugin_not_available".to_string(),
|
||||
name: "not-available".to_string(),
|
||||
status: Some(PluginAvailability::Available),
|
||||
installation_policy: Some(PluginInstallPolicy::NotAvailable),
|
||||
release: RecommendedPluginRelease {
|
||||
display_name: "Not Available".to_string(),
|
||||
app_ids: Vec::new(),
|
||||
},
|
||||
});
|
||||
|
||||
let mode = recommended_plugins_mode(RecommendedPluginsResponse {
|
||||
enabled: Some(true),
|
||||
plugins,
|
||||
});
|
||||
let RecommendedPluginsMode::Endpoint { plugins } = mode else {
|
||||
panic!("expected endpoint mode");
|
||||
};
|
||||
|
||||
assert_eq!(plugins.len(), MAX_RECOMMENDED_PLUGINS);
|
||||
assert_eq!(
|
||||
plugins.first(),
|
||||
Some(&RecommendedPlugin {
|
||||
config_id: "plugin-00@openai-curated-remote".to_string(),
|
||||
remote_plugin_id: "plugin_plugin-00".to_string(),
|
||||
display_name: "Plugin 00".to_string(),
|
||||
app_connector_ids: Vec::new(),
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
plugins.last(),
|
||||
Some(&RecommendedPlugin {
|
||||
config_id: "plugin-49@openai-curated-remote".to_string(),
|
||||
remote_plugin_id: "plugin_plugin-49".to_string(),
|
||||
display_name: "Plugin 49".to_string(),
|
||||
app_connector_ids: Vec::new(),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recommended_plugins_bound_model_visible_fields() {
|
||||
let overlong_name = "n".repeat(MAX_RECOMMENDED_PLUGIN_NAME_LEN + 1);
|
||||
let overlong_display_name = "D".repeat(MAX_RECOMMENDED_PLUGIN_DISPLAY_NAME_LEN + 1);
|
||||
let mode = recommended_plugins_mode(RecommendedPluginsResponse {
|
||||
enabled: Some(true),
|
||||
plugins: vec![
|
||||
item(&overlong_name, "Ignored"),
|
||||
item("bounded", &overlong_display_name),
|
||||
],
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
mode,
|
||||
RecommendedPluginsMode::Endpoint {
|
||||
plugins: vec![RecommendedPlugin {
|
||||
config_id: "bounded@openai-curated-remote".to_string(),
|
||||
remote_plugin_id: "plugin_bounded".to_string(),
|
||||
display_name: "D".repeat(MAX_RECOMMENDED_PLUGIN_DISPLAY_NAME_LEN),
|
||||
app_connector_ids: Vec::new(),
|
||||
}],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recommended_plugins_preserve_install_identity_and_normalize_app_ids() {
|
||||
let mode = recommended_plugins_mode(RecommendedPluginsResponse {
|
||||
enabled: Some(true),
|
||||
plugins: vec![RecommendedPluginItem {
|
||||
id: "plugin_connector_sample".to_string(),
|
||||
name: "sample".to_string(),
|
||||
status: Some(PluginAvailability::Available),
|
||||
installation_policy: Some(PluginInstallPolicy::Available),
|
||||
release: RecommendedPluginRelease {
|
||||
display_name: "Sample".to_string(),
|
||||
app_ids: vec![
|
||||
"connector_one".to_string(),
|
||||
String::new(),
|
||||
"connector_two".to_string(),
|
||||
"connector_one".to_string(),
|
||||
],
|
||||
},
|
||||
}],
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
mode,
|
||||
RecommendedPluginsMode::Endpoint {
|
||||
plugins: vec![RecommendedPlugin {
|
||||
config_id: "sample@openai-curated-remote".to_string(),
|
||||
remote_plugin_id: "plugin_connector_sample".to_string(),
|
||||
display_name: "Sample".to_string(),
|
||||
app_connector_ids: vec!["connector_one".to_string(), "connector_two".to_string(),],
|
||||
}],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recommended_plugins_ignore_invalid_remote_plugin_ids() {
|
||||
let mode = recommended_plugins_mode(RecommendedPluginsResponse {
|
||||
enabled: Some(true),
|
||||
plugins: vec![RecommendedPluginItem {
|
||||
id: "not/a/plugin".to_string(),
|
||||
name: "sample".to_string(),
|
||||
status: None,
|
||||
installation_policy: None,
|
||||
release: RecommendedPluginRelease {
|
||||
display_name: "Sample".to_string(),
|
||||
app_ids: Vec::new(),
|
||||
},
|
||||
}],
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
mode,
|
||||
RecommendedPluginsMode::Endpoint {
|
||||
plugins: Vec::new(),
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user