test(media): share coverage limitation assertions (#17367)

This commit is contained in:
Vincent Koc
2026-12-06 11:03:23 +08:00
committed by GitHub
parent bde0d92822
commit ee102492d1
@@ -42,6 +42,15 @@ const read = async (
return readArtifactEntries(reader);
};
const expectCoverageLimitation = (
result: Awaited<ReturnType<typeof read>>,
text: string,
) => {
expect(
result.coverage[0]?.limitations.some((line) => line.includes(text)),
).toBe(true);
};
describe("media asset recognition", () => {
it.each([
["ogg-opus", oggOpusFixture()],
@@ -325,11 +334,7 @@ describe("Ogg Opus headers", () => {
serials: [0x1234, 0x9999, 0x1234],
pages_read: 3,
});
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("belong to other logical streams"),
),
).toBe(true);
expectCoverageLimitation(result, "belong to other logical streams");
});
it("reports an OpusTags vendor that is not UTF-8 instead of dropping it silently", async () => {
@@ -339,11 +344,7 @@ describe("Ogg Opus headers", () => {
]);
const result = await read("ogg-opus", bytes);
expect(result.metadata).toMatchObject({ vendor: null });
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("not valid UTF-8"),
),
).toBe(true);
expectCoverageLimitation(result, "not valid UTF-8");
});
it("reports an OpusHead page without the beginning-of-stream flag", async () => {
@@ -352,11 +353,7 @@ describe("Ogg Opus headers", () => {
oggPage(1, 0n, opusTagsPacket(Buffer.from("enc")), 0),
]);
const result = await read("ogg-opus", bytes);
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("beginning-of-stream flag"),
),
).toBe(true);
expectCoverageLimitation(result, "beginning-of-stream flag");
});
});
@@ -461,11 +458,7 @@ describe("RIFF XMA2 headers", () => {
"chunks/0.fmt",
"chunks/1.data",
]);
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("follow the last declared"),
),
).toBe(true);
expectCoverageLimitation(result, "follow the last declared");
});
it("treats a partial trailing chunk header inside the RIFF form as incomplete", async () => {
@@ -480,11 +473,7 @@ describe("RIFF XMA2 headers", () => {
chunks: [{ id: "fmt ", offset: 20, length: 52 }],
});
expect(result.coverage[0]?.status).toBe("unknown");
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("partial RIFF chunk header"),
),
).toBe(true);
expectCoverageLimitation(result, "partial RIFF chunk header");
});
});
@@ -509,11 +498,7 @@ describe("RIFF chunk framing", () => {
expect(
result.contents.get("chunks/1.data")?.equals(Buffer.from([1, 2, 3])),
).toBe(true);
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("without its pad byte"),
),
).toBe(true);
expectCoverageLimitation(result, "without its pad byte");
});
it("names a chunk with a non-alphanumeric FourCC by index, keeping its ID", async () => {
@@ -702,11 +687,7 @@ describe("Bink 2 headers", () => {
});
expect(result.entries).toEqual([]);
expect(result.coverage[0]?.status).toBe("unknown");
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("header tables end at offset"),
),
).toBe(true);
expectCoverageLimitation(result, "header tables end at offset");
});
it("does not treat bytes past the declared end as audio track facts", async () => {
@@ -737,11 +718,7 @@ describe("Bink 2 headers", () => {
});
expect(result.entries).toEqual([]);
expect(result.coverage[0]?.status).toBe("unknown");
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("audio track tables end at offset"),
),
).toBe(true);
expectCoverageLimitation(result, "audio track tables end at offset");
});
it("does not claim trailing bytes beyond the declared end as frames", async () => {
@@ -773,11 +750,7 @@ describe("Bink 2 headers", () => {
expect(result.contents.get("frames.bin")).toEqual(
base.subarray(framesOffset),
);
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("follow the last declared"),
),
).toBe(true);
expectCoverageLimitation(result, "follow the last declared");
});
it("reports a cut-off Bink 2 header as truncated rather than malformed", async () => {
@@ -893,11 +866,7 @@ describe("incomplete media asset headers", () => {
const result = await read("ogg-opus", bytes);
expect(result.metadata).toMatchObject({ extent_check: "truncated" });
expect(result.coverage[0]?.status).toBe("unknown");
expect(
result.coverage[0]?.limitations.some((line) =>
line.includes("before the OpusTags packet"),
),
).toBe(true);
expectCoverageLimitation(result, "before the OpusTags packet");
});
it.each([