@@ -1033,6 +1033,89 @@ describe("runCliAgent reliability", () => {
10331033 expect ( supervisorSpawnMock ) . toHaveBeenCalledTimes ( 1 ) ;
10341034 } ) ;
10351035
1036+ it ( "projects explicit outbound MCP media without retaining echoed image bytes" , async ( ) => {
1037+ const echoedBase64 = "private-echoed-base64" ;
1038+ const mediaUrls = [
1039+ "https://example.test/one.png" ,
1040+ "https://example.test/two.png" ,
1041+ "https://example.test/three.png" ,
1042+ ] ;
1043+ supervisorSpawnMock . mockImplementationOnce ( async ( ...args : unknown [ ] ) => {
1044+ const input = args [ 0 ] as Parameters < ReturnType < typeof getProcessSupervisor > [ "spawn" ] > [ 0 ] ;
1045+ const captureKey = input . env ?. OPENCLAW_MCP_CLI_CAPTURE_KEY ?? "" ;
1046+ for ( const [ index , mediaUrl ] of mediaUrls . entries ( ) ) {
1047+ const captureHandle = markMcpLoopbackToolCallStarted ( {
1048+ captureKey,
1049+ toolName : "image_generate" ,
1050+ args : { prompt : `image ${ index + 1 } ` } ,
1051+ } ) ;
1052+ if ( ! captureHandle ) {
1053+ throw new Error ( "Expected outbound media capture" ) ;
1054+ }
1055+ recordMcpLoopbackToolCallResult ( {
1056+ captureHandle,
1057+ toolName : "image_generate" ,
1058+ args : { prompt : `image ${ index + 1 } ` } ,
1059+ result : {
1060+ content : [
1061+ {
1062+ type : "image" ,
1063+ data : echoedBase64 ,
1064+ mimeType : "image/png" ,
1065+ } ,
1066+ ] ,
1067+ details : { media : { mediaUrls : [ mediaUrl ] } } ,
1068+ } ,
1069+ outcome : "completed" ,
1070+ } ) ;
1071+ markMcpLoopbackToolCallFinished ( captureHandle ) ;
1072+ }
1073+ for ( const [ toolName , media ] of [
1074+ [ "image" , { mediaUrls : [ "/tmp/private.png" ] , outbound : false } ] ,
1075+ [ "untrusted_tool" , { mediaUrls : [ "/tmp/untrusted.png" ] } ] ,
1076+ ] as const ) {
1077+ const captureHandle = markMcpLoopbackToolCallStarted ( {
1078+ captureKey,
1079+ toolName,
1080+ args : { } ,
1081+ } ) ;
1082+ if ( ! captureHandle ) {
1083+ throw new Error ( "Expected private media capture" ) ;
1084+ }
1085+ recordMcpLoopbackToolCallResult ( {
1086+ captureHandle,
1087+ toolName,
1088+ args : { } ,
1089+ result : {
1090+ content : [ { type : "image" , data : echoedBase64 , mimeType : "image/png" } ] ,
1091+ details : { media } ,
1092+ } ,
1093+ outcome : "completed" ,
1094+ } ) ;
1095+ markMcpLoopbackToolCallFinished ( captureHandle ) ;
1096+ }
1097+ return makeManagedRun ( { stdout : "done" } ) ;
1098+ } ) ;
1099+ const context = makeClaudePreparedContext ( {
1100+ sessionKey : "agent:main:outbound-media" ,
1101+ runId : "run-outbound-media" ,
1102+ } ) ;
1103+ context . mcpDeliveryCapture = true ;
1104+
1105+ const result = await runPreparedCliAgent ( context ) ;
1106+
1107+ expect ( result . payloads ) . toEqual ( [
1108+ {
1109+ text : "done" ,
1110+ mediaUrls,
1111+ mediaUrl : mediaUrls [ 0 ] ,
1112+ } ,
1113+ ] ) ;
1114+ expect ( JSON . stringify ( result ) ) . not . toContain ( echoedBase64 ) ;
1115+ expect ( JSON . stringify ( result ) ) . not . toContain ( "/tmp/private.png" ) ;
1116+ expect ( JSON . stringify ( result ) ) . not . toContain ( "/tmp/untrusted.png" ) ;
1117+ } ) ;
1118+
10361119 it ( "surfaces a CLI failure after a delivered progress reply" , async ( ) => {
10371120 supervisorSpawnMock . mockClear ( ) ;
10381121 supervisorSpawnMock . mockImplementationOnce ( async ( ...args : unknown [ ] ) => {
@@ -3077,6 +3160,7 @@ describe("runCliAgent reliability", () => {
30773160 expect ( result . payloads ) . toEqual ( [ { text : "hello from cli" } ] ) ;
30783161 expect ( getReplyPayloadMetadata ( result . payloads ?. [ 0 ] ?? { } ) ) . toMatchObject ( {
30793162 assistantTranscriptOwned : true ,
3163+ assistantTranscriptIdempotencyKey : "cli-assistant:run-persist-cli" ,
30803164 } ) ;
30813165 expect ( onUserMessagePersisted ) . toHaveBeenCalledOnce ( ) ;
30823166 expect ( onUserMessagePersisted ) . toHaveBeenCalledWith (
0 commit comments