Skip to content

Commit 4e5f447

Browse files
authored
make invalid roots test less flaky (#324)
This test is currently red on head and I saw some flakes on a recent dependabot PR as well on windows. Adds some extra retry logic to allow for the new root notification to propagate more slowly.
1 parent 4eb2446 commit 4e5f447

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

pkgs/dart_mcp_server/test/tools/analyzer_test.dart

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -288,32 +288,34 @@ void main() {
288288
testHarness.mcpClient.addRoot(exampleRoot);
289289
await pumpEventQueue();
290290

291-
final request = CallToolRequest(
292-
name: analyzeTool.name,
293-
arguments: {
294-
ParameterNames.roots: [
295-
{'root': 'file:///invalid/root'},
296-
],
297-
},
298-
);
299-
final result = await testHarness.callToolWithRetry(
300-
request,
301-
expectError: true,
302-
);
303-
expect(result.isError, isTrue);
304-
expect(
305-
result.content.single,
306-
isA<TextContent>().having(
307-
(t) => t.text,
308-
'text',
309-
allOf(
310-
contains(
311-
'Invalid root file:///invalid/root, must be under one of the registered project roots:',
291+
// We won't see the expected error until the roots notification
292+
// propagates to the server.
293+
await callWithRetry(() async {
294+
final request = CallToolRequest(
295+
name: analyzeTool.name,
296+
arguments: {
297+
ParameterNames.roots: [
298+
{'root': 'file:///invalid/root'},
299+
],
300+
},
301+
);
302+
final result = await testHarness.callTool(request, expectError: true);
303+
expect(result.isError, isTrue);
304+
expect(
305+
result.content.single,
306+
isA<TextContent>().having(
307+
(t) => t.text,
308+
'text',
309+
allOf(
310+
contains(
311+
'Invalid root file:///invalid/root, must be under one of the '
312+
'registered project roots:',
313+
),
314+
contains(example.io.uri.toString()),
312315
),
313-
contains(example.io.uri.toString()),
314316
),
315-
),
316-
);
317+
);
318+
});
317319
});
318320

319321
test('can analyze files in multiple roots', () async {

0 commit comments

Comments
 (0)