refactor(artifacts): consolidate inventory into inspection

This commit is contained in:
morluto
2026-09-29 09:22:24 +08:00
parent a66e43a99d
commit 0fe96d92df
28 changed files with 375 additions and 280 deletions
@@ -37,23 +37,58 @@ it("returns every artifact occurrence in one MCP call", async () => {
arguments: { path: archive },
});
expect(opened.isError).not.toBe(true);
const names = (await client.listTools()).tools.map(({ name }) => name);
expect(names).toContain("inspect_artifact");
expect(names).not.toContain("inventory_artifact");
const status = await client.callTool({
name: "binary_session",
arguments: {},
});
expect(
z
.object({
result: z.object({
capabilities: z.array(z.object({ operation: z.string() })),
}),
})
.parse(status.structuredContent)
.result.capabilities.map(({ operation }) => operation),
).not.toContain("inventory_artifact");
const result = await client.callTool({
name: "inventory_artifact",
name: "inspect_artifact",
arguments: {},
});
expect(result.isError, JSON.stringify(result.structuredContent)).not.toBe(
true,
);
const inventory = z
const inspection = z
.object({
occurrences: z.array(z.object({ logical_path: z.string() })),
substeps: z.array(
z.object({
evidence: z.object({
normalized_result: z.object({
occurrences: z.array(z.object({ logical_path: z.string() })),
}),
}),
}),
),
observations: z.array(z.unknown()),
derived_relationships: z.array(z.unknown()),
hypotheses: z.array(z.unknown()),
unexplored_branches: z.array(z.unknown()),
next_probes: z.array(z.unknown()),
})
.parse(
z.object({ result: z.unknown() }).parse(result.structuredContent)
.result,
);
expect(inventory.occurrences).toHaveLength(fileCount + 1);
expect(inventory.occurrences.length).toBe(fileCount + 1);
const occurrences =
inspection.substeps[0]?.evidence.normalized_result.occurrences;
if (occurrences === undefined)
throw new Error("inspection omitted the artifact inventory");
expect(occurrences).toHaveLength(fileCount + 1);
expect(inspection.observations.length).toBeGreaterThan(0);
expect(inspection.derived_relationships.length).toBeGreaterThan(0);
} finally {
await Promise.allSettled([client.close(), server.close(), session.close()]);
}
+33 -31
View File
@@ -58,7 +58,7 @@ it.each([
expect(opened.isError).not.toBe(true);
const result = await client.callTool({
name: "inventory_artifact",
name: "inspect_artifact",
arguments: {},
});
expect(result.isError).toBe(true);
@@ -142,7 +142,7 @@ it("records an approved mismatch, preserves verified siblings, and never reports
arguments: { path: archive },
});
const result = await client.callTool({
name: "inventory_artifact",
name: "inspect_artifact",
arguments: {
integrity_policy: "record-and-continue",
integrity_continue_approved: true,
@@ -154,7 +154,20 @@ it("records an approved mismatch, preserves verified siblings, and never reports
const compact = compactResult(result.structuredContent);
const evidence = session.evidenceById(compact.evidence_id);
if (evidence === undefined) throw new Error("missing inventory Evidence");
const inventory = artifactInventoryResultSchema.parse(compact.result);
const inspection = z
.object({
contradictions: z.array(z.unknown()),
substeps: z.array(
z.object({
evidence: z.object({ normalized_result: z.unknown() }),
}),
),
})
.parse(compact.result);
const inventory = artifactInventoryResultSchema.parse(
inspection.substeps[0]?.evidence.normalized_result,
);
expect(inspection.contradictions).toHaveLength(2);
expect(inventory.integrity_contradictions).toEqual(
expect.arrayContaining([
expect.objectContaining({
@@ -183,26 +196,6 @@ it("records an approved mismatch, preserves verified siblings, and never reports
}),
]),
);
const inspected = await client.callTool({
name: "inspect_artifact",
arguments: {
integrity_policy: "record-and-continue",
integrity_continue_approved: true,
},
});
expect(inspected.isError).not.toBe(true);
expect(compactResult(inspected.structuredContent).result).toMatchObject({
contradictions: [
expect.objectContaining({ occurrence_id: expect.any(String) }),
expect.objectContaining({ occurrence_id: expect.any(String) }),
],
substeps: [
expect.objectContaining({
operation: "inventory_artifact",
status: "completed",
}),
],
});
const compared = await client.callTool({
name: "compare_artifacts",
arguments: {
@@ -362,7 +355,7 @@ it("returns full artifact graphs inline and compares changed inventories", async
inspection.substeps[0]?.evidence_id,
]);
const inventory = await client.callTool({
name: "inventory_artifact",
name: "inspect_artifact",
arguments: {},
});
expect(inventory.isError).not.toBe(true);
@@ -373,13 +366,22 @@ it("returns full artifact graphs inline and compares changed inventories", async
provider: { id: "rea-artifact-graph" },
subject: { format: "ipa" },
});
const inventoryInspection = z
.object({
substeps: z.array(
z.object({
evidence: z.object({
normalized_result: z.object({
manifest: z.object({ root_format: z.literal("ipa") }),
occurrences: z.array(z.object({ logical_path: z.string() })),
}),
}),
}),
),
})
.parse(inventoryResult.result);
expect(
z
.object({
manifest: z.object({ root_format: z.literal("ipa") }),
occurrences: z.array(z.object({ logical_path: z.string() })),
})
.parse(inventoryResult.result).occurrences,
inventoryInspection.substeps[0]?.evidence.normalized_result.occurrences,
).toEqual(
expect.arrayContaining([
expect.objectContaining({
@@ -393,7 +395,7 @@ it("returns full artifact graphs inline and compares changed inventories", async
});
expect(openedChanged.isError).not.toBe(true);
const changedInventory = await client.callTool({
name: "inventory_artifact",
name: "inspect_artifact",
arguments: {},
});
const changedResult = compactResult(changedInventory.structuredContent);
@@ -9,7 +9,6 @@ import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js
import { runProviderAnalysis } from "../../../../src/application/DirectAnalysis.js";
import { ArtifactProvider } from "../../../../src/artifacts/ArtifactProvider.js";
import { artifactInspectionInputSchema } from "../../../../src/contracts/artifactToolContracts.js";
import { artifactInventoryResultSchema } from "../../../../src/domain/artifactGraph.js";
import { artifactInspectionResultSchema } from "../../../../src/domain/artifactInspection.js";
import type { BinaryTarget } from "../../../../src/domain/binaryTarget.js";
@@ -123,7 +122,7 @@ describe("artifact archive inventory", () => {
});
const failedInspection = await new ArtifactProvider()
.createClient(target(unpackedPath, "asar"))
.execute("inspect_artifact", artifactInspectionInputSchema.parse({}));
.execute("inspect_artifact", {});
expect(failedInspection).toMatchObject({
ok: false,
error: { _tag: "ArtifactOperationError", reason: "integrity" },