455 lines
25 KiB
Markdown
455 lines
25 KiB
Markdown
# Freshyo E2E — failed test cases (detailed)
|
||
|
||
Companion to `docs/e2e-sanity-test-plan.md` (the plan) and
|
||
`docs/test reports/e2e-sanity-test-results-2026-10-10-1310.md` (all results). This
|
||
file expands **only the FAIL cases** with reproduction steps, evidence, root cause,
|
||
and a suggested fix.
|
||
|
||
All evidence was produced on 2026-10-10 against the local stack:
|
||
backend `http://localhost:8787` (`/api/trpc`), disposable local D1, iOS
|
||
simulator `com.freshyotrial.app` / `in.freshyo.adminui`, Chromium superadmin
|
||
`http://localhost:4175`.
|
||
|
||
Legend: **Severity** — Critical / High / Medium / Low.
|
||
**Case IDs** match the plan.
|
||
|
||
---
|
||
|
||
## FC-01 — SEC-01: customer token can mutate global configuration
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — `admin.const.*` now requires a staff token
|
||
(`staffProcedure`); `updateConstants` additionally rejects global-scope keys
|
||
(globals are superadmin-only); the redundant
|
||
`getGlobalConstants`/`updateGlobalConstants`/`getLegacyConstants`/`updateLegacyConstants`
|
||
procedures were removed (no production UI caller). Regression test:
|
||
`apps/backend/tests/api/authorization-matrix.test.ts` (staff-guarded block).
|
||
- **Severity:** Critical
|
||
- **Case:** SEC-01
|
||
- **Symptom:** A signed-in *customer* can call the staff/admin global-config
|
||
mutation and change app-wide constants.
|
||
- **Steps to reproduce:**
|
||
1. `user.auth.login {identifier:"e2e_u2@test.com", password:"Pass@12345"}` → customer token.
|
||
2. `admin.const.updateGlobalConstants {constants:[{key:"versionNum",value:"1.2.0"}]}` with that token.
|
||
- **Expected:** Rejected (staff-only).
|
||
- **Actual:** `200 {success:true, updatedCount:1}`.
|
||
- **Evidence:** Response body from step 2; anonymous `admin.product.getProducts` → 401,
|
||
customer `admin.product.getProducts` → 500 (`Cannot read properties of null (reading 'regionId')`).
|
||
- **Root cause:** `apps/backend/src/trpc/apis/admin-apis/apis/const.ts` — `updateGlobalConstants`
|
||
uses `protectedProcedure` (allows any authenticated user **or** staff) and never touches
|
||
`ctx.staffUser`. `protectedProcedure` is defined in `apps/backend/src/trpc/trpc-index.ts`.
|
||
- **Suggested fix:** Change the global-config procedures (`getGlobalConstants`,
|
||
`updateGlobalConstants`, legacy ones) to `superadminProcedure` (global scope) or at minimum
|
||
`staffProcedure`; remove the legacy admin global mutation or gate it behind superadmin.
|
||
|
||
---
|
||
|
||
## FC-02 — SEC-04: order accepts a SKU from another region
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — `placeOrderUtil` now rejects an item whose
|
||
product `regionId` ≠ the order region (409 "… is not available in this region").
|
||
- **Severity:** High
|
||
- **Case:** SEC-04
|
||
- **Symptom:** A region-1 order can include a region-2 SKU.
|
||
- **Steps to reproduce:**
|
||
1. U2 with a region-1 address (877).
|
||
2. `user.order.placeOrder {regionId:1, addressId:877, paymentMethod:"cod",
|
||
selectedItems:[{skuId:157 /* region-2 product */, quantity:1, slotId:2012}]}`.
|
||
- **Expected:** Rejected (SKU not in the ordering region).
|
||
- **Actual:** `200`, order 2456 created with `regionId:1` and sku 157, priced at region-2's ₹149 + ₹20 delivery.
|
||
- **Evidence:** Order 2456 in `orders`/`order_items`.
|
||
- **Root cause:** `apps/backend/src/trpc/apis/user-apis/apis/order.ts` → `placeOrderUtil` resolves
|
||
items via `getOrderProductById(item.skuId)` with no region filter. Address region is checked,
|
||
but SKU/slot/bound region coherence is not.
|
||
- **Suggested fix:** Validate each SKU's `regionId` (and its product's region) equals the order
|
||
region; reject otherwise.
|
||
|
||
---
|
||
|
||
## FC-03 — SEC-05: order accepts unassigned / out-of-stock / closed-slot items
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — `placeOrderUtil` now rejects
|
||
`isDeleted`/`isOutOfStock`/`isSuspended` items (400), requires a non-null slotId
|
||
for scheduled orders, and validates each slot: exists, region match (409),
|
||
`isActive`, `freezeTime`/`deliveryTime` in the future, and every ordered `skuId`
|
||
present in `slot.skuIds` (400).
|
||
- **Severity:** High
|
||
- **Case:** SEC-05
|
||
- **Symptom:** The backend accepts items it should reject.
|
||
- **Steps to reproduce:**
|
||
- (a) Unassigned SKU: `placeOrder {regionId:1, selectedItems:[{skuId:1, quantity:1, slotId:2012}]}` where sku 1 is **not** in slot 2012 → **200**, order 2457.
|
||
- (b) Out-of-stock: `admin.product.toggleOutOfStock{id:155}` → `placeOrder {skuId:155, slotId:2012}` → **200**, order 2458 (stock restored afterward).
|
||
- **Expected:** Both rejected.
|
||
- **Actual:** Both create orders.
|
||
- **Evidence:** Orders 2457, 2458; schema still rejects non-positive/non-integer quantity.
|
||
- **Root cause:** `placeOrderUtil` (order.ts) never checks `isOutOfStock` / `isSuspended` / `isDeleted`,
|
||
nor that the SKU is a member of the selected slot, nor slot active/frozen state (only capacity is checked).
|
||
- **Suggested fix:** In `placeOrderUtil`, for each item assert: SKU exists, belongs to region,
|
||
not OOS/suspended/deleted, is assigned to the chosen slot, and the slot is active and not frozen.
|
||
|
||
---
|
||
|
||
## FC-04 — SEC-06: user-based coupon is not restricted to its user
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — `validateAndGetCoupon` now loads
|
||
`applicableUsers` and rejects a user-based coupon for anyone not listed (unless
|
||
`isApplyForAll`): `This coupon is not applicable to your account`.
|
||
- **Severity:** High
|
||
- **Case:** SEC-06
|
||
- **Symptom:** A coupon created for U1 can be applied by U2.
|
||
- **Steps to reproduce:**
|
||
1. Admin: `coupon.create {couponCode:"E2EU1ONLY", discountPercent:10, isUserBased:true, applicableUsers:[388], maxLimitForUser:3}`.
|
||
2. U2: `placeOrder {…, couponId:46}`.
|
||
- **Expected:** Rejected (coupon is for user 388 only).
|
||
- **Actual:** `200`, order 2463 discounted.
|
||
- **Evidence:** Order 2463; coupon 46 has `isUserBased:true`.
|
||
- **Root cause:** `packages/db_helper_sqlite/src/user-apis/coupon.ts` → `validateAndGetUserCoupon`
|
||
does not consult `applicableUsers`. (Expiry **is** enforced.)
|
||
- **Suggested fix:** Reject when `coupon.isUserBased && !applicableUsers.includes(userId)`.
|
||
|
||
---
|
||
|
||
## FC-05 — SEC-07: public vendor packaging mutation + expired-snippet leak
|
||
|
||
- **Severity:** High
|
||
- **Case:** SEC-07
|
||
- **Symptom:** Anyone can toggle order-item packaging; expired snippets still list orders.
|
||
- **Steps to reproduce:**
|
||
1. Admin creates a vendor snippet for slot 2012 (`E2ESNIP`).
|
||
2. Anonymous `admin.vendorSnippets.updateOrderItemPackaging {orderItemId:8237, is_packaged:true}` → **200** (toggled U1's order item).
|
||
3. Admin creates an **expired** snippet (`validTill:"2020-01-01"`); anonymous
|
||
`admin.vendorSnippets.getOrdersBySnippetAndSlot {snippetCode:"E2ESNIPEXP", slotId:2012}` → **200** with customer names + orders.
|
||
- **Expected:** Packaging edits require vendor authority; expired snippets return nothing.
|
||
- **Actual:** Anonymous mutation succeeds; expired snippet leaks orders.
|
||
- **Evidence:** Both responses above (item 8237 toggled true→false).
|
||
- **Root cause:** `apps/backend/src/trpc/apis/admin-apis/apis/vendor-snippets.ts` —
|
||
`updateOrderItemPackaging` is `publicProcedure` with the auth check commented out;
|
||
`getOrdersBySnippetAndSlot` never checks `validTill` (unlike `getOrdersBySnippet`).
|
||
- **Suggested fix:** Require a valid `snippetCode` (unexpired) and authorize the mutation against
|
||
the order's slot/snippet; enforce expiry in the slot-variant query too.
|
||
|
||
---
|
||
|
||
## FC-06 — BL-02: `minRegularOrderValue` is not a real minimum
|
||
|
||
- **Status:** ✅ **Resolved** (2026-10-10) — the constant was removed. It was never a
|
||
hard minimum (nothing enforced it) and is no longer used as the delivery threshold,
|
||
so it was dead. Removed from both const registries, the essential-consts payload,
|
||
the web-ui hook, the admin/superadmin bound editors, the seeds, and the tests.
|
||
No minimum-order rule is enforced (matching the customer app).
|
||
- **Severity:** Medium
|
||
- **Case:** BL-02
|
||
- **Symptom:** Orders below the configured minimum are accepted.
|
||
- **Steps to reproduce:** `placeOrder` with subtotal ₹199 while bound A1 `minRegularOrderValue:300`.
|
||
- **Expected:** Blocked if it is a hard minimum (policy needs confirmation).
|
||
- **Actual:** `200` (orders 2457/2458).
|
||
- **Evidence:** Orders below 300 accepted.
|
||
- **Root cause:** `placeOrderUtil` uses `minRegularOrderValue` only as the free-delivery threshold,
|
||
never as a minimum-order gate; the client uses `freeDeliveryThreshold` instead.
|
||
- **Suggested fix:** Decide the contract (minimum vs informational). If a minimum, enforce it in
|
||
`placeOrder` and surface it in the cart; if not, rename/document it and stop using it as the fee threshold.
|
||
|
||
---
|
||
|
||
## FC-07 — BL-03 / BL-06: client and backend delivery-fee formulas diverge
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — the backend now uses the customer app's
|
||
model: threshold key `freeDeliveryThreshold` (not `minRegularOrderValue`) and the
|
||
post-discount basis (`finalTotal = subtotal − discount; delivery = finalTotal <
|
||
threshold ? charge : 0`).
|
||
- **Severity:** High
|
||
- **Cases:** BL-03, BL-06
|
||
- **Symptom:** The amount the customer sees differs from what the backend saves.
|
||
- **Steps to reproduce:**
|
||
- BL-06 (different keys): bound A2 `min=300, free=800, charge=200`; subtotal ₹548.
|
||
Backend order 2459 → `totalAmount:548, deliveryCharge:0`; client preview → `548<800` → ₹200 delivery → ₹748.
|
||
- BL-03 (different discount basis): bound A1 `threshold 300`; subtotal ₹349, flat ₹100 coupon.
|
||
Backend order 2461 → `totalAmount:249, deliveryCharge:0`; client preview → post-coupon 249<300 → ₹20 → ₹269.
|
||
- **Expected:** Identical rule in cart, checkout, persisted order, and admin.
|
||
- **Actual:** ₹200 / ₹20 discrepancies.
|
||
- **Evidence:** Orders 2459, 2461.
|
||
- **Root cause:** `apps/user-ui/components/cart-page.tsx` uses
|
||
`deliveryCharge = (subtotal − discount) < freeDeliveryThreshold ? charge : 0`.
|
||
`placeOrderUtil` (order.ts) uses `expectedDeliveryCharge = subtotal(pre-discount) < minRegularOrderValue ? charge : 0`.
|
||
Different key **and** different discount basis.
|
||
- **Suggested fix:** One shared pricing function (server-authoritative). Use the same threshold key
|
||
and the same pre/post-discount basis on both sides; ideally the client renders the server quote.
|
||
|
||
---
|
||
|
||
## FC-08 — D10: percentage discount is applied to subtotal + delivery fee
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — the coupon discount is now computed on the
|
||
cart subtotal only; delivery is decided afterwards and added on top (no longer
|
||
discounted).
|
||
- **Severity:** High
|
||
- **Case:** BL-05 (and visible in SEC-06 order 2463)
|
||
- **Symptom:** A % coupon discounts the delivery fee too.
|
||
- **Steps to reproduce:** subtotal ₹199 + delivery ₹20, 10% coupon → order 2463 `totalAmount:197.1`.
|
||
- **Expected:** Discount on the item subtotal only → ₹199×0.9 + ₹20 = ₹199.1.
|
||
- **Actual:** (199+20)×0.9 = ₹197.1.
|
||
- **Evidence:** Order 2463; also 15% case 2480 (₹186.15 = 219×0.85).
|
||
- **Root cause:** `placeOrderUtil` passes `subOrderTotalWithDelivery` into
|
||
`applyDiscountToUserOrder` for the first suborder.
|
||
- **Suggested fix:** Apply the coupon to the item subtotal, then add delivery; keep the same order on the client.
|
||
|
||
---
|
||
|
||
## FC-09 — CP-05: SKU-restricted coupon is not enforced
|
||
|
||
- **Status:** ⚪ **Not a defect for now** (2026-10-10) — SKU-specific coupons are not
|
||
created today; coupons are intended to apply to all SKUs. `skuIds` is deliberately
|
||
left unenforced. (Revisit if SKU-scoped coupons are ever introduced.)
|
||
- **Severity:** High
|
||
- **Case:** CP-05
|
||
- **Symptom:** A coupon limited to sku 155 discounts a cart containing only sku 156.
|
||
- **Steps to reproduce:** `coupon.create {couponCode:"E2ESKU155", discountPercent:10, skuIds:[155]}` →
|
||
`placeOrder` with only sku 156 → **200**, order 2474 (10% off 349).
|
||
- **Expected:** Rejected.
|
||
- **Actual:** Applied.
|
||
- **Evidence:** Order 2474.
|
||
- **Root cause:** `validateAndGetUserCoupon` does not enforce `skuIds` / applicable products.
|
||
- **Suggested fix:** Validate cart items against the coupon's product/SKU scope server-side.
|
||
|
||
---
|
||
|
||
## FC-10 — CP-11: coupons are not region-scoped
|
||
|
||
- **Status:** ⚪ **Not a defect for now** (2026-10-10) — region-scoped coupons are not
|
||
wanted; coupons are global. No region filter is added. (Revisit if regional
|
||
coupons are ever required.)
|
||
- **Severity:** High
|
||
- **Case:** CP-11
|
||
- **Symptom:** A region-1 coupon discounts a region-2 order.
|
||
- **Steps to reproduce:** U2 region-2 address (883) + region-2 sku 157 + region-1 coupon 45 → **200**, order 2477 total ₹79.
|
||
- **Expected:** Per region policy (reject if region-scoped).
|
||
- **Actual:** Applied.
|
||
- **Evidence:** Order 2477.
|
||
- **Root cause:** coupon storage/validation (`coupons`, `validateAndGetUserCoupon`, user coupon fetches)
|
||
carries no region filter.
|
||
- **Suggested fix:** Decide global-vs-regional coupon policy; if regional, store `region_id` and
|
||
filter both retrieval and validation.
|
||
|
||
---
|
||
|
||
## FC-11 — PD-13: deleting a store orphans its products
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — `deleteStore` now counts the store's products and
|
||
refuses to delete while any exist (plain error: "Cannot delete a store that still has
|
||
products…"); the `store_id → NULL` step was removed, so products can no longer be orphaned.
|
||
- **Severity:** High
|
||
- **Case:** PD-13
|
||
- **Symptom:** `deleteStore` succeeds even when the store has products.
|
||
- **Steps to reproduce:** `admin.store.deleteStore {storeId:1}` (store 1 had 41 products) → **200 "Store deleted successfully"**.
|
||
- **Expected:** Blocked (or products reassigned).
|
||
- **Actual:** 41 products left with `store_id = NULL`.
|
||
- **Evidence:** DB count of `product_info where store_id is null` jumped to 41 (restored manually).
|
||
- **Root cause:** `apps/backend/src/trpc/apis/admin-apis/apis/store.ts` `deleteStore` and
|
||
`packages/db_helper_sqlite` `deleteStoreFromDb` have no dependency guard/reassignment.
|
||
- **Suggested fix:** Reject deletion when products reference the store, or require an explicit
|
||
reassignment target; never leave products with a null store.
|
||
|
||
---
|
||
|
||
## FC-12 — DS-02: deleting a product tag fails (FK)
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — `deleteProductTag` now deletes the `product_tags`
|
||
junction rows first (in a transaction) before the tag row, so a tag with products deletes
|
||
cleanly. No FK-cascade migration needed.
|
||
- **Severity:** High
|
||
- **Case:** DS-02
|
||
- **Symptom:** Tag delete throws a raw DB error when the tag has products.
|
||
- **Steps to reproduce:** create tag 12 with products 155/156 → `admin.product.deleteProductTag {id:12}`.
|
||
- **Expected:** Tag + junction rows removed.
|
||
- **Actual:** `500` `Failed query: delete from "product_tag_info" …`.
|
||
- **Evidence:** `product_tags` still had row (product 155 → tag 12); FK `ON DELETE no action`.
|
||
- **Root cause:** `deleteProductTagInDb` deletes `product_tag_info` without first deleting
|
||
`product_tags` junction rows.
|
||
- **Suggested fix:** Delete junction rows (or use `ON DELETE CASCADE`) before the tag row.
|
||
|
||
---
|
||
|
||
## FC-13 — SL-04: closed (frozen) slot is accepted by `placeOrder`
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — the slot validation added for FC-03 rejects
|
||
a slot whose `freezeTime` (or `deliveryTime`) has passed (400).
|
||
- **Severity:** High
|
||
- **Case:** SL-04
|
||
- **Symptom:** An order can be placed into a slot whose freeze time has passed.
|
||
- **Steps to reproduce:** create slot 2015 with `freezeTime:"2020-01-01"` → `placeOrder {skuId:155, slotId:2015}` → **200**, order 2469.
|
||
- **Expected:** Rejected (orders closed).
|
||
- **Actual:** Accepted.
|
||
- **Evidence:** Order 2469.
|
||
- **Root cause:** `placeOrder` checks capacity (`getUserSlotCapacityStatus`) but not slot
|
||
active/freeze state; the client only filters slots.
|
||
- **Suggested fix:** Server-side reject when `slot.freezeTime <= now` or `!slot.isActive`.
|
||
|
||
---
|
||
|
||
## FC-14 — CT-07: cart does not reflect an out-of-stock item
|
||
|
||
- **Status:** ⚪ **Not a defect (false flag)** (2026-10-10) — reproduced and disproven. The cart
|
||
**does** implement the CT-07 behavior: `cart-page.tsx` renders an "Out of Stock" badge
|
||
(`:962`), filters OOS lines out of the checkout payload (`:1247`), and blocks checkout with
|
||
"Items Unavailable" when every line is OOS (`:1264`). The E2E only observed the
|
||
pre-propagation window: after `toggleOutOfStock` the app keeps the previous
|
||
`availability_version_num` until its `essentialConsts` `refetchInterval` (60 s) fires, so the
|
||
cart shows the line normally for up to ~1 minute, then correctly shows "Out of Stock". The
|
||
report's stated root cause (`cart-page` ignores `isOutOfStock`) was inaccurate.
|
||
- **Severity:** High
|
||
- **Case:** CT-07
|
||
- **Repro (2026-10-10):** cart held sku 155 ("E2E Chicken 500 g", qty 6, ₹1194);
|
||
`toggleOutOfStock{id:155}` bumped availability `av-17 → av-18` (published `av-18` shows
|
||
`isOutOfStock:true`); `stopApp` → `launchApp` → open cart → line normal; ~70 s later (the
|
||
refetch interval) → red "Out of Stock" badge. Stock restored afterwards.
|
||
- **Evidence (original E2E):** Published `availability.json` for region 1 `av-15` showed sku 155
|
||
`isOutOfStock:true`; the cart screenshot was taken inside the staleness window.
|
||
- **Residual (out of scope, by decision):** the ~60 s propagation delay is cache-refresh latency,
|
||
not a cart-logic bug.
|
||
|
||
---
|
||
|
||
## FC-15 — AU-07: profile update is broken (`ctx.req.header`)
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — `Context.req` is now typed as the fetch
|
||
`Request` the adapter passes, and `updateProfile` reads
|
||
`ctx.req.headers.get('authorization')`. The optional email was relaxed too: an empty
|
||
email means "no change", and the client only requires it when registering.
|
||
- **Severity:** High
|
||
- **Case:** AU-07
|
||
- **Symptom:** `updateProfile` always errors.
|
||
- **Steps to reproduce:** `user.auth.updateProfile {name:"E2E U2 Renamed", bio:"hello bio"}` with a valid token.
|
||
- **Expected:** Profile updated.
|
||
- **Actual:** `500 "ctx.req.header is not a function"`.
|
||
- **Evidence:** Response above; UI Edit Profile also blocked earlier by a required-email validation.
|
||
- **Root cause:** `apps/backend/src/trpc/apis/user-apis/apis/auth.ts` line ~342 calls
|
||
`ctx.req.header('authorization')`, but `ctx.req` is a fetch `Request` (only `.headers.get`).
|
||
- **Suggested fix:** Read the header via `ctx.req.headers.get('authorization')` (or drop the token
|
||
echo). Relax the client's email requirement if email is optional.
|
||
|
||
---
|
||
|
||
## FC-16 — AU-08: password change has no effect (duplicate creds row)
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — `upsertUserPassword` now selects then
|
||
updates-or-inserts (updating all rows for the user, repairing existing duplicates),
|
||
and a `uniqueIndex` on `user_creds.user_id` was added to the schema. Existing duplicate
|
||
rows (users 379, 908, 1311) must be deduped before the index migration is applied.
|
||
- **Severity:** High
|
||
- **Case:** AU-08
|
||
- **Symptom:** After `updatePassword`, the old password still works and the new one fails.
|
||
- **Steps to reproduce:** fresh user U5 → `user.auth.updatePassword {password:"NewPass@456"}` →
|
||
login with old (works) / new (fails).
|
||
- **Expected:** New password works, old fails.
|
||
- **Actual:** Old logs in (200), new fails (500).
|
||
- **Evidence:** `user_creds` for the user contains **two rows** (ids 26, 27) after the change.
|
||
- **Root cause:** `upsertUserAuthPasswordInDb` inserts a new row instead of updating the existing
|
||
one; login reads the stale row.
|
||
- **Suggested fix:** Update the existing `user_creds` row (unique on `user_id`) rather than inserting;
|
||
add a unique constraint if missing.
|
||
|
||
---
|
||
|
||
## FC-17 — OR-12: no order idempotency (duplicate submits)
|
||
|
||
- **Status:** 🟡 **Mitigated client-side** (2026-10-10) — the Place Order button is
|
||
disabled while a submit is in flight, and `handlePlaceOrder` early-returns via a
|
||
synchronous `useRef` guard (plus `isPending`), so an accidental double-tap cannot
|
||
submit twice. **Server-side idempotency was intentionally deferred**: `placeOrder`
|
||
still has no idempotency key, so a direct API replay or network retry can still
|
||
create duplicates.
|
||
- **Severity:** Medium
|
||
- **Case:** OR-12
|
||
- **Symptom:** Retrying/submitting twice creates duplicate orders.
|
||
- **Steps to reproduce:** call the same `placeOrder` twice with identical params.
|
||
- **Expected:** One order group (idempotent) or a clear dedupe.
|
||
- **Actual:** Two calls created 4 orders (2465–2468).
|
||
- **Evidence:** Order ids above.
|
||
- **Root cause:** `placeOrder` has no idempotency key; only the client has a loading lock.
|
||
- **Suggested fix:** Accept a client-generated idempotency key and short-circuit duplicate submissions.
|
||
|
||
---
|
||
|
||
## FC-18 — AD-06: address region/bound coherence not validated
|
||
|
||
- **Severity:** Medium
|
||
- **Case:** AD-06
|
||
- **Symptom:** An address can reference a bound from a different region.
|
||
- **Steps to reproduce:** `user.address.createAddress {regionId:2, boundId:1}` (bound 1 is region 1's) → **200**, address 882 stored region 2 / bound 1.
|
||
- **Expected:** Rejected (bound must belong to the region).
|
||
- **Actual:** Accepted.
|
||
- **Evidence:** Address 882.
|
||
- **Root cause:** `apps/backend/src/trpc/apis/user-apis/apis/address.ts` create/update do not check
|
||
that `boundId` belongs to `regionId`. Compounding this, `AddressForm` submits the current
|
||
**browsing** bound, so the client can send an incoherent pair.
|
||
- **Suggested fix:** Validate `bound.regionId === regionId` server-side; have `AddressForm` derive
|
||
the bound from the chosen address region, not the browsing region.
|
||
|
||
---
|
||
|
||
## FC-19 — RG-02: region creation is not atomic on D1
|
||
|
||
- **Status:** ✅ **Fixed** (2026-10-10) — `createRegionWithBounds` now validates the bounds
|
||
before touching the DB (≥1 bound, unique priorities) so a bad payload never reaches the
|
||
inserts, and wraps the post-region inserts in a try/catch that deletes the region + its
|
||
child rows if anything fails. Reproduced (leftover region 5), then re-verified: the
|
||
duplicate-priority create now leaves **no** region behind.
|
||
- **Severity:** Medium
|
||
- **Case:** RG-02
|
||
- **Symptom:** A failed region create leaves a half-created region.
|
||
- **Steps to reproduce:** `superadmin.regions.create` with two bounds at priority `1`.
|
||
- **Expected:** Error, no region persisted.
|
||
- **Actual:** `500 "Each bound priority must be unique…"` **and** region `E2E-DupPriority` exists with 0 bounds / 0 consts.
|
||
- **Evidence:** Region row 4 with no bounds (removed manually).
|
||
- **Root cause:** `packages/db_helper_sqlite/src/superadmin-apis/regions.ts` `createRegionWithBounds`
|
||
wraps inserts in `db.transaction`, but on D1 the region insert is not rolled back when the bound
|
||
insert violates the unique priority index.
|
||
- **Suggested fix:** Validate bounds (unique priorities, valid geometry) before inserting, or use an
|
||
atomic D1 batch that fails as a unit.
|
||
|
||
---
|
||
|
||
## FC-20 — AU-03 (and D8): error statuses flattened to HTTP 500
|
||
|
||
- **Severity:** Low
|
||
- **Case:** AU-03 (same class as the cross-region `getProductById` 500)
|
||
- **Symptom:** Auth/validation/not-found failures return 500 instead of 4xx.
|
||
- **Steps to reproduce:** `user.auth.login` with a wrong password → `500`; unknown user → `500`;
|
||
`admin.product.getProductById` cross-region → `500 "Product not found"`.
|
||
- **Expected:** 401 / 404 respectively.
|
||
- **Actual:** 500.
|
||
- **Evidence:** Response statuses above.
|
||
- **Root cause:** `ApiError` carries an HTTP status but `apps/backend/src/app.ts` `onError` /
|
||
the tRPC error mapping only maps `TRPCError` codes, so `ApiError` falls through to 500.
|
||
- **Suggested fix:** Translate `ApiError` (and thrown `Error` with a status) to the matching HTTP
|
||
status in the global error handler / tRPC error formatter.
|
||
|
||
---
|
||
|
||
## Summary
|
||
|
||
| Ref | Case | Severity | One-line |
|
||
|---|---|---|---|
|
||
| FC-01 | SEC-01 | Critical | Customer token mutates global consts — ✅ fixed |
|
||
| FC-02 | SEC-04 | High | Cross-region SKU accepted — ✅ fixed |
|
||
| FC-03 | SEC-05 | High | Unassigned / OOS / closed-slot items accepted — ✅ fixed |
|
||
| FC-04 | SEC-06 | High | User-based coupon used by another user — ✅ fixed |
|
||
| FC-05 | SEC-07 | High | Public packaging mutation + expired-snippet leak |
|
||
| FC-06 | BL-02 | Medium | Minimum order not enforced — ✅ resolved (constant removed) |
|
||
| FC-07 | BL-03/06 | High | Client vs backend delivery-fee divergence — ✅ fixed |
|
||
| FC-08 | BL-05 | High | % coupon discounts the delivery fee — ✅ fixed |
|
||
| FC-09 | CP-05 | High | SKU-restricted coupon not enforced — ⚪ not a defect for now |
|
||
| FC-10 | CP-11 | High | Coupons not region-scoped — ⚪ not a defect for now |
|
||
| FC-11 | PD-13 | High | Store delete orphans products — ✅ fixed |
|
||
| FC-12 | DS-02 | High | Tag delete fails (FK) — ✅ fixed |
|
||
| FC-13 | SL-04 | High | Frozen slot accepted — ✅ fixed |
|
||
| FC-14 | CT-07 | High | Cart ignores out-of-stock — ⚪ not a defect (false flag) |
|
||
| FC-15 | AU-07 | High | Profile update broken — ✅ fixed |
|
||
| FC-16 | AU-08 | High | Password change ineffective — ✅ fixed |
|
||
| FC-17 | OR-12 | Medium | No order idempotency — 🟡 client-side guard (server deferred) |
|
||
| FC-18 | AD-06 | Medium | Incoherent address region/bound |
|
||
| FC-19 | RG-02 | Medium | Non-atomic region create — ✅ fixed |
|
||
| FC-20 | AU-03 | Low | Errors return 500 instead of 4xx |
|
||
|
||
Suggested fix order: **FC-01 → FC-02/03/13 (order validation) → FC-07/08 (pricing) →
|
||
FC-04/09/10 (coupons) → FC-05 (vendor auth) → FC-16/15 (account) → FC-11/12/19 → FC-17/18/20.**
|
||
(FC-09/FC-10/FC-14 closed as false flags.)
|