mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 22:45:47 +00:00
fix(evidence): reject unknown fields in comparison record pairs (#13523)
This commit is contained in:
1 parent
8880382f21
commit
0eaea650c0
4 files changed
+68
-110
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"schemas": {
|
||||
"input compact": "65c9f2cad6fee49f",
|
||||
"input compact": "006beb225fddea97",
|
||||
"output compact": "4bda7c3651bfc579"
|
||||
},
|
||||
"patterns": {
|
||||
|
||||
@@ -29,7 +29,7 @@ export const bundleComparisonInputSchema = z.strictObject({
|
||||
right_bundle_path: localPathStringSchema,
|
||||
record_pairs: z
|
||||
.array(
|
||||
z.object({
|
||||
z.strictObject({
|
||||
left_evidence_id: evidenceIdSchema,
|
||||
right_evidence_id: evidenceIdSchema,
|
||||
}),
|
||||
|
||||
@@ -75,12 +75,6 @@ cliTest(
|
||||
]);
|
||||
const compare = async (path: string) =>
|
||||
cli.run({ arguments: ["compare", leftPath, path, "--json"] });
|
||||
const same = await compare(leftPath);
|
||||
expect(same.exitCode).toBe(0);
|
||||
expect(bundleComparisonResultSchema.parse(same.json)).toMatchObject({
|
||||
status: "unchanged",
|
||||
changes: [],
|
||||
});
|
||||
const display = await compare(displayPath);
|
||||
expect(display.exitCode).toBe(0);
|
||||
const displayResult = bundleComparisonResultSchema.parse(display.json);
|
||||
@@ -146,6 +140,14 @@ cliTest(
|
||||
});
|
||||
const call = await cli.sharedMcpCall?.();
|
||||
if (call === undefined) throw new Error("Expected shared MCP session");
|
||||
const mcpDisplay = await call("compare_bundles", {
|
||||
left_bundle_path: leftPath,
|
||||
right_bundle_path: displayPath,
|
||||
});
|
||||
expect(mcpDisplay.isError).not.toBe(true);
|
||||
expect(
|
||||
parseEvidence(mcpDisplay.structuredContent).normalized_result,
|
||||
).toEqual(displayResult);
|
||||
const mcp = await call("compare_bundles", {
|
||||
left_bundle_path: leftPath,
|
||||
right_bundle_path: changedPath,
|
||||
@@ -273,7 +275,7 @@ cliTest(
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"rejects relative bundle paths over stdio MCP while CLI resolves them from its cwd",
|
||||
"enforces comparison input before file lookup across stdio MCP and CLI",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-bundle-path-boundary-");
|
||||
const leftPath = join(root, "left.json");
|
||||
@@ -284,12 +286,13 @@ cliTest(
|
||||
writeFile(rightPath, encoded),
|
||||
]);
|
||||
|
||||
const schemas = createMcpSchemaValidation();
|
||||
const client = new Client(
|
||||
{
|
||||
name: "bundle-path-contract-test",
|
||||
version: "1",
|
||||
},
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
{ jsonSchemaValidator: schemas },
|
||||
);
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
@@ -340,6 +343,61 @@ cliTest(
|
||||
});
|
||||
}
|
||||
|
||||
const missing = join(root, "missing.json");
|
||||
const pair = {
|
||||
left_evidence_id: `ev_${"a".repeat(64)}`,
|
||||
right_evidence_id: `ev_${"b".repeat(64)}`,
|
||||
};
|
||||
const inputs = { left_bundle_path: missing, right_bundle_path: rightPath };
|
||||
const recordPairs = [{ ...pair, unexpected_pair_field: true }];
|
||||
const malformed = { ...inputs, record_pairs: recordPairs };
|
||||
const rejected = await cli.run({
|
||||
arguments: [
|
||||
"compare",
|
||||
missing,
|
||||
rightPath,
|
||||
"--record_pairs",
|
||||
JSON.stringify(recordPairs),
|
||||
"--json",
|
||||
],
|
||||
});
|
||||
const rejectedMcp = await client.callTool({
|
||||
name: "compare_bundles",
|
||||
arguments: malformed,
|
||||
});
|
||||
const error = {
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: ["record_pairs", 0, "unexpected_pair_field"],
|
||||
reason: "unknown_argument",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(rejected.exitCode).toBe(1);
|
||||
expect({
|
||||
cli: rejected.json,
|
||||
mcp: parseMcpToolError(rejectedMcp).error,
|
||||
}).toMatchObject({ cli: error, mcp: error });
|
||||
const { tools } = await client.listTools();
|
||||
const advertised = tools.find(({ name }) => name === "compare_bundles");
|
||||
if (advertised === undefined)
|
||||
throw new Error("Missing compare_bundles schema");
|
||||
expect(schemas.assertions.validateSchema(advertised.inputSchema)).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
schemas.assertions.validate(advertised.inputSchema, {
|
||||
...inputs,
|
||||
record_pairs: [pair],
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(schemas.assertions.validate(advertised.inputSchema, malformed)).toBe(
|
||||
false,
|
||||
);
|
||||
|
||||
const absolute = await client.callTool({
|
||||
name: "compare_bundles",
|
||||
arguments: {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { displayedEvidenceSubject } from "../../fixtures/evidenceSubject.js";
|
||||
import { unknownTarget } from "../../../src/domain/targetIdentity.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { ok as resultOk } from "../../../src/domain/result.js";
|
||||
@@ -39,105 +38,6 @@ const sourceEvidence = (label: string) =>
|
||||
},
|
||||
);
|
||||
|
||||
describe("bundle comparison MCP semantic status", () => {
|
||||
it("keeps display-only metadata out of deltas and preserves semantic changes", async () => {
|
||||
const root = await createTestTempDirectory("rea-bundle-metadata-mcp-");
|
||||
const leftPath = join(root, "left.json");
|
||||
const displayPath = join(root, "display.json");
|
||||
const changedPath = join(root, "changed.json");
|
||||
const target = {
|
||||
path: join(root, "left.elf"),
|
||||
sha256: "a".repeat(64),
|
||||
format: "elf" as const,
|
||||
architecture: "x86_64" as const,
|
||||
};
|
||||
const record = createEvidence(
|
||||
target,
|
||||
{ id: "fixture", name: "Fixture", version: "1" },
|
||||
{
|
||||
operation: "observe",
|
||||
parameters: {},
|
||||
result: { observed: true },
|
||||
confidence: "observed",
|
||||
authority: "shipped-artifact",
|
||||
},
|
||||
);
|
||||
const left = createEvidenceBundle([record]);
|
||||
const displayRecord = {
|
||||
...record,
|
||||
subject: displayedEvidenceSubject(record.subject, {
|
||||
name: "renamed.elf",
|
||||
local_path: join(root, "renamed.elf"),
|
||||
}),
|
||||
};
|
||||
const displayOnly = { ...left, records: [displayRecord] };
|
||||
const changedRecord = createEvidence(
|
||||
target,
|
||||
{ id: "fixture", name: "Fixture", version: "1" },
|
||||
{
|
||||
operation: "observe",
|
||||
parameters: {},
|
||||
result: { observed: false },
|
||||
confidence: "observed",
|
||||
authority: "shipped-artifact",
|
||||
},
|
||||
);
|
||||
await Promise.all([
|
||||
writeFile(leftPath, serializeEvidenceBundle(left)),
|
||||
writeFile(displayPath, serializeEvidenceBundle(displayOnly)),
|
||||
writeFile(
|
||||
changedPath,
|
||||
serializeEvidenceBundle(createEvidenceBundle([changedRecord])),
|
||||
),
|
||||
]);
|
||||
const connected = await connect();
|
||||
try {
|
||||
const compare = async (
|
||||
right: string,
|
||||
recordPairs: readonly {
|
||||
left_evidence_id: string;
|
||||
right_evidence_id: string;
|
||||
}[] = [],
|
||||
) => {
|
||||
const result = await connected.client.callTool({
|
||||
name: "compare_bundles",
|
||||
arguments: {
|
||||
left_bundle_path: leftPath,
|
||||
right_bundle_path: right,
|
||||
record_pairs: recordPairs,
|
||||
},
|
||||
});
|
||||
expect(result.isError).not.toBe(true);
|
||||
const evidence = toolContract("compare_bundles").outputSchema.parse(
|
||||
result.structuredContent,
|
||||
);
|
||||
return bundleComparisonResultSchema.parse(evidence.normalized_result);
|
||||
};
|
||||
const same = await compare(leftPath);
|
||||
expect(same).toMatchObject({
|
||||
status: "unchanged",
|
||||
changes: [],
|
||||
});
|
||||
const display = await compare(displayPath);
|
||||
expect(display).toMatchObject({
|
||||
status: "unchanged",
|
||||
changes: [],
|
||||
});
|
||||
expect(display.left_bundle_sha256).not.toBe(display.right_bundle_sha256);
|
||||
const changed = await compare(changedPath, [
|
||||
{
|
||||
left_evidence_id: record.evidence_id,
|
||||
right_evidence_id: changedRecord.evidence_id,
|
||||
},
|
||||
]);
|
||||
expect(changed.status).toBe("changed");
|
||||
expect(changed.changes).toHaveLength(1);
|
||||
} finally {
|
||||
await connected.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("requires absolute bundle paths without changing server-cwd semantics", async () => {
|
||||
const root = await createTestTempDirectory("rea-bundle-relative-mcp-");
|
||||
const encoded = serializeEvidenceBundle(createEvidenceBundle([]));
|
||||
|
||||
Reference in new issue
Block a user