fix(webui): unify app logos and brand mentions

This commit is contained in:
Xubin Ren committed 2026-09-13 13:53:20 +08:00
1 parent bfb4f021ed
commit b6122b9018
10 files changed
+752 -89

No files matched your search

@@ -0,0 +1,79 @@
import { describe, expect, it } from "vitest";
import { splitCapabilityMentionSegments } from "@/components/CliAppMentionText";
import { composerCompositionSegments, composerMentionLabel, composerMentionText, editComposerMentionText, mentionTextOffset } from "@/lib/composer-mention-text";
import type { CliAppInfo } from "@/lib/types";
const apps = [
["linear", "Linear"], ["drawio", "Draw.io"], ["drive", "Google Drive"],
["iterm2", "iTerm2"], ["gimp", "GIMP"], ["custom", "本地应用"],
["blank", " "], ["first", "Same Name"], ["second", "Same Name"],
].map(([name, display_name]) => ({ name, display_name, installed: true }) as CliAppInfo);
const project = (raw: string) => composerMentionText(splitCapabilityMentionSegments(raw, apps));
describe("composer mention display text", () => {
it.each([
["n @Linear @Google Drive", 0, 0, ["linear", "drive"]],
["@Linear n @Google Drive", 8, 8, ["linear", "drive"]],
["@Linear @Google Drive n", 21, 21, ["linear", "drive"]],
["@Lin中ear @Google Drive", 4, 4, ["drive"]],
["中 @Google Drive", 0, 7, ["drive"]],
])("keeps untouched mention identities during IME input: %s", (display, start, end, names) => {
const original = splitCapabilityMentionSegments("@linear @drive", apps);
const segments = composerCompositionSegments(original, display, { start, end });
expect(segments.map(composerMentionLabel).join("")).toBe(display);
expect(segments.flatMap(segment => segment.kind === "cli" ? [segment.app.name] : [])).toEqual(names);
});
it("keeps duplicate display names tied to their own identities during composition", () => {
const original = splitCapabilityMentionSegments("@first @second", apps);
const segments = composerCompositionSegments(original, "中 @Same Name", { start: 0, end: 10 });
expect(segments.map(composerMentionLabel).join("")).toBe("中 @Same Name");
expect(segments.flatMap(segment => segment.kind === "cli" ? [segment.app.name] : [])).toEqual(["second"]);
expect(composerCompositionSegments(original, "@Same Name @Same Name")).toBe(original);
});
it("adds a non-breaking logo gap only to display text and maps editing around it", () => {
const app = { ...apps[0], logo_url: "https://example.invalid/linear.svg" };
const text = composerMentionText(splitCapabilityMentionSegments("@linear next", [app]));
expect(text.display).toBe("@\u00a0Linear next");
expect(text.raw).toBe("@linear next");
expect(mentionTextOffset(text, 8, "toRaw")).toBe(7);
expect(mentionTextOffset(text, 7, "toDisplay")).toBe(8);
expect(editComposerMentionText(text, "@\u00a0Linear! next", 9, { start: 8, end: 8 }))
.toEqual({ value: "@linear! next", cursor: 8 });
});
it("preserves brand spelling without changing the raw identifiers", () => {
const raw = "@linear @drawio @drive @iterm2 @gimp @custom @blank @unknown";
const text = project(raw);
expect(text.raw).toBe(raw);
expect(text.display).toBe("@Linear @Draw.io @Google Drive @iTerm2 @GIMP @本地应用 @blank @unknown");
});
it("maps both ends of every mention and all surrounding text positions", () => {
const text = project("请用 @drive 和 @drawio 处理\n文件");
for (let raw = 0; raw <= text.raw.length; raw++) {
if (text.mentions.some((mention) => raw > mention.start && raw < mention.end)) continue;
expect(mentionTextOffset(text, mentionTextOffset(text, raw, "toDisplay"), "toRaw")).toBe(raw);
}
});
it.each([
["@drive", "@Google Drive hello", 19, "@drive hello"],
["@drive done", "@Google Drive !done", 15, "@drive !done"],
["@drive @drawio", "@Google Drive @Draw.io", 14, "@drive @drawio"],
["@drive done", "@Google Driv done", 12, " done"],
["@drive done", "@oogle Drive done", 1, " done"],
["@drive done", "@Google XDrive done", 9, "X done"],
["@drive @drawio", "@Google Drive\n@Draw.io", 14, "@drive\n@drawio"],
["@first @second", "@Same Name @Same Name!", 21, "@first @second!"],
])("applies %s → %s without rewriting untouched mentions", (raw, display, caret, expected) => {
expect(editComposerMentionText(project(raw), display, caret as number).value).toBe(expected);
});
it("replaces a selected mention without losing a shared @ prefix", () => {
expect(editComposerMentionText(project("@drive"), "@linear", 7, { start: 0, end: 13 }))
.toEqual({ value: "@linear", cursor: 7 });
});
});
+64 -10
View File
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from "vitest";
import { MessageBubble } from "@/components/MessageBubble";
import { setAppLanguage } from "@/i18n";
import * as clipboard from "@/lib/clipboard";
import { fmtDateTime, formatMessageEndTime } from "@/lib/format";
import type {
CliAppInfo,
@@ -394,7 +395,7 @@ describe("MessageBubble", () => {
);
expect(screen.getByTestId("message-slash-command")).toHaveTextContent("/goal");
expect(screen.getByTestId("message-cli-mention-zoom")).toHaveTextContent("@zoom");
expect(screen.getByTestId("message-cli-mention-zoom")).toHaveTextContent("@Zoom");
});
it("highlights skill references without a live skill catalog", () => {
@@ -422,8 +423,8 @@ describe("MessageBubble", () => {
expect(skill.getAttribute("style")).not.toContain("text-shadow");
expect(skill.getAttribute("style")).toContain("var(--inline-token-highlight)");
expect(skill.className).not.toMatch(/(?:^|\s)(?:bg-|border|ring|rounded)/);
expect(screen.getByTestId("message-cli-mention-zoom")).toHaveTextContent("@zoom");
expect(skill.parentElement).toHaveTextContent("Ask github to review this with @zoom");
expect(screen.getByTestId("message-cli-mention-zoom")).toHaveTextContent("@Zoom");
expect(skill.parentElement).toHaveTextContent("Ask github to review this with @Zoom");
});
it("highlights well-formed skill references and leaves a bare marker plain", () => {
@@ -566,14 +567,16 @@ describe("MessageBubble", () => {
render(<MessageBubble message={message} cliApps={CLI_APPS} />);
const token = screen.getByTestId("message-cli-mention-zoom");
expect(token).toHaveTextContent("@zoom");
expect(token).toHaveAttribute("title", "CLI app: Zoom");
expect(token).toHaveTextContent("@Zoom");
expect(token).toHaveAttribute("title", "CLI app: Zoom (@zoom)");
expect(token).toHaveClass("font-[550]");
expect(token.className).not.toContain("rounded");
expect(token.className).not.toContain("px-");
expect(token.getAttribute("style")).toContain("color: #0B5CFF");
expect(token.getAttribute("style")).not.toContain("text-shadow");
expect(screen.getByTestId("message-cli-mention-logo-zoom")).toBeInTheDocument();
const logo = screen.getByTestId("message-cli-mention-logo-zoom");
expect(logo).toHaveClass("h-[1.1em]", "w-[1.1em]", "rounded-[0.25em]", "top-1/2", "-translate-y-1/2");
expect(logo.parentElement).toHaveClass("mr-1", "w-[1.1em]");
expect(screen.queryByTestId("message-cli-mention-krita")).not.toBeInTheDocument();
expect(screen.getByText(/not @krita/)).toBeInTheDocument();
});
@@ -632,7 +635,7 @@ describe("MessageBubble", () => {
render(<MessageBubble message={message} cliApps={[]} />);
const token = screen.getByTestId("message-cli-mention-drawio");
expect(token).toHaveTextContent("@drawio");
expect(token).toHaveTextContent("@Draw.io");
expect(token.className).not.toContain("rounded");
expect(token.className).not.toContain("px-");
expect(token.getAttribute("style")).toContain("color: #F08705");
@@ -650,10 +653,61 @@ describe("MessageBubble", () => {
render(<MessageBubble message={message} mcpPresets={MCP_PRESETS} />);
const token = screen.getByTestId("message-mcp-mention-browserbase");
expect(token).toHaveTextContent("@browserbase");
expect(token).toHaveAttribute("title", "MCP server: Browserbase");
expect(token).toHaveTextContent("@Browserbase");
expect(token).toHaveAttribute("title", "MCP server: Browserbase (@browserbase)");
expect(token.getAttribute("style")).toContain("color: #111827");
expect(screen.getByTestId("message-mcp-mention-logo-browserbase")).toBeInTheDocument();
const logo = screen.getByTestId("message-mcp-mention-logo-browserbase");
expect(logo).toHaveClass("h-[1.1em]", "w-[1.1em]", "rounded-[0.25em]", "top-1/2", "-translate-y-1/2");
expect(logo.parentElement).toHaveClass("mr-1", "w-[1.1em]");
});
it.each((["cli", "mcp"] as const).flatMap((kind) => [
["linear", "Linear", "Linear"],
["iterm2", "iTerm2", "iTerm2"],
["drawio", "Draw.io", "Draw.io"],
["gimp", "GIMP", "GIMP"],
["google-drive", "Google Drive", "Google Drive"],
["1password-cli", "1Password CLI", "1Password CLI"],
["feishu-cli", "Feishu/Lark CLI", "Feishu/Lark CLI"],
["local-app", " 本地应用 ", "本地应用"],
["fallback-app", " ", "fallback-app"],
].map(([name, displayName, expected]) => ({ kind, name, displayName, expected }))))(
"uses the saved display name for $kind $name without rewriting its identifier",
({ kind, name, displayName, expected }) => {
const message: UIMessage = {
id: "saved-app-name",
role: "user",
content: `Use @${name} please`,
...(kind === "cli" ? {
cliApps: [{ name, display_name: displayName, category: "test", entry_point: name }],
} : {
mcpPresets: [{ name, display_name: displayName, category: "test", transport: "stdio" }],
}),
};
render(<MessageBubble message={message} />);
const token = screen.getByTestId(`message-${kind}-mention-${name}`);
expect(token.textContent).toBe(`@${expected}`);
expect(token).toHaveAttribute("title", `${kind === "cli" ? "CLI app" : "MCP server"}: ${expected} (@${name})`);
expect(token).toHaveClass("inline-flex", "items-baseline", "max-w-full", "[overflow-wrap:anywhere]");
expect(token.firstElementChild).toHaveClass("shrink-0");
expect(token.lastElementChild).toHaveClass("min-w-0");
expect(message.content).toBe(`Use @${name} please`);
},
);
it("copies the original mention identifiers rather than display names", async () => {
const copy = vi.spyOn(clipboard, "copyTextToClipboard").mockResolvedValue(true);
try {
render(<MessageBubble message={{
id: "copy-display-name", role: "user", content: "Please use @drawio",
cliApps: [{ name: "drawio", display_name: "Draw.io", category: "diagram", entry_point: "drawio" }],
}} />);
expect(screen.getByTestId("message-cli-mention-drawio")).toHaveTextContent("@Draw.io");
fireEvent.click(screen.getByRole("button", { name: "Copy", exact: true }));
await waitFor(() => expect(copy).toHaveBeenCalledWith("Please use @drawio"));
} finally {
copy.mockRestore();
}
});
it("renders persisted session mentions inside sent user messages", () => {
+46
View File
@@ -3,6 +3,7 @@ import { expect, it, vi } from "vitest";
import { installedMcpPresetsFromPayload } from "@/lib/mcp-preset-events";
import { SkillsCatalogSettings } from "@/components/settings/SkillsCatalogSettings";
import { ClientProvider } from "@/providers/ClientProvider";
import { __clearLogoFallbackCacheForTests } from "@/hooks/useLogoFallback";
import { requestMutationMock, jsonResponse, settingsPayload, renderSettingsView, installSettingsViewTestHooks } from "@/tests/settings-test-utils";
@@ -209,6 +210,51 @@ describe("Settings system domains", () => {
expect(mcpTitle.nextElementSibling).toHaveTextContent("0");
});
it.each(["cli", "mcp"] as const)(
"fills the rounded %s app icon without an inset tile and preserves its fallback",
async (kind) => {
__clearLogoFallbackCacheForTests();
const name = kind === "cli" ? "AnyGen" : "Linear";
const logoUrl = `/test-${kind}-logo.svg`;
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url === "/api/settings") return jsonResponse(settingsPayload());
if (url === "/api/settings/cli-apps") {
return jsonResponse({ apps: [{ ...installedAnyGen, logo_url: logoUrl }], installed_count: 1 });
}
if (url === "/api/settings/mcp-presets") {
return jsonResponse({ presets: [{
...agentPlugin,
name: "linear",
display_name: "Linear",
source: "builtin",
enabled: true,
logo_url: logoUrl,
}], installed_count: 1 });
}
return jsonResponse({});
}));
renderSettingsView({ initialSection: "apps", initialSettings: settingsPayload() });
await screen.findByText("AnyGen");
if (kind === "mcp") fireEvent.click(screen.getByRole("button", { name: "MCP", exact: true }));
const row = (await screen.findByText(name)).closest("article")!;
const image = row.querySelector("img")!;
expect(image).toHaveAttribute("src", logoUrl);
expect(image).toHaveClass("h-full", "w-full", "object-contain");
fireEvent.load(image);
expect(image.parentElement).toHaveClass("h-9", "w-9", "overflow-hidden", "rounded-[10px]");
for (const tileClass of ["border", "bg-background", "bg-muted"]) {
expect(image.parentElement).not.toHaveClass(tileClass);
}
fireEvent.error(image);
expect(row.querySelector("img")).toBeNull();
const fallback = within(row).getByText(name[0], { exact: true });
expect(fallback).toBeVisible();
expect(fallback.closest(".h-9")).toHaveClass("w-9", "rounded-[10px]");
},
);
it("keeps skill group labels natural without changing grouping or filtering", () => {
render(<ClientProvider client={{} as never} token="tok">
<SkillsCatalogSettings skills={[
+127 -10
View File
@@ -1707,8 +1707,8 @@ describe("ThreadComposer", () => {
);
fireEvent.keyDown(input, { key: "Enter" });
expect(input).toHaveValue("@blender ");
expect(screen.getByTestId("composer-cli-mention-blender")).toHaveTextContent("@blender");
expect(input).toHaveValue("@Blender ");
expect(screen.getByTestId("composer-cli-mention-blender")).toHaveTextContent("@Blender");
expect(screen.queryByTestId("composer-cli-app-tray")).not.toBeInTheDocument();
expect(onSend).not.toHaveBeenCalled();
expect(screen.queryByRole("listbox", { name: "Mentions" })).not.toBeInTheDocument();
@@ -1789,8 +1789,8 @@ describe("ThreadComposer", () => {
fireEvent.keyDown(input, { key: "Tab" });
expect(input).toHaveValue("use @blender ");
expect(screen.getByTestId("composer-cli-mention-blender")).toHaveTextContent("@blender");
expect(input).toHaveValue("use @Blender ");
expect(screen.getByTestId("composer-cli-mention-blender")).toHaveTextContent("@Blender");
});
it("shows configured MCP presets in the mention palette and submits metadata", () => {
@@ -1814,9 +1814,9 @@ describe("ThreadComposer", () => {
fireEvent.keyDown(input, { key: "Tab" });
expect(input).toHaveValue("use @browserbase ");
expect(input).toHaveValue("use @\u00a0Browserbase ");
const mention = screen.getByTestId("composer-mcp-mention-browserbase");
expect(mention).toHaveTextContent("@browserbase");
expect(mention.textContent).toBe("@\u00a0Browserbase");
expect(mention).toHaveClass("font-normal");
expect(mention).not.toHaveClass("font-[550]");
@@ -2201,7 +2201,7 @@ describe("ThreadComposer", () => {
fireEvent.keyDown(input, { key: "Tab" });
expect(input).toHaveValue("use @blender tonight");
expect(input).toHaveValue("use @Blender tonight");
});
it("renders a CLI app mention logo inline without moving the text cursor slot", () => {
@@ -2218,9 +2218,9 @@ describe("ThreadComposer", () => {
target: { value: "meeting in @gimp", selectionStart: 16 },
});
expect(input).toHaveValue("meeting in @gimp");
expect(input).toHaveValue("meeting in @\u00a0GIMP");
const token = screen.getByTestId("composer-cli-mention-gimp");
expect(token).toHaveTextContent("@gimp");
expect(token.textContent).toBe("@\u00a0GIMP");
expect(token).toHaveClass("font-normal");
expect(token).not.toHaveClass("font-[550]");
expect(token.className).not.toContain("zoom-in");
@@ -2231,8 +2231,14 @@ describe("ThreadComposer", () => {
expect(screen.queryByTestId("composer-cli-app-tray")).not.toBeInTheDocument();
const logo = screen.getByTestId("composer-cli-mention-logo-gimp");
expect(logo.className).toContain("top-1/2");
expect(logo.className).toContain("left-1/2");
expect(logo.className).toContain("left-0");
expect(logo.className).not.toContain("-top-");
expect(logo).toHaveClass("h-[0.9em]", "w-[0.9em]", "rounded-[0.25em]");
// The shared text projection reserves the gap; no CSS margin may shift the caret.
expect(logo.parentElement).toHaveTextContent("@");
expect(logo.parentElement).toHaveClass("inline");
expect(logo.parentElement).not.toHaveClass("inline-block");
expect(logo.parentElement?.className).not.toMatch(/(?:^|\s)(?:w-|m[rlx]-|p[rlx]-)/);
});
it("uses the shared accent when an installed CLI app has no brand metadata", () => {
@@ -2271,6 +2277,117 @@ describe("ThreadComposer", () => {
expect(token.getAttribute("style")).not.toContain("var(--primary)");
});
it.each([
["linear", "Linear"], ["drawio", "Draw.io"], ["google-drive", "Google Drive"],
["iterm2", "iTerm2"], ["gimp", "GIMP"], ["1password", "1Password"],
["local", "本地应用"], ["fallback", " "],
])("shows %s's brand in the input and sends its identifier", (name, displayName) => {
const onSend = vi.fn();
const app = { ...CLI_APPS[0], name, display_name: displayName };
render(<ThreadComposer onSend={onSend} cliApps={[app]} />);
const input = screen.getByLabelText("Message input");
fireEvent.change(input, { target: { value: `请用 @${name} 帮我`, selectionStart: name.length + 5 } });
const label = displayName.trim() || name;
expect(input).toHaveValue(`请用 @\u00a0${label} 帮我`);
expect(screen.getByTestId(`composer-cli-mention-${name}`).textContent).toBe(`@\u00a0${label}`);
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
expect(onSend).toHaveBeenCalledWith(`请用 @${name} 帮我`, undefined, {
cliApps: [expect.objectContaining({ name, display_name: displayName })],
});
});
it("keeps multiple long mentions intact while editing, copying, cutting and undoing", async () => {
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} cliApps={[
{ ...CLI_APPS[0], name: "drive", display_name: "Google Drive" },
{ ...CLI_APPS[1], name: "drawio", display_name: "Draw.io" },
]} />);
const input = screen.getByLabelText("Message input") as HTMLTextAreaElement;
fireEvent.change(input, { target: { value: "@drive @drawio" } });
input.setSelectionRange(14, 14);
await userEvent.type(input, " hello", { skipClick: true });
expect(input).toHaveValue("@\u00a0Google Drive hello @Draw.io");
input.setSelectionRange(0, 14);
const setData = vi.fn();
fireEvent.copy(input, { clipboardData: { setData } });
expect(setData).toHaveBeenCalledWith("text/plain", "@drive");
fireEvent.cut(input, { clipboardData: { setData } });
expect(input).toHaveValue(" hello @Draw.io");
fireEvent.keyDown(input, { key: "z", metaKey: true });
expect(input).toHaveValue("@\u00a0Google Drive hello @Draw.io");
fireEvent.keyDown(input, { key: "z", metaKey: true, shiftKey: true });
expect(input).toHaveValue(" hello @Draw.io");
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
expect(onSend).toHaveBeenCalledWith("hello @drawio", undefined, {
cliApps: [expect.objectContaining({ name: "drawio" })],
});
});
it("deletes a brand mention as a unit and restores it on undo", async () => {
render(<ThreadComposer onSend={vi.fn()} mcpPresets={[
{ ...MCP_PRESETS[0], name: "drive", display_name: "Google Drive" },
]} />);
const input = screen.getByLabelText("Message input") as HTMLTextAreaElement;
fireEvent.change(input, { target: { value: "@drive!" } });
input.setSelectionRange(14, 14);
await userEvent.keyboard("{Backspace}");
expect(input).toHaveValue("!");
fireEvent.keyDown(input, { key: "z", ctrlKey: true });
expect(input).toHaveValue("@\u00a0Google Drive!");
});
it("does not interrupt Chinese composition or submit on an IME confirmation", () => {
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} cliApps={[
{ ...CLI_APPS[0], name: "drive", display_name: "Google Drive" },
]} />);
const input = screen.getByLabelText("Message input") as HTMLTextAreaElement;
fireEvent.change(input, { target: { value: "@drive " } });
const logo = screen.getByTestId("composer-cli-mention-logo-drive");
fireEvent.compositionStart(input);
expect(screen.getByTestId("composer-cli-mention-logo-drive")).toBe(logo);
fireEvent.change(input, { target: { value: "@\u00a0Google Drive 中", selectionStart: 16 } });
expect(input).toHaveValue("@\u00a0Google Drive 中");
expect(input).toHaveClass("text-transparent");
expect(input.previousElementSibling).toHaveClass("z-20");
expect(screen.getByTestId("composer-cli-mention-logo-drive")).toBe(logo);
expect(input.previousElementSibling?.textContent).toBe(input.value);
fireEvent.keyDown(input, { key: "Enter", isComposing: true });
expect(onSend).not.toHaveBeenCalled();
fireEvent.compositionEnd(input, { data: "中" });
expect(input).toHaveValue("@\u00a0Google Drive 中");
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
expect(onSend).toHaveBeenCalledWith("@drive 中", undefined, {
cliApps: [expect.objectContaining({ name: "drive" })],
});
});
it("clears mention editing and undo state when switching sessions during composition", () => {
const props = { onSend: vi.fn(), cliApps: CLI_APPS };
const { rerender } = render(<ThreadComposer {...props} pendingQueueKey="chat-a" />);
const input = screen.getByLabelText("Message input");
fireEvent.change(input, { target: { value: "@gimp " } });
fireEvent.compositionStart(input);
fireEvent.change(input, { target: { value: "@\u00a0GIMP 草稿" } });
rerender(<ThreadComposer {...props} pendingQueueKey="chat-b" />);
expect(input).toHaveValue("");
fireEvent.compositionEnd(input, { data: "草稿" });
fireEvent.keyDown(input, { key: "z", metaKey: true });
expect(input).toHaveValue("");
});
it("mirrors the trailing empty line and scroll offset of a decorated textarea", () => {
render(<ThreadComposer onSend={vi.fn()} cliApps={CLI_APPS} />);
const input = screen.getByLabelText("Message input") as HTMLTextAreaElement;
fireEvent.change(input, { target: { value: "@gimp\n" } });
const overlay = input.previousElementSibling as HTMLElement;
expect(overlay.textContent).toBe("@\u00a0GIMP\n\u200b");
expect(input).toHaveClass("block");
input.scrollTop = 80;
fireEvent.scroll(input);
expect(overlay.scrollTop).toBe(80);
});
it("opens the slash command palette downward when there is more room below", async () => {
vi.spyOn(HTMLFormElement.prototype, "getBoundingClientRect").mockReturnValue(
rect({ top: 40, bottom: 160, width: 800, height: 120 }),
+2 -1
View File
@@ -4459,8 +4459,9 @@ describe("ThreadShell", () => {
expect(screen.getByRole("option", { name: /@obsidian-agent-cli/i })).toBeInTheDocument();
expect(screen.getByTestId("composer-cli-mention-obsidian-agent-cli")).toHaveTextContent(
"@obsidian-agent-cli",
"@Obsidian",
);
expect(input).toHaveValue("@Obsidian");
});
it("offers sessions across projects in restricted mode", async () => {