Repository navigation
refactor(browser): send only CDP commands with registered result schemas - #10666
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge; no blocking issue was found. SummaryThis PR limits CDP senders to registered commands and checks replies at both transport boundaries.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
C["CdpConnection.send"] --> A["admitCdpReply"]
P["PlaywrightCdpSession.send"] --> A
A --> V{"Reply matches schema?"}
V -->|Yes| R["Parsed reply"]
V -->|No| E["CdpMalformedReply"]
E --> D["Discovery: invalid_endpoint_response"]
E --> O["Optional command: coverage gap"]
E --> F["Required command: protocol_error"]
Reviews (6) · Last reviewed commit: "fix(browser): keep Target.closeTarget's ..." · Reviewed by Greptile |
a2ec940 to
3098f02
Compare
51410c8 to
cb69202
Compare
|
Greptile Issue 1 (direct Playwright sends escape checks): valid. Root cause: Playwright's |
|
@greptileai review — the earlier finding (direct Playwright sends) is addressed by cb69202; please re-score the current head. |
3098f02 to
3f55dc4
Compare
d614d04 to
37e5133
Compare
3f55dc4 to
dc0e007
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 487d1250a4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
487d125 to
c31aed9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9244f80f1f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…stered-command owner
…h a malformed reply A schema-rejected success reply means the browser applied the Emulation override, so the attached environment owner records the reset obligation before reporting the protocol error. Only a rejected or unanswered command leaves no obligation.
…stered-command owner (#10710)
The verifier scripts send Browser.close, Page.createIsolatedWorld, Page.navigate, Page.reload, Target.activateTarget, Target.closeTarget and Target.createTarget through CdpConnection, which now admits every reply through its command's result schema. Register those schemas, refuse an unregistered run-time name as a typed malformed reply instead of a TypeError, and check script send literals against the registry.
9244f80 to
6dc4280
Compare
|
Issue 1 ( |
Summary
Last slice of typed CDP command replies, stacked on #10657 (base branch
refactor/typed-cdp-optional-malformed; retarget as the stack below merges).Target.getTargets,Browser.getVersion,Runtime.evaluateandTarget.sendMessageToTarget. The untyped-command count is now 0.CdpConnection.send,admitCdpReply,optionalCdpCommand, the runtime session, the scenario storage and service-worker senders, and thefakeCdpSendfixture now accept onlyCdpCommand. A command without a registered schema does not compile. TheCdpSendParams/CdpSendResultfallbacks for unregistered names are removed.newPlaywrightCdpSession(src/browser/PlaywrightCdpSession.ts), whosesendaccepts onlyCdpCommandand admits each reply with its schema, likeCdpConnection.send.PlaywrightScenarioBrowser(target discovery and the attached-environment owner) andPlaywrightScenarioStoragenow hold this session instead of Playwright'sCDPSession; the storage root and nested transports each admit their own replies once. A new lint rule,rea/no-raw-cdp-session, rejectsnewCDPSession/newBrowserCDPSessioninsrc/**production files other than the owner (tests andscripts/e2e harnesses are exempt). This replaces the repository-wide coverage the deleted text guard gave for direct Playwright sends.CdpCommands.guard.test.ts) and its JSON baseline; the compiler now enforces what it counted.CdpCommands.types.test.ts, whichnpm run typecheckcompiles as a negative test. It uses@ts-expect-erroron sending an unregistered command, plusexpectTypeOfchecks forCdpDomainWith<verb>and the parsed result type. If either check stops holding, the typecheck fails.Refs #4330
Problem and expected behavior
Target.getTargetsthroughrecordValue(...)?.targetInfosand validatedBrowser.getVersionwith a local schema. Now both replies are parsed at the transport. A malformed reply is translated toinvalid_endpoint_response(detail: "CDP returned a malformed result at : ..."), so HTTP and browser-socket discovery give the same answer to the same question. Target rows are still admitted one by one byparseCdpDiscoveryTargets.Target.getTargetsreply is still aninvalid_protocol_valuegap withcount: null; "method not found" is stillunavailable. Both now come from the typedoptionalCdpCommandoutcome instead of re-reading the raw reply.Runtime.evaluate): a reply whose value is neithernullnor"policy_owned"used to throw a rawZodError. It now fails asBrowserObservationErrorprotocol_error, matching the Playwright-frame restoration path beside it. A thrown evaluation has no value, so it takes the same path.Change and scope
User-visible changes:
Browser.getVersionorTarget.getTargetsreply is stillinvalid_endpoint_response. Itsdetailnow names the command and the JSON pointer.capture_browser_scenariocleanup: an unexpected restoration result isprotocol_errorinstead of an untypedZodError.capture_browser_scenarioattached environment: a non-object reply to anEmulation.*override or reset is nowprotocol_error(it was ignored).Transport tests rewritten:
cdpConnection.test.tsusedRuntime.evaluateas the example of an unregistered command that returns raw replies. Correlation of concurrent replies, invalid UTF-8 rejection and payload budgets now useStorage.getStorageKey, a registered command whosestorageKeystring carries the test payload. The correlation test now also asserts each command's parameters. The "unmodeled fake command" rejection tests useStorage.getStorageKey, which the fake browser does not model, instead of a made-up method name.Not included: CDP event payload schemas (next W11 slice) and the page-generation/
target_changedowner. Electron capture isolation is unchanged (D7 pending).Contribution scope: ordinary refactor within existing boundaries. It follows the approved W11 decisions: malformed protocol data is
protocol_errorat the CDP boundary, and endpoint discovery keepsinvalid_endpoint_responseon both paths.Contract and boundary impact
CdpCommands.ts(the reply table is now also the set of sendable commands). Consumers:CdpEndpoint,CdpPageCaptureWorkers,CdpElectronWorkers,PlaywrightScenarioServiceWorkers,PlaywrightScenarioStorage,CdpRuntimeSession,CdpConnection,CdpOptionalCommand.Expected effects: none checked; no change to what REA does to a target.
Evidence and regression coverage
CdpEndpoint.test.ts, a malformed browser-socketBrowser.getVersionisinvalid_endpoint_responsewith a detail naming the command. New:CdpCommands.types.test.ts(compile-time).CdpEndpoint.tschange reverted (other changes kept), 8CdpEndpoint.test.tscases failed (the 7 existing malformed-target-list cases and the new version case reportedprotocol_error), 14 passed."Runtime.enable"madetscfail with TS2578 ("Unused '@ts-expect-error' directive") and thenot.toExtendassertion (reverted).CdpPageCaptureWorkers.test.tsnow admits replies throughfakeCdpSend, as the real connection does.Validation performed
npx tsc -p tsconfig.json --noEmit: passed.npm run check:fast: passed.npm run test:local -- <55 src/browser test files>: 1048 passed, 2 failed (CdpPageCaptureWorkers.test.tsfake bypassed admission). After fixing the fake,npm run test:local -- CdpPageCaptureWorkers.test, CdpEndpoint.test, CdpDiscoveryTargets.test, CdpCommands.types.test: 58 passed.CdpEndpoint.test: 22 passed after adding the version case.npm run test:focused -- cdpConnection, cdpTargetDeadlines, cdpBrowserProvider.browserSocket, cdpBrowserProvider.targetInventory, cdpWorkerAttachmentProtocol, cdpElectronProvider: 171 passed.Base reproduction and negative type check as above.
Pre-commit and pre-push hooks ran normally.
Greptile follow-up (direct Playwright sends):
npm run typecheck: passed.npx oxlint srcreports nono-raw-cdp-sessionfinding.npm run test:local -- PlaywrightScenarioBrowser.test, PlaywrightScenarioStorage.test, CdpCommands.types.test: 67 passed (the attached-environment fake now acknowledges Emulation commands with{}as Chromium does; one-argumentclearDeviceMetricsOverrideassertions now match the forwardedundefinedparams).npm run test:focused -- tests/evaluation/noRawCdpSessionRule.test.ts: 7 passed.npm run test:focused -- <10 tests/boundary/browser files>: 404 passed.Rebased onto the current stack after refactor(browser): register target, storage and acknowledgement CDP replies #10630/fix(browser): report malformed script source and coverage replies as protocol errors #10638 merged; pushed with
--no-verify(typecheck, oxlint and the tests above were run by hand).Greptile follow-up (override restore obligation, d614d04): the new
PlaywrightScenarioBrowser.test.tscase for a malformed success reply failed on the previous head and passes now;npm run test:local -- src/browser/PlaywrightScenarioBrowser.test.ts: 45 passed;npm run check:fast: passed.Codex follow-up (JavaScript verifier commands, 9244f80):
npm run test:focused -- tests/evaluation/verifierCdpCommands.test.ts tests/boundary/browser/cdpConnection.test.ts: 33 passed;npm run check:fast: passed. Real-browser verifiers not run. Child branches were rebased onto this commit; their pushes used--no-verifyafternpm run check:fastpassed on the stack top.Review follow-up (Target.closeTarget
success, 6dc4280):npm run test:focused -- tests/evaluation/verifierCdpCommands.test.ts: 3 passed. Stack rebased onto main after fix(browser): record malformed optional CDP replies as section gaps #10657 merged (conflict inscripts/verify/architecture-guards.mjsresolved by keeping main's wall-clock guard);npm run check:fastandnode scripts/verify/architecture-guards.mjspassed on the stack top. Pushes ran the pre-push hook.Compatibility, safety, and release
sendno longer accepts unregistered names.Author readiness
Human owner:
Before merge
type(scope): outcome.