Skip to content

Commit 1f5c823

Browse files
Leon-SK668steipete
andauthored
fix(scripts): preserve emoji in request log previews (#109481)
* fix(scripts): preserve emoji in request log previews * fix(scripts): keep mock preview standalone * refactor(scripts): reuse UTF-16 truncation helper Co-authored-by: Leon-SK668 <[email protected]> * test(scripts): cover raw Node mock loading Co-authored-by: Leon-SK668 <[email protected]> * docs(scripts): note raw Node type stripping contract Co-authored-by: Leon-SK668 <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 067635c commit 1f5c823

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

scripts/e2e/lib/mock-openai-http.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Mock OpenAI-compatible HTTP server helpers for E2E scenarios.
22
import fs from "node:fs";
3+
// Raw launchers meet the repo's Node 22.22.3 minimum, where native TS stripping is enabled.
4+
import { truncateUtf16Safe } from "../../../packages/normalization-core/src/utf16-slice.ts";
35
import { readPositiveIntEnv } from "./env-limits.mjs";
46

57
const DEFAULT_REQUEST_MAX_BYTES = 4 * 1024 * 1024;
@@ -76,7 +78,7 @@ export function boundedRequestLogBody(value, bodyText, limits = readMockOpenAiHt
7678
return {
7779
truncated: true,
7880
byteLength,
79-
preview: bodyText.slice(0, REQUEST_LOG_PREVIEW_CHARS),
81+
preview: truncateUtf16Safe(bodyText, REQUEST_LOG_PREVIEW_CHARS),
8082
};
8183
}
8284

test/scripts/mock-openai-http.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Mock Openai Http tests cover mock openai http script behavior.
2+
import { spawnSync } from "node:child_process";
23
import { PassThrough } from "node:stream";
34
import { describe, expect, it } from "vitest";
45
import {
@@ -15,6 +16,17 @@ function bodyStream(text: string) {
1516
}
1617

1718
describe("mock OpenAI HTTP helpers", () => {
19+
it("loads under raw Node without a TypeScript loader", () => {
20+
const result = spawnSync(
21+
process.execPath,
22+
["--input-type=module", "--eval", "await import('./scripts/e2e/lib/mock-openai-http.mjs')"],
23+
{ cwd: process.cwd(), encoding: "utf8" },
24+
);
25+
26+
expect(result.status, result.stderr).toBe(0);
27+
expect(result.signal).toBeNull();
28+
});
29+
1830
it("reads request bodies within the configured ceiling", async () => {
1931
await expect(readBody(bodyStream("small"), { requestMaxBytes: 8 })).resolves.toBe("small");
2032
});
@@ -43,6 +55,20 @@ describe("mock OpenAI HTTP helpers", () => {
4355
});
4456
});
4557

58+
it("does not split emoji in request-log previews", () => {
59+
const bodyText = `${"a".repeat(4095)}😀tail`;
60+
61+
expect(
62+
boundedRequestLogBody({ full: bodyText }, bodyText, {
63+
requestLogBodyMaxBytes: 8,
64+
}),
65+
).toEqual({
66+
truncated: true,
67+
byteLength: Buffer.byteLength(bodyText, "utf8"),
68+
preview: "a".repeat(4095),
69+
});
70+
});
71+
4672
it("keeps small request-log bodies intact", () => {
4773
const body = { ok: true };
4874
expect(boundedRequestLogBody(body, JSON.stringify(body), { requestLogBodyMaxBytes: 64 })).toBe(

0 commit comments

Comments
 (0)