Repository navigation
fix(shopping-list): merge case-variant ingredients into one item - #747
Conversation
LeMyst
left a comment
There was a problem hiding this comment.
Thanks. This fixes the CLI's categorised output, but two parts of #694 remain.
1. The web UI isn't fixed
src/server/handlers/shopping_list.rs:165 still calls final_list.categorize(&aisle), and this PR doesn't touch that file. So POST /api/shopping_list still returns only Sugar, which doesn't meet the issue's "the web UI answer contains both names". The new categorize (crates/core/src/shopping_list/mod.rs:351) is private, so the server can't reuse it.
2. Keeping the variants separate under-buys when the pantry has stock
Pantry lookup is case-insensitive (PantryConf::find_ingredient lowercases), so stock is subtracted from each variant. With @sugar{100%g} @Sugar{200%g} and pantry sugar = "100%g", the list shows Sugar 100 g; the right answer is 200 g. This predates the PR (the flat items view already did it), but the PR leaves it in place. Aisle lookup and the server's checked set (store.rs:377) are case-insensitive too, so ticking sugar also ticks Sugar.
Suggestion
Merge case variants into one entry under the first spelling seen, before use_common_names and the pantry step, in generate and in the server's merged() (shopping_list.rs:755). That fixes the CLI, the web UI and the pantry problem in one place, and #694 explicitly allows "or their sum". The root cause is cooklang-rs's IngredientList::categorize, which could also get an upstream issue.
Minor points
- The doc comment on
build(mod.rs:289) still points toIngredientList::categorize. - The "other" bucket now orders items
sugar, Sugar, flour, whileitemshassugar, flour, Sugar. - Non-ASCII: É/é stay apart and ß/SS don't fold, which matches aisle and pantry lookup, so that's fine.
- Tests: there is one core test, but none for the server or the pantry case.
This merges cleanly with #752, but needs a rebase after it if the merging moves into generate.
🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.
02e365c to
bafa8c7
Compare
|
Reworked per review: case variants now merge into one entry under the first spelling seen in |
|
Thanks for the rework. I checked it against the PR's binary. One small optional addition: 🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst. |
bafa8c7 to
881c966
Compare
|
Done on 881c966 — all three spots now say the merge ignores letter case and keeps the first spelling: |
sugar and Sugar travelled the pipeline as two ingredients, but the pantry, the checked set and the aisle all match case-insensitively — so upstream's categorize showed only the last variant, and each variant was charged the same pantry stock. Merge them in generate and the server's merged() under the first spelling seen, before use_common_names and the pantry subtraction, so the CLI, the web list and the pantry all see one correct total. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
881c966 to
a924455
Compare
|
Re-checked a924455 after the rebase onto #593's optional ingredients. Merging case variants separately for the required and the optional list, before the pantry step, is the right way round: I ran each case from the CLI and through
fmt, clippy and One cosmetic thing, already on 🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst. |
|
Thanks for the re-check — good to hear the required/optional split lines up with On |
Closes #694
Summary
sugarandSugartravelled the whole pipeline as two ingredients, but everything downstream matched case-insensitively — upstream'scategorizeshowed only the last variant, and the pantry's stock was subtracted from each variant (sugar 100 g+Sugar 200 gwith100 gstocked showed 100 g to buy instead of 200 g). The server's checked set ticked both variants too.merge_case_variantsincookcli_core::shopping_listnow folds case variants into one entry under the first spelling seen, summing quantities withadd_ingredient. It runs ingenerate(beforeuse_common_namesand the pantry subtraction) and in the server'smerged(), so the CLI list,POST /api/shopping_listand the pantry all see one correct total — which #694 allows ("or their sum").Test plan
Add @sugar{1%cup} and @Sugar{2%cup}.lists onesugar 3 cupin both flat and categorised views.@sugar{100%g}+@Sugar{200%g}with pantrysugar = "100%g"leaves200 g, not100 g— covered in core (merged_case_variants_subtract_the_pantry_once) and end-to-end viaPOST /api/shopping_list(case_variants_merge_and_share_the_pantry_once).Generated with Devin