Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

test(mcp): remove cache and event order dependence from fault probes

morlutob8510ee00b7c
diff --git a/docs/testing.md b/docs/testing.md
index d5a4cf4bc..93a65ffcc 100644
--- a/docs/testing.md
+++ b/docs/testing.md
@@ -98,6 +98,18 @@ isolated filesystem boundary tests because it loads both source and compiled
module graphs. Adapter, other boundary, acceptance, and process-global projects
retain per-file isolation. See `vitest.config.ts` for current settings.
+Inject producer faults through scoped dependencies in shared workers: a module
+mock cannot replace a consumer that was imported earlier. Check these tests
+with the consumer preloaded as well as alone. For simulated protocol traces,
+use an acknowledged event barrier before asserting complete observations;
+a zero-duration capture does not guarantee queued events have arrived.
+
+Check advertised schemas after SDK conversion for every supported schema
+profile. Meta-schema validity does not establish client acceptance or useful
+rendered declarations. Keep canonical rejection checks separate from the
+intentionally reduced compact advertisement, and probe actual client renderers
+when changing schema representations.
+
The reused CLI boundary workers cap V8 old space at 384 MiB, based on their
profiled allocation and cleanup behavior. This encourages collection between
files; spawned REA processes retain their own heap settings.
diff --git a/src/ida/IdaMcpConnection.ts b/src/ida/IdaMcpConnection.ts
index 1db07b861..210b80c67 100644
--- a/src/ida/IdaMcpConnection.ts
+++ b/src/ida/IdaMcpConnection.ts
@@ -45,6 +45,10 @@ export interface IdaMcpConnection {
detach(): void;
}
+export type IdaMcpConnectionDependencies = Readonly<{
+ createDiagnosticRedactor?: typeof createIdaDiagnosticRedactor;
+}>;
+
const toolResultSchema = z.object({
isError: z.boolean().optional(),
structuredContent: z.record(z.string(), z.unknown()).optional(),
@@ -332,9 +336,12 @@ const retainedTransportCause = (cause: unknown, message: string): Error => {
export const createIdaMcpConnection = (
config: IdaConfiguration,
environment: Readonly<NodeJS.ProcessEnv>,
+ dependencies: IdaMcpConnectionDependencies = {},
): IdaMcpConnection => {
const client = new Client({ name: "rea-ida-provider", version: "1" });
- const redactor = createIdaDiagnosticRedactor(config);
+ const redactor = (
+ dependencies.createDiagnosticRedactor ?? createIdaDiagnosticRedactor
+ )(config);
let stderr = Buffer.alloc(0);
let stderrBytes = 0;
const transportFailure = (
diff --git a/tests/boundary/mcp/browserMcp.test.ts b/tests/boundary/mcp/browserMcp.test.ts
index b13d17df5..779888cd8 100644
--- a/tests/boundary/mcp/browserMcp.test.ts
+++ b/tests/boundary/mcp/browserMcp.test.ts
@@ -41,6 +41,7 @@ it(
sessionTimeline: "same_origin",
webMcpTools: true,
sensitiveShapes: true,
+ eventsBeforeReply: ["Network.enable"],
});
browsers.push(browser);
const connected = await connectBrowser();
diff --git a/tests/boundary/mcp/idaTransport.test.ts b/tests/boundary/mcp/idaTransport.test.ts
index 2844d8eca..1bb8db727 100644
--- a/tests/boundary/mcp/idaTransport.test.ts
+++ b/tests/boundary/mcp/idaTransport.test.ts
@@ -1,45 +1,20 @@
import { createServer } from "node:http";
import { inspect } from "node:util";
import { ProtocolError } from "@modelcontextprotocol/client";
-import { afterEach, expect, it, vi } from "vitest";
+import { afterEach, expect, it } from "vitest";
import { constants } from "node:buffer";
import { IdaDiagnosticResourceError } from "../../../src/ida/IdaDiagnosticWriter.js";
+import { createIdaDiagnosticRedactor } from "../../../src/ida/IdaDiagnosticRedactor.js";
import { z } from "zod";
import { AnalysisProtocolError } from "../../../src/domain/analysisErrorCore.js";
import type { JsonValue } from "../../../src/domain/jsonValue.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { ProviderAdapterError } from "../../../src/domain/providerAdapterError.js";
import { createIdaMcpConnection } from "../../../src/ida/IdaMcpConnection.js";
-import type { IdaMcpConnection } from "../../../src/ida/IdaMcpConnection.js";
-
-// Inject an owned capacity failure at the producer while retaining the real
-// SDK. Small writer-limit tests separately exercise actual expansion checks.
-vi.mock("../../../src/ida/IdaDiagnosticRedactor.js", async (importOriginal) => {
- const actual =
- await importOriginal<
- typeof import("../../../src/ida/IdaDiagnosticRedactor.js")
- >();
- return {
- ...actual,
- createIdaDiagnosticRedactor: (
- config: Parameters<typeof actual.createIdaDiagnosticRedactor>[0],
- ) => {
- const redactor = actual.createIdaDiagnosticRedactor(config);
- return {
- ...redactor,
- text: redactor.text,
- json: (message: string) => {
- if (message === "fixture-resource-boundary")
- throw new IdaDiagnosticResourceError(
- message.length,
- constants.MAX_STRING_LENGTH + 1,
- );
- return redactor.json(message);
- },
- };
- },
- };
-});
+import type {
+ IdaMcpConnection,
+ IdaMcpConnectionDependencies,
+} from "../../../src/ida/IdaMcpConnection.js";
const cleanups: (() => Promise<void>)[] = [];
afterEach(async () => {
@@ -72,6 +47,7 @@ type IdaTransportFixtureOptions = {
readonly toolContentType?: string;
readonly toolResponseBody?: string | Buffer;
readonly configurationHeaders?: Readonly<Record<string, string>>;
+ readonly connectionDependencies?: IdaMcpConnectionDependencies;
};
const fixture = async ({
redirectUrl,
@@ -85,6 +61,7 @@ const fixture = async ({
toolContentType = "application/json",
toolResponseBody,
configurationHeaders = { Authorization: "Bearer transport-fixture-secret" },
+ connectionDependencies,
}: IdaTransportFixtureOptions = {}) => {
const methods: string[] = [];
const headers: (string | undefined)[] = [];
@@ -208,6 +185,7 @@ const fixture = async ({
timeoutMs: 2000,
},
{},
+ connectionDependencies,
);
cleanups.push(() => connection.close());
return {
@@ -1002,7 +980,21 @@ it.each([200, 500])(
async (toolStatus) => {
const { connection } = await fixture({
toolStatus,
- toolResponseBody: "fixture-resource-boundary",
+ toolResponseBody: "malformed fixture JSON",
+ connectionDependencies: {
+ createDiagnosticRedactor: (config) => {
+ const redactor = createIdaDiagnosticRedactor(config);
+ return {
+ ...redactor,
+ json(message: string) {
+ throw new IdaDiagnosticResourceError(
+ message.length,
+ constants.MAX_STRING_LENGTH + 1,
+ );
+ },
+ };
+ },
+ },
});
await connection.connect();
const failure = await connection