Skip to content

fix(javascript): recognize Electron APIs through renamed bindings - #1391

Merged
morluto merged 2 commits into
morluto:mainfrom
marnixpluim:fix/electron-import-aliases
Oct 10, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
marnixpluim:fix/electron-import-aliases

Conversation

@marnixpluim

Copy link
Copy Markdown
Contributor

Requested by Marnix · project thread

Summary

REA recognizes Electron APIs by the callee's spelling, such as ipcMain.handle or new BrowserWindow. Bundlers rename imports when names collide, so a bundled main process calls ipcMain2.handle(...) and new BrowserWindow2(...), and REA reports none of them. This change resolves each call or construction root to its Electron import or require origin and matches the callee under the export's name.

No issue is linked. This was found while analyzing the packaged Hermes Desktop v0.21.6 (NousResearch/hermes-agent, MIT), whose main process is one esbuild ESM bundle.

Problem and expected behavior

Smallest trigger, a directory with package.json ({ "name": "app", "main": "main.mjs" }) and:

// main.mjs
import { ipcMain as ipcMain2 } from "electron";
ipcMain2.handle("app:read", async () => 1);

// preload.js
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("api", { read: () => ipcRenderer.invoke("app:read") });

Expected: one main-process handler for app:read, paired with the preload's invoke. On 7aa4d768, electron_summary.ipc reports main_handlers: 0 and unpaired_literal_renderer_transmissions: 1; with this change, main_handlers: 1 and paired_renderer_transmissions: 1. Renamed BrowserWindow, contextBridge and utilityProcess bindings are missed the same way.

Invariant: whether a call is an Electron API depends on where its binding comes from, not on the name a bundler gave it.

Change and scope

  • classifyParsedJavaScriptElectronBindings maps each call or new root bound to electron, electron/main, electron/renderer, electron/common or electron/utility under another name to its export path. It reads import and require origins directly, including destructured require results, rather than running general value evaluation, which is costly on large bundles.
  • electronCalleeName respells a renamed root as its export before the existing matchers run; roots already spelled as their export are untouched.
  • Shadowed locals keep their own meaning: a function parameter that happens to be named ipcMain2 is not Electron's.

Not included: Electron objects passed in as function arguments or re-exported from another module, and channels built from template literals. These need more than local binding origins.

Contract and boundary impact

  • Semantic owner and earliest changed stage: domain JavaScript static analysis (src/domain/javascript), when static findings are collected.
  • CLI and MCP/tool-catalog contract: none; a renamed binding now produces the findings its unrenamed spelling already produced.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none; findings keep their evidence and source ranges.
  • Process execution, authorization, cleanup, or containment impact: none; analysis stays static.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: tests/composition/javascript-applications/electronApplicationAnalysis.test.ts, "maps Electron boundaries through bundler-renamed bindings": an ESM main with renamed BrowserWindow, ipcMain (also via electron/main) and utilityProcess imports and a shadowing ipcMain2 parameter, plus a CommonJS preload destructuring renamed contextBridge and ipcRenderer. It expects one window, one bridge with two members, two paired handlers, one utility process, and no handler for the shadowed channel.

  • Base reproduction or other evidence: on 7aa4d768 the new test finds no window, bridge, handler or utility process. On the Hermes Desktop v0.21.6 Linux app.asar, with the member-mutation fix in both runs, since without it the app's React vendor chunk alone has no result after 300 s:

    electron_summary before after
    browser_windows 0 11
    ipc.main_handlers 1 204
    ipc.paired_renderer_transmissions 1 201
    ipc.unpaired_literal_renderer_transmissions 222 22

    The 11 windows and 204 handlers match the bundle's Electron-bound new BrowserWindowN(...) and ipcMainN.handle/on(...) calls one for one. The one window and 13 handlers still missed receive BrowserWindow or ipcMain as a function parameter.

  • User-visible CLI/MCP output (if applicable): the summary changes as in the table; no field is added or removed.

  • Remaining proof gaps: the cases under Not included.

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 on the changed files: all formatted
  • npx oxlint on the changed files: no new warnings; javascriptSemanticAnalysis.ts was already over the line limit and grows from 907 to 974 lines
  • node scripts/verify-module-boundaries.mjs: passed, 1,313 source files
  • npx tsc --noEmit: exit 0
  • npx vitest run tests/composition/javascript-applications/electronApplicationAnalysis.test.ts src/domain/javascript: 38 files, 689 tests passed
  • Full suite on the four branches from this Hermes Desktop run, merged (npm run test:prepare, then npx vitest run; root, Linux x64, Node 22.22): 6,246 tests passed, 114 skipped, 1 failed. The failure is analysisSelectorCli.test.ts "rejects missing and conflicting selectors before opening a target": it starts the CLI 12 times, hit its 30 s timeout under the parallel run, and passes alone in 27.6 s. It covers CLI argument parsing, which these changes don't touch.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; static JavaScript analysis only. Run on Linux x64 with Node 22.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new process execution, file access or network access.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • 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.ai/code/session_01XPY2GmufMNGQKoEgRUx1pd

Electron recognition matched callee spellings, so a bundler rename such as
esbuild's `import { ipcMain as ipcMain2 } from "electron"`, or a destructured
`const { contextBridge: bridge } = require("electron")`, hid every IPC
handler, BrowserWindow, contextBridge and utility process behind it.

Resolve each call and construction root lexically to its Electron import or
require origin, and classify the callee under that export's name. Shadowed
locals keep their own meaning.

On Hermes Desktop v0.21.6, whose main process is one esbuild ESM bundle,
recognized main IPC handlers rise from 1 to 204, BrowserWindow constructions
from 0 to 11, and paired renderer transmissions from 1 to 201.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01XPY2GmufMNGQKoEgRUx1pd
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: This fix works for me on Linux. Renamed Electron imports now show up. A real app with no renames came out the same. Your test passes on Node 22, 24 and 26.

I tested head e4a8e0b7 against the 6.3.0 release. The base 7aa4d768 has the same source as 6.3.0.

Your test

I ran electronApplicationAnalysis.test.ts on the head.

Node result
22.23.1 6 of 6 pass
24.18.0 6 of 6 pass
26.11.1 6 of 6 pass

I also put your test file on top of 7aa4d768. There it fails, 1 of 6. So the test catches the bug.

A real app

I used a copy of the Beyond All Reason launcher (launcher code MIT; Flathub package GPL-2.0-or-later). It ships plain CommonJS. Every Electron import keeps its own name, so the bug shape is not in it. I ran it on Node 22.

The head gave the same graph as 6.3.0. Node ids, summary and stats all match. So there is no regression here.

Small fixtures

First, your own trigger from the PR body. On 6.3.0 it finds 0 main handlers. On the head it finds 1, paired with the invoke.

Next, a hand-made bundle in the esbuild style. It renames BrowserWindow, ipcMain and utilityProcess. A second ipcMain comes from electron/main. The preload renames contextBridge and ipcRenderer by destructuring.

count 6.3.0 head
windows 0 1
bridges 0 1
members 0 2
handlers 1 3
paired 0 2
utility 0 1

The traps held. An ipcMain2 function parameter was not counted. An ipcMain from a local ./fake.mjs was not counted either.

One extra case worked too. const ipc3 = require("electron").ipcRenderer paired with its handler.

One thing stays the same, as your PR says. A plain local object named ipcMain still counts as a handler. That was true on 6.3.0 too.

I also built a real bundle with rolldown 1.2.12. It kept the Electron names and renamed the locals to ipcMain$1. So it did not make this shape. The head and 6.3.0 gave the same result there.

Not run

  • The full test suite, tsc, oxlint and oxfmt.
  • esbuild itself. It was not installed, so my esbuild-style bundle is hand-written.
  • Hermes Desktop (MIT). Release v0.21.6 has no download files.
  • The launcher on Node 24 and 26.

Thanks, marnixpluim.

Test setup
  • Box: Nobara 44, x86-64

🤖 Generated with Claude Code (Opus 5.5) 🦊

@morluto
morluto merged commit 817efac into morluto:main Oct 10, 2026
1 check passed
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…aliases

fix(javascript): recognize Electron APIs through renamed bindings
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

The binding origin matters more than the bundle’s renamed local, and this change captures that, @marnixpluim. Resolving ipcMain2 back to Electron lets static analysis pair the handler while still respecting shadowed locals. Thanks for grounding the regression in a real bundled application.

@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions labels Oct 14, 2026
@morluto morluto added the provider: electron Analysis provider / engine: electron label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working provider: electron Analysis provider / engine: electron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants