fix: inject threat-detection CAUTION alert at top of markdown content#29264
fix: inject threat-detection CAUTION alert at top of markdown content#29264
Conversation
…oints The threat detection CAUTION alert was previously injected near the footer instead of at the top of the markdown content. This change moves it to the top across all places where it's injected: - add_comment.cjs: prepend CAUTION before body, pass skipDetectionCaution:true to footer - update_activation_comment.cjs: move cautionSection before body in link/commit messages - generate_footer.cjs: extract CAUTION from generateExpiredEntityFooter into getExpiredEntityCautionAlert (new exported function), callers responsible for placement - close_expired_issues/pull_requests/discussions.cjs: use getExpiredEntityCautionAlert and prepend to closing message - create_issue.cjs / create_discussion.cjs: unshift CAUTION to top of bodyLines - comment_memory.cjs: prepend CAUTION before managed comment header - close_entity_helpers.cjs: prepend CAUTION in buildCommentBody - mark_pull_request_as_ready_for_review.cjs: prepend CAUTION before sanitized reason - check_workflow_recompile_needed.cjs: prepend CAUTION to comment/issue body - pr_review_buffer.cjs: prepend CAUTION before review body - reply_to_pr_review_comment.cjs: prepend CAUTION before reply body - update_pr_description_helpers.cjs: prepend CAUTION in updateBody for all operations - messages_footer.cjs: remove CAUTION from getFooterWorkflowRecompile* functions Tests updated: add_comment.test.cjs (CAUTION position assertion), generate_footer.test.cjs (CAUTION no longer in generateExpiredEntityFooter, new tests for getExpiredEntityCautionAlert) Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a07d9fd2-8563-4c82-9b25-b766b139b7f6 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…equirement Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a07d9fd2-8563-4c82-9b25-b766b139b7f6 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
🧪 Test Quality Sentinel ReportTest Quality Score: 100/100✅ Excellent test quality
Test Classification DetailsView All Test Classifications (5 tests)
Analysis SummaryAll 5 new/modified tests enforce clear behavioral contracts:
No mocking of internal business logic was detected. Language SupportTests analyzed:
Verdict
📖 Understanding Test ClassificationsDesign Tests (High Value) verify what the system does:
Implementation Tests (Low Value) verify how the system does it:
Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators. References: §25149693646
|
There was a problem hiding this comment.
Pull request overview
Moves the threat-detection [!CAUTION] security alert out of footer generation and ensures it is surfaced at the beginning of user-visible Markdown content, avoiding duplication by passing skipDetectionCaution: true to generateFooterWithMessages().
Changes:
- Prepend threat-detection CAUTION to generated bodies/comments/reviews and skip CAUTION in the footer to prevent duplicates.
- Extract expired-entity CAUTION generation into
getExpiredEntityCautionAlert()and remove CAUTION fromgenerateExpiredEntityFooter(). - Update/extend tests to assert CAUTION placement and new helper behavior.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/update_pr_description_helpers.cjs | Adds CAUTION injection and skips footer CAUTION when building updated bodies. |
| actions/setup/js/update_activation_comment.cjs | Reorders activation comment template to place CAUTION before main body. |
| actions/setup/js/reply_to_pr_review_comment.cjs | Prepends CAUTION when footer is included and skips footer CAUTION. |
| actions/setup/js/pr_review_buffer.cjs | Prepends CAUTION before adding footer in buffered PR reviews; skips footer CAUTION. |
| actions/setup/js/messages_footer.cjs | Removes CAUTION prepend from workflow-recompile footer helpers (callers now own placement). |
| actions/setup/js/mark_pull_request_as_ready_for_review.cjs | Prepends CAUTION and skips footer CAUTION. |
| actions/setup/js/generate_footer.cjs | Adds getExpiredEntityCautionAlert() and removes CAUTION from expired-entity footer generation. |
| actions/setup/js/generate_footer.test.cjs | Updates assertions to ensure expired-entity footer no longer includes CAUTION; adds tests for new helper. |
| actions/setup/js/create_issue.cjs | Prepends CAUTION to issue body lines; skips footer CAUTION. |
| actions/setup/js/create_discussion.cjs | Prepends CAUTION to discussion body lines; skips footer CAUTION. |
| actions/setup/js/comment_memory.cjs | Prepends CAUTION to managed memory comment body; skips footer CAUTION. |
| actions/setup/js/close_expired_pull_requests.cjs | Prepends expired-entity CAUTION before expiration text; footer no longer includes CAUTION. |
| actions/setup/js/close_expired_issues.cjs | Prepends expired-entity CAUTION before expiration text; footer no longer includes CAUTION. |
| actions/setup/js/close_expired_discussions.cjs | Prepends expired-entity CAUTION before expiration text; footer no longer includes CAUTION. |
| actions/setup/js/close_entity_helpers.cjs | Prepends CAUTION to close-comment bodies and skips footer CAUTION. |
| actions/setup/js/check_workflow_recompile_needed.cjs | Prepends CAUTION to recompile issue/comment bodies (since recompile footer helpers no longer include it). |
| actions/setup/js/add_comment.cjs | Prepends CAUTION to comment body and skips footer CAUTION. |
| actions/setup/js/add_comment.test.cjs | Updates test to assert CAUTION appears before the body content. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 18/18 changed files
- Comments generated: 3
| // Inject CAUTION at top of new content if threat detection warning was raised | ||
| const detectionCaution = getDetectionCautionAlert(workflowName, runUrl); | ||
| const contentWithCaution = detectionCaution ? detectionCaution + "\n\n" + sanitizedNewContent : sanitizedNewContent; | ||
|
|
There was a problem hiding this comment.
It's ok to only be in tbe island
| // Append footer with workflow information when enabled | ||
| let finalBody = sanitizeContent(body); | ||
| if (includeFooter) { | ||
| const footer = generateFooterWithMessages(workflowName, runUrl, workflowSource, workflowSourceURL, undefined, triggeringPRNumber, undefined); | ||
| // Inject CAUTION at top of body if threat detection warning was raised | ||
| const detectionCaution = getDetectionCautionAlert(workflowName, runUrl); | ||
| if (detectionCaution) { | ||
| finalBody = detectionCaution + "\n\n" + finalBody; | ||
| } | ||
| const footer = generateFooterWithMessages(workflowName, runUrl, workflowSource, workflowSourceURL, undefined, triggeringPRNumber, undefined, undefined, { skipDetectionCaution: true }); |
| // Determine if we should add footer based on footer mode | ||
| let shouldAddFooter = footerMode === "always"; | ||
| if (footerMode === "if-body") { | ||
| // Only add footer if body is non-empty (has meaningful content) | ||
| shouldAddFooter = body.trim().length > 0; | ||
| core.info(`Footer mode "if-body": body is ${body.trim().length > 0 ? "non-empty" : "empty"}, ${shouldAddFooter ? "adding" : "skipping"} footer`); | ||
| } | ||
|
|
||
| // Add footer to review body if we should and we have footer context | ||
| if (shouldAddFooter && footerContext) { | ||
| // Inject CAUTION at top of body if threat detection warning was raised | ||
| const detectionCaution = getDetectionCautionAlert(footerContext.workflowName, footerContext.runUrl); | ||
| if (detectionCaution) { | ||
| body = detectionCaution + "\n\n" + body; | ||
| } |
|
@copilot review all comments |
… pr_review_buffer - reply_to_pr_review_comment.cjs: move CAUTION injection outside includeFooter block so it appears even when footer is disabled - pr_review_buffer.cjs: move CAUTION injection before the shouldAddFooter guard; when CAUTION is present, force shouldAddFooter=true so footer metadata is also included Agent-Logs-Url: https://github.com/github/gh-aw/sessions/d7cb63e7-66e8-40b7-af27-34bb96a8fc42 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed both open review comments in 7e6ffa9:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
The
[!CAUTION]security alert for threat detection was appended as part of footer generation, burying it at the bottom of content where it could easily be missed. It should appear at the very top so reviewers see it immediately.Strategy
Every content-building path now follows the pattern already established in
create_pull_request.cjsandhandle_agent_failure.cjs:getDetectionCautionAlert()/getExpiredEntityCautionAlert(){ skipDetectionCaution: true }togenerateFooterWithMessages()to prevent duplicationChanges by file
generate_footer.cjs— Extracted CAUTION logic out ofgenerateExpiredEntityFooterinto a new exportedgetExpiredEntityCautionAlert(). The footer itself no longer includes CAUTION; callers are responsible for prepending it. Note is kept inline (not imported frommessages_footer.cjs) due to bundler constraints that would break tests.messages_footer.cjs— Removed the CAUTION prepend fromgetFooterWorkflowRecompileMessageandgetFootorWorkflowRecompileCommentMessage; callers now own placement.close_expired_{issues,pull_requests,discussions}.cjs— UsegetExpiredEntityCautionAlertand prepend to the closing message before the expiration text.update_activation_comment.cjs— Reordered template:cautionSection + body + footer(wasbody + cautionSection + footer).create_{issue,discussion}.cjs—unshiftCAUTION lines to the front ofbodyLinesbefore joining.add_comment.cjs,comment_memory.cjs,close_entity_helpers.cjs,mark_pull_request_as_ready_for_review.cjs,check_workflow_recompile_needed.cjs,pr_review_buffer.cjs,reply_to_pr_review_comment.cjs,update_pr_description_helpers.cjs— Each prepends CAUTION to its content and passesskipDetectionCaution: trueto its footer call.Tests
add_comment.test.cjs— Updated position assertion: CAUTION index must be<body-content index.generate_footer.test.cjs— Updated to assert CAUTION is not ingenerateExpiredEntityFooter; added tests for the newgetExpiredEntityCautionAlertfunction.