refactor(artifact): simplify extraction and inventory results
This commit is contained in:
@@ -46,17 +46,14 @@ it("returns every artifact occurrence in one MCP call", async () => {
|
||||
);
|
||||
const inventory = z
|
||||
.object({
|
||||
occurrences: z.object({
|
||||
items: z.array(z.object({ logical_path: z.string() })),
|
||||
total: z.number(),
|
||||
}),
|
||||
occurrences: z.array(z.object({ logical_path: z.string() })),
|
||||
})
|
||||
.parse(
|
||||
z.object({ result: z.unknown() }).parse(result.structuredContent)
|
||||
.result,
|
||||
);
|
||||
expect(inventory.occurrences.items).toHaveLength(fileCount + 1);
|
||||
expect(inventory.occurrences.total).toBe(fileCount + 1);
|
||||
expect(inventory.occurrences).toHaveLength(fileCount + 1);
|
||||
expect(inventory.occurrences.length).toBe(fileCount + 1);
|
||||
} finally {
|
||||
await Promise.allSettled([client.close(), server.close(), session.close()]);
|
||||
}
|
||||
|
||||
@@ -94,12 +94,9 @@ it.each([
|
||||
);
|
||||
|
||||
const artifactInventoryResultSchema = z.object({
|
||||
occurrences: z.object({
|
||||
items: z.array(
|
||||
z.object({ logical_path: z.string(), hash_status: z.string() }),
|
||||
),
|
||||
total: z.number(),
|
||||
}),
|
||||
occurrences: z.array(
|
||||
z.object({ logical_path: z.string(), hash_status: z.string() }),
|
||||
),
|
||||
integrity_contradictions: z.array(
|
||||
z.object({
|
||||
logical_path: z.string(),
|
||||
@@ -170,7 +167,7 @@ it("records an approved mismatch, preserves verified siblings, and never reports
|
||||
]),
|
||||
);
|
||||
expect(inventory.integrity_contradictions).toHaveLength(2);
|
||||
expect(inventory.occurrences.items).toEqual(
|
||||
expect(inventory.occurrences).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
logical_path: "main.js",
|
||||
@@ -209,27 +206,25 @@ it("records an approved mismatch, preserves verified siblings, and never reports
|
||||
const compared = await client.callTool({
|
||||
name: "compare_artifacts",
|
||||
arguments: {
|
||||
left_evidence_ids: [evidence.evidence_id],
|
||||
right_evidence_ids: [evidence.evidence_id],
|
||||
left_evidence_id: evidence.evidence_id,
|
||||
right_evidence_id: evidence.evidence_id,
|
||||
},
|
||||
});
|
||||
expect(compared.isError).not.toBe(true);
|
||||
expect(compactResult(compared.structuredContent).result).toMatchObject({
|
||||
status: "contradiction",
|
||||
summary: { contradiction: 2 },
|
||||
changes: {
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
logical_path: "main.js",
|
||||
classification: "contradiction",
|
||||
dimensions: ["integrity"],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
logical_path: "second.js",
|
||||
classification: "contradiction",
|
||||
}),
|
||||
]),
|
||||
},
|
||||
changes: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
logical_path: "main.js",
|
||||
classification: "contradiction",
|
||||
dimensions: ["integrity"],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
logical_path: "second.js",
|
||||
classification: "contradiction",
|
||||
}),
|
||||
]),
|
||||
});
|
||||
} finally {
|
||||
await Promise.allSettled([client.close(), server.close(), session.close()]);
|
||||
@@ -382,11 +377,9 @@ it("returns full artifact graphs inline and compares changed inventories", async
|
||||
z
|
||||
.object({
|
||||
manifest: z.object({ root_format: z.literal("ipa") }),
|
||||
occurrences: z.object({
|
||||
items: z.array(z.object({ logical_path: z.string() })),
|
||||
}),
|
||||
occurrences: z.array(z.object({ logical_path: z.string() })),
|
||||
})
|
||||
.parse(inventoryResult.result).occurrences.items,
|
||||
.parse(inventoryResult.result).occurrences,
|
||||
).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
@@ -410,8 +403,8 @@ it("returns full artifact graphs inline and compares changed inventories", async
|
||||
const compared = await client.callTool({
|
||||
name: "compare_artifacts",
|
||||
arguments: {
|
||||
left_evidence_ids: [evidence.evidence_id],
|
||||
right_evidence_ids: [changedEvidence.evidence_id],
|
||||
left_evidence_id: evidence.evidence_id,
|
||||
right_evidence_id: changedEvidence.evidence_id,
|
||||
unknown_registry_approved: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -28,8 +28,8 @@ describe("artifact archive inventory", () => {
|
||||
expect(parsed.ok && parsed.value.format).toBe("apk");
|
||||
if (!parsed.ok) return;
|
||||
const zipResult = await inventory(parsed.value);
|
||||
expect(zipResult.occurrences.total).toBe(3);
|
||||
expect(zipResult.nodes.items.map(({ kind }) => kind)).toEqual(
|
||||
expect(zipResult.occurrences.length).toBe(3);
|
||||
expect(zipResult.nodes.map(({ kind }) => kind)).toEqual(
|
||||
expect.arrayContaining(["javascript", "dynamic-library"]),
|
||||
);
|
||||
const cliEvidence = parseEvidence(
|
||||
@@ -86,7 +86,7 @@ describe("artifact archive inventory", () => {
|
||||
const asarPath = join(root, "app.asar");
|
||||
await createPackage(source, asarPath);
|
||||
const asarResult = await inventory(target(asarPath, "asar"));
|
||||
expect(asarResult.occurrences.items).toEqual(
|
||||
expect(asarResult.occurrences).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ logical_path: "main.js" }),
|
||||
]),
|
||||
@@ -95,7 +95,7 @@ describe("artifact archive inventory", () => {
|
||||
const unpackedPath = join(root, "unpacked.asar");
|
||||
await createPackageWithOptions(source, unpackedPath, { unpack: "*.js" });
|
||||
const unpackedResult = await inventory(target(unpackedPath, "asar"));
|
||||
expect(unpackedResult.occurrences.items).toEqual(
|
||||
expect(unpackedResult.occurrences).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
logical_path: "main.js",
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from "../../../../src/artifacts/ArtifactPaths.js";
|
||||
import { ArtifactProvider } from "../../../../src/artifacts/ArtifactProvider.js";
|
||||
import { ArtifactReaderFailure } from "../../../../src/artifacts/ArtifactReader.js";
|
||||
import { artifactExtractionInputSchema } from "../../../../src/contracts/artifactToolContracts.js";
|
||||
import { artifactExtractionExecutionSchema } from "../../../../src/contracts/artifactToolContracts.js";
|
||||
import { artifactInventoryResultSchema } from "../../../../src/domain/artifactGraph.js";
|
||||
import type { BinaryTarget } from "../../../../src/domain/binaryTarget.js";
|
||||
import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
|
||||
@@ -47,10 +47,10 @@ describe("artifact archive safety", () => {
|
||||
if (!parsed.ok) return;
|
||||
const result = await inventory(parsed.value);
|
||||
expect(result.manifest.root_format).toBe(format);
|
||||
expect(result.nodes.items.map(({ kind }) => kind)).toEqual(
|
||||
expect(result.nodes.map(({ kind }) => kind)).toEqual(
|
||||
expect.arrayContaining(["javascript", "native-addon"]),
|
||||
);
|
||||
const selected = result.occurrences.items.find(
|
||||
const selected = result.occurrences.find(
|
||||
({ logical_path: logicalPath }) => logicalPath === "Assets/main.js",
|
||||
);
|
||||
expect(selected).toBeDefined();
|
||||
@@ -60,8 +60,7 @@ describe("artifact archive safety", () => {
|
||||
.createClient(parsed.value)
|
||||
.execute(
|
||||
"extract_artifact",
|
||||
artifactExtractionInputSchema.parse({
|
||||
approved: true,
|
||||
artifactExtractionExecutionSchema.parse({
|
||||
output_root: output,
|
||||
occurrence_ids: [selected.occurrence_id],
|
||||
}),
|
||||
|
||||
@@ -41,7 +41,7 @@ describe("artifact directory inventory", () => {
|
||||
const left = artifactInventoryResultSchema.parse(first.value.result);
|
||||
const right = artifactInventoryResultSchema.parse(second.value.result);
|
||||
expect(left.manifest).toEqual(right.manifest);
|
||||
expect(left.nodes.items.map(({ kind }) => kind)).toEqual(
|
||||
expect(left.nodes.map(({ kind }) => kind)).toEqual(
|
||||
expect.arrayContaining([
|
||||
"executable",
|
||||
"framework",
|
||||
@@ -50,17 +50,17 @@ describe("artifact directory inventory", () => {
|
||||
]),
|
||||
);
|
||||
expect(
|
||||
left.occurrences.items.find(({ logical_path: path }) =>
|
||||
left.occurrences.find(({ logical_path: path }) =>
|
||||
path.endsWith("outside"),
|
||||
),
|
||||
).toMatchObject({ artifact_id: null, entry_kind: "symlink" });
|
||||
const script = left.occurrences.items.find(({ logical_path: path }) =>
|
||||
const script = left.occurrences.find(({ logical_path: path }) =>
|
||||
path.endsWith("main.js"),
|
||||
);
|
||||
const sourceMap = left.occurrences.items.find(({ logical_path: path }) =>
|
||||
const sourceMap = left.occurrences.find(({ logical_path: path }) =>
|
||||
path.endsWith("main.js.MAP"),
|
||||
);
|
||||
expect(left.edges.items).toEqual(
|
||||
expect(left.edges).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
relation: "maps-source",
|
||||
|
||||
@@ -6,7 +6,7 @@ import { describe, expect, it } from "vitest";
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { ArtifactProvider } from "../../../../src/artifacts/ArtifactProvider.js";
|
||||
import { artifactExtractionInputSchema } from "../../../../src/contracts/artifactToolContracts.js";
|
||||
import { artifactExtractionExecutionSchema } from "../../../../src/contracts/artifactToolContracts.js";
|
||||
import {
|
||||
artifactExtractionResultSchema,
|
||||
artifactInventoryResultSchema,
|
||||
@@ -22,7 +22,7 @@ describe("artifact extraction", () => {
|
||||
await writeFile(join(source, "assets", "ignored.js"), "ignored();\n");
|
||||
const targetValue = target(source, "directory");
|
||||
const graph = await inventory(targetValue);
|
||||
const selected = graph.occurrences.items.find(
|
||||
const selected = graph.occurrences.find(
|
||||
({ logical_path: path }) => path === "assets/selected.js",
|
||||
);
|
||||
expect(selected).toBeDefined();
|
||||
@@ -34,8 +34,7 @@ describe("artifact extraction", () => {
|
||||
.createClient(targetValue)
|
||||
.execute(
|
||||
"extract_artifact",
|
||||
artifactExtractionInputSchema.parse({
|
||||
approved: true,
|
||||
artifactExtractionExecutionSchema.parse({
|
||||
output_root: cancelledOutput,
|
||||
occurrence_ids: [selected.occurrence_id],
|
||||
}),
|
||||
@@ -51,8 +50,7 @@ describe("artifact extraction", () => {
|
||||
.createClient(targetValue)
|
||||
.execute(
|
||||
"extract_artifact",
|
||||
artifactExtractionInputSchema.parse({
|
||||
approved: true,
|
||||
artifactExtractionExecutionSchema.parse({
|
||||
output_root: output,
|
||||
occurrence_ids: [selected.occurrence_id],
|
||||
}),
|
||||
@@ -63,9 +61,11 @@ describe("artifact extraction", () => {
|
||||
result.value.result,
|
||||
);
|
||||
expect(firstExtraction).toMatchObject({
|
||||
output_root: "$OUTPUT_ROOT",
|
||||
output_root: output,
|
||||
containment_verified: true,
|
||||
artifacts: { total: 1 },
|
||||
artifacts: expect.arrayContaining([
|
||||
expect.objectContaining({ relative_path: "assets/selected.js" }),
|
||||
]),
|
||||
extraction_manifest: { output_root_alias: "$OUTPUT_ROOT" },
|
||||
});
|
||||
expect(await readFile(join(output, "assets", "selected.js"), "utf8")).toBe(
|
||||
@@ -80,8 +80,7 @@ describe("artifact extraction", () => {
|
||||
.createClient(targetValue)
|
||||
.execute(
|
||||
"extract_artifact",
|
||||
artifactExtractionInputSchema.parse({
|
||||
approved: true,
|
||||
artifactExtractionExecutionSchema.parse({
|
||||
output_root: relocatedOutput,
|
||||
occurrence_ids: [selected.occurrence_id],
|
||||
}),
|
||||
@@ -97,8 +96,7 @@ describe("artifact extraction", () => {
|
||||
.createClient(targetValue)
|
||||
.execute(
|
||||
"extract_artifact",
|
||||
artifactExtractionInputSchema.parse({
|
||||
approved: true,
|
||||
artifactExtractionExecutionSchema.parse({
|
||||
output_root: output,
|
||||
occurrence_ids: [selected.occurrence_id],
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user