Skip to content

fix(cart): don't report divergence when a fresh cart gets its address - #61

Open
rsdouglas wants to merge 3 commits into
yashiels:mainfrom
rsdouglas:fix/reconcile-unset-cart-address
Open

rsdouglas wants to merge 3 commits into
yashiels:mainfrom
rsdouglas:fix/reconcile-unset-cart-address

Conversation

@rsdouglas

Copy link
Copy Markdown

Problem

add and clear print "Cart write dispatched but the cart matches neither the intended nor the original state" (exit 6) even though the write succeeded. Reproduced live:

  • After checkout: the server rotates in an empty cart whose deliveryAddressId is "". The first add stamps the account address on it.
  • After clear: DELETE rotates in a new cart with deliveryAddressId: "".

reconcile compares each cart's address strictly, so "" → address (or the reverse) reads as a collateral per-cart address change, and the outcome is divergent.

Fix

In the reconcile comparison, an unset ("") per-cart address matches any address. One real address replacing another is still divergent; the existing collateral-change tests are unchanged and still pass. The top-level deliveryAddressId comparison is untouched.

Testing

  • make ci passes. Two new tests (fresh cart gets stamped; rotated cart comes back unaddressed) fail without the fix and pass with it.
  • Live: clear, then add to the fresh cart, then clear again. All three report ✅ Done; before the fix, each one exited 6.

Independent of #60.

After checkout, and after clear (DELETE rotates in a new cart), the
server's empty cart has deliveryAddressId "". The first write stamps the
account address on it, so reconcile saw "" -> address as a collateral
per-cart address change and reported "matches neither the intended nor
the original state" even though the write succeeded.

Treat an unset per-cart address as matching any address. One real
address replacing another is still divergent.
@rsdouglas
rsdouglas requested a review from yashiels as a code owner October 26, 2026 15:08

@sentinel-skyner sentinel-skyner Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Sentinel review

Please narrow the empty-address wildcard to the target cart so collateral address clears on other carts still diverge.

1 inline comment below.

Automated review via deepseek:deepseek-v4-pro + deepseek:deepseek-v4-pro verifier. Findings only — not an approval. Push new commits to re-review.

Comment thread src/lib/cart-mutate.ts Outdated
…otation

Review on yashiels#61: the empty-address wildcard applied to every cart, so a
collateral clear of a non-target cart's address read as success.

Now unset -> set matches only when the new address is the account
address (the server stamping a fresh cart), and set -> unset only on the
target cart (DELETE rotation). Everything else stays divergent.
Comment thread src/lib/cart-mutate.ts Outdated

@sentinel-skyner sentinel-skyner Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Sentinel review

The target-cart empty-address allowance is too broad for non-DELETE mutations; restrict it to rotations.

1 inline comment below.

Automated review via deepseek:deepseek-flash + deepseek:deepseek-v4-pro verifier. Findings only — not an approval. Push new commits to re-review.

…LETE

Codex review: set -> unset on the target cart was accepted for any write,
so a normal /carts/update that cleared the cart's address reported
success. It is now accepted only when the write was a DELETE and the
target cart came back with a new id.

The fake DELETE now clears the address like the real server, and the
old test that codified the unsafe case is replaced by a clear test and
a negative update test.
@rsdouglas

Copy link
Copy Markdown
Author

Second review pass: fixed in 316a806. The previous commit still accepted a target cart losing its address on a normal /carts/update, and one of its tests treated that as success. A target cart coming back unaddressed is now accepted only when the write was a DELETE and the cart came back with a new id. The fake DELETE now clears the address like the real server does. The unsafe test is replaced by a clear test plus a negative update test, which fails on the previous commit.

@sentinel-skyner sentinel-skyner Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Sentinel review

No material, actionable issues found in this diff.

Automated review via cursorbridge:gpt-5.3-codex. Findings only — not an approval. Push new commits to re-review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant