mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
test(apple): share asset catalog fixture inputs (#17102)
This commit is contained in:
1 parent
ef161b00b0
commit
bc6f999b8b
1 file changed
+50
-93
@@ -38,6 +38,19 @@ import {
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
||||
|
||||
const analyzeFixtureCatalogs = (
|
||||
bundlePath: string,
|
||||
runAssetUtil: NonNullable<
|
||||
Parameters<typeof analyzeAppleAssetCatalogs>[0]["runAssetUtil"]
|
||||
>,
|
||||
) =>
|
||||
analyzeAppleAssetCatalogs({
|
||||
bundlePath,
|
||||
targetSha256: "a".repeat(64),
|
||||
environment: {},
|
||||
runAssetUtil,
|
||||
});
|
||||
|
||||
const noInterfaceBuilder = async () =>
|
||||
({
|
||||
graph: { nodes: [], truncated: false, coverage: [] },
|
||||
@@ -110,13 +123,8 @@ describe("Apple asset catalog traversal coverage", () => {
|
||||
Buffer.concat([Buffer.from(`${bundle}/`), Buffer.from([0xff])]),
|
||||
"unrepresented",
|
||||
);
|
||||
const result = await analyzeAppleAssetCatalogs({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
environment: {},
|
||||
runAssetUtil: async () => {
|
||||
throw new Error("no catalog was admitted");
|
||||
},
|
||||
const result = await analyzeFixtureCatalogs(bundle, async () => {
|
||||
throw new Error("no catalog was admitted");
|
||||
});
|
||||
expect(result.inventory_coverage).toEqual({
|
||||
scope: "container-entries",
|
||||
@@ -132,12 +140,7 @@ describe("Apple asset catalog traversal coverage", () => {
|
||||
it("keeps represented symlinks distinct from catalog-target inspection", async () => {
|
||||
const bundle = await createTestTempDirectory("rea-asset-subtree-");
|
||||
await symlink("unexamined", join(bundle, "Resources"));
|
||||
const result = await analyzeAppleAssetCatalogs({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
environment: {},
|
||||
runAssetUtil: async () => "[]",
|
||||
});
|
||||
const result = await analyzeFixtureCatalogs(bundle, async () => "[]");
|
||||
expect(result.inventory_coverage.status).toBe("complete");
|
||||
expect(result.catalog_coverage).toMatchObject({ status: "unknown" });
|
||||
expect(result.resource_key_coverage).toMatchObject({ status: "unknown" });
|
||||
@@ -243,12 +246,9 @@ describe("Apple asset catalog application workflow", () => {
|
||||
await mkdir(resources, { recursive: true });
|
||||
await writeFile(join(bundle, "outside.car"), "catalog");
|
||||
await symlink("../../outside.car", join(resources, "Assets.car"));
|
||||
const rejected = await analyzeAppleAssetCatalogs({
|
||||
environment: {},
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
runAssetUtil: () => Promise.resolve("[]"),
|
||||
}).catch((cause: unknown) => cause);
|
||||
const rejected = await analyzeFixtureCatalogs(bundle, () =>
|
||||
Promise.resolve("[]"),
|
||||
).catch((cause: unknown) => cause);
|
||||
expect(rejected).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(rejected).toMatchObject({
|
||||
reason: "path",
|
||||
@@ -264,12 +264,9 @@ describe("Apple asset catalog application workflow", () => {
|
||||
await mkdir(join(resources, "Nested"), { recursive: true });
|
||||
await writeFile(join(resources, "Assets.car"), "catalog");
|
||||
await symlink("../Assets.car", join(resources, "Nested", "Assets.car"));
|
||||
const result = await analyzeAppleAssetCatalogs({
|
||||
environment: {},
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
runAssetUtil: () => Promise.resolve("[]"),
|
||||
});
|
||||
const result = await analyzeFixtureCatalogs(bundle, () =>
|
||||
Promise.resolve("[]"),
|
||||
);
|
||||
expect(result.catalogs.map(({ path }) => path)).toEqual([
|
||||
"Contents/Resources/Assets.car",
|
||||
]);
|
||||
@@ -301,13 +298,8 @@ it.skipIf(process.platform === "win32")(
|
||||
}),
|
||||
);
|
||||
await symlink("Panel.data", join(resources, "Panel.nib"));
|
||||
const result = await analyzeAppleAssetCatalogs({
|
||||
bundlePath: bundle,
|
||||
environment: {},
|
||||
targetSha256: "a".repeat(64),
|
||||
runAssetUtil: () => {
|
||||
throw new Error("No catalog is present");
|
||||
},
|
||||
const result = await analyzeFixtureCatalogs(bundle, () => {
|
||||
throw new Error("No catalog is present");
|
||||
});
|
||||
expect(result.limitations).toContainEqual(
|
||||
expect.stringMatching(
|
||||
@@ -360,20 +352,16 @@ it.each([1, 2])(
|
||||
await writeFile(join(resources, "Panel.nib"), archive);
|
||||
await writeFile(join(resources, "Assets.car"), "inert catalog fixture");
|
||||
// Supplied metadata tests the post-engine join; it does not establish native catalog validity.
|
||||
const result = await analyzeAppleAssetCatalogs({
|
||||
environment: {},
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
runAssetUtil: () =>
|
||||
Promise.resolve(
|
||||
JSON.stringify(
|
||||
Array.from({ length: count }, (_, index) => ({
|
||||
Name: "Toolbar",
|
||||
RenditionName: `toolbar-${String(index)}.png`,
|
||||
})),
|
||||
),
|
||||
const result = await analyzeFixtureCatalogs(bundle, () =>
|
||||
Promise.resolve(
|
||||
JSON.stringify(
|
||||
Array.from({ length: count }, (_, index) => ({
|
||||
Name: "Toolbar",
|
||||
RenditionName: `toolbar-${String(index)}.png`,
|
||||
})),
|
||||
),
|
||||
});
|
||||
),
|
||||
);
|
||||
expect(result.resource_key_matches).toHaveLength(1);
|
||||
expect(result.resource_key_matches[0]).toMatchObject({
|
||||
field: "NSImageName",
|
||||
@@ -407,12 +395,9 @@ it("keeps recognized image fields on NIBArchive controls out of resource joins",
|
||||
}),
|
||||
);
|
||||
await writeFile(join(resources, "Assets.car"), "inert catalog fixture");
|
||||
const result = await analyzeAppleAssetCatalogs({
|
||||
environment: {},
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
runAssetUtil: () => Promise.resolve(JSON.stringify([{ Name: "Toolbar" }])),
|
||||
});
|
||||
const result = await analyzeFixtureCatalogs(bundle, () =>
|
||||
Promise.resolve(JSON.stringify([{ Name: "Toolbar" }])),
|
||||
);
|
||||
expect(result.resource_key_matches).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -789,12 +774,7 @@ it.each(["not json", "{}", "[null]"])(
|
||||
const bundle = await createTestTempDirectory("rea-asset-output-");
|
||||
await writeFile(join(bundle, "Assets.car"), "inert catalog");
|
||||
await expect(
|
||||
analyzeAppleAssetCatalogs({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
environment: {},
|
||||
runAssetUtil: async () => output,
|
||||
}),
|
||||
analyzeFixtureCatalogs(bundle, async () => output),
|
||||
).rejects.toMatchObject({
|
||||
_tag: "AnalysisOutputError",
|
||||
reason: expect.stringContaining("Assets.car"),
|
||||
@@ -818,13 +798,8 @@ it.each([
|
||||
signal: reason === "timeout" ? "SIGKILL" : null,
|
||||
});
|
||||
await expect(
|
||||
analyzeAppleAssetCatalogs({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
environment: {},
|
||||
runAssetUtil: async () => {
|
||||
throw cause;
|
||||
},
|
||||
analyzeFixtureCatalogs(bundle, async () => {
|
||||
throw cause;
|
||||
}),
|
||||
).rejects.toMatchObject({
|
||||
_tag: tag,
|
||||
@@ -872,14 +847,9 @@ it.each(["reported carutil", "tab-indented carutil", "observed assetutil"])(
|
||||
exitCode: 1,
|
||||
signal: null,
|
||||
});
|
||||
const error = await analyzeAppleAssetCatalogs({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
environment: {},
|
||||
runAssetUtil: async (selectedPath) => {
|
||||
if (selectedPath === path) throw cause;
|
||||
return "[]";
|
||||
},
|
||||
const error = await analyzeFixtureCatalogs(bundle, async (selectedPath) => {
|
||||
if (selectedPath === path) throw cause;
|
||||
return "[]";
|
||||
}).catch((failure: unknown) => failure);
|
||||
if (!(error instanceof AnalysisError)) throw error;
|
||||
expect(error.cause).toBe(cause);
|
||||
@@ -935,13 +905,8 @@ it.each([
|
||||
collectionFailure: scenario === "failed capture",
|
||||
});
|
||||
await expect(
|
||||
analyzeAppleAssetCatalogs({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
environment: {},
|
||||
runAssetUtil: async () => {
|
||||
throw cause;
|
||||
},
|
||||
analyzeFixtureCatalogs(bundle, async () => {
|
||||
throw cause;
|
||||
}),
|
||||
).rejects.toMatchObject({
|
||||
_tag: "AnalysisOutputError",
|
||||
@@ -972,12 +937,9 @@ it.each(["Toolbar", "MissingToolbar"])(
|
||||
}),
|
||||
);
|
||||
await writeFile(join(bundle, "Assets.car"), "inert catalog");
|
||||
const result = await analyzeAppleAssetCatalogs({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
environment: {},
|
||||
runAssetUtil: async () => JSON.stringify([{ Name: "Toolbar" }]),
|
||||
});
|
||||
const result = await analyzeFixtureCatalogs(bundle, async () =>
|
||||
JSON.stringify([{ Name: "Toolbar" }]),
|
||||
);
|
||||
expect(result.resource_key_matches).toMatchObject([
|
||||
{
|
||||
field: "NSResourceName",
|
||||
@@ -998,14 +960,9 @@ it("preserves every own JSON metadata field through catalog inspection and page
|
||||
// evidence that native assetutil emits these additional field names.
|
||||
const output =
|
||||
'[{"Name":"Toolbar","RenditionName":"Toolbar@2x","__proto__":{"Name":"metadata, not an inherited asset name"},"constructor":"retained constructor metadata","toString":false,"Unknown":{"__proto__":{"value":0}},"Empty":"","Zero":0,"Absent":null}]';
|
||||
const result = await analyzeAppleAssetCatalogs({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
environment: {},
|
||||
runAssetUtil: async (path) => {
|
||||
expect(path).toBe(join(bundle, "Assets.car"));
|
||||
return output;
|
||||
},
|
||||
const result = await analyzeFixtureCatalogs(bundle, async (path) => {
|
||||
expect(path).toBe(join(bundle, "Assets.car"));
|
||||
return output;
|
||||
});
|
||||
const expected: unknown = JSON.parse(output);
|
||||
expect(result.records.map(({ metadata }) => metadata)).toEqual(expected);
|
||||
|
||||
Reference in new issue
Block a user