fix(address-book): base mutations on certified data - #8006
Conversation
|
✅ No security or compliance issues detected. Reviewed everything up to 23e8224. Security Overview
Detected Code Changes
|
There was a problem hiding this comment.
🟡 Changes recommended
There are confirmed correctness/UX edge cases in the new mutation logic (notably inconsistent name normalization for removals and post-save reload behavior that can leave the store uncertified/stale).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens the address-book write path by ensuring mutations are always applied on top of freshly fetched certified backend data (rather than potentially stale/uncertified store/query data), and updates the UI flows/tests accordingly.
Changes:
- Refactored
saveAddressBookto accept explicit mutation objects (add/update/remove) and apply them to certified backend state before writing. - Disabled add/remove confirmation actions while the address book store is not certified.
- Added/updated Vitest coverage for certified-mutation behavior and disabled controls.
File summaries
| File | Description |
|---|---|
| frontend/src/lib/services/address-book.services.ts | Introduces mutation-based saving and applies writes atop certified backend data. |
| frontend/src/lib/modals/common/ConfirmationModal.svelte | Adds disabledConfirm to disable the confirm button under external conditions. |
| frontend/src/lib/modals/address-book/RemoveAddressModal.svelte | Switches remove flow to mutation-based save and disables confirm when uncertified. |
| frontend/src/lib/modals/address-book/AddAddressModal.svelte | Switches add/edit flows to mutation-based save and disables save when uncertified. |
| frontend/src/tests/lib/services/address-book.services.spec.ts | New unit tests verifying mutations are based on certified backend data. |
| frontend/src/tests/lib/modals/address-book/RemoveAddressModal.spec.ts | New modal tests for mutation invocation and disabled confirm when uncertified. |
| frontend/src/tests/lib/modals/address-book/AddAddressModal.spec.ts | Updates expectations for mutation payloads and adds disabled-save test for uncertified state. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| case "remove": { | ||
| const addresses = namedAddresses.filter( | ||
| ({ name }) => name !== mutation.name | ||
| ); | ||
| if (addresses.length === namedAddresses.length) { | ||
| throw new Error("The address book entry no longer exists."); | ||
| } | ||
| return addresses; | ||
| } |
| await setAddressBook({ identity, namedAddresses }); | ||
| await loadAddressBook(); |
Motivation
Address-book writes used local query data as their base. A later valid edit could save entries from an uncertified response.
Changes
Tests
npm run checknpx tsc --noEmit -p tsconfig.spec.jsonTodos