11// Control UI E2E tests cover slash command relevance and keyboard ordering.
22import path from "node:path" ;
3+ import { text } from "node:stream/consumers" ;
34import { expect , it } from "vitest" ;
45import { installMockGateway } from "../test-helpers/control-ui-e2e.ts" ;
56import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts" ;
@@ -9,6 +10,94 @@ const suite = createControlUiE2eSuite({
910} ) ;
1011
1112suite . define ( ( ) => {
13+ it . each ( [ "/export-session" , "/export" ] ) (
14+ "shows an empty export result and retains staged attachments for %s" ,
15+ async ( command ) => {
16+ const artifactDir = process . env . OPENCLAW_UI_E2E_ARTIFACT_DIR ?. trim ( ) ;
17+ await suite . withPage ( { viewport : { width : 1280 , height : 900 } } , async ( { page } ) => {
18+ const gateway = await installMockGateway ( page , { historyMessages : [ ] } ) ;
19+ const downloads : string [ ] = [ ] ;
20+ page . on ( "download" , ( download ) => downloads . push ( download . suggestedFilename ( ) ) ) ;
21+
22+ await page . goto ( `${ suite . server . baseUrl } chat` ) ;
23+ await gateway . waitForRequest ( "chat.startup" ) ;
24+ const composer = page . locator ( ".agent-chat__composer-combobox textarea" ) ;
25+ await composer . waitFor ( { state : "visible" } ) ;
26+ await page . locator ( ".agent-chat__file-input" ) . setInputFiles ( {
27+ name : "export-proof.txt" ,
28+ mimeType : "text/plain" ,
29+ buffer : Buffer . from ( "keep this staged" ) ,
30+ } ) ;
31+ const attachment = page . locator ( ".chat-attachment-file__name" , {
32+ hasText : "export-proof.txt" ,
33+ } ) ;
34+ await attachment . waitFor ( { state : "visible" } ) ;
35+
36+ await composer . fill ( command ) ;
37+ if ( artifactDir && command === "/export" ) {
38+ await page . screenshot ( {
39+ path : path . join ( artifactDir , "empty-export-before.png" ) ,
40+ fullPage : true ,
41+ } ) ;
42+ }
43+ await page . getByRole ( "button" , { name : "Send message" } ) . click ( ) ;
44+
45+ await page
46+ . locator ( ".chat-thread-inner" )
47+ . getByText ( "There are no messages to export yet." , { exact : true } )
48+ . waitFor ( { state : "visible" } ) ;
49+ if ( artifactDir && command === "/export" ) {
50+ await page . screenshot ( {
51+ path : path . join ( artifactDir , "empty-export-after.png" ) ,
52+ fullPage : true ,
53+ } ) ;
54+ }
55+ await expect . poll ( ( ) => composer . inputValue ( ) ) . toBe ( "" ) ;
56+ expect ( await attachment . isVisible ( ) ) . toBe ( true ) ;
57+ expect ( await gateway . getRequests ( "chat.send" ) ) . toHaveLength ( 0 ) ;
58+ expect ( downloads ) . toEqual ( [ ] ) ;
59+ } ) ;
60+ } ,
61+ ) ;
62+
63+ it ( "downloads a populated conversation as Markdown without sending a chat request" , async ( ) => {
64+ await suite . withPage ( { viewport : { width : 1280 , height : 900 } } , async ( { page } ) => {
65+ const question = "What can you export?" ;
66+ const answer = "A readable conversation." ;
67+ const gateway = await installMockGateway ( page , {
68+ historyMessages : [
69+ { role : "user" , content : question } ,
70+ { role : "assistant" , content : answer } ,
71+ ] ,
72+ } ) ;
73+
74+ await page . goto ( `${ suite . server . baseUrl } chat` ) ;
75+ await gateway . waitForRequest ( "chat.startup" ) ;
76+ await page . locator ( ".chat-thread-inner" ) . getByText ( answer , { exact : true } ) . waitFor ( {
77+ state : "visible" ,
78+ } ) ;
79+
80+ const composer = page . locator ( ".agent-chat__composer-combobox textarea" ) ;
81+ await composer . fill ( "/export" ) ;
82+ const downloadPromise = page . waitForEvent ( "download" ) ;
83+ await page . getByRole ( "button" , { name : "Send message" } ) . click ( ) ;
84+ const download = await downloadPromise ;
85+
86+ expect ( download . suggestedFilename ( ) ) . toMatch ( / ^ c h a t - O p e n C l a w - .+ \. m d $ / ) ;
87+ const stream = await download . createReadStream ( ) ;
88+ if ( ! stream ) {
89+ throw new Error ( "chat export did not provide a readable download" ) ;
90+ }
91+ const markdown = await text ( stream ) ;
92+ expect ( markdown ) . toContain ( "# Chat with OpenClaw" ) ;
93+ expect ( markdown ) . toContain ( "## You" ) ;
94+ expect ( markdown ) . toContain ( question ) ;
95+ expect ( markdown ) . toContain ( "## OpenClaw" ) ;
96+ expect ( markdown ) . toContain ( answer ) ;
97+ expect ( await gateway . getRequests ( "chat.send" ) ) . toHaveLength ( 0 ) ;
98+ } ) ;
99+ } ) ;
100+
12101 it ( "keeps visible search results and keyboard selection in relevance order" , async ( ) => {
13102 const artifactDir = process . env . OPENCLAW_UI_E2E_ARTIFACT_DIR ?. trim ( ) ;
14103 await suite . withPage (
0 commit comments