From 1d74a92384786e422d90c81f6ae5dfd7a35f9946 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Mon, 1 Dec 2025 17:20:03 +0000 Subject: [PATCH] make invalid roots test less flaky --- .../test/tools/analyzer_test.dart | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/pkgs/dart_mcp_server/test/tools/analyzer_test.dart b/pkgs/dart_mcp_server/test/tools/analyzer_test.dart index 98c55542..f83c2a0a 100644 --- a/pkgs/dart_mcp_server/test/tools/analyzer_test.dart +++ b/pkgs/dart_mcp_server/test/tools/analyzer_test.dart @@ -288,32 +288,34 @@ void main() { testHarness.mcpClient.addRoot(exampleRoot); await pumpEventQueue(); - final request = CallToolRequest( - name: analyzeTool.name, - arguments: { - ParameterNames.roots: [ - {'root': 'file:///invalid/root'}, - ], - }, - ); - final result = await testHarness.callToolWithRetry( - request, - expectError: true, - ); - expect(result.isError, isTrue); - expect( - result.content.single, - isA().having( - (t) => t.text, - 'text', - allOf( - contains( - 'Invalid root file:///invalid/root, must be under one of the registered project roots:', + // We won't see the expected error until the roots notification + // propagates to the server. + await callWithRetry(() async { + final request = CallToolRequest( + name: analyzeTool.name, + arguments: { + ParameterNames.roots: [ + {'root': 'file:///invalid/root'}, + ], + }, + ); + final result = await testHarness.callTool(request, expectError: true); + expect(result.isError, isTrue); + expect( + result.content.single, + isA().having( + (t) => t.text, + 'text', + allOf( + contains( + 'Invalid root file:///invalid/root, must be under one of the ' + 'registered project roots:', + ), + contains(example.io.uri.toString()), ), - contains(example.io.uri.toString()), ), - ), - ); + ); + }); }); test('can analyze files in multiple roots', () async {