The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 04:15 UTC
fix(server): keep characters intact in generated commit subjects (#19181)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>
Simone committed
Oct 18, 2026 at 21:17 UTC
86ce795392f78d6840b449b047f52c694d57da54
2 files changed
+42
-1
packages/provider-core/src/server/textGenerationUtils.test.ts
new
+33
@@ -0,0 +1,33 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import { sanitizeCommitSubject } from "./textGenerationUtils.ts";
4
+
5
+describe("sanitizeCommitSubject", () => {
6
+ it.each([
7
+ { name: "an emoji", prefixLength: 71, character: "🚀" },
8
+ { name: "an accented character", prefixLength: 71, character: "e\u0301" },
9
+ { name: "an emoji with a skin tone", prefixLength: 70, character: "👍🏽" },
10
+ { name: "a flag", prefixLength: 69, character: "🇮🇹" },
11
+ { name: "a joined emoji", prefixLength: 65, character: "👨👩👧👦" },
12
+ ])("keeps $name intact at the subject limit", ({ prefixLength, character }) => {
13
+ const prefix = "a".repeat(prefixLength);
14
+
15
+ expect(sanitizeCommitSubject(`${prefix}${character} more`)).toBe(prefix);
16
+ });
17
+
18
+ it("keeps a complete character that ends exactly at the limit", () => {
19
+ const expected = `${"a".repeat(70)}🚀`;
20
+
21
+ expect(sanitizeCommitSubject(`${expected} more`)).toBe(expected);
22
+ });
23
+
24
+ it("uses the existing fallback when a single character exceeds the limit", () => {
25
+ expect(sanitizeCommitSubject(`a${"\u0301".repeat(72)} more`)).toBe("Update project files");
26
+ });
27
+
28
+ it("keeps the existing ASCII limit and subject normalization", () => {
29
+ expect(sanitizeCommitSubject("a".repeat(80))).toBe("a".repeat(72));
30
+ expect(sanitizeCommitSubject(" Fix tests...\nignored ")).toBe("Fix tests");
31
+ expect(sanitizeCommitSubject("...")).toBe("Update project files");
32
+ });
33
+});
packages/provider-core/src/server/textGenerationUtils.ts
+9
-1
@@ -33,7 +33,15 @@ export function sanitizeCommitSubject(raw: string): string {
33
if (withoutTrailingPeriod.length <= 72) {
34
return withoutTrailingPeriod;
35
}
36
- return withoutTrailingPeriod.slice(0, 72).trimEnd();
36
+ const segments = new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(
37
+ withoutTrailingPeriod,
38
+ );
39
+ let subject = "";
40
+ for (const { segment } of segments) {
41
+ if (subject.length + segment.length > 72) break;
42
+ subject += segment;
43
+ }
44
+ return subject.trimEnd() || "Update project files";
45
}
46
47
export function sanitizePrTitle(raw: string): string {