Fix rate limiter config precedence and test assertions

- User config now takes precedence over default limits
- Fix test to use getStats().windowRequests instead of non-existent currentCount
- All 20 trading-safety tests now pass

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
alsk1992
2026-01-30 16:05:49 +00:00
co-authored by Claude Opus 4.5
parent 978c92a405
commit f3bec44125
2 changed files with 7 additions and 6 deletions
+2 -1
View File
@@ -149,7 +149,8 @@ export function createRateLimiter(
if (!state) {
// Find matching config from defaults
const defaultLimit = DEFAULT_RATE_LIMITS[endpoint] || DEFAULT_RATE_LIMITS['default'];
const config = { ...baseConfig, ...defaultLimit };
// User config (baseConfig) takes precedence over defaults
const config = { ...defaultLimit, ...baseConfig };
state = {
requests: [],
+5 -5
View File
@@ -218,12 +218,12 @@ describe('Rate Limiter', () => {
limiter.recordRequest('/a');
limiter.recordRequest('/b');
const statusA = limiter.getStatus('/a');
const statusB = limiter.getStatus('/b');
const statsA = limiter.getStats('/a');
const statsB = limiter.getStats('/b');
// Each should have their own count
assert.strictEqual(statusA.currentCount, 1);
assert.strictEqual(statusB.currentCount, 1);
// Each should have their own count (windowRequests = requests in current window)
assert.strictEqual(statsA.windowRequests, 1);
assert.strictEqual(statsB.windowRequests, 1);
});
it('should block when limit exceeded', () => {