Merge pull request #461 from morluto/agent/comprehensive-repository-audit
fix: harden evidence lifecycle and MCP contracts
This commit is contained in:
@@ -130,8 +130,8 @@ describe("analysis context queries: address facets", () => {
|
||||
ok(
|
||||
createAnalysisExecution(
|
||||
[
|
||||
{ address: "0x401000", value: "review" },
|
||||
{ address: "0x402000", value: "other" },
|
||||
{ address: "0x401000", name: "review" },
|
||||
{ address: "0x402000", name: "other" },
|
||||
],
|
||||
provider,
|
||||
),
|
||||
@@ -159,7 +159,7 @@ describe("analysis context queries: address facets", () => {
|
||||
},
|
||||
bookmarks: {
|
||||
state: "available",
|
||||
value: [{ address: "0x401000", value: "review" }],
|
||||
value: [{ address: "0x401000", name: "review" }],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -184,4 +184,30 @@ describe("analysis context queries: address facets", () => {
|
||||
}),
|
||||
).resolves.toEqual(err(cancelled));
|
||||
});
|
||||
|
||||
it("reports malformed bookmark output as unavailable instead of empty", async () => {
|
||||
const analysis: AnalysisOperationPort = {
|
||||
execute: (operation) =>
|
||||
Promise.resolve(
|
||||
operation === "list_bookmarks"
|
||||
? ok(createAnalysisExecution({ malformed: true }, provider))
|
||||
: ok(createAnalysisExecution(null, provider)),
|
||||
),
|
||||
};
|
||||
|
||||
await expect(
|
||||
inspectAddressContext(analysis, {
|
||||
address: "0x401000",
|
||||
document: "fixture",
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
bookmarks: {
|
||||
state: "unavailable",
|
||||
reason: expect.stringContaining("malformed"),
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -197,7 +197,7 @@ describe("capability inventory: caller guidance", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("advertises navigation context only when every cursor operation is available", () => {
|
||||
it("allows explicit documents when the provider has no current-document getter", () => {
|
||||
const capabilities = [
|
||||
"current_document",
|
||||
"current_address",
|
||||
@@ -212,14 +212,40 @@ describe("capability inventory: caller guidance", () => {
|
||||
"get_navigation_context",
|
||||
status({ open: true, kind: "executable", capabilities }),
|
||||
),
|
||||
).toMatchObject({ available: true, reason: "available" });
|
||||
).toMatchObject({
|
||||
available: true,
|
||||
reason: "available",
|
||||
default_mode_available: true,
|
||||
modes: [
|
||||
{ name: "current_selection", available: true },
|
||||
{ name: "explicit_document", available: true },
|
||||
],
|
||||
});
|
||||
expect(
|
||||
entry(
|
||||
"get_navigation_context",
|
||||
status({
|
||||
open: true,
|
||||
kind: "executable",
|
||||
capabilities: capabilities.slice(0, 2),
|
||||
capabilities: capabilities.slice(1),
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
available: true,
|
||||
reason: "available",
|
||||
default_mode_available: false,
|
||||
modes: [
|
||||
{ name: "current_selection", available: false },
|
||||
{ name: "explicit_document", available: true },
|
||||
],
|
||||
});
|
||||
expect(
|
||||
entry(
|
||||
"get_navigation_context",
|
||||
status({
|
||||
open: true,
|
||||
kind: "executable",
|
||||
capabilities: capabilities.slice(1, 2),
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
@@ -228,4 +254,33 @@ describe("capability inventory: caller guidance", () => {
|
||||
remediation: expect.stringContaining("resolve_containing_procedure"),
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves the most specific navigation mode failure", () => {
|
||||
expect(
|
||||
entry(
|
||||
"get_navigation_context",
|
||||
status({
|
||||
open: true,
|
||||
kind: "executable",
|
||||
capabilities: [
|
||||
{
|
||||
operation: "current_address",
|
||||
available: false,
|
||||
availability_code: "unsupported_host",
|
||||
reason: "Navigation requires macOS.",
|
||||
},
|
||||
{
|
||||
operation: "resolve_containing_procedure",
|
||||
available: true,
|
||||
reason: null,
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
available: false,
|
||||
reason: "unsupported_host",
|
||||
remediation: "Navigation requires macOS.",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -104,7 +104,7 @@ describe("tool contract surface", () => {
|
||||
expect(Object.keys(TOOL_EFFECTS).sort()).toEqual(names.sort());
|
||||
});
|
||||
|
||||
it("keeps exactly twenty-two additive session contracts", () => {
|
||||
it("keeps exactly twenty-three additive session contracts", () => {
|
||||
expect(
|
||||
SESSION_TOOL_CONTRACTS.map(({ name, kind }) => ({ name, kind })),
|
||||
).toEqual([
|
||||
@@ -128,6 +128,7 @@ describe("tool contract surface", () => {
|
||||
{ name: "verify_unknown_resolution", kind: "session" },
|
||||
{ name: "run_replay_machine", kind: "session" },
|
||||
{ name: "snapshot_evidence_bundle", kind: "session" },
|
||||
{ name: "release_evidence_bundle", kind: "session" },
|
||||
{ name: "get_navigation_context", kind: "session" },
|
||||
{ name: "inspect_address_context", kind: "session" },
|
||||
]);
|
||||
|
||||
@@ -87,6 +87,7 @@ describe("tool contract inventory", () => {
|
||||
"verify_unknown_resolution",
|
||||
"run_replay_machine",
|
||||
"snapshot_evidence_bundle",
|
||||
"release_evidence_bundle",
|
||||
"get_navigation_context",
|
||||
"inspect_address_context",
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
|
||||
import { applyToolInputJsonSchemaOverride } from "../../../src/contracts/toolSchemaJsonOverrides.js";
|
||||
import { z } from "zod";
|
||||
|
||||
const publicInputSchema = (name: string) => {
|
||||
const contract = TOOL_CONTRACTS.find((item) => item.name === name);
|
||||
if (contract === undefined) throw new Error(`Missing contract: ${name}`);
|
||||
return applyToolInputJsonSchemaOverride(
|
||||
name,
|
||||
z.toJSONSchema(contract.inputSchema, {
|
||||
target: "draft-07",
|
||||
unrepresentable: "any",
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
describe("public tool schema refinements", () => {
|
||||
it("requires complete web capture pairs and Evidence sources", () => {
|
||||
expect(publicInputSchema("compare_web_captures")).toMatchObject({
|
||||
oneOf: [
|
||||
{
|
||||
required: ["before", "after"],
|
||||
not: {
|
||||
anyOf: [
|
||||
{ required: ["before_scenario"] },
|
||||
{ required: ["after_scenario"] },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
required: ["before_scenario", "after_scenario"],
|
||||
not: {
|
||||
anyOf: [{ required: ["before"] }, { required: ["after"] }],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(publicInputSchema("trace_application_feature")).toMatchObject({
|
||||
oneOf: [
|
||||
{ required: ["application"] },
|
||||
{ required: ["application_evidence_id"] },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("publishes sensitive approval dependencies and exact readiness stages", () => {
|
||||
expect(
|
||||
JSON.stringify(publicInputSchema("inspect_electron_page")),
|
||||
).toContain('"source_capture_approved"');
|
||||
const readiness = publicInputSchema("evaluate_reconstruction_readiness");
|
||||
expect(readiness).toMatchObject({
|
||||
allOf: [
|
||||
{
|
||||
properties: {
|
||||
stages: {
|
||||
allOf: expect.arrayContaining([
|
||||
expect.objectContaining({ minContains: 1, maxContains: 1 }),
|
||||
]),
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(JSON.stringify(readiness)).toContain('"minContains":1');
|
||||
|
||||
const bundleSchema = JSON.stringify(
|
||||
publicInputSchema("analyze_web_bundle"),
|
||||
);
|
||||
expect(bundleSchema).toContain('"include_console_text"');
|
||||
expect(bundleSchema).toContain('"console_text_approved"');
|
||||
expect(bundleSchema).toContain('"include_json_body_shapes"');
|
||||
expect(bundleSchema).toContain('"json_body_schema_approved"');
|
||||
expect(bundleSchema).toContain('"include_websocket_shapes"');
|
||||
expect(bundleSchema).toContain('"websocket_shape_approved"');
|
||||
});
|
||||
|
||||
it("requires exactly two export-shape Evidence links", () => {
|
||||
const contract = TOOL_CONTRACTS.find(
|
||||
({ name }) => name === "compare_javascript_export_shapes",
|
||||
);
|
||||
if (contract === undefined)
|
||||
throw new Error("Missing export comparison contract");
|
||||
expect(
|
||||
JSON.stringify(
|
||||
z.toJSONSchema(contract.outputSchema, {
|
||||
target: "draft-07",
|
||||
unrepresentable: "any",
|
||||
}),
|
||||
),
|
||||
).toContain('"minItems":2');
|
||||
});
|
||||
|
||||
it("requires exactly one source for source-to-bundle comparison", () => {
|
||||
expect(publicInputSchema("compare_source_to_bundle")).toMatchObject({
|
||||
oneOf: [
|
||||
{ required: ["application"] },
|
||||
{ required: ["application_evidence_id"] },
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -198,7 +198,7 @@ describe("evidence ledger recording", () => {
|
||||
});
|
||||
expect(ledger.import(createEvidenceBundle([evidence]))).toEqual({
|
||||
ok: true,
|
||||
value: 0,
|
||||
value: { recordsAdded: 0, unknownsAdded: 0, changed: false },
|
||||
});
|
||||
expect(ledger.export().records).toEqual([evidence]);
|
||||
ledger.clear();
|
||||
|
||||
Reference in New Issue
Block a user