Files
rea/src/native/pwntools/PwntoolsFailures.test.ts
T
morluto 08fbeb8bda fix(pwntools): preserve producer cancellation outcomes
Keep opaque reasons at admission, queued work, command/file projection and
successful final cleanup. Normalize Node's ABORT_ERR envelope only at the
snapshot write API that produced it, using the verified original cause.
Remove downstream signal/name/identity guesses in decoder and debugger
catches, including reply-close and path-probe handling.

The initial regressions failed 15 cases with seven controls passing.
The complete final series passes 68 focused tests, static checks, docs and
discovery. Real owned Node/file fixtures use the actual macOS inspector;
only the Linux x64 availability gate is simulated. No native pwntools or
GDB qualification or performance improvement is claimed.

Refs #4945
2026-10-18 10:51:50 +08:00

44 lines
1.5 KiB
TypeScript

import { expect, it } from "vitest";
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
import { OwnedCommandFailure } from "../../process/OwnedCommand.js";
import { pwntoolsDecoderFailure } from "./PwntoolsFailures.js";
it.each([undefined, null, false, 0, "stop", { stop: true }, new Error("stop")])(
"preserves opaque cancellation from command and artifact owners: %s",
(reason) => {
for (const failure of [
new OwnedCommandFailure("cancelled", "cancelled", null, null, {
cause: new Error("transport wrapper"),
cancellation: { reason },
}),
new ArtifactReaderFailure("cancelled", "cancelled", {
cause: new Error("file wrapper"),
cancellation: { reason },
}),
]) {
const result = pwntoolsDecoderFailure(failure, "decoder", "/selected");
expect(result._tag).toBe("AnalysisCancelledError");
expect(result.cause).toBe(reason);
expect(Object.hasOwn(result, "cause")).toBe(true);
}
},
);
it("retains legacy owner causes without guessing cancellation from error text", () => {
const reason = { stop: "legacy" };
const result = pwntoolsDecoderFailure(
new OwnedCommandFailure("cancelled", "cancelled", null, null, {
cause: reason,
}),
"decoder",
"/selected",
);
expect(result.cause).toBe(reason);
const physical = Object.assign(new Error("physical failure"), {
name: "AbortError",
});
expect(pwntoolsDecoderFailure(physical, "decoder", "/selected")._tag).toBe(
"ProviderAdapterError",
);
});