fix(scripts): preserve emoji in issue label prompts (#109477)

This commit is contained in:
Leon-SK668
2026-07-16 22:27:04 -07:00
committed by GitHub
parent 6bd15d00c4
commit 7e34687015
2 changed files with 39 additions and 1 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import { pathToFileURL } from "node:url";
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
import { isRecord } from "../src/utils.js";
import { readBoundedResponseText as readBoundedBodyText } from "./lib/bounded-response.ts";
import { parseStrictIntegerOption } from "./lib/dev-tooling-safety.ts";
@@ -644,7 +645,7 @@ function truncateBody(body: string): string {
if (body.length <= MAX_BODY_CHARS) {
return body;
}
return `${body.slice(0, MAX_BODY_CHARS)}\n\n[truncated]`;
return `${truncateUtf16Safe(body, MAX_BODY_CHARS)}\n\n[truncated]`;
}
function buildItemPrompt(item: LabelItem, kind: "issue" | "pull request"): string {
+37
View File
@@ -226,4 +226,41 @@ describe("label-open-issues helpers", () => {
/OPENCLAW_LABEL_OPEN_ISSUES_OPENAI_TIMEOUT_MS must be an integer/u,
);
});
it("does not split boundary emoji in model prompts", async () => {
let requestBody = "";
const response = new Response(
JSON.stringify({
output_text: JSON.stringify({
category: "bug",
isSupport: false,
isSkillOnly: false,
}),
}),
{ status: 200 },
);
await testing.classifyItem(
{
...labelItem,
body: `${"a".repeat(5999)}😀tail`,
},
"issue",
{
apiKey: "placeholder",
model: "test-model",
timeoutMs: 50,
fetchImpl: ((_url, init) => {
requestBody = String(init?.body ?? "");
return Promise.resolve(response);
}) as typeof fetch,
},
);
const payload = JSON.parse(requestBody) as { input: Array<{ content: string }> };
const prompt = payload.input[1]?.content ?? "";
expect(prompt).toContain(`${"a".repeat(5999)}\n\n[truncated]`);
expect(prompt).not.toContain("\uD83D");
expect(prompt).not.toContain("tail");
});
});