Skip to content

Commit a057598

Browse files
fix: resolve check command source path from repo root (#120)
The check command resolved the header's source path relative to the pipeline YAML's parent directory. Since the header stores paths relative to the repository root (e.g. \�gents/ctf.md\), this doubled the directory prefix when the pipeline lived in a subdirectory (\�gents/agents/ctf.md\). Walk up from the pipeline file to find the .git directory and use that as the base for resolving the source path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 368acd4 commit a057598

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

src/compile/mod.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,23 @@ pub async fn check_pipeline(pipeline_path: &str) -> Result<()> {
209209
)
210210
})?;
211211

212-
// Resolve source path relative to the pipeline file's parent directory
213-
let source_path = pipeline_path
214-
.parent()
215-
.unwrap_or_else(|| Path::new("."))
216-
.join(&header_meta.source);
212+
// The header stores the source path relative to the repository root.
213+
// Walk up from the pipeline file to find the .git directory, then resolve
214+
// the source path relative to that root.
215+
let pipeline_abs = if pipeline_path.is_absolute() {
216+
pipeline_path.to_path_buf()
217+
} else {
218+
std::env::current_dir()
219+
.unwrap_or_else(|_| PathBuf::from("."))
220+
.join(pipeline_path)
221+
};
222+
let repo_root = find_repo_root(&pipeline_abs).with_context(|| {
223+
format!(
224+
"Could not find repository root (no .git directory) from {}",
225+
pipeline_path.display()
226+
)
227+
})?;
228+
let source_path = repo_root.join(&header_meta.source);
217229

218230
info!(
219231
"Checking pipeline integrity: {} -> {} (source from header)",
@@ -266,6 +278,19 @@ pub async fn check_pipeline(pipeline_path: &str) -> Result<()> {
266278
Ok(())
267279
}
268280

281+
/// Walk up from `start` to find the nearest directory containing `.git`.
282+
fn find_repo_root(start: &Path) -> Option<PathBuf> {
283+
let mut current = start.to_path_buf();
284+
loop {
285+
if current.join(".git").exists() {
286+
return Some(current);
287+
}
288+
if !current.pop() {
289+
return None;
290+
}
291+
}
292+
}
293+
269294
/// Normalize a string by removing all whitespace characters.
270295
///
271296
/// Used for integrity checks so that formatting-only differences

0 commit comments

Comments
 (0)