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
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:
@@ -3,12 +3,8 @@
|
||||
use core_test_support::test_codex::local_requests;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use anyhow::Result;
|
||||
use codex_analytics::AnalyticsEventsClient;
|
||||
use codex_analytics::PluginMeasurementRow;
|
||||
use codex_analytics::PluginMeasurementsInput;
|
||||
use codex_config::LoaderOverrides;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_core::config::Config;
|
||||
@@ -28,12 +24,10 @@ use codex_protocol::config_types::CollaborationMode;
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::config_types::Settings;
|
||||
use codex_protocol::config_types::TrustLevel;
|
||||
use codex_protocol::mcp::ClientMcpExtensions;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
#[cfg(unix)]
|
||||
use codex_protocol::protocol::GranularApprovalConfig;
|
||||
use codex_protocol::protocol::ThreadSettingsOverrides;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_skills_extension::HostSkillsLoadInput;
|
||||
@@ -58,7 +52,6 @@ use core_test_support::responses::start_mock_server;
|
||||
use core_test_support::skip_if_no_network;
|
||||
use core_test_support::skip_if_remote;
|
||||
#[cfg(unix)]
|
||||
use core_test_support::skip_if_sandbox;
|
||||
use core_test_support::skip_if_target_windows;
|
||||
use core_test_support::stdio_server_bin;
|
||||
use core_test_support::submit_thread_settings;
|
||||
@@ -82,7 +75,6 @@ const SAMPLE_PLUGIN_CONFIG_NAME: &str = "sample@test";
|
||||
const SAMPLE_REMOTE_PLUGIN_CONFIG_NAME: &str = "sample@openai-curated-remote";
|
||||
const SAMPLE_PLUGIN_DISPLAY_NAME: &str = "sample";
|
||||
const SAMPLE_PLUGIN_DESCRIPTION: &str = "inspect sample data";
|
||||
const SAMPLE_REMOTE_PLUGIN_ID: &str = "plugins~Plugin_sample";
|
||||
const SAMPLE_PLUGIN_APP_NAMESPACE: &str = "mcp__codex_apps__google_calendar";
|
||||
const SAMPLE_PLUGIN_MCP_NAMESPACE: &str = "mcp__sample";
|
||||
const PLUGIN_APP_SEARCH_CALL_ID: &str = "plugin-app-search";
|
||||
@@ -170,17 +162,6 @@ fn write_plugin_skill_plugin(home: &TempDir) -> std::path::PathBuf {
|
||||
write_sample_plugin_skill(write_sample_plugin_manifest_and_config(home))
|
||||
}
|
||||
|
||||
fn write_remote_plugin_skill_plugin(home: &TempDir) -> std::path::PathBuf {
|
||||
let plugin_root = home
|
||||
.path()
|
||||
.join("plugins/cache/openai-curated-remote/sample/local");
|
||||
write_sample_plugin_skill(write_sample_plugin_manifest_and_config_at_root(
|
||||
home,
|
||||
plugin_root,
|
||||
SAMPLE_REMOTE_PLUGIN_CONFIG_NAME,
|
||||
))
|
||||
}
|
||||
|
||||
fn write_sample_plugin_skill(plugin_root: std::path::PathBuf) -> std::path::PathBuf {
|
||||
let skill_dir = plugin_root.join("skills/sample-search");
|
||||
std::fs::create_dir_all(skill_dir.as_path()).expect("create plugin skill dir");
|
||||
@@ -285,21 +266,6 @@ fn write_plugin_app_plugin_with_name(home: &TempDir, app_name: &str) {
|
||||
.expect("write plugin app config");
|
||||
}
|
||||
|
||||
async fn build_analytics_plugin_test_codex(
|
||||
server: &MockServer,
|
||||
codex_home: Arc<TempDir>,
|
||||
) -> Result<TestCodex> {
|
||||
let chatgpt_base_url = server.uri();
|
||||
let mut builder = test_codex()
|
||||
.with_home(codex_home)
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_model("gpt-5.2")
|
||||
.with_config(move |config| {
|
||||
config.chatgpt_base_url = chatgpt_base_url;
|
||||
});
|
||||
builder.build_with_auto_env(server).await
|
||||
}
|
||||
|
||||
async fn build_apps_enabled_plugin_test_codex(
|
||||
server: &MockServer,
|
||||
codex_home: Arc<TempDir>,
|
||||
@@ -367,105 +333,6 @@ fn searched_plugin_tools(
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn shared_analytics_client_preserves_session_products() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let server = start_mock_server().await;
|
||||
Mock::given(path("/codex/analytics-events/events"))
|
||||
.respond_with(ResponseTemplate::new(200))
|
||||
.mount(&server)
|
||||
.await;
|
||||
let client = AnalyticsEventsClient::new(
|
||||
codex_core::test_support::auth_manager_from_auth(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
),
|
||||
server.uri(),
|
||||
/*analytics_enabled*/ Some(true),
|
||||
);
|
||||
let mut products = [Some("aeon"), Some("tpp"), None];
|
||||
let mut sessions = Vec::new();
|
||||
for product in products {
|
||||
sessions.push(
|
||||
test_codex()
|
||||
.with_analytics_events_client(client.clone())
|
||||
.with_config(move |config| {
|
||||
config.apps_mcp_product_sku = product.map(str::to_string);
|
||||
})
|
||||
.build_with_auto_env(&server)
|
||||
.await?,
|
||||
);
|
||||
}
|
||||
// All Sessions have registered before events are interleaved on their shared client.
|
||||
let mut expected = Vec::new();
|
||||
for (position, index) in [0, 1, 2, 0, 0].into_iter().enumerate() {
|
||||
if position == 4 {
|
||||
client.flush().await;
|
||||
let session = &mut sessions[0];
|
||||
session.codex.ensure_rollout_materialized().await;
|
||||
session.codex.shutdown_and_wait().await?;
|
||||
session
|
||||
.thread_manager
|
||||
.remove_thread(&session.session_configured.thread_id)
|
||||
.await;
|
||||
let mut config = session.config.clone();
|
||||
config.analytics_enabled = Some(false);
|
||||
let resumed = session
|
||||
.thread_manager
|
||||
.resume_legacy_thread_from_rollout(
|
||||
config,
|
||||
session.codex.rollout_path().expect("rollout path"),
|
||||
session.thread_manager.auth_manager(),
|
||||
/*parent_trace*/ None,
|
||||
ClientMcpExtensions::default(),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(resumed.thread_id, session.session_configured.thread_id);
|
||||
session.codex = resumed.thread;
|
||||
products[0] = None;
|
||||
}
|
||||
let thread_id = sessions[index].session_configured.thread_id.to_string();
|
||||
client.track_plugin_measurements(PluginMeasurementsInput {
|
||||
thread_id: thread_id.clone(),
|
||||
turn_id: "turn".into(),
|
||||
item_id: "item".into(),
|
||||
originator: "test_client".into(),
|
||||
model_slug: None,
|
||||
reasoning_effort: None,
|
||||
plugin_id: "sample@test".into(),
|
||||
execution_id: "execution".into(),
|
||||
operation: "build".into(),
|
||||
rows: vec![PluginMeasurementRow {
|
||||
measurement_name: "duration_ms".into(),
|
||||
number_value: 1.0,
|
||||
dimensions: Default::default(),
|
||||
}],
|
||||
});
|
||||
expected.push((thread_id, products[index].map(str::to_string)));
|
||||
}
|
||||
client.flush().await;
|
||||
let mut actual = Vec::new();
|
||||
for request in server.received_requests().await.unwrap_or_default() {
|
||||
if request.url.path() != "/codex/analytics-events/events" {
|
||||
continue;
|
||||
}
|
||||
let product = request
|
||||
.headers
|
||||
.get("x-openai-product-sku")
|
||||
.map(|value| value.to_str().unwrap().to_string());
|
||||
let body: serde_json::Value = serde_json::from_slice(&request.body)?;
|
||||
for event in body["events"].as_array().unwrap() {
|
||||
if event["event_type"] == "codex_plugin_measurement_event" {
|
||||
let thread_id = event["event_params"]["thread_id"].as_str().unwrap();
|
||||
actual.push((thread_id.to_string(), product.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
actual.sort();
|
||||
expected.sort();
|
||||
assert_eq!(actual, expected);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn persisted_remote_plugin_command_attribution_flows_through_turn_context() -> Result<()> {
|
||||
skip_if_target_windows!(Ok(()), "executes a POSIX shell script");
|
||||
@@ -478,19 +345,7 @@ async fn persisted_remote_plugin_command_attribution_flows_through_turn_context(
|
||||
let server = start_mock_server().await;
|
||||
let codex_home = Arc::new(TempDir::new()?);
|
||||
let script_path = write_remote_plugin_script_and_config(codex_home.as_ref());
|
||||
std::fs::write(
|
||||
&script_path,
|
||||
r#"printf '%s' '{"version":1,"measurements":[{"name":"files_scanned","value":7}]}' > "$CODEX_PLUGIN_METRICS_OUTPUT"
|
||||
"#,
|
||||
)?;
|
||||
let plugin_root = script_path
|
||||
.parent()
|
||||
.and_then(std::path::Path::parent)
|
||||
.expect("plugin root");
|
||||
std::fs::write(
|
||||
plugin_root.join("analytics.yaml"),
|
||||
"version: 1\noperations: {scan: {path: ./scripts/run.sh, measurements: {files_scanned: {}}}}\n",
|
||||
)?;
|
||||
std::fs::write(&script_path, "printf done\n")?;
|
||||
let builder = test_codex();
|
||||
let command = shlex::try_join(["/bin/sh", script_path.to_string_lossy().as_ref()])?;
|
||||
let call_id = "remote-plugin-command";
|
||||
@@ -576,316 +431,6 @@ async fn persisted_remote_plugin_command_attribution_flows_through_turn_context(
|
||||
assert_eq!(script_path, Some("scripts/run.sh"));
|
||||
}
|
||||
|
||||
let measurement = wait_for_analytics_event(&server, "codex_plugin_measurement_event").await;
|
||||
assert_eq!(
|
||||
serde_json::json!({
|
||||
"plugin_id": measurement["event_params"]["plugin_id"],
|
||||
"operation": measurement["event_params"]["operation"],
|
||||
"measurement_name": measurement["event_params"]["measurement_name"],
|
||||
"number_value": measurement["event_params"]["number_value"],
|
||||
}),
|
||||
serde_json::json!({
|
||||
"plugin_id": REMOTE_PLUGIN_CONFIG_NAME,
|
||||
"operation": "scan",
|
||||
"measurement_name": "files_scanned",
|
||||
"number_value": 7.0,
|
||||
})
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test_case(codex_exec_server::LOCAL_ENVIRONMENT_ID; "local")]
|
||||
#[test_case(codex_exec_server::REMOTE_ENVIRONMENT_ID; "remote")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn plugin_metrics_stdin_works_with_sandbox_approval_disabled(
|
||||
environment_id: &str,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
skip_if_sandbox!(Ok(()));
|
||||
let server = start_mock_server().await;
|
||||
let home = Arc::new(TempDir::new()?);
|
||||
let script = write_remote_plugin_script_and_config(home.as_ref());
|
||||
std::fs::write(
|
||||
&script,
|
||||
r#"test -n "${CODEX_PLUGIN_METRICS_OUTPUT:-}" || exit 2
|
||||
IFS= read -r input
|
||||
test "$input" = continue || exit 3
|
||||
printf '%s' '{"version":1,"measurements":[{"name":"files_scanned","value":7}]}' > "$CODEX_PLUGIN_METRICS_OUTPUT" || exit 4
|
||||
printf 'STDIN_OK\n'
|
||||
"#,
|
||||
)?;
|
||||
std::fs::write(
|
||||
script
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("analytics.yaml"),
|
||||
"version: 1\noperations: {scan: {path: ./scripts/run.sh, measurements: {files_scanned: {}}}}\n",
|
||||
)?;
|
||||
let command = shlex::try_join(["/bin/sh", script.to_string_lossy().as_ref()])?;
|
||||
let responses = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![
|
||||
ev_function_call(
|
||||
"open",
|
||||
"exec_command",
|
||||
&serde_json::json!({
|
||||
"cmd": command,
|
||||
"login": false,
|
||||
"tty": true,
|
||||
"yield_time_ms": 1000,
|
||||
"environment_id": environment_id,
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
ev_completed("opened"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_function_call(
|
||||
"input",
|
||||
"write_stdin",
|
||||
&serde_json::json!({
|
||||
"session_id": 1000,
|
||||
"chars": "continue\n",
|
||||
"yield_time_ms": 1000,
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
ev_completed("sent"),
|
||||
]),
|
||||
sse(vec![ev_completed("done")]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
let base_url = server.uri();
|
||||
let mut builder = test_codex()
|
||||
.with_home(home)
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_model("gpt-5.2")
|
||||
.with_config(move |config| {
|
||||
config.chatgpt_base_url = base_url;
|
||||
config.analytics_enabled = Some(true);
|
||||
config
|
||||
.features
|
||||
.enable(Feature::SkipHostSkillDiscovery)
|
||||
.unwrap();
|
||||
});
|
||||
// Exercise both native and executor-managed sandboxes with the same plugin fixture.
|
||||
let _executor = if environment_id == codex_exec_server::REMOTE_ENVIRONMENT_ID {
|
||||
let executor = core_test_support::exec_server::ExecServerProcess::start().await?;
|
||||
builder = builder.with_exec_server_url(executor.websocket_url.clone());
|
||||
Some(executor)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let test = builder.build(&server).await?;
|
||||
let (sandbox_policy, permission_profile) =
|
||||
turn_permission_fields(PermissionProfile::read_only(), test.config.cwd.as_path());
|
||||
test.codex
|
||||
.start_or_steer_turn(
|
||||
TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "send input to the plugin".into(),
|
||||
text_elements: Vec::new(),
|
||||
}])
|
||||
.with_thread_settings(ThreadSettingsOverrides {
|
||||
approval_policy: Some(AskForApproval::Granular(GranularApprovalConfig {
|
||||
sandbox_approval: false,
|
||||
rules: false,
|
||||
skill_approval: false,
|
||||
request_permissions: false,
|
||||
mcp_elicitations: false,
|
||||
})),
|
||||
sandbox_policy: Some(sandbox_policy),
|
||||
permission_profile,
|
||||
..Default::default()
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
let output = responses.function_call_output_text("input").unwrap();
|
||||
assert!(output.contains("Process exited with code 0"), "{output}");
|
||||
assert!(output.contains("STDIN_OK"), "{output}");
|
||||
let measurement = wait_for_analytics_event(&server, "codex_plugin_measurement_event").await;
|
||||
assert_eq!(
|
||||
serde_json::json!({
|
||||
"plugin_id": measurement["event_params"]["plugin_id"],
|
||||
"measurement_name": measurement["event_params"]["measurement_name"],
|
||||
"number_value": measurement["event_params"]["number_value"],
|
||||
}),
|
||||
serde_json::json!({
|
||||
"plugin_id": REMOTE_PLUGIN_CONFIG_NAME,
|
||||
"measurement_name": "files_scanned",
|
||||
"number_value": 7.0,
|
||||
}),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn remote_plugin_measurements_require_the_frontend_version() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
// This fixture needs a real remote transport with separately controlled frontend
|
||||
// and executor caches, rather than the runner's automatic executor selection.
|
||||
let executor = core_test_support::exec_server::ExecServerProcess::start().await?;
|
||||
let server = start_mock_server().await;
|
||||
let home = Arc::new(TempDir::new()?);
|
||||
let frontend_script = write_remote_plugin_script_and_config(home.as_ref());
|
||||
let script = r#"if [ -n "${CODEX_PLUGIN_METRICS_OUTPUT:-}" ]; then
|
||||
printf '%s' '{"version":1,"measurements":[{"name":"duration_ms","value":7,"dimensions":{"release":"v1"}}]}' > "$CODEX_PLUGIN_METRICS_OUTPUT"
|
||||
else
|
||||
printf 'no metrics sidecar\n'
|
||||
fi
|
||||
"#;
|
||||
std::fs::write(&frontend_script, script)?;
|
||||
std::fs::write(
|
||||
frontend_script
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("analytics.yaml"),
|
||||
"version: 1\noperations:\n dependency_install:\n path: ./scripts/run.sh\n measurements:\n duration_ms:\n dimensions:\n release: [v1]\n",
|
||||
)?;
|
||||
let executor_home = TempDir::new()?;
|
||||
let mut responses = Vec::new();
|
||||
for (version, call_id) in [("2.0.0", "wrong-version"), ("1.2.3", "matching-version")] {
|
||||
let root = executor_home.path().join(format!(
|
||||
"plugins/cache/openai-curated-remote/sample/{version}"
|
||||
));
|
||||
std::fs::create_dir_all(root.join("scripts"))?;
|
||||
let path = root.join("scripts/run.sh");
|
||||
std::fs::write(&path, script)?;
|
||||
// The executor's declaration is never an authority, even for matching bytes.
|
||||
std::fs::write(
|
||||
root.join("analytics.yaml"),
|
||||
"version: 1\noperations: {untrusted: {path: ./scripts/run.sh, measurements: {other: {}}}}\n",
|
||||
)?;
|
||||
// A plugin-shaped alias must use the canonical plugin's identity and version.
|
||||
let alias = executor_home.path().join(format!(
|
||||
"plugins/cache/openai-curated-remote/apparent-plugin/{version}"
|
||||
));
|
||||
std::fs::create_dir_all(alias.parent().unwrap())?;
|
||||
std::os::unix::fs::symlink(&root, &alias)?;
|
||||
let alias_script = alias.join("scripts/run.sh");
|
||||
let command = shlex::try_join(["/bin/sh", alias_script.to_string_lossy().as_ref()])?;
|
||||
responses.push(sse(vec![
|
||||
ev_response_created(call_id),
|
||||
ev_function_call(
|
||||
call_id,
|
||||
"exec_command",
|
||||
&serde_json::json!({
|
||||
"cmd": command,
|
||||
"login": false,
|
||||
"environment_id": codex_exec_server::REMOTE_ENVIRONMENT_ID,
|
||||
"yield_time_ms": 1000,
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
ev_completed(call_id),
|
||||
]));
|
||||
}
|
||||
responses.push(sse(vec![
|
||||
ev_response_created("done"),
|
||||
ev_assistant_message("done-message", "done"),
|
||||
ev_completed("done"),
|
||||
]));
|
||||
let response_mock = mount_sse_sequence(&server, responses).await;
|
||||
let base_url = server.uri();
|
||||
let mut builder = test_codex()
|
||||
.with_exec_server_url(executor.websocket_url.clone())
|
||||
.with_home(home)
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_model("gpt-5.2")
|
||||
.with_config(move |config| {
|
||||
config.chatgpt_base_url = base_url;
|
||||
config.analytics_enabled = Some(true);
|
||||
config
|
||||
.features
|
||||
.enable(Feature::SkipHostSkillDiscovery)
|
||||
.unwrap();
|
||||
});
|
||||
let test = builder.build(&server).await?;
|
||||
let manager = test.thread_manager.environment_manager();
|
||||
let remote = manager.default_environment().unwrap();
|
||||
tokio::time::timeout(Duration::from_secs(30), remote.wait_until_ready()).await??;
|
||||
assert!(remote.is_remote());
|
||||
let (sandbox_policy, permission_profile) =
|
||||
turn_permission_fields(PermissionProfile::Disabled, test.config.cwd.as_path());
|
||||
test.codex
|
||||
.start_or_steer_turn(
|
||||
TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "run both plugin versions".into(),
|
||||
text_elements: Vec::new(),
|
||||
}])
|
||||
.with_thread_settings(ThreadSettingsOverrides {
|
||||
approval_policy: Some(AskForApproval::Never),
|
||||
sandbox_policy: Some(sandbox_policy),
|
||||
permission_profile,
|
||||
..Default::default()
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
for call_id in ["wrong-version", "matching-version"] {
|
||||
let expected = (Some(REMOTE_PLUGIN_CONFIG_NAME), Some("scripts/run.sh"));
|
||||
let begin = wait_for_event_match(&test.codex, |event| match event {
|
||||
EventMsg::ExecCommandBegin(event) if event.call_id == call_id => Some(event.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
let end = wait_for_event_match(&test.codex, |event| match event {
|
||||
EventMsg::ExecCommandEnd(event) if event.call_id == call_id => Some(event.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(end.exit_code, 0, "{}", end.aggregated_output);
|
||||
assert_eq!(
|
||||
(begin.plugin_id.as_deref(), begin.script_path.as_deref()),
|
||||
expected
|
||||
);
|
||||
assert_eq!(
|
||||
(end.plugin_id.as_deref(), end.script_path.as_deref()),
|
||||
expected
|
||||
);
|
||||
}
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
assert!(
|
||||
response_mock
|
||||
.function_call_output_text("wrong-version")
|
||||
.unwrap()
|
||||
.contains("no metrics sidecar")
|
||||
);
|
||||
let event = wait_for_analytics_event(&server, "codex_plugin_measurement_event").await;
|
||||
assert_eq!(
|
||||
serde_json::json!({
|
||||
"plugin_id": event["event_params"]["plugin_id"],
|
||||
"operation": event["event_params"]["operation"],
|
||||
"measurement_name": event["event_params"]["measurement_name"],
|
||||
"number_value": event["event_params"]["number_value"],
|
||||
"dimensions": event["event_params"]["dimensions"],
|
||||
"thread_id": event["event_params"]["thread_id"],
|
||||
"item_id": event["event_params"]["item_id"],
|
||||
}),
|
||||
serde_json::json!({
|
||||
"plugin_id": REMOTE_PLUGIN_CONFIG_NAME,
|
||||
"operation": "dependency_install",
|
||||
"measurement_name": "duration_ms",
|
||||
"number_value": 7.0,
|
||||
"dimensions": {"release": "v1"},
|
||||
"thread_id": test.session_configured.thread_id.to_string(),
|
||||
"item_id": "matching-version",
|
||||
})
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -2241,205 +1786,3 @@ async fn explicitly_requested_mcp_waits_for_startup(request: ExplicitMcpRequest)
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn explicit_plugin_mentions_track_plugin_used_analytics() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let server = start_mock_server().await;
|
||||
let _resp_mock = mount_sse_once(
|
||||
&server,
|
||||
sse(vec![ev_response_created("resp-1"), ev_completed("resp-1")]),
|
||||
)
|
||||
.await;
|
||||
|
||||
let codex_home = Arc::new(TempDir::new()?);
|
||||
write_plugin_skill_plugin(codex_home.as_ref());
|
||||
let test_codex = build_analytics_plugin_test_codex(&server, codex_home).await?;
|
||||
let codex = Arc::clone(&test_codex.codex);
|
||||
|
||||
codex
|
||||
.start_or_steer_turn(
|
||||
TurnInputRequest::user_input(vec![codex_protocol::user_input::UserInput::Mention {
|
||||
name: "sample".into(),
|
||||
path: format!("plugin://{SAMPLE_PLUGIN_CONFIG_NAME}"),
|
||||
}])
|
||||
.with_responses_metadata(Some(std::collections::HashMap::from([]))),
|
||||
)
|
||||
.await?;
|
||||
wait_for_event(&codex, |ev| matches!(ev, EventMsg::TurnComplete(_))).await;
|
||||
|
||||
let event = wait_for_analytics_event(&server, "codex_plugin_used").await;
|
||||
assert_eq!(event["event_params"]["plugin_id"], "sample@test");
|
||||
assert_eq!(event["event_params"]["plugin_name"], "sample");
|
||||
assert_eq!(event["event_params"]["marketplace_name"], "test");
|
||||
assert_eq!(event["event_params"]["has_skills"], true);
|
||||
assert_eq!(event["event_params"]["mcp_server_count"], 0);
|
||||
assert_eq!(
|
||||
event["event_params"]["mcp_server_names"],
|
||||
serde_json::json!([])
|
||||
);
|
||||
assert_eq!(
|
||||
event["event_params"]["connector_ids"],
|
||||
serde_json::json!([])
|
||||
);
|
||||
assert_eq!(
|
||||
event["event_params"]["product_client_id"],
|
||||
serde_json::json!(codex_login::default_client::originator().value)
|
||||
);
|
||||
assert_eq!(event["event_params"]["model_slug"], "gpt-5.2");
|
||||
assert!(event["event_params"]["thread_id"].as_str().is_some());
|
||||
assert!(event["event_params"]["turn_id"].as_str().is_some());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn explicit_plugin_skill_invocation_tracks_remote_plugin_id() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let server = start_mock_server().await;
|
||||
let _resp_mock = mount_sse_once(
|
||||
&server,
|
||||
sse(vec![ev_response_created("resp-1"), ev_completed("resp-1")]),
|
||||
)
|
||||
.await;
|
||||
|
||||
let codex_home = Arc::new(TempDir::new()?);
|
||||
let skill_path = dunce::canonicalize(write_remote_plugin_skill_plugin(codex_home.as_ref()))?;
|
||||
persist_sample_remote_plugin_id(codex_home.as_ref());
|
||||
let test_codex = build_analytics_plugin_test_codex(&server, codex_home).await?;
|
||||
let codex = Arc::clone(&test_codex.codex);
|
||||
|
||||
codex
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Skill {
|
||||
name: "sample:sample-search".into(),
|
||||
path: skill_path,
|
||||
}]))
|
||||
.await?;
|
||||
wait_for_event(&codex, |ev| matches!(ev, EventMsg::TurnComplete(_))).await;
|
||||
|
||||
let event = wait_for_analytics_event(&server, "skill_invocation").await;
|
||||
assert_eq!(
|
||||
event["event_params"]["plugin_id"],
|
||||
SAMPLE_REMOTE_PLUGIN_CONFIG_NAME
|
||||
);
|
||||
assert_eq!(
|
||||
event["event_params"]["remote_plugin_id"],
|
||||
SAMPLE_REMOTE_PLUGIN_ID
|
||||
);
|
||||
assert_eq!(event["event_params"]["invoke_type"], "explicit");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum ImplicitPluginSkillInvocation {
|
||||
SkillDocumentRead,
|
||||
SkillScriptRun,
|
||||
}
|
||||
|
||||
#[test_case(ImplicitPluginSkillInvocation::SkillDocumentRead; "skill document read")]
|
||||
#[test_case(ImplicitPluginSkillInvocation::SkillScriptRun; "skill script run")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn implicit_plugin_skill_invocation_tracks_remote_plugin_id(
|
||||
invocation: ImplicitPluginSkillInvocation,
|
||||
) -> Result<()> {
|
||||
skip_if_target_windows!(Ok(()), "executes POSIX cat and bash commands");
|
||||
skip_if_remote!(Ok(()), "shell commands use host plugin-cache paths");
|
||||
skip_if_no_network!(Ok(()));
|
||||
let server = start_mock_server().await;
|
||||
let codex_home = Arc::new(TempDir::new()?);
|
||||
let skill_path = write_remote_plugin_skill_plugin(codex_home.as_ref());
|
||||
persist_sample_remote_plugin_id(codex_home.as_ref());
|
||||
let command = match invocation {
|
||||
ImplicitPluginSkillInvocation::SkillDocumentRead => {
|
||||
format!("cat {}", skill_path.display())
|
||||
}
|
||||
ImplicitPluginSkillInvocation::SkillScriptRun => {
|
||||
let script_path = skill_path
|
||||
.parent()
|
||||
.expect("skill path should have a parent")
|
||||
.join("scripts/test.sh");
|
||||
std::fs::create_dir_all(
|
||||
script_path
|
||||
.parent()
|
||||
.expect("script path should have a parent"),
|
||||
)?;
|
||||
std::fs::write(&script_path, "echo skill script invoked\n")?;
|
||||
format!("bash {}", script_path.display())
|
||||
}
|
||||
};
|
||||
let command_args = serde_json::json!({
|
||||
"cmd": command,
|
||||
"login": false,
|
||||
})
|
||||
.to_string();
|
||||
let _resp_mock = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
ev_function_call("call-1", "exec_command", &command_args),
|
||||
ev_completed("resp-1"),
|
||||
]),
|
||||
sse(vec![ev_response_created("resp-2"), ev_completed("resp-2")]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
let test_codex = build_analytics_plugin_test_codex(&server, codex_home).await?;
|
||||
let codex = Arc::clone(&test_codex.codex);
|
||||
|
||||
codex
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "inspect the sample skill".into(),
|
||||
text_elements: Vec::new(),
|
||||
}]))
|
||||
.await?;
|
||||
wait_for_event(&codex, |ev| matches!(ev, EventMsg::TurnComplete(_))).await;
|
||||
|
||||
let event = wait_for_analytics_event(&server, "skill_invocation").await;
|
||||
assert_eq!(
|
||||
event["event_params"]["plugin_id"],
|
||||
SAMPLE_REMOTE_PLUGIN_CONFIG_NAME
|
||||
);
|
||||
assert_eq!(
|
||||
event["event_params"]["remote_plugin_id"],
|
||||
SAMPLE_REMOTE_PLUGIN_ID
|
||||
);
|
||||
assert_eq!(event["event_params"]["invoke_type"], "implicit");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn persist_sample_remote_plugin_id(home: &TempDir) {
|
||||
let plugin_id =
|
||||
PluginId::parse(SAMPLE_REMOTE_PLUGIN_CONFIG_NAME).expect("remote plugin id should parse");
|
||||
PluginStore::new(home.path().to_path_buf())
|
||||
.write_remote_plugin_id(&plugin_id, SAMPLE_REMOTE_PLUGIN_ID)
|
||||
.expect("persist remote plugin id");
|
||||
}
|
||||
|
||||
async fn wait_for_analytics_event(server: &MockServer, event_type: &str) -> serde_json::Value {
|
||||
let deadline = Instant::now() + Duration::from_secs(10);
|
||||
loop {
|
||||
let requests = server.received_requests().await.unwrap_or_default();
|
||||
if let Some(event) = requests
|
||||
.into_iter()
|
||||
.filter(|request| request.url.path() == "/codex/analytics-events/events")
|
||||
.find_map(|request| {
|
||||
let payload: serde_json::Value = serde_json::from_slice(&request.body).ok()?;
|
||||
payload["events"].as_array().and_then(|events| {
|
||||
events
|
||||
.iter()
|
||||
.find(|event| event["event_type"] == event_type)
|
||||
.cloned()
|
||||
})
|
||||
})
|
||||
{
|
||||
break event;
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
panic!("timed out waiting for {event_type} analytics request");
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user