Skip to content

chore: declare type on properties - #3082

Closed
Lightning00Blade wants to merge 1 commit into
mainfrom
declare-types-on-properties
Closed

Lightning00Blade wants to merge 1 commit into
mainfrom
declare-types-on-properties

Conversation

@Lightning00Blade

Copy link
Copy Markdown
Collaborator

No description provided.

@Lightning00Blade
Lightning00Blade marked this pull request as ready for review October 13, 2026 10:02

@OrKoN OrKoN left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of AI findings first:

  1. Annotate tool exports with the concrete schema (e.g. PageToolFactory<typeof screenshotSchema>) instead of bare PageToolFactory / ToolFactory, in src/tools/*.ts. The bare default (zod.ZodRawShape) erases each tool's schema type for importers, which is why tests/tools/screenshot.test.ts had to switch to zod.object(tool.schema).parse({}) and lost its type checking.

  2. Enforce the annotations: either set isolatedDeclarations: true for src/ or use @typescript-eslint/explicit-module-boundary-types, instead of isolatedDeclarations: false in tsconfig.json. false is the default, so new code will skip the annotations and the codebase will drift back to inconsistent.

  3. Split the build-pipeline change (dropping allowJs, plus the hand-maintained devtoolsThirdPartyFiles copy list in scripts/post-build.ts) into its own PR. It changes how build/ is produced and has nothing to do with the PR title, and every devtools-frontend roll that adds a JS dependency now needs a manual list update; missing one only shows up at runtime as ERR_MODULE_NOT_FOUND.

  4. Restore the marked metadata entry in tests/third_party_notices.test.js.snapshot, e.g. by also copying marked/package/package.json in scripts/post-build.ts. It disappeared because removing allowJs stopped package.json from being emitted next to marked, not because of the cleanup exclude, so the bundled MIT dependency lost its name/URL/version line.

  5. Fix the comment on the exclude: ['**/marked.esm.js'] in rollup.config.js ("Minifed" is a typo). It should say the timeout comes from copying the raw minified file instead of tsc-reprinted output, so the link to the allowJs change is clear.

  6. Explain or drop declaration: true in tsconfig.json. It emits .d.ts files into the published build/src, which then reference unpublished build/third_party/devtools-frontend paths and lighthouse-devtools-mcp-bundle.js. If kept, scripts/post-build.ts must also copy src/third_party/lighthouse-devtools-mcp-bundle.d.ts.

  7. Remove no-op or unrelated compiler options from tsconfig.json:

    • no-ops: strict and module: esnext (TS 6 defaults), noUnused*: false, allowSyntheticDefaultImports
    • unrelated: experimentalDecorators, preserveConstEnums, ESNext.Array
    • workflow changes that need a justification or removal: noEmitOnError (blocks the dev build on any type error) and inlineSources (bloats sourcemaps)

    They look copied from the devtools-frontend config and none of them is justified.

  8. In scripts/tsconfig.json, either keep allowJs or drop the ./**/*.js / ./**/*.mjs include globs. Without allowJs those globs do nothing, and declaration / isolatedDeclarations are meaningless under noEmit: true.

  9. In src/third_party/lighthouse-devtools-mcp-bundle.d.ts, make snapshot / navigation return Promise<RunnerResult | undefined> and type generateReport's format as an optional output mode. Lighthouse can return undefined (src/tools/lighthouse.ts already checks if (!result)), and the bundle defaults format to "html".

  10. With the new .d.ts in place, drop the redundant as casts on snapshotImpl / navigationImpl / generateReportImpl in src/third_party/index.ts. The declaration now provides those types, and AGENTS.md forbids as.

  11. Add a PR description, and squash or reword the two commits titled fix. They contain material changes (a new .d.ts, the rollup exclude, a license snapshot change) that reviewers and git log can't see from the titles.

@Lightning00Blade
Lightning00Blade force-pushed the declare-types-on-properties branch from 2584e03 to 0e97957 Compare October 13, 2026 16:08
twotnguyen pushed a commit to twotnguyen/chrome-devtools-mcp that referenced this pull request Oct 16, 2026
Part of ChromeDevTools#2639.

Five `take_screenshot` handler tests launched a real browser only to
check which arguments reach `page.screenshot` / the element handle and
what ends up in the response. This migrates them in place to
`createHandlerMocks` and asserts the exact calls with `sinon.assert`,
following `AGENTS.md`:

- `ignores quality`: asserts a PNG capture is requested with `quality:
undefined` even when `quality: 0` is passed, plus the response line and
the attached `image/png` data.
- `with jpeg`: asserts the requested `quality` is forwarded to
`page.screenshot` with `type: 'jpeg'`, and the image is attached as
`image/jpeg`.
- `with webp`: asserts the `--screenshot-quality` CLI value is used when
no `quality` param is given, and the image is attached as `image/webp`.
- `disposes the element handle after an element screenshot` / `when the
capture fails`: use `createMockElementHandle()` instead of spying on a
real handle, and assert `dispose` is called once in both the success and
the rejection path (and no image is attached on failure).

Kept on the real browser:

- `with default options`, `with full page`, `with element uid`, `with
filePath`: the end-to-end checks that a real capture/file write works.
- The `downscales ...` / `honors screenshotMaxWidth ...` / `does not
resize ...` tests: they check real pixel sizes; the clip math is already
covered by the mock tests in the `downscale clip` block.
- `with unwritable filePath` and `with malformed filePath`: they are
currently the only tests that exercise the real `McpContext.saveFile`
write failure, so moving them belongs with `tests/McpContext.test.ts`
rather than here.
- `honors screenshotFormat default from CLI args`: left untouched
because ChromeDevTools#3082 edits the same lines.

**Testing**

- `npm run build && NODE_TEST_REPORTER=spec node scripts/test.js
tests/tools/screenshot.test.ts`: all migrated tests pass; each now takes
about 30–100 ms instead of about 80–700 ms. (On my Windows machine `with
full page resulting in a large screenshot` fails with `Page is too
large` both before and after this change; it is not touched here.)
- Sanity check that they still catch regressions: forwarding `quality`
for PNG, dropping the request `quality`, dropping the
`screenshotQuality` fallback, hard-coding the `image/png` MIME type, and
skipping the `using` disposal of the element handle each make the
corresponding migrated test(s) fail.
- `eslint` and `prettier` are clean; only
`tests/tools/screenshot.test.ts` changes.
zjdCander pushed a commit to zjdCander/chrome-devtools-mcp that referenced this pull request Oct 19, 2026
## Summary

Add a **Pre-submit checklist** section to `AGENTS.md`. Each item comes
from a recent review finding or a landed bug fix in this repository.

The checklist has five groups:

- **Scope and PR description**: one change per PR, title and commit type
match, description lists every behavior change and matches the diff,
`npm run gen` and `npm run format` ran.
- **Design**: fix in the lowest layer that owns the data, fix upstream
(Puppeteer, devtools-frontend) first, one helper for repeated code,
options objects instead of positional `undefined` arguments, validation
in Zod schemas.
- **Correctness and edge cases**: no stale state after a failed call,
artifacts written before a throw, abandoned async continuations, mutex
guards, file removal races, `dispose()` releases every resource, secrets
never reach logs, path parameters validated even when they parse as
URLs.
- **Tests**: every new function has a test, no vacuous assertions,
`notCalled` targets the first call after validation, exact-argument
assertions, reusable stubs in `tests/mocks.ts`, bounded timeouts, no
second CDP session for event waits.
- **Documentation and output**: tool descriptions state when a parameter
is ignored, skills stay generic, one-sentence inline comments.

Sources: review comments on ChromeDevTools#2679, ChromeDevTools#2797, ChromeDevTools#2859, ChromeDevTools#2881, ChromeDevTools#2901, ChromeDevTools#3048,
ChromeDevTools#3082, ChromeDevTools#3109, ChromeDevTools#3120, ChromeDevTools#3132, ChromeDevTools#3134, ChromeDevTools#3139, ChromeDevTools#3148, ChromeDevTools#3156, ChromeDevTools#3158, ChromeDevTools#3161,
ChromeDevTools#3182, ChromeDevTools#3183, ChromeDevTools#3186, ChromeDevTools#3187, ChromeDevTools#3188, ChromeDevTools#3189, ChromeDevTools#3192, ChromeDevTools#3196, ChromeDevTools#3197, ChromeDevTools#3198,
ChromeDevTools#3203, ChromeDevTools#3204, and fixes ChromeDevTools#3150, ChromeDevTools#3160, ChromeDevTools#3185, ChromeDevTools#3202, ChromeDevTools#3207, ChromeDevTools#3208.

Existing content in `AGENTS.md` is unchanged.

Closes ChromeDevTools#3222
@Lightning00Blade
Lightning00Blade force-pushed the declare-types-on-properties branch from 3a5c38a to b4199a7 Compare October 19, 2026 17:55

@OrKoN OrKoN left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the following:

  1. Annotate tool exports with the concrete schema, for example PageToolFactory<typeof screenshotSchema>, in src/tools/*.ts. The bare PageToolFactory / ToolFactory / BrowserlessToolFactory default to zod.ZodRawShape and erase the schema type, so tests/tools/screenshot.test.ts still needs the untyped zod.object(tool.schema).parse({}) workaround.
  2. Move the Lighthouse refactor (McpPage.lighthouseNavigation / lighthouseSnapshot, ContextPage, removal of lighthouseRunner, tests/tools/lighthouse.test.ts) into its own PR. It changes the call path and test seams of lighthouse_audit and is unrelated to explicit module boundary types.
  3. Add a test that calls McpPage.lighthouseNavigation and McpPage.lighthouseSnapshot, or keep a stubbable seam such as lighthouseRunner. The new methods call ES module functions that sinon cannot stub, so no test asserts that McpPage passes the page URL and flags to Lighthouse.
  4. Remove "module": "esnext" and "preserveConstEnums": true from tsconfig.json, or justify them in the PR description. esnext is already the default, and preserveConstEnums has no relation to type annotations.
  5. Add a PR description, and change the title to match the change, for example chore: enforce explicit module boundary types. The description must list the new ESLint rule, the new lighthouse-devtools-mcp-bundle.d.ts, the new copy step in scripts/post-build.ts, and the Lighthouse refactor.

@Lightning00Blade
Lightning00Blade deleted the declare-types-on-properties branch October 21, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants