Merge pull request #1161 from morluto/fix/artifact-unsupported-target-errors
fix(artifacts): report wrong target kinds as unsupported targets
This commit is contained in:
@@ -89,6 +89,22 @@ it("preserves encrypted-member and corrupt-CRC observations", async () => {
|
||||
hash_status: "unavailable",
|
||||
}),
|
||||
);
|
||||
// REA does not decrypt entries, so complete extraction is unsupported.
|
||||
const extractionRoot = join(root, "encrypted-output");
|
||||
expect(
|
||||
await new ArtifactProvider()
|
||||
.createClient(encryptedTarget.value)
|
||||
.execute("extract_artifact", { output_root: extractionRoot }),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "AnalysisUnsupportedTargetError",
|
||||
reason: expect.stringContaining("Archive entry secret.txt is encrypted"),
|
||||
},
|
||||
});
|
||||
await expect(readFile(extractionRoot)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
|
||||
const corruptPath = join(root, "corrupt-crc.zip");
|
||||
const corruptWriter = new ZipWriter(new Uint8ArrayWriter());
|
||||
|
||||
@@ -126,7 +126,41 @@ it("rejects targets that are not Mach-O", async () => {
|
||||
arguments: {},
|
||||
});
|
||||
expect(called.isError).toBe(true);
|
||||
expect(JSON.stringify(called.structuredContent)).toContain("unavailable");
|
||||
expect(called.structuredContent).toMatchObject({
|
||||
error: { code: "unsupported_target", category: "unsupported_target" },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("reports target kinds that artifact operations cannot inspect as unsupported", async () => {
|
||||
const directory = await createTestTempDirectory("rea-artifact-target-");
|
||||
const plist = join(directory, "Info.plist");
|
||||
await writeFile(plist, "<plist><dict/></plist>");
|
||||
const tool = join(directory, "tool");
|
||||
await writeFile(tool, machoImage({ commands: [buildVersionCommand(1)] }));
|
||||
await withClient(async (client) => {
|
||||
for (const [path, operation, requirement] of [
|
||||
[plist, "decode_interface_builder", "requires an active .app bundle"],
|
||||
// Elsewhere the session reports asset catalogs as unavailable on the
|
||||
// host before the provider checks the target kind.
|
||||
...(process.platform === "darwin"
|
||||
? ([
|
||||
[plist, "inspect_asset_catalog", "requires an active .app bundle"],
|
||||
] as const)
|
||||
: []),
|
||||
[tool, "inspect_keyed_archive", "requires an active plist or .app"],
|
||||
] as const) {
|
||||
const open = { name: "open_binary", arguments: { path } };
|
||||
expect((await client.callTool(open)).isError, path).not.toBe(true);
|
||||
const called = await client.callTool({ name: operation, arguments: {} });
|
||||
expect(called.structuredContent, operation).toMatchObject({
|
||||
error: {
|
||||
code: "unsupported_target",
|
||||
message: expect.stringContaining(`${operation} at ${path}`),
|
||||
details: { reason: expect.stringContaining(requirement) },
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -133,6 +133,27 @@ describe("artifact extraction", () => {
|
||||
"source",
|
||||
]);
|
||||
});
|
||||
it("refuses a format without an extraction reader before inventory or output", async () => {
|
||||
const root = await createTestTempDirectory("rea-extract-dmg-");
|
||||
const image = join(root, "Image.dmg");
|
||||
await writeFile(image, "not mounted");
|
||||
const output = join(root, "output");
|
||||
const result = await new ArtifactProvider()
|
||||
.createClient(target(image, "dmg"))
|
||||
.execute(
|
||||
"extract_artifact",
|
||||
artifactExtractionExecutionSchema.parse({ output_root: output }),
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "AnalysisUnsupportedTargetError",
|
||||
operation: "extract_artifact",
|
||||
reason: "Artifact format has no extraction reader: dmg",
|
||||
},
|
||||
});
|
||||
await expect(access(output)).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
const inventory = async (targetValue: BinaryTarget) => {
|
||||
const result = await new ArtifactProvider()
|
||||
|
||||
Reference in New Issue
Block a user