fix(javascript): analyze first-party sources before dependencies (#9341)

* fix(javascript): analyze first-party sources before dependencies

Every source in one application analysis charges the same parent result
budget, and sources were offered in lexical inventory order. On an Electron
app.asar, node_modules/ sorts before an electron-vite out-*/ directory, so
dependency files spent the budget and every first-party main, preload, and
renderer file had its semantic analysis not started and its application
projection rejected. The summary then reported zero windows, preloads, and
bridges while electron_semantics still said "recovered".

Offer application JavaScript before JavaScript under node_modules; reported
files keep inventory order. Count Electron boundary facts only from files
whose projection was admitted, and report electron_semantics "partial" (with
a limitation naming the count) when an Electron-loading source was not fully
examined or reported.

Fixes #9321

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(javascript): treat limited Electron examination as partial coverage

A static pass can stop early at the Electron wrapper expansion budget or
another resource limit without failing the worker. Such a source carries no
analysis or projection failure, so its retained IPC or bridge facts still
reported electron_semantics "recovered". Read the owned examination status
and count a limited Electron-loading source as incomplete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-09 19:42:19 +08:00
1 parent 31b6db72c6
commit 512bcf5cdb
7 files changed
+418 -44

No files matched your search

@@ -6,7 +6,10 @@ import {
ELECTRON_REFERENCE_KINDS,
} from "../../domain/javascript/javascriptElectronMemberWrites.js";
import type { ElectronBoundarySummary } from "../../domain/javascript/javascriptApplicationAnalysis.js";
import type { JavaScriptArtifactAnalysis } from "./JavaScriptArtifactAnalysisTypes.js";
import type {
AnalyzedJavaScriptArtifactFile,
JavaScriptArtifactAnalysis,
} from "./JavaScriptArtifactAnalysisTypes.js";
import type { JavaScriptArtifactFile } from "../../domain/javascript/javascriptArtifactFiles.js";
import {
resolveArtifactPathByContext,
@@ -128,7 +131,7 @@ export const createElectronIpcContext = (
};
/**
* Whether any analyzed source loads an Electron module.
* Whether one analyzed source loads an Electron module.
*
* `analysis_coverage.applicability.electron` is the domain owner of this
* question: it already excludes a `type-import`, a `require.resolve` that only
@@ -139,42 +142,51 @@ export const createElectronIpcContext = (
* Historical evidence may predate that field, so the retained references answer
* the same question for those files.
*/
export const electronModuleReferenced = (
analysis: JavaScriptArtifactAnalysis,
): boolean =>
analysis.files.some(({ javascript, semantic }) => {
const applicability = javascript?.analysis_coverage?.applicability.electron;
if (applicability !== undefined) return applicability === "observed";
const links = semantic?.ir.moduleLinks;
if (
links !== undefined &&
links.some(
({ specifier, kind, loaderAuthority }) =>
kind !== "type-import" &&
loaderAuthority !== "candidate" &&
specifier !== null &&
ELECTRON_MODULE.test(specifier),
)
)
return true;
return (javascript?.references ?? []).some(
({ specifier, kind, operation, loader_authority }) =>
operation === "load" &&
loader_authority !== "candidate" &&
ELECTRON_REFERENCE_KINDS.has(kind) &&
const electronModuleReferencedBy = ({
javascript,
semantic,
}: AnalyzedJavaScriptArtifactFile): boolean => {
const applicability = javascript?.analysis_coverage?.applicability.electron;
if (applicability !== undefined) return applicability === "observed";
const links = semantic?.ir.moduleLinks;
if (
links !== undefined &&
links.some(
({ specifier, kind, loaderAuthority }) =>
kind !== "type-import" &&
loaderAuthority !== "candidate" &&
specifier !== null &&
ELECTRON_MODULE.test(specifier),
);
});
)
)
return true;
return (javascript?.references ?? []).some(
({ specifier, kind, operation, loader_authority }) =>
operation === "load" &&
loader_authority !== "candidate" &&
ELECTRON_REFERENCE_KINDS.has(kind) &&
specifier !== null &&
ELECTRON_MODULE.test(specifier),
);
};
/** Every Electron boundary fact family the graph reports. */
/** Whether any analyzed source loads an Electron module. */
export const electronModuleReferenced = (
analysis: JavaScriptArtifactAnalysis,
): boolean => analysis.files.some(electronModuleReferencedBy);
/**
* Every Electron boundary fact family the graph reports. A rejected
* application projection keeps its static facts on the file node only, so
* those facts are not part of the reported boundary surface.
*/
export const electronBoundaryFactCount = (
analysis: JavaScriptArtifactAnalysis,
): number =>
analysis.files.reduce(
(count, { javascript }) =>
(count, { javascript, application_projection_failure }) =>
count +
(javascript === null
(javascript === null || application_projection_failure !== undefined
? 0
: javascript.electron.browser_windows.filter(provenElectronFinding)
.length +
@@ -219,18 +231,57 @@ export const hasCandidateElectronFindings = (
);
/**
* Whether the Electron boundary summary came back empty. `undefined` means no
* analyzed source names Electron, which is unknown rather than absent: unread
* sources and dynamic module names can hide its use.
* A completed static pass can still stop early, for example at the Electron
* wrapper expansion budget. Syntax recovery and examination facts jointly own that verdict.
*/
const electronExaminationLimited = ({
javascript,
}: AnalyzedJavaScriptArtifactFile): boolean => {
if (javascript === null) return false;
const status = javascript.analysis_coverage?.examination.status;
const syntax = javascript.analysis_coverage?.syntax.status;
return (
javascript.parse_status !== "complete" ||
(syntax !== undefined && syntax !== "complete") ||
(status !== undefined && status !== "complete")
);
};
/**
* Electron-loading sources whose boundary facts may be missing from the
* report: their analysis was interrupted or not started, their application
* projection was rejected for the result budget, or their static examination
* stopped at a resource limit or retained only partial syntax/semantics.
*/
export const electronIncompleteSourceCount = (
analysis: JavaScriptArtifactAnalysis,
): number =>
analysis.files.filter(
(file) =>
(file.analysis_failure !== undefined ||
file.application_projection_failure !== undefined ||
electronExaminationLimited(file)) &&
electronModuleReferencedBy(file),
).length;
/**
* Whether the Electron boundary summary came back empty or incomplete.
* `undefined` means no analyzed source names Electron, which is unknown rather
* than absent: unread sources and dynamic module names can hide its use.
* `partial` means some facts were reported while other Electron-loading
* sources were not fully examined or reported, so missing windows, preloads,
* bridges, or IPC operations from those sources are unknown.
*/
export const electronSemanticsState = (
analysis: JavaScriptArtifactAnalysis,
): "recovered" | "empty" | undefined =>
): "recovered" | "partial" | "empty" | undefined =>
electronModuleReferenced(analysis) === false
? undefined
: electronBoundaryFactCount(analysis) === 0
? "empty"
: "recovered";
: electronIncompleteSourceCount(analysis) > 0
? "partial"
: "recovered";
/** Summarize static Electron findings without treating gaps as absence. */
export const summarizeElectronBoundaries = (