@@ -2394,6 +2394,118 @@ describe("feishuOutbound.sendMedia replyToId forwarding", () => {
23942394 expect ( sendMediaCall ( ) ?. replyInThread ) . toBe ( false ) ;
23952395 } ) ;
23962396
2397+ it ( "consumes an implicit first-reply target on the caption before sending its attachment" , async ( ) => {
2398+ await feishuOutbound . sendMedia ?.( {
2399+ cfg : emptyConfig ,
2400+ to : "chat_1" ,
2401+ text : "caption text" ,
2402+ mediaUrl : "https://example.com/image.png" ,
2403+ replyToId : "om_reply_target" ,
2404+ replyToIdSource : "implicit" ,
2405+ replyToMode : "first" ,
2406+ accountId : "main" ,
2407+ } ) ;
2408+
2409+ expect ( sendMessageCall ( ) ?. replyToMessageId ) . toBe ( "om_reply_target" ) ;
2410+ expect ( sendMediaCall ( ) ?. replyToMessageId ) . toBeUndefined ( ) ;
2411+ } ) ;
2412+
2413+ it ( "does not reuse an implicit first-reply target for the upload-failure fallback" , async ( ) => {
2414+ sendMediaFeishuMock . mockRejectedValueOnce ( new Error ( "upload failed" ) ) ;
2415+
2416+ await feishuOutbound . sendMedia ?.( {
2417+ cfg : emptyConfig ,
2418+ to : "chat_1" ,
2419+ text : "caption text" ,
2420+ mediaUrl : "https://example.com/image.png" ,
2421+ replyToId : "om_reply_target" ,
2422+ replyToIdSource : "implicit" ,
2423+ replyToMode : "first" ,
2424+ accountId : "main" ,
2425+ } ) ;
2426+
2427+ expect ( sendMessageFeishuMock . mock . calls [ 0 ] ?. [ 0 ] ?. replyToMessageId ) . toBe ( "om_reply_target" ) ;
2428+ expect ( sendMessageFeishuMock . mock . calls [ 1 ] ?. [ 0 ] ?. replyToMessageId ) . toBeUndefined ( ) ;
2429+ } ) ;
2430+
2431+ it ( "preserves an unconsumed implicit reply target when the first media upload fails" , async ( ) => {
2432+ sendMediaFeishuMock . mockRejectedValueOnce ( new Error ( "upload failed" ) ) ;
2433+
2434+ await feishuOutbound . sendMedia ?.( {
2435+ cfg : emptyConfig ,
2436+ to : "chat_1" ,
2437+ text : "spoken reply" ,
2438+ mediaUrl : "https://example.com/reply.mp3" ,
2439+ audioAsVoice : true ,
2440+ replyToId : "om_reply_target" ,
2441+ replyToIdSource : "implicit" ,
2442+ replyToMode : "first" ,
2443+ accountId : "main" ,
2444+ } ) ;
2445+
2446+ expect ( sendMediaCall ( ) ?. replyToMessageId ) . toBe ( "om_reply_target" ) ;
2447+ expect ( sendMessageCall ( ) ?. replyToMessageId ) . toBe ( "om_reply_target" ) ;
2448+ } ) ;
2449+
2450+ it ( "consumes an implicit first-reply target on degraded voice media before its text" , async ( ) => {
2451+ sendMediaFeishuMock . mockResolvedValueOnce ( {
2452+ messageId : "file_msg" ,
2453+ voiceIntentDegradedToFile : true ,
2454+ } ) ;
2455+
2456+ await feishuOutbound . sendMedia ?.( {
2457+ cfg : emptyConfig ,
2458+ to : "chat_1" ,
2459+ text : "spoken reply" ,
2460+ mediaUrl : "https://example.com/reply.mp3" ,
2461+ audioAsVoice : true ,
2462+ replyToId : "om_reply_target" ,
2463+ replyToIdSource : "implicit" ,
2464+ replyToMode : "first" ,
2465+ accountId : "main" ,
2466+ } ) ;
2467+
2468+ expect ( sendMediaCall ( ) ?. replyToMessageId ) . toBe ( "om_reply_target" ) ;
2469+ expect ( sendMessageCall ( ) ?. replyToMessageId ) . toBeUndefined ( ) ;
2470+ } ) ;
2471+
2472+ it ( "keeps explicit first-mode reply targets sticky across captions and media" , async ( ) => {
2473+ await feishuOutbound . sendMedia ?.( {
2474+ cfg : emptyConfig ,
2475+ to : "chat_1" ,
2476+ text : "caption text" ,
2477+ mediaUrl : "https://example.com/image.png" ,
2478+ replyToId : "om_reply_target" ,
2479+ replyToIdSource : "explicit" ,
2480+ replyToMode : "first" ,
2481+ accountId : "main" ,
2482+ } ) ;
2483+
2484+ expect ( sendMessageCall ( ) ?. replyToMessageId ) . toBe ( "om_reply_target" ) ;
2485+ expect ( sendMediaCall ( ) ?. replyToMessageId ) . toBe ( "om_reply_target" ) ;
2486+ } ) ;
2487+
2488+ it ( "keeps native topic roots sticky across captions, attachments, and fallback" , async ( ) => {
2489+ sendMediaFeishuMock . mockRejectedValueOnce ( new Error ( "upload failed" ) ) ;
2490+
2491+ await feishuOutbound . sendMedia ?.( {
2492+ cfg : emptyConfig ,
2493+ to : "chat_1" ,
2494+ text : "caption text" ,
2495+ mediaUrl : "https://example.com/image.png" ,
2496+ threadId : "om_topic_root" ,
2497+ replyToMode : "first" ,
2498+ accountId : "main" ,
2499+ } ) ;
2500+
2501+ expect ( sendMediaCall ( ) ?. replyToMessageId ) . toBe ( "om_topic_root" ) ;
2502+ expect ( sendMediaCall ( ) ?. replyInThread ) . toBe ( true ) ;
2503+ for ( const [ params ] of sendMessageFeishuMock . mock . calls ) {
2504+ expect ( params . replyToMessageId ) . toBe ( "om_topic_root" ) ;
2505+ expect ( params . replyInThread ) . toBe ( true ) ;
2506+ }
2507+ } ) ;
2508+
23972509 it ( "forwards threadId as replyInThread=true to sendMediaFeishu" , async ( ) => {
23982510 await feishuOutbound . sendMedia ?.( {
23992511 cfg : emptyConfig ,
0 commit comments