Skip to content

test(middleware): cover pause guard state races, concurrent toggles, and route boundaries - #2219

Open
hubbuugittuuu wants to merge 1 commit into
LabsCrypt:mainfrom
hubbuugittuuu:test/pause-guard-state-races-2093
Open

hubbuugittuuu wants to merge 1 commit into
LabsCrypt:mainfrom
hubbuugittuuu:test/pause-guard-state-races-2093

Conversation

@hubbuugittuuu

Copy link
Copy Markdown

Summary

This PR adds comprehensive unit and regression test coverage for pauseGuard middleware in backend/src/middleware/__tests__/pauseGuard.test.ts, addressing concurrent pause state transitions, mid-flight loan mutation races, and exempt route boundary rules.

Closes #2093

Details of Changes

  • Concurrent State Transitions & Race Conditions:
    • Validates that concurrent invocations of setPauseState preserve valid in-memory state without race condition corruptions.
    • Tests rapid transition from unpaused to paused, verifying immediate rejection of mutating loan operations (/api/loans/disburse) with 503 AppError.
    • Tests transition from paused to unpaused, ensuring subsequent mutating operations (/api/loans/repay) are permitted through to next().
  • Error Formatting & Fallbacks:
    • Asserts error message formatting and fallback handling when reason is null or omitted, verifying Maintenance or security measure default.
  • Fail-Open Database Resilience:
    • Verifies that when database synchronization query fails, pauseGuard fails open gracefully and preserves existing in-memory state.
  • Exempt Route Boundary Verification:
    • Tests exact prefix matches for exempt routes (/api/auth/login, /api/v1/auth/session, /api/admin/recovery, /api/v1/admin/unpause, /admin/status).
    • Verifies that non-exempt or partially matching routes (/api/authentication/login, /api/administrator/kill, /api/loans/repay, /api/v1/loans/apply, /api/contracts/invoke) remain strictly blocked during an active pause.

Verification & CI Proof

  • npm run lint: Passed (0 errors)
  • npm run build: Passed (0 errors)
  • npm test -- src/middleware/__tests__/pauseGuard.test.ts: 28/28 tests passing (100% green)
  • Full backend test suite: 125 test suites passed (1102 tests green)

This branch has not been deployed

No deployments
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.

[test] Cover pause guard state races

1 participant