mirror of
https://github.com/openai/codex.git
synced 2026-04-24 06:35:50 +00:00
emigrate subagent source logic and tests
This commit is contained in:
@@ -10,7 +10,6 @@ use codex_login::default_client::originator;
|
||||
use codex_plugin::PluginTelemetryMetadata;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::SkillScope;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use serde::Serialize;
|
||||
use sha1::Digest;
|
||||
use sha1::Sha1;
|
||||
@@ -648,9 +647,8 @@ fn codex_thread_initialized_event_params(
|
||||
ephemeral: input.ephemeral,
|
||||
session_source: session_source_name(&input.session_source),
|
||||
initialization_mode: input.initialization_mode,
|
||||
subagent_source: session_source_subagent_source(&input.session_source)
|
||||
.map(subagent_source_name),
|
||||
parent_thread_id: session_source_parent_thread_id(&input.session_source),
|
||||
subagent_source: None,
|
||||
parent_thread_id: None,
|
||||
created_at: now_unix_timestamp_secs(),
|
||||
}
|
||||
}
|
||||
@@ -693,34 +691,10 @@ fn codex_plugin_used_metadata(
|
||||
fn session_source_name(session_source: &SessionSource) -> Option<&'static str> {
|
||||
match session_source {
|
||||
SessionSource::Cli | SessionSource::VSCode | SessionSource::Exec => Some("user"),
|
||||
SessionSource::SubAgent(_) => Some("subagent"),
|
||||
SessionSource::Mcp | SessionSource::Custom(_) | SessionSource::Unknown => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn subagent_source_name(subagent_source: SubAgentSource) -> String {
|
||||
match subagent_source {
|
||||
SubAgentSource::Review => "review".to_string(),
|
||||
SubAgentSource::Compact => "compact".to_string(),
|
||||
SubAgentSource::ThreadSpawn { .. } => "thread_spawn".to_string(),
|
||||
SubAgentSource::MemoryConsolidation => "memory_consolidation".to_string(),
|
||||
SubAgentSource::Other(other) => other,
|
||||
}
|
||||
}
|
||||
|
||||
fn session_source_subagent_source(session_source: &SessionSource) -> Option<SubAgentSource> {
|
||||
match session_source {
|
||||
SessionSource::SubAgent(subagent_source) => Some(subagent_source.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn session_source_parent_thread_id(session_source: &SessionSource) -> Option<String> {
|
||||
match session_source {
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id, ..
|
||||
}) => Some(parent_thread_id.to_string()),
|
||||
_ => None,
|
||||
SessionSource::SubAgent(_)
|
||||
| SessionSource::Mcp
|
||||
| SessionSource::Custom(_)
|
||||
| SessionSource::Unknown => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ use codex_plugin::PluginCapabilitySummary;
|
||||
use codex_plugin::PluginId;
|
||||
use codex_plugin::PluginTelemetryMetadata;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use std::collections::HashSet;
|
||||
@@ -232,26 +231,6 @@ fn thread_initialized_event_serializes_expected_shape() {
|
||||
assert!(payload["event_params"]["created_at"].as_u64().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thread_initialized_event_serializes_subagent_source() {
|
||||
let event = TrackEventRequest::CodexThreadInitialized(codex_thread_initialized_event_request(
|
||||
"codex-tui".to_string(),
|
||||
ThreadInitializeInput {
|
||||
connection_id: 1,
|
||||
thread_id: "thread-1".to_string(),
|
||||
model: "gpt-5".to_string(),
|
||||
ephemeral: false,
|
||||
session_source: SessionSource::SubAgent(SubAgentSource::Review),
|
||||
initialization_mode: InitializationMode::New,
|
||||
},
|
||||
));
|
||||
|
||||
let payload =
|
||||
serde_json::to_value(&event).expect("serialize subagent thread initialized event");
|
||||
assert_eq!(payload["event_params"]["session_source"], "subagent");
|
||||
assert_eq!(payload["event_params"]["subagent_source"], "review");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn initialize_caches_client_and_thread_lifecycle_publishes_once_initialized() {
|
||||
let mut reducer = AnalyticsReducer::default();
|
||||
@@ -300,16 +279,7 @@ async fn initialize_caches_client_and_thread_lifecycle_publishes_once_initialize
|
||||
thread_id: "thread-1".to_string(),
|
||||
model: "gpt-5".to_string(),
|
||||
ephemeral: true,
|
||||
session_source: SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: codex_protocol::ThreadId::from_string(
|
||||
"11111111-1111-1111-1111-111111111111",
|
||||
)
|
||||
.expect("valid thread id"),
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
agent_role: None,
|
||||
}),
|
||||
session_source: SessionSource::Exec,
|
||||
initialization_mode: InitializationMode::Resumed,
|
||||
},
|
||||
)),
|
||||
@@ -322,15 +292,9 @@ async fn initialize_caches_client_and_thread_lifecycle_publishes_once_initialize
|
||||
assert_eq!(payload[0]["event_type"], "codex_thread_initialized");
|
||||
assert_eq!(payload[0]["event_params"]["product_client_id"], "codex-tui");
|
||||
assert_eq!(payload[0]["event_params"]["initialization_mode"], "resumed");
|
||||
assert_eq!(payload[0]["event_params"]["session_source"], "subagent");
|
||||
assert_eq!(
|
||||
payload[0]["event_params"]["subagent_source"],
|
||||
"thread_spawn"
|
||||
);
|
||||
assert_eq!(
|
||||
payload[0]["event_params"]["parent_thread_id"],
|
||||
"11111111-1111-1111-1111-111111111111"
|
||||
);
|
||||
assert_eq!(payload[0]["event_params"]["session_source"], "user");
|
||||
assert_eq!(payload[0]["event_params"]["subagent_source"], Value::Null);
|
||||
assert_eq!(payload[0]["event_params"]["parent_thread_id"], Value::Null);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user