Skip to content

fix(shopping-list): count a ring of nested menus once - #811

Merged
dubadub merged 1 commit into
cooklang:mainfrom
LeMyst:fix/nested-menu-cycles
Nov 24, 2026
Merged

dubadub merged 1 commit into
cooklang:mainfrom
LeMyst:fix/nested-menu-cycles

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Closes #810

A recipe expanded from a menu entry on the shopping list is now expanded as part of that menu, so a ring of nested menus of any length counts each recipe once, as cook shopping-list does.

  • Core: ExtractOptions gets within: Option<&str>, the menu a recipe is listed under. Its file heads the chain of ancestors the cycle check walks, so B → C → A is refused at A (with the usual cycle warning naming A.menu → B.menu → C.menu → A.menu). It is resolved with the same confined rule as the starting recipe. Every other caller passes None and behaves as before.
  • Server: each POST /api/shopping_list entry takes an optional menu, which goes through check_path and the collection check before it is looked up (the route is guest-reachable). When the server rebuilds the stored list to compact ticks, it passes the menu of each nested entry as well. An entry without menu is expanded as before, so older clients get the old behaviour, not an error.
  • Page: shopping_list.html sends menu: item.path for every recipe it expands from a menu entry.
  • docs/api.md is regenerated with the new parameter.

The two-menu case keeps its existing handling in add_menu (dropping the reference straight back); it is now also covered by within.

The cycle warning stays in the server log, like the two-menu one: the page's warnings only carry references that couldn't be scaled.

Tests

  • Core a_menu_expanded_within_another_does_not_count_it_again: A → B → C → A, expanding A's meals. Without within, rice is 200 g (the bug); with it, every ingredient is 100 g, and the cycle is named.
  • menu_in_menu_test::menus_in_a_ring_of_three_are_counted_once: add_menu, then the list the way the page asks for it. Without menu it gives 4 eggs instead of 2.
  • New shopping-list-nested-menus.spec.ts: a ring of three in the seed, added with add_menu; the shopping list page sends menu for each meal, and the answer it renders has each ingredient once. It fails against the old page.
  • cargo clippy --all-targets --workspace clean; cargo test --workspace 1874 passed. Full chromium Playwright run green, apart from the specs that spawn target/debug/cook, which doesn't exist in my local setup. The shopping-list and pantry specs were rerun with --workers=1, as on CI.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MmrM91dHzvQoaerCcR9wra

A menu added to the shopping list keeps its meals as entries of their
own, and a menu used as one of them (`B` in `A`) is expanded from there,
on its own. Only a reference straight back to `A` was dropped, so with
three menus in a ring, `A` → `B` → `C` → `A`, B's expansion went on
through `C` into `A` and counted A's recipes a second time. The CLI
already counted them once.

A recipe expanded from a menu entry now names that menu (`within` in
core's `ExtractOptions`, `menu` in a `POST /api/shopping_list` entry),
and the menu heads the chain of ancestors the cycle check walks: the
reference back to `A` is refused, however long the ring. The shopping
list page sends it, and so does the server when it rebuilds the stored
list to compact ticks. An entry without it is expanded as before.

Since menus could be meals of each other, d99192b (cooklang#609).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmrM91dHzvQoaerCcR9wra
@LeMyst
LeMyst marked this pull request as ready for review October 28, 2026 21:45

@dubadub dubadub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this is a clean fix: making the parent menu the start of the ring check fixes rings of any length, the new menu field gets the same path checks as recipe, and requests without it behave as before. I checked it merged with current main (fmt, clippy, the core shopping-list tests, menu_in_menu_test and the API docs test all pass).

@dubadub
dubadub merged commit c0d798c into cooklang:main Nov 24, 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.

Shopping list counts a recipe twice when three or more menus reference each other in a ring

2 participants