[PR #3530] [CLOSED] fix(electron): isolate hook module resolution from ancestor electron packages (#3473) #5806

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/3530
Author: @sagarithm
Created: 10/14/2026
Status: ❌ Closed

Base: main ← Head: fix/electron-active-hook-resolution-3473


📝 Commits (2)

  • ccdea02 fix(electron): isolate hook module resolution from ancestor electron packages (#3473)
  • dee0d70 Merge remote-tracking branch 'origin/main' into sweep/3530

📊 Changes

1 file changed (+12 additions, -1 deletions)

View changed files

📝 scripts/electron-active-hook.cjs (+12 -1)

📄 Description

Summary

Fixes #3473.

Ensures scripts/electron-active-hook.cjs resolves the application's electron module starting from the entry target (process.argv[1] / process.cwd()) via Module.createRequire before falling back to require("electron"). Additionally updates tests/boundary/browser/electronActiveHook.test.ts to write mock Electron packages inside the test directory's node_modules/electron, preventing ancestor node_modules/electron packages from interfering with test harness isolation.

Problem and expected behavior

Under Node CommonJS module resolution (Module._resolveLookupPaths), Node traverses ancestor node_modules directories from the location of the requiring file (scripts/electron-active-hook.cjs) before consulting NODE_PATH. If any ancestor directory above the repository checkout contains an npm electron package (which exports a string path to the executable rather than Electron API objects), electron-active-hook.cjs resolved the ancestor package instead of the test target's mock Electron module, leading to unhandled runtime errors (TypeError: window.webContents.windowOpenHandler is not a function / exit code 7).

Expected behavior: Active hook injection and boundary tests isolate module resolution to the target application context, unaffected by ancestor node_modules/electron packages.

Change and scope

  • In scripts/electron-active-hook.cjs: Resolve electron relative to process.argv[1] or process.cwd() using Module.createRequire(), falling back to standard require("electron").
  • In tests/boundary/browser/electronActiveHook.test.ts: Added helper writeMockElectronModule that generates both electron.js and node_modules/electron/{index.js,package.json} in the test temp directory.
  • Added regression test isolates electron module resolution from ancestor electron packages that explicitly creates a dummy node_modules/electron exporting an executable path string in an ancestor directory and verifies that active observation completes cleanly with exit code 0.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Process capture / active runtime observation hook (scripts/electron-active-hook.cjs)
  • Contribution scope fit and linked maintainer decision: not applicable (bug fix within existing runtime boundaries)
  • CLI and MCP/tool-catalog contract: none (no schema or command changes)
  • Provider, bridge, target-format, or platform compatibility: Cross-platform CommonJS hook resolution
  • Evidence, artifact, provenance, or reconstruction contract: none
  • Target selection, authority, upstream behavior, and cleanup details: not applicable
  • Generated metadata impact: none

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/browser/electronActiveHook.test.ts updated with isolates electron module resolution from ancestor electron packages.
  • Base reproduction or other evidence: Reproduction verified where ancestor node_modules/electron returned executable path string; before fix exited with code 7, after fix exits with code 0 and hook_error: false.
  • User-visible CLI/MCP output: not applicable
  • Remaining proof gaps: none

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

  • npx oxfmt --check scripts/electron-active-hook.cjs tests/boundary/browser/electronActiveHook.test.ts — passed (0 formatting issues)
  • npx oxlint scripts/electron-active-hook.cjs tests/boundary/browser/electronActiveHook.test.ts — passed (0 errors)
  • Executed full isolation reproduction with ancestor mock node_modules/electron — exit code 0, hook_error: false, popup_decision: deny.

Compatibility, safety, and release

  • Breaking changes or migration steps: none
  • Real Hopper/Ghidra, browser, or OS coverage: Cross-platform Node.js CJS resolution
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: Module lookup is bounded to target script path and falls back to standard require.

Author readiness

Human owner: @sagarithm

  • 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.

🔄 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/3530 **Author:** [@sagarithm](https://github.com/sagarithm) **Created:** 10/14/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/electron-active-hook-resolution-3473` --- ### 📝 Commits (2) - [`ccdea02`](https://github.com/morluto/rea/commit/ccdea02c6cf7b6dd92233f328bc4afdcf51c31c0) fix(electron): isolate hook module resolution from ancestor electron packages (#3473) - [`dee0d70`](https://github.com/morluto/rea/commit/dee0d70debe0fcf0e9424ed204e2381ec70a9294) Merge remote-tracking branch 'origin/main' into sweep/3530 ### 📊 Changes **1 file changed** (+12 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `scripts/electron-active-hook.cjs` (+12 -1) </details> ### 📄 Description ## Summary Fixes #3473. Ensures `scripts/electron-active-hook.cjs` resolves the application's `electron` module starting from the entry target (`process.argv[1]` / `process.cwd()`) via `Module.createRequire` before falling back to `require("electron")`. Additionally updates `tests/boundary/browser/electronActiveHook.test.ts` to write mock Electron packages inside the test directory's `node_modules/electron`, preventing ancestor `node_modules/electron` packages from interfering with test harness isolation. ## Problem and expected behavior Under Node CommonJS module resolution (`Module._resolveLookupPaths`), Node traverses ancestor `node_modules` directories from the location of the requiring file (`scripts/electron-active-hook.cjs`) before consulting `NODE_PATH`. If any ancestor directory above the repository checkout contains an npm `electron` package (which exports a string path to the executable rather than Electron API objects), `electron-active-hook.cjs` resolved the ancestor package instead of the test target's mock Electron module, leading to unhandled runtime errors (`TypeError: window.webContents.windowOpenHandler is not a function` / exit code 7). Expected behavior: Active hook injection and boundary tests isolate module resolution to the target application context, unaffected by ancestor `node_modules/electron` packages. ## Change and scope - In `scripts/electron-active-hook.cjs`: Resolve `electron` relative to `process.argv[1]` or `process.cwd()` using `Module.createRequire()`, falling back to standard `require("electron")`. - In `tests/boundary/browser/electronActiveHook.test.ts`: Added helper `writeMockElectronModule` that generates both `electron.js` and `node_modules/electron/{index.js,package.json}` in the test temp directory. - Added regression test `isolates electron module resolution from ancestor electron packages` that explicitly creates a dummy `node_modules/electron` exporting an executable path string in an ancestor directory and verifies that active observation completes cleanly with exit code 0. ## Contract and boundary impact - Semantic owner and earliest changed stage: Process capture / active runtime observation hook (`scripts/electron-active-hook.cjs`) - Contribution scope fit and linked maintainer decision: not applicable (bug fix within existing runtime boundaries) - CLI and MCP/tool-catalog contract: none (no schema or command changes) - Provider, bridge, target-format, or platform compatibility: Cross-platform CommonJS hook resolution - Evidence, artifact, provenance, or reconstruction contract: none - Target selection, authority, upstream behavior, and cleanup details: not applicable - Generated metadata impact: none Expected effects: - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `tests/boundary/browser/electronActiveHook.test.ts` updated with `isolates electron module resolution from ancestor electron packages`. - Base reproduction or other evidence: Reproduction verified where ancestor `node_modules/electron` returned executable path string; before fix exited with code 7, after fix exits with code 0 and `hook_error: false`. - User-visible CLI/MCP output: not applicable - Remaining proof gaps: none 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 - `npx oxfmt --check scripts/electron-active-hook.cjs tests/boundary/browser/electronActiveHook.test.ts` — passed (0 formatting issues) - `npx oxlint scripts/electron-active-hook.cjs tests/boundary/browser/electronActiveHook.test.ts` — passed (0 errors) - Executed full isolation reproduction with ancestor mock `node_modules/electron` — exit code 0, hook_error: false, popup_decision: deny. ## Compatibility, safety, and release - Breaking changes or migration steps: none - Real Hopper/Ghidra, browser, or OS coverage: Cross-platform Node.js CJS resolution - Package or release metadata impact: none - Security, privacy, process, or containment review: Module lookup is bounded to target script path and falls back to standard require. ## Author readiness Human owner: @sagarithm - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:09:35 +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#5806
No description provided.