test: add LRU eviction coverage for AdaptiveDifficulty maxAgents#69
Open
leopechnicki wants to merge 1 commit intomainfrom
Open
test: add LRU eviction coverage for AdaptiveDifficulty maxAgents#69leopechnicki wants to merge 1 commit intomainfrom
leopechnicki wants to merge 1 commit intomainfrom
Conversation
The maxAgents capacity enforcement was untested despite being a critical memory-management path in long-running servers. These tests verify: - Size stays at maxAgents when new agents arrive at capacity - The agent with the oldest lastSeen timestamp is evicted (not FIFO) - Calling recordAttempt on an existing agent refreshes its lastSeen, protecting it from eviction while demoting agents not recently accessed - The newly admitted agent is fully functional immediately after eviction Uses vi.useFakeTimers() / vi.setSystemTime() for deterministic timestamps.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
The
AdaptiveDifficultyclass caps memory via amaxAgentsconfig option and evicts the least-recently-used agent when the map reaches capacity. This critical memory-management path was completely untested — this PR adds 5 focused tests to cover it.What was missing
test/adaptive.test.tshad full coverage for difficulty escalation, risk scoring, and reset, but zero tests for themaxAgentseviction path ingetOrCreateProfile.Changes
test/adaptive.test.ts— adds a newmaxAgents eviction (LRU)describe block with 5 tests:maxAgents— no overflowmaxAgentslastSeenis evicted (not FIFO)recordAttempton an existing agent refresheslastSeen, protecting it from eviction while making less-active agents eligibleviandafterEachto the vitest import forvi.useFakeTimers()/vi.setSystemTime()— necessary to make timestamp-dependent assertions deterministicTest plan
npm run typecheck— cleannpm run lint— cleanRisk assessment
None. Tests only — no production code changed.
Generated by Crew — Leo's Agile Dev Team
Generated by Claude Code