fix(electron): preserve native IPC listener behavior (#4389)

Preserve original-function removal, native IPC dispatch and argument identity, with explicit metadata ownership and Evidence verification. Runtime cleanup limitations remain documented.

Fixes #4390.

Co-authored-by: Adolanium <[email protected]>
Co-authored-by: gensokyo-dev <[email protected]>
Co-authored-by: Kaoru0822 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-17 04:17:11 +08:00
1 parent f22e8e7268
commit bf3475867f
11 files changed
+13167 -70

No files matched your search

@@ -2,28 +2,87 @@ import { expect, it } from "vitest";
import { projectElectronActiveCapture } from "./PlaywrightElectronActiveProjection.js";
const event = {
sequence: 1,
correlation_id: "capture:123:1",
kind: "main-handler-invocation" as const,
event: null,
phase: "observed" as const,
channel: "readiness:echo",
direction: "renderer-to-main" as const,
sender: null,
receiver: "main",
frame: null,
target: null,
argument_shapes: [],
result_shape: null,
process_type: "main",
source: "electron-active-hook",
capture_method: "api-wrapper" as const,
artifact_path: null,
artifact_sha256: null,
error: false,
};
it.each(["custom-apply", "listener-chain"])(
"keeps %s gaps distinct from captured IPC and retention loss",
(boundary) => {
const result = projectElectronActiveCapture(
{ executable: "/opt/electron", application: "/opt/app/main.js" },
[],
{
windows: [],
metrics: [],
electronVersion: "test-electron",
hookSnapshot: {
events: [
{
...event,
kind: "ipc-observation-gap",
event: boundary,
channel: "custom",
direction: null,
receiver: null,
target: "ipcMain.on",
},
],
retention_budget_bytes: 16 * 1024 * 1024,
estimated_retained_bytes: 1_024,
event_serialized_byte_upper_bound: 512,
retained: 1,
dropped: 2,
dropped_ipc: 0,
dropped_runtime: 2,
dropped_event_families: [{ family: "ipc-observation-gap", count: 2 }],
dropped_event_roles: [{ role: "main", count: 2 }],
observed: 3,
observed_ipc: 0,
observed_runtime: 3,
hook_error: false,
},
},
);
expect(result.ipc).toEqual({ events: [], observed: 0, dropped: 0 });
expect(result.timeline.events[0]).toMatchObject({
kind: "ipc-observation-gap",
channel: "custom",
});
expect(result.coverage.status).toBe("partial_attach");
expect(result.coverage.observed_event_families).toContain(
"ipc-observation-gap",
);
expect(result.coverage.unavailable_event_families).toContain("ipc");
expect(result.retention.dropped).toBe(2);
expect(result.limitations).toContainEqual(
expect.stringContaining("unobserved callback arguments and execution"),
);
expect(result.limitations).not.toContain(
"The active IPC hook could not be installed.",
);
},
);
it("projects hook retention and dropped event families through the result schema", () => {
const event = {
sequence: 1,
correlation_id: "capture:123:1",
kind: "main-handler-invocation" as const,
event: null,
phase: "observed" as const,
channel: "readiness:echo",
direction: "renderer-to-main" as const,
sender: null,
receiver: "main",
frame: null,
target: null,
argument_shapes: [],
result_shape: null,
process_type: "main",
source: "electron-active-hook",
capture_method: "api-wrapper" as const,
artifact_path: null,
artifact_sha256: null,
error: false,
};
const result = projectElectronActiveCapture(
{
executable: "/opt/electron",
@@ -184,6 +184,11 @@ export const projectElectronActiveCapture = (
coverage: createCoverage(hookSnapshot, observations),
limitations: [
"IPC payloads are represented by value shapes; payload values are never retained.",
...(observations.observedEventFamilies.includes("ipc-observation-gap")
? [
"IPC observation gaps have unobserved callback arguments and execution. Available ipc-observation-gap timeline records identify the custom-apply or listener-chain boundary and registered channel; dropped gap records are counted by retention. Listener-chain gaps describe registration uncertainty, not proof of IPC delivery.",
]
: []),
"IPC direction and sender/receiver identifiers are observed only where Electron exposes them at the hooked boundary.",
"The runtime timeline records lifecycle, navigation, shell, permission, popup, download, protocol, preload, native-addon, process, and IPC events; activity before hook installation is unavailable.",
"The preload and renderer process contexts are not instrumented by the main-process -r hook; preload configuration and contextBridge API-shape events are main-boundary observations, not proof of renderer-side execution.",