@@ -2149,9 +2149,9 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
21492149 expectMockCallArgFields ( finalizeSlackPreviewEditMock , 0 , "preview edit params" , {
21502150 channelId : "C123" ,
21512151 messageId : "171234.567" ,
2152- text : expect . stringMatching ( / ⏱ ️ \d + s $ / ) ,
2152+ text : FINAL_REPLY_TEXT ,
21532153 } ) ;
2154- expect ( deliverRepliesMock ) . toHaveBeenCalledTimes ( 1 ) ;
2154+ expect ( deliverRepliesMock ) . not . toHaveBeenCalled ( ) ;
21552155 expect ( draftStream . clear ) . not . toHaveBeenCalled ( ) ;
21562156 } ) ;
21572157
@@ -2245,10 +2245,10 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
22452245 ] ,
22462246 } ) ;
22472247 expect ( finalizeSlackPreviewEditMock ) . toHaveBeenCalledTimes ( 1 ) ;
2248- expect ( deliverRepliesMock ) . toHaveBeenCalledTimes ( 1 ) ;
2248+ expect ( deliverRepliesMock ) . not . toHaveBeenCalled ( ) ;
22492249 } ) ;
22502250
2251- it ( "sends a progress final fresh before collapsing its draft to a receipt" , async ( ) => {
2251+ it ( "replaces the progress draft with the final answer without posting a receipt" , async ( ) => {
22522252 const draftStream = createDraftStreamStub ( ) ;
22532253 createSlackDraftStreamMock . mockReturnValueOnce ( draftStream ) ;
22542254 finalizeSlackPreviewEditMock . mockResolvedValueOnce ( undefined ) ;
@@ -2272,20 +2272,55 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
22722272 } ) ,
22732273 ) ;
22742274
2275- expect ( deliverRepliesMock ) . toHaveBeenCalledTimes ( 1 ) ;
2276- expectDeliverReplyCall ( 0 , FINAL_REPLY_TEXT ) ;
2277- expectMockCallArgFields ( finalizeSlackPreviewEditMock , 0 , "progress receipt edit" , {
2275+ expect ( deliverRepliesMock ) . not . toHaveBeenCalled ( ) ;
2276+ expectMockCallArgFields ( finalizeSlackPreviewEditMock , 0 , "progress final edit" , {
22782277 channelId : "C123" ,
22792278 messageId : "171234.567" ,
2280- text : expect . stringMatching ( / ^ 🛠 ️ 1 t o o l c a l l · ⏱ ️ \d + s $ / ) ,
2279+ text : FINAL_REPLY_TEXT ,
22812280 } ) ;
2282- expect ( deliverRepliesMock . mock . invocationCallOrder [ 0 ] ) . toBeLessThan (
2283- finalizeSlackPreviewEditMock . mock . invocationCallOrder [ 0 ] ?? Number . POSITIVE_INFINITY ,
2284- ) ;
2281+ expect ( finalizeSlackPreviewEditMock ) . toHaveBeenCalledTimes ( 1 ) ;
22852282 expect ( draftStream . clear ) . not . toHaveBeenCalled ( ) ;
22862283 } ) ;
22872284
2288- it ( "leaves a progress draft untouched when the fresh final send fails" , async ( ) => {
2285+ it . each ( [
2286+ { description : "plain text" , finalText : "x" . repeat ( 4001 ) } ,
2287+ { description : "multibyte text" , finalText : "é" . repeat ( 2001 ) } ,
2288+ ] ) (
2289+ "delivers oversized $description intact through the normal chunked sender" ,
2290+ async ( { finalText } ) => {
2291+ const draftStream = createDraftStreamStub ( ) ;
2292+ createSlackDraftStreamMock . mockReturnValueOnce ( draftStream ) ;
2293+ mockedSlackStreamingMode = "progress" ;
2294+ mockedSlackDraftMode = "status_final" ;
2295+ mockedDispatchSequence = [ { kind : "final" , payload : { text : finalText } } ] ;
2296+ mockedReplyOptionEvents = [
2297+ {
2298+ kind : "item" ,
2299+ itemKind : "preamble" ,
2300+ itemId : "preamble-1" ,
2301+ progressText : "Checking the full answer before replying." ,
2302+ } ,
2303+ ] ;
2304+
2305+ await dispatchPreparedSlackMessage (
2306+ createPreparedSlackMessage ( {
2307+ accountConfig : {
2308+ streaming : {
2309+ mode : "progress" ,
2310+ progress : { label : false , commentary : true , toolProgress : false } ,
2311+ } ,
2312+ } ,
2313+ } ) ,
2314+ ) ;
2315+
2316+ expect ( finalizeSlackPreviewEditMock ) . not . toHaveBeenCalled ( ) ;
2317+ expect ( deliverRepliesMock ) . toHaveBeenCalledTimes ( 1 ) ;
2318+ expectDeliverReplyCall ( 0 , finalText ) ;
2319+ expect ( draftStream . clear ) . toHaveBeenCalledTimes ( 1 ) ;
2320+ } ,
2321+ ) ;
2322+
2323+ it ( "retains the progress draft when both the final edit and fallback send fail" , async ( ) => {
22892324 const draftStream = createDraftStreamStub ( ) ;
22902325 createSlackDraftStreamMock . mockReturnValueOnce ( draftStream ) ;
22912326 deliverRepliesMock . mockRejectedValueOnce ( new Error ( "final send failed" ) ) ;
@@ -2303,11 +2338,14 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
23032338 ) . rejects . toThrow ( "final send failed" ) ;
23042339
23052340 expect ( draftStream . update ) . toHaveBeenCalled ( ) ;
2306- expect ( finalizeSlackPreviewEditMock ) . not . toHaveBeenCalled ( ) ;
2341+ expectMockCallArgFields ( finalizeSlackPreviewEditMock , 0 , "progress final edit" , {
2342+ messageId : "171234.567" ,
2343+ text : FINAL_REPLY_TEXT ,
2344+ } ) ;
23072345 expect ( draftStream . clear ) . not . toHaveBeenCalled ( ) ;
23082346 } ) ;
23092347
2310- it ( "keeps a progress draft for an error final without creating a receipt" , async ( ) => {
2348+ it ( "replaces a progress draft with an error final without creating a receipt" , async ( ) => {
23112349 const draftStream = createDraftStreamStub ( ) ;
23122350 createSlackDraftStreamMock . mockReturnValueOnce ( draftStream ) ;
23132351 mockedSlackStreamingMode = "progress" ;
@@ -2323,7 +2361,7 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
23232361
23242362 expect ( deliverRepliesMock ) . toHaveBeenCalledTimes ( 1 ) ;
23252363 expect ( finalizeSlackPreviewEditMock ) . not . toHaveBeenCalled ( ) ;
2326- expect ( draftStream . clear ) . not . toHaveBeenCalled ( ) ;
2364+ expect ( draftStream . clear ) . toHaveBeenCalledTimes ( 1 ) ;
23272365 } ) ;
23282366
23292367 it ( "mandatory E2E: streams native Slack progress with the newest meaningful plan title when no explicit label exists" , async ( ) => {
@@ -3532,7 +3570,7 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
35323570 ] ,
35333571 } ) ;
35343572 expect ( finalizeSlackPreviewEditMock ) . toHaveBeenCalledTimes ( 1 ) ;
3535- expect ( deliverRepliesMock ) . toHaveBeenCalledTimes ( 1 ) ;
3573+ expect ( deliverRepliesMock ) . not . toHaveBeenCalled ( ) ;
35363574 } ) ;
35373575
35383576 it ( "preserves text Slack progress lines after a draft boundary status update" , async ( ) => {
@@ -3736,7 +3774,7 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
37363774
37373775 expect ( capturedReplyOptions ?. commentaryProgressEnabled ) . toBe ( true ) ;
37383776 expect ( capturedReplyOptions ?. suppressDefaultToolProgressMessages ) . toBe ( true ) ;
3739- expect ( draftStream . update ) . toHaveBeenLastCalledWith ( "💬 Preparing the smallest fix " ) ;
3777+ expect ( draftStream . update ) . toHaveBeenLastCalledWith ( "_Preparing the smallest fix_ " ) ;
37403778 expect ( draftStream . update . mock . calls . flat ( ) . join ( "\n" ) ) . not . toContain ( "pnpm test" ) ;
37413779
37423780 const updateCount = draftStream . update . mock . calls . length ;
@@ -3776,8 +3814,94 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
37763814 ) ;
37773815
37783816 expect ( draftStream . update ) . toHaveBeenLastCalledWith (
3779- "💬 I’m using the `monorepo` skill on Linux x86_64." ,
3817+ "_I’m using the `monorepo` skill on Linux x86\\_64._" ,
3818+ ) ;
3819+ } ) ;
3820+
3821+ it ( "escapes Slack mentions and formatting in commentary without losing outer italics or inline code" , async ( ) => {
3822+ const draftStream = createDraftStreamStub ( ) ;
3823+ createSlackDraftStreamMock . mockReturnValueOnce ( draftStream ) ;
3824+ mockedSlackStreamingMode = "progress" ;
3825+ mockedSlackDraftMode = "status_final" ;
3826+ mockedDispatchSequence = [ ] ;
3827+ mockedReplyOptionEvents = [
3828+ {
3829+ kind : "item" ,
3830+ itemKind : "preamble" ,
3831+ itemId : "preamble-1" ,
3832+ progressText :
3833+ "checking <@U123> in <#C123> and <!channel> with *urgent* _context_ `src/one.ts`" ,
3834+ } ,
3835+ ] ;
3836+
3837+ await dispatchPreparedSlackMessage (
3838+ createPreparedSlackMessage ( {
3839+ accountConfig : {
3840+ streaming : {
3841+ mode : "progress" ,
3842+ progress : { label : false , commentary : true , toolProgress : false } ,
3843+ } ,
3844+ } ,
3845+ } ) ,
3846+ ) ;
3847+
3848+ expect ( draftStream . update ) . toHaveBeenLastCalledWith (
3849+ "_checking <@U123> in <#C123> and <!channel> with \\*urgent\\* \\_context\\_ `src/one.ts`_" ,
3850+ ) ;
3851+ } ) ;
3852+
3853+ it ( "keeps the full latest preamble and turns the same Slack message into the final answer" , async ( ) => {
3854+ const draftStream = createDraftStreamStub ( ) ;
3855+ createSlackDraftStreamMock . mockReturnValueOnce ( draftStream ) ;
3856+ finalizeSlackPreviewEditMock . mockResolvedValueOnce ( undefined ) ;
3857+ mockedSlackStreamingMode = "progress" ;
3858+ mockedSlackDraftMode = "status_final" ;
3859+ mockedDispatchSequence = [ { kind : "final" , payload : { text : FINAL_REPLY_TEXT } } ] ;
3860+ const firstPreamble = "Checking the previous conversation before replying." ;
3861+ const latestPreamble =
3862+ "I found the earlier decision and am checking the owner, the current rollout, and the original feedback before deciding what would actually be useful here." ;
3863+ mockedReplyOptionEvents = [
3864+ {
3865+ kind : "item" ,
3866+ itemKind : "preamble" ,
3867+ itemId : "preamble-1" ,
3868+ progressText : firstPreamble ,
3869+ } ,
3870+ {
3871+ kind : "item" ,
3872+ itemKind : "preamble" ,
3873+ itemId : "preamble-2" ,
3874+ progressText : latestPreamble ,
3875+ } ,
3876+ ] ;
3877+
3878+ await dispatchPreparedSlackMessage (
3879+ createPreparedSlackMessage ( {
3880+ accountConfig : {
3881+ streaming : {
3882+ mode : "progress" ,
3883+ progress : {
3884+ label : false ,
3885+ commentary : true ,
3886+ toolProgress : false ,
3887+ maxLines : 1 ,
3888+ maxLineChars : 4000 ,
3889+ } ,
3890+ } ,
3891+ } ,
3892+ } ) ,
37803893 ) ;
3894+
3895+ expect ( draftStream . update ) . toHaveBeenCalledWith ( `_${ firstPreamble } _` ) ;
3896+ expect ( draftStream . update ) . toHaveBeenLastCalledWith ( `_${ latestPreamble } _` ) ;
3897+ expect ( finalizeSlackPreviewEditMock ) . toHaveBeenCalledTimes ( 1 ) ;
3898+ expectMockCallArgFields ( finalizeSlackPreviewEditMock , 0 , "progress final edit" , {
3899+ channelId : "C123" ,
3900+ messageId : "171234.567" ,
3901+ text : FINAL_REPLY_TEXT ,
3902+ } ) ;
3903+ expect ( deliverRepliesMock ) . not . toHaveBeenCalled ( ) ;
3904+ expect ( draftStream . update . mock . calls . flat ( ) . join ( "\n" ) ) . not . toMatch ( / W o r k i n g | 💬 | • | ⏱ ️ / u) ;
37813905 } ) ;
37823906
37833907 it ( "uses the enterprise event client for Slack commentary drafts" , async ( ) => {
@@ -3827,7 +3951,7 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
38273951 expect ( createSlackDraftStreamMock ) . toHaveBeenCalledWith (
38283952 expect . objectContaining ( { eventScope } ) ,
38293953 ) ;
3830- expect ( draftStream . update ) . toHaveBeenLastCalledWith ( "💬 Using the scoped listener client " ) ;
3954+ expect ( draftStream . update ) . toHaveBeenLastCalledWith ( "_Using the scoped listener client_ " ) ;
38313955 } ) ;
38323956
38333957 it ( "renders the latest Slack preamble as the status headline by default" , async ( ) => {
@@ -4025,7 +4149,7 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
40254149 ] ,
40264150 } ) ;
40274151 expect ( finalizeSlackPreviewEditMock ) . toHaveBeenCalledTimes ( 1 ) ;
4028- expect ( deliverRepliesMock ) . toHaveBeenCalledTimes ( 1 ) ;
4152+ expect ( deliverRepliesMock ) . not . toHaveBeenCalled ( ) ;
40294153 } ) ;
40304154
40314155 it ( "suppresses standalone Slack tool progress when partial preview lines are disabled" , async ( ) => {
0 commit comments