Skip to content

fix(doctor): canonicalize -b before handing it to core - #733

Closed
drawmeanelephant wants to merge 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/714-doctor-relative-base
Closed

drawmeanelephant wants to merge 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/714-doctor-relative-base

Conversation

@drawmeanelephant

Copy link
Copy Markdown
Contributor

Closes #714

cook doctor validate -b ./ passed the raw ./ to core, whose search layer could not express found recipes relative to it (Cannot search './'). All three subcommands now run the flag through resolve_to_absolute_path first, matching what the other commands do.

Test plan

  • cook doctor validate -b ./ and -b . validate the directory's recipes
  • cook doctor validate -b /nonexistent still errors cleanly

The doctor subcommands passed `args.base_path` to core verbatim, so
`cook doctor validate -b ./` reached the search layer as `./` and
failed with "cannot express bom.cook relative to it" while `cook
search -b ./` worked. Run the flag through
`resolve_to_absolute_path` like the other commands do.

Closes #714

@LeMyst LeMyst left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks. The \\?\ concern doesn't apply on Windows: configure_context already canonicalizes ctx.base_path the same way, so -b now just matches the default. Two points:

  • The error no longer names the path. cook doctor validate -b /nonexistent now prints only "Error: Failed to canonicalize path" (plus an ERROR log line). Before, core said "Cannot search '…': no such directory". shopping-list -b and pantry -b already have the same generic message, because util/mod.rs:202 adds no path context. with_context(|| format!("Base path not found: {path}")) there would fix it everywhere.
  • Overlap with #734. Once #734 lands, ctx.base_path is the canonicalized -b for doctor, and core already defaults base_dir to ctx.base_path (crates/core/src/doctor.rs:254). So scan_dir (src/doctor.rs:206, used at 284/326/372) could simply pass base_dir: None. It might be simplest to fold this into #734.

A regression test for -b ./ would be nice.


🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.

@drawmeanelephant

Copy link
Copy Markdown
Contributor Author

Superseded by #734 per the review suggestion. There, configure_context already canonicalizes -b into ctx.base_path, so the coverage calls pass base_dir: None and the per-command scan_dir never existed. The path-naming error (Base path not found: {path} in util::resolve_to_absolute_path) and a doctor validate -b ./ regression test both live on that branch too.

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.

doctor validate -b ./ fails on a valid relative path

2 participants