[analysis_server] Add a failing integration test for non-existent workspace roots

See https://github.com/dart-lang/sdk/issues/54116

Change-Id: Ic5d448f0b461fcc8d85384cf16ddd947da1ab02f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337542
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/test/integration/lsp_server/diagnostic_test.dart b/pkg/analysis_server/test/integration/lsp_server/diagnostic_test.dart
index dea1c48..97aaca6 100644
--- a/pkg/analysis_server/test/integration/lsp_server/diagnostic_test.dart
+++ b/pkg/analysis_server/test/integration/lsp_server/diagnostic_test.dart
@@ -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:analyzer/src/test_utilities/test_code_format.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -80,4 +82,45 @@
     expect(diagnostic.range.end.line, equals(0));
     expect(diagnostic.range.end.character, equals(23));
   }
+
+  /// Ensure we get diagnostics for a project even if the workspace contains
+  /// another folder that does not exist.
+  @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/54116')
+  Future<void> test_workspaceFolders_existsAndDoesNotExist() async {
+    if (!Platform.isWindows) {
+      // IF THIS TEST STARTS FAILING...
+      //
+      // This test is (at the time of writing) expected to fail on Windows. It
+      // passes on other platforms so we explicitly fail here for consistency.
+      //
+      // If the Windows bot start failing (because the issue is fixed and the
+      // test is now passing on Windows), this conditional code block should be
+      // removed, along with the .timeout() further down.
+      fail('Forced failure for non-Windows so we can detect when the Windows '
+          'issue is fixed');
+    }
+
+    final rootPath = projectFolderUri.toFilePath();
+    final existingFolderUri = Uri.file(pathContext.join(rootPath, 'exists'));
+    final existingFileUri =
+        Uri.file(pathContext.join(rootPath, 'exists', 'main.dart'));
+    final nonExistingFolderUri =
+        Uri.file(pathContext.join(rootPath, 'does_not_exist'));
+
+    newFolder(existingFolderUri.toFilePath());
+    newFile(existingFileUri.toFilePath(), 'NotAClass a;');
+
+    final diagnosticsFuture = waitForDiagnostics(existingFileUri);
+
+    await initialize(
+        workspaceFolders: [existingFolderUri, nonExistingFolderUri]);
+
+    // The .timeout() is to ensure this test fails in a way that @FailingTest
+    //  supports and does not just time out. This timeout should be removed
+    //  when the test is passing.
+    final diagnostics =
+        await diagnosticsFuture.timeout(const Duration(seconds: 10));
+    expect(diagnostics, hasLength(1));
+    expect(diagnostics!.single.code, 'undefined_class');
+  }
 }