@@ -959,6 +959,7 @@ mod tests {
959959 use serde_json:: json;
960960
961961 use super :: * ;
962+ use crate :: cli:: agent:: hook:: Source ;
962963 const INPUT : & str = r#"
963964 {
964965 "name": "some_agent",
@@ -968,21 +969,21 @@ mod tests {
968969 "fetch": { "command": "fetch3.1", "args": [] },
969970 "git": { "command": "git-mcp", "args": [] }
970971 },
971- "tools": [
972+ "tools": [
972973 "@git"
973974 ],
974975 "toolAliases": {
975976 "@gits/some_tool": "some_tool2"
976977 },
977- "allowedTools": [
978- "fs_read",
978+ "allowedTools": [
979+ "fs_read",
979980 "@fetch",
980981 "@gits/git_status"
981982 ],
982- "resources": [
983+ "resources": [
983984 "file://~/my-genai-prompts/unittest.md"
984985 ],
985- "toolsSettings": {
986+ "toolsSettings": {
986987 "fs_write": { "allowedPaths": ["~/**"] },
987988 "@git/git_status": { "git_user": "$GIT_USER" }
988989 }
@@ -1353,4 +1354,70 @@ mod tests {
13531354
13541355 assert_eq ! ( agents. get_active( ) . and_then( |a| a. model. as_ref( ) ) , None ) ;
13551356 }
1357+
1358+ #[ test]
1359+ fn test_agent_with_hooks ( ) {
1360+ let agent_json = json ! ( {
1361+ "name" : "test-agent" ,
1362+ "hooks" : {
1363+ "agentSpawn" : [
1364+ {
1365+ "command" : "git status"
1366+ }
1367+ ] ,
1368+ "preToolUse" : [
1369+ {
1370+ "matcher" : "fs_write" ,
1371+ "command" : "validate-tool.sh"
1372+ } ,
1373+ {
1374+ "matcher" : "fs_read" ,
1375+ "command" : "enforce-tdd.sh"
1376+ }
1377+ ] ,
1378+ "postToolUse" : [
1379+ {
1380+ "matcher" : "fs_write" ,
1381+ "command" : "format-python.sh"
1382+ }
1383+ ]
1384+ }
1385+ } ) ;
1386+
1387+ let agent: Agent = serde_json:: from_value ( agent_json) . expect ( "Failed to deserialize agent" ) ;
1388+
1389+ // Verify agent name
1390+ assert_eq ! ( agent. name, "test-agent" ) ;
1391+
1392+ // Verify agentSpawn hook
1393+ assert ! ( agent. hooks. contains_key( & HookTrigger :: AgentSpawn ) ) ;
1394+ let agent_spawn_hooks = & agent. hooks [ & HookTrigger :: AgentSpawn ] ;
1395+ assert_eq ! ( agent_spawn_hooks. len( ) , 1 ) ;
1396+ assert_eq ! ( agent_spawn_hooks[ 0 ] . command, "git status" ) ;
1397+ assert_eq ! ( agent_spawn_hooks[ 0 ] . matcher, None ) ;
1398+
1399+ // Verify preToolUse hooks
1400+ assert ! ( agent. hooks. contains_key( & HookTrigger :: PreToolUse ) ) ;
1401+ let pre_tool_hooks = & agent. hooks [ & HookTrigger :: PreToolUse ] ;
1402+ assert_eq ! ( pre_tool_hooks. len( ) , 2 ) ;
1403+
1404+ assert_eq ! ( pre_tool_hooks[ 0 ] . command, "validate-tool.sh" ) ;
1405+ assert_eq ! ( pre_tool_hooks[ 0 ] . matcher, Some ( "fs_write" . to_string( ) ) ) ;
1406+
1407+ assert_eq ! ( pre_tool_hooks[ 1 ] . command, "enforce-tdd.sh" ) ;
1408+ assert_eq ! ( pre_tool_hooks[ 1 ] . matcher, Some ( "fs_read" . to_string( ) ) ) ;
1409+
1410+ // Verify postToolUse hooks
1411+ assert ! ( agent. hooks. contains_key( & HookTrigger :: PostToolUse ) ) ;
1412+
1413+ // Verify default values are set correctly
1414+ for hooks in agent. hooks . values ( ) {
1415+ for hook in hooks {
1416+ assert_eq ! ( hook. timeout_ms, 30_000 ) ;
1417+ assert_eq ! ( hook. max_output_size, 10_240 ) ;
1418+ assert_eq ! ( hook. cache_ttl_seconds, 0 ) ;
1419+ assert_eq ! ( hook. source, Source :: Agent ) ;
1420+ }
1421+ }
1422+ }
13561423}
0 commit comments