mirror of
https://github.com/morluto/rea.git
synced 2026-11-12 01:41:21 +00:00
fix(javascript): preserve loader authority for exact suffixes (#9477)
* 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>
This commit is contained in:
1 parent
78a84d75c0
commit
b46f4fcebd
112 files changed
+5156
-797
No files matched your search
@@ -0,0 +1,123 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { analyzeCommonJsSemanticFixture } from "../../../tests/fixtures/javascriptCommonJsAnalysis.js";
|
||||
import {
|
||||
analyzeJavaScriptSemantics,
|
||||
analyzeParsedJavaScriptSemantics,
|
||||
} from "./javascriptSemanticAnalysis.js";
|
||||
import { parseJavaScriptSource } from "./javascriptSourceParser.js";
|
||||
|
||||
const source = `
|
||||
const fs = require('fs');
|
||||
const process = require('process');
|
||||
const http = require('http');
|
||||
fs.readFileSync('config.json');
|
||||
process.env.MODE;
|
||||
const stream = fs.createReadStream('data');
|
||||
stream.close();
|
||||
http.get('http://example.test');
|
||||
`;
|
||||
|
||||
it("retains built-in effects as conditional when the loader is unknown", () => {
|
||||
const candidate = analyzeJavaScriptSemantics(source);
|
||||
const proven = analyzeCommonJsSemanticFixture(source);
|
||||
for (const ir of [candidate, proven]) {
|
||||
expect(ir.configurationOperations.map(({ key }) => key)).toEqual([
|
||||
"config.json",
|
||||
"MODE",
|
||||
]);
|
||||
expect(ir.resourceOperations.map(({ kind }) => kind)).toEqual([
|
||||
"acquire",
|
||||
"release",
|
||||
]);
|
||||
expect(ir.requestOperations.map(({ endpoint }) => endpoint)).toEqual([
|
||||
"http://example.test",
|
||||
]);
|
||||
}
|
||||
for (const operation of [
|
||||
...candidate.configurationOperations,
|
||||
...candidate.resourceOperations,
|
||||
...candidate.requestOperations,
|
||||
])
|
||||
expect(operation.builtinAuthority).toBe("candidate");
|
||||
for (const operation of [
|
||||
...proven.configurationOperations,
|
||||
...proven.resourceOperations,
|
||||
...proven.requestOperations,
|
||||
])
|
||||
expect(operation.builtinAuthority).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not infer a conditional built-in after the selected method is replaced or the loader is shadowed", () => {
|
||||
for (const source of [
|
||||
`const fs = require('fs'); fs.readFileSync = replacement; fs.readFileSync('config');`,
|
||||
`function load(require) { const fs = require('fs'); fs.readFileSync('config'); }`,
|
||||
])
|
||||
expect(analyzeJavaScriptSemantics(source).configurationOperations).toEqual(
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
it("retains conditional built-in use across imported and unknown-loader alternatives", () => {
|
||||
for (const choice of ["builtin : alternate", "alternate : builtin"]) {
|
||||
const source = `import * as builtin from "node:fs"; const alternate = require("fs"); const selected = globalThis.flag ? ${choice}; selected.readFileSync("config.json");`;
|
||||
const parsed = parseJavaScriptSource(source, "entry.MJS");
|
||||
if (parsed === null) throw new Error("fixture did not parse");
|
||||
expect(
|
||||
analyzeParsedJavaScriptSemantics(parsed).configurationOperations,
|
||||
).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
kind: "file",
|
||||
key: "config.json",
|
||||
builtinAuthority: "candidate",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("does not equate mixed alternatives with different identities or replaced methods", () => {
|
||||
for (const source of [
|
||||
'import * as builtin from "node:fs"; const alternate = require("http"); const selected = globalThis.flag ? builtin : alternate; selected.readFileSync("config.json");',
|
||||
'import * as builtin from "node:fs"; const alternate = require("fs"); alternate.readFileSync = globalThis.replacement; const selected = globalThis.flag ? builtin : alternate; selected.readFileSync("config.json");',
|
||||
'import * as builtin from "node:fs"; const alternate = require("fs"); const selected = globalThis.flag ? builtin : alternate; selected.default.readFileSync("config.json");',
|
||||
]) {
|
||||
const parsed = parseJavaScriptSource(source, "entry.MJS");
|
||||
if (parsed === null) throw new Error("fixture did not parse");
|
||||
expect(
|
||||
analyzeParsedJavaScriptSemantics(parsed).configurationOperations,
|
||||
).toEqual([]);
|
||||
}
|
||||
});
|
||||
|
||||
it("retains a conditional built-in reached through a nested receiver", () => {
|
||||
const source =
|
||||
'import * as builtin from "node:fs"; const alternate = require("fs"); const selected = globalThis.flag ? builtin : alternate; selected.promises.readFile("config.json");';
|
||||
const parsed = parseJavaScriptSource(source, "entry.MJS");
|
||||
if (parsed === null) throw new Error("fixture did not parse");
|
||||
expect(
|
||||
analyzeParsedJavaScriptSemantics(parsed).configurationOperations,
|
||||
).toContainEqual(
|
||||
expect.objectContaining({
|
||||
kind: "file",
|
||||
key: "config.json",
|
||||
builtinAuthority: "candidate",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("does not retain a nested built-in after replacing either the object or its method", () => {
|
||||
for (const mutation of [
|
||||
"alternate.promises = globalThis.replacement;",
|
||||
"alternate.promises.readFile = globalThis.replacement;",
|
||||
"selected.promises.readFile = globalThis.replacement;",
|
||||
]) {
|
||||
const source = `import * as builtin from "node:fs"; const alternate = require("fs"); const selected = globalThis.flag ? builtin : alternate; ${mutation} selected.promises.readFile("config.json");`;
|
||||
const parsed = parseJavaScriptSource(source, "entry.MJS");
|
||||
if (parsed === null) throw new Error("fixture did not parse");
|
||||
expect(
|
||||
analyzeParsedJavaScriptSemantics(parsed).configurationOperations,
|
||||
).toEqual([]);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user