@@ -89,4 +89,80 @@ describe("googlechatPlugin outbound sendMedia", () => {
8989 chatId : "spaces/AAA" ,
9090 } ) ;
9191 } ) ;
92+
93+ it ( "keeps remote URL media fetch on fetchRemoteMedia with maxBytes cap" , async ( ) => {
94+ const loadWebMedia = vi . fn ( async ( ) => ( {
95+ buffer : Buffer . from ( "should-not-be-used" ) ,
96+ fileName : "unused.png" ,
97+ contentType : "image/png" ,
98+ } ) ) ;
99+ const fetchRemoteMedia = vi . fn ( async ( ) => ( {
100+ buffer : Buffer . from ( "remote-bytes" ) ,
101+ fileName : "remote.png" ,
102+ contentType : "image/png" ,
103+ } ) ) ;
104+
105+ setGoogleChatRuntime ( {
106+ media : { loadWebMedia } ,
107+ channel : {
108+ media : { fetchRemoteMedia } ,
109+ text : { chunkMarkdownText : ( text : string ) => [ text ] } ,
110+ } ,
111+ } as unknown as PluginRuntime ) ;
112+
113+ uploadGoogleChatAttachmentMock . mockResolvedValue ( {
114+ attachmentUploadToken : "token-2" ,
115+ } ) ;
116+ sendGoogleChatMessageMock . mockResolvedValue ( {
117+ messageName : "spaces/AAA/messages/msg-2" ,
118+ } ) ;
119+
120+ const cfg : OpenClawConfig = {
121+ channels : {
122+ googlechat : {
123+ enabled : true ,
124+ serviceAccount : {
125+ type : "service_account" ,
126+ client_email : "bot@example.com" ,
127+ private_key : "test-key" ,
128+ token_uri : "https://oauth2.googleapis.com/token" ,
129+ } ,
130+ } ,
131+ } ,
132+ } ;
133+
134+ const result = await googlechatPlugin . outbound ?. sendMedia ?.( {
135+ cfg,
136+ to : "spaces/AAA" ,
137+ text : "caption" ,
138+ mediaUrl : "https://example.com/image.png" ,
139+ accountId : "default" ,
140+ } ) ;
141+
142+ expect ( fetchRemoteMedia ) . toHaveBeenCalledWith (
143+ expect . objectContaining ( {
144+ url : "https://example.com/image.png" ,
145+ maxBytes : 20 * 1024 * 1024 ,
146+ } ) ,
147+ ) ;
148+ expect ( loadWebMedia ) . not . toHaveBeenCalled ( ) ;
149+ expect ( uploadGoogleChatAttachmentMock ) . toHaveBeenCalledWith (
150+ expect . objectContaining ( {
151+ space : "spaces/AAA" ,
152+ filename : "remote.png" ,
153+ contentType : "image/png" ,
154+ } ) ,
155+ ) ;
156+ expect ( sendGoogleChatMessageMock ) . toHaveBeenCalledWith (
157+ expect . objectContaining ( {
158+ space : "spaces/AAA" ,
159+ text : "caption" ,
160+ } ) ,
161+ ) ;
162+ expect ( result ) . toEqual ( {
163+ channel : "googlechat" ,
164+ messageId : "spaces/AAA/messages/msg-2" ,
165+ chatId : "spaces/AAA" ,
166+ } ) ;
167+ } ) ;
92168} ) ;
0 commit comments