← Back to Pull requests

fix: recipe card and chat card 'N to buy' keys add grocery lines with amounts (#868) #882

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 01, 2026 21:57 UTC
Author

Summary


The recipe card's own "Add to grocery list" key (the dish card on a saved meal's page, and the recipe card in chat) used to put bare names on the grocery list: every line read "Add amount" and landed under "Other". They now add what the meal page's to-buy line has added since PR #860: amount, unit and, for a saved meal, category. An amount already on a list line is never overwritten (the same addMissingToGroceryList rule).

What changes


  • Dish card (saved meal). The meal page already fetches the meal's to-buy detail (fetchMealToBuyDetail); it now also builds each dish's list entries from it (toBuyEntriesByDish) and passes them to the card as toBuyEntries. Same entries, same order as the names the card shows.

  • Chat recipe card. It is not a saved meal, so there is no meal id to ask /v1/grocery/meal-to-buy about. The card adds each missing food (from the pantry grading, ingredient_availability) with the amount and unit from the card's own ingredient list (toBuyEntriesFromRecipe).

  • ToBuyLine takes an optional entries (what the key adds) next to items (what it displays); addItemsToMyGroceryList accepts amounts. No change to what the line displays.

  • Every other "N to buy" surface was checked: the meal page line already adds amounts (#860); the option and compact cards have no add key.
  • Verify


    Production build of this branch (stack.sh up, commit f34f155e code; the later commit only adds screenshots) against main built from git archive origin/main. Playwright as the e2e test user, 390 px wide. Walk: click the card's "Add to grocery list", open /grocery, read the rows back.

    | Flow | Main | This PR |
    |---|---|---|
    | Dish card, saved meal (feta 200 g, parsley, 2 lemon) | Feta / Parsley / Lemon: "Add amount", all under Other | Feta 200 g (Dairy), Lemon 2 (Produce), Parsley "Add amount" (recipe gives none; Produce) |
    | Chat recipe card (50 g parmesan, 2 lemon missing) | Parmesan / Lemon: "Add amount" | Parmesan 50 g, Lemon 2 |

    | | Dish card | Chat card |
    |---|---|---|
    | Main | ![](https://github.com/ayushb3/BubblyChef/blob/aba3b25374a8794f6bdaa21aec07be227e12169f/docs/media/issue-868/dish-card-grocery-before.png?raw=true) | ![](https://github.com/ayushb3/BubblyChef/blob/aba3b25374a8794f6bdaa21aec07be227e12169f/docs/media/issue-868/chat-card-grocery-before.png?raw=true) |
    | This PR | ![](https://github.com/ayushb3/BubblyChef/blob/aba3b25374a8794f6bdaa21aec07be227e12169f/docs/media/issue-868/dish-card-grocery-after.png?raw=true) | ![](https://github.com/ayushb3/BubblyChef/blob/aba3b25374a8794f6bdaa21aec07be227e12169f/docs/media/issue-868/chat-card-grocery-after.png?raw=true) |

    Smoke suite (minus "AI round trip") passed: 4/4. Neighbours walked: the card's confirmation ("N on your grocery list") and the /grocery page.

    Mocked: every AI-service /v1/ call was blocked in the browser (no model calls); the saved meal (GET /api/meals/:id), POST /api/ai/grocery/meal-to-buy and the chat stream were stubbed with fixed payloads. Not verified: the real meal-to-buy endpoint on a real saved meal, and a real chat recipe turn (no live Gemini). The grocery list is localStorage, so nothing was written to the hosted DB.

    Tests


    New card-to-buy-amounts.test.tsx (10 tests): entry builders, the dish card handing entries on, and both cards writing amounts to the real list through the real store, including "a typed amount is kept". Red on main: 9 of 10 failed (the "never overwrites" case passes there trivially because a bare name carries no amount). Green here. One existing assertion in recipe-card-chat-and-compact-row.test.tsx expected the bare name ['Lemon']; it now expects the entry with the recipe's amount. Full jest 3736 passed, tsc --noEmit clean, eslint src 0 errors.

    Decisions


  • Chat card amounts come from the card's own ingredients, on the client. No endpoint gives amounts for a recipe that isn't a saved meal: /v1/grocery/meal-to-buy takes a meal id, /api/ai/pantry/match-ingredients returns have/low/missing without a buy amount. A food graded "missing" has nothing usable on hand, so its recipe amount is the amount to buy (the service's own rule for the meal line). Rejected: saving the recipe as a meal just to ask the endpoint (a write the user didn't ask for).

  • Chat card lines have no category (they file under "Other"): nothing on the card knows it, and the only client-reachable source is the LLM-backed estimate-category, which this must not call. Rejected: a client-side guess table.

  • A dish card adds the meal's amount for a shared food, not the dish's share. The service sums a food across dishes. Two cards sharing parsley both add the same entry and the list keeps the first amount, so nothing double counts. Rejected: re-deriving per-dish amounts on the client (would duplicate the service's matching).

  • List names use the service's name (dish card) or the recipe's wording (chat card),** so a food the meal line already added is adopted rather than duplicated.
  • Linked


    Fixes #868

    Out of scope


  • Category for chat-card lines; unit conversion between a typed amount and a recipe's (issue #6, existing: the typed amount simply wins).

  • Meal page to-buy line, option/compact cards (unchanged).
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: claude[bot] Review duration: 7m
    All Vouch review confidence checks passed
    Residual risk 0.37 = Change Risk (0.52) × (1 − Review Confidence (0.29)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 48% · Reviewer familiarity: 35%
    29%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #882"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 29.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 29.4% · Lower = rushed or shallow review
    29.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 36.7% · Moderate risk
    36.7%