mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 23:15:58 +00:00
perf(mcp): index tool contracts, skip unadvertised projection, parallelize status probes, and stream tool result sizing (#13263)
* perf(mcp): index tool contracts, skip unadvertised projection, parallelize status probes, and stream tool result sizing * fix(mcp): await readiness before session status and defer omission worklist
This commit is contained in:
1 parent
264c398c0d
commit
7a2e8da495
8 files changed
+402
-70
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { fc, it as fcIt } from "@fast-check/vitest";
|
||||
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import {
|
||||
@@ -125,3 +126,86 @@ describe("error text wire size", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("zero-allocation escaped JSON measurement parity", () => {
|
||||
fcIt.prop([fc.string({ unit: "binary-ascii" })])(
|
||||
"matches JSON.stringify and Buffer.byteLength across ASCII control and punctuation ranges",
|
||||
(sample) => {
|
||||
const candidate = { value: sample };
|
||||
const wire = JSON.stringify(projectedResult(candidate));
|
||||
const expected = Buffer.byteLength(wire);
|
||||
const encoded = encodeToolResult(candidate, expected);
|
||||
expect(encoded).toEqual({
|
||||
ok: true,
|
||||
text: JSON.stringify(candidate),
|
||||
bytes: expected,
|
||||
});
|
||||
expect(encodeToolResult(candidate, expected - 1)).toMatchObject({
|
||||
ok: false,
|
||||
bytesAtLeast: expected,
|
||||
constraint: "receive-buffer",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
fcIt.prop([
|
||||
fc.array(
|
||||
fc.oneof(
|
||||
fc.integer({ min: 0x00, max: 0x7f }),
|
||||
fc.integer({ min: 0x80, max: 0x7ff }),
|
||||
fc.integer({ min: 0x800, max: 0xffff }),
|
||||
fc.integer({ min: 0xd800, max: 0xdfff }),
|
||||
),
|
||||
{ maxLength: 64 },
|
||||
),
|
||||
])(
|
||||
"matches JSON.stringify across arbitrary UTF-16 code units including unpaired surrogates",
|
||||
(units) => {
|
||||
const sample = String.fromCharCode(...units);
|
||||
const candidate = { [sample]: sample };
|
||||
const wire = JSON.stringify(projectedResult(candidate));
|
||||
const expected = Buffer.byteLength(wire);
|
||||
const encoded = encodeToolResult(candidate, expected);
|
||||
expect(encoded).toEqual({
|
||||
ok: true,
|
||||
text: JSON.stringify(candidate),
|
||||
bytes: expected,
|
||||
});
|
||||
expect(encodeToolResult(candidate, expected - 1)).toMatchObject({
|
||||
ok: false,
|
||||
bytesAtLeast: expected,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("matches every single C0 control character, non-BMP pair, and reversed surrogate edge case", () => {
|
||||
const allControlChars = Array.from({ length: 32 }, (_, c) =>
|
||||
String.fromCharCode(c),
|
||||
).join("");
|
||||
const edgeStrings = [
|
||||
allControlChars,
|
||||
'"\\/\b\f\n\r\t\x7f',
|
||||
"\ud800",
|
||||
"\udfff",
|
||||
"\udfff\ud800",
|
||||
"\ud800a\udfff",
|
||||
"\ud83d\ude80\ud800\ud83d\ude80",
|
||||
"é߀𐍈😀\ud800end",
|
||||
];
|
||||
for (const sample of edgeStrings) {
|
||||
const candidate = { sample };
|
||||
const expected = Buffer.byteLength(
|
||||
JSON.stringify(projectedResult(candidate)),
|
||||
);
|
||||
expect(encodeToolResult(candidate, expected)).toEqual({
|
||||
ok: true,
|
||||
text: JSON.stringify(candidate),
|
||||
bytes: expected,
|
||||
});
|
||||
expect(encodeToolResult(candidate, expected - 1)).toMatchObject({
|
||||
ok: false,
|
||||
bytesAtLeast: expected,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user