refactor(artifacts): consolidate inventory into inspection
This commit is contained in:
@@ -5,7 +5,6 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import type { BinarySession } from "../../../src/application/BinarySession.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import {
|
||||
JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
|
||||
JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE,
|
||||
JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE,
|
||||
@@ -17,7 +16,6 @@ import { observed } from "../../fixtures/analysisExecution.js";
|
||||
interface TestHarness {
|
||||
readonly client: Client;
|
||||
readonly session: BinarySession;
|
||||
readonly resourceListChanges: () => number;
|
||||
readonly close: () => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -33,17 +31,12 @@ async function createTestHarness(): Promise<TestHarness> {
|
||||
});
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
let resourceListChanges = 0;
|
||||
client.setNotificationHandler("notifications/resources/list_changed", () => {
|
||||
resourceListChanges += 1;
|
||||
});
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
|
||||
return {
|
||||
client,
|
||||
session,
|
||||
resourceListChanges: () => resourceListChanges,
|
||||
close: async () => {
|
||||
await client.close();
|
||||
await server.close();
|
||||
@@ -103,8 +96,6 @@ async function runInlineEvidenceScenarios(
|
||||
}
|
||||
|
||||
async function runEvidenceIdScenarios(harness: TestHarness): Promise<void> {
|
||||
await new Promise<void>((resolve) => setImmediate(resolve));
|
||||
const notificationsBeforeIdReuse = harness.resourceListChanges();
|
||||
const tracedById = await harness.client.callTool({
|
||||
name: "trace_application_feature",
|
||||
arguments: {
|
||||
@@ -114,13 +105,10 @@ async function runEvidenceIdScenarios(harness: TestHarness): Promise<void> {
|
||||
},
|
||||
});
|
||||
expect(tracedById.isError).not.toBe(true);
|
||||
await new Promise<void>((resolve) => setImmediate(resolve));
|
||||
expect(harness.resourceListChanges()).toBe(notificationsBeforeIdReuse);
|
||||
|
||||
const comparedById = await harness.client.callTool({
|
||||
name: "compare_application_versions",
|
||||
arguments: {
|
||||
...JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
|
||||
left_evidence_id:
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left.evidence_id,
|
||||
right_evidence_id:
|
||||
@@ -138,6 +126,36 @@ async function runEvidenceIdScenarios(harness: TestHarness): Promise<void> {
|
||||
},
|
||||
});
|
||||
|
||||
const mixedLeftInline = await harness.client.callTool({
|
||||
name: "compare_application_versions",
|
||||
arguments: {
|
||||
left: JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left,
|
||||
right:
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.right.evidence_id,
|
||||
},
|
||||
});
|
||||
expect(mixedLeftInline.isError).not.toBe(true);
|
||||
|
||||
const mixedRightInline = await harness.client.callTool({
|
||||
name: "compare_application_versions",
|
||||
arguments: {
|
||||
left: JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left
|
||||
.evidence_id,
|
||||
right: JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.right,
|
||||
},
|
||||
});
|
||||
expect(mixedRightInline.isError).not.toBe(true);
|
||||
|
||||
const mixedWithLegacyAlias = await harness.client.callTool({
|
||||
name: "compare_application_versions",
|
||||
arguments: {
|
||||
left: JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left,
|
||||
right_evidence_id:
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.right.evidence_id,
|
||||
},
|
||||
});
|
||||
expect(mixedWithLegacyAlias.isError).not.toBe(true);
|
||||
|
||||
const sourceComparedById = await harness.client.callTool({
|
||||
name: "compare_source_to_bundle",
|
||||
arguments: {
|
||||
@@ -225,6 +243,17 @@ async function assertRejectedInlineEvidence(client: Client): Promise<void> {
|
||||
},
|
||||
});
|
||||
expect(spoofed.isError).toBe(true);
|
||||
|
||||
const duplicateComparisonReference = await client.callTool({
|
||||
name: "compare_application_versions",
|
||||
arguments: {
|
||||
left: JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left,
|
||||
left_evidence_id:
|
||||
JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.left.evidence_id,
|
||||
right: JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE.right,
|
||||
},
|
||||
});
|
||||
expect(duplicateComparisonReference.isError).toBe(true);
|
||||
}
|
||||
|
||||
describe("application workflow MCP parity", () => {
|
||||
|
||||
@@ -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()]);
|
||||
}
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -164,7 +164,7 @@ describe("artifact comparison", () => {
|
||||
result: evidence.normalized_result,
|
||||
});
|
||||
expect(() => compareArtifacts(wrongOperation, evidence)).toThrow(
|
||||
/inventory_artifact/u,
|
||||
/inspect_artifact/u,
|
||||
);
|
||||
const mismatchedSubject = createEvidence(
|
||||
{ path: root, sha256: "f".repeat(64), format: "directory" },
|
||||
|
||||
Reference in New Issue
Block a user