test(electron): consolidate action and projection coverage (#12959)

* test(electron): consolidate action and projection coverage

* style(tests): format Electron action diagnostics assertion
This commit is contained in:
morluto authored and GitHub committed 2026-11-20 23:39:25 +00:00
1 parent 8d2eb16710
commit 32e5f5bc1c
2 files changed
+115 -271

No files matched your search

@@ -24,70 +24,75 @@ const event = {
error: false,
};
it.each([
"custom-apply",
"listener-chain",
"once-metadata",
"listener-registration",
"listener-removal",
])(
"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,
single_instance_lock_refused: false,
},
it("keeps main-process IPC gaps distinct from delivery and retention loss", () => {
const boundaries = [
"custom-apply",
"listener-chain",
"once-metadata",
"listener-registration",
"listener-removal",
];
const result = projectElectronActiveCapture(
{ executable: "/opt/electron", application: "/opt/app/main.js" },
[],
{
windows: [],
metrics: [],
electronVersion: "test-electron",
hookSnapshot: {
events: boundaries.map((boundary, index) => ({
...event,
sequence: index + 1,
correlation_id: `capture:123:${String(index + 1)}`,
kind: "ipc-observation-gap",
event: boundary,
channel: "custom",
direction: null,
receiver: null,
target: "ipcMain.on",
})),
retention_budget_bytes: 16 * 1024 * 1024,
estimated_retained_bytes: 2_560,
event_serialized_byte_upper_bound: 512,
retained: 5,
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: 7,
observed_ipc: 0,
observed_runtime: 7,
hook_error: false,
single_instance_lock_refused: false,
},
);
expect(result.ipc).toEqual({ events: [], observed: 0, dropped: 0 });
expect(result.timeline.events[0]).toMatchObject({
},
);
expect(result.ipc).toEqual({ events: [], observed: 0, dropped: 0 });
expect(result.timeline.events).toMatchObject(
boundaries.map((boundary) => ({
kind: "ipc-observation-gap",
event: boundary,
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.",
);
},
);
})),
);
expect(result.coverage.status).toBe("partial_attach");
expect(result.coverage.observed_roles).toEqual(["main"]);
expect(result.coverage.observed_event_families).toContain(
"ipc-observation-gap",
);
expect(result.coverage.unavailable_event_families).toEqual(
expect.arrayContaining(["ipc", "renderer-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 result = projectElectronActiveCapture(
@@ -115,7 +120,7 @@ it("projects hook retention and dropped event families through the result schema
],
dropped_event_roles: [{ role: "renderer", count: 1 }],
observed: 3,
observed_ipc: 1,
observed_ipc: 2,
observed_runtime: 1,
hook_error: false,
single_instance_lock_refused: false,
@@ -135,7 +140,7 @@ it("projects hook retention and dropped event families through the result schema
],
dropped_event_roles: [{ role: "renderer", count: 1 }],
});
expect(result.ipc).toMatchObject({ observed: 1, dropped: 1 });
expect(result.ipc).toEqual({ events: [event], observed: 2, dropped: 1 });
expect(result.timeline).toMatchObject({ observed: 3, dropped: 2 });
expect(result.coverage.observed_event_families).toContain("renderer-ipc");
expect(result.coverage.unavailable_event_families).not.toContain(
@@ -153,63 +158,6 @@ it("projects hook retention and dropped event families through the result schema
);
});
it("keeps renderer coverage unavailable when only the main process was observed", () => {
const result = projectElectronActiveCapture(
{
executable: "/opt/electron",
application: "/opt/app/main.js",
},
[],
{
windows: [],
metrics: [],
electronVersion: "test-electron",
hookSnapshot: {
events: [
{
sequence: 1,
correlation_id: "capture:123:1",
kind: "app-lifecycle",
event: "ready",
phase: "observed",
channel: null,
direction: null,
sender: null,
receiver: null,
frame: null,
target: "app",
argument_shapes: [],
result_shape: null,
process_type: "main",
source: "electron-active-hook",
capture_method: "event-emitter",
artifact_path: null,
artifact_sha256: null,
error: false,
},
],
retention_budget_bytes: 16 * 1024 * 1024,
estimated_retained_bytes: 0,
event_serialized_byte_upper_bound: 0,
retained: 1,
dropped: 0,
dropped_ipc: 0,
dropped_runtime: 0,
dropped_event_families: [],
dropped_event_roles: [],
observed: 1,
observed_ipc: 0,
observed_runtime: 1,
hook_error: false,
single_instance_lock_refused: false,
},
},
);
expect(result.coverage.observed_roles).not.toContain("renderer");
expect(result.coverage.unavailable_event_families).toContain("renderer-ipc");
});
it("does not correlate legacy dropped families and roles", () => {
const result = projectElectronActiveCapture(
{