From fbbaca105d41690768175712bc47314c0acbaba2 Mon Sep 17 00:00:00 2001 From: Finjineersdev Date: Sat, 28 Nov 2026 03:08:17 +0500 Subject: [PATCH] fix(cli): accept relative project paths in plan and clean `opensweep plan .` or `opensweep clean ../site` refused every folder with "path is not absolute": the project path reached the guard as typed, and the guard (rightly) refuses relative candidates. `scan` and `pin` already resolve their paths. plan and clean now make a relative project path absolute first; absolute paths are passed on unchanged. Co-Authored-By: Claude Opus 5.5 --- engine/crates/opensweep-cli/src/main.rs | 14 ++++++++++++-- engine/crates/opensweep-cli/tests/cli.rs | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/engine/crates/opensweep-cli/src/main.rs b/engine/crates/opensweep-cli/src/main.rs index 18e4f85..644bf86 100644 --- a/engine/crates/opensweep-cli/src/main.rs +++ b/engine/crates/opensweep-cli/src/main.rs @@ -245,7 +245,7 @@ fn main() -> ExitCode { other_drives, &store, ), - Cmd::Plan { rules, project } => plan(rules.as_deref(), &project), + Cmd::Plan { rules, project } => plan(rules.as_deref(), &absolute(&project)), Cmd::Clean { rules, include_caution, @@ -256,7 +256,7 @@ fn main() -> ExitCode { projects, } => clean( rules.as_deref(), - &projects, + &projects.iter().map(|p| absolute(p)).collect::>(), Flags { caution: include_caution, active: include_active, @@ -301,6 +301,16 @@ fn main() -> ExitCode { }) } +/// A project path typed relative to the working folder (`plan .`), made +/// absolute: the guard refuses every relative candidate. Absolute paths and +/// folders that do not exist are left as given. +fn absolute(project: &Path) -> PathBuf { + if project.is_absolute() { + return project.to_path_buf(); + } + std::fs::canonicalize(project).unwrap_or_else(|_| project.to_path_buf()) +} + fn load_rules(dir: Option<&Path>) -> Result, String> { match dir { Some(d) => rules::load_dir(d), diff --git a/engine/crates/opensweep-cli/tests/cli.rs b/engine/crates/opensweep-cli/tests/cli.rs index 3202f75..a72a6ef 100644 --- a/engine/crates/opensweep-cli/tests/cli.rs +++ b/engine/crates/opensweep-cli/tests/cli.rs @@ -118,6 +118,30 @@ fn clean_is_a_dry_run_by_default() { ); } +#[test] +fn a_project_given_relative_to_the_working_folder_is_checked() { + let e = env(); + let run_in_project = |args: &[&str]| { + let out = Command::new(env!("CARGO_BIN_EXE_opensweep")) + .args(args) + .current_dir(&e.project) + .env("HOME", &e.home) + .env_remove("XDG_DATA_HOME") + .env_remove("XDG_CONFIG_HOME") + .output() + .unwrap(); + assert!(out.status.success(), "{args:?}"); + String::from_utf8(out.stdout).unwrap() + }; + let plan = run_in_project(&["plan", "--rules", RULES, "."]); + assert!(plan.contains("allow .next"), "{plan}"); + assert!(!plan.contains("not absolute"), "{plan}"); + let store = e.store.to_str().unwrap(); + let clean = run_in_project(&["clean", "--rules", RULES, "--store", store, "../site"]); + assert!(clean.contains("move .next"), "{clean}"); + assert!(clean.contains("Dry run"), "{clean}"); +} + #[test] fn a_folder_two_rules_claim_is_offered_once() { let e = env();