You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 19a770d
Browse filesBrowse the repository at this point in the historyBrowse files
* fix(sales): route TrackShip delivery poll through the status-transition path
Audit finding C2 (onetwo3d-ims-erl0): checkDeliveryStatus marked orders
DELIVERED via a raw db.salesOrder.update — no transition guard, no
side effects. A delivery detected by the cron skipped everything the
manual DELIVERED path does (status_changed activity log, WooCommerce
status push, cache revalidation), and could overwrite an order that had
moved to CANCELLED/REFUNDED between the SHIPPED query and the write.
Now routed through applySalesOrderStatusTransition with the internal
bypass token (cron has no session, so the permission check is skipped
but the guard + side effects run). The state machine rejects
DELIVERED from a non-deliverable status, so a since-cancelled order is
no longer silently overwritten — the cron logs delivery_status_skipped
and moves on.
Extracted the delivery-marking into markOrderDelivered with injected
transition + log deps so the routing and skip-on-reject behaviour are
unit-tested without the DB or external API (2 tests). workflows.md
documents that cron-driven DELIVERED runs the same guard + side
effects as manual.
Closes onetwo3d-ims-erl0.
* fix(sales): TrackShip delivery uses skipPermissionCheck, keeping the state guard (review hardening)
Codex adversarial pass found the original C2 fix did NOT actually
protect against the stale-state race it claimed to. The internal bypass
token makes validateManualSalesOrderStatusTransition short-circuit
{ success: true }, skipping BOTH the permission check AND the
state-machine guard — so a SHIPPED→CANCELLED race between the poll's
query and the write would still overwrite CANCELLED with DELIVERED, and
the docs claim was false.
Root fix: added a narrower skipPermissionCheck option to
applySalesOrderStatusTransition that skips ONLY the permission check;
the state-machine guard (pre-lock AND under-lock via
updateSalesOrderStatusUnderLock) still runs. The WooCommerce status-sync
path keeps the bypass token (skip-both) unchanged — it legitimately
forces mapped statuses and already handles rejection. TrackShip now uses
skipPermissionCheck, so a since-cancelled/refunded order is genuinely
rejected under the lock and logged as delivery_status_skipped.
Also from the review:
- Hoisted the applySalesOrderStatusTransition dynamic import above the
per-order loop (was re-evaluated each delivered order).
- Wrapped the per-order mark in try/catch so one order's failure (e.g.
a transient log write) no longer aborts the whole cron batch.
- Dropped the cast in the test; deps.transition type now
matches the real signature (extra/options optional), so a future
signature drift is caught.
Docs corrected: the cron skips permission only, not the state guard.
2/2 helper tests, 93/93 sales-domain tests.
---------
Co-authored-by: OneTwo3D IMS <dev@onetwo3d.com>
0 commit comments