From 478b5ef251b63aaebb5bac28146342ec3f79739c Mon Sep 17 00:00:00 2001 From: yousizaitianqiong <98396370+yousizaitianqiong@users.noreply.github.com> Date: Fri, 20 Nov 2026 10:43:57 +0800 Subject: [PATCH] fix(scoring): preserve Unicode in README summaries --- scoring/src/extract.ts | 8 +++++++- scoring/test/score.test.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/scoring/src/extract.ts b/scoring/src/extract.ts index 6d2c5541..4cddb8d6 100644 --- a/scoring/src/extract.ts +++ b/scoring/src/extract.ts @@ -301,7 +301,13 @@ function textMatches(text: string, words: string[]): boolean { function clampText(text: string, limit: number): string { const clean = text.replace(/\s+/g, " ").trim(); - return clean.length > limit ? `${clean.slice(0, limit - 1)}…` : clean; + if (clean.length <= limit) return clean; + + let end = limit - 1; + const boundaryCodePoint = clean.codePointAt(end - 1); + // If the final retained code unit starts a surrogate pair, omit the whole pair. + if (boundaryCodePoint !== undefined && boundaryCodePoint > 0xffff) end--; + return `${clean.slice(0, end)}…`; } export function parseReadmeFeatures(markdown: string): ReadmeFeatures { diff --git a/scoring/test/score.test.ts b/scoring/test/score.test.ts index 8a73615b..a5eb5a1f 100644 --- a/scoring/test/score.test.ts +++ b/scoring/test/score.test.ts @@ -639,6 +639,36 @@ Install the package. expect(features.prompt_summary).toContain("A clear overview"); }); + const introPrefix = "ζ–‡".repeat(348); + const sectionPrefix = "a".repeat(218); + const titlePrefix = "a".repeat(1491); + const prefixWithEmoji = `${"ζ–‡".repeat(347)}πŸš€`; + + it.each([ + ["an intro", `# Project\n\n${introPrefix}πŸš€end`, `Intro: ${introPrefix}… Sections:`], + [ + "a section", + `# Project\n\nOverview.\n\n## Usage\n\n${sectionPrefix}πŸš€end`, + `Usage: ${sectionPrefix}… Signals: usage`, + ], + ["the full summary", `# ${titlePrefix}πŸš€end`, `Title: ${titlePrefix}…`], + [ + "an intro where the emoji fits before the ellipsis", + `# Project\n\n${prefixWithEmoji}end`, + `Intro: ${prefixWithEmoji}… Sections:`, + ], + [ + "an intro at the length limit", + `# Project\n\n${introPrefix}πŸš€`, + `Intro: ${introPrefix}πŸš€ Sections:`, + ], + ])("preserves Unicode in %s", (_part, markdown, expected) => { + const { prompt_summary } = parseReadmeFeatures(markdown); + expect(prompt_summary).not.toMatch(/[\uD800-\uDFFF]/u); + expect(prompt_summary).toContain(expected); + expect(prompt_summary.length).toBeLessThanOrEqual(1500); + }); + it("treats Quick Start as a usage signal", () => { const features = parseReadmeFeatures(` # Project