@@ -48,6 +48,40 @@ describe("buildEmbeddedRunPayloads tool-error warnings", () => {
4848 expectSinglePayloadText ( payloads , "Scan complete. No new actionable inbox items." ) ;
4949 } ) ;
5050
51+ it ( "suppresses streamed text that only contains hidden reasoning" , ( ) => {
52+ const payloads = buildPayloads ( {
53+ assistantTexts : [ "<mm:think>private reasoning</mm:think>" ] ,
54+ } ) ;
55+
56+ expect ( payloads ) . toStrictEqual ( [ ] ) ;
57+ } ) ;
58+
59+ it ( "sanitizes every streamed text while preserving multiple visible answers" , ( ) => {
60+ const payloads = buildPayloads ( {
61+ assistantTexts : [
62+ '<tool_call>{"name":"exec","arguments":{"command":"secret"}}</tool_call>' ,
63+ "</mm:think>First visible answer." ,
64+ "Second visible answer." ,
65+ ] ,
66+ } ) ;
67+
68+ expect ( payloads . map ( ( payload ) => payload . text ) ) . toStrictEqual ( [
69+ "First visible answer." ,
70+ "Second visible answer." ,
71+ ] ) ;
72+ } ) ;
73+
74+ it ( "keeps media directives while sanitizing streamed assistant text" , ( ) => {
75+ const payloads = buildPayloads ( {
76+ assistantTexts : [ "</mm:think>MEDIA:/tmp/reply-image.png\nAttached image" ] ,
77+ } ) ;
78+
79+ expect ( payloads ) . toHaveLength ( 1 ) ;
80+ expect ( payloads [ 0 ] ?. text ) . toBe ( "Attached image" ) ;
81+ expect ( payloads [ 0 ] ?. mediaUrl ) . toBe ( "/tmp/reply-image.png" ) ;
82+ expect ( payloads [ 0 ] ?. mediaUrls ) . toEqual ( [ "/tmp/reply-image.png" ] ) ;
83+ } ) ;
84+
5185 it ( "falls back to final-answer assistant text when streamed text is unavailable" , ( ) => {
5286 const payloads = buildPayloads ( {
5387 lastAssistant : {
0 commit comments