()
| 3071 | |
| 3072 | #[tokio::test] |
| 3073 | async fn subagent_events_populate_session_tracker() { |
| 3074 | use super::runtime_events::RuntimeEventSink; |
| 3075 | use crate::agent::AgentEvent; |
| 3076 | use crate::subagent_task_tracker::SubagentStatus; |
| 3077 | |
| 3078 | let agent = Agent::from_config(test_config()).await.unwrap(); |
| 3079 | let session = agent |
| 3080 | .session("/tmp/test-ws-subagent-tracker", None) |
| 3081 | .unwrap(); |
| 3082 | |
| 3083 | // Drive a synthetic subagent lifecycle through the session's runtime sink. |
| 3084 | let run = session |
| 3085 | .run_store |
| 3086 | .create_run(session.session_id(), "parent prompt") |
| 3087 | .await; |
| 3088 | let sink = RuntimeEventSink::from_session(&session, &run.id); |
| 3089 | |
| 3090 | let task_id = "task-test-1".to_string(); |
| 3091 | let child_session_id = format!("task-run-{}", task_id); |
| 3092 | |
| 3093 | sink.observe(&AgentEvent::SubagentStart { |
| 3094 | task_id: task_id.clone(), |
| 3095 | session_id: child_session_id.clone(), |
| 3096 | parent_session_id: session.session_id().to_string(), |
| 3097 | agent: "explore".to_string(), |
| 3098 | description: "demo delegation".to_string(), |
| 3099 | }) |
| 3100 | .await; |
| 3101 | |
| 3102 | let snap = session |
| 3103 | .subagent_task(&task_id) |
| 3104 | .await |
| 3105 | .expect("running task should be visible"); |
| 3106 | assert_eq!(snap.status, SubagentStatus::Running); |
| 3107 | assert_eq!(snap.parent_session_id, session.session_id()); |
| 3108 | assert_eq!(snap.child_session_id, child_session_id); |
| 3109 | assert_eq!(snap.agent, "explore"); |
| 3110 | assert!(snap.finished_ms.is_none()); |
| 3111 | |
| 3112 | let pending = session.pending_subagent_tasks().await; |
| 3113 | assert_eq!(pending.len(), 1); |
| 3114 | assert_eq!(pending[0].task_id, task_id); |
| 3115 | |
| 3116 | sink.observe(&AgentEvent::SubagentEnd { |
| 3117 | task_id: task_id.clone(), |
| 3118 | session_id: child_session_id, |
| 3119 | agent: "explore".to_string(), |
| 3120 | output: "found things".to_string(), |
| 3121 | success: true, |
| 3122 | }) |
| 3123 | .await; |
| 3124 | |
| 3125 | let snap = session.subagent_task(&task_id).await.unwrap(); |
| 3126 | assert_eq!(snap.status, SubagentStatus::Completed); |
| 3127 | assert_eq!(snap.success, Some(true)); |
| 3128 | assert_eq!(snap.output.as_deref(), Some("found things")); |
| 3129 | assert!(snap.finished_ms.is_some()); |
| 3130 |
nothing calls this directly
no test coverage detected