Files
rea/tests/boundary/cli/nativeDispatchInputBudget.test.ts
T
Kaoru0822 3637205622 feat(native): let callers raise the Apple dispatch metadata input budget (#6233)
* feat(native): let callers raise the Apple dispatch metadata input budget

inspect_native_dispatch_metadata refused any Mach-O over a fixed 64 MiB
before decoding, and its recovery said there was no override. Most large
macOS binaries exceed it.

max_input_bytes (CLI --max-input-bytes) now selects the budget, default
64 MiB and at most 1 GiB, through the shared input contract, the enhanced
workflow and the native provider. Results record input_admission with the
effective budget, its source and the retained bytes. A refusal names the
observed size, the budget and its source, and the budget to select or, past
1 GiB, a deep analysis provider.

Fixes #3917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): describe --max-input-bytes in inspect-native-dispatch-metadata help

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(native): cover max_input_bytes forwarding through CLI and MCP

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:19:33 -07:00

63 lines
2.3 KiB
TypeScript

import { stat, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect } from "vitest";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { nativeDispatchMetadataResultSchema } from "../../../src/domain/native/objcSwiftMetadata.js";
import { objcRecordBudgetMacho } from "../../fixtures/objcRecordBudgetMacho.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
describe.skipIf(process.platform !== "darwin")(
"native dispatch input budget through the public CLI",
() => {
cliTest(
"forwards --max-input-bytes to the byte reader and records its admission",
async ({ cli }) => {
const directory = await createTestTempDirectory("rea-objc-input-");
const path = join(directory, "fixture.macho");
await writeFile(path, objcRecordBudgetMacho("class"));
const size = (await stat(path)).size;
const run = (...flags: string[]) =>
cli.run({
arguments: [
"inspect-native-dispatch-metadata",
path,
...flags,
"--json",
],
environment: { REA_LOG_LEVEL: "silent" },
});
const admission = (output: Awaited<ReturnType<typeof run>>) => {
expect(output.exitCode, `${output.stdout}\n${output.stderr}`).toBe(0);
return nativeDispatchMetadataResultSchema.parse(
parseEvidence(output.json).normalized_result,
).input_admission;
};
expect(admission(await run())).toEqual({
maximum_bytes: 67108864,
source: "default",
retained_bytes: size,
});
expect(admission(await run("--max-input-bytes", String(size)))).toEqual(
{ maximum_bytes: size, source: "caller", retained_bytes: size },
);
const refused = await run("--max-input-bytes", String(size - 1));
expect(refused.exitCode).not.toBe(0);
expect(refused.json).toMatchObject({
code: "resource_constraint",
details: {
reported_limits: {
input_bytes: size - 1,
input_bytes_source: "caller",
observed_input_bytes: size,
},
},
});
},
);
},
);