Files
reverse-engineering-anything/src/application/javascript/JavaScriptWrappedCallPathCancellation.test.ts
T
morluto cb4e5cfbff feat(analysis): make resource budgets recoverable across CLI and MCP (#9706)
* refactor(analysis): centralize resource budgets and recovery facts

* feat(analysis): expose ASAR and Ghidra runtime admission controls

* feat(artifacts): expose reader admission and preserve limited recognition

* feat(javascript): expose recoverable semantic precision budgets

* feat(web): add recoverable source-map budgets and compact retained views

* feat(web): make historical capture decoding budgets recoverable

* fix(desktop): enforce selected view policies across capture and export

* feat(runtime): make Frida and LLDB retention budgets selectable

* feat(native): expose diagnostic budgets and preserve exhaustion causes

* feat(managed): expose recoverable snapshot and representation budgets

* feat(metadata): make Go and Rust inspection budgets recoverable

* feat(wasm): expose representation and producer admissions

* feat(evm): expose per-call worker resource budgets

* feat(android): make resource and string-pool omissions recoverable

* feat(producers): expose command and recorded-capture budgets

* docs(analysis): record recovery contracts and integrated validation

* fix(docs): link calibration oracle from published verification pages

* fix(docs): restore desktop task anchors and receipt links

* test(analysis): align fixtures with selectable budget contracts

* fix(analysis): remove source-location projector dependency cycle

* test(analysis): refresh budget recovery and verifier regressions

* test(analysis): preserve format and publication recovery expectations

* test(windows): align conformance with owned runtime admission

* fix(desktop): preserve selected alias kinds in exported state

* test(analysis): align provider fixtures with recoverable budgets

* test(desktop): validate emitted alias metadata structurally

* fix(ghidra): classify bounded Windows endpoint refusals

* test(cli): assert selectable artifact admission recovery

* fix(cli): preserve capture provenance in environment builds
2026-11-10 05:11:20 -05:00

62 lines
2.6 KiB
TypeScript

import { expect, it } from "vitest";
import { completeJavaScriptAnalysisSteps } from "./JavaScriptAnalysisControl.js";
import { collectElectronWrappedCallPathsSteps } from "../../domain/javascript/electronWrappedCallPaths.js";
import {
indexJavaScriptBindingsWithReceiversSteps,
indexJavaScriptElectronIdentitySteps,
} from "../../domain/javascript/javascriptSemanticAnalysis.js";
import { completeSemanticSteps } from "../../domain/javascript/javascriptSemanticTraversal.js";
import { parseJavaScriptSource } from "../../domain/javascript/javascriptSourceParser.js";
import { createJavaScriptAnalysisAccumulator } from "../../domain/javascript/javascriptStaticAnalysisState.js";
it("cancels actual call-path work while its first seed indexes a long block", async () => {
const source = `const e = require("electron"); {
e.ipcMain.on("first", event => event.sender.copy());
${"0;".repeat(2048)}
}`;
const parsed = parseJavaScriptSource(source);
if (parsed === null) throw new Error("Expected parsed source");
const index = completeSemanticSteps(
indexJavaScriptBindingsWithReceiversSteps(parsed.program),
);
const identity = completeSemanticSteps(
indexJavaScriptElectronIdentitySteps(parsed.program, index.bindings),
);
const accumulator = createJavaScriptAnalysisAccumulator(source.length);
const work = collectElectronWrappedCallPathsSteps(
parsed.program,
index.bindings,
source,
accumulator,
identity,
);
// The first candidate has not yet been expanded: this checkpoint is inside
// its block indexing, before the walker's completed batch is yielded.
expect(work.next()).toEqual({ done: false, value: undefined });
expect(accumulator.ipc).toEqual([]);
const controller = new AbortController();
const reason = { request: "cancel prefix indexing" };
controller.abort(reason);
await expect(
completeJavaScriptAnalysisSteps(work, controller.signal),
).rejects.toMatchObject({ reason: "cancelled", cause: reason });
expect(work.next()).toEqual({ done: true, value: undefined });
expect(accumulator.ipc).toEqual([]);
expect(accumulator.electronCallPathLimits).toBeUndefined();
// A new analysis owns a new index and can still complete the same source.
const completed = createJavaScriptAnalysisAccumulator(source.length);
expect(
completeSemanticSteps(
collectElectronWrappedCallPathsSteps(
parsed.program,
index.bindings,
source,
completed,
identity,
),
),
).toContainEqual(expect.objectContaining({ entry: "first", conditions: [] }));
expect(completed.electronCallPathLimits).toBeUndefined();
});