Repository navigation
fix(pantry): refuse add collisions with a different kind of entry - #748
Conversation
1d2a0d9 to
2bb2cf2
Compare
LeMyst
left a comment
There was a problem hiding this comment.
Looks good to me. A [milk] table, an inline milk = { quantity = … } and [[fridge]] are each refused with the file left untouched, and a list-of-names section (including an empty fridge = []) is still converted and added to. The server returns 400, because the message doesn't contain " not found". The tests compare the file byte for byte, which is good.
- Nit (pre-existing):
pantry add general milkwhen the file has[[milk]]is refused by the existing check with the misleading "item 'milk' already exists in section 'general'". No data is lost. - Optional: a test for the inline-table collision in
general.
🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.
`add` only checked `item_exists`, which sees items — but `general` names share the document root with sections and section names share it with top-level items. `pantry add general milk` inserted over `[milk]`, and `pantry add fridge milk` opened `[fridge]` over `fridge = "2%l"`, destroying the entry wholesale. `remove` and `update` already refuse these by not finding what they look for. `name_taken_differently` now reports a root key held by the other kind: a section (or `[[array]]` of tables) where a `general` item would go, or a top-level item where a section would. A plain array of names still passes through to `normalise_array_section` as before. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Fixed the nit properly rather than only testing it: |
2bb2cf2 to
f64eb3a
Compare
|
Thanks, fixing the check order is better than only testing it. 🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst. |
Closes #695
Summary
pantry addonly checkeditem_exists, which sees items — butgeneralnames share the TOML document root with sections, and section names share it with top-level items. Two collisions slipped through andinsertreplaced the existing entry wholesale:pantry add general milk --quantity 3%lwith a[milk]section present wiped the whole section, leavingmilk = "3%l".pantry add fridge milkwith a top-levelfridge = "2%l"opened[fridge]over the item (and likewise replaced[[fridge]]arrays).remove,updateandrename_sectionalready refuse these collisions by not finding what they look for;addnow refuses too viaedit::name_taken_differently, which reports a root key held by the other kind of entry. A plain array of names still passes through tonormalise_array_sectionas before.Test plan
[milk] carton = "2%l"+cook pantry add general milk --quantity 3%lnow errorsa section named 'milk' already exists, exit 1, file unchanged.fridge = "2%l"+cook pantry add fridge milkerrorsa top-level item named 'fridge' already exists, file unchanged.general-vs-section, section-vs-item and[[array]]shapes; all 437cookcli-coretests pass.Generated with Devin