Skip to content

test: add LRU eviction coverage for AdaptiveDifficulty maxAgents#69

Open
leopechnicki wants to merge 1 commit intomainfrom
crew/test/adaptive-maxagents-eviction
Open

test: add LRU eviction coverage for AdaptiveDifficulty maxAgents#69
leopechnicki wants to merge 1 commit intomainfrom
crew/test/adaptive-maxagents-eviction

Conversation

@leopechnicki
Copy link
Copy Markdown
Owner

Summary

The AdaptiveDifficulty class caps memory via a maxAgents config 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.ts had full coverage for difficulty escalation, risk scoring, and reset, but zero tests for the maxAgents eviction path in getOrCreateProfile.

Changes

  • test/adaptive.test.ts — adds a new maxAgents eviction (LRU) describe block with 5 tests:
    1. Size stays at maxAgents — no overflow
    2. Adding past capacity caps the total at maxAgents
    3. The agent with the oldest lastSeen is evicted (not FIFO)
    4. Calling recordAttempt on an existing agent refreshes lastSeen, protecting it from eviction while making less-active agents eligible
    5. The newly admitted agent is immediately functional with correct stats
  • Adds vi and afterEach to the vitest import for vi.useFakeTimers() / vi.setSystemTime() — necessary to make timestamp-dependent assertions deterministic

Test plan

  • All 5 new tests pass against the existing implementation
  • Full suite: 519 tests pass (514 existing + 5 new), no regressions
  • npm run typecheck — clean
  • npm run lint — clean

Risk assessment

None. Tests only — no production code changed.


Generated by Crew — Leo's Agile Dev Team


Generated by Claude Code

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.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
im_robot Ready Ready Preview, Comment Apr 27, 2026 8:47am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants