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

This commit is contained in:
Andrea
2026-11-09 16:24:36 +01:00
parent 0de669e9ce
commit 981745ccc8
190 changed files with 313 additions and 9756 deletions

View File

@@ -430,262 +430,6 @@ async fn fixed_thread_text_supersedes_the_live_provider_and_isolated_helpers_rej
}
}
#[test_case::test_case(None, "chatgpt.com", 1; "ordinary_openai")]
#[test_case::test_case(Some(codex_features::RuntimeAuthMode::DualHeader), "chatgpt.com", 0; "dual_header_openai")]
#[test_case::test_case(Some(codex_features::RuntimeAuthMode::AssertionOnly), "chatgpt.com", 0; "assertion_only_openai")]
#[test_case::test_case(Some(codex_features::RuntimeAuthMode::DualHeader), "example.test", 1; "dual_header_custom_backend")]
#[test_case::test_case(Some(codex_features::RuntimeAuthMode::AssertionOnly), "example.test", 1; "assertion_only_custom_backend")]
#[tokio::test]
async fn resumed_analytics_validates_openai_destination(
mode: Option<codex_features::RuntimeAuthMode>,
host: &str,
expected_requests: usize,
) {
let proxy = MockServer::start().await;
wiremock::Mock::given(wiremock::matchers::path("/codex/analytics-events/events"))
.respond_with(wiremock::ResponseTemplate::new(200))
.mount(&proxy)
.await;
let home = tempdir().expect("tempdir");
let mut config = test_config().await;
config.codex_home = home.path().abs();
config.cwd = home.path().abs();
config.chatgpt_base_url = format!("http://{host}:{}", proxy.address().port());
config.model_provider.base_url = Some(proxy.uri());
config.respect_system_proxy = true;
config.cli_auth_credentials_store_mode = codex_login::AuthCredentialsStoreMode::File;
config.analytics_enabled = Some(true);
if let Some(mode) = mode {
config
.features
.enable(Feature::RuntimeAgentInstances)
.unwrap();
config.runtime_auth_mode = mode;
} else {
config
.features
.disable(Feature::RuntimeAgentInstances)
.unwrap();
}
codex_http_client::cache_system_proxy_route_for_test(
&format!("{}/codex/analytics-events/events", config.chatgpt_base_url),
proxy.uri(),
);
codex_login::login_with_api_key(
&config.codex_home,
"resumed-key",
codex_login::AuthCredentialsStoreMode::File,
codex_login::AuthKeyringBackendKind::default(),
)
.unwrap();
let resumed_auth =
AuthManager::shared_from_config(&config, /*enable_codex_api_key_env*/ false)
.await
.unwrap();
let original_auth = CodexAuth::from_api_key("startup-key");
let mut manager = ThreadManager::with_models_provider_and_home_for_tests(
original_auth.clone(),
config.model_provider.clone(),
config.codex_home.to_path_buf(),
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
);
let startup_analytics = AnalyticsEventsClient::new(
AuthManager::from_auth_for_testing(original_auth),
proxy.uri(),
/*analytics_enabled*/ Some(true),
);
Arc::get_mut(&mut manager.state)
.expect("unshared thread manager state")
.analytics_events_client = Some(startup_analytics);
let original = manager
.start_thread(StartThreadOptions {
history_mode: Some(ThreadHistoryMode::Legacy),
..StartThreadOptions::new(config.clone())
})
.await
.expect("start original thread");
original.thread.ensure_rollout_materialized().await;
original.thread.flush_rollout().await.unwrap();
original.thread.shutdown_and_wait().await.unwrap();
manager.remove_thread(&original.thread_id).await;
let resumed = manager
.resume_thread_with_history(
config,
InitialHistory::Resumed(ResumedHistory {
history_revision: None,
conversation_id: original.thread_id,
history: Arc::new(Vec::new()),
rollout_path: original.thread.rollout_path(),
}),
resumed_auth,
/*parent_trace*/ None,
ClientMcpExtensions::default(),
)
.await
.expect("resume with another auth owner");
let analytics = &resumed.thread.session.services.analytics_events_client;
analytics.track_plugin_used(
codex_analytics::TrackEventsContext {
turn_metadata: None,
model_slug: "test-model".to_string(),
turn_id: "test-turn".to_string(),
thread_id: resumed.thread_id.to_string(),
product_client_id: "codex_work_cca".to_string(),
},
codex_plugin::PluginTelemetryMetadata {
plugin_id: Some(codex_plugin::PluginId::parse("test@local").expect("valid plugin ID")),
remote_plugin_id: None,
capability_summary: None,
},
);
analytics.flush().await;
resumed.thread.shutdown_and_wait().await.unwrap();
let requests: Vec<_> = proxy
.received_requests()
.await
.unwrap()
.into_iter()
.filter(|request| request.url.path() == "/codex/analytics-events/events")
.collect();
assert_eq!(requests.len(), expected_requests);
for request in requests {
assert_eq!(request.headers["authorization"], "Bearer resumed-key");
assert!(!request.headers.contains_key("x-openai-agent-assertion"));
}
}
/// A thread opt-out wins over a shared client without disabling its siblings.
#[tokio::test]
async fn thread_analytics_opt_out_overrides_shared_client() {
let server = MockServer::start().await;
wiremock::Mock::given(wiremock::matchers::method("POST"))
.and(wiremock::matchers::path("/codex/analytics-events/events"))
.respond_with(wiremock::ResponseTemplate::new(200))
.mount(&server)
.await;
let temp_dir = tempdir().expect("tempdir");
let mut config = test_config().await;
config.chatgpt_base_url = server.uri();
config.model_provider.base_url = Some(server.uri());
let auth = CodexAuth::create_dummy_chatgpt_auth_for_testing();
let shared_client = AnalyticsEventsClient::new(
AuthManager::from_auth_for_testing(auth.clone()),
server.uri(),
/*analytics_enabled*/ Some(true),
);
let mut expected_thread_ids = Vec::new();
let mut opted_out_thread_ids = Vec::new();
for (name, client_override, expected_enabled) in [
(
"enabled_override",
Some(shared_client.clone()),
[false, true, true],
),
(
"disabled_override",
Some(AnalyticsEventsClient::disabled()),
[false, false, false],
),
("no_override", None, [false, true, true]),
] {
config.codex_home = temp_dir.path().join(name).abs();
config.cwd = config.codex_home.abs();
std::fs::create_dir_all(&config.codex_home).expect("create codex home");
let mut manager = ThreadManager::with_models_provider_and_home_for_tests(
auth.clone(),
config.model_provider.clone(),
config.codex_home.to_path_buf(),
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
);
Arc::get_mut(&mut manager.state)
.expect("unshared thread manager state")
.analytics_events_client = client_override;
for (setting, enabled) in [Some(false), Some(true), None]
.into_iter()
.zip(expected_enabled)
{
config.analytics_enabled = setting;
let started = manager
.start_thread(StartThreadOptions::new(config.clone()))
.await
.expect("start analytics test thread");
let services = &started.thread.session.services;
assert_eq!(started.thread.analytics_enabled(), enabled);
assert_eq!(
services
.session_extension_data
.get::<AnalyticsEventsClient>()
.expect("analytics client in session store")
.is_enabled(),
enabled,
);
let thread_id = started.thread_id.to_string();
if enabled {
expected_thread_ids.push(thread_id.clone());
} else {
opted_out_thread_ids.push(thread_id.clone());
}
services.analytics_events_client.track_app_used(
codex_analytics::TrackEventsContext {
turn_metadata: None,
model_slug: "test-model".to_string(),
turn_id: format!("test-turn-{thread_id}"),
thread_id,
product_client_id: "codex_work_cca".to_string(),
},
codex_analytics::AppInvocation {
connector_id: Some("test-connector".to_string()),
app_name: None,
invocation_type: None,
},
/*elicitation_type*/ None,
);
services.analytics_events_client.flush().await;
}
let shutdown = manager
.shutdown_all_threads_bounded(Duration::from_secs(10))
.await;
assert_eq!(shutdown.completed.len(), 3);
}
let events: Vec<serde_json::Value> = server
.received_requests()
.await
.expect("analytics requests")
.into_iter()
.filter(|request| request.url.path() == "/codex/analytics-events/events")
.flat_map(|request| {
request.body_json::<serde_json::Value>().expect("JSON body")["events"]
.as_array()
.expect("events array")
.clone()
})
.collect();
assert!(events.iter().all(|event| {
!opted_out_thread_ids
.iter()
.any(|thread_id| event["event_params"]["thread_id"] == thread_id.as_str())
}));
let mut actual_thread_ids: Vec<String> = events
.iter()
.filter(|event| event["event_type"] == "codex_app_used")
.map(|event| {
event["event_params"]["thread_id"]
.as_str()
.expect("app usage thread ID")
.to_string()
})
.collect();
actual_thread_ids.sort();
expected_thread_ids.sort();
assert_eq!(actual_thread_ids, expected_thread_ids);
}
/// Controls without a custom allocation policy still produce distinct thread identifiers.
#[test]
fn thread_id_generator_defaults_to_standard_ids() {
@@ -2196,11 +1940,11 @@ async fn start_thread_seeds_extension_data_for_mcp_and_lifecycle_contributors()
.expect("thread-scoped MCP resolution should identify its source")
.clone(),
));
let mut server = codex_mcp::codex_apps_mcp_server_config(
"https://selected.invalid",
/*apps_mcp_product_sku*/ None,
/*originator*/ None,
);
let mut server: codex_config::McpServerConfig =
serde_json::from_value(serde_json::json!({
"url": "https://selected.invalid/mcp",
}))
.expect("valid MCP server config");
let CapabilityRootLocation::Environment { environment_id, .. } =
&selected_root.location;
let source_environment_id = environment_id.clone();
@@ -2414,20 +2158,10 @@ async fn start_thread_seeds_extension_data_for_mcp_and_lifecycle_contributors()
));
assert_eq!(Some(server), expected.build().server(name));
}
let codex_apps_server = codex_mcp::configured_mcp_servers(&first_resolved.config)
.remove(codex_mcp::CODEX_APPS_MCP_SERVER_NAME)
.expect("Codex Apps server should be configured");
let codex_apps_headers = match codex_apps_server.transport {
codex_config::McpServerTransportConfig::StreamableHttp { http_headers, .. } => http_headers,
codex_config::McpServerTransportConfig::Stdio { .. } => {
panic!("Codex Apps server should use streamable HTTP")
}
};
assert_eq!(
codex_apps_headers
.expect("Codex Apps headers should be configured")
.get("originator"),
Some(&"codex_work_desktop".to_string())
// aKode never contributes the ChatGPT-hosted Codex Apps server.
assert!(
!codex_mcp::configured_mcp_servers(&first_resolved.config)
.contains_key(codex_mcp::CODEX_APPS_MCP_SERVER_NAME)
);
for (policy, disabled_plugin_ids, selected_enabled, expected_mcp_loads) in [
("", vec!["plugin-selected-a".to_string()], false, 1),