Skip to content

Commit be2e1c4

Browse files
fix(compile): resolve autodiscovered source path relative to lock file directory (#616)
* Initial plan * fix(compile): resolve autodiscovered source relative to lock file dir Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/5e7af66a-15e9-4ef7-8595-d4a1e397c08f Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
1 parent cb4eec2 commit be2e1c4

2 files changed

Lines changed: 87 additions & 1 deletion

File tree

src/compile/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,17 @@ pub async fn compile_all_pipelines(skip_integrity: bool, debug_pipeline: bool) -
382382
let mut rewrote_count = 0;
383383

384384
for pipeline in &detected {
385-
let source_path = root.join(&pipeline.source);
386385
let yaml_output_path = root.join(&pipeline.yaml_path);
386+
let source_candidate_from_yaml_dir = yaml_output_path
387+
.parent()
388+
.unwrap_or(root)
389+
.join(&pipeline.source);
390+
let source_candidate_from_root = root.join(&pipeline.source);
391+
let source_path = if source_candidate_from_yaml_dir.exists() {
392+
source_candidate_from_yaml_dir
393+
} else {
394+
source_candidate_from_root
395+
};
387396

388397
if !source_path.exists() {
389398
eprintln!(

tests/compiler_tests.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.\nstdout: {}\nstderr: {}",
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]
16661743
fn test_compile_auto_discover_skips_missing_source() {

0 commit comments

Comments
 (0)