aKode fase 2b-1: rimossi plugin remoti e share, bundle download, UI usage/crediti/banner/workspace ChatGPT; fix argomenti MCP (inviati vuoti dopo e4209e2) e overlay TUI; test analytics-upload rimossi; test sicurezza MCP adattati
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
This commit is contained in:
@@ -7,38 +7,21 @@ use crate::PluginProviderFuture;
|
||||
use crate::PluginProviders;
|
||||
use crate::PluginsThreadState;
|
||||
use crate::install_plugin_providers;
|
||||
use anyhow::Context;
|
||||
use codex_config::test_support::CloudConfigBundleFixture;
|
||||
use codex_core_plugins::ExecutorPluginProvider;
|
||||
use codex_core_plugins::PluginCatalog;
|
||||
use codex_core_plugins::PluginCatalogEntry;
|
||||
use codex_core_plugins::PluginIdentity;
|
||||
use codex_exec_server::EnvironmentManager;
|
||||
use codex_extension_api::ContextContributor;
|
||||
use codex_extension_api::ExtensionRegistryBuilder;
|
||||
use codex_extension_api::McpServerContributionContext;
|
||||
use codex_extension_api::McpServerContributor;
|
||||
use codex_extension_api::SelectedPluginSnapshot;
|
||||
use codex_extension_api::WorldStateContributionInput;
|
||||
use codex_extension_api::WorldStateSectionContribution;
|
||||
use codex_protocol::capabilities::CapabilityRootLocation;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
use codex_protocol::config_types::CollaborationMode;
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::config_types::Settings;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use core_test_support::apps_test_server::AppsTestServer;
|
||||
use core_test_support::apps_test_server::recorded_apps_tool_calls;
|
||||
use core_test_support::responses;
|
||||
use core_test_support::responses::ev_completed;
|
||||
use core_test_support::responses::ev_function_call_with_namespace;
|
||||
use core_test_support::responses::ev_response_created;
|
||||
use core_test_support::responses::mount_sse_sequence;
|
||||
use core_test_support::responses::sse;
|
||||
use core_test_support::test_codex::run_test_with_large_stack;
|
||||
use core_test_support::test_codex::test_codex;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
@@ -357,40 +340,6 @@ struct CloudProvider {
|
||||
resume_discovery: Notify,
|
||||
}
|
||||
|
||||
type ObservedPackages = Vec<(String, Option<String>)>;
|
||||
|
||||
#[derive(Default)]
|
||||
struct StepPackages(Mutex<Option<ObservedPackages>>);
|
||||
|
||||
impl ContextContributor for StepPackages {
|
||||
fn contribute_world_state<'a>(
|
||||
&'a self,
|
||||
input: WorldStateContributionInput<'a>,
|
||||
) -> ExtensionFuture<'a, Vec<WorldStateSectionContribution>> {
|
||||
Box::pin(async move {
|
||||
*self
|
||||
.0
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) = input
|
||||
.thread_store
|
||||
.get::<SelectedPluginSnapshot>()
|
||||
.map(|snapshot| {
|
||||
snapshot
|
||||
.plugins
|
||||
.iter()
|
||||
.map(|plugin| {
|
||||
(
|
||||
plugin.plugin_id.as_str().to_string(),
|
||||
plugin.selected_root_id.clone(),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
Vec::new()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CloudProvider {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -455,420 +404,3 @@ fn cloud_catalog() -> PluginCatalog {
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn app_tool(connector: &str, action: &str) -> serde_json::Value {
|
||||
json!({
|
||||
"name": format!("{connector}_{action}"),
|
||||
"description": format!("Run {action} in {connector}."),
|
||||
"annotations": {"readOnlyHint": true},
|
||||
"inputSchema": {"type": "object", "properties": {}, "additionalProperties": false},
|
||||
"_meta": {
|
||||
"connector_id": connector,
|
||||
"connector_name": connector,
|
||||
"_codex_apps": {
|
||||
"resource_uri": format!("connector://{connector}/tools/{connector}_{action}"),
|
||||
"contains_mcp_source": true,
|
||||
"connector_id": connector,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cloud_catalog_refreshes_per_turn_and_invalidates_on_auth_change() -> anyhow::Result<()> {
|
||||
run_test_with_large_stack(
|
||||
"cloud-plugin-lifecycle",
|
||||
run_cloud_catalog_refresh_lifecycle,
|
||||
)
|
||||
}
|
||||
|
||||
async fn run_cloud_catalog_refresh_lifecycle() -> anyhow::Result<()> {
|
||||
core_test_support::skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
// Each account has a fixed inventory; only the auth switch changes the server's tools.
|
||||
let apps_tools = Arc::new(Mutex::new(vec![app_tool("calendar", "list_events")]));
|
||||
let apps_server = AppsTestServer::mount_with_tools(&server, apps_tools.clone()).await?;
|
||||
let mut gmail_catalog = cloud_catalog();
|
||||
gmail_catalog.entries[0].id = PluginIdentity::Remote {
|
||||
remote_plugin_id: "plugin_gmail".to_string(),
|
||||
};
|
||||
gmail_catalog.entries[0].display_name = "Gmail Demo".to_string();
|
||||
gmail_catalog.entries[0].connector_ids = vec!["gmail".to_string()];
|
||||
let mut disabled_catalog = cloud_catalog();
|
||||
disabled_catalog.entries[0].enabled = false;
|
||||
let mut partial_catalog = gmail_catalog.clone();
|
||||
partial_catalog.is_partial = true;
|
||||
let partial_empty_catalog = PluginCatalog {
|
||||
is_partial: true,
|
||||
warnings: vec!["resource listing was truncated".to_string()],
|
||||
..Default::default()
|
||||
};
|
||||
let provider = Arc::new(CloudProvider::default());
|
||||
let step_packages = Arc::new(StepPackages::default());
|
||||
let mut extensions = ExtensionRegistryBuilder::new();
|
||||
crate::install(&mut extensions);
|
||||
extensions.prompt_contributor(step_packages.clone());
|
||||
install_plugin_providers(
|
||||
&mut extensions,
|
||||
PluginProviders::new(Arc::new(ExecutorPluginProvider::new(Arc::new(
|
||||
EnvironmentManager::default_for_tests(),
|
||||
))))
|
||||
.with_cloud_provider(provider.clone()),
|
||||
);
|
||||
let mut builder = test_codex()
|
||||
.with_cloud_config_bundle(
|
||||
CloudConfigBundleFixture::enterprise_config(
|
||||
"[mcp_servers.codex_apps]\nurl = 'https://example.com/custom'",
|
||||
)
|
||||
.add_enterprise_requirement("[mcp_servers]")
|
||||
.into_loader(),
|
||||
)
|
||||
.with_exec_server_url("none")
|
||||
.with_extensions(Arc::new(extensions.build()))
|
||||
.with_auth(codex_login::CodexAuth::from_external_chatgpt_tokens(
|
||||
"header.e30.initial",
|
||||
"account-a",
|
||||
/*chatgpt_plan_type*/ None,
|
||||
)?)
|
||||
.with_model_info_override("gpt-5.5", |model| {
|
||||
model.supports_search_tool = false;
|
||||
})
|
||||
.with_config(move |config| {
|
||||
config
|
||||
.features
|
||||
.enable(Feature::Plugins)
|
||||
.expect("enable plugins in fixture");
|
||||
config
|
||||
.features
|
||||
.enable(Feature::Apps)
|
||||
.expect("enable apps in fixture");
|
||||
config.chatgpt_base_url = apps_server.chatgpt_base_url;
|
||||
});
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
assert!(!test.config.mcp_servers.get()[codex_mcp::CODEX_APPS_MCP_SERVER_NAME].enabled);
|
||||
let calendar = ("calendar", "list_events", "Cloud Demo");
|
||||
let gmail = ("gmail", "search_email", "Gmail Demo");
|
||||
for (turn, reply, expected_plugin, new_account, tool_call) in [
|
||||
(
|
||||
"initial-partial",
|
||||
Ok(partial_catalog.clone()),
|
||||
Some("plugin_gmail"),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"partial-replaces-partial",
|
||||
Ok(PluginCatalog {
|
||||
is_partial: true,
|
||||
..cloud_catalog()
|
||||
}),
|
||||
Some("plugin_remote"),
|
||||
None,
|
||||
Some(calendar),
|
||||
),
|
||||
(
|
||||
"partial-empty-replaces-partial",
|
||||
Ok(partial_empty_catalog.clone()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"empty",
|
||||
Ok(PluginCatalog::default()),
|
||||
None,
|
||||
None,
|
||||
Some(calendar),
|
||||
),
|
||||
(
|
||||
"partial-after-complete-empty",
|
||||
Ok(partial_catalog.clone()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"discovered",
|
||||
Ok(cloud_catalog()),
|
||||
Some("plugin_remote"),
|
||||
None,
|
||||
Some(calendar),
|
||||
),
|
||||
(
|
||||
"partial-refresh",
|
||||
Ok(partial_catalog.clone()),
|
||||
Some("plugin_remote"),
|
||||
None,
|
||||
Some(calendar),
|
||||
),
|
||||
(
|
||||
"partial-empty-refresh",
|
||||
Ok(partial_empty_catalog),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"same-account-failure",
|
||||
Err("temporarily unavailable".to_string()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"complete-with-warning-disables-plugin",
|
||||
Ok(PluginCatalog {
|
||||
warnings: vec!["optional bundle hint ignored".to_string()],
|
||||
..disabled_catalog
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"partial-after-disable",
|
||||
Ok(partial_catalog.clone()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"re-enabled",
|
||||
Ok(cloud_catalog()),
|
||||
Some("plugin_remote"),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
("removed", Ok(PluginCatalog::default()), None, None, None),
|
||||
(
|
||||
"restored",
|
||||
Ok(cloud_catalog()),
|
||||
Some("plugin_remote"),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(
|
||||
"auth-changed-failure",
|
||||
Err("unavailable after auth changed".to_string()),
|
||||
None,
|
||||
Some("account-b"),
|
||||
None,
|
||||
),
|
||||
(
|
||||
"new-account-partial",
|
||||
Ok(partial_catalog),
|
||||
Some("plugin_gmail"),
|
||||
None,
|
||||
Some(gmail),
|
||||
),
|
||||
(
|
||||
"new-account-discovered",
|
||||
Ok(gmail_catalog),
|
||||
Some("plugin_gmail"),
|
||||
None,
|
||||
Some(gmail),
|
||||
),
|
||||
(
|
||||
"in-flight-auth-change",
|
||||
Ok(cloud_catalog()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
] {
|
||||
let previous_discoveries = provider.calls.load(Ordering::SeqCst);
|
||||
let retry_discovery = turn == "in-flight-auth-change";
|
||||
if let Some(account) = new_account {
|
||||
// Do not manually refresh MCP: the auth transition must pick up this new inventory.
|
||||
*apps_tools
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) =
|
||||
vec![app_tool("gmail", "search_email")];
|
||||
let resources = provider
|
||||
.resources
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.clone()
|
||||
.context("cloud provider resource client missing")?;
|
||||
let previous_auth =
|
||||
resources.auth_cache_key_for_server(codex_mcp::CODEX_APPS_MCP_SERVER_NAME);
|
||||
codex_login::auth::login_with_chatgpt_auth_tokens(
|
||||
test.codex_home_path(),
|
||||
"header.e30.changed",
|
||||
account,
|
||||
/*chatgpt_plan_type*/ None,
|
||||
)?;
|
||||
test.thread_manager.auth_manager().reload().await;
|
||||
tokio::time::timeout(std::time::Duration::from_secs(10), async {
|
||||
loop {
|
||||
if resources.auth_cache_key_for_server(codex_mcp::CODEX_APPS_MCP_SERVER_NAME)
|
||||
!= previous_auth
|
||||
&& test
|
||||
.codex
|
||||
.thread_extension_data()
|
||||
.get::<SelectedPluginSnapshot>()
|
||||
.is_some_and(|snapshot| snapshot.plugins.is_empty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(provider.calls.load(Ordering::SeqCst), previous_discoveries);
|
||||
}
|
||||
if matches!(
|
||||
turn,
|
||||
"complete-with-warning-disables-plugin" | "new-account-partial"
|
||||
) {
|
||||
// Reconnecting permits recovery before the thread's cooldown expires.
|
||||
test.codex
|
||||
.submit(codex_protocol::protocol::Op::RefreshMcpServers)
|
||||
.await?;
|
||||
}
|
||||
provider.set_reply(reply);
|
||||
let previous_calls = recorded_apps_tool_calls(&server).await.len();
|
||||
let call_id = format!("{turn}-call");
|
||||
let mut events = vec![ev_response_created("resp")];
|
||||
if let Some((connector, action, _)) = tool_call {
|
||||
events.push(ev_function_call_with_namespace(
|
||||
&call_id,
|
||||
&format!("mcp__codex_apps__{connector}"),
|
||||
&format!("_{action}"),
|
||||
"{}",
|
||||
));
|
||||
}
|
||||
events.push(ev_completed("resp"));
|
||||
let mut responses = vec![sse(events)];
|
||||
if tool_call.is_some() {
|
||||
responses.push(sse(vec![
|
||||
ev_response_created("after-tool"),
|
||||
ev_completed("after-tool"),
|
||||
]));
|
||||
}
|
||||
let response = mount_sse_sequence(&server, responses).await;
|
||||
*step_packages
|
||||
.0
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) = None;
|
||||
if turn == "in-flight-auth-change" {
|
||||
provider.pause_discovery.store(true, Ordering::SeqCst);
|
||||
tokio::time::timeout(Duration::from_secs(/*secs*/ 10), async {
|
||||
tokio::try_join!(
|
||||
test.submit_turn("What capabilities are available?"),
|
||||
async {
|
||||
provider.discovery_started.notified().await;
|
||||
let resources = provider
|
||||
.resources
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.clone()
|
||||
.context("cloud provider resource client missing")?;
|
||||
let previous_auth = resources
|
||||
.auth_cache_key_for_server(codex_mcp::CODEX_APPS_MCP_SERVER_NAME);
|
||||
// Rotate credentials without replacing the captured runtime/client.
|
||||
codex_login::auth::login_with_chatgpt_auth_tokens(
|
||||
test.codex_home_path(),
|
||||
"header.e30.rotated",
|
||||
"account-b",
|
||||
/*chatgpt_plan_type*/ None,
|
||||
)?;
|
||||
test.thread_manager.auth_manager().reload().await;
|
||||
// Auth must be published while cloud discovery remains paused.
|
||||
while resources
|
||||
.auth_cache_key_for_server(codex_mcp::CODEX_APPS_MCP_SERVER_NAME)
|
||||
== previous_auth
|
||||
{
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
provider.set_reply(Err("new-scope discovery failed".to_string()));
|
||||
provider.resume_discovery.notify_one();
|
||||
anyhow::Ok(())
|
||||
}
|
||||
)
|
||||
})
|
||||
.await??;
|
||||
// Refresh under the new auth without retaining the old catalog.
|
||||
let state = test
|
||||
.codex
|
||||
.thread_extension_data()
|
||||
.get::<PluginsThreadState>()
|
||||
.context("plugin state missing")?;
|
||||
assert_eq!(state.cloud_catalog(), None);
|
||||
assert_eq!(
|
||||
state
|
||||
.contributor_state()
|
||||
.cloud_generation
|
||||
.as_ref()
|
||||
.and_then(|generation| generation.catalog.clone()),
|
||||
None,
|
||||
);
|
||||
} else {
|
||||
test.submit_turn("What capabilities are available?").await?;
|
||||
}
|
||||
let requests = response.requests();
|
||||
let request = &requests[0];
|
||||
if let Some((connector, action, plugin_name)) = tool_call {
|
||||
assert_eq!(requests.len(), 2);
|
||||
let calls = recorded_apps_tool_calls(&server).await;
|
||||
let output = requests[1].function_call_output(&call_id);
|
||||
assert_eq!(calls.len(), previous_calls + 1, "turn {turn}: {output}");
|
||||
let call = calls.last().context("expected an Apps tool call")?;
|
||||
assert_eq!(
|
||||
call["params"]["name"],
|
||||
json!(format!("{connector}_{action}"))
|
||||
);
|
||||
assert_eq!(call["params"]["arguments"], json!({}));
|
||||
let (other_namespace, other_tool) = if connector == "calendar" {
|
||||
("mcp__codex_apps__gmail", "_search_email")
|
||||
} else {
|
||||
("mcp__codex_apps__calendar", "_list_events")
|
||||
};
|
||||
assert!(request.tool_by_name(other_namespace, other_tool).is_none());
|
||||
let tool = request
|
||||
.tool_by_name(
|
||||
&format!("mcp__codex_apps__{connector}"),
|
||||
&format!("_{action}"),
|
||||
)
|
||||
.expect("the current account's tool should be advertised");
|
||||
assert_eq!(
|
||||
tool["description"]
|
||||
.as_str()
|
||||
.context("tool description missing")?
|
||||
.contains(plugin_name),
|
||||
expected_plugin.is_some(),
|
||||
"cloud discovery should attribute tools to the current account's plugin"
|
||||
);
|
||||
// The server echoes this URI in its result; it must reach the next model step.
|
||||
assert!(
|
||||
output["output"]
|
||||
.as_str()
|
||||
.context("tool output missing")?
|
||||
.contains(&format!(
|
||||
"connector://{connector}/tools/{connector}_{action}"
|
||||
)),
|
||||
"turn {turn}: {output}"
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
*step_packages
|
||||
.0
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner),
|
||||
Some(
|
||||
expected_plugin
|
||||
.into_iter()
|
||||
.map(|id| (id.to_owned(), None))
|
||||
.collect()
|
||||
),
|
||||
"turn {turn}"
|
||||
);
|
||||
assert_eq!(
|
||||
provider.calls.load(Ordering::SeqCst),
|
||||
previous_discoveries + 1 + if retry_discovery { requests.len() } else { 0 },
|
||||
"turn {turn}"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user