Skip to content

feat(doctor): show which recipes use each reported ingredient - #510

Merged
dubadub merged 2 commits into
mainfrom
feat/doctor-ingredient-recipe-sources
Sep 17, 2026
Merged

dubadub merged 2 commits into
mainfrom
feat/doctor-ingredient-recipe-sources

Conversation

@dubadub

@dubadub dubadub commented Sep 17, 2026

Copy link
Copy Markdown
Member

Closes #485.

cook doctor aisle lists the ingredients missing from aisle.conf, but not where they come from. As #485 points out, most of that list is not a missing aisle entry at all — it is one recipe spelling something the way the rest of the collection does not: ground cumin, cumin powder, cummin, cumin seed, ground. Some of those want an alias; most want the recipe fixed. Finding the odd file out meant grepping by hand.

What changes

Every reported ingredient now carries how many recipes write it, so a one-off spelling stands out against the established one with no extra flag:

11 ingredients not found in aisle configuration:
  - cumin powder (1 recipe)
  - ground cumin (12 recipes)
  - maple syrup (2 recipes)

Run `cook doctor aisle --show-recipes` to see which recipes use them.

--show-recipes names them:

  - cumin powder (1 recipe)
      Curries/Rogan Josh.cook
  - maple syrup (2 recipes)
      2 Day Plan.menu
      Weekly Plan.menu

The recipe list is uncapped. Truncating at three would hide exactly the stray file being hunted for.

cook doctor pantry reports the same way, so an item in stock says which of your recipes it is keeping off the shopping list.

Bare cook doctor keeps the counts and never the names — it summarises three checks, and naming every recipe behind every ingredient would bury it.

In core

CheckedIngredient gains recipes: Vec<Utf8PathBuf> — the recipes that write that ingredient, deduped, in path order, relative to the scanned directory (the form doctor validate already reports a recipe by). Spellings remain separate ingredients each with their own recipes, which is what makes the inconsistency findable at all.

known_entries() / unknown_entries() expose them. known() / unknown() are unchanged and delegate, so no existing consumer moves.

Tests

Four core unit tests (an ingredient shared by several recipes, one used twice in a single recipe counted once, each spelling keeping its own recipes, the pantry check tracking them too) and four CLI characterization tests (counts with singular/plural, --show-recipes including a nested path, the pantry equivalent, and bare cook doctor not naming files).

cargo fmt, cargo clippy --all-targets and cargo test are clean.

`cook doctor aisle` lists the ingredients missing from aisle.conf, but not
where they come from. Most of that list is not a missing aisle entry at all:
it is one recipe spelling something the way the other twelve do not — "cumin
powder" against "ground cumin", "cummin", "cumin seed, ground". Finding the
odd file out meant grepping the collection by hand.

Every reported ingredient now carries how many recipes write it, so the
one-off spelling stands out against the established one without asking for
anything extra. `--show-recipes` names those recipes, uncapped — a list
truncated at three would hide exactly the stray file being hunted for.

`cook doctor pantry` reports the same way, so an item in stock says which of
your recipes it is keeping off the shopping list.

Bare `cook doctor` keeps the counts and never the names: it summarises three
checks, and naming every recipe behind every ingredient would bury it.

In core, `CheckedIngredient` gains the recipes that write it, as paths
relative to the scanned directory — the form `doctor validate` already
reports a recipe by. Spellings stay separate ingredients, each with its own
recipes, which is what makes the inconsistency findable. `known_entries` and
`unknown_entries` expose them; `known` and `unknown` are unchanged.

Closes #485
@claude

claude Bot commented Sep 17, 2026

Copy link
Copy Markdown

Review

Read through the full diff (crates/core/src/doctor.rs, src/doctor.rs, docs/doctor.md, tests/doctor_characterization_test.rs) plus the surrounding code it touches (find.rs's walk/parse_or_skip/listed_ingredients, validate_entry/relative_to). Overall this is a clean, well-scoped feature addition -- nice work.

Code quality

  • known()/unknown() are refactored to delegate to the new known_entries()/unknown_entries() rather than duplicating the filter logic -- good, no behavior drift for existing consumers.
  • CheckedIngredient/IngredientCoverage stay #[non_exhaustive], so adding the recipes: Vec<Utf8PathBuf> field is non-breaking for external consumers of cookcli-core.
  • Switching the intermediate collection in coverage() from BTreeSet<String> to BTreeMap<String, BTreeSet<Utf8PathBuf>> is the right call -- it keeps both the ingredient order and the per-ingredient recipe order deterministic without a second sort pass.
  • Reusing relative_to (the same helper validate_entry uses) so doctor aisle/doctor pantry name files the same way doctor validate does is a nice consistency touch, and the fallback chain (entry.path() -> entry.name() -> "unknown") mirrors parse_or_skip's existing pattern rather than inventing a new one.
  • usage() and print_recipes() in src/doctor.rs are small and readable.

Bugs

Nothing that looks like a functional bug. I traced through:

  • Ingredient dedup within one recipe (listed_ingredients already returns a BTreeSet<String>, so @salt twice in one recipe still inserts one path into the set) -- matches the a_recipe_using_an_ingredient_twice_is_listed_once test.
  • Spelling variants (Salt vs salt) staying separate ingredients with their own recipe lists -- matches each_spelling_keeps_its_own_recipes.
  • The .menu case (aggregated ingredients attributed to the menu file's own path) is consistent with how .menu entries were already handled elsewhere.

Minor / nit-level observations (non-blocking)

  1. Hint message asymmetry: run_aisle prints a cook doctor aisle --show-recipes hint when the flag wasn't passed, but run_pantry has no equivalent hint. That might be intentional (the pantry list is about what's already covered, less of a "go fix this" prompt than the aisle list), but worth a quick sanity check that it wasn't just missed.
  2. usage() (src/doctor.rs:229) special-cases 1 with "(1 recipe)".to_string() vs the format! branch for other counts -- fine as written, just flagging in case a future edit to the plural form only touches one arm since they're not derived from a single format string.
  3. The recipe list under --show-recipes is intentionally uncapped per the PR description ("truncating at three would hide exactly the stray file being hunted for") -- reasonable for typo-hunting, but a collection where an ingredient is genuinely used in, say, 200 recipes will print all 200 paths. Opt-in via the flag though, so this seems like an acceptable tradeoff rather than a problem.

Performance

No concerns. The extra BTreeSet<Utf8PathBuf> per ingredient and the path.clone() per ingredient-in-recipe are proportional to collection size and only paid once per doctor aisle/doctor pantry invocation -- not a hot path.

Security

None. Purely local filesystem scanning and stdout formatting; no new untrusted input handling introduced.

Test coverage

Strong -- four core unit tests covering the sharing/dedup/spelling-separation/pantry cases, plus four CLI characterization tests covering count pluralization, --show-recipes with a nested path, the pantry equivalent, and confirming the bare cook doctor summary intentionally omits recipe names. The characterization tests also assert the absence of file names/hints where appropriate (.not()), which is a good way to lock in the "summary vs. detail" behavior split described in the PR body.

Note: I wasn't able to execute cargo fmt --check / cargo clippy / cargo test in this sandboxed review environment, so I can't independently confirm the "clean" claim in the PR description -- but the manual read-through didn't surface anything that looks like it would fail either.

🤖 Generated with Claude Code

The new tests wrote their expectations as `Breakfast/porridge.cook`, which
Windows prints as `Breakfast\porridge.cook`, so `doctor aisle --show-recipes`
failed there while passing everywhere else.

The output is right as it stands: a reported recipe is a file to go and open,
and `doctor validate` has always named one with the platform separator. It is
a Cooklang *reference* that must always be written with `/`, and that is a
different path (see `cooklang_format::REFERENCE_SEPARATOR`, #442).

So the expectations move rather than the output. Core compares `Utf8Path`s,
which compare component by component, and the CLI test spells the expected
line with `MAIN_SEPARATOR_STR`.
@claude

claude Bot commented Sep 17, 2026

Copy link
Copy Markdown

Review

Nicely scoped change with strong test coverage (4 core unit tests + 4 CLI characterization tests) and documentation that stays in sync with the behavior. Went through crates/core/src/doctor.rs, src/doctor.rs, docs/doctor.md, and the characterization tests. I wasn't able to run cargo build/test/clippy in this sandbox, so this is a static read — worth confirming CI is green.

Code quality

  • CheckedIngredient is already #[non_exhaustive], so adding the recipes field is not a breaking change for any external constructor — good foresight.
  • known()/unknown() now delegate to the new known_entries()/unknown_entries(), so existing consumers are unaffected. Confirmed no other call sites in the repo depend on the old filtered() signature.
  • The BTreeMap<String, BTreeSet<Utf8PathBuf>> swap in coverage() keeps both ingredient and recipe ordering deterministic, matching the existing "ordered so results don't depend on walk order" invariant.
  • Comments explain the non-obvious why (e.g. why relative_to's fallback can't fire, why --show-recipes output is uncapped) rather than restating the code, consistent with this repo's style.

Potential issues (minor, not blocking)

  1. docs/doctor.md example output is slightly incomplete. The non---show-recipes example under aisle only shows the ingredient list, but the actual CLI (per src/doctor.rs run_aisle) always appends Run \cook doctor aisle --show-recipes` to see which recipes use them.` when the flag isn't passed. Worth adding that line to the doc snippet so it matches real output.
  2. Asymmetric hinting between aisle and pantry. run_aisle nudges the user toward --show-recipes when it's not set (if !args.show_recipes { println!("\nRun ...") }), but run_pantry has no equivalent nudge when in_pantry is non-empty and the flag wasn't passed. Might be intentional (pantry items aren't "problems" to chase down the way aisle gaps are), but if the goal is a consistent UX it'd be worth adding the same hint there.
  3. Bare cook doctor still prints the aisle --show-recipes hint. Since run_aisle is invoked with show_recipes: false from the no-subcommand path too, the === Aisle Check === section in the summary will include Run \cook doctor aisle --show-recipes`.... That doesn't leak any recipe names, so it doesn't violate the stated goal ("never the names"), and arguably it's a helpful pointer — but it's worth confirming that's intended, since the new doctor_with_no_subcommand_counts_recipes_but_does_not_name_them` test only asserts the file name is absent, not whether this hint line is present.

Bugs

None found. The dedup logic (BTreeSet<Utf8PathBuf> per ingredient), the "used twice in one recipe counts once" behavior, and the per-spelling recipe tracking all check out against the tests and match the stated intent.

Performance

No concerns — the walk is still a single pass over recipes/ingredients; the added Utf8PathBuf clones are bounded by (ingredients × recipes) in a collection, which is small in practice.

Security

None applicable — this only reads local recipe files already within the scanned directory and prints their relative paths.

Test coverage

Good breadth: shared-ingredient-across-recipes, same-ingredient-twice-in-one-recipe, per-spelling recipe separation, pantry parity, and the no-subcommand "don't name files" guarantee are all covered. Nothing critical missing that I can see.

@dubadub
dubadub merged commit dca25c1 into main Sep 17, 2026
6 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.

Cook doctor ingredient list to identify source recipes

1 participant