Description
InMemoryIdempotencyStore in src/middleware/idempotency.ts exposes checkAndReserve, save, release, and a pruneExpired path driven by ttlMs, but the expiry and in-flight state machine need exhaustive tests. Add unit tests that exercise the new → inflight → cached transitions and TTL-based eviction with a controllable clock.
Requirements and context
- Must be secure, tested, and documented
- Should be efficient and easy to review
- Relevant code:
src/middleware/idempotency.ts, src/middleware/idempotency.test.ts
- Expired cached records must be treated as
new and never returned as cached
Suggested execution
- Fork the repo and create a branch
git checkout -b test/idempotency-store-ttl
- Implement changes
- Use fake timers to advance past
ttlMs
- Assert reserve → inflight, save → cached, release frees the key
- Assert pruning removes expired entries on access
- Validate security and correctness assumptions
Test and commit
- Run tests
- Cover edge cases
- Zero/undefined TTL never expires, double release, save without reserve, concurrent reserve
- Include test output and notes
Example commit message
test: cover idempotency store TTL and state transitions
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
InMemoryIdempotencyStoreinsrc/middleware/idempotency.tsexposescheckAndReserve,save,release, and apruneExpiredpath driven byttlMs, but the expiry and in-flight state machine need exhaustive tests. Add unit tests that exercise thenew→inflight→cachedtransitions and TTL-based eviction with a controllable clock.Requirements and context
src/middleware/idempotency.ts,src/middleware/idempotency.test.tsnewand never returned ascachedSuggested execution
git checkout -b test/idempotency-store-ttlttlMsTest and commit
npm testExample commit message
test: cover idempotency store TTL and state transitionsGuidelines