Files
reverse-engineering-anything/src/desktop/HostQuery.test.ts
T
morluto 0fead85457 fix(desktop): preserve exact dpkg ownership from partial queries (#12360)
* fix(desktop): preserve exact dpkg ownership from partial queries

* test(desktop): cover dpkg executable ownership transcripts

* test(desktop): keep executable ownership regression outside describe
2026-11-19 09:07:59 -05:00

46 lines
1.4 KiB
TypeScript

import { expect, it } from "vitest";
import { ArtifactReaderFailure } from "../resources/ArtifactReader.js";
import { runHostQuery } from "./HostQuery.js";
it("returns an inert Node query's actual output and status", async () => {
expect(
await runHostQuery(
process.execPath,
["-e", "process.stdout.write('query result')"],
undefined,
),
).toEqual({ stdout: "query result", exitCode: 0 });
});
it("retains raw stdout on a completed nonzero exit when requested", async () => {
const output = await runHostQuery(
process.execPath,
[
"-e",
"process.stdout.write(Buffer.from([0x61, 0xff])); process.exitCode = 1;",
],
undefined,
{ preserveStdoutBytes: true },
);
expect(output).toEqual({
stdout: "a�",
stdoutBuffer: Buffer.from([0x61, 0xff]),
exitCode: 1,
});
});
it("preserves cancellation recorded by the actual command owner", async () => {
const reason = new Error("caller cancelled host query");
const failure = await runHostQuery(
process.execPath,
["-e", "void 0"],
AbortSignal.abort(reason),
).catch((cause: unknown) => cause);
expect(failure).toBeInstanceOf(ArtifactReaderFailure);
expect(failure).toMatchObject({ reason: "cancelled", cause: reason });
if (!(failure instanceof ArtifactReaderFailure))
throw new Error("expected owner cancellation");
expect(failure.cause).toBe(reason);
});