@@ -119,6 +119,13 @@ describe("WebChat message tool internal source reply", () => {
119119 const sourceReply = extractMessagingToolSourceReplyPayload ( toolResult ) ;
120120 expect ( sourceReply ) . toMatchObject ( { text : "Attached proof." } ) ;
121121 expect ( sourceReply ?. mediaUrls ) . toHaveLength ( 1 ) ;
122+ expect ( sourceReply ?. attachments ) . toEqual ( [
123+ expect . objectContaining ( {
124+ name : "proof.txt" ,
125+ mimeType : "text/plain" ,
126+ trustedLocalMedia : true ,
127+ } ) ,
128+ ] ) ;
122129 const mediaPath = sourceReply ?. mediaUrls ?. [ 0 ] ;
123130 expect ( mediaPath ) . toBeTruthy ( ) ;
124131 await expect ( fs . readFile ( mediaPath as string ) ) . resolves . toEqual ( attachment ) ;
@@ -147,7 +154,7 @@ describe("WebChat message tool internal source reply", () => {
147154 ) ;
148155 } ) ;
149156
150- it ( "publishes managed images with the current run owner" , async ( ) => {
157+ it ( "publishes managed media with aligned metadata and the current run owner" , async ( ) => {
151158 await withOpenClawTestState (
152159 { layout : "state-only" , prefix : "openclaw-internal-source-reply-" } ,
153160 async ( state ) => {
@@ -157,12 +164,14 @@ describe("WebChat message tool internal source reply", () => {
157164 const sessionKey = "agent:main:webchat:dm:restart-proof" ;
158165 const sessionId = "restart-proof-session" ;
159166 const imagePaths = [ "first.png" , "second.png" ] . map ( ( name ) => path . join ( workspaceDir , name ) ) ;
167+ const documentPath = path . join ( workspaceDir , "report.json" ) ;
160168 await fs . mkdir ( workspaceDir , { recursive : true } ) ;
161169 await Promise . all (
162170 imagePaths . map ( ( imagePath ) =>
163171 fs . writeFile ( imagePath , Buffer . from ( TINY_PNG_BASE64 , "base64" ) ) ,
164172 ) ,
165173 ) ;
174+ await fs . writeFile ( documentPath , '{"status":"ready"}\n' ) ;
166175
167176 await replaceSessionEntry (
168177 { agentId : "main" , sessionKey, storePath } ,
@@ -195,7 +204,7 @@ describe("WebChat message tool internal source reply", () => {
195204 const sendParams = {
196205 action : "send" as const ,
197206 message : "Durable image reply" ,
198- mediaUrls : imagePaths ,
207+ mediaUrls : [ ... imagePaths , documentPath ] ,
199208 } ;
200209 const updates : SessionTranscriptUpdate [ ] = [ ] ;
201210 const publishedDownloads : Array < Promise < unknown > > = [ ] ;
@@ -239,6 +248,18 @@ describe("WebChat message tool internal source reply", () => {
239248 reasoningLevel : "off" ,
240249 toolResultFormat : "plain" ,
241250 } ) ;
251+ expect ( sourcePayloads [ 0 ] ) . toMatchObject ( {
252+ attachments : [
253+ expect . objectContaining ( { name : "first.png" , trustedLocalMedia : true } ) ,
254+ expect . objectContaining ( { name : "second.png" , trustedLocalMedia : true } ) ,
255+ expect . objectContaining ( {
256+ name : "report.json" ,
257+ mimeType : "application/json" ,
258+ trustedLocalMedia : true ,
259+ } ) ,
260+ ] ,
261+ trustedLocalMedia : true ,
262+ } ) ;
242263 const mirror = getReplyPayloadMetadata (
243264 sourcePayloads [ 0 ] as object ,
244265 ) ?. sourceReplyTranscriptMirror ;
@@ -262,6 +283,7 @@ describe("WebChat message tool internal source reply", () => {
262283 ? ( assistant . content as Array < Record < string , unknown > > )
263284 : [ ] ;
264285 const image = content . find ( ( block ) => block . type === "image" ) ;
286+ const document = content . find ( ( block ) => block . type === "attachment" ) ;
265287 expect ( toolResult . details ) . toMatchObject ( {
266288 sourceReplySink : "internal-ui" ,
267289 idempotencyKey : expect . any ( String ) ,
@@ -272,8 +294,17 @@ describe("WebChat message tool internal source reply", () => {
272294 artifactId : expect . stringMatching ( / ^ a r t i f a c t _ m a n a g e d _ i m a g e _ / u) ,
273295 } ) ;
274296 expect ( content . filter ( ( block ) => block . type === "image" ) ) . toHaveLength ( 2 ) ;
297+ expect ( document ) . toMatchObject ( {
298+ type : "attachment" ,
299+ attachment : {
300+ artifactId : expect . stringMatching ( / ^ a r t i f a c t _ m a n a g e d _ m e d i a _ / u) ,
301+ kind : "document" ,
302+ label : "report.json" ,
303+ mimeType : "application/json" ,
304+ } ,
305+ } ) ;
275306 expect ( JSON . stringify ( assistant ) ) . not . toContain ( workspaceDir ) ;
276- expect ( listManagedImageRecordEntries ( { stateDir, sessionKey } ) ) . toHaveLength ( 2 ) ;
307+ expect ( listManagedImageRecordEntries ( { stateDir, sessionKey } ) ) . toHaveLength ( 3 ) ;
277308 const published = updates . find (
278309 ( update ) =>
279310 update . runId === "restart-proof-run" &&
@@ -303,6 +334,15 @@ describe("WebChat message tool internal source reply", () => {
303334 } ) ,
304335 ) . resolves . toMatchObject ( { type : "image" } ) ;
305336 }
337+ const documentAttachment = document ?. attachment as { artifactId ?: unknown } | undefined ;
338+ await expect (
339+ resolveManagedOutgoingMediaArtifactDownload ( {
340+ sessionKey,
341+ agentId : "main" ,
342+ artifactId : String ( documentAttachment ?. artifactId ) ,
343+ stateDir,
344+ } ) ,
345+ ) . resolves . toMatchObject ( { type : "file" , title : "report.json" } ) ;
306346 } ,
307347 ) ;
308348 } ) ;
0 commit comments