mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
* refactor(native): bind producer_limits and max_input_bytes as the per-call controls of pwntools and Apple dispatch refusals producerLimitControl in src/domain/producerResourceLimits.ts names one producer budget as producer_limits.<field>; the shared provider outcome classifier now carries a resource signal's limit. Pwntools file-size, CPU and output refusals and the Apple dispatch input refusal bind their control, and their remediation no longer names CLI flags. * fix(native): report the selected output allowance as the omitted file_bytes default * fix(native): bind producer_limits.diagnostic_bytes as the pwntools command output-limit control * refactor(rust): bind producer_limits as the per-call control of Rust input and report refusals (#11458) * refactor(rust): bind producer_limits as the per-call control of Rust input and report refusals * test(rust): cover the complete-report refusal's producer_limits control * refactor(browser): bind caller-selectable browser deadlines as per-call controls instead of naming CLI flags (#11466) * refactor(rust): bind producer_limits as the per-call control of Rust input and report refusals * test(rust): cover the complete-report refusal's producer_limits control * refactor(browser): bind caller-selectable browser deadlines as per-call controls instead of naming CLI flags deadlineParameterLimit in src/domain/analysisResourceLimits.ts owns the millisecond deadline control that nativeDeadlineRecovery and the browser recoveries share. CDP command and discovery, web bundle per-script and total, network capture and source-map decode deadlines now carry it; browserDeadlineIncrease no longer takes CLI flag text. * fix(browser): record a per-script deadline's parameter control in partial web bundle results * refactor(providers): bind Wabt, SQLite, EVMole, Apktool and Go controls instead of naming CLI commands (#11472) * refactor(providers): bind Wabt, SQLite, EVMole and Apktool deadline and byte controls instead of naming CLI commands These remediation strings named rea commands and flags through template text the cli-option guard did not count. Wabt byte refusals and output limits bind max_input_bytes, max_tool_bytes or max_output_bytes while a larger value is selectable; SQLite worker_timeout_ms, EVMole timeout_ms and Apktool decode_timeout_ms bind through deadlineParameterLimit; the shared provider outcome classifier now carries an output limit's control. * refactor(go): bind Go analysis budgets as per-call controls instead of naming CLI flags * fix(providers): keep the typed primary when Wabt, EVMole or pwntools command cleanup fails * ci(guards): count template-built CLI option and command text outside the CLI layer (#11478) * refactor(providers): bind Wabt, SQLite, EVMole and Apktool deadline and byte controls instead of naming CLI commands These remediation strings named rea commands and flags through template text the cli-option guard did not count. Wabt byte refusals and output limits bind max_input_bytes, max_tool_bytes or max_output_bytes while a larger value is selectable; SQLite worker_timeout_ms, EVMole timeout_ms and Apktool decode_timeout_ms bind through deadlineParameterLimit; the shared provider outcome classifier now carries an output limit's control. * refactor(go): bind Go analysis budgets as per-call controls instead of naming CLI flags * fix(providers): keep the typed primary when Wabt, EVMole or pwntools command cleanup fails * ci(guards): count template-built CLI option and command text outside the CLI layer The cli-option-text-outside-cli pattern now also matches "(CLI ...", "on the CLI", "or use rea ..." and backticked `rea <command>` references, so remediation built from a template such as --${name} or rea inspect-... <path> is counted. Doctor.ts is exempt: setup and doctor run only through the CLI. The baseline records the newly counted pre-existing sites (22 -> 45 across 21 files). * ci(guards): extract the CLI text matcher, exempt host-only commands with written reasons, and test each spelling * ci(guards): exempt a host-only command and its own arguments in any matched CLI phrase * fix(native): bind producer_limits.output_bytes for oversized pwndbg debugger replies through one owner * fix(cli): name an Evidence target source failure's control by the source option that sets it * feat(cli): render the flags of result-recorded controls in the full-output envelope (#11507) * feat(cli): render the flags of result-recorded controls in the full-output envelope * fix(cli): collect result controls only for a full-output envelope, in its requested format, past undefined values * ci(guards): end a host-only command's arguments before the next CLI command * refactor(reverse): record the output budget that stopped a one-shot command as a parameter control (#11528) * fix(cli): read result controls only at positions the output schema declares as recorded controls * refactor(providers): record the controls that bounded Rust compiler paths and kernel module text instead of naming CLI options (#11532) * refactor(rust): record the control that bounded compiler-path coverage instead of naming CLI options * refactor(native): record the controls that omitted kernel module .modinfo text instead of naming CLI options (#11534) * fix(rust): describe compiler coverage from the retained result after report trimming * refactor(providers): record managed representation and JavaScript semantic ceiling controls instead of naming CLI options (#11537) * refactor(managed): record the representation budget on a resource-limit issue instead of naming its CLI option * refactor(javascript): record the semantic retention ceilings that stopped a graph instead of naming CLI options (#11540) * fix(cli): name a composed command's source options for the controls its result records * fix(cli): read result controls from the delivered Evidence when a summary wraps it * fix(rust): keep the report-byte control recorded when trimming omits every compiler path When the complete-report allowance left room for no compiler path, rustc_commit became null and its coverage.limit was lost, so --full-output could not name the option that raises the allowance. The report now records rustc_commit_omission { reason, limit } outside the dropped record, and the summary view carries it. * refactor(flutter): record the string-pool budgets that left a projection partial instead of naming the CLI option (#11541) * refactor(flutter): record the string-pool budgets that left a projection partial instead of naming the CLI option * test(flutter): assert the complete set of recorded string-pool budgets * feat(cli): name the options of controls a failure's partial Evidence records (#11557) meta.cli_controls was collected only from a successful result. A failure whose partial observation is Evidence of the command's own operation is now read the same way, at the positions the output schema declares as recorded controls; Evidence of another operation or a retained reference is not read. When --evidence_output publishes the partial, the delivery records it before replacing it. * refactor(javascript): record the evaluator budgets that limited sources instead of naming the CLI option (#11564) Per-value unknown reasons and the Electron wrapper limitation named --semantic-precision. The static examination now records the semantic_precision controls that limited a source (examination.controls), and analyze_javascript_application's semantic_graph.coverage.controls records every evaluator budget that limited any source (examination and semantic IR coverage), beside the retention ceilings. The CLI renders --semantic-precision from those records in meta.cli_controls; the reason texts name only the contract field.
462 lines
15 KiB
TypeScript
462 lines
15 KiB
TypeScript
import { fileSubjectArchitecture } from "../fixtures/evidenceSubject.js";
|
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { parseEvidence, createEvidence } from "../../src/domain/evidence.js";
|
|
import { createEvidenceBundle } from "../../src/domain/evidenceBundle.js";
|
|
import { rustBinarySchema } from "../../src/domain/rust/rustBinary.js";
|
|
import { analysisViewResultSchema } from "../../src/domain/analysisView/analysisViewResult.js";
|
|
import { readEvidenceBundle } from "../../src/application/EvidenceBundleFiles.js";
|
|
import { connectLocalToolsMcp } from "../fixtures/localToolsMcp.js";
|
|
import { parseMcpToolError } from "../fixtures/mcpToolError.js";
|
|
import {
|
|
createRustImage,
|
|
createRustHashOverflowImage,
|
|
rustDependencyPayload,
|
|
} from "../fixtures/rust/image.js";
|
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../support/cli/cliFixture.js";
|
|
|
|
cliTest(
|
|
"keeps compiler-prefix coverage in CLI summaries until the selected budget admits every hash",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-rust-compiler-summary-");
|
|
const path = join(root, "compiler-paths.elf");
|
|
await writeFile(path, createRustHashOverflowImage());
|
|
for (const maxHashes of [64, 65]) {
|
|
const output = join(root, `source-${String(maxHashes)}.json`);
|
|
const delivered = await cli.run({
|
|
arguments: [
|
|
"inspect-rust-binary",
|
|
path,
|
|
"--detail",
|
|
"summary",
|
|
"--evidence_output",
|
|
output,
|
|
"--max-rustc-hashes",
|
|
String(maxHashes),
|
|
"--full-output",
|
|
"--json",
|
|
],
|
|
});
|
|
expect(delivered.exitCode, delivered.stderr).toBe(0);
|
|
const envelope = delivered.json as {
|
|
data: { summary: { normalized_result: unknown } };
|
|
meta: { cli_controls?: unknown };
|
|
};
|
|
// The summary wraps the view; the CLI still names the option for the
|
|
// control the complete Evidence records.
|
|
expect(envelope.meta.cli_controls).toEqual(
|
|
maxHashes === 64
|
|
? { max_rustc_hashes: "--max-rustc-hashes" }
|
|
: undefined,
|
|
);
|
|
const summary = analysisViewResultSchema.parse(
|
|
envelope.data.summary.normalized_result,
|
|
);
|
|
if (
|
|
summary.kind !== "summary" ||
|
|
summary.parent_operation !== "inspect_rust_binary"
|
|
)
|
|
throw new Error("Expected a Rust summary");
|
|
expect(summary.summary.rustc_commit).toEqual({
|
|
evidence_kind: "inferred",
|
|
hashes_count: maxHashes,
|
|
...(maxHashes === 64
|
|
? {
|
|
coverage: {
|
|
status: "partial",
|
|
reason: "max_rustc_hashes",
|
|
effective_limit: 64,
|
|
limit: expect.objectContaining({
|
|
parameter: "max_rustc_hashes",
|
|
effective_value: 64,
|
|
}),
|
|
},
|
|
}
|
|
: {}),
|
|
});
|
|
expect(summary.summary.auditable_metadata?.counts.packages).toBe(2);
|
|
}
|
|
},
|
|
);
|
|
|
|
/** Both authenticated retention and portable imports query the same captured facts. */
|
|
const assertRetainedPages = async (
|
|
call: Awaited<ReturnType<typeof connectLocalToolsMcp>>["call"],
|
|
evidenceId: string,
|
|
exported: string,
|
|
) => {
|
|
for (const [filter, expected] of [
|
|
[
|
|
{ names: ["same"], versions: ["2"], fields: ["name", "version"] },
|
|
[{ index: 1, name: "same", version: "2" }],
|
|
],
|
|
[{ names: ["same"], indices: [0], fields: [] }, [{ index: 0 }]],
|
|
[{ names: ["same"], versions: [], fields: [] }, []],
|
|
] as const) {
|
|
const reply = await call("inspect_analysis_view", {
|
|
source: { kind: "retained-evidence", evidence_id: evidenceId },
|
|
view: { kind: "rust", collection: "packages", ...filter },
|
|
});
|
|
expect(reply.isError).not.toBe(true);
|
|
expect(
|
|
parseEvidence(reply.structuredContent).normalized_result,
|
|
).toMatchObject({ page: { rows: expected } });
|
|
}
|
|
|
|
for (const source of [
|
|
{ kind: "retained-evidence", evidence_id: evidenceId },
|
|
{ kind: "evidence-file", path: exported },
|
|
]) {
|
|
const reply = await call("inspect_analysis_view", {
|
|
source,
|
|
view: {
|
|
kind: "rust",
|
|
collection: "packages",
|
|
names: ["same"],
|
|
indices: [0, 1, 99],
|
|
offset: 1,
|
|
limit: 1,
|
|
fields: [],
|
|
},
|
|
});
|
|
expect(reply.isError, JSON.stringify(reply)).not.toBe(true);
|
|
expect(
|
|
parseEvidence(reply.structuredContent).normalized_result,
|
|
).toMatchObject({
|
|
parent_evidence_id: evidenceId,
|
|
page: { rows: [{ index: 1 }] },
|
|
coverage: {
|
|
total: 2,
|
|
examined: 1,
|
|
exhausted: true,
|
|
next_offset: null,
|
|
},
|
|
});
|
|
const edgeReply = await call("inspect_analysis_view", {
|
|
source,
|
|
view: {
|
|
kind: "rust",
|
|
collection: "edges",
|
|
from_indices: [1, 3],
|
|
to_indices: [0],
|
|
fields: ["from_index", "to_index"],
|
|
},
|
|
});
|
|
expect(edgeReply.isError).not.toBe(true);
|
|
expect(
|
|
parseEvidence(edgeReply.structuredContent).normalized_result,
|
|
).toMatchObject({
|
|
page: {
|
|
collection: "edges",
|
|
rows: [
|
|
{ index: 1, from_index: 1, to_index: 0 },
|
|
{ index: 3, from_index: 3, to_index: 0 },
|
|
],
|
|
},
|
|
});
|
|
const empty = await call("inspect_analysis_view", {
|
|
source,
|
|
view: {
|
|
kind: "rust",
|
|
collection: "packages",
|
|
names: [],
|
|
versions: ["1"],
|
|
fields: ["name"],
|
|
},
|
|
});
|
|
expect(
|
|
parseEvidence(empty.structuredContent).normalized_result,
|
|
).toMatchObject({
|
|
page: { rows: [] },
|
|
coverage: { total: 0, exhausted: true },
|
|
});
|
|
}
|
|
};
|
|
|
|
cliTest(
|
|
"queries stable Rust packages and edges through real CLI/MCP and portable Evidence",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-rust-views-");
|
|
const { call } = await connectLocalToolsMcp();
|
|
for (const format of ["elf", "pe", "macho"] as const) {
|
|
const path = join(root, `source.${format}`);
|
|
const output = join(root, `${format}-source.json`);
|
|
const payload = rustDependencyPayload({
|
|
packages: [
|
|
{
|
|
name: "same",
|
|
version: "1",
|
|
source: "crates.io",
|
|
dependencies: [2],
|
|
features: ["default"],
|
|
},
|
|
{
|
|
name: "same",
|
|
version: "2",
|
|
source: "git+https://upstream.example/repo",
|
|
dependencies: [0, 2],
|
|
},
|
|
{ name: "leaf", version: "1", source: "local" },
|
|
{
|
|
name: "app",
|
|
version: "1",
|
|
source: "local",
|
|
dependencies: [0, 1],
|
|
root: true,
|
|
},
|
|
],
|
|
});
|
|
await writeFile(path, createRustImage({ format, payload }));
|
|
const fullReply = await call("inspect_rust_binary", { path });
|
|
expect(fullReply.isError).not.toBe(true);
|
|
const full = parseEvidence(fullReply.structuredContent);
|
|
const report = rustBinarySchema.parse(full.normalized_result);
|
|
const explicit = await call("inspect_rust_binary", {
|
|
path,
|
|
detail: "complete",
|
|
});
|
|
expect(parseEvidence(explicit.structuredContent)).toEqual(full);
|
|
const selection = {
|
|
collection: "packages",
|
|
names: ["same"],
|
|
fields: ["name", "version", "dependencies", "features"],
|
|
};
|
|
const direct = await call("inspect_rust_binary", {
|
|
path,
|
|
view: selection,
|
|
});
|
|
expect(direct.isError, JSON.stringify(direct)).not.toBe(true);
|
|
const selected = parseEvidence(
|
|
direct.structuredContent,
|
|
).normalized_result;
|
|
expect(selected).toMatchObject({
|
|
kind: "rust",
|
|
parent_evidence_id: full.evidence_id,
|
|
page: {
|
|
collection: "packages",
|
|
rows: [
|
|
{
|
|
index: 0,
|
|
name: "same",
|
|
version: "1",
|
|
dependencies: [2],
|
|
features: ["default"],
|
|
},
|
|
{ index: 1, name: "same", version: "2", dependencies: [0, 2] },
|
|
],
|
|
},
|
|
});
|
|
const summary = await call("inspect_rust_binary", {
|
|
path,
|
|
detail: "summary",
|
|
});
|
|
expect(summary.isError).not.toBe(true);
|
|
expect(
|
|
parseEvidence(summary.structuredContent).normalized_result,
|
|
).toMatchObject({
|
|
kind: "summary",
|
|
summary: {
|
|
auditable_metadata: {
|
|
counts: { packages: 4, edges: 5 },
|
|
format_version: null,
|
|
},
|
|
},
|
|
source_coverage: {
|
|
embedded_records: "complete",
|
|
runtime_dependencies: "unknown",
|
|
},
|
|
});
|
|
const delivered = await cli.run({
|
|
arguments: [
|
|
"inspect-rust-binary",
|
|
path,
|
|
"--view",
|
|
JSON.stringify(selection),
|
|
"--evidence_output",
|
|
output,
|
|
"--json",
|
|
],
|
|
});
|
|
expect(delivered.exitCode, delivered.stderr).toBe(0);
|
|
expect(delivered.json).toMatchObject({
|
|
summary: { normalized_result: selected },
|
|
});
|
|
const bundle = await readEvidenceBundle(output);
|
|
if (!bundle.ok) throw bundle.error;
|
|
expect(
|
|
bundle.value.records.find(
|
|
(row) => row.evidence_id === full.evidence_id,
|
|
),
|
|
).toEqual({ ...full, caller_input_path: path });
|
|
const exported = join(root, `${format}-record.json`);
|
|
await writeFile(exported, JSON.stringify(full));
|
|
await unlink(path);
|
|
|
|
await assertRetainedPages(call, full.evidence_id, exported);
|
|
const malformed = structuredClone(report);
|
|
malformed.auditable_metadata!.dependency_edges[0]!.to_index = 999;
|
|
const invalid = createEvidence(
|
|
{
|
|
path,
|
|
sha256: report.artifact.sha256,
|
|
format: format === "macho" ? "mach-o" : format,
|
|
...fileSubjectArchitecture(full.subject),
|
|
},
|
|
full.provider,
|
|
{
|
|
operation: full.operation,
|
|
parameters: full.parameters,
|
|
result: malformed,
|
|
},
|
|
);
|
|
expect(
|
|
parseMcpToolError(
|
|
await call("inspect_analysis_view", {
|
|
source: { kind: "inline", evidence: invalid },
|
|
view: { kind: "rust", collection: "edges" },
|
|
}),
|
|
).error,
|
|
).toMatchObject({ code: "invalid_request" });
|
|
}
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"queries historical feature omissions from authenticated bundles without changing the parent",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-rust-historical-features-");
|
|
const path = join(root, "source.elf");
|
|
await writeFile(
|
|
path,
|
|
createRustImage({
|
|
format: "elf",
|
|
payload: rustDependencyPayload({
|
|
packages: [{ name: "old", version: "1", source: "local" }],
|
|
}),
|
|
}),
|
|
);
|
|
const { call } = await connectLocalToolsMcp();
|
|
const captured = await call("inspect_rust_binary", { path });
|
|
expect(captured.isError, JSON.stringify(captured.content)).not.toBe(true);
|
|
const full = parseEvidence(captured.structuredContent);
|
|
const report = rustBinarySchema.parse(full.normalized_result);
|
|
const metadata = report.auditable_metadata;
|
|
if (metadata === null) throw new Error("Expected Rust dependency metadata");
|
|
const historical = createEvidence(
|
|
{
|
|
path,
|
|
sha256: report.artifact.sha256,
|
|
format: "elf",
|
|
...fileSubjectArchitecture(full.subject),
|
|
},
|
|
full.provider,
|
|
{
|
|
operation: full.operation,
|
|
parameters: full.parameters,
|
|
result: {
|
|
...report,
|
|
auditable_metadata: {
|
|
...metadata,
|
|
packages: metadata.packages.map(
|
|
({ features: _features, ...row }) => row,
|
|
),
|
|
},
|
|
},
|
|
},
|
|
);
|
|
const bundle = join(root, "historical-bundle.json");
|
|
const record = join(root, "historical-record.json");
|
|
await writeFile(bundle, JSON.stringify(createEvidenceBundle([historical])));
|
|
await writeFile(record, JSON.stringify(historical));
|
|
await unlink(path);
|
|
const view = { kind: "rust", collection: "packages", fields: ["features"] };
|
|
for (const source of [
|
|
{ kind: "retained-evidence", evidence_id: historical.evidence_id },
|
|
{ kind: "evidence-file", path: record },
|
|
]) {
|
|
const reply = await cli.run({
|
|
arguments: [
|
|
"inspect-analysis-view",
|
|
JSON.stringify({ source, view }),
|
|
...(source.kind === "retained-evidence"
|
|
? ["--evidence-bundle", bundle]
|
|
: []),
|
|
"--json",
|
|
],
|
|
});
|
|
expect(reply.exitCode, reply.stderr + JSON.stringify(reply.json)).toBe(0);
|
|
expect(parseEvidence(reply.json).normalized_result).toMatchObject({
|
|
parent_evidence_id: historical.evidence_id,
|
|
page: { rows: [{ index: 0, features: null }] },
|
|
});
|
|
}
|
|
const imported = await call("import_evidence_bundle", { path: bundle });
|
|
expect(imported.isError, JSON.stringify(imported.content)).not.toBe(true);
|
|
for (const fields of [["features"], [], ["features"]]) {
|
|
const reply = await call("inspect_analysis_view", {
|
|
source: {
|
|
kind: "retained-evidence",
|
|
evidence_id: historical.evidence_id,
|
|
},
|
|
view: { ...view, fields },
|
|
});
|
|
expect(reply.isError, JSON.stringify(reply.content)).not.toBe(true);
|
|
expect(
|
|
parseEvidence(reply.structuredContent).normalized_result,
|
|
).toMatchObject({
|
|
parent_evidence_id: historical.evidence_id,
|
|
page: {
|
|
rows: [
|
|
fields.length === 0 ? { index: 0 } : { index: 0, features: null },
|
|
],
|
|
},
|
|
});
|
|
}
|
|
expect(JSON.parse(await readFile(record, "utf8"))).toEqual(historical);
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"preserves unknown Rust metadata and refuses invalid compact CLI choices before reading",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-rust-view-missing-");
|
|
const path = join(root, "plain.elf");
|
|
await writeFile(
|
|
path,
|
|
createRustImage({ format: "elf", omitSection: true }),
|
|
);
|
|
const { call } = await connectLocalToolsMcp();
|
|
const summary = await call("inspect_rust_binary", {
|
|
path,
|
|
detail: "summary",
|
|
});
|
|
expect(summary.isError).not.toBe(true);
|
|
const view = analysisViewResultSchema.parse(
|
|
parseEvidence(summary.structuredContent).normalized_result,
|
|
);
|
|
expect(view).toMatchObject({
|
|
summary: { auditable_metadata: null },
|
|
source_coverage: {
|
|
embedded_records: "unknown",
|
|
runtime_dependencies: "unknown",
|
|
},
|
|
});
|
|
const missing = join(root, "never-created");
|
|
for (const args of [
|
|
["--detail", "summary"],
|
|
["--view", "{"],
|
|
["--detail", "complete", "--view", '{"collection":"packages"}'],
|
|
]) {
|
|
const refused = await cli.run({
|
|
arguments: ["inspect-rust-binary", missing, ...args, "--json"],
|
|
});
|
|
expect(refused.exitCode).toBe(1);
|
|
expect(refused.json).toMatchObject({ code: "invalid_request" });
|
|
expect(JSON.stringify(refused.json)).not.toContain("ENOENT");
|
|
}
|
|
expect((await readFile(path)).length).toBeGreaterThan(0);
|
|
},
|
|
);
|