import { rename, symlink, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { expect, it } from "vitest"; import { readStableArtifact } from "../../../src/artifacts/readStableArtifact.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; it("reads exact binary and empty bytes and rejects symlink/size/cancellation boundaries", async () => { const root = await createTestTempDirectory("rea-stable-artifact-"); const path = join(root, "source.bin"); await writeFile(path, Buffer.from([0, 255, 254])); expect((await readStableArtifact(path, 3)).bytes).toEqual( Buffer.from([0, 255, 254]), ); await expect(readStableArtifact(path, 2)).rejects.toMatchObject({ reason: "limit", }); await writeFile(path, ""); expect((await readStableArtifact(path, 0)).bytes.length).toBe(0); const real = join(root, "original.bin"); await rename(path, real); await symlink(real, path); await expect(readStableArtifact(path, 3)).rejects.toMatchObject({ reason: "path", }); const controller = new AbortController(); controller.abort(); await expect(readStableArtifact(real, 3, controller.signal)).rejects.toBe( controller.signal.reason, ); });