-
-
Notifications
You must be signed in to change notification settings - Fork 664
feat: comprehensive MockAgent debugging improvements #4381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mcollina
wants to merge
8
commits into
main
Choose a base branch
from
feature/mockagent-debugging-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add comprehensive plan to improve MockAgent debugging experience including enhanced error messages, real-time request tracing, and development mode features. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
Add comprehensive debugging features to MockAgent: - Enhanced error messages with interceptor context and suggestions - Real-time request tracing with console.error output - MockAgent.debug() method for state inspection - MockAgent.inspect() method for formatted console output - New constructor options: traceRequests, developmentMode, verboseErrors - Development mode that auto-enables debugging features - Smart request matching with similarity scoring - Updated TypeScript definitions - Comprehensive test coverage Features improve debugging experience by providing detailed context when mocks don't match, real-time request visibility, and easy state inspection tools. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
Add MockAgent.compareRequest() method that compares a request against an interceptor and returns detailed difference analysis: - Field-by-field comparison (path, method, body, headers) - Similarity scoring for each field - Overall match score calculation - Detailed difference objects with expected vs actual values This helps developers understand exactly why a request doesn't match a specific interceptor, making debugging more precise. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
Add comprehensive debugging features to complete the plan: **Interceptor Validation:** - Add MockScope.validate() method for interceptor configuration validation - Detect common issues like double slashes, unusual methods, conflicting settings - Provide detailed feedback with severity levels (warning/error) **Enhanced assertNoPendingInterceptors:** - Add showUnusedInterceptors option to show interceptors never called - Add showCallHistory option to include recent call history in errors - Add includeRequestDiff option for detailed request vs interceptor comparison **Smart Request Tracing:** - Enhanced tracing with closest match suggestions in basic mode - Show available interceptors when requests don't match - Intelligent similarity-based recommendations **Utility Functions:** - Export calculateStringSimilarity, findClosestMatches, buildEnhancedErrorMessage - Complete TypeScript definitions for all new methods and options - Comprehensive test coverage for all features All features maintain backward compatibility and follow existing code patterns. The implementation significantly improves MockAgent debugging experience with actionable insights when mocks don't work as expected. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
… coverage - Add configurable console option to MockAgent for custom tracing output - Implement comprehensive test suite for all tracing scenarios (basic, verbose, custom console) - Fix enhanced error messages to be opt-in via verboseErrors option to maintain backward compatibility - Update TypeScript definitions to include console option - Add example demonstrating custom console usage for tracing - Ensure all 92 existing MockAgent tests continue to pass The console option allows developers to: - Capture tracing output in tests for assertions - Send logs to custom logging systems - Filter or format tracing messages - Test tracing behavior itself 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
- Fix assertNoPendingInterceptors signature to include new options - Add type tests for debug(), inspect(), and compareRequest() methods - Add type tests for new constructor options (traceRequests, developmentMode, verboseErrors, console) - Add type tests for MockScope.validate() method - Ensure all TypeScript tests pass with proper type coverage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
Signed-off-by: Matteo Collina <[email protected]>
Add detailed documentation for the new MockAgent debugging capabilities: - New constructor options: traceRequests, developmentMode, verboseErrors, console - Request tracing with basic and verbose modes - Enhanced error messages with interceptor context - debug() and inspect() methods for state inspection - compareRequest() method for interceptor analysis - Enhanced assertNoPendingInterceptors() options - Custom console support for testing - Development mode for streamlined debugging setup 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements comprehensive debugging improvements for MockAgent to address the common pain point of difficult debugging when mocks don't match requests. The changes provide detailed context, intelligent suggestions, and powerful state inspection tools.
🚀 Key Features
Enhanced Error Messages
Real-time Request Tracing
traceRequests: true
): Simple match/no-match with interceptor suggestionstraceRequests: 'verbose'
): Detailed step-by-step matching processconsole.error
for easy debuggingDevelopment Mode
developmentMode: true
automatically enables debugging featuresState Inspection Tools
debug()
: Returns comprehensive MockAgent state as structured datainspect()
: Pretty-prints debug information to console with tablescompareRequest()
: Detailed diff analysis between requests and interceptorsInterceptor Validation
validate()
: Proactive validation of interceptor configurationEnhanced Assertions
assertNoPendingInterceptors()
with new options:showUnusedInterceptors
: Display interceptors that were never calledshowCallHistory
: Include recent request history in error messagesincludeRequestDiff
: Show detailed comparison between recent requests and pending interceptors📊 Usage Examples
🔧 Technical Details
📈 Before/After
Before:
After:
🧪 Test Plan
🔗 Related
Addresses the MockAgent debugging challenges outlined in the planning document. This implementation follows the prioritized feature list and maintains full backward compatibility while dramatically improving the debugging experience.
🤖 Generated with Claude Code