@@ -199,6 +199,86 @@ func TestExecute_GmailMessagesSearch_JSON_IncludeBody(t *testing.T) {
199199 }
200200}
201201
202+ func TestExecute_GmailMessagesSearch_Text_IncludeBodyTruncationDiscoverable (t * testing.T ) {
203+ longBody := strings .Repeat ("b" , 240 )
204+ srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
205+ path := r .URL .Path
206+ switch {
207+ case strings .Contains (path , "/users/me/messages" ) && ! strings .Contains (path , "/users/me/messages/" ):
208+ w .Header ().Set ("Content-Type" , "application/json" )
209+ _ = json .NewEncoder (w ).Encode (map [string ]any {
210+ "messages" : []map [string ]any {
211+ {"id" : "m1" , "threadId" : "t1" },
212+ },
213+ })
214+ return
215+ case strings .Contains (path , "/users/me/messages/m1" ):
216+ w .Header ().Set ("Content-Type" , "application/json" )
217+ _ = json .NewEncoder (w ).Encode (map [string ]any {
218+ "id" : "m1" ,
219+ "threadId" : "t1" ,
220+ "labelIds" : []string {"INBOX" },
221+ "payload" : map [string ]any {
222+ "mimeType" : "text/plain" ,
223+ "headers" : []map [string ]any {
224+ {"name" : "From" , "value" : "Example <no-reply@example.com>" },
225+ {"name" : "Subject" , "value" : "Receipt" },
226+ {"name" : "Date" , "value" : "Mon, 02 Jan 2006 15:04:05 -0700" },
227+ },
228+ "body" : map [string ]any {
229+ "data" : encodeBase64URL (longBody ),
230+ },
231+ },
232+ })
233+ return
234+ case strings .Contains (path , "/users/me/labels" ):
235+ w .Header ().Set ("Content-Type" , "application/json" )
236+ _ = json .NewEncoder (w ).Encode (map [string ]any {
237+ "labels" : []map [string ]any {
238+ {"id" : "INBOX" , "name" : "INBOX" , "type" : "system" },
239+ },
240+ })
241+ return
242+ default :
243+ http .NotFound (w , r )
244+ return
245+ }
246+ }))
247+ defer srv .Close ()
248+
249+ svc := newGmailServiceFromServer (t , srv )
250+
251+ defaultResult := executeWithGmailTestService (
252+ t ,
253+ []string {"--plain" , "--account" , "a@b.com" , "gmail" , "messages" , "search" , "from:example.com" , "--include-body" },
254+ svc ,
255+ )
256+ if defaultResult .err != nil {
257+ t .Fatalf ("Execute: %v\n stderr=%q" , defaultResult .err , defaultResult .stderr )
258+ }
259+ if ! strings .Contains (defaultResult .stdout , strings .Repeat ("b" , 200 )+ gmailTextTruncationMarker ) {
260+ t .Fatalf ("expected actionable truncation marker, got: %q" , defaultResult .stdout )
261+ }
262+ if strings .Contains (defaultResult .stdout , longBody ) {
263+ t .Fatalf ("expected body to be truncated, got: %q" , defaultResult .stdout )
264+ }
265+
266+ fullResult := executeWithGmailTestService (
267+ t ,
268+ []string {"--plain" , "--account" , "a@b.com" , "gmail" , "messages" , "search" , "from:example.com" , "--full" },
269+ svc ,
270+ )
271+ if fullResult .err != nil {
272+ t .Fatalf ("Execute full: %v\n stderr=%q" , fullResult .err , fullResult .stderr )
273+ }
274+ if strings .Contains (fullResult .stdout , "[truncated" ) {
275+ t .Fatalf ("expected full output without truncation marker, got: %q" , fullResult .stdout )
276+ }
277+ if ! strings .Contains (fullResult .stdout , longBody ) {
278+ t .Fatalf ("expected full body, got: %q" , fullResult .stdout )
279+ }
280+ }
281+
202282func TestExecute_GmailMessagesSearch_AppliesSystemLabelFilters (t * testing.T ) {
203283 var gotQuery string
204284 var gotLabels []string
0 commit comments