test: add memory leak prevention pattern tests (P1)

Add comprehensive tests for the cleanup patterns used to prevent
memory leaks in long-running sessions:

- Task description cache with TTL expiration
- Promise callback null-after-rejection pattern
- Event listener tracking and removal
- DOM handler storage for frontend cleanup
- Timer/interval management
- Map cleanup patterns and safe iteration
- WeakRef/WeakMap usage patterns
- Cleanup order verification (LIFO)

Update CLAUDE.md with reference to new test file.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-30 14:07:27 +01:00
co-authored by Claude Opus 4.5
parent 322802c1b9
commit e27c046abf
2 changed files with 682 additions and 0 deletions
+7
View File
@@ -191,6 +191,7 @@ Use `LRUMap` for bounded caches with eviction, `StaleExpirationMap` for TTL-base
| **Error codes** | `createErrorResponse()` in `src/types.ts` |
| **Test fixtures** | `test/e2e/fixtures/` |
| **Test utilities** | `test/respawn-test-utils.ts` |
| **Memory leak patterns** | `test/memory-leak-prevention.test.ts` |
| **Keyboard shortcuts** | README.md or App Settings in web UI |
| **Plan orchestrator** | `src/plan-orchestrator.ts` file header |
| **Agent prompts** | `src/prompts/` directory |
@@ -227,3 +228,9 @@ When adding new event listeners or timers:
1. Store handler references for later removal
2. Add cleanup to appropriate `stop()` or `cleanup*()` method
3. For singleton watchers, store refs in class properties and remove in server `stop()`
### Verification Tests
Memory leak prevention patterns are tested in `test/memory-leak-prevention.test.ts`. Run with:
```bash
npx vitest run test/memory-leak-prevention.test.ts
```