Skip to content
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
7 changes: 2 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ This repository contains an MCP server and CLI for Chrome DevTools.
`browser.js`; never re-export them from `index.ts`. Small pure modules may be
re-exported from `index.ts` by their direct file path.
- ESLint (`@typescript-eslint/no-restricted-imports` in `eslint.config.js`)
rejects value imports from `browser.js` in `src/tools/`, `src/config/` and
`src/telemetry/`. It only sees direct imports, so
`tests/browser-imports.test.ts` also checks that the listed modules do not
reach `browser.js` through other modules. Add new tool, config and telemetry
modules to it.
rejects direct value imports from `browser.js` in `src/tools/`,
`src/config/` and `src/telemetry/`.

## Rules for TypeScript

Expand Down
2 changes: 0 additions & 2 deletions tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ ts_library("tests") {
"SlimMcpResponse.test.ts",
"TextSnapshot.test.ts",
"ToolHandler.test.ts",
"browser-imports.test.ts",
"browser.test.ts",
"cli-imports.test.ts",
"cli.test.ts",
Expand Down Expand Up @@ -60,7 +59,6 @@ ts_library("tests") {
"formatters/RemoteObjectFormatter.test.ts",
"formatters/WebAuthnFormatter.test.ts",
"formatters/snapshotFormatter.test.ts",
"importGraph.ts",
"index.test.ts",
"mocks.ts",
"network_blocking.test.ts",
Expand Down
53 changes: 0 additions & 53 deletions tests/browser-imports.test.ts

This file was deleted.

44 changes: 39 additions & 5 deletions tests/cli-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,55 @@
*/

import assert from 'node:assert';
import {readFileSync} from 'node:fs';
import path from 'node:path';
import {describe, it} from 'node:test';

import {zod} from '../src/third_party/index.js';

import {BUILD_SRC, findImportPath} from './importGraph.js';

const BUILD_SRC = path.resolve(import.meta.dirname, '..', 'src');
const CLI_ENTRY = path.join(BUILD_SRC, 'bin', 'chrome-devtools.js');
const FULL_BUNDLE = path.join(BUILD_SRC, 'third_party', 'index.js');

const IMPORT_RE = /\b(?:from|import)\s*\(?\s*['"](\.{1,2}\/[^'"]+)['"]/g;

/**
* Walks the static and dynamic relative imports of the built JS files and
* returns the first path from `entry` to `target`, or undefined.
*/
function findImportPath(entry: string, target: string): string[] | undefined {
const parents = new Map<string, string | undefined>([[entry, undefined]]);
const queue = [entry];
while (queue.length > 0) {
const file = queue.shift();
if (file === undefined) {
break;
}
if (file === target) {
const chain = [];
for (let f: string | undefined = file; f; f = parents.get(f)) {
chain.unshift(path.relative(BUILD_SRC, f));
}
return chain;
}
if (!file.startsWith(BUILD_SRC)) {
continue;
}
const source = readFileSync(file, 'utf8');
for (const match of source.matchAll(IMPORT_RE)) {
const next = path.resolve(path.dirname(file), match[1]);
if (!parents.has(next)) {
parents.set(next, file);
queue.push(next);
}
}
}
return undefined;
}

describe('chrome-devtools CLI imports', () => {
it('does not load the full third-party bundle', () => {
const chain = findImportPath(CLI_ENTRY, FULL_BUNDLE, {
includeDynamicImports: true,
});
const chain = findImportPath(CLI_ENTRY, FULL_BUNDLE);
assert.strictEqual(
chain,
undefined,
Expand Down
54 changes: 0 additions & 54 deletions tests/importGraph.ts

This file was deleted.