* refactor(test): colocate pure-domain tests and reduce test debt Move focused immutable domain/contracts/adapter tests from tests/composition/** beside their production owners under src/** as colocated *.test.ts/*.fixture.ts, and relocate persistence-shaped composition tests under tests/boundary/filesystem/**. Update import paths, the Vitest project topology (shared worker context for pure domain/contracts and recording-port service projects), the test migration ledger, testing docs, and AGENTS.md to match. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: remove test migration ledger The cutover is complete and the ledger is no longer referenced anywhere in source, scripts, or the docs gate. Drop the standalone artifact. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: clean up stale migration artifacts Remove empty directories left by the test migration and replace the "final cutover" language in docs/testing.md with standing PR guidance that no longer references the completed migration. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: repair CI failures from schema, knip, and stale generated artifacts Three root causes fixed: 1. catalog-schemas.mjs: valuesAt only traversed anyOf from Zod's toJSONSchema, not oneOf. The webScreenshotDiffSchema change to a discriminated union produces oneOf, so the product catalog generator could not derive the web_screenshot_diff schema version. Add oneOf traversal. 2. conformancePackage.ts: the test rewrite removed the only imports of ScenarioManifest, ReplayPlan, ShimPlan, and ExpectedEvidence, making them unused exports that knip flags. Remove the dead type aliases. 3. Regenerate stale artifacts (product catalog, MCP tool catalog, skill metadata, conformance manifest) that drifted from the source changes. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
153 lines
5.4 KiB
TypeScript
153 lines
5.4 KiB
TypeScript
import { rm, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
|
import { afterEach, describe, expect, test } from "vitest";
|
|
|
|
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 { parseConfig } from "../../../src/config.js";
|
|
import { createServer } from "../../../src/server/createServer.js";
|
|
import { observed } from "../../fixtures/analysisExecution.js";
|
|
import { startFakeV8Inspector } from "../../fixtures/fakeV8Inspector.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
describe("JavaScript runtime observation MCP tools", () => {
|
|
const resources: Array<{ close(): Promise<unknown> }> = [];
|
|
const temporary: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(resources.splice(0).map((item) => item.close()));
|
|
await Promise.all(
|
|
temporary
|
|
.splice(0)
|
|
.map((path) => rm(path, { recursive: true, force: true })),
|
|
);
|
|
});
|
|
|
|
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 listed = await client.callTool({
|
|
name: "list_javascript_runtime_targets",
|
|
arguments: {
|
|
inspector_endpoint: inspector.endpoint,
|
|
allowed_file_roots: [root],
|
|
allowed_origins: [],
|
|
approved: true,
|
|
},
|
|
});
|
|
expect(listed.isError).not.toBe(true);
|
|
expect(listed.structuredContent).toMatchObject({
|
|
result: {
|
|
targets: { items: [{ target_id: inspector.targetId }] },
|
|
},
|
|
});
|
|
|
|
const observedRuntime = await client.callTool({
|
|
name: "observe_javascript_runtime",
|
|
arguments: {
|
|
inspector_endpoint: inspector.endpoint,
|
|
allowed_file_roots: [root],
|
|
allowed_origins: [],
|
|
target_id: inspector.targetId,
|
|
runtime_kind: "node",
|
|
approved: true,
|
|
observation_ms: 10,
|
|
},
|
|
});
|
|
expect(observedRuntime.isError).not.toBe(true);
|
|
expect(observedRuntime.structuredContent).toMatchObject({
|
|
result: {
|
|
target: {
|
|
target_id: inspector.targetId,
|
|
runtime_kind: "node",
|
|
runtime_kind_authority: "caller-declared-unverified",
|
|
},
|
|
scripts: {
|
|
items: [
|
|
expect.objectContaining({
|
|
location: { kind: "file", file_path: entry },
|
|
}),
|
|
],
|
|
},
|
|
},
|
|
});
|
|
const evidenceId = evidenceIdFrom(observedRuntime.structuredContent);
|
|
expect(session.evidenceById(evidenceId)).toBeDefined();
|
|
expect(inspector.commands.map(({ method }) => method)).toEqual([
|
|
"Runtime.enable",
|
|
"Debugger.enable",
|
|
]);
|
|
const direct = await observeJavaScriptRuntime(
|
|
new V8InspectorProvider(),
|
|
authority.value,
|
|
{
|
|
inspector_endpoint: inspector.endpoint,
|
|
allowed_file_roots: [root],
|
|
allowed_origins: [],
|
|
target_id: inspector.targetId,
|
|
runtime_kind: "node",
|
|
approved: true,
|
|
observation_ms: 10,
|
|
limits: {
|
|
max_events: 10_000,
|
|
max_scripts: 2_000,
|
|
max_execution_contexts: 1_000,
|
|
max_location_bytes: 16_384,
|
|
max_total_metadata_bytes: 4_194_304,
|
|
},
|
|
},
|
|
);
|
|
expect(direct.ok).toBe(true);
|
|
if (direct.ok) expect(evidenceId).toBe(direct.value.evidence_id);
|
|
});
|
|
});
|
|
|
|
const evidenceIdFrom = (value: unknown): string => {
|
|
if (typeof value !== "object" || value === null)
|
|
throw new TypeError("Missing structured result");
|
|
const evidenceId = Reflect.get(value, "evidence_id");
|
|
if (typeof evidenceId !== "string")
|
|
throw new TypeError("Missing Evidence ID");
|
|
return evidenceId;
|
|
};
|