fix(tools)!: simplify direct invocation and harden boundary contracts (#555)
Remove REA permission grants, scope ceilings, approval confirmations, and inert settings. Preserve selected local evidence, accept caller-chosen commands and paths, and report actual runtime failures. Harden provider results, schema serialization, snapshot evidence binding, archive paths, source maps, native screenshots, managed EH parsing, and cancellation cleanup. Regenerate tool metadata and document direct invocation. BREAKING CHANGE: Removed permission configuration and policy commands, approval fields, filesystem scope inputs, and fixed confirmation options. Process capture inherits the host environment and accepts command names; callers must refresh tool schemas and migrate removed fields.
This commit is contained in:
@@ -26,23 +26,18 @@ describe("browser CLI parity", () => {
|
||||
sensitiveShapes: true,
|
||||
});
|
||||
browsers.push(browser);
|
||||
const environment = {
|
||||
...process.env,
|
||||
REA_BROWSER_OBSERVE_ENABLED: "true",
|
||||
REA_BROWSER_CDP_ENDPOINTS_JSON: JSON.stringify([browser.endpoint]),
|
||||
REA_BROWSER_ALLOWED_ORIGINS_JSON: JSON.stringify([
|
||||
browser.allowedOrigin,
|
||||
]),
|
||||
};
|
||||
const listed = await runCli(
|
||||
["list-browser-targets", browser.endpoint, "--json"],
|
||||
environment,
|
||||
process.env,
|
||||
);
|
||||
expect(listed).toMatchObject({
|
||||
operation: "list_browser_targets",
|
||||
provider: { id: "rea-cdp-browser" },
|
||||
normalized_result: {
|
||||
targets: [{ target_id: "allowed-page" }],
|
||||
targets: expect.arrayContaining([
|
||||
expect.objectContaining({ target_id: "allowed-page" }),
|
||||
expect.objectContaining({ target_id: "disallowed-page" }),
|
||||
]),
|
||||
},
|
||||
});
|
||||
const inspected = await runCli(
|
||||
@@ -57,7 +52,7 @@ describe("browser CLI parity", () => {
|
||||
"--include-websocket-shapes",
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
process.env,
|
||||
);
|
||||
expect(inspected).toMatchObject({
|
||||
operation: "inspect_web_page",
|
||||
@@ -82,7 +77,7 @@ describe("browser CLI parity", () => {
|
||||
JSON.stringify({ inspection }),
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
process.env,
|
||||
);
|
||||
expect(compared).toMatchObject({
|
||||
operation: "compare_web_captures",
|
||||
@@ -103,7 +98,7 @@ describe("browser CLI parity", () => {
|
||||
'{"rules":[]}',
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
process.env,
|
||||
);
|
||||
expect(scenarioCompared).toMatchObject({
|
||||
operation: "compare_web_captures",
|
||||
@@ -120,7 +115,7 @@ describe("browser CLI parity", () => {
|
||||
|
||||
describe("browser CLI capture parity", () => {
|
||||
it(
|
||||
"returns the same analysis, session, WebMCP, screenshot, and policy contracts",
|
||||
"runs analysis, session, WebMCP, screenshot, and comparison from explicit request scope",
|
||||
async () => {
|
||||
const browser = await startFakeCdpBrowser({
|
||||
sessionTimeline: "same_origin",
|
||||
@@ -128,24 +123,18 @@ describe("browser CLI capture parity", () => {
|
||||
sensitiveShapes: true,
|
||||
});
|
||||
browsers.push(browser);
|
||||
const environment = {
|
||||
...process.env,
|
||||
REA_BROWSER_OBSERVE_ENABLED: "true",
|
||||
REA_BROWSER_CDP_ENDPOINTS_JSON: JSON.stringify([browser.endpoint]),
|
||||
REA_BROWSER_ALLOWED_ORIGINS_JSON: JSON.stringify([
|
||||
browser.allowedOrigin,
|
||||
]),
|
||||
};
|
||||
const scopeArgs = ["--allowed-origins", browser.allowedOrigin];
|
||||
const analyzed = await runCli(
|
||||
[
|
||||
"analyze-web-bundle",
|
||||
browser.endpoint,
|
||||
"allowed-page",
|
||||
...scopeArgs,
|
||||
"--observation-ms",
|
||||
"0",
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
process.env,
|
||||
);
|
||||
expect(analyzed).toMatchObject({
|
||||
operation: "analyze_web_bundle",
|
||||
@@ -159,11 +148,12 @@ describe("browser CLI capture parity", () => {
|
||||
"observe-web-session",
|
||||
browser.endpoint,
|
||||
"allowed-page",
|
||||
...scopeArgs,
|
||||
"--observation-ms",
|
||||
"5",
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
process.env,
|
||||
);
|
||||
expect(observedSession).toMatchObject({
|
||||
operation: "observe_web_session",
|
||||
@@ -179,11 +169,12 @@ describe("browser CLI capture parity", () => {
|
||||
"discover-webmcp-tools",
|
||||
browser.endpoint,
|
||||
"allowed-page",
|
||||
...scopeArgs,
|
||||
"--observation-ms",
|
||||
"0",
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
process.env,
|
||||
);
|
||||
expect(webMcp).toMatchObject({
|
||||
operation: "discover_webmcp_tools",
|
||||
@@ -194,8 +185,14 @@ describe("browser CLI capture parity", () => {
|
||||
},
|
||||
});
|
||||
const screenshot = await runCli(
|
||||
["capture-web-screenshot", browser.endpoint, "allowed-page", "--json"],
|
||||
environment,
|
||||
[
|
||||
"capture-web-screenshot",
|
||||
browser.endpoint,
|
||||
"allowed-page",
|
||||
...scopeArgs,
|
||||
"--json",
|
||||
],
|
||||
process.env,
|
||||
);
|
||||
const artifact = screenshotArtifact(screenshot);
|
||||
expect(artifact).toMatchObject({ media_type: "image/png", bytes: 70 });
|
||||
@@ -206,31 +203,12 @@ describe("browser CLI capture parity", () => {
|
||||
JSON.stringify(artifact),
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
process.env,
|
||||
);
|
||||
expect(visual).toMatchObject({
|
||||
operation: "compare_web_screenshots",
|
||||
normalized_result: { status: "identical", changed_pixels: 0 },
|
||||
});
|
||||
const policy = await runCli(
|
||||
[
|
||||
"policy",
|
||||
"explain",
|
||||
"browser_observe",
|
||||
"--origins",
|
||||
browser.endpoint,
|
||||
"--origins",
|
||||
browser.allowedOrigin,
|
||||
"--network",
|
||||
"loopback",
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
);
|
||||
expect(policy).toEqual({
|
||||
allowed: true,
|
||||
grant_id: "administrator:browser_observe",
|
||||
});
|
||||
},
|
||||
INTEGRATION_TEST_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { readFile, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import {
|
||||
readProjectPermissionStore,
|
||||
writeProjectPermissionStore,
|
||||
} from "../../../src/application/ProjectPermissionStore.js";
|
||||
import { approvePolicyRevocation } from "../../../src/cliPolicyCommands.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const roots: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
describe("policy revocation approval", () => {
|
||||
it.each([
|
||||
[true, { approved: true }],
|
||||
[false, { approved: false, reason: "cancelled" }],
|
||||
] as const)(
|
||||
"uses the interactive decision %s",
|
||||
async (decision, expected) => {
|
||||
const confirm = vi.fn(() => Promise.resolve(decision));
|
||||
|
||||
await expect(
|
||||
approvePolicyRevocation({
|
||||
approved: false,
|
||||
interactive: true,
|
||||
grantId: "grant-1",
|
||||
confirm,
|
||||
}),
|
||||
).resolves.toEqual(expected);
|
||||
expect(confirm).toHaveBeenCalledWith("grant-1");
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps the packaged project store unchanged until --yes is supplied", async () => {
|
||||
const project = await createTestTempDirectory("rea-policy-cli-");
|
||||
roots.push(project);
|
||||
const store = join(project, ".rea", "permissions.json");
|
||||
const grant = {
|
||||
grant_id: "project:revoke-me",
|
||||
capability: "managed_runtime" as const,
|
||||
roots: [project],
|
||||
executables: [],
|
||||
environment_names: [],
|
||||
network: "none" as const,
|
||||
mount: false,
|
||||
lifetime: "project" as const,
|
||||
operation_identity: null,
|
||||
expires_at: null,
|
||||
};
|
||||
expect(
|
||||
await writeProjectPermissionStore(store, project, [grant]),
|
||||
).toMatchObject({
|
||||
ok: true,
|
||||
value: { grants: [grant] },
|
||||
});
|
||||
const before = await readFile(store);
|
||||
const environment = {
|
||||
...process.env,
|
||||
REA_PERMISSION_PROJECT_ROOT: project,
|
||||
REA_PERMISSION_PROJECT_STORE: store,
|
||||
};
|
||||
|
||||
const denied = await runCli(
|
||||
["policy", "revoke", grant.grant_id, "--json"],
|
||||
environment,
|
||||
);
|
||||
expect(denied.status).toBe(1);
|
||||
expect(denied.output).toEqual({
|
||||
error:
|
||||
"Policy revoke requires confirmation. Rerun interactively or with --yes.",
|
||||
grant_id: grant.grant_id,
|
||||
});
|
||||
expect(await readFile(store)).toEqual(before);
|
||||
|
||||
const approved = await runCli(
|
||||
["policy", "revoke", grant.grant_id, "--yes", "--json"],
|
||||
environment,
|
||||
);
|
||||
expect(approved).toEqual({
|
||||
status: 0,
|
||||
output: {
|
||||
revoked: grant.grant_id,
|
||||
reload: "Send SIGHUP to the REA MCP process",
|
||||
},
|
||||
});
|
||||
expect(await readProjectPermissionStore(store, project)).toMatchObject({
|
||||
ok: true,
|
||||
value: { grants: [] },
|
||||
});
|
||||
}, 40_000);
|
||||
});
|
||||
|
||||
describe("policy capability coverage", () => {
|
||||
it.each(["v8_inspector_observe", "javascript_replay", "managed_runtime"])(
|
||||
"explains %s without granting disabled authority",
|
||||
async (capability) => {
|
||||
const result = await runCli(["policy", "explain", capability, "--json"], {
|
||||
...process.env,
|
||||
REA_V8_INSPECTOR_OBSERVE_ENABLED: "false",
|
||||
REA_JAVASCRIPT_REPLAY_ENABLED: "false",
|
||||
REA_MANAGED_RUNTIME_ENABLED: "false",
|
||||
});
|
||||
expect(result.output).toMatchObject({
|
||||
allowed: false,
|
||||
error: { code: "permission_required" },
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
const runCli = async (
|
||||
arguments_: readonly string[],
|
||||
environment: NodeJS.ProcessEnv,
|
||||
): Promise<{ readonly status: number; readonly output: unknown }> => {
|
||||
try {
|
||||
const { stdout } = await execute(
|
||||
process.execPath,
|
||||
["scripts/rea.mjs", ...arguments_],
|
||||
{ cwd: process.cwd(), env: environment },
|
||||
);
|
||||
return { status: 0, output: JSON.parse(stdout) };
|
||||
} catch (cause: unknown) {
|
||||
if (
|
||||
typeof cause === "object" &&
|
||||
cause !== null &&
|
||||
"code" in cause &&
|
||||
typeof cause.code === "number" &&
|
||||
"stdout" in cause &&
|
||||
typeof cause.stdout === "string"
|
||||
)
|
||||
return { status: cause.code, output: JSON.parse(cause.stdout) };
|
||||
throw cause;
|
||||
}
|
||||
};
|
||||
@@ -44,10 +44,7 @@ describe("Electron CLI parity", () => {
|
||||
electronFileUrl: pathToFileURL(join(root, "index.html")).href,
|
||||
});
|
||||
browsers.push(browser);
|
||||
const environment = {
|
||||
...process.env,
|
||||
REA_ELECTRON_OBSERVE_ENABLED: "true",
|
||||
};
|
||||
const environment = { ...process.env };
|
||||
const listed = await runCli(
|
||||
["list-electron-targets", browser.endpoint, "--json"],
|
||||
environment,
|
||||
|
||||
@@ -6,11 +6,9 @@ import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, test } from "vitest";
|
||||
|
||||
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 { parseConfig } from "../../../src/config.js";
|
||||
import { startFakeV8Inspector } from "../../fixtures/fakeV8Inspector.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -41,10 +39,7 @@ describe("JavaScript runtime observation CLI parity", () => {
|
||||
targetUrl: pathToFileURL(entry).href,
|
||||
});
|
||||
resources.push(inspector);
|
||||
const environment = {
|
||||
...process.env,
|
||||
REA_V8_INSPECTOR_OBSERVE_ENABLED: "true",
|
||||
};
|
||||
const environment = { ...process.env };
|
||||
|
||||
const listed = await runCli(
|
||||
["list-javascript-runtime-targets", inspector.endpoint, "--json"],
|
||||
@@ -85,13 +80,8 @@ describe("JavaScript runtime observation CLI parity", () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
const config = parseConfig(environment);
|
||||
if (!config.ok) throw config.error;
|
||||
const authority = await loadConfiguredPermissionAuthority(config.value);
|
||||
if (!authority.ok) throw authority.error;
|
||||
const direct = await observeJavaScriptRuntime(
|
||||
new V8InspectorProvider(),
|
||||
authority.value,
|
||||
observeJavaScriptRuntimeInputSchema.parse({
|
||||
inspector_endpoint: inspector.endpoint,
|
||||
target_id: inspector.targetId,
|
||||
|
||||
@@ -86,37 +86,36 @@ describe("process CLI errors", () => {
|
||||
});
|
||||
expect(await captureProcessScenarioFile(invalid)).toEqual({
|
||||
error: "Process command failed",
|
||||
code: "invalid_request",
|
||||
category: "invalid_input",
|
||||
message:
|
||||
"Process scenario is invalid. Check its required fields and limits, then try again.",
|
||||
message: "Analysis input is invalid. Check the arguments and try again.",
|
||||
retryable: true,
|
||||
remediation: { action: "Correct the listed arguments and retry." },
|
||||
details: expect.objectContaining({
|
||||
operation: "capture_process_scenario",
|
||||
issues: expect.arrayContaining([
|
||||
expect.objectContaining({ path: ["executable"] }),
|
||||
]),
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
it("reports the exact process-capture policy recovery", async () => {
|
||||
it("captures the minimal executable-and-arguments scenario", async () => {
|
||||
const root = await fixture();
|
||||
const scenario = join(root, "scenario.json");
|
||||
await writeFile(
|
||||
scenario,
|
||||
JSON.stringify({
|
||||
executable: "/bin/sh",
|
||||
working_directory: "/tmp",
|
||||
executable: process.execPath,
|
||||
arguments: ["-e", "process.stdout.write('minimal-capture')"],
|
||||
}),
|
||||
);
|
||||
expect(await captureProcessScenarioFile(scenario)).toMatchObject({
|
||||
error: "Process command failed",
|
||||
code: "permission_required",
|
||||
category: "permission_required",
|
||||
message:
|
||||
"This operation needs additional local permission. Review the requested scope and remediation.",
|
||||
details: {
|
||||
capability: "process_capture",
|
||||
ceiling: null,
|
||||
},
|
||||
remediation: {
|
||||
restart_required: false,
|
||||
elicitation_supported: false,
|
||||
},
|
||||
const evidence = await captureProcessScenarioFile(scenario);
|
||||
expect(evidence).toMatchObject({
|
||||
predicate_type: "rea.process-capture",
|
||||
operation: "capture_process_scenario",
|
||||
});
|
||||
expect(JSON.stringify(evidence)).toContain("minimal-capture");
|
||||
});
|
||||
|
||||
it("rejects unrelated capture evidence", async () => {
|
||||
|
||||
@@ -8,7 +8,7 @@ describe("projected CLI failures", () => {
|
||||
async ({ cli }) => {
|
||||
const result = await cli.run({
|
||||
arguments: ["run-controlled-replay", "{}", "--json"],
|
||||
environment: { REA_JAVASCRIPT_REPLAY_ENABLED: "not-a-bool" },
|
||||
environment: { REA_JAVASCRIPT_REPLAY_NODE_PATH: "relative/node" },
|
||||
});
|
||||
expect(result.json).toMatchObject({
|
||||
code: "configuration_invalid",
|
||||
|
||||
Reference in New Issue
Block a user