mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 20:14:06 +00:00
fix(scripts): cap memory FD repro RPC bodies
This commit is contained in:
@@ -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`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user