[PR #3901] [MERGED] fix(browser): keep malformed Electron CDP inventories incomplete #5959

Closed
opened 2026-10-31 01:10:44 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/3901
Author: @kaoru0822-kitauji
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/3379-electron-cdp-inventories


📝 Commits (1)

  • 127a275 fix(browser): keep malformed Electron CDP inventories incomplete

📊 Changes

4 files changed (+234 additions, -113 deletions)

View changed files

📝 src/browser/CdpCaptureDocuments.ts (+119 -69)
📝 src/browser/CdpElectronInspection.ts (+45 -38)
📝 src/browser/CdpElectronWorkers.ts (+13 -6)
📝 tests/boundary/browser/cdpElectronProvider.test.ts (+57 -0)

📄 Description

Summary

Fixes #3379. inspect-electron-page turned unreadable CDP replies into empty inventories while still reporting complete_within_window:

  • a DOM snapshot without documents, or with missing/misaligned node arrays;
  • a resource tree frame with resources: null;
  • a Target.getTargets reply with targetInfos: null.

A caller could not tell these apart from genuinely empty collections.

Problem and expected behavior

Smallest trigger: a successful DOMSnapshot.captureSnapshot reply of {} yields 0 DOM nodes with complete_within_window and no exclusion. A missing or invalid required collection must remain unknown and be identified in completeness. A valid empty array may still mean empty.

Change and scope

  • Shared parsers: the web capture path (CdpCaptureDocuments.ts) already validated these replies, while the Electron inspection had a separate, weaker copy. The validation now has one owner in CdpCaptureDocuments.ts, used by both web and Electron inspection:
    • snapshotDocuments(value, onInvalid): a missing, empty or non-array document list, or a non-record document, is reported as invalid.
    • snapshotDocumentNodes(value): returns the validated parallel node arrays (types, names, values, parents, attributes, backend IDs), plus the count of attribute rows beyond the node count. Missing or misaligned arrays return undefined.
    • frameTreeResources(root, onInvalid): yields resource records across the frame tree via walkFrameTrees. A non-array resources list or a non-record entry is reported as invalid.
  • Electron consumers: captureDom and captureResources use the shared parsers, so the Electron copies (recordsValue/arrayValue defaults) are removed. Unreadable parts are recorded as invalid_protocol_value exclusions on dom or resources.
  • Workers: CdpElectronWorkers records a non-array targetInfos as an invalid_protocol_value exclusion with unknown count, and each non-record target as a counted exclusion.
  • Web path: behavior is unchanged; it now calls the same functions.
  • Not included: Electron still throws protocol_error when the resource tree has no frameTree root, as before. Unreadable documentURL indexes keep their existing out-of-scope classification.

Contract and boundary impact

  • Semantic owner and earliest changed stage: CDP reply parsing for DOM snapshots, resource trees and worker targets (src/browser/CdpCaptureDocuments.ts, CdpElectronInspection.ts, CdpElectronWorkers.ts).
  • Contribution scope fit and linked maintainer decision: an ordinary fix within existing boundaries, so not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. Malformed replies now add completeness.excluded entries and the section to unavailable_sections. The status is derived by the existing completeness owner, so it becomes attach_limited, as the web capture path already reports for identical replies.
  • Provider, bridge, target-format, or platform compatibility: the CDP/Electron provider only.
  • Evidence, artifact, provenance, or reconstruction contract: unreadable collections are reported as incomplete instead of as empty.
  • Target selection, authority, upstream behavior, and cleanup details: unchanged.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process. This is existing inspect-electron-page behavior, unchanged here; tests attach only to a local fake CDP endpoint.

Evidence and regression coverage

  • Tests added to tests/boundary/browser/cdpElectronProvider.test.ts, covering 4 malformed replies through the public provider and a fake CDP endpoint:

    • a snapshot without documents;
    • a snapshot document with a null node array;
    • a frame with resources: null;
    • targetInfos: null.

    Each must record an invalid_protocol_value exclusion for its section and not report complete_within_window. All 4 fail on main.

  • Base reproduction (executed): the issue's public-CLI matrix (inspect-electron-page … --observation-ms 100 --include-script-sources --json against its local HTTP/WebSocket CDP fixture), main cf0a38ad9 vs. this branch.

Mode DOM / resources / workers main branch Output bytes (main → branch)
control 1 / 1 / 1 complete_within_window, no exclusions unchanged 3,714 → 3,714
malformed DOM ({}) 0 / 1 / 1 complete_within_window, no exclusions attach_limited, {section: "dom", reason: "invalid_protocol_value", count: null} 3,604 → 3,657
malformed resources (resources: null) 1 / 0 / 1 complete_within_window, no exclusions attach_limited, resources invalid_protocol_value 3,406 → 3,471
malformed workers (targetInfos: null) 1 / 1 / 0 complete_within_window, no exclusions attach_limited, workers invalid_protocol_value 3,463 → 3,524
  • Timing: no measurable change expected. The same loops run over the same records; only validation branches moved, so no performance claim is made.
  • Remaining proof gaps: no real Electron application was attached. As in the report, no real Electron instance emitting these malformed replies is known; the valid paths are covered by the existing fake-CDP boundary suite.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/browser/*.test.ts: 49 files passed, 1 skipped. That is 550 tests passed and 6 skipped, including the 4 new cases, which fail on main.
  • npm run test:local -- src/browser/*.test.ts: 23 files and 257 tests passed.
  • npm run check:fast: typecheck and lint pass. The pre-push hook also passed.
  • The issue's public-CLI matrix above, on both main and this branch.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Callers that relied on malformed replies being "complete" now see an accurate incomplete status.
  • Real Hopper/Ghidra, browser, or OS coverage: fake CDP endpoints only; no real Electron or Chromium run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new target interaction, and file-scope authorization is unchanged.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/3901 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/3379-electron-cdp-inventories` --- ### 📝 Commits (1) - [`127a275`](https://github.com/morluto/rea/commit/127a27598b9d1674c4e6efea5d7d93256b4d1411) fix(browser): keep malformed Electron CDP inventories incomplete ### 📊 Changes **4 files changed** (+234 additions, -113 deletions) <details> <summary>View changed files</summary> 📝 `src/browser/CdpCaptureDocuments.ts` (+119 -69) 📝 `src/browser/CdpElectronInspection.ts` (+45 -38) 📝 `src/browser/CdpElectronWorkers.ts` (+13 -6) 📝 `tests/boundary/browser/cdpElectronProvider.test.ts` (+57 -0) </details> ### 📄 Description ## Summary Fixes #3379. `inspect-electron-page` turned unreadable CDP replies into empty inventories while still reporting `complete_within_window`: - a DOM snapshot without `documents`, or with missing/misaligned node arrays; - a resource tree frame with `resources: null`; - a `Target.getTargets` reply with `targetInfos: null`. A caller could not tell these apart from genuinely empty collections. ## Problem and expected behavior Smallest trigger: a successful `DOMSnapshot.captureSnapshot` reply of `{}` yields 0 DOM nodes with `complete_within_window` and no exclusion. A missing or invalid required collection must remain unknown and be identified in completeness. A valid empty array may still mean empty. ## Change and scope - **Shared parsers:** the web capture path (`CdpCaptureDocuments.ts`) already validated these replies, while the Electron inspection had a separate, weaker copy. The validation now has one owner in `CdpCaptureDocuments.ts`, used by both web and Electron inspection: - `snapshotDocuments(value, onInvalid)`: a missing, empty or non-array document list, or a non-record document, is reported as invalid. - `snapshotDocumentNodes(value)`: returns the validated parallel node arrays (types, names, values, parents, attributes, backend IDs), plus the count of attribute rows beyond the node count. Missing or misaligned arrays return `undefined`. - `frameTreeResources(root, onInvalid)`: yields resource records across the frame tree via `walkFrameTrees`. A non-array `resources` list or a non-record entry is reported as invalid. - **Electron consumers:** `captureDom` and `captureResources` use the shared parsers, so the Electron copies (`recordsValue`/`arrayValue` defaults) are removed. Unreadable parts are recorded as `invalid_protocol_value` exclusions on `dom` or `resources`. - **Workers:** `CdpElectronWorkers` records a non-array `targetInfos` as an `invalid_protocol_value` exclusion with unknown count, and each non-record target as a counted exclusion. - **Web path:** behavior is unchanged; it now calls the same functions. - **Not included:** Electron still throws `protocol_error` when the resource tree has no `frameTree` root, as before. Unreadable `documentURL` indexes keep their existing out-of-scope classification. ## Contract and boundary impact - Semantic owner and earliest changed stage: CDP reply parsing for DOM snapshots, resource trees and worker targets (`src/browser/CdpCaptureDocuments.ts`, `CdpElectronInspection.ts`, `CdpElectronWorkers.ts`). - Contribution scope fit and linked maintainer decision: an ordinary fix within existing boundaries, so not applicable. - CLI and MCP/tool-catalog contract: no schema change. Malformed replies now add `completeness.excluded` entries and the section to `unavailable_sections`. The status is derived by the existing completeness owner, so it becomes `attach_limited`, as the web capture path already reports for identical replies. - Provider, bridge, target-format, or platform compatibility: the CDP/Electron provider only. - Evidence, artifact, provenance, or reconstruction contract: unreadable collections are reported as incomplete instead of as empty. - Target selection, authority, upstream behavior, and cleanup details: unchanged. - Generated metadata, package, or installation impact: none. Expected effects: - [x] Read existing files or captured data. - [x] Launch or attach to a process. This is existing `inspect-electron-page` behavior, unchanged here; tests attach only to a local fake CDP endpoint. ## Evidence and regression coverage - Tests added to `tests/boundary/browser/cdpElectronProvider.test.ts`, covering 4 malformed replies through the public provider and a fake CDP endpoint: - a snapshot without documents; - a snapshot document with a null node array; - a frame with `resources: null`; - `targetInfos: null`. Each must record an `invalid_protocol_value` exclusion for its section and not report `complete_within_window`. All 4 fail on main. - Base reproduction (executed): the issue's public-CLI matrix (`inspect-electron-page … --observation-ms 100 --include-script-sources --json` against its local HTTP/WebSocket CDP fixture), main cf0a38ad9 vs. this branch. | Mode | DOM / resources / workers | main | branch | Output bytes (main → branch) | |---|---|---|---|---| | control | 1 / 1 / 1 | `complete_within_window`, no exclusions | unchanged | 3,714 → 3,714 | | malformed DOM (`{}`) | 0 / 1 / 1 | `complete_within_window`, no exclusions | `attach_limited`, `{section: "dom", reason: "invalid_protocol_value", count: null}` | 3,604 → 3,657 | | malformed resources (`resources: null`) | 1 / 0 / 1 | `complete_within_window`, no exclusions | `attach_limited`, `resources` `invalid_protocol_value` | 3,406 → 3,471 | | malformed workers (`targetInfos: null`) | 1 / 1 / 0 | `complete_within_window`, no exclusions | `attach_limited`, `workers` `invalid_protocol_value` | 3,463 → 3,524 | - Timing: no measurable change expected. The same loops run over the same records; only validation branches moved, so no performance claim is made. - Remaining proof gaps: no real Electron application was attached. As in the report, no real Electron instance emitting these malformed replies is known; the valid paths are covered by the existing fake-CDP boundary suite. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:focused -- tests/boundary/browser/*.test.ts`: 49 files passed, 1 skipped. That is 550 tests passed and 6 skipped, including the 4 new cases, which fail on main. - `npm run test:local -- src/browser/*.test.ts`: 23 files and 257 tests passed. - `npm run check:fast`: typecheck and lint pass. The pre-push hook also passed. - The issue's public-CLI matrix above, on both main and this branch. ## Compatibility, safety, and release - Breaking changes or migration steps: none. Callers that relied on malformed replies being "complete" now see an accurate incomplete status. - Real Hopper/Ghidra, browser, or OS coverage: fake CDP endpoints only; no real Electron or Chromium run. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new target interaction, and file-scope authorization is unchanged. ## Author readiness Human owner: <!-- @GitHub-handle --> - [ ] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [ ] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [ ] I declare this PR ready for initial maintainer review. ## Before merge - [ ] This PR addresses a concrete problem or an agreed enhancement. - [ ] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [ ] The PR has one focused outcome and the title follows `type(scope): outcome`. - [ ] Related issue is linked, or the reason for not linking one is stated above. - [ ] Tests cover changed observable behavior and meaningful failure paths. - [ ] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [ ] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:10:44 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5959
No description provided.