-
Notifications
You must be signed in to change notification settings - Fork 39
add prompt for using flutter driver to write a test for a user journey #243
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:dart_mcp/server.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
/// A mixin which adds support for various dart and flutter specific prompts. | ||
base mixin DashPrompts on PromptsSupport { | ||
@override | ||
FutureOr<InitializeResult> initialize(InitializeRequest request) { | ||
addPrompt(flutterDriverUserJourneyTest, _flutterDriverUserJourneyPrompt); | ||
return super.initialize(request); | ||
} | ||
|
||
/// Creates the flutter driver user journey prompt based on a request. | ||
GetPromptResult _flutterDriverUserJourneyPrompt(GetPromptRequest request) { | ||
return GetPromptResult( | ||
messages: [ | ||
PromptMessage( | ||
role: Role.user, | ||
content: flutterDriverUserJourneyPromptContent, | ||
), | ||
], | ||
); | ||
} | ||
|
||
@visibleForTesting | ||
static final flutterDriverUserJourneyTest = Prompt( | ||
name: 'flutter_driver_user_journey_test', | ||
title: 'User journey flutter driver test', | ||
description: ''' | ||
Prompts the LLM to attempt to accomplish a user journey in the running app using | ||
flutter driver. If successful, it will then translate the steps it followed into | ||
a flutter driver test and write that to disk. | ||
''', | ||
); | ||
|
||
@visibleForTesting | ||
static final flutterDriverUserJourneyPromptContent = Content.text( | ||
text: ''' | ||
Perform the following tasks in order: | ||
|
||
- Prompt the user to navigate to the home page of the app. | ||
- Prompt the user for a user journey that they would like to write a test for. | ||
- Attempt to complete the given user journey using flutter driver to inspect the | ||
widget tree and interact with the application. Only durable interactions | ||
should be performed, do not use temporary IDs to select or interact with | ||
widgets, but instead select them based on text, type, tooltip, etc. Avoid | ||
reading in files to accomplish this task, just inspect the live state of the | ||
app and widget tree. If you get stuck, feel free to ask the user for help. | ||
- If you are able to successfully complete the journey, then create a flutter | ||
driver based test with an appropriate name, which performs all the same | ||
actions that you performed. Include the original user journey as a comment | ||
in the test file. | ||
''', | ||
); | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:dart_mcp/server.dart'; | ||
import 'package:dart_mcp_server/src/mixins/prompts.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../test_harness.dart'; | ||
|
||
void main() { | ||
late TestHarness testHarness; | ||
|
||
// TODO: Use setUpAll, currently this fails due to an apparent TestProcess | ||
// issue. | ||
setUp(() async { | ||
testHarness = await TestHarness.start(); | ||
}); | ||
|
||
test('can list prompts', () async { | ||
final server = testHarness.mcpServerConnection; | ||
final promptsResult = await server.listPrompts(ListPromptsRequest()); | ||
expect( | ||
promptsResult.prompts, | ||
equals([ | ||
isA<GetPromptRequest>().having( | ||
(p) => p.name, | ||
'name', | ||
DashPrompts.flutterDriverUserJourneyTest.name, | ||
), | ||
]), | ||
); | ||
}); | ||
|
||
test('can get the flutter driver user journey prompt', () async { | ||
final server = testHarness.mcpServerConnection; | ||
final prompt = await server.getPrompt( | ||
GetPromptRequest(name: DashPrompts.flutterDriverUserJourneyTest.name), | ||
); | ||
expect( | ||
prompt.messages.single, | ||
isA<PromptMessage>() | ||
.having((m) => m.role, 'role', Role.user) | ||
.having( | ||
(m) => m.content, | ||
'content', | ||
equals(DashPrompts.flutterDriverUserJourneyPromptContent), | ||
), | ||
); | ||
}); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Note that this was just duplicative, this getter exists in one of the implemented types already