MCPcopy Index your code
hub / github.com/AI45Lab/Code / test_load_agents_from_dir

Function test_load_agents_from_dir

core/src/subagent.rs:1501–1552  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1499
1500 #[test]
1501 fn test_load_agents_from_dir() {
1502 let temp_dir = tempfile::tempdir().unwrap();
1503
1504 // Create a YAML agent file
1505 std::fs::write(
1506 temp_dir.path().join("agent1.yaml"),
1507 r#"
1508name: yaml-agent
1509description: Agent from YAML file
1510"#,
1511 )
1512 .unwrap();
1513
1514 // Create a Markdown agent file
1515 std::fs::write(
1516 temp_dir.path().join("agent2.md"),
1517 r#"---
1518name: md-agent
1519description: Agent from Markdown file
1520---
1521System prompt here
1522"#,
1523 )
1524 .unwrap();
1525
1526 // Create an invalid file (should be skipped)
1527 std::fs::write(temp_dir.path().join("invalid.yaml"), "not: valid: yaml: [").unwrap();
1528
1529 // Create a nested agent file (Claude-style directories are recursive)
1530 std::fs::create_dir_all(temp_dir.path().join("nested")).unwrap();
1531 std::fs::write(
1532 temp_dir.path().join("nested").join("agent3.md"),
1533 r#"---
1534name: nested-agent
1535description: Agent from nested Markdown file
1536---
1537Nested prompt
1538"#,
1539 )
1540 .unwrap();
1541
1542 // Create a non-agent file (should be skipped)
1543 std::fs::write(temp_dir.path().join("readme.txt"), "Just a text file").unwrap();
1544
1545 let agents = load_agents_from_dir(temp_dir.path());
1546 assert_eq!(agents.len(), 3);
1547
1548 let names: Vec<&str> = agents.iter().map(|a| a.name.as_str()).collect();
1549 assert!(names.contains(&"yaml-agent"));
1550 assert!(names.contains(&"md-agent"));
1551 assert!(names.contains(&"nested-agent"));
1552 }
1553
1554 #[test]
1555 fn test_load_agents_from_nonexistent_dir() {

Callers

nothing calls this directly

Calls 4

writeFunction · 0.85
load_agents_from_dirFunction · 0.85
pathMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected