Skip to content

fix relative path imports for config path#10

Merged
Bechma merged 1 commit intocyberfabric:mainfrom
Bechma:main
Mar 9, 2026
Merged

fix relative path imports for config path#10
Bechma merged 1 commit intocyberfabric:mainfrom
Bechma:main

Conversation

@Bechma
Copy link
Copy Markdown
Collaborator

@Bechma Bechma commented Mar 9, 2026

Summary by CodeRabbit

  • Refactor
    • Unified and simplified how CLI resolves workspace and config file paths across build, database, and module commands.
  • User-facing change
    • The config path is now expected explicitly (no implicit default); commands may require an explicit config file path where previously a default could be assumed.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

Refactors CLI config resolution: PathConfigArgs.config is now required, DEFAULT_CONFIG_FILE removed from the public API, and BuildRunArgs::resolve_workspace_and_config changed to an instance method using new PathConfigArgs helpers; call sites updated to match.

Changes

Cohort / File(s) Summary
Core API
crates/cli/src/common.rs
Made PathConfigArgs.config: PathBuf (was Option); removed DEFAULT_CONFIG_FILE; removed resolve_config_required/resolve_config_with_default; added resolve_config() and resolve_path(); changed BuildRunArgs::resolve_workspace_and_config(&self) to use new helpers.
Build & Run Call Sites
crates/cli/src/build/mod.rs, crates/cli/src/run/mod.rs
Replaced calls that passed a default config path with instance method self.br_args.resolve_workspace_and_config(); removed import/usage of DEFAULT_CONFIG_FILE.
Config Subcommands
crates/cli/src/config/db/mod.rs, crates/cli/src/config/modules/mod.rs
Swapped uses of resolve_config_required() for resolve_config() and switched workspace path resolution to resolve_path() where applicable.
Tests / Fixtures
crates/cli/src/config/modules/add.rs
Updated test constructors to set PathConfigArgs.config to a PathBuf (e.g., PathBuf::from(".")) instead of None to match required field change.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through paths both near and far,
Made configs firm — no optional spar,
Methods snug in their cozy nest,
Callers updated, all well dressed.
A tidy trail, a carrot snack — hooray! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix relative path imports for config path' directly relates to the main changes in the PR, which involve refactoring path and config resolution logic, removing DEFAULT_CONFIG_FILE constant, and updating method signatures to handle config paths without external arguments.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
crates/cli/src/common.rs (2)

29-33: Consider improving the error message for workspace path resolution.

Similar to the config path, the error message could be more descriptive to help users understand what went wrong.

Suggested improvement
     pub fn resolve_path(&self) -> anyhow::Result<PathBuf> {
         self.path
             .canonicalize()
-            .context("can't canonicalize workspace path")
+            .with_context(|| format!(
+                "workspace path '{}' not found or inaccessible",
+                self.path.display()
+            ))
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/cli/src/common.rs` around lines 29 - 33, The current resolve_path
method returns a generic "can't canonicalize workspace path" error; update
resolve_path to include the failing path value and more context by wrapping the
canonicalize error with a descriptive message (e.g., include self.path.display()
or similar) so the process that calls resolve_path sees which path failed and
why; locate the resolve_path function and modify the .context(...) call around
self.path.canonicalize() to include the path and a short human-readable message
referencing workspace path.

23-27: canonicalize() fails if the config file doesn't exist.

The canonicalize() call will return an error if the file path doesn't exist on disk. While load_config() also requires the file to exist, this creates an unclear error message ("can't canonicalize config") when users provide a path to a non-existent config file.

Consider providing a more helpful error message that guides users:

Suggested improvement for error clarity
     pub fn resolve_config(&self) -> anyhow::Result<PathBuf> {
         self.config
             .canonicalize()
-            .context("can't canonicalize config")
+            .with_context(|| format!(
+                "config file '{}' not found or inaccessible",
+                self.config.display()
+            ))
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/cli/src/common.rs` around lines 23 - 27, The resolve_config method
currently calls self.config.canonicalize() which fails with an unclear "can't
canonicalize config" when the path doesn't exist; change resolve_config to first
check existence (e.g., self.config.exists() or std::fs::metadata) and return a
clear error like "config file not found: <path>" if missing, otherwise call
canonicalize and keep a contextual error for canonicalization failures;
reference resolve_config and the canonicalize() call so the check and improved
error message are applied there (and keep behavior consistent with load_config
which also expects the file to exist).
crates/cli/src/config/modules/mod.rs (1)

117-120: Inconsistent path resolution: workspace_path is not canonicalized.

The config_path is resolved via resolve_config() which canonicalizes it, but workspace_path uses a direct clone without canonicalization. This could lead to inconsistent behavior when relative paths are provided.

Consider using the new resolve_path() helper for consistency:

Suggested fix
 pub(super) fn resolve_modules_context(
     path_config: &PathConfigArgs,
 ) -> anyhow::Result<ModulesContext> {
     Ok(ModulesContext {
-        workspace_path: path_config.path.clone(),
+        workspace_path: path_config.resolve_path()?,
         config_path: path_config.resolve_config()?,
     })
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/cli/src/config/modules/mod.rs` around lines 117 - 120, ModulesContext
is constructed with a non-canonicalized workspace_path
(path_config.path.clone()) while config_path uses path_config.resolve_config();
change workspace_path to use the same canonicalization helper by calling
path_config.resolve_path() (or the new resolve_path() helper) so both paths are
consistently resolved; update the ModulesContext construction to assign
workspace_path from the resolved result and handle the returned Result/err as
resolve_config() does.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/cli/src/common.rs`:
- Around line 29-33: The current resolve_path method returns a generic "can't
canonicalize workspace path" error; update resolve_path to include the failing
path value and more context by wrapping the canonicalize error with a
descriptive message (e.g., include self.path.display() or similar) so the
process that calls resolve_path sees which path failed and why; locate the
resolve_path function and modify the .context(...) call around
self.path.canonicalize() to include the path and a short human-readable message
referencing workspace path.
- Around line 23-27: The resolve_config method currently calls
self.config.canonicalize() which fails with an unclear "can't canonicalize
config" when the path doesn't exist; change resolve_config to first check
existence (e.g., self.config.exists() or std::fs::metadata) and return a clear
error like "config file not found: <path>" if missing, otherwise call
canonicalize and keep a contextual error for canonicalization failures;
reference resolve_config and the canonicalize() call so the check and improved
error message are applied there (and keep behavior consistent with load_config
which also expects the file to exist).

In `@crates/cli/src/config/modules/mod.rs`:
- Around line 117-120: ModulesContext is constructed with a non-canonicalized
workspace_path (path_config.path.clone()) while config_path uses
path_config.resolve_config(); change workspace_path to use the same
canonicalization helper by calling path_config.resolve_path() (or the new
resolve_path() helper) so both paths are consistently resolved; update the
ModulesContext construction to assign workspace_path from the resolved result
and handle the returned Result/err as resolve_config() does.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c984176e-4f7c-47c4-ad01-0deb0c87469a

📥 Commits

Reviewing files that changed from the base of the PR and between 30ef4f7 and a458b62.

📒 Files selected for processing (6)
  • crates/cli/src/build/mod.rs
  • crates/cli/src/common.rs
  • crates/cli/src/config/db/mod.rs
  • crates/cli/src/config/modules/add.rs
  • crates/cli/src/config/modules/mod.rs
  • crates/cli/src/run/mod.rs

Signed-off-by: Bechma <19294519+Bechma@users.noreply.github.com>
@Bechma
Copy link
Copy Markdown
Collaborator Author

Bechma commented Mar 9, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 9, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/cli/src/common.rs`:
- Around line 17-19: The CLI struct change made the config field mandatory (pub
config: PathBuf), breaking existing invocations; revert config back to
Option<PathBuf> and restore the previous fallback logic in
resolve_workspace_and_config() so that when config is None it uses
DEFAULT_CONFIG_FILE (or the same default path previously used), or alternatively
clearly document the breaking change—specifically, change the CLI struct's
config field back to Option<PathBuf> and update the call sites and
resolve_workspace_and_config() to accept Option<PathBuf> and apply the default
when None.
- Around line 23-26: The current resolve_config() uses
self.config.canonicalize(), which produces Windows verbatim paths (\\?\...) that
break when later embedded and normalized in prepare_cargo_server_main(); change
resolve_config to stop canonicalizing and instead return the original path
(e.g., return self.config.clone()/to_path_buf()) so the path string remains in
the same platform-native form the template serialization expects; reference
resolve_config and prepare_cargo_server_main and ensure any code that embeds the
path (the generated main.rs that calls PathBuf::from(...)) receives the
unmodified path string.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f0cc232c-59ae-4569-9f8c-ff5365551969

📥 Commits

Reviewing files that changed from the base of the PR and between a458b62 and e15e0be.

📒 Files selected for processing (6)
  • crates/cli/src/build/mod.rs
  • crates/cli/src/common.rs
  • crates/cli/src/config/db/mod.rs
  • crates/cli/src/config/modules/add.rs
  • crates/cli/src/config/modules/mod.rs
  • crates/cli/src/run/mod.rs
✅ Files skipped from review due to trivial changes (1)
  • crates/cli/src/config/modules/add.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • crates/cli/src/config/modules/mod.rs
  • crates/cli/src/config/db/mod.rs
  • crates/cli/src/build/mod.rs
  • crates/cli/src/run/mod.rs

@Bechma Bechma merged commit a97e1f2 into cyberfabric:main Mar 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant