mirror of
https://github.com/morluto/rea.git
synced 2026-10-30 11:25:39 +00:00
fix(javascript): preserve runtime path bytes and Electron ownership (#4941)
* fix(javascript): preserve literal percent runtime paths * fix(javascript): ignore resolve prefixes before the final anchor * fix(electron): retain application roots for loadFile declarations * fix(electron): resolve loadFile from enclosing application package * fix(electron): retain outer application root across package scopes * fix(electron): derive application ownership from inventoried packages * fix(electron): retain resolved package entrypoint ownership * fix(electron): preserve competing application ownership * fix(electron): retain invalid and omitted runtime ownership * fix(electron): preserve omitted module ownership and runtime paths * fix(electron): preserve proven roots before confining page paths * fix(electron): retain possible owners behind missing imports * fix(electron): distinguish absent imports and owned page candidates * fix(electron): keep unavailable JSON out of owner gaps * fix(electron): retain exact loader formats and default entry status * fix(electron): retain unavailable entrypoint ownership candidates * test(ghidra): preserve Windows Node probe prerequisites * test(ghidra): assert cancellation during profile shutdown * fix(electron): separate examined imports from frontend ownership * fix(electron): retain unavailable directory entrypoint owners * test(jeb): retain Linux ownership prerequisite in isolation * fix(javascript): retain unchecked loader ownership and literal main paths * fix(javascript): preserve runtime paths and call-site module aliases * fix(javascript): bound module alias traversal and preserve projections * fix(javascript): retain host module and nested artifact path boundaries * fix(javascript): preserve ESM and archive module loader provenance * test(javascript): distinguish unmapped containers from missing exports * fix: retain default module aliases and Electron builtin imports * fix: preserve host file URL and inward ASAR ownership * fix: preserve CommonJS file URL classification in CI fixtures * fix: retain bound module loaders and Windows entrypoint uncertainty * fix: retain ASAR uncertainty and invalidate changed Electron app roots * fix(javascript): retain ownership uncertainty across loader boundaries * fix(javascript): preserve loader sources and bound alias queries * fix(javascript): retain destructured loader sources * fix(javascript): preserve loader uncertainty at resolution boundaries * fix(javascript): preserve callable and package launch ownership * fix(javascript): preserve captured values across member reads * test(process): assert tagged filesystem cancellation failures * fix(javascript): preserve inventory bases and invocation read timing * fix(javascript): preserve ownership across indirect and unread loads * test(javascript): order fixture directory creation on Windows * test(javascript): share ordered filesystem fixture writer * fix(javascript): unify loader provenance and package validation * fix(javascript): preserve captured Node require loader values * fix(javascript): preserve loader invocation authority * fix(javascript): verify generic loader invocation authority * fix(javascript): preserve conditional loader method alternatives * fix(javascript): require proven factories for source association * fix(javascript): honor replaced Electron app path setters * fix(javascript): prove path and assignment source ownership * fix(javascript): retain native delegate eligibility through shared writes * fix(process): settle stale baseline errors after confirmed absence * fix(javascript): preserve assignment and path boundary evidence * fix(javascript): prove source-directory resolve anchors * fix: preserve application path provenance and portable schemas * fix(javascript): retain CommonJS exported setter effects * fix: isolate Linux identity observations and retain native module exports * fix(javascript): preserve published app and helper provenance * fix(javascript): normalize typed stores and native path fixtures
This commit is contained in:
1 parent
d532b18123
commit
e9fc8fb30c
149 files changed
+16881
-988
No files matched your search
+141
@@ -0,0 +1,141 @@
|
||||
import { createRequire } from "node:module";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptArtifactFiles } from "../../../../src/application/javascript/JavaScriptArtifactAnalysis.js";
|
||||
import { buildJavaScriptArtifactGraph } from "../../../../src/application/javascript/JavaScriptArtifactGraphBuilder.js";
|
||||
import { resolveArtifactPathByContext } from "../../../../src/application/javascript/JavaScriptArtifactPathResolution.js";
|
||||
import { createJavaScriptArtifactReader } from "../../../../src/artifacts/javascript/JavaScriptArtifactReader.js";
|
||||
import { scanCanonicalArtifactInventory } from "../../../fixtures/artifactInventory.js";
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
import { readJavaScriptArtifactFiles } from "../../../support/javascriptApplicationScope.js";
|
||||
import { writeFixtureFiles } from "../../../support/javascriptApplicationFixture.js";
|
||||
|
||||
const windowSource =
|
||||
'const {BrowserWindow}=require("electron");new BrowserWindow().loadFile("index.html");';
|
||||
|
||||
it.each(
|
||||
[null, false, 123, {}, []].flatMap((main) =>
|
||||
[false, true].map((index) => ({ main, index, request: "./b" })),
|
||||
),
|
||||
)(
|
||||
"follows Node index admission for main=$main with index=$index",
|
||||
async ({ main, index, request }) => {
|
||||
const root = await createTestTempDirectory("rea-nonstring-package-main-");
|
||||
await writeFixtureFiles(root, {
|
||||
"a/package.json": JSON.stringify({ main: "main.cjs" }),
|
||||
"a/main.cjs": index ? "module.exports={};" : windowSource,
|
||||
"a/index.html": "first application page",
|
||||
"b/package.json": JSON.stringify({ main }),
|
||||
...(index ? { "b/index.js": windowSource } : {}),
|
||||
"b/index.html": "second application page",
|
||||
"index.html": "artifact-root decoy",
|
||||
});
|
||||
const require = createRequire(join(root, "node-control.cjs"));
|
||||
if (index) expect(require.resolve(request)).toBe(join(root, "b/index.js"));
|
||||
else
|
||||
expect(() => require.resolve(request)).toThrow(
|
||||
expect.objectContaining({ code: "MODULE_NOT_FOUND" }),
|
||||
);
|
||||
const snapshot = await scanCanonicalArtifactInventory(root, {});
|
||||
const reader = createJavaScriptArtifactReader(root, "directory");
|
||||
try {
|
||||
const files = await readJavaScriptArtifactFiles(reader, snapshot);
|
||||
const analysis = analyzeJavaScriptArtifactFiles(files);
|
||||
expect(
|
||||
analysis.packages.find(({ path }) => path === "b/package.json"),
|
||||
).toMatchObject({ main_status: "invalid", main_entrypoint: "" });
|
||||
const graph = buildJavaScriptArtifactGraph(snapshot, files, analysis);
|
||||
const roles = graph.nodes.filter(
|
||||
({ kind }) => kind === "electron-renderer",
|
||||
);
|
||||
expect(roles).toHaveLength(1);
|
||||
expect(roles[0]?.observations).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: index ? "b/index.html" : "a/index.html",
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each(
|
||||
(
|
||||
[
|
||||
["{", false],
|
||||
["[]", false],
|
||||
["[{}]", false],
|
||||
["123", false],
|
||||
['"root"', false],
|
||||
["null", false],
|
||||
["false", false],
|
||||
["{}", true],
|
||||
['{"main":[]}', true],
|
||||
] as const
|
||||
).map(([text, valid]) => ({ text, valid, request: "./b" })),
|
||||
)(
|
||||
"distinguishes malformed package root $text from a valid index fallback",
|
||||
async ({ text, valid, request }) => {
|
||||
const root = await createTestTempDirectory("rea-invalid-package-main-");
|
||||
await writeFixtureFiles(root, {
|
||||
"a/package.json": JSON.stringify({ main: "main.cjs" }),
|
||||
"a/main.cjs": windowSource,
|
||||
"a/index.html": "first application page",
|
||||
"b/package.json": text,
|
||||
"b/index.js": "module.exports={};",
|
||||
"index.html": "artifact-root decoy",
|
||||
});
|
||||
const require = createRequire(join(root, "node-control.cjs"));
|
||||
if (valid) expect(require.resolve(request)).toBe(join(root, "b/index.js"));
|
||||
else
|
||||
expect(() => require.resolve(request)).toThrow(
|
||||
expect.objectContaining({ code: "ERR_INVALID_PACKAGE_CONFIG" }),
|
||||
);
|
||||
const snapshot = await scanCanonicalArtifactInventory(root, {});
|
||||
const reader = createJavaScriptArtifactReader(root, "directory");
|
||||
try {
|
||||
const files = await readJavaScriptArtifactFiles(reader, snapshot);
|
||||
const analysis = analyzeJavaScriptArtifactFiles(files);
|
||||
expect(
|
||||
analysis.packages.find(({ path }) => path === "b/package.json"),
|
||||
).toMatchObject({
|
||||
status: valid ? "included" : "invalid",
|
||||
main_entrypoint: valid ? "" : null,
|
||||
});
|
||||
expect(
|
||||
resolveArtifactPathByContext({
|
||||
sourcePath: "a/main.cjs",
|
||||
declaredPath: "../b",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files: new Map(files.files.map((file) => [file.path, file])),
|
||||
}),
|
||||
).toMatchObject({
|
||||
resolution_status: valid ? "resolved" : "unavailable",
|
||||
resolved_path: valid ? "b/index.js" : null,
|
||||
});
|
||||
const graph = buildJavaScriptArtifactGraph(snapshot, files, analysis);
|
||||
const role = graph.nodes.find(({ kind }) => kind === "electron-renderer");
|
||||
expect(role?.observations).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({
|
||||
resolution_status: valid ? "resolved" : "unavailable",
|
||||
resolved_path: valid ? "a/index.html" : null,
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user