@@ -1661,6 +1661,83 @@ This agent tests the auto-discovery feature.
16611661 let _ = fs:: remove_dir_all ( & temp_dir) ;
16621662}
16631663
1664+ /// Test that auto-discover resolves a bare source path relative to the lock file directory
1665+ #[ test]
1666+ fn test_compile_auto_discover_resolves_source_relative_to_lock_file_dir ( ) {
1667+ let temp_dir = std:: env:: temp_dir ( ) . join ( format ! (
1668+ "agentic-pipeline-autodiscover-relative-source-{}" ,
1669+ std:: process:: id( )
1670+ ) ) ;
1671+ let _ = fs:: remove_dir_all ( & temp_dir) ;
1672+ fs:: create_dir_all ( & temp_dir) . expect ( "Failed to create temp directory" ) ;
1673+
1674+ let templates_dir = temp_dir. join ( "azure-pipelines" ) . join ( "templates" ) ;
1675+ fs:: create_dir_all ( & templates_dir) . expect ( "Failed to create templates directory" ) ;
1676+
1677+ let source_content = r#"---
1678+ name: "Nested Agent"
1679+ description: "An agent in a nested directory"
1680+ ---
1681+
1682+ ## Nested Agent
1683+ "# ;
1684+ let source_path = templates_dir. join ( "nested-agent.md" ) ;
1685+ fs:: write ( & source_path, source_content) . expect ( "Failed to write source markdown" ) ;
1686+
1687+ // Compile from the lock-file directory so the header stores a bare source filename.
1688+ let binary_path = PathBuf :: from ( env ! ( "CARGO_BIN_EXE_ado-aw" ) ) ;
1689+ let output = std:: process:: Command :: new ( & binary_path)
1690+ . args ( [ "compile" , "nested-agent.md" ] )
1691+ . current_dir ( & templates_dir)
1692+ . output ( )
1693+ . expect ( "Failed to run initial compile" ) ;
1694+
1695+ assert ! (
1696+ output. status. success( ) ,
1697+ "Initial compile should succeed: {}" ,
1698+ String :: from_utf8_lossy( & output. stderr)
1699+ ) ;
1700+
1701+ let yaml_path = templates_dir. join ( "nested-agent.lock.yml" ) ;
1702+ assert ! ( yaml_path. exists( ) , "Compiled YAML should exist" ) ;
1703+
1704+ let initial_yaml = fs:: read_to_string ( & yaml_path) . expect ( "Should read initial YAML" ) ;
1705+ assert ! (
1706+ initial_yaml. contains( r#"source="nested-agent.md""# ) ,
1707+ "Expected bare source path in header, got:\n {}" ,
1708+ initial_yaml
1709+ ) ;
1710+
1711+ // Re-run auto-discover from repo root. This should find nested-agent.md next to the lock file.
1712+ let output = std:: process:: Command :: new ( & binary_path)
1713+ . args ( [ "compile" ] )
1714+ . current_dir ( & temp_dir)
1715+ . output ( )
1716+ . expect ( "Failed to run auto-discover compile" ) ;
1717+
1718+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
1719+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
1720+
1721+ assert ! (
1722+ output. status. success( ) ,
1723+ "Auto-discover compile should succeed.\n stdout: {}\n stderr: {}" ,
1724+ stdout,
1725+ stderr
1726+ ) ;
1727+ assert ! (
1728+ stdout. contains( "1 compiled" ) ,
1729+ "Should report 1 compiled, got stdout: {}" ,
1730+ stdout
1731+ ) ;
1732+ assert ! (
1733+ !stderr. contains( "not found" ) ,
1734+ "Should not report missing source, got stderr: {}" ,
1735+ stderr
1736+ ) ;
1737+
1738+ let _ = fs:: remove_dir_all ( & temp_dir) ;
1739+ }
1740+
16641741/// Test that auto-discover mode gracefully skips missing source files
16651742#[ test]
16661743fn test_compile_auto_discover_skips_missing_source ( ) {
0 commit comments