@@ -255,68 +255,71 @@ describe("Feishu thread bindings", () => {
255255 ) . toBeNull ( ) ;
256256 } ) ;
257257
258- it ( "preserves delivery routing metadata when rebinding the same conversation" , async ( ) => {
259- vi . spyOn ( Date , "now" ) . mockReturnValue ( 1_700_000_100_000 ) ;
260- const manager = createFeishuThreadBindingManager ( { cfg : baseCfg , accountId : "default" } ) ;
261-
262- manager . bindConversation ( {
263- conversationId : "oc_group_chat:topic:om_topic_root:sender:ou_sender_1" ,
264- parentConversationId : "oc_group_chat" ,
265- targetKind : "subagent" ,
266- targetSessionKey : "agent:main:subagent:child" ,
267- metadata : {
268- agentId : "codex" ,
269- label : "child" ,
270- boundBy : "system" ,
271- deliveryTo : "user:ou_sender_1" ,
272- deliveryThreadId : "om_topic_root" ,
273- } ,
274- } ) ;
258+ it . each ( [ false , true ] ) (
259+ "preserves conversation delivery fields without inheriting another target's owner (replace=%s)" ,
260+ async ( replace ) => {
261+ vi . spyOn ( Date , "now" ) . mockReturnValue ( 1_700_000_100_000 ) ;
262+ const manager = createFeishuThreadBindingManager ( { cfg : baseCfg , accountId : "default" } ) ;
275263
276- await getSessionBindingService ( ) . bind ( {
277- targetSessionKey : "agent:main:subagent:child" ,
278- targetKind : "subagent" ,
279- conversation : {
280- channel : "feishu" ,
281- accountId : "default" ,
264+ manager . bindConversation ( {
282265 conversationId : "oc_group_chat:topic:om_topic_root:sender:ou_sender_1" ,
283266 parentConversationId : "oc_group_chat" ,
284- } ,
285- placement : "current" ,
286- metadata : {
287- label : "child" ,
288- } ,
289- } ) ;
267+ targetKind : "subagent" ,
268+ targetSessionKey : "agent:main:subagent:child" ,
269+ metadata : {
270+ agentId : "previous-agent" ,
271+ label : "child" ,
272+ boundBy : "system" ,
273+ deliveryTo : "user:ou_sender_1" ,
274+ deliveryThreadId : "om_topic_root" ,
275+ } ,
276+ } ) ;
290277
291- expect (
292- getSessionBindingService ( ) . resolveByConversation ( {
293- channel : "feishu" ,
294- accountId : "default" ,
295- conversationId : "oc_group_chat:topic:om_topic_root:sender:ou_sender_1" ,
296- } ) ,
297- ) . toEqual ( {
298- bindingId : "default:oc_group_chat:topic:om_topic_root:sender:ou_sender_1" ,
299- targetSessionKey : "agent:main:subagent:child" ,
300- targetKind : "subagent" ,
301- conversation : {
302- channel : "feishu" ,
303- accountId : "default" ,
304- conversationId : "oc_group_chat:topic:om_topic_root:sender:ou_sender_1" ,
305- parentConversationId : "oc_group_chat" ,
306- } ,
307- status : "active" ,
308- boundAt : 1_700_000_100_000 ,
309- expiresAt : 1_700_086_500_000 ,
310- metadata : {
311- agentId : "codex" ,
312- label : "child" ,
313- boundBy : "system" ,
314- deliveryTo : "user:ou_sender_1" ,
315- deliveryThreadId : "om_topic_root" ,
316- lastActivityAt : 1_700_000_100_000 ,
317- idleTimeoutMs : 86_400_000 ,
318- maxAgeMs : 0 ,
319- } ,
320- } ) ;
321- } ) ;
278+ await getSessionBindingService ( ) . bind ( {
279+ targetSessionKey : replace ? "agent:main:subagent:replacement" : "agent:main:subagent:child" ,
280+ targetKind : "subagent" ,
281+ conversation : {
282+ channel : "feishu" ,
283+ accountId : "default" ,
284+ conversationId : "oc_group_chat:topic:om_topic_root:sender:ou_sender_1" ,
285+ parentConversationId : "oc_group_chat" ,
286+ } ,
287+ placement : "current" ,
288+ metadata : {
289+ label : "child" ,
290+ } ,
291+ } ) ;
292+
293+ expect (
294+ getSessionBindingService ( ) . resolveByConversation ( {
295+ channel : "feishu" ,
296+ accountId : "default" ,
297+ conversationId : "oc_group_chat:topic:om_topic_root:sender:ou_sender_1" ,
298+ } ) ,
299+ ) . toEqual ( {
300+ bindingId : "default:oc_group_chat:topic:om_topic_root:sender:ou_sender_1" ,
301+ targetSessionKey : replace ? "agent:main:subagent:replacement" : "agent:main:subagent:child" ,
302+ targetKind : "subagent" ,
303+ conversation : {
304+ channel : "feishu" ,
305+ accountId : "default" ,
306+ conversationId : "oc_group_chat:topic:om_topic_root:sender:ou_sender_1" ,
307+ parentConversationId : "oc_group_chat" ,
308+ } ,
309+ status : "active" ,
310+ boundAt : 1_700_000_100_000 ,
311+ expiresAt : 1_700_086_500_000 ,
312+ metadata : {
313+ agentId : replace ? "main" : "previous-agent" ,
314+ label : "child" ,
315+ boundBy : replace ? undefined : "system" ,
316+ deliveryTo : "user:ou_sender_1" ,
317+ deliveryThreadId : "om_topic_root" ,
318+ lastActivityAt : 1_700_000_100_000 ,
319+ idleTimeoutMs : 86_400_000 ,
320+ maxAgeMs : 0 ,
321+ } ,
322+ } ) ;
323+ } ,
324+ ) ;
322325} ) ;
0 commit comments