@@ -954,124 +954,6 @@ describe("dispatchReplyFromConfig", () => {
954954 ) ;
955955 } ) ;
956956
957- it ( "lets queue-aware resolvers see active Telegram topic turns" , async ( ) => {
958- setNoAbort ( ) ;
959- const sessionKey = "agent:main:telegram:group:-1003774691294:topic:3731" ;
960- const activeOperation = createReplyOperation ( {
961- sessionKey,
962- sessionId : "heartbeat-session" ,
963- resetTriggered : false ,
964- } ) ;
965- activeOperation . setPhase ( "running" ) ;
966- const dispatcher = createDispatcher ( ) ;
967- const replyResolver = vi . fn ( async ( _ctx : MsgContext , opts ?: GetReplyOptions ) => {
968- const internalOpts = opts as GetReplyOptions & {
969- replyOperation ?: { sessionId ?: string } ;
970- } ;
971- expect ( internalOpts . replyOperation ) . toBeUndefined ( ) ;
972- return { text : "visible after active run" } satisfies ReplyPayload ;
973- } ) ;
974- const waitForIdleSpy = vi . spyOn ( replyRunRegistry , "waitForIdle" ) ;
975-
976- const dispatchPromise = dispatchReplyFromConfig ( {
977- ctx : buildTestCtx ( {
978- Provider : "telegram" ,
979- Surface : "telegram" ,
980- OriginatingChannel : "telegram" ,
981- SessionKey : sessionKey ,
982- ChatType : "group" ,
983- IsForum : true ,
984- MessageThreadId : 3731 ,
985- TransportThreadId : 3731 ,
986- To : "telegram:-1003774691294:topic:3731" ,
987- BodyForAgent : "real user message while heartbeat is active" ,
988- } ) ,
989- cfg : automaticGroupReplyConfig ,
990- dispatcher,
991- replyResolver,
992- } ) ;
993-
994- const result = await dispatchPromise ;
995- activeOperation . complete ( ) ;
996- waitForIdleSpy . mockRestore ( ) ;
997-
998- expect ( result . queuedFinal ) . toBe ( true ) ;
999- expect ( replyResolver ) . toHaveBeenCalledTimes ( 1 ) ;
1000- expect ( waitForIdleSpy ) . not . toHaveBeenCalled ( ) ;
1001- expect ( firstFinalReplyPayload ( dispatcher ) ?. text ) . toBe ( "visible after active run" ) ;
1002- } ) ;
1003-
1004- it ( "does not serialize custom resolvers before queue policy runs" , async ( ) => {
1005- setNoAbort ( ) ;
1006- const sessionKey = "agent:main:telegram:group:-1003774691294:topic:3731" ;
1007- const activeOperation = createReplyOperation ( {
1008- sessionKey,
1009- sessionId : "active-session" ,
1010- resetTriggered : false ,
1011- } ) ;
1012- activeOperation . setPhase ( "running" ) ;
1013- let releaseFirstResolver ! : ( ) => void ;
1014- let releaseSecondResolver ! : ( ) => void ;
1015- const firstResolverReleased = new Promise < void > ( ( resolve ) => {
1016- releaseFirstResolver = resolve ;
1017- } ) ;
1018- const secondResolverReleased = new Promise < void > ( ( resolve ) => {
1019- releaseSecondResolver = resolve ;
1020- } ) ;
1021- const firstDispatcher = createDispatcher ( ) ;
1022- const secondDispatcher = createDispatcher ( ) ;
1023- const firstReplyResolver = vi . fn ( async ( ) => {
1024- await firstResolverReleased ;
1025- return { text : "first visible reply" } satisfies ReplyPayload ;
1026- } ) ;
1027- const secondReplyResolver = vi . fn ( async ( ) => {
1028- await secondResolverReleased ;
1029- return { text : "second visible reply" } satisfies ReplyPayload ;
1030- } ) ;
1031- const createTopicCtx = ( messageSid : string , body : string ) =>
1032- buildTestCtx ( {
1033- Provider : "telegram" ,
1034- Surface : "telegram" ,
1035- OriginatingChannel : "telegram" ,
1036- SessionKey : sessionKey ,
1037- ChatType : "group" ,
1038- IsForum : true ,
1039- MessageSid : messageSid ,
1040- MessageThreadId : 3731 ,
1041- TransportThreadId : 3731 ,
1042- To : "telegram:-1003774691294:topic:3731" ,
1043- BodyForAgent : body ,
1044- } ) ;
1045-
1046- const firstDispatch = dispatchReplyFromConfig ( {
1047- ctx : createTopicCtx ( "27782" , "first queued user message" ) ,
1048- cfg : automaticGroupReplyConfig ,
1049- dispatcher : firstDispatcher ,
1050- replyResolver : firstReplyResolver ,
1051- } ) ;
1052- const secondDispatch = dispatchReplyFromConfig ( {
1053- ctx : createTopicCtx ( "27783" , "second queued user message" ) ,
1054- cfg : automaticGroupReplyConfig ,
1055- dispatcher : secondDispatcher ,
1056- replyResolver : secondReplyResolver ,
1057- } ) ;
1058-
1059- await vi . waitFor ( ( ) => {
1060- expect ( firstReplyResolver . mock . calls . length + secondReplyResolver . mock . calls . length ) . toBe ( 2 ) ;
1061- } ) ;
1062-
1063- releaseFirstResolver ( ) ;
1064- releaseSecondResolver ( ) ;
1065- activeOperation . complete ( ) ;
1066-
1067- await expect ( Promise . all ( [ firstDispatch , secondDispatch ] ) ) . resolves . toEqual ( [
1068- expect . objectContaining ( { queuedFinal : true } ) ,
1069- expect . objectContaining ( { queuedFinal : true } ) ,
1070- ] ) ;
1071- expect ( firstFinalReplyPayload ( firstDispatcher ) ?. text ) . toBe ( "first visible reply" ) ;
1072- expect ( firstFinalReplyPayload ( secondDispatcher ) ?. text ) . toBe ( "second visible reply" ) ;
1073- } ) ;
1074-
1075957 it ( "skips pre-dispatch admission when the caller already aborted" , async ( ) => {
1076958 setNoAbort ( ) ;
1077959 const sessionKey = "agent:main:telegram:group:-1003774691294:topic:3731" ;
0 commit comments