Skip to content

Commit aca83ac

Browse files
clawsweeperroboclaw-botTakhoffman
authored
fix(ui): make multi-user session avatars legible (#128040)
* fix(ui): make multi-user session avatars legible Render sidebar owners and participants as equal 18px peers while preserving owner precedence, row height, and single-owner sizing. Co-authored-by: Tak Hoffman <[email protected]> * test(ui): isolate disclosure anchor geometry Measure the raw-details toggle independently from the widget menu overlay, whose close and reposition behavior is already covered separately and was producing a deterministic false CI failure. Co-authored-by: Tak Hoffman <[email protected]> * test(ui): stabilize completed-work spacing geometry Disable the unrelated settle-in animation in the final-layout fixture and restore the original tight spacing contract. This prevents CI timing from sampling a mid-animation transform. Co-authored-by: Tak Hoffman <[email protected]> * test(ui): prove sidebar lead alignment Assert that collaborative avatar artwork stays within the fixed 20px lead contract and leaves titles aligned with single-owner rows. Co-authored-by: Tak Hoffman <[email protected]> --------- Co-authored-by: RoboClaw <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
1 parent cc56ea5 commit aca83ac

5 files changed

Lines changed: 304 additions & 43 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { afterEach, describe, expect, it } from "vitest";
2+
import "../test-helpers/load-styles.ts";
3+
import type { SessionCreatedActor } from "./session-owner-chip.ts";
4+
import "./session-owner-chip.ts";
5+
6+
type OwnerChipElement = HTMLElement & {
7+
owner: SessionCreatedActor | null;
8+
participants: readonly SessionCreatedActor[];
9+
participantCount: number;
10+
size: "row" | "header";
11+
updateComplete: Promise<boolean>;
12+
};
13+
14+
const hasBrowserLayout = !navigator.userAgent.toLowerCase().includes("jsdom");
15+
16+
afterEach(() => {
17+
document.body.replaceChildren();
18+
});
19+
20+
async function mountOwnerChip(params: {
21+
participants?: readonly SessionCreatedActor[];
22+
participantCount?: number;
23+
}) {
24+
// SAFETY: the imported module registers this custom element with these reactive properties.
25+
const chip = document.createElement("openclaw-session-owner-chip") as OwnerChipElement;
26+
chip.owner = { type: "human", id: "profile-ada", label: "Ada" };
27+
chip.size = "row";
28+
chip.participants = params.participants ?? [];
29+
chip.participantCount = params.participantCount ?? chip.participants.length;
30+
document.body.append(chip);
31+
await chip.updateComplete;
32+
return chip;
33+
}
34+
35+
describe.skipIf(!hasBrowserLayout)("session owner stack layout", () => {
36+
it.each([
37+
{
38+
backSelector: ".session-owner-stack__back .viewer-avatar",
39+
name: "one participant avatar",
40+
participantCount: 1,
41+
participants: [{ type: "human" as const, id: "profile-bob", label: "Bob" }],
42+
},
43+
{
44+
backSelector: ".session-owner-stack__overflow",
45+
name: "participant overflow",
46+
participantCount: 2,
47+
participants: [
48+
{ type: "human" as const, id: "profile-bob", label: "Bob" },
49+
{ type: "agent" as const, id: "research", label: "Research" },
50+
],
51+
},
52+
])("keeps $name legible as an equal peer behind the owner", async (fixture) => {
53+
const chip = await mountOwnerChip(fixture);
54+
const stack = chip.querySelector<HTMLElement>(".session-owner-stack");
55+
const back = chip.querySelector<HTMLElement>(fixture.backSelector);
56+
const front = chip.querySelector<HTMLElement>(".session-owner-stack__front");
57+
if (!stack || !back || !front) {
58+
throw new Error("expected complete session owner stack");
59+
}
60+
61+
const stackBounds = stack.getBoundingClientRect();
62+
const backBounds = back.getBoundingClientRect();
63+
const frontBounds = front.getBoundingClientRect();
64+
expect({
65+
backSize: [backBounds.width, backBounds.height],
66+
frontSize: [frontBounds.width, frontBounds.height],
67+
stackSize: [stackBounds.width, stackBounds.height],
68+
}).toEqual({
69+
backSize: [18, 18],
70+
frontSize: [18, 18],
71+
stackSize: [28, 20],
72+
});
73+
expect(backBounds.right - frontBounds.left).toBe(8);
74+
expect(frontBounds.left - backBounds.left).toBe(10);
75+
});
76+
77+
it("keeps the single-owner row avatar at its established size", async () => {
78+
const chip = await mountOwnerChip({});
79+
const owner = chip.querySelector<HTMLElement>(".session-owner-chip--row");
80+
if (!owner) {
81+
throw new Error("expected single owner row avatar");
82+
}
83+
const bounds = owner.getBoundingClientRect();
84+
expect([bounds.width, bounds.height]).toEqual([20, 20]);
85+
expect(chip.querySelector(".session-owner-stack")).toBeNull();
86+
});
87+
});

‎ui/src/e2e/chat-transcript-disclosure-anchor.e2e.test.ts‎

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -388,30 +388,16 @@ suite.define(() => {
388388
const widgetHost = page.locator(".chat-tool-card__widget-host");
389389
const rawDetailsToggle = widgetHost.locator(".chat-tool-card__raw-toggle");
390390
await rawDetailsToggle.waitFor({ state: "attached" });
391-
const widgetActions = widgetHost.getByRole("button", { name: "Widget actions" });
392-
const rawDetailsAction =
393-
'.chat-tool-card__widget-actions wa-dropdown-item[value="raw-details"]';
394-
const rawDetailsItem = widgetHost.locator(rawDetailsAction);
395391
await page.locator(".chat-thread").evaluate((thread) => {
396392
thread.scrollTop = thread.scrollHeight;
397393
});
398394
await waitForChatScrollIdle(page);
399395
expect(Math.abs(await chatThreadDistanceFromBottom(page))).toBeLessThanOrEqual(2);
400396
const traces: Record<string, DisclosureFrame[]> = {};
401-
await widgetActions.click();
402-
await rawDetailsItem.waitFor({ state: "visible" });
403-
traces.rawDetailsEndExpand = await toggleDisclosureWithFrameTrace(
404-
page,
405-
rawDetailsToggle,
406-
rawDetailsAction,
407-
);
408-
await widgetActions.click();
409-
await rawDetailsItem.waitFor({ state: "visible" });
410-
traces.rawDetailsEndCollapse = await toggleDisclosureWithFrameTrace(
411-
page,
412-
rawDetailsToggle,
413-
rawDetailsAction,
414-
);
397+
// Menu selection already proves it clicks this toggle; exclude the popup's
398+
// own close/reposition geometry from the transcript-anchor measurement.
399+
traces.rawDetailsEndExpand = await toggleDisclosureWithFrameTrace(page, rawDetailsToggle);
400+
traces.rawDetailsEndCollapse = await toggleDisclosureWithFrameTrace(page, rawDetailsToggle);
415401

416402
await rawDetailsToggle.evaluate((button) => {
417403
const row = button.closest<HTMLElement>(".chat-virtual-row");
@@ -423,13 +409,7 @@ suite.define(() => {
423409
thread.scrollTop += Math.round(rowTop - thread.clientHeight / 2);
424410
});
425411
await waitForChatScrollIdle(page);
426-
await widgetActions.click();
427-
await rawDetailsItem.waitFor({ state: "visible" });
428-
traces.rawDetailsMiddleExpand = await toggleDisclosureWithFrameTrace(
429-
page,
430-
rawDetailsToggle,
431-
rawDetailsAction,
432-
);
412+
traces.rawDetailsMiddleExpand = await toggleDisclosureWithFrameTrace(page, rawDetailsToggle);
433413

434414
if (artifactDir) {
435415
await fs.mkdir(artifactDir, { recursive: true });
@@ -448,13 +428,7 @@ suite.define(() => {
448428
path: path.join(artifactDir, "raw-details-geometry-dark.png"),
449429
});
450430
}
451-
await widgetActions.click();
452-
await rawDetailsItem.waitFor({ state: "visible" });
453-
traces.rawDetailsMiddleCollapse = await toggleDisclosureWithFrameTrace(
454-
page,
455-
rawDetailsToggle,
456-
rawDetailsAction,
457-
);
431+
traces.rawDetailsMiddleCollapse = await toggleDisclosureWithFrameTrace(page, rawDetailsToggle);
458432
const video = page.video();
459433
await context.close();
460434
if (artifactDir) {

‎ui/src/e2e/session-ownership.e2e.test.ts‎

Lines changed: 201 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Control UI E2E tests cover session ownership dormancy and owner filtering.
22
import { mkdir } from "node:fs/promises";
33
import path from "node:path";
4-
import type { Page } from "playwright";
4+
import type { BrowserContext, Page } from "playwright";
55
import { expect as expectBrowser } from "playwright/test";
66
import { afterEach, expect, it } from "vitest";
77
import { installMockGateway } from "../test-helpers/control-ui-e2e.ts";
@@ -13,6 +13,12 @@ const suite = createControlUiE2eSuite({
1313

1414
const captureUiProofEnabled = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1";
1515
const uiProofArtifactDir = path.join(process.cwd(), ".artifacts", "control-ui-e2e", "drafts-ux");
16+
const sessionOwnerProofArtifactDir = path.join(
17+
process.cwd(),
18+
".artifacts",
19+
"control-ui-e2e",
20+
"session-owner-stack",
21+
);
1622

1723
let page: Page | undefined;
1824
function sessionsList(owners: [string, string]) {
@@ -67,6 +73,72 @@ function draftSessionsList() {
6773
return result;
6874
}
6975

76+
function collaborativeSessionsList() {
77+
const ada = {
78+
type: "human" as const,
79+
id: "profile-ada",
80+
label: "Ada",
81+
avatarUrl: "/api/users/profile-ada/avatar?v=1",
82+
};
83+
const bob = {
84+
type: "human" as const,
85+
id: "profile-bob",
86+
label: "Bob",
87+
avatarUrl: "/api/users/profile-bob/avatar?v=1",
88+
};
89+
const carol = { type: "human" as const, id: "profile-carol", label: "Carol" };
90+
return {
91+
count: 3,
92+
owners: [ada, bob, carol],
93+
defaults: { contextTokens: null, model: null, modelProvider: null },
94+
path: "",
95+
sessions: [
96+
{
97+
key: "agent:main:collaboration",
98+
kind: "direct",
99+
label: "Fix issue #127689",
100+
createdActor: ada,
101+
owner: { actor: ada },
102+
participants: [bob],
103+
participantCount: 1,
104+
updatedAt: 3,
105+
},
106+
{
107+
key: "agent:main:release-planning",
108+
kind: "direct",
109+
label: "Release planning",
110+
createdActor: bob,
111+
owner: { actor: bob },
112+
participants: [ada, { type: "agent" as const, id: "research", label: "Research" }],
113+
participantCount: 2,
114+
updatedAt: 2,
115+
},
116+
{
117+
key: "agent:main:single-owner",
118+
kind: "direct",
119+
label: "Single-owner baseline",
120+
createdActor: carol,
121+
owner: { actor: carol },
122+
updatedAt: 1,
123+
},
124+
],
125+
ts: 1,
126+
};
127+
}
128+
129+
async function createAvatarPng(context: BrowserContext, background: string, label: string) {
130+
const avatarPage = await context.newPage();
131+
try {
132+
await avatarPage.setViewportSize({ width: 64, height: 64 });
133+
await avatarPage.setContent(
134+
`<body style="margin:0;width:64px;height:64px;display:grid;place-items:center;background:${background};color:white;font:700 26px system-ui">${label}</body>`,
135+
);
136+
return await avatarPage.screenshot({ animations: "disabled", type: "png" });
137+
} finally {
138+
await avatarPage.close().catch(() => {});
139+
}
140+
}
141+
70142
async function captureUiProof(targetPage: Page, fileName: string) {
71143
if (!captureUiProofEnabled) {
72144
return;
@@ -79,6 +151,17 @@ async function captureUiProof(targetPage: Page, fileName: string) {
79151
});
80152
}
81153

154+
async function captureSessionOwnerProof(targetPage: Page, fileName: string) {
155+
if (!captureUiProofEnabled) {
156+
return;
157+
}
158+
await mkdir(sessionOwnerProofArtifactDir, { recursive: true });
159+
await targetPage.locator(".sidebar-sessions").screenshot({
160+
animations: "disabled",
161+
path: path.join(sessionOwnerProofArtifactDir, fileName),
162+
});
163+
}
164+
82165
async function openSidebarSortMenu(targetPage: Page) {
83166
const filterAndSort = targetPage.getByRole("button", { name: "Filter & sort" });
84167
await expect.poll(() => filterAndSort.count(), { timeout: 2_000 }).toBe(1);
@@ -109,6 +192,123 @@ suite.define(() => {
109192
page = undefined;
110193
});
111194

195+
it("keeps collaborative owner stacks legible without shifting session rows", async () => {
196+
const context = await suite.browser.newContext({ viewport: { height: 800, width: 1200 } });
197+
const currentPage = await context.newPage();
198+
page = currentPage;
199+
const [adaAvatar, bobAvatar] = await Promise.all([
200+
createAvatarPng(context, "#3f6f76", "A"),
201+
createAvatarPng(context, "#985b42", "B"),
202+
]);
203+
await currentPage.route("**/api/users/profile-ada/avatar*", (route) =>
204+
route.fulfill({ body: adaAvatar, contentType: "image/png", status: 200 }),
205+
);
206+
await currentPage.route("**/api/users/profile-bob/avatar*", (route) =>
207+
route.fulfill({ body: bobAvatar, contentType: "image/png", status: 200 }),
208+
);
209+
await installMockGateway(currentPage, {
210+
hasMultipleSessionSharingIdentities: true,
211+
sessionKey: "agent:main:collaboration",
212+
historyMessages: [{ role: "assistant", content: [{ type: "text", text: "Ready." }] }],
213+
methodResponses: { "sessions.list": collaborativeSessionsList() },
214+
});
215+
216+
await currentPage.goto(`${suite.server?.baseUrl ?? ""}chat`);
217+
const collaborativeRow = currentPage.locator('[data-session-key="agent:main:collaboration"]');
218+
const overflowRow = currentPage.locator('[data-session-key="agent:main:release-planning"]');
219+
const singleOwnerRow = currentPage.locator('[data-session-key="agent:main:single-owner"]');
220+
await collaborativeRow.waitFor();
221+
await overflowRow.waitFor();
222+
await singleOwnerRow.waitFor();
223+
await expect.poll(() => collaborativeRow.locator(".session-owner-stack img").count()).toBe(2);
224+
await expect
225+
.poll(() =>
226+
collaborativeRow
227+
.locator(".session-owner-stack img")
228+
.evaluateAll((images) =>
229+
images.every(
230+
(image) =>
231+
image instanceof HTMLImageElement && image.complete && image.naturalWidth > 0,
232+
),
233+
),
234+
)
235+
.toBe(true);
236+
237+
const geometry = await collaborativeRow.evaluate((row) => {
238+
const stack = row.querySelector<HTMLElement>(".session-owner-stack");
239+
const back = row.querySelector<HTMLElement>(".session-owner-stack__back .viewer-avatar");
240+
const front = row.querySelector<HTMLElement>(".session-owner-stack__front");
241+
const slot = row.querySelector<HTMLElement>(".sidebar-session-indicator");
242+
const text = row.querySelector<HTMLElement>(".sidebar-recent-session__text");
243+
if (!stack || !back || !front || !slot || !text) {
244+
throw new Error("expected complete collaborative session row");
245+
}
246+
const stackBounds = stack.getBoundingClientRect();
247+
const backBounds = back.getBoundingClientRect();
248+
const frontBounds = front.getBoundingClientRect();
249+
const slotBounds = slot.getBoundingClientRect();
250+
const textBounds = text.getBoundingClientRect();
251+
return {
252+
backSize: [backBounds.width, backBounds.height],
253+
centerDelta:
254+
stackBounds.left + stackBounds.width / 2 - (slotBounds.left + slotBounds.width / 2),
255+
frontSize: [frontBounds.width, frontBounds.height],
256+
overlap: backBounds.right - frontBounds.left,
257+
reveal: frontBounds.left - backBounds.left,
258+
slotWidth: slotBounds.width,
259+
stackSize: [stackBounds.width, stackBounds.height],
260+
textGap: textBounds.left - stackBounds.right,
261+
};
262+
});
263+
expect(geometry).toEqual({
264+
backSize: [18, 18],
265+
centerDelta: 0,
266+
frontSize: [18, 18],
267+
overlap: 8,
268+
reveal: 10,
269+
slotWidth: 20,
270+
stackSize: [28, 20],
271+
textGap: 4,
272+
});
273+
await expectBrowser(overflowRow.locator(".session-owner-stack__overflow")).toHaveText("+2");
274+
const rowHeights = await Promise.all([
275+
collaborativeRow.evaluate((row) => row.getBoundingClientRect().height),
276+
singleOwnerRow.evaluate((row) => row.getBoundingClientRect().height),
277+
]);
278+
expect(rowHeights[0]).toBeCloseTo(rowHeights[1] ?? 0, 5);
279+
const titleLefts = await Promise.all(
280+
[collaborativeRow, singleOwnerRow].map((row) =>
281+
row
282+
.locator(".sidebar-recent-session__text")
283+
.evaluate((text) => text.getBoundingClientRect().left),
284+
),
285+
);
286+
expect(titleLefts[0]).toBeCloseTo(titleLefts[1] ?? 0, 5);
287+
288+
if (captureUiProofEnabled) {
289+
const legacyStyles = await currentPage.addStyleTag({
290+
content: `
291+
.session-owner-stack { width: 24px; }
292+
.session-owner-stack__back { width: 14px; height: 14px; }
293+
.session-owner-stack__back .viewer-avatar,
294+
.session-owner-stack__overflow { width: 14px; height: 14px; font-size: 7px; }
295+
.session-owner-stack__front { width: 20px; height: 20px; }
296+
`,
297+
});
298+
await captureSessionOwnerProof(currentPage, "00-before-light.png");
299+
await currentPage.evaluate(() =>
300+
document.documentElement.setAttribute("data-theme-mode", "dark"),
301+
);
302+
await captureSessionOwnerProof(currentPage, "01-before-dark.png");
303+
await legacyStyles.evaluate((style) => style.parentNode?.removeChild(style));
304+
await captureSessionOwnerProof(currentPage, "02-after-dark.png");
305+
await currentPage.evaluate(() =>
306+
document.documentElement.setAttribute("data-theme-mode", "light"),
307+
);
308+
await captureSessionOwnerProof(currentPage, "03-after-light.png");
309+
}
310+
});
311+
112312
it("shows permanent owner chips and filters existing custom groups", async () => {
113313
const context = await suite.browser.newContext({ viewport: { height: 800, width: 1200 } });
114314
const currentPage = await context.newPage();

0 commit comments

Comments
 (0)