fix(scripts): cap memory FD repro RPC bodies

This commit is contained in:
Vincent Koc
2026-05-29 17:29:30 +02:00
parent b67679fb73
commit edc573daba
2 changed files with 97 additions and 1 deletions

View File

@@ -2,8 +2,10 @@ import { EventEmitter } from "node:events";
import { describe, expect, it, vi } from "vitest";
import {
GATEWAY_READY_OUTPUT_MAX_CHARS,
MEMORY_SEARCH_RESPONSE_MAX_BYTES,
hasChildExited,
parseArgs,
readBoundedResponseText,
readNumber,
readPositiveNumber,
stopGatewayWithRuntime,
@@ -178,4 +180,44 @@ describe("check-memory-fd-repro", () => {
expect(state.readySeen).toBe(true);
expect(state.tail).toBe("w output");
});
it("reads memory_search response bodies under the byte cap", async () => {
await expect(
readBoundedResponseText(
new Response("ok"),
"memory_search",
MEMORY_SEARCH_RESPONSE_MAX_BYTES,
),
).resolves.toBe("ok");
});
it("rejects oversized memory_search response bodies from content-length", async () => {
const response = new Response("ignored", {
headers: { "content-length": String(MEMORY_SEARCH_RESPONSE_MAX_BYTES + 1) },
});
await expect(
readBoundedResponseText(response, "memory_search", MEMORY_SEARCH_RESPONSE_MAX_BYTES),
).rejects.toThrow(
`memory_search response body exceeded ${MEMORY_SEARCH_RESPONSE_MAX_BYTES} bytes`,
);
});
it("stops reading memory_search response streams after the byte cap", async () => {
const chunk = new Uint8Array(MEMORY_SEARCH_RESPONSE_MAX_BYTES + 1);
const response = new Response(
new ReadableStream({
start(controller) {
controller.enqueue(chunk);
controller.close();
},
}),
);
await expect(
readBoundedResponseText(response, "memory_search", MEMORY_SEARCH_RESPONSE_MAX_BYTES),
).rejects.toThrow(
`memory_search response body exceeded ${MEMORY_SEARCH_RESPONSE_MAX_BYTES} bytes`,
);
});
});