@@ -237,7 +237,9 @@ const mockCore = {
237237 for ( const item of items . slice ( 0 , - 1 ) ) {
238238 expect ( body . includes ( item . message || item . reason ) ) . toBe ( published ) ;
239239 }
240- expect ( body . includes ( "<summary>Continuation requested</summary>" ) ) . toBe ( published ) ;
240+ expect ( body . includes ( "## Agent messages" ) ) . toBe ( published ) ;
241+ expect ( body . includes ( "**Continuation requested**" ) ) . toBe ( published ) ;
242+ expect ( body ) . not . toContain ( "<summary>No-op message</summary>" ) ;
241243 if ( detectionDisabled ) expect ( body ) . toContain ( "completed successfully" ) ;
242244 expect ( body ) . not . toContain ( "Unrequested details" ) ;
243245 expect ( body ) . not . toContain ( "Unrelated safe output" ) ;
@@ -247,7 +249,22 @@ const mockCore = {
247249 } ) ;
248250 } ) ,
249251 describe ( "rendering accepted agent explanations" , ( ) => {
250- async function renderAcceptedExplanations ( items ) {
252+ it ( "keeps agent content tainted under framework-authored section labels" , ( ) => {
253+ const children = eval ( `(() => {
254+ ${ notifyCommentScript }
255+ const children = [];
256+ appendAgentReports(children, [{ type: "noop", message: "No changes needed." }]);
257+ return children;
258+ })()` ) ;
259+
260+ expect ( children ) . toMatchObject ( [
261+ { type : "heading" , level : 2 , agentTainted : false , children : [ { type : "text" , value : "Agent messages" , agentTainted : false } ] } ,
262+ { type : "paragraph" , agentTainted : false , children : [ { type : "strong" , agentTainted : false } ] } ,
263+ { type : "paragraph" , agentTainted : true , children : [ { type : "text" , value : "No changes needed." , agentTainted : true } ] } ,
264+ ] ) ;
265+ } ) ;
266+
267+ async function renderAcceptedExplanations ( items , noopCommentBody ) {
251268 const fixtureDir = fs . mkdtempSync ( path . join ( process . cwd ( ) , "gh-aw-explanation-rendering-" ) ) ;
252269 try {
253270 const outputPath = path . join ( fixtureDir , "agent-output.json" ) ;
@@ -261,6 +278,7 @@ const mockCore = {
261278 delete process . env . GH_AW_SAFE_OUTPUTS_RESULT ;
262279 delete process . env . GH_AW_NOOP_COMMENT_BODY ;
263280 delete process . env . GH_AW_SAFE_OUTPUT_MESSAGES ;
281+ if ( noopCommentBody ) process . env . GH_AW_NOOP_COMMENT_BODY = noopCommentBody ;
264282
265283 await eval ( `(async () => { ${ notifyCommentScript } ; await main(); })()` ) ;
266284
@@ -281,7 +299,7 @@ const mockCore = {
281299 message : "# No changes\n\nNotify @some-org/some-team <b>if needed</b>. [Health](https://api.example.com/health) [Blocked](https://blocked.example.net/health)" ,
282300 } ,
283301 ] ) ;
284- expect ( body ) . toContain ( "<summary> No-op message</summary> \n\n### No changes\n" ) ;
302+ expect ( body ) . toContain ( "## Agent messages\n\n** No-op message** \n\n### No changes\n" ) ;
285303 expect ( body ) . toContain ( "Notify `@some-org/some-team` **if needed**." ) ;
286304 expect ( body . replace ( "`@some-org/some-team`" , "" ) ) . not . toContain ( "@some-org/some-team" ) ;
287305 expect ( body ) . not . toMatch ( / < \/ ? b > / ) ;
@@ -292,12 +310,88 @@ const mockCore = {
292310 }
293311 } ) ;
294312
313+ it ( "shows multiline agent messages before links, categorized outcomes, and attribution" , async ( ) => {
314+ process . env . GH_AW_ACTIVATION_COMMENT_LINKS = "Pull request created: [#900](https://github.com/owner/repo/pull/900)" ;
315+ const body = await renderAcceptedExplanations (
316+ [
317+ { type : "noop" , message : "No findings.\n\nReviewed all changed contracts." } ,
318+ { type : "report_missing_data" , reason : "No input was provided." } ,
319+ ] ,
320+ "### test-workflow\n\n**Outcome:** `reported_action`\n\nStructured outcome explanation."
321+ ) ;
322+
323+ expect ( body ) . toContain ( "## Agent messages\n\n**No-op message**\n\nNo findings.\n\nReviewed all changed contracts.\n\n**Missing data**\n\nNo input was provided." ) ;
324+ expect ( body ) . not . toContain ( "<details>" ) ;
325+ expect ( body . indexOf ( "completed successfully" ) ) . toBeLessThan ( body . indexOf ( "## Agent messages" ) ) ;
326+ expect ( body . indexOf ( "No input was provided." ) ) . toBeLessThan ( body . indexOf ( "Pull request created:" ) ) ;
327+ expect ( body . indexOf ( "Pull request created:" ) ) . toBeLessThan ( body . indexOf ( "**Outcome:**" ) ) ;
328+ expect ( body . indexOf ( "**Outcome:**" ) ) . toBeLessThan ( body . indexOf ( "> Generated by" ) ) ;
329+ expect ( body . match ( / < ! - - g h - a w - a g e n t i c - w o r k f l o w : / g) ) . toHaveLength ( 1 ) ;
330+ } ) ;
331+
332+ it ( "bounds many accepted explanations while preserving the status and footer" , async ( ) => {
333+ const items = Array . from ( { length : 3000 } , ( _ , index ) => ( { type : "noop" , message : `Message ${ index } ` } ) ) ;
334+ const body = await renderAcceptedExplanations ( items ) ;
335+
336+ expect ( body . length ) . toBeLessThanOrEqual ( 65536 ) ;
337+ expect ( body . match ( / \* \* N o - o p m e s s a g e \* \* / g) ) . toHaveLength ( 50 ) ;
338+ expect ( body ) . toContain ( "Message 49" ) ;
339+ expect ( body ) . not . toContain ( "Message 50\n" ) ;
340+ expect ( body ) . toContain ( "Additional agent messages omitted." ) ;
341+ expect ( body ) . toContain ( "completed successfully" ) ;
342+ expect ( body ) . toContain ( "> Generated by" ) ;
343+ expect ( body ) . toContain ( "<!-- gh-aw-agentic-workflow:" ) ;
344+ } ) ;
345+
346+ it ( "fits large explanations without omitting an exact-limit collection" , async ( ) => {
347+ const items = Array . from ( { length : 50 } , ( ) => ( { type : "report_missing_data" , reason : "Large explanation " . repeat ( 1000 ) } ) ) ;
348+ const body = await renderAcceptedExplanations ( items ) ;
349+
350+ expect ( body . length ) . toBeLessThanOrEqual ( 65536 ) ;
351+ expect ( body ) . toContain ( "Content redacted to fit size limit." ) ;
352+ expect ( body ) . not . toContain ( "Additional agent messages omitted." ) ;
353+ expect ( body ) . toContain ( "completed successfully" ) ;
354+ expect ( body ) . toContain ( "<!-- gh-aw-agentic-workflow:" ) ;
355+ } ) ;
356+
357+ it ( "does not count invalid or unsupported explanations toward the limit" , async ( ) => {
358+ const items = [
359+ ...Array . from ( { length : 50 } , ( _ , index ) => ( { type : "noop" , message : `Message ${ index } ` } ) ) ,
360+ { type : "noop" , message : " " } ,
361+ { type : "noop" , message : "API_SECRET=synthetic-opaque-value" } ,
362+ { type : "add_comment" , body : "Unrelated output" } ,
363+ ] ;
364+ const body = await renderAcceptedExplanations ( items ) ;
365+
366+ expect ( body ) . toContain ( "Message 49" ) ;
367+ expect ( body ) . not . toContain ( "Additional agent messages omitted." ) ;
368+ expect ( body ) . not . toContain ( "synthetic-opaque-value" ) ;
369+ } ) ;
370+
371+ it ( "preserves agent-authored alerts without nesting them in another alert" , async ( ) => {
372+ const body = await renderAcceptedExplanations ( [ { type : "report_incomplete" , reason : "> [!WARNING]\n> Review did not finish." } ] ) ;
373+
374+ expect ( body ) . toContain ( "## Agent messages\n\n**Incomplete work**\n\n> [!WARNING]\n> Review did not finish." ) ;
375+ expect ( body ) . not . toContain ( "> > [!" ) ;
376+ } ) ;
377+
378+ it ( "omits the info section when there are no publishable explanations" , async ( ) => {
379+ const body = await renderAcceptedExplanations ( [
380+ { type : "noop" , message : " " } ,
381+ { type : "add_comment" , body : "Unrelated output" } ,
382+ ] ) ;
383+
384+ expect ( body ) . not . toContain ( "## Agent messages" ) ;
385+ expect ( body ) . not . toContain ( "**No-op message**" ) ;
386+ expect ( body ) . toContain ( "completed successfully" ) ;
387+ } ) ;
388+
295389 it ( "masks recognized credentials in the published explanation" , async ( ) => {
296390 const pat = `ghp_${ "A" . repeat ( 36 ) } ` ;
297391 const awsKey = `AKIA${ "B" . repeat ( 16 ) } ` ;
298392 const body = await renderAcceptedExplanations ( [ { type : "noop" , message : `Credential diagnostics:\n\n\`\`\`text\n${ pat } \n${ awsKey } \n\`\`\`` } ] ) ;
299393
300- expect ( body ) . toContain ( "<summary> No-op message</summary> " ) ;
394+ expect ( body ) . toContain ( "** No-op message** " ) ;
301395 expect ( body ) . toContain ( "Credential diagnostics:" ) ;
302396 expect ( body ) . toContain ( "***REDACTED***\n***REDACTED***" ) ;
303397 expect ( body . includes ( pat ) ) . toBe ( false ) ;
0 commit comments