TypeScript
fix(provider-core): background work notices no longer end in a broken character (#30369)
spoukyii94690956fd8f
diff --git a/packages/provider-core/src/server/notification.test.ts b/packages/provider-core/src/server/notification.test.tsindex cab8ed06a64..272cd007632 100644--- a/packages/provider-core/src/server/notification.test.ts+++ b/packages/provider-core/src/server/notification.test.ts@@ -42,6 +42,12 @@ describe("backgroundWorkNotification", () => {.summary,'Monitor "Three ticks" reported new output',);+ assert.equal(+ backgroundWorkNotification([+ { kind: "command", label: `${"a".repeat(78)}😀 and more`, outcome: "completed" },+ ]).summary,+ `Command "${"a".repeat(78)}…" finished`,+ );});it("names every piece of work that ended together, without opening one of them", () => {diff --git a/packages/provider-core/src/server/notification.ts b/packages/provider-core/src/server/notification.tsindex 85cac547cfa..55b1125fd94 100644--- a/packages/provider-core/src/server/notification.ts+++ b/packages/provider-core/src/server/notification.ts@@ -25,9 +25,14 @@ const LABEL_MAX_LENGTH = 80;export function reportLabel(label: string | undefined): string | undefined {const firstLine = label?.trim().split("\n")[0]?.trim();if (firstLine === undefined || firstLine.length === 0) return undefined;- return firstLine.length > LABEL_MAX_LENGTH- ? `${firstLine.slice(0, LABEL_MAX_LENGTH - 1)}…`- : firstLine;+ if (firstLine.length <= LABEL_MAX_LENGTH) return firstLine;+ let end = LABEL_MAX_LENGTH - 1;+ const previous = firstLine.charCodeAt(end - 1);+ const next = firstLine.charCodeAt(end);+ if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {+ end -= 1;+ }+ return `${firstLine.slice(0, end)}…`;}const KIND_NOUN: Record<BackgroundWork["kind"], readonly [string, string]> = {