test(firmware): share the short positional read fixture (#16953)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 13:22:51 +08:00
1 parent 47443f4c64
commit 2ddfb362ff
3 files changed
+35 -56

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import { lstat, open, realpath } from "node:fs/promises";
import type { StableArtifactFileSystem } from "../../src/resources/readStableArtifact.js";
export const shortReadAfterStreamFileSystem = (): StableArtifactFileSystem => ({
lstat: (path) => lstat(path, { bigint: true }),
realpath,
open: async (path, flags, mode) => {
const handle = await open(path, flags, mode);
const originalRead = handle.read.bind(handle);
let streamed = false;
handle.read = (async (
buffer: Buffer,
bufOffset?: number | null,
length?: number | null,
position?: number | bigint | null,
) => {
const res = await originalRead(
buffer,
bufOffset ?? 0,
length ?? buffer.length,
position ?? null,
);
if (res.bytesRead === 0) streamed = true;
else if (streamed && typeof position === "number" && position > 0) {
return { bytesRead: 0, buffer };
}
return res;
}) as typeof handle.read;
return handle;
},
});