Fix extract_bugs.ts to look into TestExpectations for skipped tests

Bug: 393986723
Change-Id: I878cd58ec586f38ed745d7483a241bed70685b73
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/8158061
Reviewed-by: Nikolay Vitkov <nvitkov@chromium.org>
Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org>
Auto-Submit: Alex Rudenko <alexrudenko@chromium.org>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
diff --git a/scripts/extract_bugs.ts b/scripts/extract_bugs.ts
index 91ccf50..dd52a98 100644
--- a/scripts/extract_bugs.ts
+++ b/scripts/extract_bugs.ts
@@ -2,11 +2,13 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-import {globSync, readFileSync} from 'node:fs';
+import {existsSync, globSync, readFileSync} from 'node:fs';
 import * as ts from 'typescript';
 import yargs from 'yargs';
 import {hideBin} from 'yargs/helpers';
 
+import {parseExpectations} from '../test/conductor/test_expectations_parser.js';
+
 const argv = yargs(hideBin(process.argv))
                  .option('format', {
                    alias: 'f',
@@ -84,6 +86,21 @@
         file, readFileSync(file).toString(), ts.ScriptTarget.ESNext,
         /* setParentNodes */ true));
   }
+
+  const devtoolsExpectationsPath = 'test/TestExpectations';
+  if (existsSync(devtoolsExpectationsPath)) {
+    const content = readFileSync(devtoolsExpectationsPath, 'utf-8');
+    const expectations = parseExpectations(content);
+    for (const exp of expectations) {
+      if (!exp.isCommentOrEmpty && exp.results?.includes('Skip')) {
+        for (const bug of exp.bugs || []) {
+          const bugId = bug.replace('crbug.com/', '');
+          bugs.add(bugId);
+          bugToFile.set(bugId, exp.testName || '');
+        }
+      }
+    }
+  }
 }
 
 if (argv.sources.includes('chromium')) {