Files
reverse-engineering-anything/src/application/LinuxHopperPublisher.test.ts
T
morlutoandCursor Agent 67f74c5fb9 fix(setup): retain Hopper operation failure attribution (#9958)
* fix(setup): retain Hopper operation failure attribution

* fix(setup): retain falsy Hopper abort reasons from body reads

After response headers, Node's fetch body reader rejects a null, false,
0, or empty-string abort with a fresh AbortError instead of that reason.
Replace that substituted error with the caller's reason. A body
AbortError while the caller has not aborted still propagates.

* fix(setup): preserve independent response body aborts

* fix(setup): identify aborts through owned transport

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-11-11 17:28:23 +08:00

51 lines
1.8 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
import { ExecFileOutputCancelledError } from "../process/ExecFileOutput.js";
import { LinuxHopperPublisher } from "./LinuxHopperPublisher.js";
it.each(["physical", "caller", "node-wrapper", "producer"] as const)(
"attributes package-family observation failure after hashing (%s)",
async (kind) => {
const root = await createTestTempDirectory("rea-publisher-cancellation-");
const path = join(root, "inert-launcher");
await writeFile(path, "inert launcher bytes");
const controller = new AbortController();
const reason = { caller: "stop inspection" };
const physical = new Error("distribution inspection failed");
const wrapped = Object.assign(
new Error("operation aborted", { cause: reason }),
{
name: "AbortError",
code: "ABORT_ERR",
},
);
const publisher = new LinuxHopperPublisher({ HOME: root }, async () => {
if (kind !== "producer") controller.abort(reason);
throw kind === "physical"
? physical
: kind === "caller"
? reason
: kind === "node-wrapper"
? wrapped
: new ExecFileOutputCancelledError(reason);
});
try {
const result = await publisher.inspectLauncher(path, controller.signal);
expect(result).toMatchObject({
ok: false,
error: {
reason:
kind === "physical" ? "verification_unavailable" : "cancelled",
},
});
if (result.ok) throw new Error("Expected failed observation");
expect(result.error.cause).toBe(kind === "physical" ? physical : reason);
} finally {
await publisher.close();
}
},
);