mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +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.
301 lines
10 KiB
TypeScript
301 lines
10 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
cdpCleanupGraceExpired,
|
|
cdpCommandDeadlineRecovery,
|
|
cdpDiscoveryTimeoutRecovery,
|
|
} from "./browserDeadline.js";
|
|
import { listBrowserTargetsInputSchema } from "./browserObservation.js";
|
|
import {
|
|
analyzeWebBundleInputSchema,
|
|
webBundleHeapExhaustedReason,
|
|
webBundleHeapExhaustedRemediation,
|
|
webBundleHeapLimit,
|
|
webBundleMemoryExhaustion,
|
|
webBundleResultAdmissionFailure,
|
|
webBundleScriptTimeoutRecovery,
|
|
} from "./webBundleAnalysis.js";
|
|
import {
|
|
inspectWebNetworkCaptureInputSchema,
|
|
webNetworkCaptureTimeoutRecovery,
|
|
} from "./webNetworkCapture.js";
|
|
import {
|
|
webSourceLocationInputSchema,
|
|
webSourceMapDecodeTimeoutRecovery,
|
|
} from "./webSourceLocation.js";
|
|
|
|
const bundle = {
|
|
cdp_endpoint: "http://127.0.0.1:9222",
|
|
target_id: "page",
|
|
};
|
|
|
|
describe("web deadline controls", () => {
|
|
it("rejects a per-script deadline above the total", () => {
|
|
const parsed = analyzeWebBundleInputSchema.safeParse({
|
|
...bundle,
|
|
analysis_timeout_ms: 40_000,
|
|
total_analysis_timeout_ms: 30_000,
|
|
});
|
|
expect(parsed.success).toBe(false);
|
|
if (parsed.success) return;
|
|
expect(
|
|
parsed.error.issues.map((issue) => issue.message).join(" "),
|
|
).toContain("analysis_timeout_ms");
|
|
});
|
|
|
|
it("keeps omitted web-bundle deadlines at today's defaults", () => {
|
|
const parsed = analyzeWebBundleInputSchema.parse(bundle);
|
|
expect(parsed.analysis_timeout_ms).toBeUndefined();
|
|
expect(parsed.total_analysis_timeout_ms).toBeUndefined();
|
|
expect(parsed.max_heap_mb).toBeUndefined();
|
|
expect(parsed.source_map_fetch_timeout_ms).toBeUndefined();
|
|
expect(parsed.discovery_timeout_ms).toBeUndefined();
|
|
expect(parsed.command_timeout_ms).toBeUndefined();
|
|
});
|
|
|
|
it("accepts the promoted deadlines inside 1..2147483647", () => {
|
|
expect(
|
|
analyzeWebBundleInputSchema.safeParse({
|
|
...bundle,
|
|
discovery_timeout_ms: 2_147_483_647,
|
|
command_timeout_ms: 2_147_483_647,
|
|
}).success,
|
|
).toBe(true);
|
|
expect(
|
|
listBrowserTargetsInputSchema.safeParse({
|
|
cdp_endpoint: "http://127.0.0.1:9222",
|
|
discovery_timeout_ms: 15_000,
|
|
}).success,
|
|
).toBe(true);
|
|
expect(
|
|
listBrowserTargetsInputSchema.safeParse({
|
|
cdp_endpoint: "http://127.0.0.1:9222",
|
|
discovery_timeout_ms: 0,
|
|
}).success,
|
|
).toBe(false);
|
|
expect(
|
|
listBrowserTargetsInputSchema.safeParse({
|
|
cdp_endpoint: "http://127.0.0.1:9222",
|
|
command_timeout_ms: 1_500,
|
|
}).success,
|
|
).toBe(false);
|
|
expect(
|
|
inspectWebNetworkCaptureInputSchema.safeParse({
|
|
capture_path: "/tmp/capture.har",
|
|
format: "har",
|
|
capture_timeout_ms: 0,
|
|
}).success,
|
|
).toBe(false);
|
|
expect(
|
|
webSourceLocationInputSchema.safeParse({
|
|
manifest_path: "/tmp/manifest.json",
|
|
script_index: 0,
|
|
source_map: {
|
|
path: "/tmp/app.js.map",
|
|
url: "https://example.test/app.js.map",
|
|
},
|
|
generated_position: { line: 1, column: 0 },
|
|
decode_timeout_ms: 20_000,
|
|
}).success,
|
|
).toBe(true);
|
|
});
|
|
|
|
it("names each deadline and the independent budgets it does not raise", () => {
|
|
expect(webBundleScriptTimeoutRecovery(30_000).userMessage).toContain(
|
|
"analysis_timeout_ms",
|
|
);
|
|
const captureRecovery = webNetworkCaptureTimeoutRecovery(30_000);
|
|
for (const control of [
|
|
"max_input_bytes",
|
|
"max_reply_bytes",
|
|
"max_nesting_depth",
|
|
]) {
|
|
expect(captureRecovery.remediationAction).toContain(control);
|
|
}
|
|
expect(captureRecovery.remediationAction).toContain(
|
|
"capture_timeout_ms does not raise them",
|
|
);
|
|
expect(webSourceMapDecodeTimeoutRecovery(20_000).userMessage).toContain(
|
|
"decode_timeout_ms",
|
|
);
|
|
expect(
|
|
cdpCommandDeadlineRecovery(20_000, "handshake").userMessage,
|
|
).toContain("command_timeout_ms");
|
|
expect(cdpCleanupGraceExpired()).toContain("5000 ms");
|
|
expect(cdpCleanupGraceExpired()).toContain("no runtime override");
|
|
const inspector = cdpCommandDeadlineRecovery(
|
|
20_000,
|
|
"handshake",
|
|
undefined,
|
|
false,
|
|
);
|
|
expect(inspector.userMessage).not.toContain("command_timeout_ms");
|
|
expect(inspector.remediationAction).not.toContain("--command-timeout-ms");
|
|
// A fixed deadline binds no per-call control.
|
|
expect(inspector.limit).toBeUndefined();
|
|
expect(inspector.remediationAction).toContain("no runtime override");
|
|
const selectableDiscovery = cdpDiscoveryTimeoutRecovery(
|
|
"inspect_web_page",
|
|
15_000,
|
|
"browser-socket",
|
|
"The 67108864-byte browser-socket message budget",
|
|
);
|
|
expect(selectableDiscovery.userMessage).toContain(
|
|
"15000 ms discovery_timeout_ms",
|
|
);
|
|
expect(selectableDiscovery.remediationAction).toContain(
|
|
"Increase discovery_timeout_ms above 15000",
|
|
);
|
|
expect(selectableDiscovery.remediationAction).not.toContain("--");
|
|
expect(selectableDiscovery.limit).toMatchObject({
|
|
control_kind: "parameter",
|
|
parameter: "discovery_timeout_ms",
|
|
effective_value: 15_000,
|
|
});
|
|
expect(selectableDiscovery.remediationAction).toContain(
|
|
"command_timeout_ms does not raise it",
|
|
);
|
|
const fixedDiscovery = cdpDiscoveryTimeoutRecovery(
|
|
"observe_web_execution",
|
|
10_000,
|
|
"response",
|
|
"The 8388608-byte discovery document budget",
|
|
);
|
|
expect(fixedDiscovery.userMessage).not.toContain("discovery_timeout_ms");
|
|
expect(fixedDiscovery.remediationAction).not.toContain(
|
|
"--discovery-timeout-ms",
|
|
);
|
|
expect(fixedDiscovery.limit).toBeUndefined();
|
|
expect(fixedDiscovery.remediationAction).toContain("no runtime override");
|
|
});
|
|
});
|
|
|
|
it("names web-bundle exhaustion by the runtime that enforced it", () => {
|
|
const node = webBundleMemoryExhaustion({
|
|
runtime: "node",
|
|
heapMb: 1024,
|
|
memoryLimitReached: true,
|
|
processMemoryLimitBytes: 99,
|
|
});
|
|
expect(node.kind).toBe("v8-heap");
|
|
expect(webBundleHeapExhaustedReason(node)).toContain(
|
|
"exhausted its max_heap_mb V8 old-space heap of 1024 MiB",
|
|
);
|
|
expect(webBundleHeapExhaustedRemediation(node)).toContain(
|
|
"Increase max_heap_mb above 1024",
|
|
);
|
|
expect(webBundleHeapExhaustedRemediation(node)).not.toContain("--");
|
|
expect(webBundleHeapLimit(node)).toMatchObject({
|
|
control_kind: "parameter",
|
|
parameter: "max_heap_mb",
|
|
effective_value: 1024,
|
|
unit: "MiB",
|
|
});
|
|
|
|
const commitBytes = 1024 * 1024 * 1024 + 512 * 1024 * 1024;
|
|
const windows = webBundleMemoryExhaustion({
|
|
runtime: "bun",
|
|
heapMb: 1024,
|
|
memoryLimitReached: true,
|
|
processMemoryLimitBytes: commitBytes,
|
|
});
|
|
const windowsReason = webBundleHeapExhaustedReason(windows);
|
|
expect(windows.kind).toBe("process-commit");
|
|
expect(windowsReason).toContain(
|
|
`${String(commitBytes)}-byte process commit limit`,
|
|
);
|
|
expect(windowsReason).toContain("512 MiB Bun runtime reserve");
|
|
expect(windowsReason).not.toContain("V8 old-space heap of");
|
|
const windowsRemediation = webBundleHeapExhaustedRemediation(windows);
|
|
expect(windowsRemediation).toContain("Increase max_heap_mb above 1024");
|
|
expect(windowsRemediation).toContain("Windows process commit limit");
|
|
expect(windowsRemediation).toContain("not a V8 old-space heap");
|
|
expect(windowsRemediation).not.toContain(
|
|
"exhausted its max_heap_mb V8 old-space heap",
|
|
);
|
|
|
|
const bun = webBundleMemoryExhaustion({
|
|
runtime: "bun",
|
|
heapMb: 1024,
|
|
memoryLimitReached: false,
|
|
processMemoryLimitBytes: null,
|
|
});
|
|
expect(bun.kind).toBe("bun-allocation");
|
|
expect(webBundleHeapExhaustedReason(bun)).toContain(
|
|
"Bun ignores the V8 old-space flag",
|
|
);
|
|
expect(webBundleHeapExhaustedReason(bun)).not.toContain(
|
|
"V8 old-space heap of",
|
|
);
|
|
expect(webBundleHeapExhaustedRemediation(bun)).not.toContain(
|
|
"Increase max_heap_mb",
|
|
);
|
|
// Raising max_heap_mb does not change a Bun allocation exit.
|
|
expect(webBundleHeapLimit(bun)).toBeUndefined();
|
|
expect(webBundleHeapExhaustedRemediation(bun)).toContain(
|
|
"does not change this exit",
|
|
);
|
|
|
|
const beforeLimit = webBundleMemoryExhaustion({
|
|
runtime: "bun",
|
|
heapMb: 1024,
|
|
memoryLimitReached: false,
|
|
processMemoryLimitBytes: commitBytes,
|
|
});
|
|
expect(beforeLimit.kind).toBe("bun-allocation");
|
|
const beforeLimitReason = webBundleHeapExhaustedReason(beforeLimit);
|
|
expect(beforeLimitReason).toContain(
|
|
`${String(commitBytes)}-byte process commit limit was reported as reached`,
|
|
);
|
|
expect(beforeLimitReason).not.toContain(
|
|
"enforces no analyzer process commit limit",
|
|
);
|
|
expect(webBundleHeapExhaustedRemediation(beforeLimit)).toContain(
|
|
"was not reported as reached",
|
|
);
|
|
expect(webBundleHeapExhaustedRemediation(beforeLimit)).not.toContain(
|
|
"Increase max_heap_mb",
|
|
);
|
|
expect(webBundleHeapExhaustedReason(bun)).toContain(
|
|
"enforces no analyzer process commit limit",
|
|
);
|
|
expect(
|
|
webBundleHeapExhaustedRemediation({
|
|
kind: "v8-heap",
|
|
heapMb: 16_384,
|
|
}),
|
|
).toContain("already at the maximum 16384 MiB");
|
|
});
|
|
|
|
it("names host heap pressure only while the fixed result budget still has room", () => {
|
|
const host = webBundleResultAdmissionFailure({
|
|
fixedBudgetBytes: 8_388_608,
|
|
fixedRemainingBytes: 8_388_608,
|
|
hostCapacityBytes: 0,
|
|
});
|
|
expect(host.kind).toBe("host-capacity");
|
|
expect(host.reason).toContain("host result capacity 0 bytes");
|
|
expect(host.reason).toContain("still has 8388608 bytes available");
|
|
expect(host.reason).not.toContain("has no further room");
|
|
if (host.kind !== "host-capacity") return;
|
|
expect(host.remediationAction).not.toContain("has no further room");
|
|
expect(host.remediationAction).toContain("NODE_OPTIONS");
|
|
expect(host.reportedLimits).toEqual({
|
|
result_bytes: 8_388_608,
|
|
result_budget_remaining_bytes: 8_388_608,
|
|
host_result_capacity_bytes: 0,
|
|
});
|
|
|
|
const fixed = webBundleResultAdmissionFailure({
|
|
fixedBudgetBytes: 8_388_608,
|
|
fixedRemainingBytes: 0,
|
|
hostCapacityBytes: 0,
|
|
});
|
|
expect(fixed.kind).toBe("fixed-budget");
|
|
expect(fixed.reason).toContain(
|
|
"8388608-byte web-bundle result budget has no further room",
|
|
);
|
|
expect(fixed.reason).toContain("no runtime override");
|
|
expect(fixed.reason).not.toContain("host result capacity");
|
|
});
|