fix(javascript): trace nested Electron bridge members (#2745)
* fix(javascript): trace nested Electron bridge members * fix(javascript): preserve shallow Electron bridge paths * fix(javascript): preserve exact Electron bridge member paths * fix(javascript): preserve exact Electron bridge paths * fix(javascript): preserve bridge entry ownership * fix(javascript): preserve bridge path identity * fix(javascript): normalize typed feature seeds before tracing * test(javascript): normalize direct selector seed inputs * refactor(javascript): consume normalized feature seed defaults --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
+68
-2
@@ -9,7 +9,10 @@ import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import { matchJavaScriptApplicationVersions } from "../../../../src/domain/javascript/javascriptApplicationVersionKeys.js";
|
||||
import { findApplicationFeatureSeeds } from "../../../../src/domain/javascript/javascriptFeatureSeed.js";
|
||||
import { traceApplicationFeatureInputSchema } from "../../../../src/domain/javascript/javascriptFeatureTraceSchemas.js";
|
||||
import {
|
||||
applicationFeatureSeedSchema,
|
||||
traceApplicationFeatureInputSchema,
|
||||
} from "../../../../src/domain/javascript/javascriptFeatureTraceSchemas.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../support/javascriptApplicationScope.js";
|
||||
|
||||
const analyzeSource = async (
|
||||
@@ -76,6 +79,59 @@ it("retains empty literal evidence across the application boundary surfaces", as
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps bridge entry paths stable through worker validation and API seed matching", async () => {
|
||||
const output = await analyzeSource(`
|
||||
const { contextBridge, ipcRenderer } = require("electron");
|
||||
const literal = () => ipcRenderer.send("literal");
|
||||
const nested = () => ipcRenderer.send("nested");
|
||||
contextBridge.exposeInMainWorld("desktop", {
|
||||
"nested.write": literal,
|
||||
nested: { write: nested },
|
||||
});
|
||||
`);
|
||||
const semanticPathIds = new Set(
|
||||
(output.semantic_graph?.nodes ?? [])
|
||||
.map(({ properties }) => properties.path_id)
|
||||
.filter((pathId): pathId is string => typeof pathId === "string"),
|
||||
);
|
||||
const applicationPathIds = new Set(
|
||||
output.graph.nodes.flatMap(({ observations }) =>
|
||||
observations
|
||||
.map(({ properties }) => properties.path_id)
|
||||
.filter((pathId): pathId is string => typeof pathId === "string"),
|
||||
),
|
||||
);
|
||||
expect(semanticPathIds).toEqual(applicationPathIds);
|
||||
|
||||
const matches = findApplicationFeatureSeeds(
|
||||
output.graph.nodes,
|
||||
applicationFeatureSeedSchema.parse({
|
||||
kind: "api",
|
||||
value: "desktop.nested.write",
|
||||
entry_path: ["desktop", "nested.write"],
|
||||
}),
|
||||
);
|
||||
expect(matches).toHaveLength(1);
|
||||
expect(
|
||||
output.graph.nodes
|
||||
.find(({ node_id: nodeId }) => nodeId === matches[0]?.node_id)
|
||||
?.observations.some(
|
||||
({ properties }) =>
|
||||
Array.isArray(properties.entry_path) &&
|
||||
properties.entry_path.join("\0") === "desktop\0nested.write",
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
findApplicationFeatureSeeds(
|
||||
output.graph.nodes,
|
||||
applicationFeatureSeedSchema.parse({
|
||||
kind: "api",
|
||||
value: "desktop.nested.write",
|
||||
}),
|
||||
),
|
||||
).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("analyzes a plain long-line loader without package metadata", async () => {
|
||||
const output = await analyzeSource(
|
||||
`var Module = {}; fetch(""); new Worker(""); var payload = "${"x".repeat(65_536)}";`,
|
||||
@@ -240,8 +296,18 @@ it.each([
|
||||
[{ kind: "channel", value: "" }, false],
|
||||
[{ kind: "channel", value: "", match: "contains" }, false],
|
||||
[{ kind: "node-id", value: "", match: "exact" }, false],
|
||||
[{ kind: "api", value: "desktop.nested.write" }, true],
|
||||
[
|
||||
{
|
||||
kind: "api",
|
||||
value: "desktop.nested.write",
|
||||
entry_path: ["desktop", "nested.write"],
|
||||
},
|
||||
true,
|
||||
],
|
||||
[{ kind: "channel", value: "channel", entry_path: ["channel"] }, false],
|
||||
] as const)(
|
||||
"validates empty seed %j at runtime and in the advertised schema",
|
||||
"validates seed %j at runtime and in the advertised schema",
|
||||
(seed, accepted) => {
|
||||
expect(seedSchema.safeParse(seed).success).toBe(accepted);
|
||||
expect(validateAdvertisedSeed(seed)).toBe(accepted);
|
||||
|
||||
Reference in New Issue
Block a user