Skip to content

Commit 579f490

Browse files
loganjLarry
andcommitted
fix(desktop): restore mention chip identity icons
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Signed-off-by: Logan Johnson <[email protected]>
1 parent e7e2993 commit 579f490

5 files changed

Lines changed: 98 additions & 15 deletions

File tree

‎desktop/src/shared/ui/markdown.test.mjs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,11 @@ test("resolved human mentions replace the authored at-sign with the shared icon"
14001400
);
14011401

14021402
assert.match(html, /data-mention=""/);
1403-
assert.match(html, /inline-chip-icon-human/);
1403+
assert.match(
1404+
html,
1405+
/inline-chip-leading-fragment[^>]*inline-chip-icon-human[^>]*>alice<\/span>/,
1406+
);
1407+
assert.match(html, /aria-label="alice"/);
14041408
assert.match(html, />alice</);
14051409
assert.doesNotMatch(html, />@alice</);
14061410
});
@@ -1432,7 +1436,11 @@ test("agent mentions retain the bot treatment instead of the human icon", () =>
14321436

14331437
assert.match(html, /data-mention=""/);
14341438
assert.match(html, /agent-mention-highlight/);
1435-
assert.match(html, /inline-chip-icon-agent/);
1439+
assert.match(
1440+
html,
1441+
/inline-chip-leading-fragment[^>]*inline-chip-icon-agent[^>]*>alice<\/span>/,
1442+
);
1443+
assert.match(html, /aria-label="alice"/);
14361444
assert.match(html, />alice</);
14371445
assert.doesNotMatch(html, />@alice</);
14381446
});

‎desktop/src/shared/ui/markdown/MarkdownMention.tsx‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import type * as React from "react";
22
import { AgentManagementMarker } from "@/features/agents/ui/OtherSetupAgentMarker";
33
import { UserProfilePopover } from "@/features/profile/ui/UserProfilePopover";
44
import { cn } from "@/shared/lib/cn";
5-
import { WRAPPING_INLINE_CHIP_CLASSES } from "@/shared/ui/mentionChip";
5+
import {
6+
inlineChipIconClasses,
7+
inlineChipLeadingEnd,
8+
WRAPPING_INLINE_CHIP_CLASSES,
9+
} from "@/shared/ui/mentionChip";
610
import { InlineChip } from "@/shared/ui/InlineChip";
711
import { useMarkdownRuntime } from "./runtimeContext";
812

@@ -28,6 +32,8 @@ export function createMarkdownMention(interactive: boolean) {
2832
pubkey !== undefined &&
2933
agentMentionPubkeysByName?.[mentionName] === pubkey;
3034
const mentionLabel = mentionText.replace(/^@/, "");
35+
const icon = isAgentMention ? "agent" : "human";
36+
const leadingEnd = inlineChipLeadingEnd(mentionLabel);
3137
// Only chips that actually open a profile get the clickable affordance.
3238
// A mention whose pubkey didn't resolve stays a plain chip — a pointer
3339
// cursor there promises a click that does nothing.
@@ -46,10 +52,20 @@ export function createMarkdownMention(interactive: boolean) {
4652
)}
4753
title={mentionLabel}
4854
aria-label={mentionLabel}
49-
icon={isAgentMention ? "agent" : "human"}
55+
icon={icon}
5056
interactive={opensProfile}
5157
>
52-
{mentionLabel}
58+
{/* Wrapping chips hide the outer icon; keep it with a bounded prefix. */}
59+
<span
60+
aria-hidden="true"
61+
className={cn(
62+
"inline-chip-leading-fragment",
63+
inlineChipIconClasses(icon),
64+
)}
65+
>
66+
{mentionLabel.slice(0, leadingEnd)}
67+
</span>
68+
{mentionLabel.slice(leadingEnd)}
5369
{isAgentMention ? <AgentManagementMarker pubkey={pubkey} /> : null}
5470
</InlineChip>
5571
);

‎desktop/tests/e2e/cloud-provenance.spec.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ for (const agentListDelayMs of [0, 6_000]) {
139139
).toBeVisible();
140140
const chip = article.locator("[data-mention]");
141141
await expect(chip.locator("svg.lucide-cloud")).toBeVisible();
142+
const leading = chip.locator(".inline-chip-leading-fragment");
143+
await expect(leading).toHaveText("Remot");
144+
expect(
145+
await leading.evaluate(
146+
(element) => getComputedStyle(element, "::before").display,
147+
),
148+
).toBe("block");
142149
await waitForAnimations(page);
143150
await article.screenshot({
144151
path: testInfo.outputPath("cloud-author-chip.png"),

‎desktop/tests/e2e/mention-clipboard.spec.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ async function copyFromTimeline(
133133
selection.removeAllRanges();
134134
const range = document.createRange();
135135
if (selectPartialChip) {
136-
const label = chip.firstChild;
137-
if (!label) throw new Error("Mention chip has no text node.");
136+
const walker = document.createTreeWalker(chip, NodeFilter.SHOW_TEXT);
137+
const label = walker.nextNode();
138+
if (!label?.nodeValue?.startsWith("John")) {
139+
throw new Error("Mention chip has no leading John text node.");
140+
}
138141
range.setStart(label, 0);
139142
range.setEnd(label, 4);
140143
} else {
@@ -930,7 +933,7 @@ test("a boundary-crossing default copy pastes its chip fragment without a sigil"
930933
return nodes;
931934
};
932935
const label = textNodesUnder(chip).find((node) =>
933-
node.nodeValue?.includes("John Smith"),
936+
node.nodeValue?.includes("Smith"),
934937
);
935938
const tail = textNodesUnder(body).find((node) =>
936939
node.nodeValue?.includes("fixed the bug"),

‎desktop/tests/e2e/mention-recipients.spec.ts‎

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const SECOND = TEST_IDENTITIES.bob.pubkey;
77
const AMBIGUOUS =
88
"The mention @Scout is ambiguous. Choose a recipient from the mention picker.";
99

10-
async function install(page: Page, channel = "general") {
10+
async function install(page: Page, channel = "general", agents = false) {
1111
await installMockBridge(page, {
1212
managedAgents:
1313
channel === "watercooler"
@@ -17,10 +17,18 @@ async function install(page: Page, channel = "general") {
1717
status: "running",
1818
channelNames: ["watercooler"],
1919
}))
20-
: [],
20+
: agents
21+
? [FIRST, SECOND].map((pubkey) => ({
22+
pubkey,
23+
name: "Scout",
24+
status: "running",
25+
channelNames: [channel],
26+
}))
27+
: [],
2128
searchProfiles: [FIRST, SECOND].map((pubkey) => ({
2229
pubkey,
2330
displayName: "Scout",
31+
isAgent: agents,
2432
})),
2533
});
2634
await page.goto("/");
@@ -419,12 +427,19 @@ test("editing to a longer typed member drops the original shorter reference", as
419427
await expect(row).toContainText("Scout Jones hello");
420428
});
421429

422-
for (const scale of [1, 1.5]) {
423-
test(`exact-key chips wrap in narrow composer, sent message and reopen at ${scale}x text`, async ({
430+
// The default relay directory knows FIRST as an agent; SECOND is a human.
431+
// The agent variant makes SECOND managed too, covering a qualified bot label.
432+
for (const { kind, scale } of [
433+
{ kind: "mixed", scale: 1 },
434+
{ kind: "mixed", scale: 1.5 },
435+
{ kind: "agent", scale: 1 },
436+
{ kind: "agent", scale: 1.5 },
437+
]) {
438+
test(`exact-key ${kind} chips wrap in narrow composer, sent message and reopen at ${scale}x text`, async ({
424439
page,
425440
}, testInfo) => {
426441
await page.setViewportSize({ width: 800, height: 900 });
427-
await install(page);
442+
await install(page, "general", kind === "agent");
428443
await page.evaluate((scale) => {
429444
document.documentElement.style.fontSize = `${16 * scale}px`;
430445
}, scale);
@@ -460,6 +475,13 @@ for (const scale of [1, 1.5]) {
460475
host: import("@playwright/test").Locator,
461476
stage: string,
462477
) => {
478+
if (stage === "sent") {
479+
await expect(host.locator("[data-mention]")).toHaveCount(2);
480+
await expect(host.locator("[data-mention]").last()).toHaveAttribute(
481+
"data-mention-kind",
482+
kind === "agent" ? "agent" : "human",
483+
);
484+
}
463485
const result = await geometry(host);
464486
expect(result.chips.length).toBeGreaterThanOrEqual(2);
465487
expect(result.scrollWidth).toBeLessThanOrEqual(result.clientWidth + 1);
@@ -475,7 +497,34 @@ for (const scale of [1, 1.5]) {
475497
expect(rect.right).toBeLessThanOrEqual(result.width + 1);
476498
}
477499
}
478-
if (stage !== "sent") {
500+
if (stage === "sent") {
501+
for (const chip of await host.locator("[data-mention]").all()) {
502+
const expectedKind =
503+
kind === "agent" ||
504+
(await chip.getAttribute("data-mention-pubkey")) === FIRST
505+
? "agent"
506+
: "human";
507+
await expect(chip).toHaveAttribute("data-mention-kind", expectedKind);
508+
const leading = chip.locator(".inline-chip-leading-fragment");
509+
await expect(leading).toHaveText("Scout");
510+
const icon = await leading.evaluate((element) => {
511+
const style = getComputedStyle(element, "::before");
512+
return {
513+
display: style.display,
514+
mask: style.maskImage,
515+
width: parseFloat(style.width),
516+
height: parseFloat(style.height),
517+
};
518+
});
519+
expect(icon.display).toBe("block");
520+
expect(icon.mask).toContain("data:image/svg+xml");
521+
expect(icon.width).toBeGreaterThan(0);
522+
expect(icon.height).toBeGreaterThan(0);
523+
await expect(leading).toHaveClass(
524+
new RegExp(`inline-chip-icon-${expectedKind}`),
525+
);
526+
}
527+
} else {
479528
for (const prefix of await host
480529
.locator(".mention-prefix-hidden")
481530
.all()) {
@@ -495,7 +544,7 @@ for (const scale of [1, 1.5]) {
495544
});
496545
await waitForAnimations(page);
497546
await page.screenshot({
498-
path: `test-results/mention-recipients/layout-${scale}-${stage}.png`,
547+
path: `test-results/mention-recipients/layout-${kind}-${scale}-${stage}.png`,
499548
});
500549
};
501550
await expect(input).toHaveText(content);

0 commit comments

Comments
 (0)