refactor(tools): return complete analysis results inline
This commit is contained in:
@@ -272,7 +272,6 @@ const connectBrowser = async (browser: FakeCdpBrowser) => {
|
||||
permissionAuthority: authority.value,
|
||||
availabilityPolicy: () => ({
|
||||
processCaptureEnabled: false,
|
||||
evidenceFileRoots: 0,
|
||||
investigationInputRoots: 0,
|
||||
browserObservationEnabled: true,
|
||||
}),
|
||||
|
||||
@@ -176,7 +176,6 @@ describe("browser scenario MCP tool", () => {
|
||||
permissionAuthority: authority.value,
|
||||
availabilityPolicy: () => ({
|
||||
processCaptureEnabled: false,
|
||||
evidenceFileRoots: 0,
|
||||
investigationInputRoots: 0,
|
||||
browserObservationEnabled: true,
|
||||
browserScenarioEnabled: true,
|
||||
@@ -208,7 +207,6 @@ describe("browser scenario MCP tool", () => {
|
||||
],
|
||||
},
|
||||
capture: { after_each_step: [], at_end: ["url"], events: [] },
|
||||
limits: { max_duration_ms: 60_000 },
|
||||
});
|
||||
|
||||
const captured = await client.callTool({
|
||||
|
||||
@@ -36,7 +36,7 @@ const sourceEvidence = (label: string) =>
|
||||
);
|
||||
|
||||
describe("bundle comparison MCP integration", () => {
|
||||
it("reads two approved bounded bundle files and records a compact result", async () => {
|
||||
it("reads caller-selected bundle files and records a compact result", async () => {
|
||||
const root = await createTestTempDirectory("rea-bundle-mcp-");
|
||||
roots.push(root);
|
||||
const leftPath = join(root, "left.json");
|
||||
@@ -53,7 +53,7 @@ describe("bundle comparison MCP integration", () => {
|
||||
serializeEvidenceBundle(createEvidenceBundle([rightRecord])),
|
||||
),
|
||||
]);
|
||||
const connected = await connect(root);
|
||||
const connected = await connect();
|
||||
try {
|
||||
const result = await connected.client.callTool({
|
||||
name: "compare_bundles",
|
||||
@@ -78,7 +78,7 @@ describe("bundle comparison MCP integration", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects a bundle path outside the approved root", async () => {
|
||||
it("reads a bundle path outside any configured roots", async () => {
|
||||
const root = await createTestTempDirectory("rea-bundle-root-");
|
||||
const outside = await createTestTempDirectory("rea-bundle-outside-");
|
||||
roots.push(root, outside);
|
||||
@@ -89,7 +89,7 @@ describe("bundle comparison MCP integration", () => {
|
||||
writeFile(leftPath, encoded),
|
||||
writeFile(rightPath, encoded),
|
||||
]);
|
||||
const connected = await connect(root);
|
||||
const connected = await connect();
|
||||
try {
|
||||
const result = await connected.client.callTool({
|
||||
name: "compare_bundles",
|
||||
@@ -98,36 +98,9 @@ describe("bundle comparison MCP integration", () => {
|
||||
right_bundle_path: rightPath,
|
||||
},
|
||||
});
|
||||
expect(result).toMatchObject({
|
||||
isError: true,
|
||||
structuredContent: { error: { code: "outside_approved_root" } },
|
||||
});
|
||||
} finally {
|
||||
await connected.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects an oversized approved bundle", async () => {
|
||||
const root = await createTestTempDirectory("rea-bundle-size-");
|
||||
roots.push(root);
|
||||
const leftPath = join(root, "left.json");
|
||||
const rightPath = join(root, "right.json");
|
||||
await Promise.all([
|
||||
writeFile(leftPath, " ".repeat(2_000)),
|
||||
writeFile(rightPath, serializeEvidenceBundle(createEvidenceBundle([]))),
|
||||
]);
|
||||
const connected = await connect(root, 1_024);
|
||||
try {
|
||||
const result = await connected.client.callTool({
|
||||
name: "compare_bundles",
|
||||
arguments: {
|
||||
left_bundle_path: leftPath,
|
||||
right_bundle_path: rightPath,
|
||||
},
|
||||
});
|
||||
expect(result).toMatchObject({
|
||||
isError: true,
|
||||
structuredContent: { error: { code: "truncated" } },
|
||||
expect(result.isError).not.toBe(true);
|
||||
expect(result.structuredContent).toMatchObject({
|
||||
result: { status: "unchanged" },
|
||||
});
|
||||
} finally {
|
||||
await connected.close();
|
||||
@@ -135,21 +108,13 @@ describe("bundle comparison MCP integration", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const connect = async (root: string, maxBytes = 1024 * 1024) => {
|
||||
const connect = async () => {
|
||||
const session = createTestBinarySession(() => ({
|
||||
health: () => Promise.resolve(),
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}));
|
||||
const server = createServer(session, session, {
|
||||
evidenceFilePolicy: {
|
||||
roots: [root],
|
||||
maxBytes,
|
||||
maxDepth: 68,
|
||||
maxStringLength: 1024 * 1024,
|
||||
maxNodes: 100_000,
|
||||
},
|
||||
});
|
||||
const server = createServer(session, session);
|
||||
const client = new Client({ name: "bundle-comparison-test", version: "1" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
|
||||
@@ -71,7 +71,6 @@ it("exposes root-confined Electron discovery and inspection as Evidence", async
|
||||
permissionAuthority: authority.value,
|
||||
availabilityPolicy: () => ({
|
||||
processCaptureEnabled: false,
|
||||
evidenceFileRoots: 0,
|
||||
investigationInputRoots: 1,
|
||||
electronObservationEnabled: true,
|
||||
}),
|
||||
@@ -222,7 +221,6 @@ it("exposes active Electron scenarios through the separately granted MCP boundar
|
||||
permissionAuthority: authority.value,
|
||||
availabilityPolicy: () => ({
|
||||
processCaptureEnabled: false,
|
||||
evidenceFileRoots: 0,
|
||||
investigationInputRoots: 0,
|
||||
electronAutomationEnabled: true,
|
||||
}),
|
||||
@@ -297,7 +295,6 @@ it("exposes the target-free static JavaScript application workflow", async () =>
|
||||
permissionAuthority: authority.value,
|
||||
availabilityPolicy: () => ({
|
||||
processCaptureEnabled: false,
|
||||
evidenceFileRoots: 0,
|
||||
investigationInputRoots: 1,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
} from "../../../src/domain/jsonValue.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { observed } from "../../fixtures/analysisExecution.js";
|
||||
import type { EvidenceFilePolicy } from "../../../src/domain/evidenceBundle.js";
|
||||
import type { PermissionAuthority } from "../../../src/application/PermissionAuthority.js";
|
||||
|
||||
it("aggregates comparison Evidence and records an approved runtime gap", async () => {
|
||||
@@ -287,25 +286,17 @@ it("cannot omit a session-owned active unknown from reconstruction input", async
|
||||
}
|
||||
});
|
||||
|
||||
const connected = async (
|
||||
evidenceFilePolicy?: EvidenceFilePolicy,
|
||||
investigationInputRoots: readonly string[] = evidenceFilePolicy?.roots ?? [],
|
||||
permissionAuthority?: PermissionAuthority,
|
||||
) => {
|
||||
const connected = async (permissionAuthority?: PermissionAuthority) => {
|
||||
const session = createTestBinarySession(() => ({
|
||||
health: () => Promise.resolve(),
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}));
|
||||
const server = createServer(session, session, {
|
||||
...(evidenceFilePolicy === undefined
|
||||
? {}
|
||||
: {
|
||||
evidenceFilePolicy,
|
||||
investigationInputRoots,
|
||||
}),
|
||||
...(permissionAuthority === undefined ? {} : { permissionAuthority }),
|
||||
});
|
||||
const server = createServer(
|
||||
session,
|
||||
session,
|
||||
permissionAuthority === undefined ? {} : { permissionAuthority },
|
||||
);
|
||||
const client = new Client({ name: "investigation-test", version: "1" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
|
||||
@@ -9,7 +9,11 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { loadConfiguredPermissionAuthority } from "../../../src/application/PermissionConfiguration.js";
|
||||
import { observeJavaScriptRuntime } from "../../../src/application/JavaScriptRuntimeObservationService.js";
|
||||
import { V8InspectorProvider } from "../../../src/browser/V8InspectorProvider.js";
|
||||
import { observeJavaScriptRuntimeInputSchema } from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
import {
|
||||
javascriptRuntimeObservationSchema,
|
||||
javascriptRuntimeTargetListSchema,
|
||||
observeJavaScriptRuntimeInputSchema,
|
||||
} from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
import { parseConfig } from "../../../src/config.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { observed } from "../../fixtures/analysisExecution.js";
|
||||
@@ -29,43 +33,89 @@ describe("JavaScript runtime observation MCP tools", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("accepts long caller windows and complete observation metadata", () => {
|
||||
const repeated = (count: number): string[] =>
|
||||
Array.from({ length: count }, (_, index) => `item-${index}`);
|
||||
const scope = {
|
||||
inspector_endpoint: "http://127.0.0.1:9222",
|
||||
allowed_file_roots: ["/tmp/rea-runtime"],
|
||||
allowed_origins: [],
|
||||
};
|
||||
expect(
|
||||
observeJavaScriptRuntimeInputSchema.parse({
|
||||
...scope,
|
||||
target_id: "target",
|
||||
observation_ms: 2_147_483_648,
|
||||
}).observation_ms,
|
||||
).toBe(2_147_483_648);
|
||||
expect(
|
||||
javascriptRuntimeTargetListSchema.parse({
|
||||
runtime: {
|
||||
product: "Node.js",
|
||||
protocol_version: "1.0",
|
||||
v8_version: null,
|
||||
},
|
||||
targets: [],
|
||||
excluded: {
|
||||
outside_file_roots: 0,
|
||||
outside_origins: 0,
|
||||
unsupported_location: 0,
|
||||
unconnectable: 0,
|
||||
},
|
||||
limitations: repeated(101),
|
||||
}).limitations,
|
||||
).toHaveLength(101);
|
||||
|
||||
const unknowns = repeated(101);
|
||||
const limitations = repeated(101);
|
||||
expect(
|
||||
javascriptRuntimeObservationSchema.parse({
|
||||
runtime: {
|
||||
product: "Node.js",
|
||||
protocol_version: "1.0",
|
||||
v8_version: null,
|
||||
},
|
||||
target: {
|
||||
target_id: "target",
|
||||
protocol_type: "node",
|
||||
attached: false,
|
||||
location: { kind: "file", file_path: "/tmp/rea-runtime/main.js" },
|
||||
runtime_kind: "node",
|
||||
runtime_kind_authority: "caller-declared-unverified",
|
||||
},
|
||||
capture: {
|
||||
observation_ms: 10_001,
|
||||
events_observed: 0,
|
||||
events_retained: 0,
|
||||
events_dropped: 0,
|
||||
metadata_bytes_retained: 0,
|
||||
truncated: false,
|
||||
truncation_reasons: repeated(21),
|
||||
},
|
||||
scripts: {
|
||||
items: [],
|
||||
observed_total: 0,
|
||||
excluded: {
|
||||
outside_file_roots: 0,
|
||||
outside_origins: 0,
|
||||
unsupported_location: 0,
|
||||
invalid_protocol_value: 0,
|
||||
},
|
||||
},
|
||||
execution_contexts: [],
|
||||
directly_observed: repeated(21),
|
||||
unavailable_without_instrumentation: repeated(21),
|
||||
unknowns,
|
||||
limitations,
|
||||
}),
|
||||
).toMatchObject({ unknowns, limitations });
|
||||
});
|
||||
|
||||
test("lists and observes one target as retained Evidence", async () => {
|
||||
const root = await createTestTempDirectory("rea-v8-mcp-");
|
||||
temporary.push(root);
|
||||
const entry = join(root, "entry.js");
|
||||
await writeFile(entry, "export const value = 1;\n");
|
||||
const inspector = await startFakeV8Inspector({
|
||||
targetUrl: pathToFileURL(entry).href,
|
||||
});
|
||||
resources.push(inspector);
|
||||
const config = parseConfig({
|
||||
REA_V8_INSPECTOR_OBSERVE_ENABLED: "true",
|
||||
REA_V8_INSPECTOR_ENDPOINTS_JSON: JSON.stringify([inspector.endpoint]),
|
||||
REA_V8_INSPECTOR_FILE_ROOTS_JSON: JSON.stringify([root]),
|
||||
});
|
||||
if (!config.ok) throw config.error;
|
||||
const authority = await loadConfiguredPermissionAuthority(config.value);
|
||||
if (!authority.ok) throw authority.error;
|
||||
const session = createTestBinarySession(() => ({
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}));
|
||||
const server = createServer(session, session, {
|
||||
javascriptRuntimeObservation: new V8InspectorProvider(),
|
||||
permissionAuthority: authority.value,
|
||||
availabilityPolicy: () => ({
|
||||
processCaptureEnabled: false,
|
||||
evidenceFileRoots: 0,
|
||||
investigationInputRoots: 0,
|
||||
v8InspectorObservationEnabled: true,
|
||||
}),
|
||||
});
|
||||
const client = new Client({ name: "v8-mcp-test", version: "1" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server, session);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const { entry, inspector, authority, client, session } =
|
||||
await createObservationClient(root, resources);
|
||||
|
||||
const listed = await client.callTool({
|
||||
name: "list_javascript_runtime_targets",
|
||||
@@ -115,23 +165,70 @@ describe("JavaScript runtime observation MCP tools", () => {
|
||||
"Runtime.enable",
|
||||
"Debugger.enable",
|
||||
]);
|
||||
const direct = await observeJavaScriptRuntime(
|
||||
new V8InspectorProvider(),
|
||||
authority.value,
|
||||
observeJavaScriptRuntimeInputSchema.parse({
|
||||
inspector_endpoint: inspector.endpoint,
|
||||
allowed_file_roots: [root],
|
||||
allowed_origins: [],
|
||||
target_id: inspector.targetId,
|
||||
runtime_kind: "node",
|
||||
observation_ms: 10,
|
||||
}),
|
||||
);
|
||||
const direct = await observeDirectly(root, inspector, authority);
|
||||
expect(direct.ok).toBe(true);
|
||||
if (direct.ok) expect(evidenceId).toBe(direct.value.evidence_id);
|
||||
});
|
||||
});
|
||||
|
||||
const createObservationClient = async (
|
||||
root: string,
|
||||
resources: Array<{ close(): Promise<unknown> }>,
|
||||
) => {
|
||||
const entry = join(root, "entry.js");
|
||||
await writeFile(entry, "export const value = 1;\n");
|
||||
const inspector = await startFakeV8Inspector({
|
||||
targetUrl: pathToFileURL(entry).href,
|
||||
});
|
||||
resources.push(inspector);
|
||||
const config = parseConfig({
|
||||
REA_V8_INSPECTOR_OBSERVE_ENABLED: "true",
|
||||
REA_V8_INSPECTOR_ENDPOINTS_JSON: JSON.stringify([inspector.endpoint]),
|
||||
REA_V8_INSPECTOR_FILE_ROOTS_JSON: JSON.stringify([root]),
|
||||
});
|
||||
if (!config.ok) throw config.error;
|
||||
const authority = await loadConfiguredPermissionAuthority(config.value);
|
||||
if (!authority.ok) throw authority.error;
|
||||
const session = createTestBinarySession(() => ({
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
close: () => Promise.resolve(),
|
||||
}));
|
||||
const server = createServer(session, session, {
|
||||
javascriptRuntimeObservation: new V8InspectorProvider(),
|
||||
permissionAuthority: authority.value,
|
||||
availabilityPolicy: () => ({
|
||||
processCaptureEnabled: false,
|
||||
investigationInputRoots: 0,
|
||||
v8InspectorObservationEnabled: true,
|
||||
}),
|
||||
});
|
||||
const client = new Client({ name: "v8-mcp-test", version: "1" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server, session);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return { entry, inspector, authority: authority.value, client, session };
|
||||
};
|
||||
|
||||
const observeDirectly = (
|
||||
root: string,
|
||||
inspector: Awaited<ReturnType<typeof startFakeV8Inspector>>,
|
||||
authority: Parameters<typeof observeJavaScriptRuntime>[1],
|
||||
) =>
|
||||
observeJavaScriptRuntime(
|
||||
new V8InspectorProvider(),
|
||||
authority,
|
||||
observeJavaScriptRuntimeInputSchema.parse({
|
||||
inspector_endpoint: inspector.endpoint,
|
||||
allowed_file_roots: [root],
|
||||
allowed_origins: [],
|
||||
target_id: inspector.targetId,
|
||||
runtime_kind: "node",
|
||||
observation_ms: 10,
|
||||
}),
|
||||
);
|
||||
|
||||
const evidenceIdFrom = (value: unknown): string => {
|
||||
if (typeof value !== "object" || value === null)
|
||||
throw new TypeError("Missing structured result");
|
||||
|
||||
@@ -62,7 +62,6 @@ it("opens a managed PE and executes the managed static provider through MCP", as
|
||||
}),
|
||||
availabilityPolicy: () => ({
|
||||
processCaptureEnabled: false,
|
||||
evidenceFileRoots: 0,
|
||||
investigationInputRoots: 0,
|
||||
browserObservationEnabled: false,
|
||||
electronObservationEnabled: false,
|
||||
|
||||
@@ -132,7 +132,6 @@ describe("server and catalog identity", () => {
|
||||
it("reports composed, host, and target-specific availability truthfully", () => {
|
||||
const policy = {
|
||||
processCaptureEnabled: true,
|
||||
evidenceFileRoots: 1,
|
||||
investigationInputRoots: 1,
|
||||
};
|
||||
const composed = buildCapabilityInventory(
|
||||
|
||||
@@ -43,17 +43,8 @@ export const createSessionMcpHarness = async (
|
||||
resolveAnalysisProfile: () =>
|
||||
Promise.resolve(ok({ profile: SNAPSHOT_PROFILE, compatibility: {} })),
|
||||
});
|
||||
const filePolicy = {
|
||||
roots: [root],
|
||||
maxBytes: 1024 * 1024,
|
||||
maxDepth: 68,
|
||||
maxStringLength: 1024,
|
||||
maxNodes: 10_000,
|
||||
};
|
||||
const server = createServer(session, session, {
|
||||
logger: silentLogger,
|
||||
evidenceFilePolicy: filePolicy,
|
||||
analysisSnapshotFilePolicy: filePolicy,
|
||||
});
|
||||
const mcp = new Client({ name: "session-test", version: "1.0.0" });
|
||||
const [clientTransport, serverTransport] =
|
||||
|
||||
Reference in New Issue
Block a user