Skip to content

fix(orders): no 24 h approval expiry in Mode B - #627

Open
privatejoel wants to merge 1 commit into
mainfrom
fix/approval-ttl-mode-b
Open

privatejoel wants to merge 1 commit into
mainfrom
fix/approval-ttl-mode-b

Conversation

@privatejoel

Copy link
Copy Markdown
Collaborator

Summary

C-11 (A-PR19, decision C-D8). In Mode B, an approval does not expire. Mode A keeps the 24 h expiry.

In Mode B the order stays at APPROVED while a clerk keys the ERP. After 24 h, the expiry refused the later status moves of the order. The owner accepted the default of C-D8: in Mode B there is no 24 h expiry, and a line edit still clears the approval.

What changes:

  • Approve. In Mode B the server stores approval_expires_at = null. In Mode A it stores now + 24 h.
  • The expiry check (approvalExpiryBlocks, the only reader of approval_expires_at) treats a Mode B approval as not expired. This includes old rows that have a stored 24 h expiry.
  • The server sets the TTL. The client value body.approval.ttlHours is ignored. Before this change, ttlHours: 1e6 gave a Mode A approval that did not expire, and ttlHours: "x" gave a 500. No screen sends it.
  • Mode switch from B to A. A Mode B approval has no stored expiry. In Mode A, the check now uses approved_at + 24 h when no expiry is stored. Thus a Mode B approval does not escape the 24 h rule after the tenant goes to Mode A.
  • Fail closed. The handler reads the mode with the existing isModeB reader (_lib/so-processing-mode.js, filters tenant_id). If the setting is missing, or the read returns an error, or the read throws, the mode is A. Thus the 24 h expiry stays (the stricter rule).
  • A line edit still clears the approval in both modes. This did not change. A new test pins it.

The handler reads the mode only for a PATCH that sets status. A line edit does not read it.

Deploy notes

  • No migration. The mode column is from migration 221.
  • No new action. No RBAC change.
  • No step after deploy. Old Mode B rows with a 24 h expiry are not rewritten. The check ignores their expiry in Mode B.

Tests

New file: src/v3-app/api-orders-approval-ttl.modeB.test.js. It runs the real PATCH handler on an in-memory database.

  • Mode B approve stores no expiry. Mode A approve stores 24 h.
  • A client ttlHours is ignored: 1e6 and "x" in Mode A give 24 h (and no 500). 1 in Mode B gives no expiry.
  • A Mode B order approved 30 h ago (old row with an expiry 6 h ago, and a row with no expiry) can move to EXPORTED_TO_TALLY.
  • A Mode A order approved 30 h ago is refused with 409.
  • A Mode B approval (no stored expiry) in a tenant that is now in Mode A is refused after 24 h.
  • A line edit clears the approval, its expiry and its actions, in Mode B and in Mode A.
  • A mode that is missing, a read that returns an error, and a read that throws: approve sets 24 h, and an expired approval is refused.

Changed: src/v3-app/api-order-status-actions.test.js. Its describe label said "Mode B", but its tests run with no mode row (Mode A). The label now says what the tests do. The assertions did not change.

Mutation check. I broke each rule, ran the new test file, saw tests fail, and restored the code:

Mutation Tests that fail
M1: remove the Mode B short-circuit in approvalExpiryBlocks 2 (Mode B, 30 h ago, can move)
M2: approve always writes 24 h 2 (Mode B stores no expiry; Mode B ttlHours 1)
M3: use the client ttlHours again 2 (1e6 and "x" in Mode A)
M4: a line edit keeps the approval 2 (line edit, Mode B and Mode A)
M5: a thrown mode read reads as B (.catch(() => true)) 2 (the read throws)
M6: isModeB reads an unknown mode as B 3 (missing setting; read error)
M7: no approved_at fallback in Mode A 1 (Mode B approval, tenant now in Mode A)
M8: the handler never reads the mode 4 (every Mode B case)

Not covered

  • The SO workspace Approval card still shows "Approval expires" from the stored column. For a new Mode B approval it shows "not recorded". For an old Mode B row it shows the old date, but the server does not use that date. A label such as "does not expire (Mode B)" is a separate screen change.
  • The stored approval JSON keeps the keys the client sent, ttlHours included. The server does not read it.
  • The Tally push and requireApprovedOrder do not read the expiry (before and after this change). This PR does not add an expiry to them.
  • A stored expiry from Mode A stays on the row after a switch to Mode B. The check ignores it while the tenant is in Mode B.

🤖 Generated with Claude Code

C-11 (A-PR19, decision C-D8). In Mode B, an approval does not expire.
Mode A keeps the 24 h expiry.

- Approve in Mode B stores approval_expires_at = null. Approve in
  Mode A stores now + 24 h.
- approvalExpiryBlocks treats a Mode B approval as not expired. This
  includes old rows with a stored 24 h expiry.
- The server sets the TTL. The client ttlHours is ignored. Before,
  ttlHours 1e6 gave an approval that did not expire, and "x" gave a 500.
- In Mode A, an approval with no stored expiry (given in Mode B)
  expires 24 h after approved_at.
- The handler reads the mode with isModeB. A missing setting, a read
  error or a thrown read is Mode A, so the 24 h expiry stays.
- A line edit still clears the approval in both modes. A new test
  pins it.

No migration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
anvil Ready Ready Preview Oct 20, 2026 3:23am UTC

This branch was successfully deployed

1 active deployment
Preview — 6be473ad Deployed Oct 20, 2026 by vercel[bot]
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