Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(javascript): omit self-referential static references with disclosure
A bundled module that requires its own key (`r(50)` inside webpack
module 50) resolved, through the static-reference composer, to its own
module node. The resulting self-referential imports edge failed result
validation and lost the entire analysis ("Result schema rejected 1
issue ... (custom)"). This is the same invariant as #1146; #1152 fixed
the bundler async-chunk composer, and this is the remaining adjacent
composer.

Skip a reference whose resolved target is its own source, count it, and
disclose the omission the way #1152 discloses async-chunk references.
Sibling requires are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
kaoru0822-kitauji and claude committed Oct 9, 2026
commit e04a67304782608b8467322ed0b787c3eb56be9b
3 changes: 2 additions & 1 deletion src/application/javascript/JavaScriptArtifactGraphBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const buildJavaScriptArtifactGraphInput = (
addJavaScriptSourceModules(context);
const bundlerLimitations = addJavaScriptBundlerNodes(context);
const relationshipOmissions = addJavaScriptModuleRelationships(context);
addJavaScriptStaticFindings(context);
const findingLimitations = addJavaScriptStaticFindings(context);
addElectronBoundaries(context);
addJavaScriptHtmlRoles(context);
addJavaScriptSourceMapOriginals(context);
Expand All @@ -106,6 +106,7 @@ const buildJavaScriptArtifactGraphInput = (
coverage,
limitations: [
...bundlerLimitations,
...findingLimitations,
...graphLimitations(context, coverage.status, relationshipOmissions),
],
};
Expand Down
19 changes: 17 additions & 2 deletions src/application/javascript/JavaScriptArtifactGraphFindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ interface ResolvedReference {
/** Project imports, workers, roles, endpoints, storage, and source-map links. */
export const addJavaScriptStaticFindings = (
context: JavaScriptArtifactGraphContext,
): void => {
): readonly string[] => {
const omissions = { selfReferences: 0 };
for (const analyzed of context.analysis.files) {
const { file, javascript } = analyzed;
const asset = context.assetNodes.get(file.path);
if (javascript === null || asset === undefined) continue;
const coverage = javascriptAnalysisCoverage(javascript);
for (const value of javascript.references)
addReference(context, { file, asset, value, coverage });
addReference(context, { file, asset, value, coverage }, omissions);
for (const value of javascript.endpoints)
addEndpoint(context, { file, asset, value, coverage });
for (const value of javascript.storage)
Expand All @@ -59,11 +60,18 @@ export const addJavaScriptStaticFindings = (
for (const value of javascript.source_map_urls)
addSourceMapEdge(context, { file, asset, value, coverage });
}
const count = omissions.selfReferences;
return count === 0
? []
: [
`${String(count)} static ${count === 1 ? "reference" : "references"} resolved back to the referencing module itself and ${count === 1 ? "was" : "were"} omitted; application graph edges cannot be self-referential.`,
];
};

const addReference = (
context: JavaScriptArtifactGraphContext,
input: FindingInput<StaticReference>,
omissions: { selfReferences: number },
): void => {
const source =
sourceNodeFor(context, input.file.path, input.value.module_key) ??
Expand Down Expand Up @@ -119,6 +127,13 @@ const addReference = (
});
return;
}
// A reference that resolves to its own source, such as a bundled module
// requiring its own key, cannot become an edge: the application graph
// forbids self-referential edges and one would fail the whole analysis.
if (resolved?.node.node_id === source.node_id) {
omissions.selfReferences += 1;
return;
}
const target =
resolved?.node ??
unresolvedReferenceNode(context, input.file, input.value, input.coverage);
Expand Down
45 changes: 45 additions & 0 deletions tests/boundary/cli/javascriptBundlerSelfReferences.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,48 @@ for (const scenario of [
},
);
}

cliTest(
"preserves bundle evidence when a module requires its own key",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-bundler-self-require-");
await writeFixtureFiles(root, {
"runtime.js": `
(self.webpackChunkdemo = self.webpackChunkdemo || []).push([
[5], {50(e,t,r){r(50); r(51)}, 51(e,t,r){r.r(t)}}
]);
`,
});
const output = await cli.run({
arguments: ["analyze-javascript-application", root, "--json"],
});
expect(output.exitCode).toBe(0);
const result = javascriptApplicationAnalysisResultSchema.parse(
parseEvidence(output.json).normalized_result,
);
const { graph } = result;
expect(
graph.edges.filter((edge) => edge.source_node_id === edge.target_node_id),
).toEqual([]);
expect(graph.limitations).toContainEqual(
expect.stringMatching(
/^1 static reference resolved back to the referencing module itself and was omitted;/u,
),
);
expect(result.limitations).toEqual(
expect.arrayContaining(graph.limitations),
);
expect(
graph.edges.filter(
({ relation, properties }) =>
relation === "imports" &&
properties.kind === "require" &&
["50", "51"].includes(String(properties.specifier)),
),
).toEqual([
expect.objectContaining({
properties: expect.objectContaining({ specifier: "51" }),
}),
]);
},
);
Loading