Skip to content

Commit 689825c

Browse files
fix: strip redundant ./ prefixes from source path in header comment (#106)
compile_all_pipelines joins Path(".") with the source path read from a previously generated header. Each recompilation prepended another "./", causing paths like ././././agents/release-readiness.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 28721a9 commit 689825c

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/compile/common.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,19 @@ pub const HEADER_MARKER: &str = "# @ado-aw";
476476
/// are normalized to forward slashes for cross-platform consistency.
477477
pub fn generate_header_comment(input_path: &std::path::Path) -> String {
478478
let version = env!("CARGO_PKG_VERSION");
479-
let source_path = input_path
479+
let mut source_path = input_path
480480
.to_string_lossy()
481481
.replace('\\', "/")
482482
.replace('\n', "")
483483
.replace('\r', "")
484484
.replace('"', "\\\"");
485485

486+
// Strip redundant leading "./" prefixes to prevent accumulation when
487+
// compile_all_pipelines re-joins paths through Path::new(".").join(source).
488+
while source_path.starts_with("./") {
489+
source_path = source_path[2..].to_string();
490+
}
491+
486492
format!(
487493
"# This file is auto-generated by ado-aw. Do not edit manually.\n\
488494
# @ado-aw source=\"{}\" version={}\n",
@@ -1039,4 +1045,26 @@ mod tests {
10391045
.expect("Should parse header with escaped quotes");
10401046
assert_eq!(meta.source, r#"agents/my "agent".md"#);
10411047
}
1048+
1049+
#[test]
1050+
fn test_generate_header_comment_strips_dot_slash_prefixes() {
1051+
let path = std::path::Path::new("././././agents/release-readiness.md");
1052+
let header = generate_header_comment(path);
1053+
assert!(
1054+
header.contains(r#"source="agents/release-readiness.md""#),
1055+
"Redundant ./ prefixes should be stripped: {}",
1056+
header
1057+
);
1058+
}
1059+
1060+
#[test]
1061+
fn test_generate_header_comment_strips_single_dot_slash() {
1062+
let path = std::path::Path::new("./agents/my-agent.md");
1063+
let header = generate_header_comment(path);
1064+
assert!(
1065+
header.contains(r#"source="agents/my-agent.md""#),
1066+
"Single ./ prefix should be stripped: {}",
1067+
header
1068+
);
1069+
}
10421070
}

0 commit comments

Comments
 (0)