11import { mkdir } from "node:fs/promises" ;
22import path from "node:path" ;
3+ import { MAX_DATE_TIMESTAMP_MS } from "@openclaw/normalization-core/number-coercion" ;
34import type { Page } from "playwright" ;
45import { expect , it } from "vitest" ;
56import {
@@ -35,6 +36,7 @@ const suite = createChatFlowE2eSuite();
3536suite . define ( ( ) => {
3637 it ( "keeps one live card placement and a compact transcript receipt" , async ( ) => {
3738 const sessionKey = "agent:main:progress-placement" ;
39+ const updatedAt = Date . now ( ) - 5 * 60_000 ;
3840 const plan = [
3941 { step : "Inspect" , status : "completed" } ,
4042 { step : "Implement" , status : "in_progress" } ,
@@ -79,15 +81,15 @@ suite.define(() => {
7981 revision : 2 ,
8082 sessionKey,
8183 steps : plan ,
82- updatedAt : 2 ,
84+ updatedAt,
8385 } ,
8486 } ,
8587 "sessions.list" : chatSessionListResponse ( [
8688 {
8789 key : sessionKey ,
8890 kind : "direct" ,
8991 label : "Progress placement" ,
90- updatedAt : 2 ,
92+ updatedAt,
9193 } ,
9294 ] ) ,
9395 } ,
@@ -98,6 +100,28 @@ suite.define(() => {
98100 await expect . poll ( ( ) => gateway . getRequests ( "progressCard.get" ) ) . toHaveLength ( 1 ) ;
99101
100102 const visiblePane = page . locator ( "openclaw-chat-pane.chat-pane-cache__pane--visible" ) ;
103+ const expectVisibleLastActivity = async ( placement : "composer" | "dock" | "rail" ) => {
104+ const card = visiblePane . locator ( `[data-progress-card-placement="${ placement } "]` ) ;
105+ const timestamp = card . locator ( "time" ) ;
106+ await expect
107+ . poll ( ( ) => timestamp . getAttribute ( "datetime" ) )
108+ . toBe ( new Date ( updatedAt ) . toISOString ( ) ) ;
109+ await expect . poll ( ( ) => timestamp . getAttribute ( "aria-label" ) ) . toMatch ( / ^ L a s t a c t i v i t y : / ) ;
110+ await expect . poll ( ( ) => timestamp . textContent ( ) ) . toMatch ( / \d { 1 , 2 } : \d { 2 } : \d { 2 } / ) ;
111+ await expect . poll ( ( ) => timestamp . isVisible ( ) ) . toBe ( true ) ;
112+ const accessibleCard = placement === "composer" ? card . locator ( "summary" ) : card ;
113+ await expect
114+ . poll ( ( ) => accessibleCard . getAttribute ( "aria-label" ) )
115+ . toContain ( "Last activity:" ) ;
116+ const timestampBounds = await timestamp . boundingBox ( ) ;
117+ const cardBounds = await card . boundingBox ( ) ;
118+ if ( ! timestampBounds || ! cardBounds ) {
119+ throw new Error ( "The progress card and last activity time must both remain visible" ) ;
120+ }
121+ expect ( timestampBounds . x + timestampBounds . width ) . toBeLessThanOrEqual (
122+ cardBounds . x + cardBounds . width ,
123+ ) ;
124+ } ;
101125 // Wide enough for the composer gutter to hold the card: it docks beside
102126 // the composer instead of stacking inside it.
103127 await page . setViewportSize ( { height : 900 , width : 1600 } ) ;
@@ -123,6 +147,7 @@ suite.define(() => {
123147 ) ;
124148 } )
125149 . toBe ( true ) ;
150+ await expectVisibleLastActivity ( "dock" ) ;
126151 await captureProof ( page , "dock-beside-composer.png" ) ;
127152
128153 await page . setViewportSize ( { height : 900 , width : 1280 } ) ;
@@ -143,6 +168,7 @@ suite.define(() => {
143168 await expect
144169 . poll ( ( ) => visiblePane . locator ( ".chat-thread" ) . textContent ( ) )
145170 . not . toContain ( "Implementation is moving." ) ;
171+ await expectVisibleLastActivity ( "rail" ) ;
146172 await captureProof ( page , "rail-visible.png" ) ;
147173
148174 await page . setViewportSize ( { height : 900 , width : 560 } ) ;
@@ -161,6 +187,7 @@ suite.define(() => {
161187 await expect
162188 . poll ( ( ) => visiblePane . locator ( '[data-progress-card-placement="composer"]' ) . isVisible ( ) )
163189 . toBe ( true ) ;
190+ await expectVisibleLastActivity ( "composer" ) ;
164191 await captureProof ( page , "composer-adjacent.png" ) ;
165192 } ,
166193 ) ;
@@ -237,8 +264,25 @@ suite.define(() => {
237264 await expectMarkerCentered ( ) ;
238265 await captureProof ( page , `completed-${ colorScheme } -before.png` ) ;
239266
267+ await gateway . setMethodResponse ( "progressCard.put" , {
268+ card : {
269+ revision : 4 ,
270+ sessionKey,
271+ steps : plan ,
272+ updatedAt : MAX_DATE_TIMESTAMP_MS + 1 ,
273+ } ,
274+ } ) ;
275+ await card . getByRole ( "button" , { name : "Dismiss progress card" } ) . click ( ) ;
276+ await expect . poll ( ( ) => gateway . getRequests ( "progressCard.put" ) ) . toHaveLength ( 1 ) ;
277+ await page . getByText ( "Could not dismiss the progress card. Try again." ) . waitFor ( ) ;
278+ await expect . poll ( ( ) => card . isVisible ( ) ) . toBe ( true ) ;
279+ await expect
280+ . poll ( ( ) => card . locator ( "time" ) . getAttribute ( "datetime" ) )
281+ . toBe ( new Date ( 3 ) . toISOString ( ) ) ;
282+
283+ await gateway . setMethodResponse ( "progressCard.put" , { card : null } ) ;
240284 await card . getByRole ( "button" , { name : "Dismiss progress card" } ) . click ( ) ;
241- const dismissRequest = await gateway . waitForRequest ( "progressCard.put" ) ;
285+ const dismissRequest = await gateway . waitForRequest ( "progressCard.put" , { after : 1 } ) ;
242286 expect ( dismissRequest . params ) . toEqual ( { sessionKey, expectedRevision : 3 } ) ;
243287 await expect . poll ( ( ) => card . count ( ) ) . toBe ( 0 ) ;
244288
0 commit comments