feat(electron): reconcile static artifacts with passive runtime

This commit is contained in:
N0zoM1z0
2026-07-16 09:55:21 +09:00
committed by N0zoM1z0
parent 3fa2304bc7
commit 8c67dbd49e
258 changed files with 7609 additions and 650 deletions
+20 -1
View File
@@ -5,6 +5,7 @@ import { BinarySession } from "../src/application/BinarySession.js";
import { loadConfiguredPermissionAuthority } from "../src/application/PermissionConfiguration.js";
import { CdpBrowserProvider } from "../src/browser/CdpBrowserProvider.js";
import { parseConfig } from "../src/config.js";
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "../src/contracts/javascriptRuntimeReconciliationExample.js";
import { createServer } from "../src/server/createServer.js";
import { observed } from "./fixtures/analysisExecution.js";
import {
@@ -36,7 +37,7 @@ describe("browser MCP tools", () => {
const connected = await connectBrowser(browser);
const tools = await connected.client.listTools();
expect(tools.tools).toHaveLength(79);
expect(tools.tools).toHaveLength(80);
expect(tools.tools.map(({ name }) => name)).toEqual(
expect.arrayContaining([
"list_browser_targets",
@@ -99,6 +100,7 @@ describe("browser MCP tools", () => {
json_body_schema_approved: true,
include_websocket_shapes: true,
websocket_shape_approved: true,
include_script_sources: true,
},
});
expect(inspected.isError).not.toBe(true);
@@ -117,6 +119,23 @@ describe("browser MCP tools", () => {
},
},
});
const reconciled = await connected.client.callTool({
name: "reconcile_javascript_runtime",
arguments: {
static_layers:
JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE.static_layers,
runtime_observations: [inspected.structuredContent],
},
});
expect(reconciled.isError).not.toBe(true);
expect(reconciled.structuredContent).toMatchObject({
operation: "reconcile_javascript_runtime",
provider: { id: "rea-javascript-runtime-reconciliation" },
normalized_result: { summary: { runtime_scripts: 1 } },
});
expect(JSON.stringify(reconciled.structuredContent)).not.toContain(
"source-secret",
);
const analyzed = await connected.client.callTool({
name: "analyze_web_bundle",
arguments: {
+55
View File
@@ -2,6 +2,9 @@ import { describe, expect, it } from "vitest";
import { listBrowserTargets } from "../src/application/BrowserObservationService.js";
import { createPermissionAuthority } from "../src/application/PermissionAuthority.js";
import { CdpCaptureCompleteness } from "../src/browser/CdpCaptureCompleteness.js";
import { CdpCaptureEvents } from "../src/browser/CdpCaptureEvents.js";
import { ingestElectronScriptEvent } from "../src/browser/CdpElectronScriptEvents.js";
import {
browserEndpointSchema,
browserOriginSchema,
@@ -188,6 +191,58 @@ describe("browser observation contracts", () => {
).toBe(true);
});
it("removes stale frame attribution when CDP destroys execution contexts", () => {
const request = inspectWebPageInputSchema.parse({
cdp_endpoint: "http://127.0.0.1:9222",
allowed_origins: ["https://app.example.test"],
target_id: "page-1",
approved: true,
});
const browser = new CdpCaptureEvents(
request,
new Set(["https://app.example.test"]),
);
browser.beginAuthorizedFrame("frame-old");
browser.ingest({
method: "Runtime.executionContextCreated",
params: { context: { id: 7, auxData: { frameId: "frame-old" } } },
});
browser.ingest({
method: "Runtime.executionContextDestroyed",
params: { executionContextId: 7 },
});
browser.ingest({
method: "Debugger.scriptParsed",
params: {
scriptId: "script-1",
url: "https://app.example.test/app.js",
executionContextId: 7,
},
});
const script = browser.scripts.get("script-1");
if (script === undefined) throw new TypeError("Expected captured script");
expect(browser.frameForScript(script, new Set(["frame-old"]))).toBeNull();
const electronFrames = new Map<string, string>();
const completeness = new CdpCaptureCompleteness();
ingestElectronScriptEvent({
event: {
method: "Runtime.executionContextCreated",
params: { context: { id: 7, auxData: { frameId: "frame-old" } } },
},
scripts: [],
executionContextFrames: electronFrames,
completeness,
});
ingestElectronScriptEvent({
event: { method: "Runtime.executionContextsCleared", params: {} },
scripts: [],
executionContextFrames: electronFrames,
completeness,
});
expect(electronFrames.size).toBe(0);
});
it("removes credentials, query values, and fragments from observed URLs", () => {
expect(
sanitizeBrowserUrl(
+5
View File
@@ -275,6 +275,7 @@ describe("CdpBrowserProvider", () => {
expect(result.value.scripts.items[0]?.script_key).toMatch(
/^scr_[a-f0-9]{64}$/u,
);
expect(result.value.scripts.items[0]?.frame_id).toBe("frame-main");
expect(result.value.scripts.items[0]?.source_map_url).toBe(
`${browser.allowedOrigin}/app.js.map?token=%5BREDACTED%5D`,
);
@@ -312,6 +313,10 @@ describe("CdpBrowserProvider", () => {
]);
expect(result.value.console.events[0]?.argument_types).toEqual(["string"]);
expect(result.value.workers).toHaveLength(1);
expect(result.value.workers[0]).toMatchObject({
opener_target_id: "allowed-page",
parent_frame_id: null,
});
expect(result.value.metadata).toMatchObject({
headers_allowlisted: true,
responses: [
+1 -1
View File
@@ -56,7 +56,7 @@ describe("CdpElectronProvider", () => {
expect(listed.value.excluded).toEqual({
outside_root: 0,
unsupported_url: 3,
non_page: 1,
non_page: 2,
});
const inspected = await provider.inspectPage(
+3 -3
View File
@@ -58,7 +58,7 @@ describe("tool contract surface", () => {
...BROWSER_TOOL_CONTRACTS,
...ELECTRON_TOOL_CONTRACTS,
];
expect(contracts).toHaveLength(61);
expect(contracts).toHaveLength(62);
for (const contract of contracts) {
const inputSchema = contractJsonSchema(contract.inputSchema);
const outputSchema = contractJsonSchema(contract.outputSchema);
@@ -148,7 +148,7 @@ describe("tool contract surface", () => {
}
});
it("publishes no unconstrained output-schema holes across all 79 tools", () => {
it("publishes no unconstrained output-schema holes across all 80 tools", () => {
const contracts = [
...OFFICIAL_TOOL_CONTRACTS,
...ENHANCED_TOOL_CONTRACTS,
@@ -158,7 +158,7 @@ describe("tool contract surface", () => {
...ELECTRON_TOOL_CONTRACTS,
...SESSION_TOOL_CONTRACTS,
];
expect(contracts).toHaveLength(79);
expect(contracts).toHaveLength(80);
for (const contract of contracts) {
const schema = contractJsonSchema(contract.outputSchema);
expect(emptySchemaPaths(schema), contract.name).toEqual([]);
+39
View File
@@ -12,6 +12,7 @@ import {
type FakeCdpBrowser,
} from "./fixtures/fakeCdpBrowser.js";
import { writeElectronBoundaryFixture } from "./fixtures/electronBoundaryApplication.js";
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "../src/contracts/javascriptRuntimeReconciliationExample.js";
const execute = promisify(execFile);
const INTEGRATION_TEST_TIMEOUT_MS = 20_000;
@@ -115,6 +116,44 @@ describe("Electron CLI parity", () => {
},
INTEGRATION_TEST_TIMEOUT_MS,
);
it(
"reads a file and returns the derived static/runtime reconciliation contract",
async () => {
const root = await mkdtemp(join(tmpdir(), "rea-runtime-cli-"));
const inputPath = join(root, "reconciliation.json");
temporary.push(root);
await writeFile(
inputPath,
JSON.stringify(JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE),
);
const reconciled = await runCli(
["reconcile-javascript-runtime", inputPath, "--json"],
process.env,
);
expect(reconciled).toMatchObject({
operation: "reconcile_javascript_runtime",
provider: { id: "rea-javascript-runtime-reconciliation" },
normalized_result: {
schema_version: 1,
summary: { runtime_scripts: 1, matched: 1 },
source_map_authority: { used_for_primary_matching: false },
},
});
const missingPath = join(root, "missing.json");
const missing = await runCli(
["reconcile-javascript-runtime", missingPath, "--json"],
process.env,
);
expect(missing).toMatchObject({
input_path: missingPath,
input_reason: "read-failed",
maximum_input_bytes: 64 * 1_024 * 1_024,
});
},
INTEGRATION_TEST_TIMEOUT_MS,
);
});
const runCli = async (
+48 -2
View File
@@ -39,7 +39,15 @@ describe("Electron MCP tools", () => {
const root = await mkdtemp(join(tmpdir(), "rea-electron-mcp-"));
temporary.push(root);
await writeFile(join(root, "index.html"), "<script src='app.js'></script>");
await writeFile(join(root, "app.js"), "export const app = true;");
await writeFile(
join(root, "app.js"),
"export const observed = 'source-secret';",
);
await writeFile(
join(root, "package.json"),
JSON.stringify({ name: "runtime-fixture", renderer: "index.html" }),
);
await writeFile(join(root, "worker.js"), "self.onmessage = () => {};\n");
const browser = await startFakeCdpBrowser({
electronFileUrl: pathToFileURL(join(root, "index.html")).href,
});
@@ -48,6 +56,7 @@ describe("Electron MCP tools", () => {
REA_ELECTRON_OBSERVE_ENABLED: "true",
REA_ELECTRON_CDP_ENDPOINTS_JSON: JSON.stringify([browser.endpoint]),
REA_ELECTRON_FILE_ROOTS_JSON: JSON.stringify([root]),
REA_INVESTIGATION_INPUT_ROOTS_JSON: JSON.stringify([root]),
});
if (!config.ok) throw config.error;
const authority = await loadConfiguredPermissionAuthority(config.value);
@@ -96,6 +105,31 @@ describe("Electron MCP tools", () => {
target_id: "electron-page",
approved: true,
observation_ms: 0,
include_script_sources: true,
source_capture_approved: true,
},
});
const analyzed = await client.callTool({
name: "analyze_javascript_application",
arguments: { input_path: root, approved: true },
});
expect(analyzed.isError).not.toBe(true);
const reconciled = await client.callTool({
name: "reconcile_javascript_runtime",
arguments: {
static_layers: [
{ role: "application", analysis: analyzed.structuredContent },
],
runtime_observations: [inspected.structuredContent],
},
});
expect(reconciled.isError).not.toBe(true);
expect(reconciled.structuredContent).toMatchObject({
operation: "reconcile_javascript_runtime",
provider: { id: "rea-javascript-runtime-reconciliation" },
normalized_result: {
summary: { runtime_scripts: 1, matched: expect.any(Number) },
source_map_authority: { used_for_primary_matching: false },
},
});
expect(inspected.isError).not.toBe(true);
@@ -104,8 +138,20 @@ describe("Electron MCP tools", () => {
normalized_result: {
target: { file_path: join(root, "index.html") },
scripts: {
items: [expect.objectContaining({ file_path: join(root, "app.js") })],
items: [
expect.objectContaining({
frame_id: "frame-main",
file_path: join(root, "app.js"),
}),
],
},
workers: [
expect.objectContaining({
target_id: "electron-worker",
opener_target_id: "electron-page",
file_path: join(root, "worker.js"),
}),
],
},
});
const outside = join(root, "..", `outside-${Date.now().toString(16)}`);
+20
View File
@@ -322,6 +322,14 @@ const targets = (
webSocketDebuggerUrl: `ws://localhost:${String(port)}/devtools/page/electron-page`,
}),
},
{
id: "electron-worker",
type: "worker",
title: "Electron worker",
url: new URL("worker.js", options.electronFileUrl).href,
attached: false,
openerId: "electron-page",
},
]),
];
@@ -652,6 +660,7 @@ const emitEvents = (
hash: "cdp-hash",
length: 40,
isModule: true,
executionContextId: 1,
scriptLanguage: "JavaScript",
sourceMapURL: "/app.js.map?token=map-secret",
});
@@ -665,6 +674,7 @@ const emitEvents = (
hash: "cdp-hash",
length: 40,
isModule: true,
executionContextId: 1,
scriptLanguage: "JavaScript",
});
event(socket, "Debugger.scriptParsed", command.sessionId, {
@@ -785,6 +795,16 @@ const emitEvents = (
});
}
if (command.method === "Runtime.enable") {
event(socket, "Runtime.executionContextCreated", command.sessionId, {
context: {
id: 1,
origin:
options.electronFileUrl === undefined
? `http://127.0.0.1:${String(port)}`
: "file://",
auxData: { frameId: "frame-main", isDefault: true },
},
});
event(socket, "Runtime.consoleAPICalled", command.sessionId, {
type: "log",
timestamp: 123,
+2 -2
View File
@@ -131,7 +131,7 @@ describe("full MCP integration with multi-tool sequences", () => {
});
});
it("preserves the complete 79-tool inventory with a session", async () => {
it("preserves the complete 80-tool inventory with a session", async () => {
const session = new BinarySession(
(_path) =>
({
@@ -154,7 +154,7 @@ describe("full MCP integration with multi-tool sequences", () => {
await client.connect(clientTransport);
const listed = await client.listTools();
expect(listed.tools).toHaveLength(79);
expect(listed.tools).toHaveLength(80);
const names = listed.tools.map((t) => t.name);
expect(names).toContain("open_binary");
expect(names).toContain("close_binary");
@@ -0,0 +1,542 @@
import { execFile } from "node:child_process";
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { promisify } from "node:util";
import { afterEach, describe, expect, it } from "vitest";
import { createElectronEvidence } from "../src/application/ElectronEvidence.js";
import { analyzeJavaScriptApplication } from "../src/application/JavaScriptApplicationService.js";
import { reconcileJavaScriptRuntime } from "../src/domain/javascriptRuntimeReconciliation.js";
import { javascriptRuntimeReconciliationResultSchema } from "../src/domain/javascriptRuntimeReconciliationSchemas.js";
import { createWebTextArtifact } from "../src/domain/webContentArtifact.js";
import { permissionAuthorityForRoot } from "./fixtures/permissionAuthority.js";
const SOURCE = `const worker = new Worker("./worker.js");\nexport const observed = worker;\n`;
const execute = promisify(execFile);
describe("JavaScript static/passive-runtime reconciliation", () => {
const temporary: string[] = [];
afterEach(async () => {
await Promise.all(
temporary
.splice(0)
.map(async (path) => rm(path, { recursive: true, force: true })),
);
});
it("matches renderer, frame, script bytes, and worker without claiming execution", async () => {
const fixture = await applicationFixture();
temporary.push(fixture);
const staticEvidence = await analyzeFixture(fixture);
const runtimeEvidence = electronRuntimeEvidence(fixture, SOURCE);
const result = reconcileJavaScriptRuntime({
static_layers: [{ role: "application", analysis: staticEvidence }],
runtime_observations: [runtimeEvidence],
});
expect(() =>
javascriptRuntimeReconciliationResultSchema.parse(result),
).not.toThrow();
expect(result.summary).toMatchObject({
runtime_targets: 1,
runtime_frames: 1,
runtime_scripts: 1,
runtime_workers: 1,
matched: 2,
ambiguous: 2,
unmatched: 0,
});
expect(result.reconciliations).toEqual(
expect.arrayContaining([
expect.objectContaining({
entity_kind: "script",
status: "matched",
basis: "content-and-location",
}),
expect.objectContaining({
entity_kind: "worker",
status: "matched",
basis: "artifact-path",
}),
expect.objectContaining({
entity_kind: "target",
status: "ambiguous",
reason: "ambiguous-static-candidates",
}),
]),
);
expect(result.static_load_states).toEqual(
expect.arrayContaining([
expect.objectContaining({
kind: "javascript-asset",
status: "loaded",
}),
]),
);
expect(result.limitations.join(" ")).toMatch(
/not reported as executed|not code reachability/u,
);
expect(
result.graph.edges
.filter(({ relation }) => relation === "observed_as")
.every(
({ evidence }) =>
evidence.authority === "cross-layer-reconciliation" &&
evidence.state === "inferred",
),
).toBe(true);
const worker = result.reconciliations.find(
({ entity_kind: kind }) => kind === "worker",
);
const frame = result.reconciliations.find(
({ entity_kind: kind }) => kind === "frame",
);
expect(result.graph.edges).toContainEqual(
expect.objectContaining({
source_node_id: frame?.runtime_node_id,
target_node_id: worker?.runtime_node_id,
relation: "contains",
}),
);
});
it("reports a captured digest disagreement instead of accepting a path match", async () => {
const fixture = await applicationFixture();
temporary.push(fixture);
const staticEvidence = await analyzeFixture(fixture);
const runtimeEvidence = electronRuntimeEvidence(
fixture,
"export const observed = 'different';\n",
);
const result = reconcileJavaScriptRuntime({
static_layers: [{ role: "application", analysis: staticEvidence }],
runtime_observations: [runtimeEvidence],
});
const script = result.reconciliations.find(
({ entity_kind: kind }) => kind === "script",
);
expect(script).toMatchObject({
status: "unmatched",
reason: "captured-content-disagrees-with-static-location",
});
expect(script?.candidate_static_nodes).toHaveLength(1);
});
it("keeps source-map declarations outside primary matching authority", async () => {
const fixture = await applicationFixture();
temporary.push(fixture);
const staticEvidence = await analyzeFixture(fixture);
const runtimeEvidence = electronRuntimeEvidence(fixture, SOURCE);
const result = reconcileJavaScriptRuntime({
static_layers: [{ role: "application", analysis: staticEvidence }],
runtime_observations: [runtimeEvidence],
});
expect(result.source_map_authority).toMatchObject({
used_for_primary_matching: false,
static_layers_with_read_approval: 0,
runtime_script_declarations: 0,
});
});
it("imports an operator-provided cache layer through an explicit file mapping", async () => {
const application = await applicationFixture();
const cache = await mkdtemp(join(tmpdir(), "rea-runtime-cache-static-"));
const runtimeCache = await mkdtemp(
join(tmpdir(), "rea-runtime-cache-live-"),
);
temporary.push(application, cache, runtimeCache);
const cacheSource = "export const cachedFeature = 'fixture';\n";
await mkdir(join(cache, "mapped"));
await Promise.all([
writeFile(join(cache, "mapped", "chunk.js"), cacheSource),
writeFile(join(cache, "outside.js"), "export const outside = true;\n"),
writeFile(join(runtimeCache, "chunk.js"), cacheSource),
writeFile(join(runtimeCache, "index.html"), "<script></script>"),
]);
const applicationEvidence = await analyzeFixture(application);
const cacheEvidence = await analyzeFixture(cache);
const runtimeEvidence = electronRuntimeEvidence(runtimeCache, cacheSource, {
scriptFile: "chunk.js",
includeWorker: false,
});
const result = reconcileJavaScriptRuntime({
static_layers: [
{ role: "application", analysis: applicationEvidence },
{
role: "cache",
analysis: cacheEvidence,
runtime_mappings: [
{
kind: "file-root",
root: runtimeCache,
artifact_prefix: "mapped",
},
],
},
],
runtime_observations: [runtimeEvidence],
});
const script = result.reconciliations.find(
({ entity_kind: kind }) => kind === "script",
);
const cacheLayer = result.static_layers.find(
({ role }) => role === "cache",
);
expect(script).toMatchObject({
status: "matched",
basis: "content-and-location",
static_layer_id: cacheLayer?.layer_id,
});
const outside = result.graph.nodes.find(
(node) =>
node.kind === "javascript-asset" &&
node.observations.some(
({ properties }) => properties.path === "outside.js",
),
);
expect(
result.static_load_states.find(
({ static_node_id: nodeId }) => nodeId === outside?.node_id,
),
).toMatchObject({
status: "unknown",
reason: "layer-outside-runtime-scope",
});
});
it("keeps byte-identical cross-layer candidates explicitly ambiguous", async () => {
const application = await applicationFixture();
const assets = await mkdtemp(join(tmpdir(), "rea-runtime-assets-static-"));
const runtime = await mkdtemp(join(tmpdir(), "rea-runtime-assets-live-"));
temporary.push(application, assets, runtime);
await Promise.all([
writeFile(join(assets, "app.js"), SOURCE),
writeFile(join(runtime, "app.js"), SOURCE),
writeFile(join(runtime, "index.html"), "<script></script>"),
]);
const result = reconcileJavaScriptRuntime({
static_layers: [
{
role: "application",
analysis: await analyzeFixture(application),
},
{ role: "assets", analysis: await analyzeFixture(assets) },
],
runtime_observations: [
electronRuntimeEvidence(runtime, SOURCE, { includeWorker: false }),
],
});
const script = result.reconciliations.find(
({ entity_kind: kind }) => kind === "script",
);
expect(script).toMatchObject({
status: "ambiguous",
reason: "ambiguous-static-candidates",
candidate_static_count: 2,
});
expect(script?.candidate_static_nodes).toHaveLength(2);
expect(
new Set(
script?.candidate_static_nodes.map(
({ static_layer_id: layerId }) => layerId,
),
).size,
).toBe(2);
});
it("retains one target per capture and keeps load-state absence unknown when output is bounded", async () => {
const fixture = await applicationFixture();
temporary.push(fixture);
const staticEvidence = await analyzeFixture(fixture);
const runtimeObservations = [
electronRuntimeEvidence(fixture, SOURCE, {
includeWorker: false,
targetId: "target-one",
}),
electronRuntimeEvidence(fixture, SOURCE, {
includeWorker: false,
targetId: "target-two",
}),
];
const result = reconcileJavaScriptRuntime({
static_layers: [{ role: "application", analysis: staticEvidence }],
runtime_observations: runtimeObservations,
limits: {
max_runtime_entities: 2,
max_reconciliation_items: 2,
max_static_load_states: 20_000,
},
});
expect(result.runtime_captures).toHaveLength(2);
expect(
new Set(result.runtime_captures.map(({ target_node_id: id }) => id)).size,
).toBe(2);
expect(result.summary).toMatchObject({
runtime_targets: 2,
runtime_frames: 0,
runtime_scripts: 0,
runtime_workers: 0,
static_not_observed: 0,
});
expect(result.coverage).toMatchObject({
status: "truncated",
truncated: true,
omitted_runtime_entities: 4,
});
expect(
result.static_load_states.every(({ status }) => status === "unknown"),
).toBe(true);
});
it("rejects runtime source bytes whose Evidence omits source-capture approval", async () => {
const fixture = await applicationFixture();
temporary.push(fixture);
const staticEvidence = await analyzeFixture(fixture);
const contradictoryRuntime = electronRuntimeEvidence(fixture, SOURCE, {
includeWorker: false,
sourceCaptureApproved: false,
});
expect(() =>
reconcileJavaScriptRuntime({
static_layers: [{ role: "application", analysis: staticEvidence }],
runtime_observations: [contradictoryRuntime],
}),
).toThrow(/source-capture approval/u);
});
it("keeps graph omission counts unknown when a runtime section is unavailable", async () => {
const fixture = await applicationFixture();
temporary.push(fixture);
const result = reconcileJavaScriptRuntime({
static_layers: [
{ role: "application", analysis: await analyzeFixture(fixture) },
],
runtime_observations: [
electronRuntimeEvidence(fixture, SOURCE, {
includeWorker: false,
workersUnavailable: true,
}),
],
});
expect(result.coverage).toMatchObject({
status: "partial",
truncated: false,
});
expect(result.graph.coverage).toMatchObject({
status: "partial",
truncated: false,
omitted_count: null,
});
});
it("runs the local verifier from operator-provided paths without emitting source", async () => {
const fixture = await applicationFixture();
const evidenceRoot = await mkdtemp(join(tmpdir(), "rea-runtime-evidence-"));
const evidencePath = join(evidenceRoot, "runtime-evidence.json");
temporary.push(fixture, evidenceRoot);
await writeFile(
evidencePath,
JSON.stringify(electronRuntimeEvidence(fixture, SOURCE)),
);
const { stdout } = await execute(
process.execPath,
[
"scripts/verify-local-javascript-runtime.mjs",
"--application",
fixture,
"--runtime-evidence",
evidencePath,
],
{ cwd: process.cwd(), maxBuffer: 16 * 1_024 * 1_024 },
);
const output: unknown = JSON.parse(stdout);
expect(output).toMatchObject({
verified: true,
summary: { runtime_scripts: 1 },
});
expect(stdout).not.toContain(SOURCE.trim());
});
});
const applicationFixture = async (): Promise<string> => {
const root = await mkdtemp(join(tmpdir(), "rea-runtime-reconciliation-"));
await Promise.all([
writeFile(
join(root, "package.json"),
JSON.stringify({
name: "rea-runtime-reconciliation-fixture",
version: "1.0.0",
renderer: "index.html",
}),
),
writeFile(join(root, "index.html"), "<script src='./app.js'></script>"),
writeFile(join(root, "app.js"), SOURCE),
writeFile(join(root, "worker.js"), "self.onmessage = () => undefined;\n"),
]);
return root;
};
const analyzeFixture = async (root: string) => {
const authority = await permissionAuthorityForRoot(
root,
["investigation_input"],
["investigation_input"],
);
const result = await analyzeJavaScriptApplication(authority, {
input_path: root,
approved: true,
});
if (!result.ok) throw result.error;
return result.value;
};
const electronRuntimeEvidence = (
root: string,
source: string,
options: {
readonly scriptFile?: string;
readonly includeWorker?: boolean;
readonly targetId?: string;
readonly sourceCaptureApproved?: boolean;
readonly workersUnavailable?: boolean;
} = {},
) => {
const scriptFile = options.scriptFile ?? "app.js";
const includeWorker = options.includeWorker ?? true;
const targetId = options.targetId ?? "target-main";
const sourceCaptureApproved = options.sourceCaptureApproved ?? true;
const input = {
cdp_endpoint: "http://127.0.0.1:9223",
allowed_file_roots: [root],
target_id: targetId,
approved: true as const,
observation_ms: 100,
include_script_sources: sourceCaptureApproved,
source_capture_approved: sourceCaptureApproved,
limits: {
max_frames: 200,
max_dom_nodes: 2_000,
max_scripts: 500,
max_resources: 2_000,
max_workers: 500,
max_script_source_bytes: 1_048_576,
max_total_script_source_bytes: 4_194_304,
},
};
return createElectronEvidence(
"inspect_electron_page",
input,
{
schema_version: 1,
browser: {
product: "Electron/fixture",
protocol_version: "1.3",
revision: "fixture",
user_agent: "Electron fixture",
js_version: "13",
},
target: {
target_id: targetId,
type: "page",
title: "Fixture",
file_path: join(root, "index.html"),
attached: false,
},
capture_window: {
started_at: "2026-07-15T00:00:00.000Z",
ended_at: "2026-07-15T00:00:00.100Z",
observation_ms: 100,
},
completeness: options.workersUnavailable
? {
...completeCapture(),
status: "attach_limited" as const,
conditions: ["attach_limited" as const],
attach_limited_sections: ["workers" as const],
unavailable_sections: ["workers" as const],
}
: completeCapture(),
frames: [
{
frame_id: "frame-main",
parent_frame_id: null,
file_path: join(root, "index.html"),
},
],
dom: { total_nodes: 0, nodes: [] },
scripts: {
total: 1,
items: [
{
script_key: `electron_script_${"1".repeat(64)}`,
frame_id: "frame-main",
file_path: join(root, scriptFile),
cdp_hash: "fixture",
length: Buffer.byteLength(source),
is_module: true,
language: "JavaScript",
source: {
included: true as const,
artifact: createWebTextArtifact(source, "text/javascript"),
},
},
],
},
resources: [],
workers: includeWorker
? [
{
target_id: "worker-main",
type: "worker",
file_path: join(root, "worker.js"),
attached: false,
opener_target_id: targetId,
parent_frame_id: "frame-main",
},
]
: [],
limitations: ["Synthetic passive capture fixture."],
},
{
id: "rea-cdp-electron",
name: "REA Electron file-page CDP observation provider",
version: "1",
},
);
};
const completeCapture = () => ({
status: "complete_within_window" as const,
conditions: ["complete_within_window" as const],
policy_filtered_sections: [],
attach_limited_sections: [],
truncated_sections: [],
unavailable_sections: [],
excluded: [],
dropped_events: {
scripts: 0,
network_requests: 0,
console_events: 0,
websocket_connections: 0,
websocket_frames: 0,
webmcp_tools: 0,
timeline_events: 0,
total: 0,
},
});
+12 -1
View File
@@ -10,6 +10,7 @@ import { SUPPORTED_CLIENT_DEFINITIONS } from "../src/application/SupportedClient
import {
ARTIFACT_GRAPH_PROVIDER,
JAVASCRIPT_APPLICATION_PROVIDER,
JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER,
} from "../src/application/InvestigationProviders.js";
import { CDP_BROWSER_PROVIDER_IDENTITY } from "../src/browser/CdpBrowserProvider.js";
import { CDP_ELECTRON_PROVIDER_IDENTITY } from "../src/browser/CdpElectronProvider.js";
@@ -70,6 +71,7 @@ describe("canonical product catalog", () => {
CDP_BROWSER_PROVIDER_IDENTITY,
CDP_ELECTRON_PROVIDER_IDENTITY,
JAVASCRIPT_APPLICATION_PROVIDER,
JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER,
]
.map(({ id }) => id)
.sort(),
@@ -92,6 +94,11 @@ describe("canonical product catalog", () => {
({ id }) => id === JAVASCRIPT_APPLICATION_PROVIDER.id,
)?.capabilities,
).toEqual(["analyze_javascript_application"]);
expect(
catalog.providers.find(
({ id }) => id === JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER.id,
)?.capabilities,
).toEqual(["reconcile_javascript_runtime"]);
expect(
z.toJSONSchema(analysisSnapshotSchema).properties?.snapshot_version,
).toMatchObject({
@@ -161,7 +168,11 @@ describe("canonical product catalog", () => {
),
};
const issues = await documentationFactIssues(root, drifted);
expect(issues.some((issue) => issue.includes("80-tool"))).toBe(true);
expect(
issues.some((issue) =>
issue.includes(`${String(catalog.tools.total + 1)}-tool`),
),
).toBe(true);
expect(issues.some((issue) => issue.includes("Future Client"))).toBe(true);
expect(issues.some((issue) => issue.includes("Process Capture v5"))).toBe(
true,
+1 -1
View File
@@ -54,7 +54,7 @@ describe("guided prompts over MCP", () => {
),
);
}
expect((await client.listTools()).tools).toHaveLength(79);
expect((await client.listTools()).tools).toHaveLength(80);
const result = await client.getPrompt({
name: "investigate_feature",
arguments: {
+3 -3
View File
@@ -10,7 +10,7 @@ const fixturePath = fileURLToPath(
);
describe("production stdio runtime", () => {
it("starts the built entrypoint, lists 79 tools, calls one, and shuts down", async () => {
it("starts the built entrypoint, lists 80 tools, calls one, and shuts down", async () => {
const transport = new StdioClientTransport({
command: process.execPath,
args: [mainPath],
@@ -32,7 +32,7 @@ describe("production stdio runtime", () => {
try {
await client.connect(transport);
const tools = await client.listTools();
expect(tools.tools).toHaveLength(79);
expect(tools.tools).toHaveLength(80);
const result = await client.callTool({
name: "current_document",
arguments: {},
@@ -78,7 +78,7 @@ describe("production stdio runtime", () => {
try {
await client.connect(transport);
expect((await client.listTools()).tools).toHaveLength(79);
expect((await client.listTools()).tools).toHaveLength(80);
} finally {
await client.close();
await transport.close();
+5 -5
View File
@@ -24,11 +24,11 @@ describe("server and catalog identity", () => {
});
expect(PRODUCT_IDENTITY.packageVersion).toBe(packageJson.version);
expect(SDK_IDENTITY.server).toBe("2.0.0-beta.4");
expect(CLI_COMMAND_NAMES).toHaveLength(39);
expect(new Set(CLI_COMMAND_NAMES).size).toBe(39);
expect(CLI_COMMAND_NAMES).toHaveLength(40);
expect(new Set(CLI_COMMAND_NAMES).size).toBe(40);
expect(CATALOG_IDENTITY.counts).toEqual({
cli_commands: 39,
mcp_tools: 79,
cli_commands: 40,
mcp_tools: 80,
mcp_prompts: 6,
mcp_resources: 2,
mcp_resource_templates: 7,
@@ -162,7 +162,7 @@ describe("server and catalog identity", () => {
expect(status.structuredContent).toMatchObject({
result: {
server_identity: {
catalog: { counts: { mcp_tools: 79, cli_commands: 39 } },
catalog: { counts: { mcp_tools: 80, cli_commands: 40 } },
alignment: { state: "mcp_server_restart_required" },
},
tool_availability: expect.arrayContaining([
+1 -1
View File
@@ -142,7 +142,7 @@ describe("target-free MCP lifecycle", () => {
expect(text(before)).toBe(
"No app is open. Ask the user which app to investigate, then call open_binary with its local path.",
);
expect((await mcp.listTools()).tools).toHaveLength(79);
expect((await mcp.listTools()).tools).toHaveLength(80);
const deniedCapture = await mcp.callTool({
name: "capture_process_scenario",
arguments: {
+1 -1
View File
@@ -31,7 +31,7 @@ describe("canonical skill transaction", () => {
expect(await readFile(`${destination}.rea.backup`, "utf8")).toBe(
"stale managed skill\n",
);
expect(await readFile(destination, "utf8")).toContain('version: "15"');
expect(await readFile(destination, "utf8")).toContain('version: "16"');
expect(await readFile(destination, "utf8")).toContain(
`tool_count: ${String(TOOL_CONTRACTS.length)}`,
);
+4 -3
View File
@@ -12,7 +12,7 @@ import { BROWSER_TOOL_CONTRACTS } from "../src/contracts/browserToolContracts.js
import { ELECTRON_TOOL_CONTRACTS } from "../src/contracts/electronToolContracts.js";
describe("tool contract inventory", () => {
it("publishes 61 analysis contracts and eighteen session tools", () => {
it("publishes 62 analysis contracts and eighteen session tools", () => {
expect(OFFICIAL_TOOL_CONTRACTS).toHaveLength(33);
expect(ENHANCED_TOOL_CONTRACTS).toHaveLength(10);
expect(NATIVE_TOOL_CONTRACTS).toHaveLength(5);
@@ -31,6 +31,7 @@ describe("tool contract inventory", () => {
"list_electron_targets",
"inspect_electron_page",
"analyze_javascript_application",
"reconcile_javascript_runtime",
]);
expect(SESSION_TOOL_CONTRACTS.map(({ name }) => name)).toEqual([
"open_binary",
@@ -52,8 +53,8 @@ describe("tool contract inventory", () => {
"update_unknown",
"verify_unknown_resolution",
]);
expect(TOOL_CONTRACTS).toHaveLength(79);
expect(new Set(TOOL_CONTRACTS.map(({ name }) => name)).size).toBe(79);
expect(TOOL_CONTRACTS).toHaveLength(80);
expect(new Set(TOOL_CONTRACTS.map(({ name }) => name)).size).toBe(80);
});
it("retains documented enhanced-tool limits at the input boundary", () => {