@@ -61,6 +61,59 @@ describe("resolveCurrentTurnImages", () => {
6161 } ) ;
6262 } ) ;
6363
64+ it ( "preserves the full order when only inline image payloads are present" , async ( ) => {
65+ const inlineImage = {
66+ type : "image" as const ,
67+ data : Buffer . from ( "inline" ) . toString ( "base64" ) ,
68+ mimeType : "image/png" ,
69+ } ;
70+
71+ const result = await resolveCurrentTurnImages ( {
72+ ctx : { Body : "compare these" } satisfies MsgContext ,
73+ cfg : { } as OpenClawConfig ,
74+ images : [ inlineImage ] ,
75+ imageOrder : [ "offloaded" , "inline" , "offloaded" ] ,
76+ } ) ;
77+
78+ expect ( result ) . toEqual ( {
79+ images : [ inlineImage ] ,
80+ imageOrder : [ "offloaded" , "inline" , "offloaded" ] ,
81+ } ) ;
82+ } ) ;
83+
84+ it ( "preserves all-offloaded image order without inline payloads" , async ( ) => {
85+ const result = await resolveCurrentTurnImages ( {
86+ ctx : { Body : "compare these" } satisfies MsgContext ,
87+ cfg : { } as OpenClawConfig ,
88+ images : [ ] ,
89+ imageOrder : [ "offloaded" , "offloaded" ] ,
90+ } ) ;
91+
92+ expect ( result ) . toEqual ( {
93+ imageOrder : [ "offloaded" , "offloaded" ] ,
94+ } ) ;
95+ } ) ;
96+
97+ it ( "preserves interleaved offloaded slots around inline image payloads" , async ( ) => {
98+ const inlineImages = [ "first" , "second" ] . map ( ( data ) => ( {
99+ type : "image" as const ,
100+ data : Buffer . from ( data ) . toString ( "base64" ) ,
101+ mimeType : "image/png" ,
102+ } ) ) ;
103+
104+ const result = await resolveCurrentTurnImages ( {
105+ ctx : { Body : "compare these" } satisfies MsgContext ,
106+ cfg : { } as OpenClawConfig ,
107+ images : inlineImages ,
108+ imageOrder : [ "inline" , "offloaded" , "inline" ] ,
109+ } ) ;
110+
111+ expect ( result ) . toEqual ( {
112+ images : inlineImages ,
113+ imageOrder : [ "inline" , "offloaded" , "inline" ] ,
114+ } ) ;
115+ } ) ;
116+
64117 it ( "appends extracted PDF page images without dropping current image attachments" , async ( ) => {
65118 await withTempDir ( { prefix : "openclaw-current-turn-pdf-images-" } , async ( base ) => {
66119 const imagePath = path . join ( base , "photo.png" ) ;
0 commit comments