generated from nhcarrigan/template
feat: handle TaskCreated hook event (closes #254)
This commit is contained in:
@@ -332,6 +332,18 @@ pub struct FileChangedEvent {
|
||||
pub conversation_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TaskCreatedEvent {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub task_id: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parent_tool_use_id: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub conversation_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AgentStartEvent {
|
||||
pub tool_use_id: String,
|
||||
@@ -803,4 +815,49 @@ mod tests {
|
||||
assert!(serialized.contains("\"file\":\"/tmp/test.txt\""));
|
||||
assert!(!serialized.contains("conversation_id"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_task_created_event_serialization() {
|
||||
let event = TaskCreatedEvent {
|
||||
task_id: Some("task-abc123".to_string()),
|
||||
description: Some("Explore the codebase".to_string()),
|
||||
parent_tool_use_id: Some("toolu_xyz".to_string()),
|
||||
conversation_id: Some("conv-abc".to_string()),
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&event).unwrap();
|
||||
assert!(serialized.contains("\"task_id\":\"task-abc123\""));
|
||||
assert!(serialized.contains("\"description\":\"Explore the codebase\""));
|
||||
assert!(serialized.contains("\"parent_tool_use_id\":\"toolu_xyz\""));
|
||||
assert!(serialized.contains("\"conversation_id\":\"conv-abc\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_task_created_event_omits_none_fields() {
|
||||
let event = TaskCreatedEvent {
|
||||
task_id: None,
|
||||
description: None,
|
||||
parent_tool_use_id: None,
|
||||
conversation_id: None,
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&event).unwrap();
|
||||
assert_eq!(serialized, "{}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_task_created_event_partial_fields() {
|
||||
let event = TaskCreatedEvent {
|
||||
task_id: Some("task-001".to_string()),
|
||||
description: None,
|
||||
parent_tool_use_id: None,
|
||||
conversation_id: None,
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&event).unwrap();
|
||||
assert!(serialized.contains("\"task_id\":\"task-001\""));
|
||||
assert!(!serialized.contains("description"));
|
||||
assert!(!serialized.contains("parent_tool_use_id"));
|
||||
assert!(!serialized.contains("conversation_id"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user