aKode fase 2c: eliminato il codice di invio dati (crate analytics, otel-trace-websocket, sentry, esportatori OTLP); /feedback salva solo in locale; chiavi legacy [analytics]/[otel] accettate e ignorate; test di analytics/OTLP/upload rimossi
Some checks failed
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
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
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 18:45:41 +01:00
parent 981745ccc8
commit 60532b6337
509 changed files with 2043 additions and 46606 deletions

View File

@@ -9,9 +9,7 @@ use std::time::Duration;
use anyhow::Result;
use anyhow::bail;
use app_test_support::ChatGptAuthFixture;
use app_test_support::DEFAULT_CLIENT_NAME;
use app_test_support::TestAppServer;
use app_test_support::start_analytics_events_server;
use app_test_support::write_chatgpt_auth;
use axum::Json;
use axum::Router;
@@ -565,12 +563,11 @@ async fn plugin_install_rejects_invalid_remote_plugin_name() -> Result<()> {
}
#[tokio::test]
async fn plugin_install_tracks_analytics_when_remote_detail_fetch_fails() -> Result<()> {
async fn plugin_install_reports_remote_detail_fetch_failure() -> Result<()> {
let codex_home = TempDir::new()?;
let server = MockServer::start().await;
configure_remote_plugin_test(codex_home.path(), &server)?;
mount_empty_remote_installed_plugins(&server).await;
mount_backend_analytics_events(&server).await;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
@@ -587,27 +584,11 @@ async fn plugin_install_tracks_analytics_when_remote_detail_fetch_fails() -> Res
assert_eq!(err.error.code, -32600);
assert!(err.error.message.contains("failed with status 404"));
let payload = wait_for_plugin_analytics_payload(&server, "codex_plugin_install_failed").await?;
let event_params = &payload["events"][0]["event_params"];
assert_eq!(
payload["events"][0]["event_type"],
"codex_plugin_install_failed"
);
assert_eq!(event_params["plugin_id"], json!(null));
assert_eq!(event_params["remote_plugin_id"], REMOTE_PLUGIN_ID);
assert_eq!(event_params["plugin_name"], json!(null));
assert_eq!(event_params["marketplace_name"], json!(null));
assert_eq!(event_params["source"], "manual");
assert_eq!(
event_params["error_type"],
"remote_catalog_unexpected_status"
);
assert_eq!(event_params["sub_error_type"], "http_404");
Ok(())
}
#[tokio::test]
async fn plugin_install_tracks_analytics_when_remote_install_is_rate_limited() -> Result<()> {
async fn plugin_install_reports_rate_limited_remote_install() -> Result<()> {
let codex_home = TempDir::new()?;
let server = MockServer::start().await;
let bundle_url = mount_remote_plugin_bundle(
@@ -628,7 +609,6 @@ async fn plugin_install_tracks_analytics_when_remote_install_is_rate_limited() -
.respond_with(ResponseTemplate::new(/*status_code*/ 429).set_body_string("rate limited"))
.mount(&server)
.await;
mount_backend_analytics_events(&server).await;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
@@ -659,21 +639,6 @@ async fn plugin_install_tracks_analytics_when_remote_install_is_rate_limited() -
/*expected_count*/ 1,
)
.await?;
let payload = wait_for_plugin_analytics_payload(&server, "codex_plugin_install_failed").await?;
let event_params = &payload["events"][0]["event_params"];
assert_eq!(
payload["events"][0]["event_type"],
"codex_plugin_install_failed"
);
assert_eq!(event_params["plugin_id"], "linear@openai-curated-remote");
assert_eq!(event_params["remote_plugin_id"], REMOTE_PLUGIN_ID);
assert_eq!(event_params["marketplace_name"], "openai-curated-remote");
assert_eq!(event_params["source"], "manual");
assert_eq!(
event_params["error_type"],
"remote_catalog_unexpected_status"
);
assert_eq!(event_params["sub_error_type"], "http_429");
Ok(())
}
@@ -697,7 +662,6 @@ async fn plugin_install_rejects_remote_plugin_disabled_by_admin_before_download(
)
.await;
mount_empty_remote_installed_plugins(&server).await;
mount_backend_analytics_events(&server).await;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
@@ -734,16 +698,6 @@ async fn plugin_install_rejects_remote_plugin_disabled_by_admin_before_download(
.join("plugins/cache/openai-curated-remote/linear")
.exists()
);
let payload = wait_for_plugin_analytics_payload(&server, "codex_plugin_install_failed").await?;
let event_params = &payload["events"][0]["event_params"];
assert_eq!(
payload["events"][0]["event_type"],
"codex_plugin_install_failed"
);
assert_eq!(event_params["plugin_id"], "linear@openai-curated-remote");
assert_eq!(event_params["remote_plugin_id"], REMOTE_PLUGIN_ID);
assert_eq!(event_params["error_type"], "remote_plugin_not_available");
assert_eq!(event_params["sub_error_type"], "disabled_by_admin");
Ok(())
}
@@ -760,7 +714,6 @@ async fn plugin_install_rejects_remote_plugin_not_available() -> Result<()> {
)
.await;
mount_empty_remote_installed_plugins(&server).await;
mount_backend_analytics_events(&server).await;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
@@ -783,19 +736,6 @@ async fn plugin_install_rejects_remote_plugin_not_available() -> Result<()> {
/*expected_count*/ 0,
)
.await?;
let payload = wait_for_plugin_analytics_payload(&server, "codex_plugin_install_failed").await?;
let event_params = &payload["events"][0]["event_params"];
assert_eq!(
payload["events"][0]["event_type"],
"codex_plugin_install_failed"
);
assert_eq!(event_params["plugin_id"], "linear@openai-curated-remote");
assert_eq!(event_params["remote_plugin_id"], REMOTE_PLUGIN_ID);
assert_eq!(event_params["error_type"], "remote_plugin_not_available");
assert_eq!(
event_params["sub_error_type"],
"install_policy_not_available"
);
Ok(())
}
@@ -831,18 +771,8 @@ async fn plugin_install_returns_invalid_request_for_missing_marketplace_file() -
}
#[tokio::test]
async fn plugin_install_tracks_analytics_when_marketplace_file_cannot_be_read() -> Result<()> {
let analytics_server = start_analytics_events_server().await?;
async fn plugin_install_reports_unreadable_marketplace_file() -> Result<()> {
let codex_home = TempDir::new()?;
write_analytics_config(codex_home.path(), &analytics_server.uri())?;
write_chatgpt_auth(
codex_home.path(),
ChatGptAuthFixture::new("chatgpt-token")
.account_id("account-123")
.chatgpt_user_id("user-123")
.chatgpt_account_id("account-123"),
AuthCredentialsStoreMode::File,
)?;
let marketplace_path = codex_home.path().join("marketplace-dir");
std::fs::create_dir_all(&marketplace_path)?;
@@ -872,20 +802,6 @@ async fn plugin_install_tracks_analytics_when_marketplace_file_cannot_be_read()
.contains("failed to read marketplace file")
);
let payload =
wait_for_plugin_analytics_payload(&analytics_server, "codex_plugin_install_failed").await?;
let event_params = &payload["events"][0]["event_params"];
assert_eq!(
payload["events"][0]["event_type"],
"codex_plugin_install_failed"
);
assert_eq!(event_params["plugin_id"], json!(null));
assert_eq!(event_params["remote_plugin_id"], json!(null));
assert_eq!(event_params["error_type"], "marketplace_io");
assert_eq!(
event_params["sub_error_type"],
"failed_to_read_marketplace_file"
);
Ok(())
}
@@ -984,85 +900,8 @@ async fn plugin_install_returns_invalid_request_for_disallowed_product_plugin()
}
#[tokio::test]
async fn plugin_install_tracks_analytics_event() -> Result<()> {
let analytics_server = start_analytics_events_server().await?;
async fn plugin_install_rejects_missing_local_plugin_source() -> Result<()> {
let codex_home = TempDir::new()?;
write_analytics_config(codex_home.path(), &analytics_server.uri())?;
write_chatgpt_auth(
codex_home.path(),
ChatGptAuthFixture::new("chatgpt-token")
.account_id("account-123")
.chatgpt_user_id("user-123")
.chatgpt_account_id("account-123"),
AuthCredentialsStoreMode::File,
)?;
let repo_root = TempDir::new()?;
write_plugin_marketplace(
repo_root.path(),
"debug",
"sample-plugin",
"./sample-plugin",
/*install_policy*/ None,
/*auth_policy*/ None,
)?;
write_plugin_source(repo_root.path(), "sample-plugin", &[])?;
let marketplace_path =
AbsolutePathBuf::try_from(repo_root.path().join(".agents/plugins/marketplace.json"))?;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
.build_initialized_with_timeout(DEFAULT_TIMEOUT)
.await?;
let request_id = mcp
.send_plugin_install_request(PluginInstallParams {
marketplace_path: Some(marketplace_path),
remote_marketplace_name: None,
install_attempt_id: None,
plugin_name: "sample-plugin".to_string(),
})
.await?;
let response: PluginInstallResponse =
timeout(DEFAULT_TIMEOUT, mcp.read_response(request_id)).await??;
assert_eq!(response.apps_needing_auth, Vec::<AppSummary>::new());
let payload =
wait_for_plugin_analytics_payload(&analytics_server, "codex_plugin_installed").await?;
assert_eq!(
payload,
json!({
"events": [{
"event_type": "codex_plugin_installed",
"event_params": {
"plugin_id": "sample-plugin@debug",
"remote_plugin_id": null,
"plugin_name": "sample-plugin",
"marketplace_name": "debug",
"has_skills": false,
"mcp_server_count": 0,
"connector_ids": [],
"product_client_id": DEFAULT_CLIENT_NAME,
}
}]
})
);
Ok(())
}
#[tokio::test]
async fn plugin_install_failure_tracks_analytics_event() -> Result<()> {
let analytics_server = start_analytics_events_server().await?;
let codex_home = TempDir::new()?;
write_analytics_config(codex_home.path(), &analytics_server.uri())?;
write_chatgpt_auth(
codex_home.path(),
ChatGptAuthFixture::new("chatgpt-token")
.account_id("account-123")
.chatgpt_user_id("user-123")
.chatgpt_account_id("account-123"),
AuthCredentialsStoreMode::File,
)?;
let repo_root = TempDir::new()?;
write_plugin_marketplace(
@@ -1096,28 +935,11 @@ async fn plugin_install_failure_tracks_analytics_event() -> Result<()> {
.await??;
assert_eq!(err.error.code, -32600);
let payload =
wait_for_plugin_analytics_payload(&analytics_server, "codex_plugin_install_failed").await?;
let event_params = &payload["events"][0]["event_params"];
assert_eq!(
payload["events"][0]["event_type"],
"codex_plugin_install_failed"
);
assert_eq!(event_params["plugin_id"], "sample-plugin@debug");
assert_eq!(event_params["remote_plugin_id"], json!(null));
assert_eq!(event_params["plugin_name"], "sample-plugin");
assert_eq!(event_params["marketplace_name"], "debug");
assert_eq!(event_params["has_skills"], json!(null));
assert_eq!(event_params["mcp_server_count"], json!(null));
assert_eq!(event_params["connector_ids"], json!(null));
assert_eq!(event_params["product_client_id"], DEFAULT_CLIENT_NAME);
assert_eq!(event_params["source"], "manual");
assert_eq!(event_params["error_type"], "store_invalid");
Ok(())
}
#[tokio::test]
async fn plugin_install_tracks_remote_plugin_analytics_event() -> Result<()> {
async fn plugin_install_forwards_install_attempt_id_to_remote_install() -> Result<()> {
let codex_home = TempDir::new()?;
let server = MockServer::start().await;
let bundle_url = mount_remote_plugin_bundle(
@@ -1130,7 +952,6 @@ async fn plugin_install_tracks_remote_plugin_analytics_event() -> Result<()> {
mount_remote_plugin_detail(&server, REMOTE_PLUGIN_ID, "1.2.3", Some(&bundle_url)).await;
mount_empty_remote_installed_plugins(&server).await;
mount_remote_plugin_install(&server, REMOTE_PLUGIN_ID).await;
mount_backend_analytics_events(&server).await;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
@@ -1154,25 +975,6 @@ async fn plugin_install_tracks_remote_plugin_analytics_event() -> Result<()> {
json!({"install_attempt_id": INSTALL_ATTEMPT_ID})
);
let payload = wait_for_plugin_analytics_payload(&server, "codex_plugin_installed").await?;
assert_eq!(
payload,
json!({
"events": [{
"event_type": "codex_plugin_installed",
"event_params": {
"plugin_id": "linear@openai-curated-remote",
"remote_plugin_id": REMOTE_PLUGIN_ID,
"plugin_name": "linear",
"marketplace_name": "openai-curated-remote",
"has_skills": true,
"mcp_server_count": 0,
"connector_ids": [],
"product_client_id": DEFAULT_CLIENT_NAME,
}
}]
})
);
Ok(())
}
@@ -1188,7 +990,6 @@ async fn plugin_install_preserves_status_when_remote_bundle_error_body_is_too_la
mount_remote_plugin_detail(&server, REMOTE_PLUGIN_ID, "1.2.3", Some(&bundle_url)).await;
mount_empty_remote_installed_plugins(&server).await;
mount_remote_plugin_install(&server, REMOTE_PLUGIN_ID).await;
mount_backend_analytics_events(&server).await;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
@@ -1234,18 +1035,6 @@ async fn plugin_install_preserves_status_when_remote_bundle_error_body_is_too_la
/*expected_count*/ 0,
)
.await?;
let payload = wait_for_plugin_analytics_payload(&server, "codex_plugin_install_failed").await?;
let event_params = &payload["events"][0]["event_params"];
assert_eq!(
payload["events"][0]["event_type"],
"codex_plugin_install_failed"
);
assert_eq!(event_params["plugin_id"], "linear@openai-curated-remote");
assert_eq!(event_params["remote_plugin_id"], REMOTE_PLUGIN_ID);
assert_eq!(event_params["marketplace_name"], "openai-curated-remote");
assert_eq!(event_params["source"], "manual");
assert_eq!(event_params["error_type"], "remote_bundle_download_status");
assert_eq!(event_params["sub_error_type"], "http_5xx");
assert!(
!codex_home
.path()
@@ -2861,84 +2650,6 @@ connectors = true
)
}
fn write_analytics_config(codex_home: &std::path::Path, base_url: &str) -> std::io::Result<()> {
std::fs::write(
codex_home.join("config.toml"),
format!("chatgpt_base_url = \"{base_url}\"\n"),
)
}
async fn mount_backend_analytics_events(server: &MockServer) {
Mock::given(method("POST"))
.and(path("/backend-api/codex/analytics-events/events"))
.respond_with(ResponseTemplate::new(200).set_body_string(r#"{"status":"ok"}"#))
.mount(server)
.await;
}
async fn wait_for_plugin_analytics_payload(
server: &MockServer,
event_type: &str,
) -> Result<serde_json::Value> {
timeout(DEFAULT_TIMEOUT, async {
loop {
let Some(requests) = server.received_requests().await else {
tokio::time::sleep(Duration::from_millis(25)).await;
continue;
};
for request in requests.iter().filter(|request| {
request.method == "POST"
&& request
.url
.path()
.ends_with("/codex/analytics-events/events")
}) {
let mut payload: serde_json::Value = serde_json::from_slice(&request.body)
.map_err(|err| anyhow::anyhow!("invalid analytics payload: {err}"))?;
let events = payload["events"]
.as_array_mut()
.ok_or_else(|| anyhow::anyhow!("analytics payload missing events array"))?;
events.retain(|event| event["event_type"] == event_type);
if !events.is_empty() {
return Ok(payload);
}
}
tokio::time::sleep(Duration::from_millis(25)).await;
}
})
.await?
}
#[tokio::test]
async fn plugin_analytics_wait_ignores_unrelated_requests_and_batched_events() -> Result<()> {
let server = MockServer::start().await;
mount_backend_analytics_events(&server).await;
let client = HttpClientBuilder::new().build_direct()?;
let expected = json!({
"event_type": "codex_plugin_install_failed",
"event_params": {"plugin_id": "sample-plugin@debug"}
});
for events in [
json!([{"event_type": "codex_turn_event"}]),
json!([{"event_type": "codex_thread_initialized"}, expected.clone()]),
] {
client
.post(format!(
"{}/backend-api/codex/analytics-events/events",
server.uri()
))
.json(&json!({"events": events}))
.send()
.await?
.error_for_status()?;
}
assert_eq!(
wait_for_plugin_analytics_payload(&server, "codex_plugin_install_failed").await?,
json!({"events": [expected]})
);
Ok(())
}
async fn oauth_discovery_request_count(server: &MockServer) -> usize {
server
.received_requests()