* Add test demonstrating bug #4788 - ClosePrompt panics with nil
Adds TestClosePromptNilCancelPanic that reproduces the bug where
ClosePrompt() panics with a nil pointer dereference when cancelPrompt
is nil. This can happen if ClosePrompt is called before the prompt is
fully initialized.
Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix#4788: Add nil check before calling cancelPrompt
Prevents panic in ClosePrompt() when cancelPrompt is nil.
This can happen if ClosePrompt is called before the prompt
is fully initialized.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Changes:
1. Renamed TestQueryContextLeakage -> TestContextCancellationTiming
- The test was checking cancellation timing, not memory leaks
- Updated comments to reflect actual purpose
2. Increased timeout from 1ms to 100ms
- 1ms is too aggressive for CI runners under load
- 100ms still catches real deadlocks while avoiding flakiness
- Added detailed comments explaining the timeout choice
3. Added TestNoGoroutineLeaks using goleak
- Properly tests for actual resource leaks (goroutines)
- More reliable than memory-based leak detection
- Uses industry-standard goleak library
The original 1ms timeout caused intermittent CI failures on slower
runners, as context cancellation involves goroutine scheduling that
has no guaranteed sub-millisecond timing.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <noreply@anthropic.com>