mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
test(mcp): share retained comparison integrity setup (#16183)
This commit is contained in:
1 parent
1f72e699e4
commit
407cedca98
1 file changed
+49
-112
@@ -3,15 +3,18 @@ import { expect, it, onTestFinished } from "vitest";
|
||||
|
||||
import { ARTIFACT_COMPARISON_EXAMPLE } from "../../../src/contracts/artifactComparisonExample.js";
|
||||
import { compareArtifacts } from "../../../src/domain/artifactComparison.js";
|
||||
import { createEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createEvidence, type Evidence } from "../../../src/domain/evidence.js";
|
||||
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
|
||||
it("rejects an unchanged artifact comparison that retains a changed row", async () => {
|
||||
const left = ARTIFACT_COMPARISON_EXAMPLE.left;
|
||||
const right = ARTIFACT_COMPARISON_EXAMPLE.right;
|
||||
const verifyRetainedComparison = async (
|
||||
left: Evidence,
|
||||
right: Evidence,
|
||||
result: ReturnType<typeof compareArtifacts>,
|
||||
unexpectedProvider: string,
|
||||
) => {
|
||||
const comparison = createEvidence(
|
||||
unknownTarget("derived-from-linked-evidence"),
|
||||
{
|
||||
@@ -26,19 +29,14 @@ it("rejects an unchanged artifact comparison that retains a changed row", async
|
||||
left_evidence_ids: [left.evidence_id],
|
||||
right_evidence_ids: [right.evidence_id],
|
||||
},
|
||||
result: {
|
||||
...compareArtifacts(left, right),
|
||||
status: "unchanged",
|
||||
},
|
||||
result,
|
||||
confidence: "derived",
|
||||
authority: "analyst-inference",
|
||||
evidenceLinks: [left.evidence_id, right.evidence_id],
|
||||
},
|
||||
);
|
||||
const session = createTestBinarySession(() => {
|
||||
throw new Error(
|
||||
"Retained comparison verification must not launch a provider",
|
||||
);
|
||||
throw new Error(unexpectedProvider);
|
||||
});
|
||||
const harness = await createApplicationMcpHarness({ session });
|
||||
onTestFinished(harness.close);
|
||||
@@ -62,6 +60,21 @@ it("rejects an unchanged artifact comparison that retains a changed row", async
|
||||
},
|
||||
},
|
||||
});
|
||||
return { response, comparison, session };
|
||||
};
|
||||
|
||||
it("rejects an unchanged artifact comparison that retains a changed row", async () => {
|
||||
const left = ARTIFACT_COMPARISON_EXAMPLE.left;
|
||||
const right = ARTIFACT_COMPARISON_EXAMPLE.right;
|
||||
const { response, comparison, session } = await verifyRetainedComparison(
|
||||
left,
|
||||
right,
|
||||
{
|
||||
...compareArtifacts(left, right),
|
||||
status: "unchanged",
|
||||
},
|
||||
"Retained comparison verification must not launch a provider",
|
||||
);
|
||||
|
||||
expect(response.isError).toBe(true);
|
||||
expect(parseMcpToolError(response)).toMatchObject({
|
||||
@@ -89,58 +102,20 @@ it("does not fail a changed aggregate when source inventories are equal", async
|
||||
const equal = compareArtifacts(left, right);
|
||||
expect(equal.status).toBe("unchanged");
|
||||
const changed = compareArtifacts(left, ARTIFACT_COMPARISON_EXAMPLE.right);
|
||||
const comparison = createEvidence(
|
||||
unknownTarget("derived-from-linked-evidence"),
|
||||
const { response } = await verifyRetainedComparison(
|
||||
left,
|
||||
right,
|
||||
{
|
||||
id: "rea-artifact-comparison",
|
||||
name: "REA artifact comparison",
|
||||
version: "1",
|
||||
},
|
||||
{
|
||||
predicateType: "rea.artifact-comparison",
|
||||
operation: "compare_artifacts",
|
||||
parameters: {
|
||||
left_evidence_ids: [left.evidence_id],
|
||||
right_evidence_ids: [right.evidence_id],
|
||||
},
|
||||
result: {
|
||||
...changed,
|
||||
left_manifest_id: equal.left_manifest_id,
|
||||
right_manifest_id: equal.right_manifest_id,
|
||||
changes: changed.changes.map((row) => ({
|
||||
...row,
|
||||
evidence_links: [left.evidence_id, right.evidence_id],
|
||||
})),
|
||||
},
|
||||
confidence: "derived",
|
||||
authority: "analyst-inference",
|
||||
evidenceLinks: [left.evidence_id, right.evidence_id],
|
||||
...changed,
|
||||
left_manifest_id: equal.left_manifest_id,
|
||||
right_manifest_id: equal.right_manifest_id,
|
||||
changes: changed.changes.map((row) => ({
|
||||
...row,
|
||||
evidence_links: [left.evidence_id, right.evidence_id],
|
||||
})),
|
||||
},
|
||||
"No provider expected",
|
||||
);
|
||||
const session = createTestBinarySession(() => {
|
||||
throw new Error("No provider expected");
|
||||
});
|
||||
const harness = await createApplicationMcpHarness({ session });
|
||||
onTestFinished(harness.close);
|
||||
for (const record of [left, right, comparison])
|
||||
expect(session.recordEvidence(record).ok).toBe(true);
|
||||
const response = await harness.client.callTool({
|
||||
name: "verify_reconstruction",
|
||||
arguments: {
|
||||
specification: {
|
||||
name: "Artifact structure",
|
||||
claims: [
|
||||
{
|
||||
kind: "structural-artifact",
|
||||
claim_id: "artifact-graph",
|
||||
title: "Artifact graph remains equal",
|
||||
comparison_evidence_id: comparison.evidence_id,
|
||||
dimension: "overall",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(response.isError, JSON.stringify(response)).not.toBe(true);
|
||||
expect(response.structuredContent).toMatchObject({
|
||||
normalized_result: {
|
||||
@@ -179,62 +154,24 @@ it("does not pass an unchanged aggregate over unavailable source coverage", asyn
|
||||
const right = ARTIFACT_COMPARISON_EXAMPLE.right;
|
||||
const actual = compareArtifacts(left, right);
|
||||
expect(actual.status).toBe("unknown");
|
||||
const comparison = createEvidence(
|
||||
unknownTarget("derived-from-linked-evidence"),
|
||||
const { response, comparison, session } = await verifyRetainedComparison(
|
||||
left,
|
||||
right,
|
||||
{
|
||||
id: "rea-artifact-comparison",
|
||||
name: "REA artifact comparison",
|
||||
version: "1",
|
||||
},
|
||||
{
|
||||
predicateType: "rea.artifact-comparison",
|
||||
operation: "compare_artifacts",
|
||||
parameters: {
|
||||
left_evidence_ids: [left.evidence_id],
|
||||
right_evidence_ids: [right.evidence_id],
|
||||
...actual,
|
||||
status: "unchanged",
|
||||
changes: [],
|
||||
summary: {
|
||||
unchanged: 1,
|
||||
added: 0,
|
||||
removed: 0,
|
||||
changed: 0,
|
||||
unknown: 0,
|
||||
contradiction: 0,
|
||||
},
|
||||
result: {
|
||||
...actual,
|
||||
status: "unchanged",
|
||||
changes: [],
|
||||
summary: {
|
||||
unchanged: 1,
|
||||
added: 0,
|
||||
removed: 0,
|
||||
changed: 0,
|
||||
unknown: 0,
|
||||
contradiction: 0,
|
||||
},
|
||||
},
|
||||
confidence: "derived",
|
||||
authority: "analyst-inference",
|
||||
evidenceLinks: [left.evidence_id, right.evidence_id],
|
||||
},
|
||||
"No provider expected",
|
||||
);
|
||||
const session = createTestBinarySession(() => {
|
||||
throw new Error("No provider expected");
|
||||
});
|
||||
const harness = await createApplicationMcpHarness({ session });
|
||||
onTestFinished(harness.close);
|
||||
for (const record of [left, right, comparison])
|
||||
expect(session.recordEvidence(record).ok).toBe(true);
|
||||
const response = await harness.client.callTool({
|
||||
name: "verify_reconstruction",
|
||||
arguments: {
|
||||
specification: {
|
||||
name: "Artifact structure",
|
||||
claims: [
|
||||
{
|
||||
kind: "structural-artifact",
|
||||
claim_id: "artifact-graph",
|
||||
title: "Artifact graph remains equal",
|
||||
comparison_evidence_id: comparison.evidence_id,
|
||||
dimension: "overall",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(response.isError, JSON.stringify(response)).not.toBe(true);
|
||||
expect(response.structuredContent).toMatchObject({
|
||||
normalized_result: {
|
||||
|
||||
Reference in new issue
Block a user