fix(scripts): preserve emoji in GitHub API errors (#108184)

* fix(scripts): keep GitHub errors valid Unicode

* style(scripts): format GitHub error boundary test

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
Leon-SK668
2026-07-16 17:33:35 -07:00
committed by GitHub
co-authored by Peter Steinberger
parent 7ba436ac70
commit bdf3886024
2 changed files with 22 additions and 1 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ import { createPrivateKey, createSign } from "node:crypto";
import { pathToFileURL } from "node:url";
import { readSecretFileSync } from "@openclaw/fs-safe/secret";
import { expectDefined } from "../packages/normalization-core/src/expect.js";
import { truncateUtf16Safe } from "../packages/normalization-core/src/utf16-slice.js";
import { readBoundedResponseText } from "./lib/bounded-response.ts";
import { parseStrictIntegerOption } from "./lib/dev-tooling-safety.ts";
import {
@@ -238,7 +239,7 @@ export async function readBoundedGitHubErrorText(
text += decoder.decode(value, { stream: true });
if (text.length > maxChars) {
text = text.slice(0, maxChars);
text = truncateUtf16Safe(text, maxChars);
truncated = true;
break;
}
+20
View File
@@ -173,6 +173,26 @@ describe("gh-read helpers", () => {
expect(text.length).toBeLessThan(4200);
});
it.each([
{
caseName: "drops a split surrogate pair",
responseBody: `abc\u{1f600}tail`,
expectedText: "abc\n[truncated]",
},
{
caseName: "preserves a complete surrogate pair",
responseBody: `ab\u{1f600}tail`,
expectedText: `ab\u{1f600}\n[truncated]`,
},
])(
"keeps GitHub API error truncation UTF-16 safe: $caseName",
async ({ responseBody, expectedText }) => {
const response = new Response(responseBody, { status: 500 });
await expect(readBoundedGitHubErrorText(response, 4)).resolves.toBe(expectedText);
},
);
it("reads bounded GitHub API JSON responses", async () => {
await expect(readBoundedGitHubJson(new Response('{"id":123}'), 1024)).resolves.toEqual({
id: 123,