Repository navigation
chore: declare type on properties - #3082
Lightning00Blade wants to merge 1 commit into
Conversation
OrKoN
left a comment
There was a problem hiding this comment.
A bunch of AI findings first:
-
Annotate tool exports with the concrete schema (e.g.
PageToolFactory<typeof screenshotSchema>) instead of barePageToolFactory/ToolFactory, insrc/tools/*.ts. The bare default (zod.ZodRawShape) erases each tool's schema type for importers, which is whytests/tools/screenshot.test.tshad to switch tozod.object(tool.schema).parse({})and lost its type checking. -
Enforce the annotations: either set
isolatedDeclarations: trueforsrc/or use@typescript-eslint/explicit-module-boundary-types, instead ofisolatedDeclarations: falseintsconfig.json.falseis the default, so new code will skip the annotations and the codebase will drift back to inconsistent. -
Split the build-pipeline change (dropping
allowJs, plus the hand-maintaineddevtoolsThirdPartyFilescopy list inscripts/post-build.ts) into its own PR. It changes howbuild/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 asERR_MODULE_NOT_FOUND. -
Restore the
markedmetadata entry intests/third_party_notices.test.js.snapshot, e.g. by also copyingmarked/package/package.jsoninscripts/post-build.ts. It disappeared because removingallowJsstoppedpackage.jsonfrom being emitted next to marked, not because of the cleanup exclude, so the bundled MIT dependency lost its name/URL/version line. -
Fix the comment on the
exclude: ['**/marked.esm.js']inrollup.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 theallowJschange is clear. -
Explain or drop
declaration: trueintsconfig.json. It emits.d.tsfiles into the publishedbuild/src, which then reference unpublishedbuild/third_party/devtools-frontendpaths andlighthouse-devtools-mcp-bundle.js. If kept,scripts/post-build.tsmust also copysrc/third_party/lighthouse-devtools-mcp-bundle.d.ts. -
Remove no-op or unrelated compiler options from
tsconfig.json:- no-ops:
strictandmodule: 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) andinlineSources(bloats sourcemaps)
They look copied from the devtools-frontend config and none of them is justified.
- no-ops:
-
In
scripts/tsconfig.json, either keepallowJsor drop the./**/*.js/./**/*.mjsinclude globs. WithoutallowJsthose globs do nothing, anddeclaration/isolatedDeclarationsare meaningless undernoEmit: true. -
In
src/third_party/lighthouse-devtools-mcp-bundle.d.ts, makesnapshot/navigationreturnPromise<RunnerResult | undefined>and typegenerateReport'sformatas an optional output mode. Lighthouse can returnundefined(src/tools/lighthouse.tsalready checksif (!result)), and the bundle defaultsformatto"html". -
With the new
.d.tsin place, drop the redundantascasts onsnapshotImpl/navigationImpl/generateReportImplinsrc/third_party/index.ts. The declaration now provides those types, andAGENTS.mdforbidsas. -
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 andgit logcan't see from the titles.
2584e03 to
0e97957
Compare
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.
## 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
3a5c38a to
b4199a7
Compare
OrKoN
left a comment
There was a problem hiding this comment.
Please check the following:
- Annotate tool exports with the concrete schema, for example
PageToolFactory<typeof screenshotSchema>, insrc/tools/*.ts. The barePageToolFactory/ToolFactory/BrowserlessToolFactorydefault tozod.ZodRawShapeand erase the schema type, sotests/tools/screenshot.test.tsstill needs the untypedzod.object(tool.schema).parse({})workaround. - Move the Lighthouse refactor (
McpPage.lighthouseNavigation/lighthouseSnapshot,ContextPage, removal oflighthouseRunner,tests/tools/lighthouse.test.ts) into its own PR. It changes the call path and test seams oflighthouse_auditand is unrelated to explicit module boundary types. - Add a test that calls
McpPage.lighthouseNavigationandMcpPage.lighthouseSnapshot, or keep a stubbable seam such aslighthouseRunner. The new methods call ES module functions that sinon cannot stub, so no test asserts thatMcpPagepasses the page URL andflagsto Lighthouse. - Remove
"module": "esnext"and"preserveConstEnums": truefromtsconfig.json, or justify them in the PR description.esnextis already the default, andpreserveConstEnumshas no relation to type annotations. - 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 newlighthouse-devtools-mcp-bundle.d.ts, the new copy step inscripts/post-build.ts, and the Lighthouse refactor.
No description provided.