mirror of
https://github.com/morluto/rea.git
synced 2026-11-05 06:15:59 +00:00
Use completed codec input to establish legacy CCOB extents, preserving declaration/integrity failures independently. Reuse bounded input windows, charge actual reads and decoding attempts, and qualify recovery after incomplete decoding. Publish only established or qualified terminal extents so interruption retains completed declarations. Recognize bitcode representation in HIP bundles while leaving inner facts unsupported. Fixes #6887 Fixes #6880
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { deflateSync, zstdCompressSync } from "node:zlib";
|
|
import { decodeGpuPayload, decodeGpuPayloadStream } from "./GpuPayloadCodec.js";
|
|
it.each(["zlib", "zstd"] as const)(
|
|
"requires all declared %s input bytes to belong to the codec stream",
|
|
async (codec) => {
|
|
const source = Buffer.from("kernel"),
|
|
encode = codec === "zstd" ? zstdCompressSync : deflateSync,
|
|
compressed = encode(source);
|
|
expect(await decodeGpuPayload(compressed, codec, source.length)).toEqual(
|
|
source,
|
|
);
|
|
await expect(
|
|
decodeGpuPayload(
|
|
Buffer.concat([compressed, Buffer.from("junk")]),
|
|
codec,
|
|
source.length,
|
|
),
|
|
).rejects.toMatchObject({ kind: "malformed" });
|
|
},
|
|
);
|
|
it.each(["zlib", "zstd"] as const)(
|
|
"retains completed %s input accounting before trailing container bytes",
|
|
async (codec) => {
|
|
const source = Buffer.from("ordinary CCOB marker"),
|
|
compressed =
|
|
codec === "zstd"
|
|
? zstdCompressSync(source)
|
|
: deflateSync(source, { level: 0 }),
|
|
input = Buffer.concat([
|
|
compressed,
|
|
Buffer.from("CCOB following container"),
|
|
]);
|
|
expect(await decodeGpuPayloadStream(input, codec, source.length)).toEqual({
|
|
buffer: source,
|
|
consumedBytes: compressed.length,
|
|
});
|
|
await expect(
|
|
decodeGpuPayloadStream(compressed.subarray(0, -1), codec, source.length),
|
|
).rejects.toMatchObject({ kind: "malformed" });
|
|
await expect(
|
|
decodeGpuPayload(compressed, codec, source.length + 1),
|
|
).rejects.toMatchObject({ kind: "malformed" });
|
|
},
|
|
);
|