Files
rea/src/artifacts/AsarEntryStream.test.ts
T
morluto 542fa84957 fix(artifacts): retain descriptor ownership and read completion facts
Refs #4458, #4483.

Own admitted descriptors through final close, retain exact failed owners, and preserve physical read failures and cancellation reasons. Track stream coverage independently from delivered bytes and share the boundary across archive, Mach-O, hashing, and output readback consumers.
2026-10-17 00:44:02 +08:00

44 lines
1.5 KiB
TypeScript

import type { FileHandle } from "node:fs/promises";
import { expect, it } from "vitest";
import { readArtifactFileChunks } from "./readArtifactFileChunks.js";
import { readValidatedAsarEntry } from "./AsarEntryStream.js";
it.each(["complete", "truncated"])(
"preserves %s source facts when output is cancelled after physical EOF",
async (kind) => {
const controller = new AbortController();
const bytes = Buffer.from("ASAR member");
let delivered = false;
const read = (async (target: Buffer) => {
if (delivered) return { bytesRead: 0, buffer: target };
delivered = true;
bytes.copy(target);
return { bytesRead: bytes.length, buffer: target };
}) as FileHandle["read"];
const source = readArtifactFileChunks(
{ read },
{ signal: controller.signal },
);
const output = readValidatedAsarEntry(
source,
bytes.length + (kind === "truncated" ? 1 : 0),
"member",
"/fixture/archive.asar",
controller.signal,
);
const failed = new Promise<Error>((resolve) =>
output.once("error", resolve),
);
output.read(0);
await expect.poll(() => source.readCoverage().kind).toBe("complete");
expect(output.readableLength).toBeGreaterThan(0);
expect(output.readableEnded).toBe(false);
controller.abort(null);
await expect(failed).resolves.toMatchObject(
kind === "complete"
? { reason: "cancelled", cancellation: { reason: null } }
: { reason: "integrity" },
);
},
);