Skip to content

Add spouseCalculations to ASR context#1682

Open
dr-bizz wants to merge 2 commits intomainfrom
MPDX-9425-spouse-calculations
Open

Add spouseCalculations to ASR context#1682
dr-bizz wants to merge 2 commits intomainfrom
MPDX-9425-spouse-calculations

Conversation

@dr-bizz
Copy link
Copy Markdown
Contributor

@dr-bizz dr-bizz commented Apr 6, 2026

Summary

This PR is a follow-up for #1680 to address Will's comments

Changes

  • Added spouseCalculations to AdditionalSalaryRequestContext (mirroring existing calculations)
  • Replaced all direct requestData?.latestAdditionalSalaryRequest?.calculations and requestData?.latestAdditionalSalaryRequest?.spouseCalculations access with context values
  • Updated tests to provide calculations at the top level of mock context values

Test plan

  • All 318 AdditionalSalaryRequest tests pass
  • TypeScript compiles cleanly
  • ESLint passes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Bundle sizes [mpdx-react]

Compared against f7ae0e1

No significant changes found

@dr-bizz
Copy link
Copy Markdown
Contributor Author

dr-bizz commented Apr 6, 2026

🤖 Multi-Agent Code Review Report

PR: #1682 — Add spouseCalculations to ASR context
Agents: 5 specialized reviewers (Architecture, Testing, UX, Financial, Standards)
Review Mode: Standard (smart selection)


📊 RISK ASSESSMENT

Risk Score: 7/15 — MEDIUM
Files Changed: 22 (+213 -103 lines)
Scope: Single feature area (AdditionalSalaryRequest)

Risk Factors: Custom hooks with business logic, financial calculations (salary caps, balances)


🚫 CRITICAL BLOCKERS (Severity 9-10)

None. All 5 agents confirmed no blocking issues. All financial calculations are preserved exactly through this refactor.


⚠️ IMPORTANT ISSUES (Severity 7-8)

1. Dual-path access: requestData + calculations both exposed on context

Severity: 8/10 (Architecture Agent)
File: AdditionalSalaryRequestContext.tsx:242-251

The context now exposes both requestData (full query result) and calculations/spouseCalculations (shortcuts). Some consumers still use requestData directly (e.g., EligibleDisplay, CapSubContent), while refactored components use the shortcuts. This creates two valid-looking paths for future developers.

Recommendation: This is expected for an incremental migration. Consider a follow-up to migrate remaining requestData.calculations consumers and eventually narrow the requestData exposure.

2. useMemo dependency array missing calculations/spouseCalculations

Severity: 7/10 (UX + Testing Agents)
File: AdditionalSalaryRequestContext.tsx:267-300

The contextValue useMemo includes calculations and spouseCalculations in the returned object but not in the dependency array. Both derive from requestData which IS in deps, so no stale data bug exists in practice. However, the deps array is technically incomplete.

Recommendation: Not blocking — requestData changing will trigger recalculation. But adding them explicitly would be more correct.

3. Asymmetric Pick types: combinedCap on calculations but not spouseCalculations

Severity: 7/10 (Architecture + Financial Agents)
File: AdditionalSalaryRequestContext.tsx:56-68

calculations picks 4 fields (including combinedCap), while spouseCalculations picks only 3 (excluding combinedCap). This matches the GraphQL query which doesn't fetch combinedCap for spouse — so it's correct. The Financial Agent notes combinedCap is not consumed by any calculation logic currently.

Recommendation: No action needed. The asymmetry matches the GraphQL schema.


💡 MEDIUM PRIORITY (Severity 5-7)

  • Weak isSpouse test (Severity 5.5 — Testing + Standards): useAdditionalSalaryRequestForm.test.tsx line 296 — the renamed test 'should read isSpouse from context' only asserts values is defined, which passes trivially. The original test verified isSpouse was passed as a query variable.

  • Redundant requestData in test mocks (Severity 3.5 — Testing + Financial): After the refactor, useSalaryCalculations reads calculations/spouseCalculations from context, but test mocks still include full requestData.latestAdditionalSalaryRequest.calculations. This is dead test data that could confuse future maintainers.


💭 SUGGESTIONS (Severity 3-5)

  • Add context integration test verifying calculations/spouseCalculations are correctly populated from query data
  • Clean up redundant requestData from test mocks in useSalaryCalculations.test.ts and useFormUserInfo.test.ts
  • Consider adding a comment on the SpouseComponent ternary explaining the isSpouse perspective swap

💰 FINANCIAL ACCURACY VERIFICATION

The Financial Agent confirmed all calculations are preserved exactly:

Calculation Status
totalAnnualSalary = grossAnnualSalary + pendingAsrAmount + total ✅ Preserved
spouseTotalAnnualSalary = spouseGrossAnnualSalary + spousePendingAsrAmount ✅ Preserved
exceedsCap, spouseExceedsCap, splitAsr logic ✅ Preserved
AT_CAP_TOLERANCE boundary logic ✅ Preserved
403b deduction calculations ✅ Not touched
staffAccountBalance / primaryAccountBalance flow ✅ Preserved

No arithmetic was changed. Only the data source was moved from requestData?.latestAdditionalSalaryRequest?.calculations to context shortcuts.


📋 STANDARDS COMPLIANCE

Standard Status
File Naming
Named Exports
GraphQL ✅ N/A (no new operations)
Localization
Testing
Code Quality

📝 REVIEW SUMMARY

Agent Critical Important Suggestions Confidence
🏗️ Architecture 0 3 3 High
🧪 Testing 0 4 2 High
👤 UX 0 1 0 High
💰 Financial 0 2 2 High
📋 Standards 0 0 1 High
Total 0 5 unique 4 unique High

🎯 VERDICT

✅ APPROVE — Clean refactoring PR. No critical or high-priority blockers. All financial calculations verified preserved. The important issues noted are incremental improvement opportunities, not merge blockers.


🤖 Generated by MPDX Multi-Agent Review System v3.0 — 5 agents, standard mode

@dr-bizz dr-bizz changed the base branch from main to MPDX-9425 April 6, 2026 15:09
Base automatically changed from MPDX-9425 to main April 6, 2026 15:09
const individualCap =
requestData?.latestAdditionalSalaryRequest?.calculations.currentSalaryCap ??
0;
const individualCap = calculations?.currentSalaryCap ?? 0;
Copy link
Copy Markdown
Contributor Author

@dr-bizz dr-bizz Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are doing this in the context, which is why we don't need to call useAdditionalSalaryRequestQuery here

@dr-bizz dr-bizz requested a review from wjames111 April 6, 2026 15:17
@dr-bizz dr-bizz added the Preview Environment Add this label to create an Amplify Preview label Apr 6, 2026
@dr-bizz dr-bizz self-assigned this Apr 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

@wjames111 wjames111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great thanks for the refactor! Sorry I didn't realize how many test files would need to change. I did notice there's a few mocks with requestData in them that I don't think are needed anymore.

Comment on lines 307 to 460
@@ -400,6 +404,9 @@ describe('RequestPage', () => {
currentIndex: 1,
currentStep: AdditionalSalaryRequestSectionEnum.CompleteForm,
pageType: PageEnum.New,
calculations: {
currentSalaryCap: 50,
},
requestData: {
latestAdditionalSalaryRequest: {
calculations: {
@@ -451,6 +458,14 @@ describe('RequestPage', () => {
lastName: 'Doe',
},
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need these?

Comment on lines 21 to 28
requestData: {
latestAdditionalSalaryRequest: {
calculations: {
currentSalaryCap: 100000,
staffAccountBalance: 40000,
},
},
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove this now too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Preview Environment Add this label to create an Amplify Preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants