diff --git a/apps/mobile/src/lib/projectThreadStartTurn.test.ts b/apps/mobile/src/lib/projectThreadStartTurn.test.ts index a4b21fec19448..d01a79e32ac47 100644 --- a/apps/mobile/src/lib/projectThreadStartTurn.test.ts +++ b/apps/mobile/src/lib/projectThreadStartTurn.test.ts @@ -5,6 +5,7 @@ import { serializeComposerMessageForServer } from "./composerContext"; import { buildProjectThreadStartTurnInput, + deriveThreadTitleFromPrompt, type ProjectThreadStartTurnSpec, } from "./projectThreadStartTurn"; @@ -98,4 +99,10 @@ describe("project thread title", () => { repositories: [{ path: "/workspace/api" }], }); }); + + it("shortens a long prompt without splitting an emoji", () => { + expect(deriveThreadTitleFromPrompt(`${"a".repeat(68)}😀 and the rest of the prompt`)).toBe( + `${"a".repeat(68)}...`, + ); + }); }); diff --git a/apps/mobile/src/lib/projectThreadStartTurn.ts b/apps/mobile/src/lib/projectThreadStartTurn.ts index c7e89d8c6e600..e4b550f6b5cd4 100644 --- a/apps/mobile/src/lib/projectThreadStartTurn.ts +++ b/apps/mobile/src/lib/projectThreadStartTurn.ts @@ -13,6 +13,7 @@ import { deriveThreadTitleSeed, threadTitleTextFromPrompt, } from "@t3tools/client-runtime/operations"; +import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations"; import { msg } from "gt-react-native"; import { m } from "../i18n/messages"; @@ -95,5 +96,7 @@ export function buildProjectThreadStartTurnInput(spec: ProjectThreadStartTurnSpe export function deriveThreadTitleFromPrompt(value: string): string { const title = threadTitleTextFromPrompt(value, m) || m(msg("New thread")); - return title.length <= 72 ? title : `${title.slice(0, 69).trimEnd()}...`; + if (title.length <= 72) return title; + const end = splitsSurrogatePair(title, 69) ? 68 : 69; + return `${title.slice(0, end).trimEnd()}...`; } diff --git a/scripts/scenarios/new-task-draft-title-keeps-whole-characters.e2e.ts b/scripts/scenarios/new-task-draft-title-keeps-whole-characters.e2e.ts new file mode 100644 index 0000000000000..1dc7bba2758e8 --- /dev/null +++ b/scripts/scenarios/new-task-draft-title-keeps-whole-characters.e2e.ts @@ -0,0 +1,38 @@ +import { expect } from "e2e"; + +import { IOS, test } from "./t3-mobile.ts"; + +const KEPT = "a".repeat(68); +// The emoji's two UTF-16 units straddle unit 69, where a draft's title is cut. +const PROMPT = `${KEPT}😀 and the rest of the prompt`; + +test( + "An unsent new-task draft's row title ends without a broken character", + IOS, + async ({ t3, app, screen, device }) => { + await t3.project("demo"); + // A local simulator keeps the last run's drafts. + await app.clearState().catch(() => {}); + await t3.open(); + + await screen.getByRole("button", "New chat").tap({ timeout: 120_000 }); + const composer = screen.getByRole("textbox", "Ask anything"); + const projectSearch = screen.getByRole("textbox", "Search projects"); + // The project list slides over the draft, which names its project too. + await projectSearch.waitFor(); + await composer.waitFor({ state: "hidden" }); + await screen.getByRole("button", "demo").tap(); + await projectSearch.waitFor({ state: "hidden" }); + await composer.fill(PROMPT); + await screen.getByTestId("BackButton").tap(); + + const row = screen.getByLabel(KEPT, { exact: false }); + await row.waitFor({ timeout: 30_000 }); + // The row clips its title before the cut; the discard prompt shows it whole. + await row.longPress(); + await screen.getByRole("button", "Discard").tap(); + await app.screenshot("discard-prompt"); + await device.alert("dismiss"); + await expect(row).toHaveAccessibleName(`${KEPT}...`); + }, +);