Files
reverse-engineering-anything/src/domain/javascript/javascriptSemanticAnalysis.fingerprints.test.ts
T
morluto 60149282fc test: strengthen integration oracles and verification (#8295)
* test: strengthen integration oracles and verification

* test: bound lifecycle gates and strengthen workflow checks

* test: verify complete paged and extracted results

* test: preserve bytecode and cancellation evidence

* test: strengthen retained evidence and fixture cleanup

* test: require cross-projection bridge identities

* test: retain fixture owners through cleanup failures

* test: verify graph examples and project selectors

* test: tighten provider and lifecycle regressions

* test: consolidate hex coverage and bound cutter cleanup

* test: bound subprocess output waits and strengthen graph checks

* test: check mcp recovery and preserve cleanup owners

* test: verify structured mcp argument failures

* test: preserve artifact cleanup and gdb limit evidence

* test: preserve evidence identities and bound provider gates

* test: retain browser and comparison cleanup owners

* test: bound startup and strengthen fixture oracles

* test: bound lifecycle gates and verify recovered evidence

* test: verify public outcomes and lifecycle ownership

* test: assert precise evidence and release lifecycle gates

* test: verify selected facts and bound cleanup waits

* test: check retained evidence and decoded records

* test: verify final reports and retain cleanup ownership

* test: bound reviewed startup gates and retain cleanup

* test: verify PE errors and preserve MCP cleanup

* test: preserve MCP fixture cleanup ownership

* test: release provider gates before late startup
2026-11-01 00:15:28 +08:00

68 lines
2.4 KiB
TypeScript

import { expect, it } from "vitest";
import { analyzeJavaScriptSemantics } from "./javascriptSemanticAnalysis.js";
const components = (source: string) => {
const ir = analyzeJavaScriptSemantics(source);
expect(ir.functionFingerprints).toHaveLength(1);
const fingerprint = ir.functionFingerprints[0];
if (fingerprint === undefined)
throw new Error("Expected a function fingerprint");
expect(fingerprint.status).toBe("complete");
return fingerprint.components;
};
it.each([
["recognized directives", '"use strict"', '"use asm"'],
["ordinary directives", '"alpha"', '"beta"'],
["empty directive", '""', '"alpha"'],
["escaped strict spelling", '"use strict"', String.raw`"use\x20strict"`],
])("retains %s in the function literal commitment", (_name, left, right) => {
const source = (directive: string) =>
`function sample(value) { ${directive}; return value; }`;
expect(components(source(left)).literalSetSha256).not.toBe(
components(source(right)).literalSetSha256,
);
});
it.each([
[
'function sample(value) { "use strict"; return value; }',
"function renamed(input) {\n 'use strict' ;\n return input;\n}",
],
[
String.raw`function sample(value) { "use\x20strict"; return value; }`,
String.raw`function renamed(input) { 'use\x20strict'; return input; }`,
],
])(
"normalizes quote style, formatting and names for %s",
(original, renamed) => {
expect(components(renamed)).toEqual(components(original));
},
);
it("keeps a nested function's directive out of its owner fingerprint", () => {
const analyze = (directive: string) => {
const ir = analyzeJavaScriptSemantics(
`function outer() { function inner(value) { ${directive}; return value; } return 1; }`,
);
return new Map(
ir.functionFingerprints.map((fingerprint) => [
ir.callables.find(
({ callableId }) => callableId === fingerprint.callableId,
)?.name,
fingerprint.components,
]),
);
};
const first = analyze('"use strict"');
const second = analyze('"ordinary"');
expect(first.size).toBe(2);
expect(second.get("outer")).toEqual(first.get("outer"));
expect(first.get("inner")?.literalSetSha256).toEqual(expect.any(String));
expect(second.get("inner")?.literalSetSha256).toEqual(expect.any(String));
expect(second.get("inner")?.literalSetSha256).not.toBe(
first.get("inner")?.literalSetSha256,
);
});