Skip to content

feat: show warning in coverage comment when coverage report too long - #298

Open
mschoettle wants to merge 1 commit into
MishaKav:mainfrom
mschoettle:surface-warning
Open

feat: show warning in coverage comment when coverage report too long#298
mschoettle wants to merge 1 commit into
MishaKav:mainfrom
mschoettle:surface-warning

Conversation

@mschoettle

@mschoettle mschoettle commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

When the coverage comment is too long and gets truncated it is only visible in the job log. This PR adds a warning to the comment itself to show that it was truncated as it can otherwise go unnoticed.

Related Issue

Closes #

Checklist

  • Tested locally
  • Ran npm run all
  • Updated docs (if needed)

Summary by cubic

Adds a warning to the coverage comment when it's too long and gets truncated, instead of only logging the truncation to the job log.

  • New tooLongNotice displays a warning in the comment when the coverage report is dropped.
  • Links to the job log when a run ID is available.
  • Adds unit tests covering the notice text, link behavior, and blockquote formatting.

Written for commit 516234d. Summary will update on new commits.

Review in cubic

@codeant-ai

codeant-ai Bot commented Aug 27, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 516234d Aug 27, 2026 · 19:15 19:17

@codeant-ai

codeant-ai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Surface truncation warnings in oversized coverage comments

✨ Enhancement 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Shows a GitHub warning when oversized comments omit the detailed coverage report.
• Links affected comments to job logs containing report-reduction guidance.
• Adds unit coverage for warning content, link fallback, and blockquote formatting.
Diagram

sequenceDiagram
  participant A as GitHub Action
  participant R as Report Renderer
  participant C as Comment Builder
  participant L as Length Check
  participant J as Job Log
  participant P as PR Comment
  A->>R: Build coverage report
  R-->>C: Return markdown
  C->>L: Measure comment
  alt Over limit
    L-->>C: Reject full report
    C->>J: Log reduction tips
    C->>R: Rebuild hidden report
    R-->>C: Return compact markdown
    C->>P: Post warning and summary
  else Within limit
    L-->>C: Accept report
    C->>P: Post full comment
  end
Loading
High-Level Assessment

The current approach is appropriate: it keeps the in-comment notice short, preserves detailed remediation advice in the existing job warning, and links directly to the relevant run when available. Embedding all reduction suggestions in the comment was reasonably avoided because it would consume more of the already-exceeded size budget.

Files changed (3) +78 / -4

Enhancement (1) +28 / -1
index.tsAdd visible warning when coverage reports are omitted +28/-1

Add visible warning when coverage reports are omitted

• Introduces a compact GitHub warning notice for oversized comments, optionally linking to the current workflow run. Includes the notice in length calculations and inserts it when the detailed coverage report is rebuilt in hidden mode.

src/index.ts

Tests (1) +27 / -1
index.test.tsCover oversized-comment warning output +27/-1

Cover oversized-comment warning output

• Adds unit tests for the maximum-length message, optional job-log link, linkless fallback, and GitHub blockquote formatting.

tests/index.test.ts

Other (1) +23 / -2
index.jsBundle oversized-comment warning behavior +23/-2

Bundle oversized-comment warning behavior

• Regenerates the distributable GitHub Action bundle with the warning helper, run URL construction, comment-length accounting, and final warning insertion.

dist/index.js

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Notice can exceed limit 🐞 Bug ☼ Reliability
Description
After adding tooLongHtml, the fallback only removes failed-test blocks; if the hidden coverage
output plus the summary or multiple-files table remains over 65,536 characters, the new notice
leaves the body oversized and the GitHub comment operation fails. This also affects cases that
previously fit after hiding the report but cross the limit solely because of the added notice and
uncounted final separators/watermark.
Code

src/index.ts[484]

+    tooLongHtml = tooLongNotice(MAX_COMMENT_LENGTH, runUrl);
Evidence
The repository defines the comment maximum as 65,536, but the fallback does not guarantee that its
reductions bring the body below that value. The final body then adds separators and WATERMARK
omitted from commentLength() and passes the result directly to GitHub's comment APIs.

src/index.ts[17-18]
src/index.ts[437-443]
src/index.ts[480-508]
src/index.ts[511-519]
src/index.ts[549-585]
src/multiFiles.ts[48-65]
src/multiFiles.ts[71-84]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Adding the truncation notice can leave the fallback comment above `MAX_COMMENT_LENGTH`, because the existing reductions are conditional and there is no final size enforcement before posting.

## Issue Context
`commentLength()` includes the notice but omits the watermark and assembly separators. After hiding the detailed coverage report, the code only removes failed-test content; an oversized summary or multiple-files table remains untouched and is posted.

## Fix Focus Areas
- src/index.ts[437-443]
- src/index.ts[480-508]
- src/index.ts[511-553]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/index.ts
const runUrl = context.runId
? `${options.repoUrl}/actions/runs/${context.runId}`
: null;
tooLongHtml = tooLongNotice(MAX_COMMENT_LENGTH, runUrl);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Notice can exceed limit 🐞 Bug ☼ Reliability

After adding tooLongHtml, the fallback only removes failed-test blocks; if the hidden coverage
output plus the summary or multiple-files table remains over 65,536 characters, the new notice
leaves the body oversized and the GitHub comment operation fails. This also affects cases that
previously fit after hiding the report but cross the limit solely because of the added notice and
uncounted final separators/watermark.
Agent Prompt
## Issue description
Adding the truncation notice can leave the fallback comment above `MAX_COMMENT_LENGTH`, because the existing reductions are conditional and there is no final size enforcement before posting.

## Issue Context
`commentLength()` includes the notice but omits the watermark and assembly separators. After hiding the detailed coverage report, the code only removes failed-test content; an oversized summary or multiple-files table remains untouched and is posted.

## Fix Focus Areas
- src/index.ts[437-443]
- src/index.ts[480-508]
- src/index.ts[511-553]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/index.ts
summaryReport.length +
failedTestsHtml.length +
multipleFilesHtml.length;
multipleFilesHtml.length +

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The new size accounting can enter this truncation path when multipleFilesHtml itself exceeds the limit, but the fallback only removes failed-test sections when they are present. If the multiple-files report has no failed-test block, it remains oversized and is appended unchanged, so the final GitHub comment can still exceed MAX_COMMENT_LENGTH and be rejected. Add a final fallback that truncates or removes the remaining oversized section before assembling the body. [incorrect control logic]

Severity Level: Major ⚠️
- ❌ Large multiple-file comments can be rejected by GitHub.
- ❌ Coverage comments fail despite the warning notice.
- ⚠️ `getMultipleReport()` has no size truncation fallback.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/index.ts
**Line:** 442:442
**Comment:**
	*Incorrect Control Logic: The new size accounting can enter this truncation path when `multipleFilesHtml` itself exceeds the limit, but the fallback only removes failed-test sections when they are present. If the multiple-files report has no failed-test block, it remains oversized and is appended unchanged, so the final GitHub comment can still exceed `MAX_COMMENT_LENGTH` and be rejected. Add a final fallback that truncates or removes the remaining oversized section before assembling the body.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The change adds the exported tooLongNotice helper. The helper creates a blockquoted warning and optionally links to the job log. The comment-length calculation now includes the notice length. Oversized comments build and append the notice before the summary report. Tests cover the warning text, maximum length, optional link, and blockquote formatting.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🔵 Low · up to 51623

Coverage comments near the configured size limit may still exceed that limit because assembly separators are not included in the check, allowing truncation behavior to remain inaccurate. The change is otherwise mergeable with explicit owner awareness and a small fix to calculate the length from the final assembled comment.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: showing a warning in the coverage comment when the report is too long.
Description check ✅ Passed The description follows the required template, explains the change, records local testing and npm run all, and includes relevant implementation details. The Related Issue field is not linked to a spec…
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

Full details: Description check

Explanation

The description follows the required template, explains the change, records local testing and npm run all, and includes relevant implementation details. The Related Issue field is not linked to a specific issue, but the description is otherwise complete.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1bf13a3d-bd9e-4ca1-94a6-b5402189e2c1

📥 Commits

Reviewing files that changed from the base of the PR and between ce64cfb and 516234d.

⛔ Files ignored due to path filters (1)
  • dist/index.js is excluded by !**/dist/**
📒 Files selected for processing (2)
  • __tests__/index.test.ts
  • src/index.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.

Comment thread src/index.ts
Comment on lines +437 to +443
let tooLongHtml = '';
const commentLength = (): number =>
html.length +
summaryReport.length +
failedTestsHtml.length +
multipleFilesHtml.length;
multipleFilesHtml.length +
tooLongHtml.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Include final assembly separators in the length check.

commentLength() adds tooLongHtml.length, but the final assembly adds \n\n before the notice at Line 513 and before the summary at Line 515. Near MAX_COMMENT_LENGTH, the check can pass while the emitted comment exceeds the configured limit. Calculate the length from the assembled comment, including separators.

Also applies to: 512-514

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/index.ts">

<violation number="1" location="src/index.ts:513">
P1: Enforce `MAX_COMMENT_LENGTH` after assembling the fallback comment. Hiding the coverage report does not guarantee that the summary or multiple-files section fits, so this path can still submit an oversized comment.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/index.ts

finalHtml += html;
if (tooLongHtml) {
finalHtml += finalHtml.length ? `\n\n${tooLongHtml}` : tooLongHtml;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Enforce MAX_COMMENT_LENGTH after assembling the fallback comment. Hiding the coverage report does not guarantee that the summary or multiple-files section fits, so this path can still submit an oversized comment.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/index.ts, line 513:

<comment>Enforce `MAX_COMMENT_LENGTH` after assembling the fallback comment. Hiding the coverage report does not guarantee that the summary or multiple-files section fits, so this path can still submit an oversized comment.</comment>

<file context>
@@ -485,6 +509,9 @@ const main = async (): Promise<void> => {
 
   finalHtml += html;
+  if (tooLongHtml) {
+    finalHtml += finalHtml.length ? `\n\n${tooLongHtml}` : tooLongHtml;
+  }
   finalHtml += finalHtml.length ? `\n\n${summaryReport}` : summaryReport;
</file context>

@mschoettle

Copy link
Copy Markdown
Contributor Author

@MishaKav The issue found is pre-existing. We could fix it but I think it would be better separately. WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant