Skip to content

run tests on windows, fix executable paths for dart/flutter #149

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
merged 17 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/dart_mcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ defaults:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
sdk: [stable, dev]
sdk:
- stable
- dev
os:
- ubuntu-latest
- windows-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/dart_mcp_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ defaults:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
flutterSdk: [stable, master]
flutterSdk:
- stable
- master
os:
- ubuntu-latest
- windows-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# We need the flutter SDK in order to run the counter app for integration
Expand Down
12 changes: 9 additions & 3 deletions pkgs/dart_mcp_server/lib/src/utils/sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class Sdk {
if (dartSdkPath.parent case final cacheDir
when cacheDir.basename == 'cache' && flutterSdkPath == null) {
if (cacheDir.parent case final binDir when binDir.basename == 'bin') {
final flutterExecutable = binDir.child('flutter');
final flutterExecutable = binDir.child(
'flutter${Platform.isWindows ? '.bat' : ''}',
);
if (File(flutterExecutable).existsSync()) {
flutterSdkPath = binDir.parent;
}
Expand All @@ -61,7 +63,9 @@ class Sdk {
///
/// Throws an [ArgumentError] if [dartSdkPath] is `null`.
String get dartExecutablePath =>
dartSdkPath?.child('bin').child('dart') ??
dartSdkPath
?.child('bin')
.child('dart${Platform.isWindows ? '.exe' : ''}') ??
(throw ArgumentError(
'Dart SDK location unknown, try setting the DART_SDK environment '
'variable.',
Expand All @@ -71,7 +75,9 @@ class Sdk {
///
/// Throws an [ArgumentError] if [flutterSdkPath] is `null`.
String get flutterExecutablePath =>
flutterSdkPath?.child('bin').child('flutter') ??
flutterSdkPath
?.child('bin')
.child('flutter${Platform.isWindows ? '.bat' : ''}') ??
(throw ArgumentError(
'Flutter SDK location unknown. To work on flutter projects, you must '
'spawn the server using `dart` from the flutter SDK and not a Dart '
Expand Down
8 changes: 5 additions & 3 deletions pkgs/dart_mcp_server/test/test_harness.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:io' hide File;
import 'dart:io' as io show File;

import 'package:async/async.dart';
import 'package:dart_mcp/client.dart';
Expand Down Expand Up @@ -256,7 +257,7 @@ final class AppDebugSession {
await process.shouldExit(0);
} else {
unawaited(process.kill());
await process.shouldExit(anyOf(0, -9));
await process.shouldExit(anyOf(0, Platform.isWindows ? -1 : -9));
}
}

Expand Down Expand Up @@ -497,5 +498,6 @@ class _CommandMatcher extends Matcher {
}

extension RootPath on Root {
String get path => Uri.parse(uri).path;
/// Get the OS specific file path for this root.
String get path => io.File.fromUri(Uri.parse(uri)).path;
}
14 changes: 8 additions & 6 deletions pkgs/dart_mcp_server/test/tools/analyzer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// 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:io';

import 'package:dart_mcp/server.dart';
import 'package:dart_mcp_server/src/mixins/analyzer.dart';
import 'package:dart_mcp_server/src/utils/constants.dart';
Expand Down Expand Up @@ -75,14 +73,18 @@ void main() {
});

test('can look up symbols in a workspace', () async {
final currentRoot = testHarness.rootForPath(Directory.current.path);
testHarness.mcpClient.addRoot(currentRoot);
final example = d.dir('lib', [
d.file('awesome_class.dart', 'class MyAwesomeClass {}'),
]);
await example.create();
final exampleRoot = testHarness.rootForPath(example.io.path);
testHarness.mcpClient.addRoot(exampleRoot);
await pumpEventQueue();

final result = await testHarness.callToolWithRetry(
CallToolRequest(
name: DartAnalyzerSupport.resolveWorkspaceSymbolTool.name,
arguments: {ParameterNames.query: 'DartAnalyzerSupport'},
arguments: {ParameterNames.query: 'MyAwesomeClass'},
),
);
expect(result.isError, isNot(true));
Expand All @@ -92,7 +94,7 @@ void main() {
isA<TextContent>().having(
(t) => t.text,
'text',
contains('analyzer.dart'),
contains('awesome_class.dart'),
),
);
});
Expand Down
25 changes: 17 additions & 8 deletions pkgs/dart_mcp_server/test/tools/dart_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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:io';

import 'package:dart_mcp/server.dart';
import 'package:dart_mcp_server/src/mixins/dash_cli.dart';
import 'package:dart_mcp_server/src/utils/constants.dart';
Expand All @@ -15,6 +17,8 @@ void main() {
late TestProcessManager testProcessManager;
late Root exampleFlutterAppRoot;
late Root dartCliAppRoot;
final dartExecutableName = 'dart${Platform.isWindows ? '.exe' : ''}';
final flutterExecutableName = 'flutter${Platform.isWindows ? '.bat' : ''}';

// TODO: Use setUpAll, currently this fails due to an apparent TestProcess
// issue.
Expand Down Expand Up @@ -76,7 +80,7 @@ dependencies:
expect(result.isError, isNot(true));
expect(testProcessManager.commandsRan, [
equalsCommand((
command: [endsWith('dart'), 'fix', '--apply'],
command: [endsWith(dartExecutableName), 'fix', '--apply'],
workingDirectory: exampleFlutterAppRoot.path,
)),
]);
Expand All @@ -98,7 +102,7 @@ dependencies:
expect(result.isError, isNot(true));
expect(testProcessManager.commandsRan, [
equalsCommand((
command: [endsWith('dart'), 'format', '.'],
command: [endsWith(dartExecutableName), 'format', '.'],
workingDirectory: exampleFlutterAppRoot.path,
)),
]);
Expand All @@ -123,7 +127,12 @@ dependencies:
expect(result.isError, isNot(true));
expect(testProcessManager.commandsRan, [
equalsCommand((
command: [endsWith('dart'), 'format', 'foo.dart', 'bar.dart'],
command: [
endsWith(dartExecutableName),
'format',
'foo.dart',
'bar.dart',
],
workingDirectory: exampleFlutterAppRoot.path,
)),
]);
Expand Down Expand Up @@ -155,15 +164,15 @@ dependencies:
expect(testProcessManager.commandsRan, [
equalsCommand((
command: [
endsWith('flutter'),
endsWith(flutterExecutableName),
'test',
'foo_test.dart',
'bar_test.dart',
],
workingDirectory: exampleFlutterAppRoot.path,
)),
equalsCommand((
command: [endsWith('dart'), 'test', 'zip_test.dart'],
command: [endsWith(dartExecutableName), 'test', 'zip_test.dart'],
workingDirectory: dartCliAppRoot.path,
)),
]);
Expand All @@ -186,7 +195,7 @@ dependencies:
expect(testProcessManager.commandsRan, [
equalsCommand((
command: [
endsWith('dart'),
endsWith(dartExecutableName),
'create',
'--template',
'cli',
Expand All @@ -213,7 +222,7 @@ dependencies:
expect(testProcessManager.commandsRan, [
equalsCommand((
command: [
endsWith('flutter'),
endsWith(flutterExecutableName),
'create',
'--template',
'app',
Expand Down Expand Up @@ -243,7 +252,7 @@ dependencies:
expect(testProcessManager.commandsRan, [
equalsCommand((
command: [
endsWith('flutter'),
endsWith(flutterExecutableName),
'create',
'--template',
'app',
Expand Down
Loading