Skip to content

Commit 29d0713

Browse files
authored
refactor(ui): reuse protocol file response types (#130789)
* refactor(ui): reuse protocol file response types * test(ui): make session hovercard timing deterministic
1 parent 95e040c commit 29d0713

2 files changed

Lines changed: 42 additions & 95 deletions

File tree

‎ui/src/api/types.ts‎

Lines changed: 9 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
CronListParams,
55
CronRunLogEntry as ProtocolCronRunLogEntry,
66
CronRunsParams,
7+
SessionsFilesListResult as ProtocolSessionsFilesListResult,
78
} from "../../../packages/gateway-protocol/src/index.js";
89
import type { AgentsListResult as ProtocolAgentsListResult } from "../../../packages/gateway-protocol/src/schema/agents-models-skills.js";
910
import type { ChannelsStatusResult } from "../../../packages/gateway-protocol/src/schema/channels.js";
@@ -23,6 +24,12 @@ import type {
2324
SessionsPatchResultBase,
2425
} from "../../../src/shared/session-types.js";
2526
export type {
27+
AgentsFileEntry as AgentFileEntry,
28+
AgentsFilesListResult,
29+
AgentsFilesGetResult,
30+
AgentsFilesSetResult,
31+
SessionsFilesGetResult as SessionWorkspaceGetResult,
32+
SessionsFilesSetResult as SessionWorkspaceSetResult,
2633
CronJob,
2734
CronRunLogEntry,
2835
UpdateAvailable,
@@ -302,70 +309,6 @@ export type AgentIdentityResult = {
302309
emoji?: string;
303310
};
304311

305-
export type AgentFileEntry = {
306-
name: string;
307-
path: string;
308-
missing: boolean;
309-
// Absence is a normal workspace state (optional profile files, MEMORY.md before
310-
// anything is written); the editor offers these for creation instead of flagging them.
311-
expectedAbsent?: boolean;
312-
size?: number;
313-
updatedAtMs?: number;
314-
content?: string;
315-
};
316-
317-
export type AgentsFilesListResult = {
318-
agentId: string;
319-
workspace: string;
320-
files: AgentFileEntry[];
321-
};
322-
323-
export type AgentsFilesGetResult = {
324-
agentId: string;
325-
workspace: string;
326-
file: AgentFileEntry;
327-
};
328-
329-
export type AgentsFilesSetResult = {
330-
ok: true;
331-
agentId: string;
332-
workspace: string;
333-
file: AgentFileEntry;
334-
};
335-
336-
type SessionWorkspaceFileEntry = {
337-
path: string;
338-
workspacePath?: string;
339-
name: string;
340-
kind: "modified" | "read";
341-
missing: boolean;
342-
size?: number;
343-
updatedAtMs?: number;
344-
content?: string;
345-
/** sha256 hex of the file bytes; the CAS token for sessions.files.set. */
346-
hash?: string;
347-
mimeType?: string;
348-
contentEncoding?: "utf8" | "base64";
349-
previewKind?: "text" | "image" | "unsupported";
350-
};
351-
352-
type SessionWorkspaceBrowserEntry = {
353-
path: string;
354-
name: string;
355-
kind: "file" | "directory";
356-
sessionKind?: "modified" | "read" | "mixed";
357-
size?: number;
358-
updatedAtMs?: number;
359-
};
360-
361-
type SessionWorkspaceBrowserResult = {
362-
path: string;
363-
parentPath?: string;
364-
search?: string;
365-
entries: SessionWorkspaceBrowserEntry[];
366-
truncated?: boolean;
367-
};
368-
369312
type SessionWorkspaceArtifactEntry = {
370313
id: string;
371314
type: string;
@@ -378,27 +321,11 @@ type SessionWorkspaceArtifactEntry = {
378321
};
379322
};
380323

381-
export type SessionWorkspaceListResult = {
382-
sessionKey: string;
383-
root?: string;
384-
gitCheckout?: boolean;
385-
files: SessionWorkspaceFileEntry[];
386-
browser?: SessionWorkspaceBrowserResult;
324+
// The workspace view joins file results with separately fetched artifacts.
325+
export type SessionWorkspaceListResult = ProtocolSessionsFilesListResult & {
387326
artifacts?: SessionWorkspaceArtifactEntry[];
388327
};
389328

390-
export type SessionWorkspaceGetResult = {
391-
sessionKey: string;
392-
root?: string;
393-
file: SessionWorkspaceFileEntry;
394-
};
395-
396-
export type SessionWorkspaceSetResult = {
397-
sessionKey: string;
398-
root?: string;
399-
file: SessionWorkspaceFileEntry;
400-
};
401-
402329
export type ArtifactDownloadResult = {
403330
artifact: SessionWorkspaceArtifactEntry;
404331
encoding?: "base64";

‎ui/src/e2e/session-progress-hovercard.e2e.test.ts‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
controlUiSessionUrl,
1212
createChatFlowE2eSuite,
1313
installMockGateway,
14+
pauseVirtualClock,
1415
} from "./chat-flow.test-support.ts";
1516

1617
const proofDir = path.join(
@@ -536,6 +537,8 @@ suite.define(() => {
536537
viewport: { height: 900, width: 1280 },
537538
},
538539
async ({ page }) => {
540+
// Browser RPC time must not consume the hover-delay assertion windows.
541+
await page.clock.install();
539542
await installMockGateway(page, {
540543
featureMethods: ["chat.metadata", "chat.startup", "progressCard.get"],
541544
methodResponses: {
@@ -559,6 +562,7 @@ suite.define(() => {
559562
() => customElements.get("openclaw-session-progress-hovercard-provider") === undefined,
560563
),
561564
).toBe(true);
565+
await pauseVirtualClock(page);
562566

563567
const pointer = async (
564568
locator: typeof first,
@@ -574,9 +578,11 @@ suite.define(() => {
574578
});
575579

576580
await first.hover();
581+
await expect.poll(() => first.getAttribute("aria-haspopup")).toBe("dialog");
577582
expect(await card.count()).toBe(0);
578-
await page.waitForTimeout(300);
583+
await page.clock.runFor(449);
579584
expect(await card.count()).toBe(0);
585+
await page.clock.runFor(1);
580586
await card.waitFor({ state: "visible" });
581587
const firstBounds = await first.boundingBox();
582588
expect(firstBounds).not.toBeNull();
@@ -586,50 +592,64 @@ suite.define(() => {
586592
clientX: (firstBounds?.x ?? 0) + (firstBounds?.width ?? 0),
587593
clientY: (firstBounds?.y ?? 0) + (firstBounds?.height ?? 0) / 2,
588594
});
589-
await page.waitForTimeout(150);
595+
await page.clock.runFor(219);
590596
expect(await card.count()).toBe(1);
591597
await page.mouse.move(
592598
(cardBounds?.x ?? 0) + (cardBounds?.width ?? 0) / 2,
593599
(cardBounds?.y ?? 0) + (cardBounds?.height ?? 0) / 2,
594600
);
601+
await page.clock.runFor(1);
595602
expect(await card.count()).toBe(1);
596603
await page.mouse.move(900, 800);
597-
await page.waitForTimeout(50);
604+
await page.clock.runFor(99);
598605
expect(await card.count()).toBe(1);
599-
await expect.poll(() => card.count()).toBe(0);
600-
await page.waitForTimeout(300);
606+
await page.clock.runFor(1);
607+
expect(
608+
await card.evaluateAll((cards) =>
609+
cards.every((element) => element.getAttribute("data-open") === "false"),
610+
),
611+
).toBe(true);
612+
await page.clock.runFor(300);
613+
expect(await card.count()).toBe(0);
601614

602615
await first.hover();
603616
await first.locator("a.sidebar-recent-session__link").focus();
617+
await page.clock.runFor(1);
604618
await card.waitFor({ state: "visible" });
605619
await expect
606620
.poll(() => card.locator(".session-hovercard__title").textContent())
607621
.toBe("First timing row");
608622
await page.keyboard.press("Escape");
609623
await expect.poll(() => card.count()).toBe(0);
610624
await page.mouse.move(900, 800);
611-
await page.waitForTimeout(300);
625+
await page.clock.runFor(300);
612626

613627
await first.hover();
614628
expect(await card.count()).toBe(0);
629+
await page.clock.runFor(449);
630+
expect(await card.count()).toBe(0);
631+
await page.clock.runFor(1);
615632
await card.waitFor({ state: "visible" });
616633

617634
await second.hover();
618-
await page.waitForTimeout(40);
635+
await page.clock.runFor(79);
619636
expect(await card.locator(".session-hovercard__title").textContent()).toBe(
620637
"First timing row",
621638
);
622-
await expect
623-
.poll(() => card.locator(".session-hovercard__title").textContent())
624-
.toBe("Second timing row");
639+
await page.clock.runFor(1);
640+
expect(await card.locator(".session-hovercard__title").textContent()).toBe(
641+
"Second timing row",
642+
);
625643

626644
await card.hover();
627645
expect(await card.count()).toBe(1);
628646
await page.mouse.move(900, 800);
629-
await expect.poll(() => card.count()).toBe(0);
630-
await page.waitForTimeout(300);
647+
await page.clock.runFor(100);
648+
await page.clock.runFor(300);
649+
expect(await card.count()).toBe(0);
631650

632651
await first.hover();
652+
await page.clock.runFor(450);
633653
await card.waitFor({ state: "visible" });
634654
await first
635655
.getByRole("button", { name: "Open session menu: First timing row" })
@@ -639,7 +659,7 @@ suite.define(() => {
639659
.poll(() => page.locator("openclaw-session-menu").getByRole("menuitem").count())
640660
.toBeGreaterThan(0);
641661
await second.dispatchEvent("pointerover", { pointerType: "mouse" });
642-
await page.waitForTimeout(500);
662+
await page.clock.runFor(500);
643663
expect(await card.count()).toBe(0);
644664
},
645665
);

0 commit comments

Comments
 (0)