fix(javascript): honor cancellation before evidence publication (#1098)

This commit is contained in:
Ysopwnable authored and GitHub committed 2026-10-09 01:15:50 +08:00
1 parent f8e143a3bc
commit cc0ee2edc6
18 files changed
+1080 -74

No files matched your search

+14 -10
View File
@@ -25,6 +25,7 @@ import {
} from "../cliObservationOptions.js";
import { runCliJavaScriptApplicationAnalysis } from "./javascriptApplicationAnalysis.js";
import type { CliResultOutput } from "./streamedJsonOutput.js";
import { withCommandCancellation } from "./commandCancellation.js";
/** Register CLI equivalents of the Electron MCP tools. */
export const registerElectronCommands = (
@@ -184,16 +185,19 @@ const registerJavaScriptApplicationCommand = (
}),
options: javascriptApplicationOptions,
run: ({ args, options, format }) =>
logCliCommand(logger, CLI_COMMANDS.analyzeJavaScriptApplication, () =>
runCliJavaScriptApplicationAnalysis(
{ input_path: args.path, format: options.artifactFormat },
resultOutput === undefined
? undefined
: {
output: resultOutput,
command: CLI_COMMANDS.analyzeJavaScriptApplication,
format,
},
withCommandCancellation((signal) =>
logCliCommand(logger, CLI_COMMANDS.analyzeJavaScriptApplication, () =>
runCliJavaScriptApplicationAnalysis(
{ input_path: args.path, format: options.artifactFormat },
resultOutput === undefined
? undefined
: {
output: resultOutput,
command: CLI_COMMANDS.analyzeJavaScriptApplication,
format,
},
signal,
),
),
),
});
+7 -2
View File
@@ -8,6 +8,7 @@ import type { CliCommandOutput } from "./streamedJsonOutput.js";
export const runCliJavaScriptApplicationAnalysis = async (
input: unknown,
output?: CliCommandOutput,
signal?: AbortSignal,
): Promise<JsonValue | undefined> => {
const started = performance.now();
const progress = createProgressReporter(
@@ -16,7 +17,10 @@ export const runCliJavaScriptApplicationAnalysis = async (
},
{ minimumIntervalMs: 0 },
);
const result = await analyzeJavaScriptApplication(input, { progress });
const result = await analyzeJavaScriptApplication(input, {
progress,
...(signal === undefined ? {} : { signal }),
});
const value = result.ok ? result.value : cliError(result.error);
if (
output !== undefined &&
@@ -26,7 +30,8 @@ export const runCliJavaScriptApplicationAnalysis = async (
duration: `${Math.round(performance.now() - started)}ms`,
}))
)
return undefined;
// Keep failures visible to command logging after the stream has handled stdout.
return result.ok ? undefined : value;
return value;
};