None of these were caught by 105 green tests, because the code they live in was barely tested and the HTTP path was not tested at all. 1. reconcilePendingOrders hardcoded category 'dining', so any order resolved through the deferred path booked as dining regardless of merchant — a Woolworths grocery order that parks and later reconciles was misfiled. That reintroduced, through the back door, exactly the misfiling resolveCategory() exists to prevent. Now calls it. 2. reconcileCardLeg never marked a statement line as consumed, so two orders on the same card inside the +/-4 day window both bound to the same charge and each booked its own credits remainder — double-counting spend. At 10-15 orders a month on one card that is not a corner case. Migration 0020 adds matched_transaction_id with a unique index; the matcher now excludes lines already claimed. 3. The ingest API returned HTTP 200 for every parse failure, and the Slack alert fires only on non-200. So the single most likely production failure — a provider template change breaking every order at once — was completely silent. Split into NotAReceiptError (promotions, delivery updates, refund and adjustment notices: 200, silent, expected traffic) and OrderParseError (it IS a receipt and would not parse: 422, alerts). Also: order_reference now anchors on Uber's own tripReference cell rather than 'first UUID in the document'. I had claimed to verify that the first UUID was always the order UUID; that check compared against zero samples and was vacuous. tripReference is present in all 29 captured receipts and, for ue-00, equals the UUID the PDF redirect resolves to. The positional fallback remains but only flags when there is genuine ambiguity. Adds the API route's first tests — auth gate and error taxonomy — plus anchoring regressions. 63 unit + 53 integration green on five consecutive runs; corpus holds at 63/65.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
-- Which statement line settled an order's card leg.
|
||||
--
|
||||
-- Without this, reconcileCardLeg has no way to know a charge has already been
|
||||
-- consumed, so two orders on the same card inside the match window both bind to
|
||||
-- it and each books its own credits remainder -- double-counting spend.
|
||||
ALTER TABLE expense_metadata
|
||||
ADD COLUMN IF NOT EXISTS matched_transaction_id INTEGER
|
||||
REFERENCES transactions(id) ON DELETE SET NULL;
|
||||
|
||||
-- One statement line settles at most one order.
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_expense_matched_txn
|
||||
ON expense_metadata (matched_transaction_id)
|
||||
WHERE matched_transaction_id IS NOT NULL;
|
||||
Reference in New Issue
Block a user