feat(backend): implement exponential backoff retry, distributed locking, payload sanitization & integration tests - #1594
Open
kingsebuks001 wants to merge 2 commits into
Conversation
…ng, payload sanitization/validation, and integration test suite Closes emdevelopa#1429 - Implement automated retry with exponential backoff in Fraud Detection Engine Closes emdevelopa#1430 - Enhance distributed concurrency control and locking for Fraud Detection Engine Closes emdevelopa#1431 - Add comprehensive integration and stress test suite for Fraud Detection Engine Closes emdevelopa#1432 - Implement payload sanitization and strict validation for Audit Circuit Breaker - Added executeWithRetry() with exponential backoff and jitter to fraud-detection-engine.js - Added acquireLock(), releaseLock(), withLock() distributed locking primitives using Redis NX - Added sanitizePayload() with allowlist filtering, redaction, and prototype pollution protection - Added validatePayload() with strict field validation and descriptive ValidationError - Added 22-case integration and stress test suite in tests/integration/fraud-detection-integration.test.js - Updated .gitignore to exclude test snapshots, output files, logs, and build artifacts
|
@kingsebuks001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@kingsebuks001 is attempting to deploy a commit to the Emmanuel's projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR resolves 4 backend issues targeting the Fraud Detection Engine and Audit Circuit Breaker modules.
Changes
Closes #1429 — Exponential Backoff Retry in Fraud Detection Engine
isTransientError(err)to classify retryable errors (network errors, HTTP 429/503/5xx)executeWithRetry(fn, options)with configurablemaxRetries(default 3),baseDelayMs(200ms),maxDelayMs(5s), and ±20% jitterCloses #1430 — Distributed Concurrency Control and Locking for Fraud Detection Engine
LockTimeoutErrorclass for clean error handling on lock acquisition timeoutacquireLock(key, ttlMs, redis)using Redis SET NX EX with namespaced keys (fraud:lock:{id})releaseLock(lockKey, token, redis)using atomic Lua compare-and-delete to prevent accidental releasewithLock(key, ttlMs, fn, redis, opts)convenience wrapper — polls until acquired (3s timeout, 50ms interval), always releases infinallyanalyzePaymentLocked()wrapping core evaluation inwithLock+executeWithRetryCloses #1432 — Payload Sanitization and Strict Validation for Audit Circuit Breaker
ValidationErrorclass carryingfieldandreasonpropertiessanitizePayload(payload)— allowlist filtering (18 permitted fields), string truncation >1000 chars, prototype pollution blocking (__proto__/constructor/prototype), sensitive field redaction ([REDACTED])validatePayload(payload)— enforcesevent,timestamp,merchantIdwith strict regex and type checksAuditCircuitBreaker.process(rawPayload, handler)entry point running sanitize → validate before any circuit logicCloses #1431 — Comprehensive Integration and Stress Test Suite for Fraud Detection Engine
backend/tests/integration/fraud-detection-integration.test.js— 22 test casesFiles Changed
backend/src/lib/fraud-detection-engine.jsbackend/src/lib/audit-circuit-breaker.jsbackend/tests/integration/fraud-detection-integration.test.js.gitignore*.snap,__snapshots__/, output files, logs,.codexSecurity Notes