fix(javascript): version syntax-aware structural fingerprints

Retain bigint/directive values, assignment operators, fixed public keys and
execution-affecting syntax flags in v3. Preserve local/private binding renames
and isolate structural matching by algorithm version. Remove the redundant
test grouping and document structural matching as heuristic evidence.

Validated AST, worker admission, archived-version matching, reconstruction and
public CLI comparisons. Auto-accessors are tested at the AST boundary because
the production JavaScript parser does not enable their Babel plugin.
Refs #3952, #4020.

Co-authored-by: ShitK <1724059440@qq.com>
This commit is contained in:
morluto
2026-10-16 05:43:14 +08:00
parent c0d550b231
commit 0ef938f4c5
8 changed files with 421 additions and 58 deletions
@@ -29,34 +29,39 @@ it("retains candidate endpoint interpretation across the worker boundary", () =>
).toBe(false);
});
it("versions fingerprints through the worker schema and rejects v1", () => {
const facts =
analyzeJavaScriptStaticSource(`globalThis.webpackChunkApp.push([[1], {
it.each(["babel-ast-v1", "babel-ast-v2"])(
"versions fingerprints through the worker schema and rejects %s",
(oldAlgorithm) => {
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,
);
});
expect(facts.bundler_registrations[0]?.modules[0]).toMatchObject({
structural_fingerprint_algorithm: "babel-ast-v3",
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: oldAlgorithm,
})),
}),
),
};
expect(javaScriptWorkerStaticAnalysisSchema.safeParse(old).success).toBe(
false,
);
},
);
it("accepts candidate endpoint interpretations from static analysis", () => {
const facts = analyzeJavaScriptStaticSource(`http.request("POST", target);`);