mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
* fix(limits): report details.limit for ELF dependency, unwind, and kernel reader refusals
Attach structured `details.limit` metadata to per-call budget refusals across
the remaining `src/native/elf/` providers (`ElfDependenciesProvider`,
`KernelModuleProvider`, `KernelBuildConfigProvider`, and
`ElfUnwindRangesProvider`), following the `#14243` shared-budget pattern:
- Generalize `elfReadBudgetLimit` in `src/domain/native/elfReadBudgets.ts` so
ELF and kernel readers share one parameter-limit builder.
- Export `ELF_DEPENDENCIES_READ_BUDGETS`, `KERNEL_MODULE_READ_BUDGETS`,
`KERNEL_BUILD_CONFIG_READ_BUDGETS`, and `ELF_UNWIND_RANGES_READ_BUDGETS` from
their domain schemas so Zod input bounds and projected `details.limit`
metadata have a single owner.
- Report `details.limit` for caller-selected file, entry, inflation, and record
budgets, including `compressed_candidate_bytes` (`max_config_bytes`), while
moving `KernelBuildConfigProvider` file-size handling onto
`offlineArtifactFailureDialect.fileSize` and removing its unreachable
`capacity` branch.
- Report `ElfUnwindRangesProvider`'s fixed 16 MiB `symbol_name_text_bytes`
allowance through `fixedAllowanceOptions` with narrowing guidance and
`related: { parameters: ["limit", "offset"] }`, registered in
`scripts/verify/fixed-ceiling-registry.json` under `#14235`, rather than
reporting an inverted `details.limit`.
- Remove `ElfDependenciesProvider.ts`, `ElfUnwindRangesProvider.ts`, and
`KernelBuildConfigProvider.ts` from
`scripts/verify/untyped-budget-refusal-baseline.json`, clearing all
`src/native/elf/` entries from the baseline, and update
`docs/reference/rea-limit-inventory.md` and
`docs/reference/limits-and-recovery.md`.
Part of #14234
* test(elf): assert CLI details.limit and flags for kernel module budgets
* fix(elf): report required_value for KernelModuleProvider max_file_bytes and add MCP recovery test
232 lines
8.0 KiB
TypeScript
232 lines
8.0 KiB
TypeScript
import { fileIdentity } from "../../fixtures/evidenceSubject.js";
|
|
import { canonicalOutputSchema } from "../../fixtures/canonicalOutputSchema.js";
|
|
import { writeFile } from "node:fs/promises";
|
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
import type { AnySchema } from "ajv";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
|
import { kernelModuleFixture } from "../../../src/native/elf/KernelModule.fixture.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { fileInspectionTest } from "../../support/mcp/fileInspection.js";
|
|
|
|
fileInspectionTest(
|
|
"keeps valid omitted modinfo fields distinct from malformed syntax and recovers on the same connection",
|
|
async ({ client }) => {
|
|
const root = await createTestTempDirectory("rea-kernel-module-text-mcp-");
|
|
const path = join(root, "text.ko");
|
|
const key = "k".repeat(257);
|
|
const value = "v".repeat(4097);
|
|
await writeFile(
|
|
path,
|
|
kernelModuleFixture({ modinfo: Buffer.from(`${key}=${value}\0`) }),
|
|
);
|
|
const inspect = async (budgets: Record<string, number> = {}) => {
|
|
const response = await client.callTool({
|
|
name: "inspect_kernel_module",
|
|
arguments: { path, ...budgets },
|
|
});
|
|
expect(response.isError, JSON.stringify(response.content)).not.toBe(true);
|
|
return response.structuredContent;
|
|
};
|
|
const initialReply = await inspect();
|
|
const outputSchema = canonicalOutputSchema("inspect_kernel_module");
|
|
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
|
expect(ajv.validateSchema(outputSchema as AnySchema)).toBe(true);
|
|
expect(ajv.compile(outputSchema as AnySchema)(initialReply)).toBe(true);
|
|
const parse = toolContract("inspect_kernel_module").outputSchema.parse;
|
|
const initial = parse(initialReply);
|
|
const omitted = initial.normalized_result.modinfo?.entries[0];
|
|
expect(omitted).toMatchObject({
|
|
status: "observed",
|
|
reason: null,
|
|
key: null,
|
|
value: null,
|
|
omitted_fields: ["key", "value"],
|
|
raw_hex: null,
|
|
});
|
|
expect(() =>
|
|
parse({
|
|
...initial,
|
|
normalized_result: {
|
|
...initial.normalized_result,
|
|
modinfo: {
|
|
...initial.normalized_result.modinfo,
|
|
entries: [
|
|
{
|
|
...omitted,
|
|
status: "malformed",
|
|
reason: "modinfo_field_exceeds_limit",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
}),
|
|
).toThrow();
|
|
expect(initial.normalized_result.coverage.status).toBe("partial");
|
|
expect(initial.normalized_result.limitations).toEqual(
|
|
expect.arrayContaining([
|
|
expect.stringContaining("max_modinfo_key_bytes at least 257"),
|
|
expect.stringContaining("max_modinfo_value_bytes at least 4097"),
|
|
]),
|
|
);
|
|
// The result records each control by contract field; MCP text names no
|
|
// CLI option.
|
|
expect(initial.normalized_result.modinfo?.omission_limits).toEqual([
|
|
{
|
|
control_kind: "parameter",
|
|
parameter: "max_modinfo_key_bytes",
|
|
effective_value: 256,
|
|
unit: "bytes",
|
|
minimum: 1,
|
|
maximum: 536870912,
|
|
default_value: 256,
|
|
applies_at: "next_call",
|
|
},
|
|
expect.objectContaining({
|
|
parameter: "max_modinfo_value_bytes",
|
|
effective_value: 4096,
|
|
default_value: 4096,
|
|
}),
|
|
]);
|
|
expect(initial.normalized_result.limitations.join(" ")).not.toContain(
|
|
"--max-modinfo",
|
|
);
|
|
const recovered = parse(
|
|
await inspect({
|
|
max_modinfo_key_bytes: 257,
|
|
max_modinfo_value_bytes: 4097,
|
|
}),
|
|
);
|
|
expect(recovered.subject).toEqual(initial.subject);
|
|
expect(recovered.normalized_result.modinfo?.entries[0]).toEqual({
|
|
...omitted,
|
|
key,
|
|
value,
|
|
omitted_fields: [],
|
|
});
|
|
expect(recovered.normalized_result.coverage.status).toBe("complete");
|
|
expect(recovered.normalized_result.modinfo).not.toHaveProperty(
|
|
"omission_limits",
|
|
);
|
|
},
|
|
);
|
|
|
|
fileInspectionTest(
|
|
"advertises inspect_kernel_module and reads an ELF32 big-endian module",
|
|
async ({ client }) => {
|
|
const advertised = (await client.listTools()).tools.find(
|
|
(tool) => tool.name === "inspect_kernel_module",
|
|
);
|
|
expect(advertised?.annotations).toMatchObject({
|
|
readOnlyHint: false,
|
|
idempotentHint: true,
|
|
});
|
|
const root = await createTestTempDirectory("rea-kernel-module-mcp-");
|
|
const path = join(root, "demo.ko");
|
|
await writeFile(path, kernelModuleFixture({ bits: 32, little: false }));
|
|
const response = await client.callTool({
|
|
name: "inspect_kernel_module",
|
|
arguments: { path },
|
|
});
|
|
expect(response.isError, JSON.stringify(response.content)).not.toBe(true);
|
|
const evidence = toolContract("inspect_kernel_module").outputSchema.parse(
|
|
response.structuredContent,
|
|
);
|
|
expect(evidence.normalized_result).toMatchObject({
|
|
format: "elf32",
|
|
byte_order: "big",
|
|
machine: 20,
|
|
applicability: "applicable",
|
|
});
|
|
expect(fileIdentity(evidence.subject).architecture).toBe("powerpc");
|
|
expect(evidence.normalized_result.modinfo?.entries[0]).toMatchObject({
|
|
key: "license",
|
|
value: "GPL",
|
|
});
|
|
expect(evidence.normalized_result.versions?.entries[1]?.crc_hex).toBe(
|
|
"90abcdef",
|
|
);
|
|
},
|
|
);
|
|
|
|
fileInspectionTest(
|
|
"reports structured details.limit without CLI flags for max_file_bytes and max_entries refusals and recovers",
|
|
async ({ client }) => {
|
|
const root = await createTestTempDirectory("rea-kernel-module-mcp-limit-");
|
|
const path = join(root, "demo.ko");
|
|
const bytes = kernelModuleFixture();
|
|
await writeFile(path, bytes);
|
|
|
|
const parseError = (reply: Awaited<ReturnType<typeof client.callTool>>) => {
|
|
expect(reply.isError).toBe(true);
|
|
const first = (
|
|
reply.content as Array<{ type: string; text?: string }>
|
|
)[0];
|
|
return (
|
|
JSON.parse(first?.text ?? "{}") as {
|
|
error: {
|
|
code: string;
|
|
remediation: { action: string };
|
|
details: { limit?: Record<string, unknown> };
|
|
};
|
|
}
|
|
).error;
|
|
};
|
|
|
|
const fileRefusal = parseError(
|
|
await client.callTool({
|
|
name: "inspect_kernel_module",
|
|
arguments: { path, max_file_bytes: 64 },
|
|
}),
|
|
);
|
|
expect(fileRefusal.code).toBe("resource_constraint");
|
|
expect(fileRefusal.details.limit).toEqual({
|
|
control_kind: "parameter",
|
|
parameter: "max_file_bytes",
|
|
effective_value: 64,
|
|
unit: "bytes",
|
|
minimum: 64,
|
|
maximum: 536870912,
|
|
default_value: 67108864,
|
|
applies_at: "next_call",
|
|
required_value: bytes.length,
|
|
});
|
|
expect(fileRefusal.details.limit).not.toHaveProperty("cli_flag");
|
|
expect(fileRefusal.remediation.action).toContain("max_file_bytes");
|
|
expect(fileRefusal.remediation.action).not.toContain("--max-file-bytes");
|
|
|
|
const entryRefusal = parseError(
|
|
await client.callTool({
|
|
name: "inspect_kernel_module",
|
|
arguments: { path, max_entries: 1 },
|
|
}),
|
|
);
|
|
expect(entryRefusal.code).toBe("resource_constraint");
|
|
expect(entryRefusal.details.limit).toEqual({
|
|
control_kind: "parameter",
|
|
parameter: "max_entries",
|
|
effective_value: 1,
|
|
unit: "count",
|
|
minimum: 1,
|
|
maximum: 65536,
|
|
default_value: 8192,
|
|
applies_at: "next_call",
|
|
});
|
|
expect(entryRefusal.details.limit).not.toHaveProperty("cli_flag");
|
|
expect(entryRefusal.remediation.action).toContain("max_entries");
|
|
expect(entryRefusal.remediation.action).not.toContain("--max-entries");
|
|
|
|
const recovered = await client.callTool({
|
|
name: "inspect_kernel_module",
|
|
arguments: { path, max_file_bytes: bytes.length, max_entries: 16 },
|
|
});
|
|
expect(recovered.isError, JSON.stringify(recovered.content)).not.toBe(true);
|
|
expect(
|
|
toolContract("inspect_kernel_module").outputSchema.parse(
|
|
recovered.structuredContent,
|
|
).normalized_result.applicability,
|
|
).toBe("applicable");
|
|
},
|
|
);
|