mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 04:15:48 -06:00
fix(bench): preserve Unicode across bounded gateway diagnostics (#120125)
This commit is contained in:
@@ -9,6 +9,7 @@ import { performance } from "node:perf_hooks";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { PROTOCOL_VERSION } from "../packages/gateway-protocol/src/version.ts";
|
||||
import { asFiniteNumber } from "../packages/normalization-core/src/number-coercion.ts";
|
||||
import { sliceUtf16Safe } from "../packages/normalization-core/src/utf16-slice.ts";
|
||||
import { applyMockOpenAiModelConfig } from "./e2e/lib/fixtures/mock-openai-config.mjs";
|
||||
import { delay, stopChild } from "./lib/gateway-bench-child.ts";
|
||||
import { getFreePort } from "./lib/gateway-bench-probes.ts";
|
||||
@@ -402,8 +403,7 @@ async function requestHttp(params: {
|
||||
}
|
||||
|
||||
function describeProbeError(error: unknown): string {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
return message.slice(0, 500);
|
||||
return sliceUtf16Safe(error instanceof Error ? error.message : String(error), 0, 500);
|
||||
}
|
||||
|
||||
function formatProbeResult(name: string, probe: TimedProbe & { status?: number }): string {
|
||||
@@ -431,12 +431,12 @@ function captureChildOutput(child: ChildProcessWithoutNullStreams): {
|
||||
let output = "";
|
||||
let stderr = "";
|
||||
const appendOutput = (chunk: Buffer) => {
|
||||
output = `${output}${chunk.toString("utf8")}`.slice(-64 * 1_024);
|
||||
output = sliceUtf16Safe(`${output}${chunk.toString("utf8")}`, -64 * 1_024);
|
||||
};
|
||||
child.stdout.on("data", appendOutput);
|
||||
child.stderr.on("data", (chunk: Buffer) => {
|
||||
appendOutput(chunk);
|
||||
stderr = `${stderr}${chunk.toString("utf8")}`.slice(-64 * 1_024);
|
||||
stderr = sliceUtf16Safe(`${stderr}${chunk.toString("utf8")}`, -64 * 1_024);
|
||||
});
|
||||
return {
|
||||
readOutput: () => output,
|
||||
|
||||
@@ -200,6 +200,16 @@ describe("gateway concurrency benchmark script", () => {
|
||||
error: "sessions.list failed: unauthorized",
|
||||
ok: false,
|
||||
});
|
||||
const unicodeSample = await testing.sampleGateway({
|
||||
deadlineAt: performance.now() + 5_000,
|
||||
port: address.port,
|
||||
rpc: async () => {
|
||||
throw new Error(`${"x".repeat(499)}😀`);
|
||||
},
|
||||
runStartedAt: performance.now(),
|
||||
serial: true,
|
||||
});
|
||||
expect(unicodeSample.sessionsList.error).toBe("x".repeat(499));
|
||||
const failure = testing.formatRunFailure(
|
||||
new Error(testing.formatProbeFailure(sample)),
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user