Skip to content

Commit 3bf3acb

Browse files
authored
fix(ui): preserve steer order and simplify composer ownership (#124915)
* refactor(ui): simplify composer steer ownership * fix(ui): preserve target order for landed steers
1 parent 6e026c2 commit 3bf3acb

21 files changed

Lines changed: 166 additions & 345 deletions

‎ui/src/e2e/chat-composer-redesign.e2e.test.ts‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
// Control UI E2E tests cover the redesigned chat composer.
2-
import { mkdir } from "node:fs/promises";
3-
import path from "node:path";
4-
import type { Page } from "playwright-core";
52
import { expect, it } from "vitest";
63
import { installMockGateway } from "../test-helpers/control-ui-e2e.ts";
74
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
@@ -10,25 +7,6 @@ const suite = createControlUiE2eSuite({
107
name: "Control UI chat composer redesign",
118
});
129

13-
const captureUiProofEnabled = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1";
14-
const uiProofArtifactDir = path.join(
15-
process.cwd(),
16-
".artifacts",
17-
"control-ui-e2e",
18-
"chat-composer-redesign",
19-
);
20-
21-
async function captureUiProof(page: Page, fileName: string) {
22-
if (!captureUiProofEnabled) {
23-
return;
24-
}
25-
await mkdir(uiProofArtifactDir, { recursive: true });
26-
await page.screenshot({
27-
animations: "disabled",
28-
path: path.join(uiProofArtifactDir, fileName),
29-
});
30-
}
31-
3210
// Browser contexts preserve test isolation; keep one process warm for this file.
3311
suite.define(() => {
3412
it("keeps mobile picker panels above an attachment-expanded composer", async () => {
@@ -203,7 +181,6 @@ suite.define(() => {
203181
const emptySend = page.getByRole("button", { name: "Write a message to send." });
204182
await expect.poll(() => emptySend.isVisible()).toBe(true);
205183
await expect.poll(() => emptySend.isDisabled()).toBe(true);
206-
await captureUiProof(page, "01-empty-idle-disabled-send.png");
207184
await expect
208185
.poll(() => page.getByRole("button", { name: "Start video talk" }).count())
209186
.toBe(0);
@@ -433,7 +410,6 @@ suite.define(() => {
433410
await expect
434411
.poll(() => page.getByRole("button", { name: "Start voice input" }).isVisible())
435412
.toBe(true);
436-
await captureUiProof(page, "02-draft-single-send.png");
437413

438414
await page.getByRole("button", { name: "Send message" }).click();
439415
const sendRequest = await gateway.waitForRequest("chat.send");
@@ -496,12 +472,10 @@ suite.define(() => {
496472
});
497473
await expect.poll(() => followUp.isVisible()).toBe(true);
498474
await expect.poll(() => page.locator(".chat-send-btn--stop").count()).toBe(0);
499-
await captureUiProof(page, "03-active-run-draft-single-follow-up.png");
500475

501476
await textarea.fill("");
502477
const stop = page.getByRole("button", { name: "Stop generating" });
503478
await expect.poll(() => stop.isVisible()).toBe(true);
504-
await captureUiProof(page, "04-active-run-empty-stop.png");
505479
await textarea.press("Escape");
506480
const abortRequest = await gateway.waitForRequest("chat.abort");
507481
expect(abortRequest.params).toMatchObject({
@@ -627,7 +601,6 @@ suite.define(() => {
627601
await expect
628602
.poll(() => microphonePickerShell.evaluate((node) => getComputedStyle(node).opacity))
629603
.toBe("1");
630-
await captureUiProof(page, "05-mic-hover-reveals-picker.png");
631604
await microphonePicker.click();
632605
await expect.poll(() => microphonePicker.getAttribute("aria-expanded")).toBe("true");
633606
await expect.poll(() => page.locator(".chat-talk-input-picker[open]").count()).toBe(1);

‎ui/src/e2e/chat-flow.active-run-follow-ups.e2e.test.ts‎

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ async function expectChatBubbleAbove(page: Page, upperText: string, lowerText: s
4545

4646
suite.define(() => {
4747
it("steers ordinary follow-ups when the server default is steer", async () => {
48-
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
4948
const context = await suite.newBrowserContext({
5049
locale: "en-US",
5150
serviceWorkers: "block",
5251
viewport: { height: 900, width: 1280 },
53-
...(artifactDir
54-
? { recordVideo: { dir: artifactDir, size: { height: 900, width: 1280 } } }
55-
: {}),
5652
});
5753
const page = await context.newPage();
5854
const runtimeConfig = {
@@ -127,12 +123,6 @@ suite.define(() => {
127123
timeout: 10_000,
128124
});
129125
await queue.getByText(followUp).waitFor({ timeout: 10_000 });
130-
if (artifactDir) {
131-
await page.screenshot({
132-
path: `${artifactDir}/steer-before-persistence.png`,
133-
fullPage: true,
134-
});
135-
}
136126
await gateway.emitGatewayEvent("session.message", {
137127
activeRunIds: [activeRunId],
138128
clientRunId: activeRunId,
@@ -165,19 +155,12 @@ suite.define(() => {
165155
.poll(() => page.locator(".chat-thread .chat-group.user", { hasText: followUp }).count())
166156
.toBe(1);
167157
await expectChatBubbleAbove(page, originalPrompt, followUp);
168-
if (artifactDir) {
169-
await page.screenshot({
170-
path: `${artifactDir}/steer-after-persistence.png`,
171-
fullPage: true,
172-
});
173-
}
174158
} finally {
175159
await suite.closeBrowserContext(context);
176160
}
177161
});
178162

179163
it("preserves a non-steer server default for active-run follow-ups", async () => {
180-
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
181164
const context = await suite.newBrowserContext({
182165
locale: "en-US",
183166
serviceWorkers: "block",
@@ -206,12 +189,6 @@ suite.define(() => {
206189
await followUpSelect.waitFor({ state: "visible", timeout: 10_000 });
207190
expect(await followUpSelect.inputValue()).toBe("server");
208191
await page.getByText("Using server default (followup)").waitFor({ timeout: 10_000 });
209-
if (artifactDir) {
210-
await page.screenshot({
211-
path: `${artifactDir}/server-followup-setting.png`,
212-
fullPage: true,
213-
});
214-
}
215192
const configPatchCount = (await gateway.getRequests("config.patch")).length;
216193
const configGetCount = (await gateway.getRequests("config.get")).length;
217194
const overrideConfig = {
@@ -238,12 +215,6 @@ suite.define(() => {
238215
runtimeConfig,
239216
valid: true,
240217
});
241-
if (artifactDir) {
242-
await page.screenshot({
243-
path: `${artifactDir}/server-followup-override.png`,
244-
fullPage: true,
245-
});
246-
}
247218
await page.getByRole("button", { name: "Reset to server default" }).click();
248219
await waitForRequests(gateway, "config.patch", configPatchCount + 2);
249220
await waitForRequests(gateway, "config.get", configGetCount + 2);
@@ -276,14 +247,10 @@ suite.define(() => {
276247
});
277248

278249
it("steers a queued follow-up with modified Enter in Enter shortcut mode", async () => {
279-
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
280250
const context = await suite.newBrowserContext({
281251
locale: "en-US",
282252
serviceWorkers: "block",
283253
viewport: { height: 900, width: 1280 },
284-
...(artifactDir
285-
? { recordVideo: { dir: artifactDir, size: { height: 900, width: 1280 } } }
286-
: {}),
287254
});
288255
const page = await context.newPage();
289256
const gateway = await installMockGateway(page);
@@ -303,28 +270,6 @@ suite.define(() => {
303270

304271
const steerText = "steer this keyboard follow-up now";
305272
await composer.fill(steerText);
306-
const enterQueueButton = page.getByRole("button", { name: "Queue message" });
307-
const enterTooltip = await enterQueueButton
308-
.locator("..")
309-
.evaluate((element) => (element as HTMLElement & { content?: string }).content);
310-
expect(enterTooltip).toBe("Queue ⏎ · Steer ⌘/Ctrl+Enter");
311-
if (artifactDir) {
312-
await enterQueueButton.hover();
313-
await expect
314-
.poll(() =>
315-
enterQueueButton.evaluate((button) => {
316-
const tooltip = button
317-
.closest("openclaw-tooltip")
318-
?.shadowRoot?.querySelector("wa-tooltip");
319-
return (tooltip as (HTMLElement & { open?: boolean }) | null)?.open === true;
320-
}),
321-
)
322-
.toBe(true);
323-
await page.screenshot({
324-
path: `${artifactDir}/queue-steer-shortcut.png`,
325-
fullPage: true,
326-
});
327-
}
328273
await composer.press("Control+Enter");
329274

330275
const firstRunSends = await waitForRequests(gateway, "chat.send", 2);
@@ -338,17 +283,6 @@ suite.define(() => {
338283
});
339284
const steeredRow = page.locator(".chat-queue__item--steered", { hasText: steerText });
340285
await steeredRow.waitFor({ timeout: 10_000 });
341-
await gateway.emitGatewayEvent("chat", {
342-
runId: requireString(steerParams.idempotencyKey, "steer send id"),
343-
sessionKey: "main",
344-
state: "final",
345-
});
346-
await steeredRow.waitFor({ state: "detached", timeout: 10_000 });
347-
348-
await gateway.emitChatFinal({ runId: firstRunId, text: "First shortcut run finished." });
349-
await page
350-
.getByRole("button", { name: "Stop generating" })
351-
.waitFor({ state: "detached", timeout: 10_000 });
352286
} finally {
353287
await suite.closeBrowserContext(context);
354288
}
@@ -377,11 +311,6 @@ suite.define(() => {
377311

378312
const queuedText = "leave this modifier follow-up queued";
379313
await composer.fill(queuedText);
380-
const queueButton = page.getByRole("button", { name: "Queue message" });
381-
const tooltip = await queueButton
382-
.locator("..")
383-
.evaluate((element) => (element as HTMLElement & { content?: string }).content);
384-
expect(tooltip).toBe("Queue");
385314
await composer.press("Control+Enter");
386315

387316
const queuedRow = page.locator(".chat-queue__item", { hasText: queuedText });
@@ -459,14 +388,10 @@ suite.define(() => {
459388
});
460389

461390
it("dismisses an informational steer notice when the steer request lands", async () => {
462-
const artifactDir = process.env.OPENCLAW_UI_E2E_ARTIFACT_DIR?.trim();
463391
const context = await suite.newBrowserContext({
464392
locale: "en-US",
465393
serviceWorkers: "block",
466394
viewport: { height: 900, width: 1280 },
467-
...(artifactDir
468-
? { recordVideo: { dir: artifactDir, size: { height: 900, width: 1280 } } }
469-
: {}),
470395
});
471396
const page = await context.newPage();
472397
const gateway = await installMockGateway(page);
@@ -548,10 +473,6 @@ suite.define(() => {
548473
infoSubtle,
549474
};
550475
});
551-
if (artifactDir) {
552-
await page.screenshot({ path: `${artifactDir}/steer-pending.png`, fullPage: true });
553-
}
554-
555476
await gateway.emitGatewayEvent("chat", {
556477
runId: steerRunId,
557478
sessionKey: "main",
@@ -560,9 +481,6 @@ suite.define(() => {
560481
await row.waitFor({ state: "detached", timeout: 10_000 });
561482
await page.getByText(steerText, { exact: true }).waitFor({ timeout: 10_000 });
562483
await expectChatBubbleAbove(page, "keep this run active", steerText);
563-
if (artifactDir) {
564-
await page.screenshot({ path: `${artifactDir}/steer-landed.png`, fullPage: true });
565-
}
566484

567485
expect(pendingPresentation).toMatchObject({
568486
badgeColor: pendingPresentation.infoColor,

‎ui/src/pages/chat/chat-composer-actions.test.ts‎

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,52 @@ describe("renderChatComposer controls", () => {
254254
});
255255

256256
it.each([
257-
["Meta", { metaKey: true }],
258-
["Control", { ctrlKey: true }],
259-
] as const)("uses %s+Enter to steer an active queued follow-up", (_name, modifiers) => {
260-
const onSend = vi.fn();
261-
const { container } = renderComposer({
262-
canAbort: true,
263-
draft: "Steer this now",
264-
followUpMode: "queue",
265-
onAbort: vi.fn(),
266-
onSend,
267-
sendShortcut: "enter",
268-
});
257+
["Meta+Enter with a rendered draft", { metaKey: true }, "Steer this now", undefined, undefined],
258+
[
259+
"Control+Enter with a rendered draft",
260+
{ ctrlKey: true },
261+
"Steer this now",
262+
undefined,
263+
undefined,
264+
],
265+
[
266+
"Control+Enter with attachment-only content",
267+
{ ctrlKey: true },
268+
"",
269+
() => [{ id: "image-1", mimeType: "image/png", fileName: "proof.png" }],
270+
undefined,
271+
],
272+
[
273+
"Control+Enter with live textarea content before the draft prop rerenders",
274+
{ ctrlKey: true },
275+
"",
276+
undefined,
277+
"Steer the live textarea value",
278+
],
279+
] as const)(
280+
"uses %s to steer an active queued follow-up",
281+
(_name, modifiers, draft, getAttachments, liveDraft) => {
282+
const onSend = vi.fn();
283+
const { container } = renderComposer({
284+
canAbort: true,
285+
draft,
286+
followUpMode: "queue",
287+
getAttachments,
288+
onAbort: vi.fn(),
289+
onSend,
290+
sendShortcut: "enter",
291+
});
292+
const textarea = container.querySelector<HTMLTextAreaElement>("textarea");
293+
if (textarea && liveDraft !== undefined) {
294+
textarea.value = liveDraft;
295+
}
269296

270-
pressComposerEnter(container, modifiers);
297+
pressComposerEnter(container, modifiers);
271298

272-
expect(onSend).toHaveBeenCalledOnce();
273-
expect(onSend).toHaveBeenCalledWith({ followUpMode: "steer" });
274-
});
299+
expect(onSend).toHaveBeenCalledOnce();
300+
expect(onSend).toHaveBeenCalledWith("steer");
301+
},
302+
);
275303

276304
it.each([
277305
["modifier-enter", true, "queue", false],
@@ -374,6 +402,17 @@ describe("renderChatComposer controls", () => {
374402
},
375403
tooltip: t("chat.queue.steer"),
376404
},
405+
{
406+
overrides: {
407+
canAbort: true,
408+
connected: false,
409+
draft: "Queue until the gateway reconnects",
410+
followUpMode: "queue" as const,
411+
onAbort: vi.fn(),
412+
sendShortcut: "enter" as const,
413+
},
414+
tooltip: t("chat.runControls.queue"),
415+
},
377416
];
378417
for (const testCase of unavailable) {
379418
const view = renderComposer(testCase.overrides);

‎ui/src/pages/chat/chat-composer-context.test.ts‎

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,16 @@
11
/* @vitest-environment jsdom */
22

3-
import { render } from "lit";
43
import { afterEach, describe, expect, it, vi } from "vitest";
5-
import { i18n } from "../../i18n/index.ts";
6-
import { renderChatComposer, resetChatComposerState } from "./components/chat-composer.ts";
4+
import { renderComposerFixture, resetComposerFixture } from "./chat-composer.test-support.ts";
75

8-
type ComposerProps = Parameters<typeof renderChatComposer>[0];
6+
type ComposerOverrides = Parameters<typeof renderComposerFixture>[0];
97

10-
function renderComposer(overrides: Partial<ComposerProps> = {}) {
11-
const container = document.createElement("div");
12-
render(
13-
renderChatComposer({
14-
paneId: crypto.randomUUID(),
15-
sessionKey: "main",
16-
currentAgentId: "main",
17-
connected: true,
18-
canSend: true,
19-
disabledReason: null,
20-
sending: false,
21-
messages: [],
22-
stream: null,
23-
queue: [],
24-
draft: "",
25-
sessions: null,
26-
assistantName: "OpenClaw",
27-
onDraftChange: vi.fn(),
28-
onSend: vi.fn(),
29-
onQueueRemove: vi.fn(),
30-
onNewSession: vi.fn(),
31-
...overrides,
32-
}),
33-
container,
34-
);
35-
return container;
8+
function renderComposer(overrides: ComposerOverrides = {}) {
9+
return renderComposerFixture(overrides).container;
3610
}
3711

3812
afterEach(async () => {
39-
resetChatComposerState();
40-
document.body.replaceChildren();
41-
vi.useRealTimers();
42-
await i18n.setLocale("en");
43-
vi.restoreAllMocks();
13+
await resetComposerFixture();
4414
});
4515

4616
describe("renderChatComposer context usage", () => {

0 commit comments

Comments
 (0)