@@ -1952,6 +1952,95 @@ describe("processDiscordMessage draft streaming", () => {
19521952 expectSinglePreviewEdit ( ) ;
19531953 } ) ;
19541954
1955+ it ( "delivers a fresh message instead of a preview edit when the final reply resolves a mention alias" , async ( ) => {
1956+ dispatchInboundMessage . mockImplementationOnce ( async ( params ?: DispatchInboundParams ) => {
1957+ await params ?. dispatcher . sendFinalReply ( { text : "On it @Sentinel" } ) ;
1958+ return { queuedFinal : true , counts : { final : 1 , tool : 0 , block : 0 } } ;
1959+ } ) ;
1960+
1961+ const ctx = await createAutomaticSourceDeliveryContext ( {
1962+ discordConfig : { streamMode : "partial" , maxLinesPerMessage : 5 } ,
1963+ cfg : {
1964+ channels : { discord : { mentionAliases : { Sentinel : "1485891428809707651" } } } ,
1965+ } ,
1966+ } ) ;
1967+
1968+ await runProcessDiscordMessage ( ctx ) ;
1969+
1970+ // Discord only fires mention notifications on create, never on edits, so the
1971+ // streamed preview must be abandoned and the mention delivered fresh.
1972+ expect ( editMessageDiscord ) . not . toHaveBeenCalled ( ) ;
1973+ expect ( deliverDiscordReply ) . toHaveBeenCalledTimes ( 1 ) ;
1974+ } ) ;
1975+
1976+ it ( "delivers a fresh message instead of a preview edit for a literal user mention in the final reply" , async ( ) => {
1977+ dispatchInboundMessage . mockImplementationOnce ( async ( params ?: DispatchInboundParams ) => {
1978+ await params ?. dispatcher . sendFinalReply ( { text : "On it <@1485891428809707651>" } ) ;
1979+ return { queuedFinal : true , counts : { final : 1 , tool : 0 , block : 0 } } ;
1980+ } ) ;
1981+
1982+ const ctx = await createAutomaticSourceDeliveryContext ( {
1983+ discordConfig : { streamMode : "partial" , maxLinesPerMessage : 5 } ,
1984+ } ) ;
1985+
1986+ await runProcessDiscordMessage ( ctx ) ;
1987+
1988+ expect ( editMessageDiscord ) . not . toHaveBeenCalled ( ) ;
1989+ expect ( deliverDiscordReply ) . toHaveBeenCalledTimes ( 1 ) ;
1990+ } ) ;
1991+
1992+ it ( "still finalizes via preview edit when an unaliased handle stays plain text" , async ( ) => {
1993+ dispatchInboundMessage . mockImplementationOnce ( async ( params ?: DispatchInboundParams ) => {
1994+ await params ?. dispatcher . sendFinalReply ( { text : "On it @Sentinel" } ) ;
1995+ return { queuedFinal : true , counts : { final : 1 , tool : 0 , block : 0 } } ;
1996+ } ) ;
1997+
1998+ const ctx = await createAutomaticSourceDeliveryContext ( {
1999+ discordConfig : { streamMode : "partial" , maxLinesPerMessage : 5 } ,
2000+ } ) ;
2001+
2002+ await runProcessDiscordMessage ( ctx ) ;
2003+
2004+ expect ( editMessageDiscord ) . toHaveBeenCalledTimes ( 1 ) ;
2005+ expect ( deliverDiscordReply ) . not . toHaveBeenCalled ( ) ;
2006+ } ) ;
2007+
2008+ it ( "still finalizes via preview edit for broadcast mentions like @everyone" , async ( ) => {
2009+ dispatchInboundMessage . mockImplementationOnce ( async ( params ?: DispatchInboundParams ) => {
2010+ await params ?. dispatcher . sendFinalReply ( { text : "heads up @everyone" } ) ;
2011+ return { queuedFinal : true , counts : { final : 1 , tool : 0 , block : 0 } } ;
2012+ } ) ;
2013+
2014+ const ctx = await createAutomaticSourceDeliveryContext ( {
2015+ discordConfig : { streamMode : "partial" , maxLinesPerMessage : 5 } ,
2016+ } ) ;
2017+
2018+ await runProcessDiscordMessage ( ctx ) ;
2019+
2020+ expect ( editMessageDiscord ) . toHaveBeenCalledTimes ( 1 ) ;
2021+ expect ( deliverDiscordReply ) . not . toHaveBeenCalled ( ) ;
2022+ } ) ;
2023+
2024+ it ( "still finalizes via preview edit when a targeted mention is mixed with @everyone" , async ( ) => {
2025+ dispatchInboundMessage . mockImplementationOnce ( async ( params ?: DispatchInboundParams ) => {
2026+ await params ?. dispatcher . sendFinalReply ( { text : "heads up @Sentinel @everyone" } ) ;
2027+ return { queuedFinal : true , counts : { final : 1 , tool : 0 , block : 0 } } ;
2028+ } ) ;
2029+
2030+ const ctx = await createAutomaticSourceDeliveryContext ( {
2031+ discordConfig : { streamMode : "partial" , maxLinesPerMessage : 5 } ,
2032+ cfg : {
2033+ channels : { discord : { mentionAliases : { Sentinel : "1485891428809707651" } } } ,
2034+ } ,
2035+ } ) ;
2036+
2037+ await runProcessDiscordMessage ( ctx ) ;
2038+
2039+ // Mixed targeted + broadcast must not escalate into a create that pings @everyone.
2040+ expect ( editMessageDiscord ) . toHaveBeenCalledTimes ( 1 ) ;
2041+ expect ( deliverDiscordReply ) . not . toHaveBeenCalled ( ) ;
2042+ } ) ;
2043+
19552044 it ( "accepts streaming=true alias for partial preview mode" , async ( ) => {
19562045 await runSingleChunkFinalScenario ( { streaming : true , maxLinesPerMessage : 5 } ) ;
19572046 expectSinglePreviewEdit ( ) ;
0 commit comments