mirror of
https://github.com/morluto/rea.git
synced 2026-11-12 09:52:27 +00:00
* fix(javascript): require exact loader suffix case * fix(javascript): share exact loader mode across import resolution * test(process): align symlink fixture with filesystem checkpoints * test(javascript): normalize the module resolution oracle path separators * test(frida): assert the CLI spawn Evidence contract * test(mcp): use an unsupported analysis-view parent * test(browser): separate source-location line bounds from parity * fix(javascript): preserve uncertain loader provenance * test(javascript): cover uncertain require resolution * fix(javascript): retain conditional Electron evidence * fix(javascript): preserve timed semantic provenance * fix(javascript): retain conditional builtin effects * test(javascript): distinguish bundled host authority * fix(javascript): preserve nested loader invocation identity * test(javascript): qualify Electron fixture authority * fix(javascript): preserve loader invocation authority * fix(javascript): respect source order for resolver escapes * fix(javascript): check nested loader callable mutations * fix(javascript): retain conditional constructor requests * fix(reference): retain constructor loader relationships * fix(reference): follow nested loader callable paths * refactor(javascript): share callable mutation interpretation * fix(javascript): require exact package loader suffixes * refactor(javascript): unify conditional relation evidence * refactor(javascript): unify conditional node evidence * fix(javascript): retain unknown authority for mixed case sources * fix(javascript): preserve loader uncertainty for dotfiles * fix(reference): classify javascript suffix dotfiles * test(reference): cover suffix dotfiles through cli * fix(javascript): retain equivalent conditional built-in origins * fix(javascript): preserve wrapped resolver operation * fix(javascript): retain nested conditional built-in receivers * test(javascript): declare CommonJS in native addon fixtures * fix(javascript): retain wrapped resolver candidates * style: format merged native command schema * fix(javascript): preserve uncertain loader authority * test(javascript): require candidate preload evidence * test(javascript): cover reference loader member writes --------- Co-authored-by: ShuaixinHuang <1836656514@qq.com>
145 lines
5.6 KiB
TypeScript
145 lines
5.6 KiB
TypeScript
import { expect } from "vitest";
|
|
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
import { analyzeJavaScriptDirectory } from "../../support/cli/javascriptApplication.js";
|
|
import { writeFixtureFiles } from "../../support/javascriptApplicationFixture.js";
|
|
|
|
const window = `const { app, BrowserWindow, ipcMain } = require("electron");
|
|
const path = require("node:path");
|
|
const win = new BrowserWindow({ webPreferences: { preload: path.join(__dirname, "preload.js") } });`;
|
|
const sends = `const { ipcRenderer } = require("electron");
|
|
ipcRenderer.send("app:log", 1);
|
|
ipcRenderer.invoke("app:get");`;
|
|
|
|
const cases = [
|
|
{
|
|
// An unresolved channel may receive app:log; it never handles invoke.
|
|
shape: "a directly registered computed channel",
|
|
main: `ipcMain.on(process.env.CHANNEL, () => {});
|
|
ipcMain.handle("app:get", () => 1);`,
|
|
preload: sends,
|
|
pairing: { paired: 1, ambiguous: 1, unpaired: 0 },
|
|
},
|
|
{
|
|
shape: "a wrapper with one computed call site",
|
|
main: `function register(channel, handler) { ipcMain.on(channel, handler); }
|
|
register("app:log", () => {});
|
|
register(process.env.CHANNEL, () => {});`,
|
|
preload: sends,
|
|
pairing: { paired: 0, ambiguous: 1, unpaired: 1 },
|
|
},
|
|
{
|
|
// Importers of the wrapper can register channels this file never names.
|
|
shape: "an exported wrapper",
|
|
main: `function register(channel, handler) { ipcMain.on(channel, handler); }
|
|
register("other", () => {});
|
|
module.exports = register;`,
|
|
preload: sends,
|
|
pairing: { paired: 0, ambiguous: 1, unpaired: 1 },
|
|
},
|
|
{
|
|
// Every call site supplies a literal; the guarded one competes only for
|
|
// its own channel, so app:log still pairs with its finding.
|
|
shape: "a wrapper whose call sites are all literal",
|
|
main: `function register(channel, handler) { ipcMain.on(channel, handler); }
|
|
register("app:log", () => {});
|
|
if (process.env.EXTRA) register("other", () => {});`,
|
|
preload: sends,
|
|
pairing: { paired: 1, ambiguous: 0, unpaired: 1 },
|
|
},
|
|
{
|
|
// A guarded registration has no IPC finding, yet it may receive app:log.
|
|
shape: "a guarded wrapper registration",
|
|
main: `function register(channel, handler) { ipcMain.on(channel, handler); }
|
|
if (process.env.EXTRA) register("app:log", () => {});`,
|
|
preload: sends,
|
|
pairing: { paired: 0, ambiguous: 1, unpaired: 1 },
|
|
},
|
|
{
|
|
// The guarded registration competes with the direct handler on app:log.
|
|
shape: "a guarded wrapper registration and a direct handler",
|
|
main: `function register(channel, handler) { ipcMain.on(channel, handler); }
|
|
if (process.env.EXTRA) register("app:log", () => {});
|
|
ipcMain.on("app:log", () => {});`,
|
|
preload: sends,
|
|
pairing: { paired: 0, ambiguous: 1, unpaired: 1 },
|
|
},
|
|
{
|
|
// A renderer listener and a main-to-renderer send receive no renderer sends.
|
|
shape: "computed channels in other directions",
|
|
main: `ipcMain.on("app:log", () => {});
|
|
win.webContents.send(process.env.CHANNEL, 1);`,
|
|
preload: `const { ipcRenderer } = require("electron");
|
|
ipcRenderer.on(process.env.CHANNEL, () => {});
|
|
ipcRenderer.send("app:log", 1);`,
|
|
pairing: { paired: 1, ambiguous: 0, unpaired: 0 },
|
|
},
|
|
] as const;
|
|
|
|
for (const surface of ["CLI", "stdio MCP"] as const)
|
|
cliTest.for(cases)(
|
|
`classifies literal sends beside $shape through ${surface}`,
|
|
async ({ main, preload, pairing }, { cli }) => {
|
|
const root = await createTestTempDirectory("rea-electron-dynamic-ipc-");
|
|
await writeFixtureFiles(root, {
|
|
"package.json": JSON.stringify({
|
|
name: "dynamic-ipc",
|
|
version: "1.0.0",
|
|
main: "main.js",
|
|
}),
|
|
"main.js": `${window}\n${main}`,
|
|
"preload.js": preload,
|
|
});
|
|
const { summary } = await analyzeJavaScriptDirectory(surface, cli, root);
|
|
expect(summary.ipc).toMatchObject({
|
|
paired_renderer_transmissions: pairing.paired,
|
|
ambiguous_renderer_transmissions: pairing.ambiguous,
|
|
unpaired_literal_renderer_transmissions: pairing.unpaired,
|
|
});
|
|
},
|
|
);
|
|
|
|
cliTest.for(["CLI", "stdio MCP"] as const)(
|
|
"keeps a proven IPC match ambiguous when a candidate Electron handler competes through %s",
|
|
async (surface, { cli }) => {
|
|
const root = await createTestTempDirectory("rea-electron-candidate-ipc-");
|
|
await writeFixtureFiles(root, {
|
|
"package.json": JSON.stringify({
|
|
name: "candidate-ipc",
|
|
main: "main.js",
|
|
}),
|
|
"main.js": `${window}\nipcMain.handle("app:get", () => 1);`,
|
|
"preload.js":
|
|
'const { ipcRenderer } = require("electron"); ipcRenderer.invoke("app:get");',
|
|
});
|
|
const known = await analyzeJavaScriptDirectory(surface, cli, root);
|
|
expect(known.summary.ipc).toMatchObject({
|
|
paired_renderer_transmissions: 1,
|
|
ambiguous_renderer_transmissions: 0,
|
|
});
|
|
await writeFixtureFiles(root, {
|
|
"candidate.MJS":
|
|
'const { ipcMain } = require("electron"); ipcMain.handle("app:get", () => 2);',
|
|
});
|
|
const conditional = await analyzeJavaScriptDirectory(surface, cli, root);
|
|
expect(conditional.summary.ipc).toMatchObject({
|
|
paired_renderer_transmissions: 0,
|
|
ambiguous_renderer_transmissions: 1,
|
|
});
|
|
expect(conditional.graph.nodes).toContainEqual(
|
|
expect.objectContaining({
|
|
kind: "ipc-handler",
|
|
observations: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
properties: expect.objectContaining({
|
|
loader_authority: "candidate",
|
|
}),
|
|
evidence: expect.objectContaining({ confidence: "low" }),
|
|
}),
|
|
]),
|
|
}),
|
|
);
|
|
},
|
|
);
|