Repository navigation
fix(shopping-list): count a ring of nested menus once - #811
Merged
Merged
Conversation
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
marked this pull request as ready for review
October 28, 2026 21:45
dubadub
approved these changes
Nov 24, 2026
dubadub
left a comment
Member
There was a problem hiding this comment.
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-listdoes.ExtractOptionsgetswithin: Option<&str>, the menu a recipe is listed under. Its file heads the chain of ancestors the cycle check walks, soB→C→Ais refused atA(with the usual cycle warning namingA.menu → B.menu → C.menu → A.menu). It is resolved with the sameconfinedrule as the starting recipe. Every other caller passesNoneand behaves as before.POST /api/shopping_listentry takes an optionalmenu, which goes throughcheck_pathand 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 withoutmenuis expanded as before, so older clients get the old behaviour, not an error.shopping_list.htmlsendsmenu: item.pathfor every recipe it expands from a menu entry.docs/api.mdis 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 bywithin.The cycle warning stays in the server log, like the two-menu one: the page's
warningsonly carry references that couldn't be scaled.Tests
a_menu_expanded_within_another_does_not_count_it_again: A → B → C → A, expanding A's meals. Withoutwithin, 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. Withoutmenuit gives 4 eggs instead of 2.shopping-list-nested-menus.spec.ts: a ring of three in the seed, added withadd_menu; the shopping list page sendsmenufor each meal, and the answer it renders has each ingredient once. It fails against the old page.cargo clippy --all-targets --workspaceclean;cargo test --workspace1874 passed. Full chromium Playwright run green, apart from the specs that spawntarget/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