Skip to content

fix(refunds): preserve approval selection during loading - #1413

Merged
khaira777 merged 1 commit into
mainfrom
codex/audit-refund-approval
Oct 31, 2026
Merged

khaira777 merged 1 commit into
mainfrom
codex/audit-refund-approval

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Summary

Fixes an approver-selection race condition in RefundModal when fetching approvers while an approver is already selected or during parent order refreshes, and isolates server-app-ordering.spec.ts in test runners to avoid request rate-limiting on batch runs.

Changes

  • RefundModal.tsx: Retain selectedApproverId and PIN during approver re-fetch if previously selected approver remains valid in the newly fetched list.
  • scheduled-orders.spec.ts: Synchronize approver selection with approver fetch completion before entering manager credentials.
  • package.json: Split server-app-ordering.spec.ts into a separate Playwright test invocation under test:e2e:browser to protect the backend rate limiter during single-process test runs.
  • docs/architecture/order-lifecycle.md: Clarify refund approval selection persistence semantics.

Stack

  • Layer 1 of 6 (Base of audit remediation stack)

Verification

  • npm run test:refunds: Passed
  • npm run test:scheduled-orders: Passed
  • 3x repeat of refund & approval selection E2E specs: Passed (12/12)

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Preserve refund approval selection across time-tier updates

🐞 Bug fix 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Keep eligible refund approvers and PINs selected as orders cross approval time tiers.
Diagram

graph TD
  Modal["Refund modal"] --> API["Approvers API"] --> Eligible{"Eligible now?"} --> Selection["Approver and PIN"] --> Refund["Refund API"]
  Tick["Time tick"] --> Eligible
  Eligible --> Reset["Clear invalid PIN"] --> Selection
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Refetch approvers at each time-tier change
  • ➕ Would pick up staff configuration changes without waiting for submission.
  • ➖ Adds requests and reintroduces asynchronous selection races that require careful reconciliation.

Recommendation: Locally reevaluating the loaded approvers is appropriate for the time-tier transition: it preserves valid input without another fetch, while submission still refreshes approvers and the backend remains authoritative. Keep the loading and identity guards because readiness must not expose stale credentials.

Files changed (4) +170 / -56

Bug fix (1) +40 / -21
RefundModal.tsxKeep refund approval state stable across time ticks +40/-21

Keep refund approval state stable across time ticks

• Stops refetching approvers when the order's time tier changes and clears the PIN only when the selected approver becomes ineligible. Tracks which user the loaded approvers belong to and disables PIN entry and submission until loading succeeds.

frontend/src/components/orders/RefundModal.tsx

Tests (1) +124 / -34
scheduled-orders.spec.tsExercise refund approver loading and time-tier transitions +124/-34

Exercise refund approver loading and time-tier transitions

• Uses disposable manager fixtures and waits for approvers before entering credentials. Adds coverage for stale responses, failed or empty loads, PIN retention, and clearing an invalid selection.

frontend/e2e/scheduled-orders.spec.ts

Documentation (1) +5 / -0
order-lifecycle.mdDocument refund approval selection behavior +5/-0

Document refund approval selection behavior

• Explains when the modal retains an approver and PIN, when it clears the PIN, and that the backend rechecks approval at submission.

docs/architecture/order-lifecycle.md

Other (1) +1 / -1
package.jsonRun server-app ordering browser tests separately +1/-1

Run server-app ordering browser tests separately

• Excludes the ordering spec from the main browser test invocation and runs it in a second Playwright invocation to reduce batch-run rate-limiting.

package.json

@qodo-code-review

qodo-code-review Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Cashiers cannot refund after tier change ✓ Resolved
Description
The interval in RefundModal selects a new default only when approverId is nonempty and no longer
eligible. If the modal starts with multiple approvers and no selection, then crosses into the
owner-only tier with one owner available, it displays that owner but leaves PIN entry and submission
disabled until the modal is reopened.
Code

frontend/src/components/orders/RefundModal.tsx[153]

+      if (approverId && !eligible.some((member) => String(member.id) === approverId)) {
Relevance

●●● Strong

Accepted precedent requires live refund-tier refresh; stale fallback disables required PIN and
submission.

PR-#733

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The interval skips its update when approverId is empty. The render-time fallback displays the sole
eligible owner without updating that state; both submission and PIN entry require the fallback ID to
equal the stateful ID.

frontend/src/components/orders/RefundModal.tsx[146-172]
frontend/src/components/orders/RefundModal.tsx[264-276]
frontend/src/components/orders/RefundModal.tsx[527-545]
shared/role-permissions.ts[28-30]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
When the refund tier changes, an empty approver selection is never replaced, even if exactly one eligible owner remains. The displayed owner cannot receive a PIN or submit the refund.

## Fix Focus Areas
- frontend/src/components/orders/RefundModal.tsx[150-158]

## Recommended Fix
On each eligibility check, also set the approver ID when it is empty and there is exactly one eligible approver. Preserve the existing behavior for a selected approver that remains eligible, and clear the PIN when the selected approver becomes ineligible.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

2. Refund timing hint can lag after approver changes 🐞 Bug ☼ Reliability
Description
The 30-second interval that updates now and re-checks approver eligibility is now torn down and
recreated every time approvers or approverId changes, unlike the old timer with empty
dependencies. Each time a cashier switches approvers (or submit reloads approvers), the next tick
starts over, so the late-tier hint and the auto-clear of an ineligible approver or PIN fire later
than the 30-second cadence the comment above now promises.
Code

frontend/src/components/orders/RefundModal.tsx[R159-161]

+    }, 30000);
+    return () => clearInterval(interval);
+  }, [approvers, approverId, order, user?.id]);
Relevance

●● Moderate

PR #733 supports live tier refresh, but no close precedent addresses timer restart cadence
specifically.

PR-#733

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The effect's dependency array includes approverId and approvers, so a dropdown change or the
submit path's setApprovers(configuredApprovers) clears and restarts the interval. The comment at
lines 79-80 says the timer ticks while the modal is open. The backend still checks the approver at
submit, so the impact is limited to the UI being out of date for a while.

frontend/src/components/orders/RefundModal.tsx[79-83]
frontend/src/components/orders/RefundModal.tsx[146-161]
frontend/src/components/orders/RefundModal.tsx[293-299]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The RefundModal interval is recreated whenever `approvers`/`approverId` change, so the 30s tick that updates `now` restarts and the late-tier re-check is pushed back.

## Fix Focus Areas
- frontend/src/components/orders/RefundModal.tsx[146-161]

## Recommended Fix
Go back to a single `setInterval(() => setNow(Date.now()), 30000)` with `[]` deps. Move the eligibility reconciliation into a separate effect keyed on `[isLikelyLate, approvers]`, or do it during render with a synced-value guard. That effect clears `approverId` and the PIN and picks the preferred default when the selected approver is no longer eligible. Keep reading `approverId` through state or a ref so the timer doesn't have to restart.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Compliance rules (platform): 5 rules
✅ Web pages:
  +13 more
✅ Cross-repo context — repo relationships
Review mode: Auto: 🧠 Deep: Refund approval logic and timing tests contain multiple subtle, independent race risks.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@khaira777
khaira777 force-pushed the codex/audit-refund-approval branch from b49d891 to 6f3c647 Compare October 31, 2026 21:26
@khaira777
khaira777 merged commit 818a104 into main Oct 31, 2026
23 checks passed
@khaira777
khaira777 deleted the codex/audit-refund-approval branch October 31, 2026 22:43
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