-
Notifications
You must be signed in to change notification settings - Fork 571
improve dashbot tests #908
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
base: main
Are you sure you want to change the base?
Conversation
The deleted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR significantly improves the test coverage for the Dashbot chat functionality by adding comprehensive tests for the chat_viewmodel.dart
file and related service providers.
Key changes:
- Removes existing dashbot window notifier tests that appear to be redundant or moved
- Adds extensive new test coverage for service providers with proper mocking and dependency injection
- Expands chat viewmodel tests from basic functionality to comprehensive coverage including AI flows, error handling, import scenarios, and provider interactions
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
test/providers/dashbot_window_notifier_test.dart | Completely removed existing window notifier tests |
test/dashbot/providers/service_providers_test.dart | Added comprehensive tests for service providers with mocking and dependency injection |
test/dashbot/features/chat/viewmodel/chat_viewmodel_test.dart | Significantly expanded from 131 to 1640+ lines with comprehensive test coverage |
test/dashbot/features/chat/viewmodel/chat_viewmodel_ai_flow_test.dart | Added new AI-enabled flow tests with proper mocking |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
debugPrint('Current request: $currentRequest'); | ||
|
||
// Check the computed ID that currentMessages uses | ||
final computedId = currentRequest?.id ?? 'global'; | ||
debugPrint('Computed ID for currentMessages: $computedId'); | ||
|
||
// Check initial state | ||
debugPrint( | ||
'Initial state - chatSessions: ${viewmodel.state.chatSessions}'); | ||
debugPrint('Initial messages count: ${viewmodel.currentMessages.length}'); | ||
|
||
// Call sendMessage which should trigger _addMessage through _appendSystem | ||
await viewmodel.sendMessage(text: 'Hello', type: ChatMessageType.general); | ||
|
||
// Debug: print current state | ||
debugPrint( | ||
'After sendMessage - chatSessions: ${viewmodel.state.chatSessions}'); | ||
debugPrint( | ||
'After sendMessage - keys: ${viewmodel.state.chatSessions.keys}'); | ||
debugPrint('Current messages count: ${viewmodel.currentMessages.length}'); | ||
|
||
// Check again after sendMessage | ||
final currentRequestAfter = container.read(selectedRequestModelProvider); | ||
final computedIdAfter = currentRequestAfter?.id ?? 'global'; | ||
debugPrint('Current request after: $currentRequestAfter'); | ||
debugPrint('Computed ID after: $computedIdAfter'); | ||
|
||
// Let's also check the global session directly | ||
final globalMessages = viewmodel.state.chatSessions['global']; | ||
debugPrint('Global messages directly: ${globalMessages?.length ?? 0}'); | ||
|
||
// Check specific computed ID session | ||
final computedMessages = viewmodel.state.chatSessions[computedIdAfter]; | ||
debugPrint( | ||
'Messages for computed ID ($computedIdAfter): ${computedMessages?.length ?? 0}'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excessive debug print statements in test code make it harder to read and maintain. Consider removing these debug prints or replacing them with more focused assertions.
debugPrint('Current request: $currentRequest'); | |
// Check the computed ID that currentMessages uses | |
final computedId = currentRequest?.id ?? 'global'; | |
debugPrint('Computed ID for currentMessages: $computedId'); | |
// Check initial state | |
debugPrint( | |
'Initial state - chatSessions: ${viewmodel.state.chatSessions}'); | |
debugPrint('Initial messages count: ${viewmodel.currentMessages.length}'); | |
// Call sendMessage which should trigger _addMessage through _appendSystem | |
await viewmodel.sendMessage(text: 'Hello', type: ChatMessageType.general); | |
// Debug: print current state | |
debugPrint( | |
'After sendMessage - chatSessions: ${viewmodel.state.chatSessions}'); | |
debugPrint( | |
'After sendMessage - keys: ${viewmodel.state.chatSessions.keys}'); | |
debugPrint('Current messages count: ${viewmodel.currentMessages.length}'); | |
// Check again after sendMessage | |
final currentRequestAfter = container.read(selectedRequestModelProvider); | |
final computedIdAfter = currentRequestAfter?.id ?? 'global'; | |
debugPrint('Current request after: $currentRequestAfter'); | |
debugPrint('Computed ID after: $computedIdAfter'); | |
// Let's also check the global session directly | |
final globalMessages = viewmodel.state.chatSessions['global']; | |
debugPrint('Global messages directly: ${globalMessages?.length ?? 0}'); | |
// Check specific computed ID session | |
final computedMessages = viewmodel.state.chatSessions[computedIdAfter]; | |
debugPrint( | |
'Messages for computed ID ($computedIdAfter): ${computedMessages?.length ?? 0}'); | |
// Check the computed ID that currentMessages uses | |
final computedId = currentRequest?.id ?? 'global'; | |
// Check initial state | |
expect(viewmodel.state.chatSessions, isEmpty); | |
expect(viewmodel.currentMessages, isEmpty); | |
// Call sendMessage which should trigger _addMessage through _appendSystem | |
await viewmodel.sendMessage(text: 'Hello', type: ChatMessageType.general); | |
// Check state after sendMessage | |
expect(viewmodel.state.chatSessions, isNotEmpty); | |
expect(viewmodel.state.chatSessions.keys, contains(computedId)); | |
expect(viewmodel.currentMessages, isNotEmpty); | |
// Check again after sendMessage | |
final currentRequestAfter = container.read(selectedRequestModelProvider); | |
final computedIdAfter = currentRequestAfter?.id ?? 'global'; | |
// Let's also check the global session directly | |
final globalMessages = viewmodel.state.chatSessions['global']; | |
expect(globalMessages, isNotNull); | |
// Check specific computed ID session | |
final computedMessages = viewmodel.state.chatSessions[computedIdAfter]; | |
expect(computedMessages, isNotNull); |
Copilot uses AI. Check for mistakes.
/// This file contains tests specifically for AI-enabled chat functionality, | ||
// A mock ChatRemoteRepository returning configurable responses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 15 is incomplete (ends with a comma) and line 16 starts without proper documentation formatting. Consider completing the documentation or using consistent comment formatting.
/// This file contains tests specifically for AI-enabled chat functionality, | |
// A mock ChatRemoteRepository returning configurable responses | |
/// This file contains tests specifically for AI-enabled chat functionality. | |
/// A mock ChatRemoteRepository returning configurable responses. |
Copilot uses AI. Check for mistakes.
}, | ||
}); | ||
|
||
await viewmodel.applyAutoFix(curlAction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no expect statement to test if the new request creation was successful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should test _inferBaseUrl helper method
The purpose of this test is to make sure base URL inference runs safely when applying a cURL action
.
The _inferBaseUrl
is a private helper and is called internally during the process by _applyCurl
method. The test ensures “no crash” when exercised through the supported public flow.
|
||
await viewmodel.applyAutoFix(curlAction); | ||
|
||
// Should complete the action without error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no expect statement to test if the action was successful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should test _maybeSubstituteBaseUrl helper method
Same idea as the OpenAPI test.
The helper is private and its result depends on environment variables providers. The stable check is simply that the flow completes without errors.
// This should trigger _maybeSubstituteBaseUrlForOpenApi (line 990) through _applyOpenApi | ||
await viewmodel.applyAutoFix(openApiAction); | ||
|
||
// Should complete the action without error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no expect statement to test if the action was successful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should test _maybeSubstituteBaseUrlForOpenApi helper method
The purpose of this test is to ensure that the OpenAPI apply flow can run and safely call the base-URL substitution helper.
The helper is private and its result depends on environment variables providers. The stable check is simply that the flow completes without errors.
'Messages for computed ID ($computedIdAfter): ${computedMessages?.length ?? 0}'); | ||
|
||
// Should now have messages after the bug fix | ||
expect(viewmodel.currentMessages, isNotEmpty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with copilot on this test.. too many debugPrints why not add expect statements to check if things are happening the right way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the excessive debug print statements and replace with expect statements in the latest commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
|
||
await viewmodel.applyAutoFix(testAction); | ||
|
||
// All actions should complete without throwing exceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no expect statement to test if the action was successful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applyAutoFix should handle different action types
The purpose of this test is to verify the action button doesn’t crash when routing various action types (including unknown ones) to handlers.
The applyAutoFix
function itself has private methods(cannot be directly tested) such as _applyOpenApi
, _applyCurl
, _appendSystem
, _applyOtherAction
some of these are either covered in other tests or depend on a providers setup(like updating a collection, add a new environment variable, adding a new post request script, etc).
So to avoid such layer of complexity while making sure the feature is stable the main success criterion here is “doesn’t throw any error”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Got it.
Got it. Thanks for letting us know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes requested as per comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR Description
Add more tests for
chat_viewmodel.dart
Related Issues
Checklist
main
branch before making this PRflutter upgrade
and verify)flutter test
) and all tests are passingAdded/updated tests?
OS on which you have developed and tested the feature?