mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 14:35:45 +00:00
* test(limits): reference limit constants instead of repeating their values Point duplicated default literals at their owner constants and replace recovery-wording locks with the setting name, units, and those constants. Keep the single default pins that guard shipped values. * test(limits): pin the shipped Ghidra value-flow defaults Consumer checks follow the owner constants, so they no longer catch a change to 3000, 64, or 12000. One owner pin keeps those shipped values. Co-authored-by: morluto <morluto@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { STDIO_DEFAULT_MAX_BUFFER_SIZE } from "@modelcontextprotocol/server";
|
|
|
|
import {
|
|
MINIMUM_RESPONSE_BYTES,
|
|
nodeStringCeilingRecovery,
|
|
parseMcpResponseBudget,
|
|
stdioResponseBudgetRecovery,
|
|
} from "../../../src/config/mcpResponseBudget.js";
|
|
import {
|
|
MCP_RESULT_STRING_LIMIT,
|
|
NODE_MAX_STRING_LENGTH,
|
|
} from "../../../src/server/toolResultEncoding.js";
|
|
|
|
describe("MCP response budget configuration", () => {
|
|
it("requires the override to accommodate the pinned transport's default frames", () => {
|
|
expect(
|
|
parseMcpResponseBudget(String(STDIO_DEFAULT_MAX_BUFFER_SIZE)).ok,
|
|
).toBe(true);
|
|
expect(
|
|
parseMcpResponseBudget(String(STDIO_DEFAULT_MAX_BUFFER_SIZE - 1)).ok,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("names the effective stdio budget without claiming it raises the string ceiling", () => {
|
|
const effectiveResponseBytes = 20_971_520;
|
|
const recovery = stdioResponseBudgetRecovery(
|
|
effectiveResponseBytes,
|
|
MCP_RESULT_STRING_LIMIT,
|
|
NODE_MAX_STRING_LENGTH,
|
|
);
|
|
const nodeRecovery = nodeStringCeilingRecovery(
|
|
MCP_RESULT_STRING_LIMIT,
|
|
NODE_MAX_STRING_LENGTH,
|
|
);
|
|
expect(recovery).toContain("REA_MCP_MAX_RESPONSE_BYTES");
|
|
expect(recovery).toContain(`${String(effectiveResponseBytes)} bytes`);
|
|
expect(recovery).toContain(`${String(MINIMUM_RESPONSE_BYTES)} bytes`);
|
|
for (const guidance of [recovery, nodeRecovery]) {
|
|
expect(guidance).toContain(
|
|
`${String(MCP_RESULT_STRING_LIMIT)} UTF-16 code units`,
|
|
);
|
|
expect(guidance).toContain(
|
|
`${String(NODE_MAX_STRING_LENGTH)} UTF-16 code units`,
|
|
);
|
|
expect(guidance).toContain("REA_MCP_MAX_RESPONSE_BYTES");
|
|
}
|
|
expect(MCP_RESULT_STRING_LIMIT).toBeLessThan(NODE_MAX_STRING_LENGTH);
|
|
});
|
|
|
|
it.each(["", "1.5", "1e8", " 10485760", "9007199254740992"])(
|
|
"rejects malformed or unusable budgets: %j",
|
|
(value) => {
|
|
const parsed = parseMcpResponseBudget(value);
|
|
if (parsed.ok) throw new Error("Expected invalid budget");
|
|
expect(parsed.error.message).toContain("REA_MCP_MAX_RESPONSE_BYTES");
|
|
},
|
|
);
|
|
});
|