fix(javascript): align module lookup and source evidence

Preserve CommonJS literal paths and confined ESM URL semantics, including package main fallback, directory intent, Unicode identity, and present opaque modules. Parse extraction inputs at their AST/source owner, retain skipped HTML and source-map coverage, and distinguish endpoint candidates from proven receiver facts. Version structural fingerprints with computed literal contents and propagate them through worker contracts.

Reviewed fixes include #1810, #1840, #2642, #2700, #2702, #2714, #2803, #2960, #2968, #2986, #3035, and #3036.

Validation: 158 resolver tests passed; public CLI/MCP module lookup controls, package-main/Unicode workflows, and six builtin workflows passed in the current compiled lane. Worker schema/fingerprint regressions passed. Large public pdf.js completion and real Electron analysis remain unverified.
This commit is contained in:
morluto
2026-10-14 08:46:50 +08:00
parent 04672f2b91
commit b58adafa4f
63 changed files with 4066 additions and 326 deletions
@@ -0,0 +1,33 @@
import { expect, it } from "vitest";
import { analyzeJavaScriptStaticSource } from "../../domain/javascript/javascriptStaticAnalysis.js";
import { javaScriptWorkerStaticAnalysisSchema } from "./JavaScriptAnalysisWorkerSchemas.js";
it("versions fingerprints through the worker schema and rejects v1", () => {
const facts =
analyzeJavaScriptStaticSource(`globalThis.webpackChunkApp.push([[1], {
17(module, exports) { const key = selectKey(); exports.read = value[key]; }
}]);`);
expect(facts.bundler_registrations[0]?.modules[0]).toMatchObject({
structural_fingerprint_algorithm: "babel-ast-v2",
structural_fingerprint_sha256: expect.stringMatching(/^[a-f0-9]{64}$/u),
});
expect(
javaScriptWorkerStaticAnalysisSchema.safeParse(
JSON.parse(JSON.stringify(facts)) as unknown,
).success,
).toBe(true);
const old = {
...facts,
bundler_registrations: facts.bundler_registrations.map((registration) => ({
...registration,
modules: registration.modules.map((module) => ({
...module,
structural_fingerprint_algorithm: "babel-ast-v1",
})),
})),
};
expect(javaScriptWorkerStaticAnalysisSchema.safeParse(old).success).toBe(
false,
);
});
@@ -1,6 +1,7 @@
import { z } from "zod";
import { digestSchema } from "../../domain/digests.js";
import type { JavaScriptStaticAnalysis } from "../../domain/javascript/javascriptStaticAnalysisTypes.js";
import { JAVASCRIPT_AST_FINGERPRINT_ALGORITHM } from "../../domain/javascript/javascriptStaticAnalysisTypes.js";
import type {
JavaScriptSemanticProperty,
JavaScriptSemanticValue,
@@ -363,7 +364,9 @@ export const javaScriptWorkerStaticAnalysisSchema = z
exports: strings,
location: range,
structural_fingerprint_sha256: digestSchema,
structural_fingerprint_algorithm: z.literal("babel-ast-v1"),
structural_fingerprint_algorithm: z.literal(
JAVASCRIPT_AST_FINGERPRINT_ALGORITHM,
),
}),
),
location: range,