@@ -194,6 +194,67 @@ export async function pastePng(target: Locator, count = 1) {
194194 ) ;
195195}
196196
197+ export async function waitForPersistedNewSessionDraft (
198+ page : Page ,
199+ expectedText : string | null ,
200+ expectedAttachmentCount : number ,
201+ ) : Promise < void > {
202+ // Filling only proves DOM state. The durable read waits for the IndexedDB
203+ // transaction so reload or navigation cannot beat the snapshot write.
204+ await page . waitForFunction (
205+ async ( { text, attachmentCount } ) => {
206+ try {
207+ const app = document . querySelector ( "openclaw-app" ) as HTMLElement & {
208+ runtime ?: {
209+ context : {
210+ gateway : {
211+ connection : { gatewayUrl : string } ;
212+ snapshot : { client : { recoveryScope ?: string } | null } ;
213+ } ;
214+ } ;
215+ } ;
216+ } ;
217+ const gateway = app . runtime ?. context . gateway ;
218+ const recoveryScope = gateway ?. snapshot . client ?. recoveryScope ;
219+ if ( ! gateway || ! recoveryScope ) {
220+ return false ;
221+ }
222+ const storeUrl = performance
223+ . getEntriesByType ( "resource" )
224+ . map ( ( entry ) => entry . name )
225+ . find ( ( name ) => / \/ c o m p o s e r - d r a f t - s t o r e \. r u n t i m e - [ ^ / ] + \. j s $ / u. test ( name ) ) ;
226+ if ( ! storeUrl ) {
227+ return false ;
228+ }
229+ const draftStore = ( await import (
230+ /* @vite -ignore */ storeUrl
231+ ) ) as typeof import ( "../lib/chat/composer-draft-store.runtime.ts" ) ;
232+ const params = new URLSearchParams ( window . location . search ) ;
233+ const result = await draftStore . readDurableComposerDraft ( {
234+ gatewayOwner : gateway . connection . gatewayUrl . trim ( ) || "default" ,
235+ recoveryScope,
236+ scopeKey : JSON . stringify ( [
237+ params . get ( "agent" ) ?. trim ( ) ?? "" ,
238+ params . get ( "catalog" ) ?. trim ( ) ?? "" ,
239+ params . get ( "group" ) ?. trim ( ) ?? "" ,
240+ ] ) ,
241+ } ) ;
242+ if ( text === null ) {
243+ return result . status === "not-found" && result . revision !== undefined ;
244+ }
245+ return (
246+ result . status === "found" &&
247+ result . draft . text === text &&
248+ result . draft . attachments . length === attachmentCount
249+ ) ;
250+ } catch {
251+ return false ;
252+ }
253+ } ,
254+ { text : expectedText , attachmentCount : expectedAttachmentCount } ,
255+ ) ;
256+ }
257+
197258export async function replaceGatewayClient ( page : Page ) {
198259 await page . evaluate ( ( ) => {
199260 const app = document . querySelector ( "openclaw-app" ) as HTMLElement & {
0 commit comments