* fix(cancellation): preserve caller abort reason in cancellation errors Several application, provider, and MCP boundaries constructed AnalysisCancelledError, ArtifactReaderFailure, or DetachedPgpSignatureError for an already-observed or newly-observed abort without passing the caller's signal.reason as the error cause. The typed result then reported cancellation with an undefined reason even though the exact object supplied to AbortController.abort(reason) was still available. Pass signal.reason as the cause at each producing cancellation site: JavaScript artifact reconstruction and file abort checks, derived MCP operation checkpoints, detached PGP verification, ASAR listing admission, Dart AOT inspection and its provider guard, evidence-file analysis views, binary layout and recorded crash admission, WASM inspection admission, and the Kuna shared assembly-index wait. Cancellation classification and cleanup behavior are unchanged. Fixes morluto/rea#5935 Fixes morluto/rea#5944 Fixes morluto/rea#6100 Fixes morluto/rea#6101 Fixes morluto/rea#6110 Fixes morluto/rea#6113 Fixes morluto/rea#6121 Fixes morluto/rea#6131 Fixes morluto/rea#6132 * test(cancellation): assert the exact caller reason identity Copied reasons satisfied toMatchObject, so the tests would pass even if the caller's abort reason were replaced by a structurally equal copy. Capture the rejection and assert the cause is the same object. Co-authored-by: Copilot <[email protected]> Copilot-Session: 35b247e9-c793-4b8f-979a-807c27112cf5 --------- Co-authored-by: Copilot <[email protected]> Copilot-Session: 35b247e9-c793-4b8f-979a-807c27112cf5
113 lines
3.9 KiB
TypeScript
113 lines
3.9 KiB
TypeScript
import { isAbsolute } from "node:path";
|
|
import type { ExecutionOptions } from "../AnalysisProvider.js";
|
|
import type { WasmArtifactPort } from "./WasmArtifactPort.js";
|
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import {
|
|
AnalysisCancelledError,
|
|
AnalysisInputError,
|
|
AnalysisOutputError,
|
|
type AnalysisInputIssue,
|
|
} from "../../domain/analysisErrorCore.js";
|
|
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
|
import {
|
|
inspectWasmArtifactInputSchema,
|
|
wasmArtifactSchema,
|
|
wasmArtifactMatchesSubject,
|
|
DEFAULT_WASM_COMMAND_TIMEOUT_MS,
|
|
} from "../../domain/wasm/wasmArtifact.js";
|
|
import { analysisInputErrorFromIssues } from "../../domain/inputIssueProjection.js";
|
|
import { err, type Result } from "../../domain/result.js";
|
|
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
|
|
|
const OPERATION = "inspect_wasm_artifact";
|
|
|
|
/** Shared artifact validation and typed inline Evidence for CLI/MCP. */
|
|
export class WasmArtifactService {
|
|
constructor(readonly provider: WasmArtifactPort) {}
|
|
|
|
/** Join provider cleanup during shutdown or an explicit retry. */
|
|
close(): Promise<void> {
|
|
return this.provider.close();
|
|
}
|
|
|
|
/** Preserve exact selected artifact identity and validated upstream observations. */
|
|
async inspect(
|
|
rawInput: unknown,
|
|
options?: ExecutionOptions,
|
|
): Promise<Result<Evidence, AnalysisError>> {
|
|
if (options?.signal?.aborted)
|
|
return err(
|
|
new AnalysisCancelledError(OPERATION, {
|
|
cause: options.signal.reason,
|
|
}),
|
|
);
|
|
const input = inspectWasmArtifactInputSchema.safeParse(rawInput);
|
|
if (!input.success)
|
|
return err(
|
|
analysisInputErrorFromIssues(OPERATION, input.error.issues, rawInput, {
|
|
cause: input.error,
|
|
}),
|
|
);
|
|
const pathIssues = [
|
|
{ value: input.data.path, path: ["path"] },
|
|
...input.data.glue_paths.map((value, index) => ({
|
|
value,
|
|
path: ["glue_paths", index],
|
|
})),
|
|
...input.data.candidate_paths.map((value, index) => ({
|
|
value,
|
|
path: ["candidate_paths", index],
|
|
})),
|
|
].flatMap<AnalysisInputIssue>(({ value, path }) =>
|
|
isAbsolute(value)
|
|
? []
|
|
: [
|
|
{
|
|
path,
|
|
reason: "invalid_format",
|
|
message: "Expected an absolute filesystem path on this host.",
|
|
},
|
|
],
|
|
);
|
|
if (pathIssues.length > 0)
|
|
return err(new AnalysisInputError(OPERATION, undefined, pathIssues));
|
|
const inspected = await this.provider.inspect(input.data, options);
|
|
if (!inspected.ok) return inspected;
|
|
const execution = inspected.value;
|
|
const report = wasmArtifactSchema.safeParse(execution.result);
|
|
if (
|
|
!report.success ||
|
|
report.data.artifact.path !== input.data.path ||
|
|
report.data.tool_profile.timeout_ms !==
|
|
(input.data.command_timeout_ms ?? DEFAULT_WASM_COMMAND_TIMEOUT_MS) ||
|
|
!wasmArtifactMatchesSubject(report.data.artifact, execution.subject) ||
|
|
JSON.stringify(report.data.glue.map((item) => item.artifact.path)) !==
|
|
JSON.stringify(input.data.glue_paths) ||
|
|
JSON.stringify(report.data.candidates.map((item) => item.path)) !==
|
|
JSON.stringify([
|
|
...new Set([input.data.path, ...input.data.candidate_paths]),
|
|
])
|
|
)
|
|
return err(
|
|
new AnalysisOutputError(
|
|
OPERATION,
|
|
"WABT adapter returned malformed data or changed the selected artifact identity.",
|
|
),
|
|
);
|
|
return completeProviderEvidence(
|
|
createEvidence(execution.subject, execution.provider, {
|
|
operation: OPERATION,
|
|
parameters: input.data,
|
|
result: report.data,
|
|
...(execution.rawResult === null
|
|
? {}
|
|
: { rawResult: execution.rawResult }),
|
|
confidence: "observed",
|
|
locations: execution.locations,
|
|
limitations: execution.limitations,
|
|
}),
|
|
options?.signal,
|
|
);
|
|
}
|
|
}
|