Download src/lib/rateLimiter.test.ts from HonzaH/Letschat: direct link, hf CLI and curl.
- Browser
- Download file 782 Bytes
-
https://huggingface.co/spaces/HonzaH/Letschat/resolve/main/src/lib/rateLimiter.test.ts
- Command line
-
hf download hf://spaces/HonzaH/Letschat/src/lib/rateLimiter.test.ts
-
curl -L -o rateLimiter.test.ts https://huggingface.co/spaces/HonzaH/Letschat/resolve/main/src/lib/rateLimiter.test.ts
782 Bytes
| import { describe, it, expect, beforeEach } from 'vitest' | |
| import { assertNotBlocked, noteFailure, resetFailures } from './rateLimiter' | |
| const cfg = { limit: 3, windowMs: 5 * 60 * 1000, blockMs: 5 * 60 * 1000, escalateAfterBlocks: 3, escalateBlockMs: 24 * 60 * 60 * 1000 } | |
| describe('rateLimiter', () => { | |
| beforeEach(() => { | |
| resetFailures('key') | |
| }) | |
| it('blocks after threshold', () => { | |
| assertNotBlocked('key') | |
| noteFailure('key', cfg) | |
| noteFailure('key', cfg) | |
| noteFailure('key', cfg) | |
| expect(() => assertNotBlocked('key')).toThrow() | |
| }) | |
| it('resets after resetFailures', () => { | |
| noteFailure('key', cfg) | |
| noteFailure('key', cfg) | |
| noteFailure('key', cfg) | |
| resetFailures('key') | |
| expect(() => assertNotBlocked('key')).not.toThrow() | |
| }) | |
| }) | |