test(managed): share available metadata heap fixtures (#16289)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-03 08:40:27 +00:00
1 parent bf7646b0c7
commit 2f69bbd442
1 file changed
+14 -35
+14 -35
View File
@@ -11,6 +11,13 @@ import {
type ManagedMetadataLayout,
} from "./managedMetadataLayout.js";
const availableHeap = (name: string, size: number) =>
({
kind: "available",
stream: { name, offset: 0, size },
issue: null,
}) satisfies ManagedMetadataLayout["strings"];
describe("managed metadata heap entries", () => {
it("admits a metadata root that omits its empty #Blob stream", () => {
const bytes = Buffer.alloc(108);
@@ -90,21 +97,9 @@ describe("managed metadata heap entries", () => {
size: bytes.length,
version: "",
streamNames: ["#Blob"],
strings: {
kind: "available",
stream: { name: "#Strings", offset: 0, size: 0 },
issue: null,
},
guid: {
kind: "available",
stream: { name: "#GUID", offset: 0, size: 0 },
issue: null,
},
blob: {
kind: "available",
stream: { name: "#Blob", offset: 0, size: bytes.length },
issue: null,
},
strings: availableHeap("#Strings", 0),
guid: availableHeap("#GUID", 0),
blob: availableHeap("#Blob", bytes.length),
userStrings: null,
tables: new Map(),
rowCounts: [],
@@ -122,11 +117,7 @@ describe("managed metadata heap entries", () => {
it("requires a compressed blob length prefix to fit inside #Blob", () => {
const bytes = Buffer.from([0, 0x80, 0, 0]);
const layout = {
blob: {
kind: "available",
stream: { name: "#Blob", offset: 0, size: 2 },
issue: null,
},
blob: availableHeap("#Blob", 2),
} as unknown as ManagedMetadataLayout;
expect(() => readMetadataBlob(bytes, layout, 1)).toThrow(
expect.objectContaining({
@@ -146,11 +137,7 @@ describe("managed metadata heap entries", () => {
// #US ends at the end of the artifact, inside a multi-byte length prefix.
const bytes = Buffer.from([0x00, ...prefix]);
const layout = {
userStrings: {
kind: "available",
stream: { name: "#US", offset: 0, size: bytes.length },
issue: null,
},
userStrings: availableHeap("#US", bytes.length),
} as unknown as ManagedMetadataLayout;
expect(() =>
@@ -177,16 +164,8 @@ it("does not re-charge the decode budget on metadata string cache hits", () => {
size: strBytes.length,
version: "",
streamNames: ["#Strings"],
strings: {
kind: "available",
stream: { name: "#Strings", offset: 0, size: strBytes.length },
issue: null,
},
guid: {
kind: "available",
stream: { name: "#GUID", offset: 0, size: 0 },
issue: null,
},
strings: availableHeap("#Strings", strBytes.length),
guid: availableHeap("#GUID", 0),
blob: null,
userStrings: null,
tables: new Map(),