Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/mobile/src/lib/projectThreadStartTurn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { serializeComposerMessageForServer } from "./composerContext";

import {
buildProjectThreadStartTurnInput,
deriveThreadTitleFromPrompt,
type ProjectThreadStartTurnSpec,
} from "./projectThreadStartTurn";

Expand Down Expand Up @@ -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)}...`,
);
});
});
5 changes: 4 additions & 1 deletion apps/mobile/src/lib/projectThreadStartTurn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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()}...`;
}
Original file line number Diff line number Diff line change
@@ -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}...`);
},
);
Loading