@@ -960,7 +960,7 @@ describe("feishuPlugin actions", () => {
960960 ] ) ;
961961 } ) ;
962962
963- it ( "sends media through the outbound adapter" , async ( ) => {
963+ it ( "sends core-normalized media through the outbound adapter" , async ( ) => {
964964 feishuOutboundSendMediaMock . mockResolvedValueOnce ( {
965965 channel : "feishu" ,
966966 messageId : "om_media" ,
@@ -973,6 +973,9 @@ describe("feishuPlugin actions", () => {
973973 to : "chat:oc_group_1" ,
974974 message : "test" ,
975975 media : "/tmp/image.png" ,
976+ mediaUrl : "/tmp/image.png" ,
977+ mediaUrls : [ "/tmp/image.png" ] ,
978+ attachments : [ { media : "/tmp/image.png" } ] ,
976979 } ,
977980 cfg,
978981 accountId : undefined ,
@@ -992,6 +995,159 @@ describe("feishuPlugin actions", () => {
992995 expect ( resultDetails ( result ) . messageId ) . toBe ( "om_media" ) ;
993996 } ) ;
994997
998+ it . each ( [
999+ [ "attachment" , { path : "/tmp/script.py" } ] ,
1000+ [ "file" , "/tmp/script.py" ] ,
1001+ ] as const ) ( "rejects unsupported Feishu attachment param %s" , async ( key , value ) => {
1002+ await expect (
1003+ feishuPlugin . actions ?. handleAction ?.( {
1004+ action : "send" ,
1005+ params : {
1006+ to : "chat:oc_group_1" ,
1007+ message : "see attached" ,
1008+ [ key ] : value ,
1009+ } ,
1010+ cfg,
1011+ accountId : undefined ,
1012+ toolContext : { } ,
1013+ mediaLocalRoots : [ "/tmp" ] ,
1014+ } as never ) ,
1015+ ) . rejects . toThrow (
1016+ `Feishu send supports media attachments through the media parameter; ${ key } is not supported.` ,
1017+ ) ;
1018+
1019+ expect ( sendMessageFeishuMock ) . not . toHaveBeenCalled ( ) ;
1020+ expect ( sendCardFeishuMock ) . not . toHaveBeenCalled ( ) ;
1021+ expect ( feishuOutboundSendMediaMock ) . not . toHaveBeenCalled ( ) ;
1022+ } ) ;
1023+
1024+ // Core resolves its own alias chain into `media` before dispatch, so Feishu must not
1025+ // reject the aliases themselves; doing so regressed previously working sends.
1026+ it . each ( [
1027+ [ "path" , "/tmp/script.py" ] ,
1028+ [ "filePath" , "/tmp/script.py" ] ,
1029+ [ "fileUrl" , "file:///tmp/script.py" ] ,
1030+ [ "image" , "/tmp/script.py" ] ,
1031+ [ "mediaUrl" , "/tmp/script.py" ] ,
1032+ ] as const ) (
1033+ "accepts core-canonical media alias %s alongside normalized media" ,
1034+ async ( key , value ) => {
1035+ feishuOutboundSendMediaMock . mockResolvedValueOnce ( {
1036+ channel : "feishu" ,
1037+ messageId : "om_media" ,
1038+ chatId : "oc_group_1" ,
1039+ } ) ;
1040+
1041+ await feishuPlugin . actions ?. handleAction ?.( {
1042+ action : "send" ,
1043+ params : {
1044+ to : "chat:oc_group_1" ,
1045+ message : "see attached" ,
1046+ media : "/tmp/script.py" ,
1047+ [ key ] : value ,
1048+ } ,
1049+ cfg,
1050+ accountId : undefined ,
1051+ toolContext : { } ,
1052+ mediaLocalRoots : [ "/tmp" ] ,
1053+ } as never ) ;
1054+
1055+ expect ( feishuOutboundSendMediaMock ) . toHaveBeenCalledOnce ( ) ;
1056+ expect ( sendMessageFeishuMock ) . not . toHaveBeenCalled ( ) ;
1057+ } ,
1058+ ) ;
1059+
1060+ it ( "rejects multiple media attachments rather than dropping all but the first" , async ( ) => {
1061+ await expect (
1062+ feishuPlugin . actions ?. handleAction ?.( {
1063+ action : "send" ,
1064+ params : {
1065+ to : "chat:oc_group_1" ,
1066+ message : "see attached" ,
1067+ media : "/tmp/first.py" ,
1068+ mediaUrls : [ "/tmp/first.py" , "/tmp/second.py" ] ,
1069+ } ,
1070+ cfg,
1071+ accountId : undefined ,
1072+ toolContext : { } ,
1073+ mediaLocalRoots : [ "/tmp" ] ,
1074+ } as never ) ,
1075+ ) . rejects . toThrow ( "Feishu send supports a single media attachment." ) ;
1076+
1077+ expect ( feishuOutboundSendMediaMock ) . not . toHaveBeenCalled ( ) ;
1078+ } ) ;
1079+
1080+ it ( "rejects media on thread replies instead of delivering text only" , async ( ) => {
1081+ await expect (
1082+ feishuPlugin . actions ?. handleAction ?.( {
1083+ action : "thread-reply" ,
1084+ params : {
1085+ to : "chat:oc_group_1" ,
1086+ messageId : "om_parent" ,
1087+ message : "see attached" ,
1088+ attachments : [ { media : "/tmp/script.py" } ] ,
1089+ } ,
1090+ cfg,
1091+ accountId : undefined ,
1092+ toolContext : { } ,
1093+ mediaLocalRoots : [ "/tmp" ] ,
1094+ } as never ) ,
1095+ ) . rejects . toThrow (
1096+ "Feishu thread-reply does not support media attachments; attachments is not supported." ,
1097+ ) ;
1098+
1099+ expect ( sendMessageFeishuMock ) . not . toHaveBeenCalled ( ) ;
1100+ expect ( feishuOutboundSendMediaMock ) . not . toHaveBeenCalled ( ) ;
1101+ } ) ;
1102+
1103+ it ( "ignores empty optional attachment defaults" , async ( ) => {
1104+ sendMessageFeishuMock . mockResolvedValueOnce ( { messageId : "om_sent" , chatId : "oc_group_1" } ) ;
1105+
1106+ await feishuPlugin . actions ?. handleAction ?.( {
1107+ action : "send" ,
1108+ params : {
1109+ to : "chat:oc_group_1" ,
1110+ message : "hello" ,
1111+ attachment : { } ,
1112+ attachments : [ ] ,
1113+ buffer : "" ,
1114+ file : null ,
1115+ filename : "" ,
1116+ mediaUrls : [ ] ,
1117+ } ,
1118+ cfg,
1119+ accountId : undefined ,
1120+ toolContext : { } ,
1121+ } as never ) ;
1122+
1123+ expect ( sendMessageFeishuMock ) . toHaveBeenCalledOnce ( ) ;
1124+ expect ( feishuOutboundSendMediaMock ) . not . toHaveBeenCalled ( ) ;
1125+ } ) ;
1126+
1127+ it . each ( [
1128+ [ "blank string" , " " ] ,
1129+ [ "object" , { path : "/tmp/script.py" } ] ,
1130+ ] as const ) ( "rejects invalid Feishu media param %s" , async ( _name , media ) => {
1131+ await expect (
1132+ feishuPlugin . actions ?. handleAction ?.( {
1133+ action : "send" ,
1134+ params : {
1135+ to : "chat:oc_group_1" ,
1136+ message : "see attached" ,
1137+ media,
1138+ } ,
1139+ cfg,
1140+ accountId : undefined ,
1141+ toolContext : { } ,
1142+ mediaLocalRoots : [ "/tmp" ] ,
1143+ } as never ) ,
1144+ ) . rejects . toThrow ( "Feishu send media must be a non-empty string." ) ;
1145+
1146+ expect ( sendMessageFeishuMock ) . not . toHaveBeenCalled ( ) ;
1147+ expect ( sendCardFeishuMock ) . not . toHaveBeenCalled ( ) ;
1148+ expect ( feishuOutboundSendMediaMock ) . not . toHaveBeenCalled ( ) ;
1149+ } ) ;
1150+
9951151 it ( "passes asVoice through media sends" , async ( ) => {
9961152 feishuOutboundSendMediaMock . mockResolvedValueOnce ( {
9971153 channel : "feishu" ,
0 commit comments