Repository navigation
fix(shopping-list): refuse scaling a recipe that makes nothing - #752
Conversation
LeMyst
left a comment
There was a problem hiding this comment.
Looks good to me. servings: 0, servings: "0" and yield: 0%g / 0.0%g all now give the new warning, and the reference is listed as written. That matches the policy from #682. The server gets the fix through core extract_ingredients, and the new key is in all 9 locales. UnscalableCause is #[non_exhaustive], so adding a variant breaks nothing. I also checked servings: 0.4 and -2: the parser rejects both, so they keep the existing NoServings warning.
Optional, same family of bug: yield: -500%g with @./sauce{500%g} lists tomatoes -4 without a warning. Using <= 0.0 instead of == 0.0 in zero_base (crates/core/src/shopping_list/mod.rs:1189, :1196) and target_factor (:1291, :1306) would cover negative bases too.
Nit: zero_base re-parses the servings and yield that target_factor already reads. If target_factor returned why it failed, there would be one copy.
🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.
4abb94d to
ec997ea
Compare
|
Done — negative bases are refused the same way as zero. On the |
|
Thanks, checked again on ec997ea. Two optional things, neither blocking:
Looks good to merge either way. 🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst. |
`target_factor` declines a zero base — `servings: 0` or `yield: 0%g` —
but the caller then fell through to `scale_to_target`, which divides by
the same zero, scales by infinity and answers `Ok`: the list read
`tomatoes inf` with no warning. A declared zero base is now refused as
unscalable before `scale_to_target` runs, so the reference is listed as
written and the recipe below it is not expanded.
The new `UnscalableCause::ZeroBase` words the warning as what to change
("it declares `servings: 0`, so there is nothing to scale from") rather
than pointing at servings or a yield the recipe already has. The page
shows it through a new `shopping-warning-zero-base` message in every
locale.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Both taken: |
ec997ea to
5c8c5b8
Compare
Closes #699
Summary
cook shopping-list main0.cookon a recipe referencing@./sauce0{6%servings}wheresauce0.cookdeclaresservings: 0printed
tomatoes inf, exit 0, no warning.target_factoralready declines a zero base (servings: 0/yield: 0%g) by returningNone— but the caller then fell through tocooklang'sscale_to_target, which divides by the same zero, scales byinfinity and returns
Ok.servings: 0is a whole number of servings,so cooklang's own
InvalidServingsrefusal never fires.Changes
zero_basecheck inshopping_list::expandruns beforescale_to_target: a declared-but-zero base (servings: 0for aservings target,
yield: 0%unitin the asked unit) takes the existingUnscalableReferencepath — warning, reference listed as written,nothing below it expanded. A yield in another unit still reports the
unit mismatch, not a zero base.
UnscalableCause::ZeroBaseso the advice names the actualproblem — "it declares
servings: 0, so there is nothing to scalefrom" — instead of pointing at servings or a yield the recipe already
has.
warning_textmaps it to a newshopping-warning-zero-basemessage,added to all nine locales (
locales_testparity).Test plan
a_zero_servings_recipe_is_unscalable_not_scaled_by_infinityanda_zero_yield_recipe_is_unscalable_not_scaled_by_infinitypin theZeroBasediagnostic and thattomatoesis never listed.cook shopping-list main0.cooknow warns"Could not scale recipe reference 'sauce0' to 6 servings: it declares
servings: 0, so there is nothing to scale from" and listssauce0 6 servings— neverinf.cargo test --all-featuresgreen.Generated with Devin