mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +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.
252 lines
8.1 KiB
TypeScript
252 lines
8.1 KiB
TypeScript
import { Writable } from "node:stream";
|
|
|
|
import { Cli, Formatter } from "incur";
|
|
import { expect, it } from "vitest";
|
|
import { z } from "zod";
|
|
|
|
import { parseCliOutputArguments } from "../../../src/cliOutput.js";
|
|
import { registerContractCommand } from "../../../src/cli/contractCommand.js";
|
|
import { createCliResultOutput } from "../../../src/cli/cliResultOutput.js";
|
|
import {
|
|
cliResultControls,
|
|
withCliResultControls,
|
|
} from "../../../src/cli/cliResultControls.js";
|
|
import { cliResultControlsIn } from "../../../src/cli/projectCliAnalysisResult.js";
|
|
import type { CliInstance } from "../../../src/cli/types.js";
|
|
import { deadlineParameterLimit } from "../../../src/domain/analysisResourceLimits.js";
|
|
import {
|
|
analysisParameterLimitSchema,
|
|
analysisResultLimitSchema,
|
|
} from "../../../src/domain/analysisSettingDefinitions.js";
|
|
import { producerLimitControl } from "../../../src/domain/producerResourceLimits.js";
|
|
import { silentLogger } from "../../../src/logger.js";
|
|
|
|
/** A partial result that records its controls by contract field only. */
|
|
const partialResult = () => ({
|
|
status: "partial",
|
|
unknowns: [
|
|
{
|
|
dimension: "javascript_analysis",
|
|
limit: deadlineParameterLimit("worker_timeout_ms", 5, 1_000),
|
|
},
|
|
],
|
|
coverage: {
|
|
limits: [
|
|
producerLimitControl("output_bytes", 4, 8),
|
|
// An environment control has no per-call option.
|
|
{
|
|
control_kind: "environment",
|
|
environment: "REA_FIXTURE_BYTES",
|
|
parameter: "ignored",
|
|
},
|
|
],
|
|
},
|
|
// A control this command takes no flag for keeps only its field.
|
|
unbound: { limit: deadlineParameterLimit("other_timeout_ms", 1, 2) },
|
|
// Captured content that looks like a control is data, not a reference
|
|
// REA recorded, even when it names a bound flag.
|
|
captured: {
|
|
reported: deadlineParameterLimit("max_reply_bytes", 1, 2),
|
|
nested: [{ limit: deadlineParameterLimit("max_reply_bytes", 1, 2) }],
|
|
},
|
|
// An omitted optional value that JSON output skips ends nothing.
|
|
trailing: undefined,
|
|
});
|
|
|
|
/** The fixture's output schema: only its declared positions are controls. */
|
|
const partialResultSchema = z.strictObject({
|
|
status: z.string(),
|
|
unknowns: z.array(
|
|
z.strictObject({
|
|
dimension: z.string(),
|
|
limit: analysisResultLimitSchema.exactOptional(),
|
|
}),
|
|
),
|
|
coverage: z.strictObject({
|
|
limits: z.array(
|
|
z.union([
|
|
analysisParameterLimitSchema,
|
|
z.strictObject({
|
|
control_kind: z.literal("environment"),
|
|
environment: z.string(),
|
|
parameter: z.string(),
|
|
}),
|
|
]),
|
|
),
|
|
}),
|
|
unbound: z.strictObject({ limit: analysisParameterLimitSchema }),
|
|
captured: z.record(z.string(), z.unknown()),
|
|
trailing: z.undefined().optional(),
|
|
});
|
|
|
|
const binding = {
|
|
operation: "inspect_control_fixture",
|
|
fields: {},
|
|
flags: {
|
|
worker_timeout_ms: "--worker-timeout-ms",
|
|
producer_limits: "--producer-limits",
|
|
max_reply_bytes: "--max-reply-bytes",
|
|
},
|
|
};
|
|
|
|
it("collects each recorded control's flag without changing the result", () => {
|
|
const result = partialResult();
|
|
const before = structuredClone(result);
|
|
expect(cliResultControlsIn(result, partialResultSchema, binding)).toEqual({
|
|
worker_timeout_ms: "--worker-timeout-ms",
|
|
"producer_limits.output_bytes": "--producer-limits",
|
|
});
|
|
expect(result).toEqual(before);
|
|
});
|
|
|
|
/** Run the fixture command once, returning its output and recorded controls. */
|
|
const runFixtureCommand = async (produce: () => unknown) => {
|
|
const contract = {
|
|
name: "inspect_control_fixture",
|
|
inputSchema: z.strictObject({
|
|
path: z.string(),
|
|
worker_timeout_ms: z.number().int().optional(),
|
|
}),
|
|
outputSchema: partialResultSchema,
|
|
};
|
|
const cli = Cli.create("rea-result-controls", { version: "1", sync: false });
|
|
registerContractCommand(
|
|
cli as unknown as CliInstance,
|
|
silentLogger,
|
|
contract,
|
|
{
|
|
command: "inspect-control-fixture",
|
|
description: "Control fixture",
|
|
positionals: ["path"],
|
|
},
|
|
async () => produce() as never,
|
|
);
|
|
const command = Cli.toCommands.get(cli)?.get("inspect-control-fixture");
|
|
if (command === undefined) throw new Error("command is not registered");
|
|
const parse = (key: "args" | "options", value: unknown) =>
|
|
(Reflect.get(command, key) as { parse(v: unknown): unknown }).parse(value);
|
|
return withCliResultControls(async () => {
|
|
const value: unknown = await (
|
|
Reflect.get(command, "run") as (value: unknown) => Promise<unknown>
|
|
)({
|
|
args: parse("args", { path: "fixture.bin" }),
|
|
options: parse("options", {}),
|
|
});
|
|
return { output: value, controls: cliResultControls() };
|
|
});
|
|
};
|
|
|
|
it("records the controls of a contract command's result and returns the result unchanged", async () => {
|
|
const { output, controls } = await runFixtureCommand(partialResult);
|
|
expect(output).toEqual(partialResult());
|
|
// Only controls this command takes as options are rendered.
|
|
expect(controls).toEqual({ worker_timeout_ms: "--worker-timeout-ms" });
|
|
});
|
|
|
|
it("reads a failure's partial Evidence of the same operation at the declared positions only", async () => {
|
|
const failure = (operation: string) => ({
|
|
code: "timeout",
|
|
message: "Fixture stopped",
|
|
details: {
|
|
partial_observation: { ...partialResult(), operation },
|
|
},
|
|
});
|
|
const same = await runFixtureCommand(() =>
|
|
failure("inspect_control_fixture"),
|
|
);
|
|
expect(same.output).toEqual(failure("inspect_control_fixture"));
|
|
expect(same.controls).toEqual({ worker_timeout_ms: "--worker-timeout-ms" });
|
|
// Evidence of another operation is not described by this output schema.
|
|
const other = await runFixtureCommand(() => failure("inspect_source_step"));
|
|
expect(other.controls).toBeUndefined();
|
|
});
|
|
|
|
const written = async (
|
|
argv: readonly string[],
|
|
cliControls?: Readonly<Record<string, string>>,
|
|
): Promise<{ readonly text: string; readonly collected: number }> => {
|
|
const chunks: Buffer[] = [];
|
|
const destination = new Writable({
|
|
write(chunk: Buffer, _encoding, callback) {
|
|
chunks.push(chunk);
|
|
callback();
|
|
},
|
|
});
|
|
const output = createCliResultOutput(
|
|
parseCliOutputArguments(["fixture", ...argv]),
|
|
destination,
|
|
);
|
|
if (output === undefined) throw new Error("Missing output surface");
|
|
const format = argv[argv.indexOf("--format") + 1] ?? "json";
|
|
let collected = 0;
|
|
// The ordinary command path: no forced output, controls collected on demand.
|
|
const handled = await output.write(partialResult(), {
|
|
command: "fixture",
|
|
duration: "0ms",
|
|
format,
|
|
collectCliControls: () => {
|
|
collected += 1;
|
|
return cliControls;
|
|
},
|
|
});
|
|
return {
|
|
text: handled ? Buffer.concat(chunks).toString("utf8") : "",
|
|
collected,
|
|
};
|
|
};
|
|
|
|
const cliControls = { worker_timeout_ms: "--worker-timeout-ms" };
|
|
|
|
it("renders the flags in the full-output envelope, outside the result", async () => {
|
|
const full = await written(
|
|
["--format", "json", "--full-output"],
|
|
cliControls,
|
|
);
|
|
expect(JSON.parse(full.text)).toEqual({
|
|
ok: true,
|
|
data: partialResult(),
|
|
meta: {
|
|
command: "fixture",
|
|
duration: "0ms",
|
|
cli_controls: cliControls,
|
|
},
|
|
});
|
|
expect(full.collected).toBe(1);
|
|
// The bare result is the record itself: it gains nothing, and the result
|
|
// is not walked for controls nothing will show.
|
|
const bare = await written(["--format", "json"], cliControls);
|
|
expect(JSON.parse(bare.text)).toEqual(partialResult());
|
|
expect(bare.collected).toBe(0);
|
|
expect(
|
|
JSON.parse((await written(["--format", "json", "--full-output"])).text),
|
|
).toEqual({
|
|
ok: true,
|
|
data: partialResult(),
|
|
meta: { command: "fixture", duration: "0ms" },
|
|
});
|
|
});
|
|
|
|
it.each(["yaml", "toon"] as const)(
|
|
"keeps the requested %s format when the envelope shows the flags",
|
|
async (format) => {
|
|
const { text } = await written(
|
|
["--format", format, "--full-output"],
|
|
cliControls,
|
|
);
|
|
expect(text).toBe(
|
|
`${Formatter.format(
|
|
{
|
|
ok: true,
|
|
data: partialResult(),
|
|
meta: {
|
|
command: "fixture",
|
|
duration: "0ms",
|
|
cli_controls: cliControls,
|
|
},
|
|
},
|
|
format,
|
|
)}\n`,
|
|
);
|
|
},
|
|
);
|