#19095: test(discord): add unit tests for presence cache module
channel: discord
size: S
trusted-contributor
Cluster:
Test Coverage Enhancements
The presence cache module (`src/discord/monitor/presence-cache.ts`) had zero test coverage.
Adds 9 unit tests covering:
- Store and retrieve presence data
- Undefined accountId fallback behavior
- Overwrites for same user+account
- Per-account clearing
- Global clearing
- Cross-account size tracking
- Max-size eviction (5000 cap)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds a comprehensive unit test suite for the Discord presence cache module (`src/discord/monitor/presence-cache.ts`), which previously had zero test coverage. The 9 tests cover the full public API surface: `setPresence`, `getPresence`, `clearPresences`, and `presenceCacheSize`, including edge cases like the `undefined` accountId fallback to `"default"` key and the 5000-entry per-account eviction cap.
- Tests follow project conventions: colocated `*.test.ts`, vitest framework, proper `afterEach` cleanup of module-level state
- Eviction test correctly verifies FIFO eviction behavior at the 5000-entry boundary
- No issues found — clean, focused test addition with no production code changes
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it only adds a new test file with no changes to production code.
- Score of 5 reflects that this is a pure test addition with no production code changes. The tests are correctly written, properly isolated, and follow project conventions. No logical errors or issues found.
- No files require special attention.
<sub>Last reviewed commit: 7a61b28</sub>
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
<!-- /greptile_comment -->
Most Similar PRs
#12684: Test: add missing unit tests for src/utils modules
by shaynhornik · 2026-02-09
78.2%
#15569: test: comprehensive test coverage expansion (57 new test files)
by tangcruz · 2026-02-13
76.4%
#19104: test(discord): improve gateway logging test coverage
by Clawborn · 2026-02-17
75.9%
#9333: Tests: add test coverage for security/audit-fs.ts
by M00N7682 · 2026-02-05
73.7%
#7585: Tests: fix lint in discord auto-thread race test
by justinhuangcode · 2026-02-03
73.1%
#20496: test(utils): add comprehensive unit tests for utility functions
by masifislamm · 2026-02-19
72.7%
#4086: Test/add backoff tests
by TechWizard9999 · 2026-01-29
72.4%
#8964: test(msteams): add comprehensive tests for graph-upload module
by RajdeepKushwaha5 · 2026-02-04
72.3%
#11421: Tests: add unit tests for infra/format-duration
by PythonUser42 · 2026-02-07
71.9%
#4095: Test/add format duration tests
by TechWizard9999 · 2026-01-29
71.7%