refactor!: enforce canonical evidence and provider boundaries

Deliver complete Evidence directly through MCP with required nullable analysis profiles and immutable per-server delivery settings. Bind selected environments at construction and require typed cleanup outcomes with retained retry ownership.

Remove test-only routing, duplicate session and snapshot metadata, producer-field repairs, and ambiguous provider arguments. Separate artifact byte identity from occurrence classification and retain typed source-map and partial native facts across CLI, MCP, and verifier consumers.

BREAKING CHANGE: obsolete Evidence envelopes, session aliases, incomplete snapshots, and missing normalized producer facts are no longer accepted.
This commit is contained in:
morluto
2026-10-09 20:18:52 +08:00
parent 2a7746998d
commit 63bf91405c
514 changed files with 9296 additions and 5825 deletions
+28
View File
@@ -6,12 +6,31 @@ import { afterEach, describe, expect, it } from "vitest";
import {
startFakeCdpBrowser,
type FakeCdpBrowser,
type FakeOptions,
} from "../../fixtures/fakeCdpBrowser.js";
const execute = promisify(execFile);
const browsers: FakeCdpBrowser[] = [];
const INTEGRATION_TEST_TIMEOUT_MS = 60_000;
const partialScriptEvents: FakeOptions["commandEvents"] = (
{ method },
origin,
) =>
method === "Debugger.enable"
? [
{
method: "Debugger.scriptParsed",
sessionId: "session-1",
params: {
scriptId: "partial-script",
url: `${origin}/app.js`,
executionContextId: 1,
},
},
]
: undefined;
afterEach(async () => {
await Promise.all(browsers.splice(0).map(async (browser) => browser.close()));
});
@@ -24,6 +43,7 @@ describe("browser CLI parity", () => {
sessionTimeline: "same_origin",
webMcpTools: true,
sensitiveShapes: true,
commandEvents: partialScriptEvents,
});
browsers.push(browser);
const listed = await runCli(
@@ -59,6 +79,9 @@ describe("browser CLI parity", () => {
provider: { id: "rea-cdp-browser" },
normalized_result: {
target: { target_id: "allowed-page" },
scripts: {
items: [{ cdp_hash: null, length: null, is_module: null }],
},
network: {
prior_activity_available: false,
requests: [
@@ -355,6 +378,11 @@ const completeScenarioCapture = () => {
start_origin: "https://app.example.test",
action_count: 1,
secret_references: [],
network_content: {
request_body: false,
response_body: false,
header_values: false,
},
},
duration_ms: 1,
steps: [
+83 -69
View File
@@ -9,13 +9,12 @@ import { workspaceCliTest } from "../../support/cli/workspaceCliFixture.js";
import {
renderCliOutputArgumentError,
renderEmptyFilteredCliOutput,
sanitizeCliOutput,
validateCliOutputArguments,
} from "../../../src/cliOutput.js";
const CLI_INTEGRATION_TIMEOUT_MS = 60_000;
describe("CLI output argument and sanitization boundary", () => {
describe("CLI output argument boundary", () => {
it("rejects token windows that would corrupt structured output", () => {
for (const format of ["json", "jsonl", "yaml"] as const) {
const validation = validateCliOutputArguments([
@@ -157,57 +156,7 @@ describe("CLI output valued-flag parsing", () => {
);
});
describe("CLI output argument and sanitization boundary", () => {
it("preserves normal output and sanitizes text and JSON validation errors", () => {
expect(sanitizeCliOutput("result: ok\n")).toBe("result: ok\n");
expect(sanitizeCliOutput("result: VALIDATION_ERROR\n")).toBe(
"result: VALIDATION_ERROR\n",
);
const raw =
'code: VALIDATION_ERROR\nmessage: "raw Zod details"\nfieldErrors: SECRET\n';
expect(sanitizeCliOutput(raw)).toBe(
'code: VALIDATION_ERROR\nmessage: "REA could not read the command arguments. Run `rea --help`, correct the arguments, then try again."\n',
);
expect(
JSON.parse(
sanitizeCliOutput(
JSON.stringify({
code: "VALIDATION_ERROR",
message: "raw Zod details",
fieldErrors: [{ code: "invalid_type" }],
}),
),
),
).toEqual({
code: "VALIDATION_ERROR",
message:
"REA could not read the command arguments. Run `rea --help`, correct the arguments, then try again.",
});
expect(
JSON.parse(
sanitizeCliOutput(
JSON.stringify({
ok: false,
error: {
code: "VALIDATION_ERROR",
message: "raw Zod details",
fieldErrors: [{ code: "invalid_type" }],
},
meta: { command: "analyze" },
}),
),
),
).toEqual({
ok: false,
error: {
code: "VALIDATION_ERROR",
message:
"REA could not read the command arguments. Run `rea --help`, correct the arguments, then try again.",
},
meta: { command: "analyze" },
});
});
describe("CLI output argument boundary", () => {
it("renders an explicit empty projection for structured filtered output", () => {
for (const format of ["json", "jsonl", "yaml"])
expect(
@@ -287,33 +236,98 @@ describe("compiled CLI output boundary", () => {
);
workspaceCliTest(
"sanitizes a real missing-argument dispatcher failure",
"preserves missing-argument coordinates through every dispatcher formatter",
async ({ cli }) => {
const ordinary = await cli.run({ arguments: ["analyze"] });
expect(ordinary).toMatchObject({
exitCode: 1,
stdout:
'code: VALIDATION_ERROR\nmessage: "REA could not read the command arguments. Run `rea --help`, correct the arguments, then try again."\n',
});
const json = await cli.run({
arguments: ["--json", "analyze"],
});
const json = await cli.run({ arguments: ["--json", "analyze"] });
expect(json).toMatchObject({
exitCode: 1,
stdout: expect.not.stringContaining("fieldErrors"),
json: {
code: "VALIDATION_ERROR",
message: expect.stringContaining("expected string"),
fieldErrors: [
{
path: "path",
code: "invalid_type",
missing: true,
expected: "string",
},
],
},
});
const yaml = await cli.run({
arguments: ["--full-output", "analyze"],
for (const arguments_ of [
["analyze"],
["--format", "yaml", "analyze"],
["--full-output", "analyze"],
]) {
const result = await cli.run({ arguments: arguments_ });
expect(result.exitCode).toBe(1);
expect(result.stdout).toContain("VALIDATION_ERROR");
expect(result.stdout).toContain("fieldErrors");
expect(result.stdout).toContain("path");
expect(result.stdout).toContain("expected string");
}
},
CLI_INTEGRATION_TIMEOUT_MS,
);
workspaceCliTest(
"preserves invalid option names and enum constraints in structured diagnostics",
async ({ cli }) => {
const result = await cli.run({
arguments: [
"search",
"/caller/local/input",
"needle",
"--kind",
"unrecognized",
"--json",
],
});
expect(yaml).toMatchObject({
expect(result).toMatchObject({
exitCode: 1,
stdout:
'ok: false\nerror:\n code: VALIDATION_ERROR\n message: "REA could not read the command arguments. Run `rea --help`, correct the arguments, then try again."\n',
json: {
code: "VALIDATION_ERROR",
fieldErrors: [
{
path: "kind",
code: "invalid_value",
missing: false,
message: expect.stringContaining('"strings"|"procedures"'),
},
],
},
});
},
CLI_INTEGRATION_TIMEOUT_MS,
);
workspaceCliTest(
"prints field-specific missing-argument recovery in terminal mode",
async ({ processes }) => {
const result = await processes.run(
process.execPath,
[
"--input-type=module",
"--eval",
[
'import { createCli } from "./dist/cli.js";',
'Object.defineProperty(process.stdout, "isTTY", { value: true });',
'await createCli({}).serve(["analyze"], { exit: (code) => { process.exitCode = code; } });',
].join("\n"),
],
{ cwd: process.cwd() },
);
expect(result.exitCode).toBe(1);
expect(result.stdout).toContain(
"Error: missing required argument <path>",
);
expect(result.stdout).toContain("See below for usage.");
},
CLI_INTEGRATION_TIMEOUT_MS,
);
});
describe("compiled CLI artifact diagnostics", () => {
workspaceCliTest(
"preserves artifact diagnostics in JSON output",
async ({ cli, workspace }) => {
+1 -1
View File
@@ -28,7 +28,7 @@ describe("executable dispatcher", () => {
),
workspace.write(
"dist/cliOutput.js",
"export const sanitizeCliOutput = (output) => output; export const validateCliOutputArguments = () => ({ ok: true }); export const renderCliOutputArgumentError = () => ''; export const renderEmptyFilteredCliOutput = () => undefined;\n",
"export const validateCliOutputArguments = () => ({ ok: true }); export const renderCliOutputArgumentError = () => ''; export const renderEmptyFilteredCliOutput = () => undefined;\n",
),
workspace.write(
"dist/cli/streamedJsonOutput.js",
+17
View File
@@ -42,6 +42,20 @@ describe("Electron CLI parity", () => {
await writeFile(join(root, "app.js"), "export const app = true;");
const browser = await startFakeCdpBrowser({
electronFileUrl: pathToFileURL(join(root, "index.html")).href,
commandEvents: ({ method }) =>
method === "Debugger.enable"
? [
{
method: "Debugger.scriptParsed",
sessionId: "session-1",
params: {
scriptId: "partial-script",
url: pathToFileURL(join(root, "app.js")).href,
executionContextId: 1,
},
},
]
: undefined,
});
browsers.push(browser);
const environment = { ...process.env };
@@ -71,6 +85,9 @@ describe("Electron CLI parity", () => {
provider: { id: "rea-cdp-electron" },
normalized_result: {
target: { file_path: join(root, "index.html") },
scripts: {
items: [{ cdp_hash: null, length: null, is_module: null }],
},
},
});
},
+6 -16
View File
@@ -4,31 +4,21 @@ import { workspaceCliTest } from "../../support/cli/workspaceCliFixture.js";
const CLI_INTEGRATION_TIMEOUT_MS = 60_000;
const EXPECTED_HELP = [
"rea mcp doctor — Validate MCP server startup and tool listing",
"",
"Usage: rea mcp doctor [options]",
"",
"Options:",
" --format <toon|json|yaml|md|jsonl> Output format",
" --json Emit the report as JSON",
" --full-output Show the full output envelope",
" --help, -h Show help",
"",
"This entry accepts only the options above.",
"",
].join("\n");
describe("MCP doctor help boundary", () => {
workspaceCliTest(
"answers the advertised help option instead of validating it",
async ({ cli }) => {
const parent = await cli.run({ arguments: ["mcp", "--help"] });
expect(parent.exitCode).toBe(0);
expect(parent.stdout).toContain("doctor");
for (const argument of ["--help", "-h"]) {
const result = await cli.run({
arguments: ["mcp", "doctor", argument],
});
expect(result).toMatchObject({ exitCode: 0 });
expect(result.stdout).toBe(EXPECTED_HELP);
expect(result.stdout).toContain("Usage: rea mcp doctor [options]");
expect(result.stdout).toContain("--format <toon|json|yaml|md|jsonl>");
expect(result.stdout).toContain("--full-output");
// Help returns before the diagnostic session starts, so no report
// envelope and no startup diagnostics are produced.
expect(result.stdout).not.toContain("healthy");
-132
View File
@@ -1,5 +1,3 @@
import { EVMOLE_PROVIDER_IDENTITY } from "../../../src/evm/EvmoleRelease.js";
import { PWNTOOLS_PROVIDER_IDENTITY } from "../../../src/native/pwntools/PwntoolsRelease.js";
import { copyFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
@@ -9,35 +7,8 @@ import { afterEach, describe, expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { SUPPORTED_CLIENT_DEFINITIONS } from "../../../src/application/SupportedClients.js";
import {
ANALYSIS_VIEW_PROVIDER,
ANDROID_APPLICATION_PROVIDER,
APPLE_APPLICATION_PROVIDER,
ARTIFACT_GRAPH_PROVIDER,
JAVASCRIPT_APPLICATION_PROVIDER,
JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER,
WEB_SCRIPT_EXPORT_PROVIDER,
JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER,
MANAGED_STATIC_PROVIDER,
MANAGED_WORKFLOW_PROVIDER,
} from "../../../src/application/InvestigationProviders.js";
import { CDP_BROWSER_PROVIDER_IDENTITY } from "../../../src/browser/CdpBrowserProvider.js";
import {
HAR_CAPTURE_PROVIDER_IDENTITY,
MITMPROXY_CAPTURE_PROVIDER_IDENTITY,
} from "../../../src/browser/history/CaptureRelease.js";
import { CDP_ELECTRON_PROVIDER_IDENTITY } from "../../../src/browser/CdpElectronProvider.js";
import { PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY } from "../../../src/browser/PlaywrightElectronActiveProvider.js";
import { PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY } from "../../../src/browser/PlaywrightBrowserScenarioProvider.js";
import { V8_INSPECTOR_PROVIDER_IDENTITY } from "../../../src/inspector/V8InspectorProvider.js";
import { CLI_COMMAND_NAMES } from "../../../src/cliCommandNames.js";
import { createCli } from "../../../src/cli.js";
import {
BINWALK_PROVIDER_IDENTITY,
UNBLOB_PROVIDER_IDENTITY,
} from "../../../src/firmware/FirmwareRelease.js";
import { WAKARU_PROVIDER_IDENTITY } from "../../../src/javascript/recovery/WakaruRelease.js";
import { JADX_PROVIDER_IDENTITY } from "../../../src/android/JadxRelease.js";
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
import {
HOPPER_PROVIDER_IDENTITY,
@@ -47,10 +18,7 @@ import {
GHIDRA_PROVIDER_IDENTITY,
GHIDRA_OPERATIONS,
} from "../../../src/ghidra/GhidraProvider.js";
import { NATIVE_MACOS_PROVIDER_IDENTITY } from "../../../src/native/NativeMacOSProvider.js";
import { IDA_PROVIDER_IDENTITY } from "../../../src/ida/IdaProvider.js";
import {
assertDocumentationFacts,
documentationFactIssues,
skillReferenceIssues,
} from "../../../scripts/lib/docs-facts.mjs";
@@ -98,47 +66,9 @@ describe("canonical product catalog", () => {
it("matches every source-derived build-generated product fact", async () => {
const catalog = await createProductCatalog(root);
expect(catalog.tools.total).toBe(TOOL_CONTRACTS.length);
expect(
catalog.tools.families.reduce((total, family) => total + family.count, 0),
).toBe(TOOL_CONTRACTS.length);
expect(catalog.setup_clients.map(({ id }) => id)).toEqual(
SUPPORTED_CLIENT_DEFINITIONS.map(({ name }) => name),
);
expect(catalog.cli.commands).toHaveLength(CLI_COMMAND_NAMES.length);
expect(catalog.providers.map(({ id }) => id).sort()).toEqual(
[
HOPPER_PROVIDER_IDENTITY,
JADX_PROVIDER_IDENTITY,
BINWALK_PROVIDER_IDENTITY,
UNBLOB_PROVIDER_IDENTITY,
WAKARU_PROVIDER_IDENTITY,
HAR_CAPTURE_PROVIDER_IDENTITY,
MITMPROXY_CAPTURE_PROVIDER_IDENTITY,
GHIDRA_PROVIDER_IDENTITY,
IDA_PROVIDER_IDENTITY,
NATIVE_MACOS_PROVIDER_IDENTITY,
PWNTOOLS_PROVIDER_IDENTITY,
EVMOLE_PROVIDER_IDENTITY,
ARTIFACT_GRAPH_PROVIDER,
ANDROID_APPLICATION_PROVIDER,
APPLE_APPLICATION_PROVIDER,
MANAGED_STATIC_PROVIDER,
MANAGED_WORKFLOW_PROVIDER,
CDP_BROWSER_PROVIDER_IDENTITY,
PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY,
CDP_ELECTRON_PROVIDER_IDENTITY,
PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY,
V8_INSPECTOR_PROVIDER_IDENTITY,
JAVASCRIPT_APPLICATION_PROVIDER,
JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER,
JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER,
ANALYSIS_VIEW_PROVIDER,
WEB_SCRIPT_EXPORT_PROVIDER,
]
.map(({ id }) => id)
.sort(),
);
expect(
catalog.providers.find(({ id }) => id === HOPPER_PROVIDER_IDENTITY.id)
?.capabilities,
@@ -147,65 +77,6 @@ describe("canonical product catalog", () => {
catalog.providers.find(({ id }) => id === GHIDRA_PROVIDER_IDENTITY.id)
?.capabilities,
).toEqual([...GHIDRA_OPERATIONS].sort());
expect(
catalog.providers.find(
({ id }) => id === CDP_ELECTRON_PROVIDER_IDENTITY.id,
)?.capabilities,
).toEqual(["inspect_electron_page", "list_electron_targets"]);
expect(
catalog.providers.find(
({ id }) => id === PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY.id,
)?.capabilities,
).toEqual(["capture_electron_scenario"]);
expect(
catalog.providers.find(
({ 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(
catalog.providers.find(
({ id }) => id === JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER.id,
)?.capabilities,
).toEqual([
"build_reconstruction_obligation_ledger",
"compare_application_versions",
"compare_javascript_export_shapes",
"compare_source_to_bundle",
"evaluate_reconstruction_coverage",
"trace_application_feature",
"trace_javascript_semantics",
]);
expect(
catalog.providers.find(({ id }) => id === ANALYSIS_VIEW_PROVIDER.id)
?.capabilities,
).toEqual(["inspect_analysis_view"]);
expect(
catalog.providers.find(({ id }) => id === ANDROID_APPLICATION_PROVIDER.id)
?.capabilities,
).toEqual(["project_android_application_graph"]);
expect(
catalog.providers.find(({ id }) => id === APPLE_APPLICATION_PROVIDER.id)
?.capabilities,
).toEqual(["project_apple_application_graph"]);
expect(
catalog.providers.find(({ id }) => id === MANAGED_WORKFLOW_PROVIDER.id)
?.capabilities,
).toEqual([
"compare_managed_members",
"import_managed_reconstruction",
"project_managed_application_graph",
"verify_managed_native_boundaries",
]);
// Runtime schema commitments must not fan out into checked-in documentation.
// Provider commitments cover the facts actually present in this projection.
expect(Object.keys(catalog.runtime_catalog.digests)).toEqual([
"providers_sha256",
]);
expect(catalog.runtime_catalog.digests.providers_sha256).toBe(
providerCatalogDigest(catalog.providers),
);
@@ -215,9 +86,6 @@ describe("canonical product catalog", () => {
expect(await serializeProductCatalog(catalog)).toBe(
await readFile("docs/public/product-catalog.json", "utf8"),
);
await expect(
assertDocumentationFacts(root, catalog),
).resolves.toBeUndefined();
await expect(documentationFactIssues(root, catalog)).resolves.toEqual([]);
}, 60_000);
});