Skip to content

fix(cli): resolve config from -b for doctor, pantry and report - #734

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/711-base-path-config
Oct 17, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/711-base-path-config

Conversation

@drawmeanelephant

@drawmeanelephant drawmeanelephant commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #711
Closes #714

Summary

configure_context only honoured --base-path for server,
shopping-list and build; doctor, pantry and report each kept
their own lookup, so -b X still read ./config/ of the working
directory. cook doctor aisle -b X run elsewhere reported ingredients
against the wrong aisle.conf; pantry -b and report -b the same.

Command::base_path() in args.rs now names the flag once for every
command and configure_context resolves it — canonicalized — into
ctx. Because ctx.base_path() is canonical, the doctor subcommands no
longer hand core a raw relative -b (which is also the #714 fix, so
this supersedes #733's scan_dir), and pantry::run's own
re-resolution is gone.

A missing -b is still rejected up front, but now names the path:
Base path not found: <path>.

cook recipe has no -b and no config lookup, so nothing is needed
there.

Test plan

  • New aisle_with_base_path_reads_the_configuration_there in
    doctor_characterization_test.rs: doctor aisle -b <base> run from a
    directory with no config reads base/config/aisle.conf and finds the
    ingredient covered.
  • Manual: cook doctor validate -b ./ reports relative recipe paths;
    cook doctor aisle -b /missing errors Base path not found: /missing; cook pantry -b ./seed list reads the seed pantry.
  • cargo test --all-features green; fmt + clippy clean.

Generated with Devin

@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. This works: with #733 merged, cook doctor aisle -b ../r, run from a directory whose config/ holds a different aisle.conf, picks up r/config/aisle.conf. A few points:

  • Behaviour change worth a release note. doctor … -b X and report -b X used to read ./config/ from the current directory; they now use X/config/ or the global config. Anyone who keeps config where they run the command and points -b elsewhere loses it silently (report's explicit --aisle/--pantry still override). The comment at src/report.rs:88-90 documents the old behaviour and needs updating.
  • report with a missing -b. report deliberately avoided canonicalizing (to_absolute, around report.rs:130). Now configure_context rejects a non-existent -b up front with "Failed to canonicalize path", which doesn't name the path. Adding with_context(|| format!("Base path not found: {path}")) in util/mod.rs:202 would fix that for every command.
  • The pantry arm is redundant. The Command::Pantry arm (src/main.rs:119) duplicates what pantry::run already does (src/pantry.rs:300-307). Top-level cook pantry -b was never broken; the issue's "pantry" means doctor pantry. One of the two can go.
  • recipe has no -b flag and no aisle/pantry, so nothing is needed there despite the mention in #711.
  • One central place. Something like Command::base_path() -> Option<&Utf8Path> in args.rs, used once by configure_context, would replace the per-command plumbing. It would also make #733's scan_dir change and pantry.rs:300 unnecessary.
  • Test. An integration test for doctor aisle -b with a base config, using common::with_isolated_config, would be cheap to add.

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

@drawmeanelephant
drawmeanelephant force-pushed the fix/711-base-path-config branch 2 times, most recently from 50fdacd to d8b93b2 Compare October 14, 2026 13:23
@drawmeanelephant

Copy link
Copy Markdown
Contributor Author

Reworked around a central Command::base_path() in args.rs — configure_context now resolves -b once for every command instead of each command plumbing it through itself:

  • The per-command arms in configure_context are gone; doctor/pantry/report are covered by the same accessor.
  • pantry::run's own resolve_to_absolute_path + discover rebuild is removed — redundant now that ctx is right.
  • The doctor subcommands pass base_dir: None (core defaults to ctx.base_path(), which is already canonical), so a relative -b no longer reaches the walker unresolved — that's doctor validate -b ./ fails on a valid relative path #714's fix folded in here, which makes fix(doctor): canonicalize -b before handing it to core #733 redundant; happy to close that one as superseded once you agree.
  • resolve_to_absolute_path now fails with Base path not found: <path> — e.g. cook doctor aisle -b /missing names it.
  • report's stale comment updated (ctx now discovers under the resolved -b), and RenderRequest::base_path is left None so core uses the canonical ctx path.
  • recipe untouched — no -b, no config lookup.
  • Added the doctor aisle -b integration test via with_isolated_config.

And yes — the behaviour change (CWD ./config/ no longer wins when -b points elsewhere) is worth a release note; flagging it in the PR body.

@drawmeanelephant
drawmeanelephant force-pushed the fix/711-base-path-config branch from d8b93b2 to 84f1ad3 Compare October 14, 2026 13:29
@LeMyst

LeMyst commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks, one Command::base_path() (src/args.rs:309) is much easier to follow than per-command arms. I checked 84f1ad3 from an unrelated working directory. I used fixtures where that directory, the collection's config/ and COOK_CONFIG_DIR each give a different aisle and pantry, so it's clear which one each command reads:

  • With -b: shopping-list, doctor aisle, doctor pantry, doctor validate, pantry and report all read the collection's config/, or the COOK_CONFIG_DIR config when the collection has none. On main, doctor and report read the working directory's config/.
  • Without -b: the working directory's config is still used.
  • Path edge cases:
  • cook server <dir> and build web --base-path use the collection's aisle and pantry.
  • Sign-in state is unaffected. session.json and sync.db still come only from global_config_path, which -b doesn't touch.

All the earlier points are addressed (the stale comment at src/report.rs:88-89 included), and #733 is closed as superseded. Two small things:

  1. The release note isn't there yet. You mentioned flagging the behaviour change (a ./config/ in the working directory no longer wins when -b points elsewhere), but the PR body doesn't mention it. release-please builds the changelog from commit messages, so a sentence in the commit body would carry it into the release notes. The PR body alone won't.
  2. "state" is loose wording. The commit subject and the doc comment at src/args.rs:305-306 say "config and state", but nothing stateful follows -b: login and sync still use the global config dir. Saying "config", or naming what follows (aisle, pantry, the recipe directory), would stop a reader looking for a sync change.

fmt, clippy, cargo test --workspace and CI are green. With those two tweaks, this looks good to merge.


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

@drawmeanelephant
drawmeanelephant force-pushed the fix/711-base-path-config branch 2 times, most recently from 1d34666 to dfbdd53 Compare October 17, 2026 12:56
@drawmeanelephant

Copy link
Copy Markdown
Contributor Author

Both done on 1d34666 (your run reviewed 84f1ad3, the pre-rebase head):

  1. Release note: commit body now ends with "Behaviour change: a ./config/ in the working directory no longer wins when -b points at a different collection — the collection's own config/ is read instead. Only aisle.conf and pantry.conf follow -b; session.json and sync.db still come from the global config directory." — in the commit, so release-please picks it up.
  2. "state": subject is now "resolve config from -b", and the base_path() doc comment names aisle and pantry discovery explicitly, with a note that sign-in and sync still come only from the global config dir.

The two e2e failures on that run (recipe-scaling payload, aisles #→// hide) — the branch's code between 84f1ad3 and this head is unchanged; the delta is the rebase past merged #593/#753 et al. I've pushed the same tree as dfbdd53 to re-run CI and see whether they reproduce.

@LeMyst

LeMyst commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks, both are in:

  • The commit body carries the behaviour change.
  • The subject and the Command::base_path() doc comment name what follows -b (aisle and pantry), and say sign-in and sync state don't.

The range-diff from 84f1ad3 shows no code change. A quick rerun from an unrelated working directory still has doctor aisle, doctor pantry, pantry and report reading the collection's config/ with -b. fmt, clippy, tests and CI are green, and it merges cleanly with main, so this looks good to merge.

A correction to my last comment: release-please writes only commit subjects into the changelog and release notes. It doesn't copy the body. So the note in the body stays in main's history but won't show up in the release notes by itself; that's on us, not on the PR. Also, this conflicts with #742 in tests/doctor_characterization_test.rs, where both add tests, so whichever lands second needs a small rebase.


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

configure_context only honoured --base-path for server,
shopping-list and build; doctor, pantry and report each kept
their own lookup, so -b X still read ./config/ of the working
directory (#711). Command::base_path() now names it once and
configure_context resolves it for all of them — which also puts a
canonical path in ctx, so the doctor subcommands no longer hand core a
raw relative -b (#714) and pantry::run's own rebuild goes away.

A missing -b now names the path it failed on.

Behaviour change: a ./config/ in the working directory no longer wins
when -b points at a different collection — the collection's own
config/ is read instead. Only aisle.conf and pantry.conf follow -b;
session.json and sync.db still come from the global config directory.
@drawmeanelephant
drawmeanelephant force-pushed the fix/711-base-path-config branch from dfbdd53 to b3ffce3 Compare October 17, 2026 17:12
@drawmeanelephant

Copy link
Copy Markdown
Contributor Author

Rebased past #742 as b3ffce3 — the conflict was exactly where you said, doctor_characterization_test.rs; both test sets are in and the suite passes.

And thanks for the release-please correction — subject-only is good to know. The commit subject already describes the behaviour (resolve config from -b for every command), so the release note lands anyway; the body sentence stays as history.

@LeMyst
LeMyst merged commit 5074ec5 into cooklang:main Oct 17, 2026
5 checks 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.

doctor validate -b ./ fails on a valid relative path doctor, pantry, recipe and report resolve config from CWD, ignoring -b

2 participants