mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 21:23:45 +00:00
fix(javascript): attribute call-path unknowns only where the walk can reach Electron (#4915)
* test(javascript): cover the isolated-world probe outside Electron identity
* fix(javascript): expand Electron call paths only with an Electron reference
* test(javascript): cover Electron reach through resolved names, aliases and worker URLs
* fix(javascript): attribute call-path unknowns only where the walk can reach Electron
* test(javascript): cover a hoisted read that precedes a loader alias
* fix(javascript): keep call-path unknowns for late-initialized loader aliases
* test(javascript): drop a duplicate loader-alias case
* test(javascript): cover loader aliases reached through bindings and calls
* fix(javascript): prove a late initializer loader-free before dropping its unknown
* test(javascript): cover loaders behind default parameters, wrappers and long alias chains
* fix(javascript): resolve identifiers inside late initializers and bound the loader proof
* fix(javascript): bound late loader proofs and preserve input uncertainty
* fix(javascript): fail closed for receiver and mutated loaders
* fix(javascript): close loader-free proof gaps
* fix(javascript): retain uncertain loader sources
* test(javascript): cover remaining loader proof gaps
* fix(javascript): bound alias writes and preserve loader uncertainty
* test(javascript): cover demand-driven loader mutation facts
* perf(javascript): index loader mutation facts on demand
* style(javascript): apply oxfmt to the loader proof changes
* test(javascript): cover inherited loaders and rebound alias writes
* fix(javascript): preserve inherited loaders and rebound aliases
* test(evaluation): update scoped feature coverage oracle
* test(javascript): cover inherited loader proof gaps
* fix(javascript): preserve projected and inherited loaders
* fix(javascript): prove safe parameter member reads
* test(javascript): cover loader proof review gaps
* fix(javascript): close remaining loader proof gaps
* fix(javascript): preserve qualified global replacements
* fix(javascript): preserve spread rest uncertainty
* fix(javascript): retain retried handler uncertainty
* fix(javascript): retain import.meta loader uncertainty
* fix(javascript): detach fresh constructed aliases
* fix(javascript): check inherited members of ambient loaders
* test(javascript): parse call-path gate fixtures as established CommonJS
* fix(javascript): prove projected locals inside late initializers
A function-local binding was accepted by scope alone, so a destructuring
projection such as `const { r } = {}` inside a late initializer never met
the inherited-member check that a top-level projection goes through. Route
projected locals through the binding proof; locals with inline initializers
keep the scope shortcut, since the walk already visits their expressions.
* fix(javascript): keep late results with changed prototypes or import.meta uncertain
The loader-free proof inspected member expressions inside a late function
but not what its caller does with the result. With `Object.prototype.load =
require`, `var load = () => ({})` and `load().load("electron")` reach the
loader through a member selected after the call, and a bare `import.meta`
returned after `import.meta.load = ...` does the same. Check each result
expression: a literal fails when its prototype chain gained members, a bare
`import.meta` when any of its members changed, and a result of unknown shape
when either happened. Promise and generator results inherit from
Object.prototype as well. `SemanticPropertyPathCoverage.touches` answers
whether any retained write or escape sits below a prefix.
* fix(javascript): detach replacements held by fresh bindings
`alias = replacement` with `const replacement = {}` selected an identifier
initializer, so the later `alias.other = 1` stayed a shared write on the
original alias group and the resolver treated `base` as overwritten,
dropping its bridge call path. Resolve the identifier to its binding and
accept it when that binding only ever received one fresh allocation.
Bindings that can hold the original object keep the shared write.
* fix(javascript): charge loader proofs through the wrapper-visit budget
#11319 replaced the wrapper-visit counter with a Budget, so the loader proof charge no longer compiled on current main. Spend it through the shared helper, which records the same limit.
* test(javascript): keep the alias bound off the quadratic write index
The 8,000 by 8,000 alias bound spent its time in the ambient write index, which walks every store to an object for each member write. That cost is the same on main and is not what the bound covers. Reach the same 64 million alias and write pairs with 32,000 aliases and 2,000 writes, which runs in about 2.5 seconds instead of 8.5 on the same host.
Drop the 30 second overrides on both alias bounds too. They halved the hosted CI deadline the source project gives them, and the testing guide asks tests to leave deadlines to the project.
* refactor(javascript): ask the effect log for loader proof effects
Main now guards reads of the effect indexes outside javascriptSemanticEffectLog.ts. The loader proof read them directly in 15 places. Route those reads through the log: the existing ambientPathMayHaveChanged and bindingHasMemberWrites queries, plus three timeless queries for a path or any member below it, an ambient binding write, and an escape at a site other than the call being proved. The answers are unchanged.
* fix(javascript): retain uncertainty for changed ambient values
---------
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
1 parent
166347f38b
commit
cad3209533
13 files changed
+2535
-83
No files matched your search
@@ -0,0 +1,92 @@
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { writeFixtureFiles } from "../../support/javascriptApplicationFixture.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
import { analyzeJavaScriptDirectory } from "../../support/cli/javascriptApplication.js";
|
||||
|
||||
cliTest(
|
||||
"reports complete coverage for a parsed module without Electron identity whose hoisted read precedes its initializer",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-js-coverage-hoisted-read-");
|
||||
await writeFixtureFiles(root, {
|
||||
"index.js": [
|
||||
"function schedule(callback) {",
|
||||
" return scheduleTimeout(callback, 0);",
|
||||
"}",
|
||||
'var scheduleTimeout = "function" === typeof setTimeout ? setTimeout : void 0;',
|
||||
"module.exports = { schedule };",
|
||||
"",
|
||||
].join("\n"),
|
||||
});
|
||||
const application = await analyzeJavaScriptDirectory("CLI", cli, root);
|
||||
|
||||
expect(application.statistics).toMatchObject({
|
||||
parsed_javascript_files: 1,
|
||||
parse_failures: 0,
|
||||
});
|
||||
const source = application.graph.nodes
|
||||
.flatMap((node) => node.observations)
|
||||
.find((observation) => observation.properties.file_kind === "javascript");
|
||||
expect(source?.properties.parse_status).toBe("complete");
|
||||
expect(application.graph.coverage).toEqual({
|
||||
status: "complete",
|
||||
truncated: false,
|
||||
omitted_count: 0,
|
||||
limits: [],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
for (const surface of ["CLI", "stdio MCP"] as const) {
|
||||
cliTest(
|
||||
`retains inherited loader uncertainty through ${surface}`,
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-js-inherited-loader-");
|
||||
await writeFixtureFiles(root, {
|
||||
"index.js": `Object.prototype.load = require;
|
||||
function register() { load("electron").ipcMain.on("ping", () => {}); }
|
||||
var load = [].load;
|
||||
register();`,
|
||||
});
|
||||
const application = await analyzeJavaScriptDirectory(surface, cli, root);
|
||||
const source = application.graph.nodes
|
||||
.flatMap((node) => node.observations)
|
||||
.find(
|
||||
(observation) => observation.properties.file_kind === "javascript",
|
||||
);
|
||||
|
||||
expect(source?.properties.parse_status).toBe("partial");
|
||||
expect(application.graph.coverage.status).toBe("partial");
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
`retains bridge paths after alias replacement through ${surface}`,
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-js-replaced-alias-");
|
||||
await writeFixtureFiles(root, {
|
||||
"preload.js": `const { contextBridge, ipcRenderer } = require("electron");
|
||||
const base = { ping: () => ipcRenderer.send("ping") };
|
||||
let alias = base;
|
||||
alias = {};
|
||||
alias.other = 1;
|
||||
contextBridge.exposeInMainWorld("api", base);`,
|
||||
});
|
||||
const application = await analyzeJavaScriptDirectory(surface, cli, root);
|
||||
const observations = application.graph.nodes.flatMap(
|
||||
(node) => node.observations,
|
||||
);
|
||||
|
||||
expect(observations).toContainEqual(
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({
|
||||
entry: "api.ping",
|
||||
entry_kind: "bridge-member",
|
||||
step_kind: "terminal",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user