mirror of
https://github.com/alsk1992/CloddsBot.git
synced 2026-10-02 02:54:40 +08:00
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:
co-authored by
Claude Opus 4.5
parent
978c92a405
commit
f3bec44125
@@ -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: [],
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user