mirror of
https://github.com/morluto/rea.git
synced 2026-11-12 09:52:27 +00:00
fix(reference): retain proven loader calls and unresolved targets (#9920)
* fix(reference): retain proven loader calls and unresolved targets * refactor(reference): remove unused ancestor lookup * fix(reference): drop loader calls that return a reassigned member An immediate call could still use a member's original require initializer because mutation facts were not built for a call-valued callee. A definite assignment that precedes the call now replaces that initializer. * fix(reference): select returned loaders from indexed read facts * fix(reference): refresh loader facts for wrapped returned members A sequence such as (0, box.load) still used the original require initializer. Follow sequence, conditional, and logical returns to the member before deciding whether a prior assignment replaced it. * test(reference): record unresolved CommonJS targets in source evidence unknown.cjs calls require with a non-literal target. The inventory now keeps that coverage limitation on the file entry, and the boundary fixture asserts it beside the resolved member relationships. * fix(reference): cover opaque apply lists and assigned returned members require.apply(null, args) has no normalized argument list, so the inventory now records an unresolved target instead of complete coverage. An assignment return such as f = box.load is followed to the member before a prior replacement is trusted. * fix(reference): keep self-defaulted module delegates loadable Timing a member read at a later call made `box.load = box.load || null` observe its own write and drop the native delegate. Reads that already fed an earlier assignment stay at the member. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
1 parent
d9537fc75c
commit
cb17828dd1
9 files changed
+317
-41
No files matched your search
@@ -9,7 +9,11 @@ import { expect, it } from "vitest";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { importReferenceSource } from "../../support/referenceSourceResourceScope.js";
|
||||
|
||||
const hashedSourceEntry = (path: string, source: string) => ({
|
||||
const hashedSourceEntry = (
|
||||
path: string,
|
||||
source: string,
|
||||
limitations: readonly string[] = [],
|
||||
) => ({
|
||||
path,
|
||||
kind: "file",
|
||||
sha256: createHash("sha256").update(source).digest("hex"),
|
||||
@@ -17,7 +21,7 @@ const hashedSourceEntry = (path: string, source: string) => ({
|
||||
language: "JavaScript",
|
||||
classifications: ["source"],
|
||||
content_state: "hashed",
|
||||
limitations: [],
|
||||
limitations: [...limitations],
|
||||
});
|
||||
|
||||
const memberFixtures = [
|
||||
@@ -173,5 +177,15 @@ it("distinguishes computed require member values from literal members in source
|
||||
]);
|
||||
expect(graph.entries).toHaveLength(Object.keys(sources).length);
|
||||
for (const [path, source] of Object.entries(sources))
|
||||
expect(graph.entries).toContainEqual(hashedSourceEntry(path, source));
|
||||
expect(graph.entries).toContainEqual(
|
||||
hashedSourceEntry(
|
||||
path,
|
||||
source,
|
||||
path === "unknown.cjs"
|
||||
? [
|
||||
"A CommonJS module target in unknown.cjs could not be determined statically.",
|
||||
]
|
||||
: [],
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -118,3 +118,67 @@ it("retains constructor loader requests without inventing host authority", async
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("indexes returned loader reads before publishing dependency edges", async () => {
|
||||
const root = await createTestTempDirectory("rea-returned-loader-reads-");
|
||||
const sources = {
|
||||
"unchanged.cjs": 'const box={load:require};(()=>box.load)()("./dep.cjs");',
|
||||
"child-only.cjs":
|
||||
'const box={load:require};box.load.extra=1;(()=>box.load)()("./dep.cjs");',
|
||||
"captured-before.cjs":
|
||||
'const box={load:require};const load=box.load;box.load=()=>{};(()=>load)()("./dep.cjs");',
|
||||
"nested-unchanged.cjs":
|
||||
'const box={api:{load:require}};(()=>box.api.load)()("./dep.cjs");',
|
||||
"overwritten.cjs":
|
||||
'const box={load:require};box.load=()=>{};(()=>box.load)()("./dep.cjs");',
|
||||
"conditional.cjs":
|
||||
'const box={load:require};box.load=()=>{};(()=>(true?box.load:box.load))()("./dep.cjs");',
|
||||
"sequence.cjs":
|
||||
'const box={load:require};box.load=()=>{};(()=>(0,box.load))()("./dep.cjs");',
|
||||
"deleted.cjs":
|
||||
'const box={load:require};delete box.load;(()=>box.load)()("./dep.cjs");',
|
||||
"nested-replaced.cjs":
|
||||
'const box={api:{load:require}};box.api.load=()=>{};(()=>box.api.load)()("./dep.cjs");',
|
||||
"own-write.cjs":
|
||||
'const box={load:require};(()=>(box.load=()=>{},box.load))()("./dep.cjs");',
|
||||
"local.cjs": 'const box={load:()=>{}};(()=>box.load)()("./dep.cjs");',
|
||||
"direct-overwritten.cjs":
|
||||
'const box={load:require};box.load=()=>{};box.load("./dep.cjs");',
|
||||
"dep.cjs": "module.exports={};",
|
||||
};
|
||||
await Promise.all(
|
||||
Object.entries(sources).map(([name, source]) =>
|
||||
writeFile(join(root, name), source),
|
||||
),
|
||||
);
|
||||
const result = await importReferenceSource({
|
||||
root,
|
||||
caller: "returned-loader-reads",
|
||||
policy: { secretPatterns: [] },
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.parse_failures).toEqual([]);
|
||||
expect(result.value.relationships).toEqual([
|
||||
...["captured-before.cjs", "child-only.cjs"].map((from_path) => ({
|
||||
from_path,
|
||||
to: "dep.cjs",
|
||||
kind: "requires",
|
||||
resolution: "internal",
|
||||
parse_state: "parsed",
|
||||
})),
|
||||
{
|
||||
from_path: "direct-overwritten.cjs",
|
||||
to: "./dep.cjs",
|
||||
kind: "requires",
|
||||
resolution: "unknown",
|
||||
parse_state: "partial",
|
||||
},
|
||||
...["nested-unchanged.cjs", "unchanged.cjs"].map((from_path) => ({
|
||||
from_path,
|
||||
to: "dep.cjs",
|
||||
kind: "requires",
|
||||
resolution: "internal",
|
||||
parse_state: "parsed",
|
||||
})),
|
||||
]);
|
||||
});
|
||||
Reference in new issue
Block a user