Files
proffesor-for-testing__agen…/tests/integration/api-contract-validator-integration.test.ts
Profa 669361dfa2 fix: Resolve memory leaks and MCP test response structure mismatches
Fixes #35: Integration Test Memory Leak (Partial)
- Add MemoryManager instance tracking with Set<MemoryManager>
- Implement MemoryManager.shutdownAll() for batch cleanup
- Make shutdown() idempotent with isShutdown flag
- Add leak warnings when >10 instances exist
- Enhance jest.global-teardown.ts with MemoryManager cleanup
- Add comprehensive afterEach cleanup template

Fixes #37: MCP Test Response Structure Mismatches
- Update 24 MCP test files to use nested metadata structure
- Fix 29+ assertions: expect(response).toHaveProperty('requestId')
- Fix 6+ direct access: response.requestId → response.metadata.requestId
- All tests now correctly check response.metadata.requestId

Changes:
- src/core/MemoryManager.ts: Instance tracking, shutdownAll(), idempotent shutdown
- jest.global-teardown.ts: Global MemoryManager cleanup with timeout
- tests/integration/api-contract-validator-integration.test.ts: Cleanup template
- tests/mcp/handlers/**/*.test.ts: 24 files with response structure fixes

Impact:
- Prevents 270-540MB memory leak from MemoryManager timers
- Fixes all MCP test response structure assertions
- TypeScript compilation: 0 errors
- Centralized cleanup reduces "Jest did not exit" errors

Test Results:
- TypeScript build: SUCCESS
- MCP tests: Response structure fixed (validation logic separate issue)
- Integration test: Cleanup template established

Remaining Work:
- Validation logic fixes (handlers should reject invalid input)
- Additional integration test cleanup (35 more files)
- Both tracked for separate PRs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 11:16:11 +00:00

34 KiB