Merge pull request #1226 from morluto/fix/keyed-archive-kind-refusal

fix(artifacts): report non-archive keyed-archive selections as unsupported targets
This commit is contained in:
Kaoru0822
2026-10-09 01:37:29 -07:00
committed by GitHub
3 changed files with 99 additions and 14 deletions
@@ -6,7 +6,12 @@ import { expect, it } from "vitest";
import { ArtifactReaderFailure } from "../../../src/artifacts/ArtifactReader.js";
import { inspectBundleKeyedArchive } from "../../../src/artifacts/apple/KeyedArchiveReader.js";
import { AnalysisInputError } from "../../../src/domain/analysisErrorCore.js";
import { AnalysisError } from "../../../src/domain/analysisErrorBase.js";
import {
AnalysisInputError,
AnalysisUnsupportedTargetError,
} from "../../../src/domain/analysisErrorCore.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const archive = build({
@@ -76,24 +81,62 @@ it("reports an absent named root with the archive's available roots", async () =
});
it.each([
["plain plist", Buffer.from(build({ plain: true })), "NSKeyedArchiver"],
[
"plain plist",
Buffer.from(build({ plain: true })),
"it has no $archiver key",
"inspect_plist",
],
[
"plist with another archiver",
Buffer.from(build({ $archiver: "NSArchiver", $objects: [] })),
'its $archiver is "NSArchiver"',
"inspect_plist",
],
[
"compiled NIBArchive",
Buffer.concat([Buffer.from("NIBArchive"), Buffer.alloc(40)]),
"compiled NIBArchive",
"decode_interface_builder",
],
])(
"keeps the decoder reason for a selected %s",
async (_label, bytes, detail) => {
"reports a selected %s as an unsupported target with the workflow that reads it",
async (_label, bytes, reason, workflow) => {
const root = await bundle();
await writeFile(join(root, "Contents", "Resources", "Other.nib"), bytes);
const rejected = await inspect(root, {
path: "Contents/Resources/Other.nib",
}).catch((cause: unknown) => cause);
expect(rejected).toBeInstanceOf(ArtifactReaderFailure);
expect(rejected).toMatchObject({
reason: "format",
message: expect.stringContaining(detail),
expect(rejected).toBeInstanceOf(AnalysisUnsupportedTargetError);
expect(projectAnalysisError(asAnalysisError(rejected))).toMatchObject({
code: "unsupported_target",
message: expect.stringContaining(reason),
remediation: { action: expect.stringContaining(workflow) },
details: {
operation: "inspect_keyed_archive",
path: join(root, "Contents", "Resources", "Other.nib"),
},
});
},
);
it("keeps a damaged NSKeyedArchiver archive a format failure", async () => {
const root = await bundle();
await writeFile(
join(root, "Contents", "Resources", "Damaged.plist"),
Buffer.from(build({ $archiver: "NSKeyedArchiver", $top: {} })),
);
const rejected = await inspect(root, {
path: "Contents/Resources/Damaged.plist",
}).catch((cause: unknown) => cause);
expect(rejected).toBeInstanceOf(ArtifactReaderFailure);
expect(rejected).toMatchObject({
reason: "format",
message: expect.stringContaining("$objects array"),
});
});
const asAnalysisError = (value: unknown): AnalysisError => {
if (!(value instanceof AnalysisError)) throw value;
return value;
};