mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
test(model): share model header fixture reads (#15929)
This commit is contained in:
1 parent
d472a9e3cb
commit
911cbf9142
1 file changed
+74
-106
@@ -49,6 +49,13 @@ const providerAt = async (bytes: Buffer) => {
|
||||
return { provider, ...fixture };
|
||||
};
|
||||
|
||||
const readFixtureHeader = async (bytes: Buffer) => {
|
||||
const { provider, path } = await providerAt(bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
return result.value;
|
||||
};
|
||||
|
||||
it("refuses a missing model file as the shared selected-file input refusal", async () => {
|
||||
const root = await createTestTempDirectory("rea-model-missing-");
|
||||
const provider = new ModelArtifactProvider();
|
||||
@@ -97,16 +104,9 @@ it.each([
|
||||
);
|
||||
|
||||
it("continues reading little-endian GGUF v2 declarations", async () => {
|
||||
const { provider, path } = await providerAt(
|
||||
ggufFixture({ version: 2 }).bytes,
|
||||
);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value).toMatchObject({ version: 2, byte_order: "little" });
|
||||
expect(result.value.tensors.map(({ name }) => name)).toEqual([
|
||||
"weight",
|
||||
"quant",
|
||||
]);
|
||||
const report = await readFixtureHeader(ggufFixture({ version: 2 }).bytes);
|
||||
expect(report).toMatchObject({ version: 2, byte_order: "little" });
|
||||
expect(report.tensors.map(({ name }) => name)).toEqual(["weight", "quant"]);
|
||||
});
|
||||
|
||||
it("continues refusing the unsupported big-endian GGUF v2 layout", async () => {
|
||||
@@ -205,18 +205,14 @@ it.each([false, true])(
|
||||
{ name: "scalar", type: 0, shape: [], offset: 0n, bytes: 4 },
|
||||
];
|
||||
const fixture = ggufFixture({ bigEndian, tensors: declarations });
|
||||
const { provider, path } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(
|
||||
result.value.tensors.map(
|
||||
({ name, shape, byte_length, parameter_count }) => ({
|
||||
name,
|
||||
shape,
|
||||
byte_length,
|
||||
parameter_count,
|
||||
}),
|
||||
),
|
||||
report.tensors.map(({ name, shape, byte_length, parameter_count }) => ({
|
||||
name,
|
||||
shape,
|
||||
byte_length,
|
||||
parameter_count,
|
||||
})),
|
||||
).toEqual(
|
||||
declarations.map(({ name, shape, bytes }) => ({
|
||||
name,
|
||||
@@ -225,11 +221,11 @@ it.each([false, true])(
|
||||
parameter_count: name === "scalar" ? "1" : "0",
|
||||
})),
|
||||
);
|
||||
expect(result.value.totals).toMatchObject({
|
||||
expect(report.totals).toMatchObject({
|
||||
parameter_count: "1",
|
||||
tensor_bytes: 4,
|
||||
});
|
||||
expect(result.value.artifact.bytes_read).toBe(fixture.header.length);
|
||||
expect(report.artifact.bytes_read).toBe(fixture.header.length);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -254,15 +250,13 @@ it.each([8, 24, 40])(
|
||||
"accepts format-valid GGUF alignment %s and preserves exact offsets",
|
||||
async (alignment) => {
|
||||
const fixture = ggufFixture({ alignment });
|
||||
const { path, provider } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.alignment).toBe(alignment);
|
||||
expect(result.value.tensor_data_offset).toBe(fixture.dataOffset);
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.alignment).toBe(alignment);
|
||||
expect(report.tensor_data_offset).toBe(fixture.dataOffset);
|
||||
expect(
|
||||
result.value.tensors.every((row) => row.file_offset % alignment === 0),
|
||||
report.tensors.every((row) => row.file_offset % alignment === 0),
|
||||
).toBe(true);
|
||||
expect(result.value.tensors[1]?.file_offset).toBe(
|
||||
expect(report.tensors[1]?.file_offset).toBe(
|
||||
fixture.dataOffset + Math.ceil(16 / alignment) * alignment,
|
||||
);
|
||||
},
|
||||
@@ -275,12 +269,10 @@ it("aligns the GGUF data section after an empty tensor directory", async () => {
|
||||
base.header,
|
||||
Buffer.alloc(dataOffset - base.header.length),
|
||||
]);
|
||||
const { path, provider } = await providerAt(bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.tensors).toEqual([]);
|
||||
expect(result.value.tensor_data_offset).toBe(dataOffset);
|
||||
expect(result.value.artifact.header_length).toBe(base.header.length);
|
||||
const report = await readFixtureHeader(bytes);
|
||||
expect(report.tensors).toEqual([]);
|
||||
expect(report.tensor_data_offset).toBe(dataOffset);
|
||||
expect(report.artifact.header_length).toBe(base.header.length);
|
||||
});
|
||||
|
||||
it.each([0, 1, 2, 4, 12])(
|
||||
@@ -333,10 +325,8 @@ it("accepts standardized GGUF metadata keys containing numeric hierarchy compone
|
||||
{ key: "general.base_model.0.name", type: 8, value: base.text("parent") },
|
||||
],
|
||||
});
|
||||
const { path, provider } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.metadata[0]).toMatchObject({
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.metadata[0]).toMatchObject({
|
||||
key: "general.base_model.0.name",
|
||||
value: "parent",
|
||||
});
|
||||
@@ -507,17 +497,15 @@ it("returns unknown lengths for unknown GGUF types without inventing storage siz
|
||||
const fixture = ggufFixture({
|
||||
tensors: [{ name: "future", type: 999, shape: [1n], offset: 0n, bytes: 1 }],
|
||||
});
|
||||
const { provider, path } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.tensors[0]).toMatchObject({
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.tensors[0]).toMatchObject({
|
||||
type_id: 999,
|
||||
type: "UNKNOWN_999",
|
||||
byte_length: null,
|
||||
byte_length_state: "unknown",
|
||||
});
|
||||
expect(result.value.coverage.tensor_ranges).toBe("partial");
|
||||
expect(result.value.totals.tensor_bytes).toBeNull();
|
||||
expect(report.coverage.tensor_ranges).toBe("partial");
|
||||
expect(report.totals.tensor_bytes).toBeNull();
|
||||
});
|
||||
|
||||
it.each([
|
||||
@@ -548,12 +536,10 @@ it.each([
|
||||
},
|
||||
],
|
||||
});
|
||||
const { provider, path } = await providerAt(
|
||||
const report = await readFixtureHeader(
|
||||
Buffer.concat([fixture.bytes, Buffer.alloc(16)]),
|
||||
);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.tensors).toMatchObject([
|
||||
expect(report.tensors).toMatchObject([
|
||||
{ name: "control", byte_length: 16, storage_validation: "consistent" },
|
||||
{
|
||||
name: "weight",
|
||||
@@ -568,7 +554,7 @@ it.each([
|
||||
storage_validation: "unknown",
|
||||
},
|
||||
]);
|
||||
expect(result.value.totals).toMatchObject({
|
||||
expect(report.totals).toMatchObject({
|
||||
parameter_count: "324",
|
||||
tensor_bytes: null,
|
||||
by_type: [
|
||||
@@ -576,18 +562,18 @@ it.each([
|
||||
{ type: "Q8_1", bytes: null, parameter_count: "320" },
|
||||
],
|
||||
});
|
||||
expect(result.value.coverage).toMatchObject({
|
||||
expect(report.coverage).toMatchObject({
|
||||
header: "complete",
|
||||
tensor_ranges: "partial",
|
||||
storage_sizes: "partial",
|
||||
});
|
||||
expect(result.value.limitations).toContainEqual(
|
||||
expect(report.limitations).toContainEqual(
|
||||
expect.stringContaining("Q8_1 has released 40-byte and 36-byte layouts"),
|
||||
);
|
||||
expect(result.value.limitations.join(" ")).not.toContain(
|
||||
expect(report.limitations.join(" ")).not.toContain(
|
||||
"Unknown tensor type Q8_1",
|
||||
);
|
||||
expect(result.value.artifact.bytes_read).toBe(fixture.header.length);
|
||||
expect(report.artifact.bytes_read).toBe(fixture.header.length);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -598,18 +584,16 @@ it("derives empty Q8_1 storage without choosing a historical block layout", asyn
|
||||
{ name: "empty", type: 9, shape: [32n, 0n], offset: 0n, bytes: 0 },
|
||||
],
|
||||
});
|
||||
const { provider, path } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.tensors[0]).toMatchObject({
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.tensors[0]).toMatchObject({
|
||||
type: "Q8_1",
|
||||
parameter_count: "0",
|
||||
byte_length: 0,
|
||||
byte_length_state: "derived",
|
||||
storage_validation: "consistent",
|
||||
});
|
||||
expect(result.value.totals.tensor_bytes).toBe(0);
|
||||
expect(result.value.coverage).toMatchObject({
|
||||
expect(report.totals.tensor_bytes).toBe(0);
|
||||
expect(report.coverage).toMatchObject({
|
||||
tensor_ranges: "complete",
|
||||
storage_sizes: "complete",
|
||||
});
|
||||
@@ -642,15 +626,13 @@ it.each(ggufKLayouts)(
|
||||
},
|
||||
],
|
||||
});
|
||||
const { provider, path } = await providerAt(
|
||||
const report = await readFixtureHeader(
|
||||
Buffer.concat([
|
||||
fixture.bytes,
|
||||
Buffer.alloc(Math.ceil(bytes / 32) * 32 - bytes),
|
||||
]),
|
||||
);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.tensors[0]).toMatchObject({
|
||||
expect(report.tensors[0]).toMatchObject({
|
||||
type: name,
|
||||
type_id: id,
|
||||
shape: [String(elements)],
|
||||
@@ -658,12 +640,12 @@ it.each(ggufKLayouts)(
|
||||
byte_length: null,
|
||||
storage_validation: "unknown",
|
||||
});
|
||||
expect(result.value.coverage).toMatchObject({
|
||||
expect(report.coverage).toMatchObject({
|
||||
tensor_ranges: "partial",
|
||||
storage_sizes: "partial",
|
||||
});
|
||||
expect(result.value.totals.tensor_bytes).toBeNull();
|
||||
expect(result.value.limitations).toContainEqual(
|
||||
expect(report.totals.tensor_bytes).toBeNull();
|
||||
expect(report.limitations).toContainEqual(
|
||||
expect.stringContaining("common 64-element row constraint"),
|
||||
);
|
||||
}
|
||||
@@ -709,10 +691,8 @@ it.each(ggufShiftedTypeLayouts)(
|
||||
},
|
||||
],
|
||||
});
|
||||
const { provider, path } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.tensors[0]).toMatchObject({
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.tensors[0]).toMatchObject({
|
||||
type: `AMBIGUOUS_${String(id)}`,
|
||||
type_id: id,
|
||||
shape: [String(elements)],
|
||||
@@ -720,11 +700,11 @@ it.each(ggufShiftedTypeLayouts)(
|
||||
byte_length: elements === 0 ? 0 : null,
|
||||
storage_validation: elements === 0 ? "consistent" : "unknown",
|
||||
});
|
||||
expect(result.value.limitations).toContainEqual(
|
||||
expect(report.limitations).toContainEqual(
|
||||
expect.stringContaining(`type ID ${String(id)} has released`),
|
||||
);
|
||||
expect(result.value.limitations.join(" ")).toContain(modernName);
|
||||
expect(result.value.totals.tensor_bytes).toBe(elements === 0 ? 0 : null);
|
||||
expect(report.limitations.join(" ")).toContain(modernName);
|
||||
expect(report.totals.tensor_bytes).toBe(elements === 0 ? 0 : null);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -741,10 +721,8 @@ it("retains established storage for stable GGUF types and zero-byte K declaratio
|
||||
{ name: "arm-8x8", type: 33, shape: [32n], offset: 224n, bytes: 18 },
|
||||
],
|
||||
});
|
||||
const { provider, path } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.tensors).toMatchObject([
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.tensors).toMatchObject([
|
||||
{ type: "I32", byte_length: 12, storage_validation: "consistent" },
|
||||
{ type: "Q2_K", byte_length: 0, storage_validation: "consistent" },
|
||||
{ type: "Q4_0", byte_length: 18, storage_validation: "consistent" },
|
||||
@@ -753,8 +731,8 @@ it("retains established storage for stable GGUF types and zero-byte K declaratio
|
||||
{ type: "Q4_0_4_8", byte_length: 18, storage_validation: "consistent" },
|
||||
{ type: "Q4_0_8_8", byte_length: 18, storage_validation: "consistent" },
|
||||
]);
|
||||
expect(result.value.totals.tensor_bytes).toBe(141);
|
||||
expect(result.value.coverage).toMatchObject({
|
||||
expect(report.totals.tensor_bytes).toBe(141);
|
||||
expect(report.coverage).toMatchObject({
|
||||
tensor_ranges: "complete",
|
||||
storage_sizes: "complete",
|
||||
});
|
||||
@@ -765,15 +743,13 @@ it("keeps unknown safetensors storage validation separate from observed valid by
|
||||
'{"future":{"dtype":"FUTURE4","shape":[2],"data_offsets":[0,4]}}',
|
||||
Buffer.alloc(4),
|
||||
);
|
||||
const { path, provider } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.tensors[0]).toMatchObject({
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.tensors[0]).toMatchObject({
|
||||
byte_length: 4,
|
||||
byte_length_state: "declared",
|
||||
storage_validation: "unknown",
|
||||
});
|
||||
expect(result.value.coverage).toMatchObject({
|
||||
expect(report.coverage).toMatchObject({
|
||||
tensor_ranges: "complete",
|
||||
storage_sizes: "partial",
|
||||
});
|
||||
@@ -829,10 +805,8 @@ it.each([false, true])(
|
||||
value,
|
||||
})),
|
||||
});
|
||||
const { path, provider } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.metadata.map((row) => [row.type, row.value])).toEqual(
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.metadata.map((row) => [row.type, row.value])).toEqual(
|
||||
rows.map(([, name, , expected]) => [name, expected]),
|
||||
);
|
||||
},
|
||||
@@ -847,10 +821,8 @@ it("preserves nonfinite floating metadata and negative zero without JSON coercio
|
||||
return { key: `custom.float_${String(index)}`, type: 12, value: b };
|
||||
}),
|
||||
});
|
||||
const { path, provider } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.metadata.map((row) => [row.type, row.value])).toEqual(
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.metadata.map((row) => [row.type, row.value])).toEqual(
|
||||
["NaN", "+Infinity", "-Infinity", "-0"].map((value) => ["FLOAT64", value]),
|
||||
);
|
||||
});
|
||||
@@ -902,20 +874,18 @@ it.each([false, true])(
|
||||
},
|
||||
],
|
||||
});
|
||||
const { path, provider } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.metadata[0]).toMatchObject({
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.metadata[0]).toMatchObject({
|
||||
value: preview,
|
||||
element_count: strings.length,
|
||||
preview_complete: false,
|
||||
});
|
||||
expect(result.value.coverage.array_values).toBe("partial");
|
||||
expect(result.value.artifact).toMatchObject({
|
||||
expect(report.coverage.array_values).toBe("partial");
|
||||
expect(report.artifact).toMatchObject({
|
||||
bytes_read: fixture.header.length,
|
||||
header_sha256: createHash("sha256").update(fixture.header).digest("hex"),
|
||||
});
|
||||
expect(result.value.tensors).toHaveLength(2);
|
||||
expect(report.tensors).toHaveLength(2);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1389,12 +1359,10 @@ it("accepts null safetensors metadata and ignores tensor extension fields", asyn
|
||||
'{"__metadata__":null,"weight":{"dtype":"F32","shape":[1],"data_offsets":[0,4],"note":{"source":"local","flags":[null,false,-1,1.25]}}}',
|
||||
Buffer.alloc(4),
|
||||
);
|
||||
const { provider, path } = await providerAt(fixture.bytes);
|
||||
const result = await provider.inspect({ path, hash: "header" });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.metadata).toEqual([]);
|
||||
const report = await readFixtureHeader(fixture.bytes);
|
||||
expect(report.metadata).toEqual([]);
|
||||
expect(
|
||||
result.value.tensors.map(({ name, type, shape }) => ({
|
||||
report.tensors.map(({ name, type, shape }) => ({
|
||||
name,
|
||||
type,
|
||||
shape,
|
||||
|
||||
Reference in new issue
Block a user