mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
test(macos-pkg): share unknown coverage expectations (#17272)
This commit is contained in:
@@ -75,6 +75,13 @@ import {
|
||||
parseCpioOdcPrefix,
|
||||
} from "./macosPkg/CpioOdc.js";
|
||||
|
||||
const unknownCoverage = (limitations?: unknown) => [
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
...(limitations === undefined ? {} : { limitations }),
|
||||
}),
|
||||
];
|
||||
|
||||
const writePkg = (name: string, bytes: Buffer): Promise<string> =>
|
||||
createTestTempFile("rea-macos-pkg-", name, bytes);
|
||||
|
||||
@@ -353,7 +360,7 @@ it("retains known files and reports ambiguous reused-inode aliases as unavailabl
|
||||
}),
|
||||
);
|
||||
try {
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
for (const path of ["._ordinary", "base", "._alias"]) {
|
||||
const entry = entries.find((item) => item.path === `Payload/${path}`)!;
|
||||
expect(entry.declaredSize).toBeNull();
|
||||
@@ -596,7 +603,7 @@ it("refuses pbzx payload expansion while keeping PackageInfo and Scripts", async
|
||||
buildPbzxPayloadPackage(),
|
||||
);
|
||||
try {
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
const metadata = reader.formatMetadata();
|
||||
expect(metadata?.payload).toMatchObject({
|
||||
present: true,
|
||||
@@ -630,7 +637,7 @@ it("keeps a truncated xar header as a typed refusal", async () => {
|
||||
expect(reader.formatMetadata()?.refusals).toEqual([
|
||||
expect.objectContaining({ code: "truncated-header" }),
|
||||
]);
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -668,7 +675,7 @@ it("keeps other members when a heap range is out of bounds", async () => {
|
||||
"heap-oob.pkg",
|
||||
);
|
||||
try {
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
expect(reader.formatMetadata()?.refusals).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ code: "heap-out-of-bounds" }),
|
||||
@@ -688,7 +695,7 @@ it("keeps PackageInfo when Payload cpio headers are garbage", async () => {
|
||||
"bad-cpio.pkg",
|
||||
);
|
||||
try {
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
expect(reader.formatMetadata()?.refusals).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ code: "cpio-malformed" }),
|
||||
@@ -730,7 +737,7 @@ it("keeps members read before a damaged cpio tail next to the refusal", async ()
|
||||
}),
|
||||
]);
|
||||
expect(entries.map((entry) => entry.path)).toContain("Scripts/preinstall");
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -788,9 +795,7 @@ it.each([
|
||||
),
|
||||
}),
|
||||
]);
|
||||
expect(coverage).toEqual([
|
||||
expect.objectContaining({ status: "unknown" }),
|
||||
]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -839,9 +844,7 @@ it.each([
|
||||
),
|
||||
}),
|
||||
]);
|
||||
expect(coverage).toEqual([
|
||||
expect.objectContaining({ status: "unknown" }),
|
||||
]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -868,14 +871,13 @@ it("records a cpio name refusal even when it matches the remaining budget", asyn
|
||||
message: expect.stringContaining("namesize 0"),
|
||||
}),
|
||||
]);
|
||||
expect(coverage).toEqual([
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
limitations: expect.not.arrayContaining([
|
||||
expect(coverage).toEqual(
|
||||
unknownCoverage(
|
||||
expect.not.arrayContaining([
|
||||
expect.stringContaining("Did not expand Scripts/Payload"),
|
||||
]),
|
||||
}),
|
||||
]);
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -1106,14 +1108,13 @@ it("names skipped component archives when the expansion budget is exhausted", as
|
||||
1,
|
||||
);
|
||||
try {
|
||||
expect(coverage).toEqual([
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
limitations: expect.arrayContaining([
|
||||
expect(coverage).toEqual(
|
||||
unknownCoverage(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("Did not expand Scripts/Payload for"),
|
||||
]),
|
||||
}),
|
||||
]);
|
||||
),
|
||||
);
|
||||
expect(coverage[0]).toMatchObject({
|
||||
limitations: expect.arrayContaining([
|
||||
expect.stringMatching(/A\.pkg\/Scripts.*B\.pkg\/Payload/s),
|
||||
@@ -1165,16 +1166,11 @@ it("admits zlib XAR members in TOC order within one expansion allowance", async
|
||||
await expect(reader.open(second)).rejects.toBeInstanceOf(
|
||||
ArtifactEntryContentUnavailable,
|
||||
);
|
||||
expect(coverage).toEqual([
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
limitations: [
|
||||
expect.stringMatching(
|
||||
/second\.bin.*artifact_limits\.expanded_bytes/u,
|
||||
),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
expect(coverage).toEqual(
|
||||
unknownCoverage([
|
||||
expect.stringMatching(/second\.bin.*artifact_limits\.expanded_bytes/u),
|
||||
]),
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -1192,16 +1188,13 @@ it("charges decoded payload bytes against the shared expansion budget", async ()
|
||||
expect(paths).toContain("A.pkg/Payload/big.bin");
|
||||
expect(paths).not.toContain("B.pkg/Payload/big.bin");
|
||||
expect(paths).toContain("B.pkg/Payload");
|
||||
expect(coverage).toEqual([
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
limitations: [
|
||||
expect.stringMatching(
|
||||
/Did not expand Scripts\/Payload for B\.pkg\/Payload/u,
|
||||
),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
expect(coverage).toEqual(
|
||||
unknownCoverage([
|
||||
expect.stringMatching(
|
||||
/Did not expand Scripts\/Payload for B\.pkg\/Payload/u,
|
||||
),
|
||||
]),
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -1233,14 +1226,13 @@ it("charges cpio hard-link aliases against the expansion budget", async () => {
|
||||
expect(paths).toContain("Payload");
|
||||
expect(paths).not.toContain("Payload/original.bin");
|
||||
expect(paths).not.toContain("Payload/alias.bin");
|
||||
expect(skipped.coverage).toEqual([
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
limitations: expect.arrayContaining([
|
||||
expect(skipped.coverage).toEqual(
|
||||
unknownCoverage(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("Did not expand Scripts/Payload for Payload"),
|
||||
]),
|
||||
}),
|
||||
]);
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await skipped.reader.close();
|
||||
}
|
||||
@@ -1315,16 +1307,15 @@ it("lets admitted cpio aliases exhaust the budget for a later component", async
|
||||
expect(paths).toContain("A.pkg/Payload/alias.bin");
|
||||
expect(paths).toContain("B.pkg/Payload");
|
||||
expect(paths).not.toContain("B.pkg/Payload/big.bin");
|
||||
expect(coverage).toEqual([
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
limitations: expect.arrayContaining([
|
||||
expect(coverage).toEqual(
|
||||
unknownCoverage(
|
||||
expect.arrayContaining([
|
||||
expect.stringMatching(
|
||||
/Did not expand Scripts\/Payload for B\.pkg\/Payload/u,
|
||||
),
|
||||
]),
|
||||
}),
|
||||
]);
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -1609,7 +1600,7 @@ it("keeps a refusal from a cancelled preparation when another caller retries", a
|
||||
path: "A.pkg/PackageInfo",
|
||||
}),
|
||||
]);
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
expect(
|
||||
listed.filter((entry) => entry.path === "A.pkg/PackageInfo"),
|
||||
).toHaveLength(1);
|
||||
@@ -1830,14 +1821,11 @@ it("keeps intact PackageInfo, payload and signature when an unrelated TOC file r
|
||||
]),
|
||||
);
|
||||
expect(entries.map((entry) => entry.path)).not.toContain("damaged.bin");
|
||||
expect(coverage).toEqual([
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
limitations: expect.arrayContaining([
|
||||
expect.stringContaining("<size>"),
|
||||
]),
|
||||
}),
|
||||
]);
|
||||
expect(coverage).toEqual(
|
||||
unknownCoverage(
|
||||
expect.arrayContaining([expect.stringContaining("<size>")]),
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -1959,7 +1947,7 @@ it("enforces a package-wide cpio member cap across multiple Payload archives", a
|
||||
const paths = entries.map((entry) => entry.path);
|
||||
expect(paths).toContain("C.pkg/Payload");
|
||||
expect(paths.some((path) => path.startsWith("C.pkg/Payload/"))).toBe(false);
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -2011,7 +1999,7 @@ it("refuses non-UTF-8 cpio member names strictly without lossy replacement colli
|
||||
path: "Payload",
|
||||
}),
|
||||
]);
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -2096,7 +2084,7 @@ it("refuses an ordinary stored XAR member whose TOC size disagrees with its arch
|
||||
path: "Resources/note.txt",
|
||||
}),
|
||||
]);
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
const note = entries.find((entry) => entry.path === "Resources/note.txt");
|
||||
expect(note).toBeDefined();
|
||||
await expect(reader.open(note!)).rejects.toBeInstanceOf(
|
||||
@@ -2180,7 +2168,7 @@ it("bounds total installer metadata bytes when many PackageInfo TOC records alia
|
||||
expect(vi.mocked(inflateXarMemberBytes)).toHaveBeenCalledTimes(
|
||||
expectedAdmitted,
|
||||
);
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -2212,7 +2200,7 @@ it("bounds total retained bundle records across aliased PackageInfo entries and
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(coverage).toEqual([expect.objectContaining({ status: "unknown" })]);
|
||||
expect(coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
@@ -2237,9 +2225,7 @@ it("bounds total retained bundle records across aliased PackageInfo entries and
|
||||
expect(vi.mocked(inflateXarMemberBytes)).toHaveBeenCalledTimes(
|
||||
Math.floor(MACOS_PKG_MAX_TOTAL_METADATA_XML_BYTES / oneMibBundles.length),
|
||||
);
|
||||
expect(dense.coverage).toEqual([
|
||||
expect.objectContaining({ status: "unknown" }),
|
||||
]);
|
||||
expect(dense.coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await dense.reader.close();
|
||||
}
|
||||
@@ -2266,9 +2252,7 @@ it("raises installer metadata byte, record, and XML-node allowances when artifac
|
||||
refusal.message.includes("artifact_limits.expanded_bytes"),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(defaulted.coverage).toEqual([
|
||||
expect.objectContaining({ status: "unknown" }),
|
||||
]);
|
||||
expect(defaulted.coverage).toEqual(unknownCoverage());
|
||||
} finally {
|
||||
await defaulted.reader.close();
|
||||
}
|
||||
@@ -2357,14 +2341,13 @@ it("charges stored PackageInfo reads against the shared artifact_limits.expanded
|
||||
expect.objectContaining({ identifier: "com.rea.shared" }),
|
||||
]);
|
||||
expect(entries.map((entry) => entry.path)).not.toContain("Payload/big.bin");
|
||||
expect(coverage).toEqual([
|
||||
expect.objectContaining({
|
||||
status: "unknown",
|
||||
limitations: expect.arrayContaining([
|
||||
expect(coverage).toEqual(
|
||||
unknownCoverage(
|
||||
expect.arrayContaining([
|
||||
expect.stringContaining("Did not expand Scripts/Payload for Payload"),
|
||||
]),
|
||||
}),
|
||||
]);
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user