Skip to content

fix(ci): surface incomplete review coverage in GitHub and GitLab summaries - #2108

Open
wzxsdf wants to merge 2 commits into
alibaba:mainfrom
wzxsdf:fix/issue-2103-partial-coverage-summaries
Open

wzxsdf wants to merge 2 commits into
alibaba:mainfrom
wzxsdf:fix/issue-2103-partial-coverage-summaries

Conversation

@wzxsdf

@wzxsdf wzxsdf commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #2103

Summary

Both CI integrations reported findings without ever saying whether the review actually finished. A partial or failed report now identifies itself at the top of the PR/MR summary:

⚠️ Partial review: 2 of 3 selected file(s) reviewed.

Not completed:

  • src/b.go (budget: token budget reached)
  • Publishers (scripts/github-actions/post-review-comments.js, examples/gitlab_ci/post_review.py): one coverage banner rendered on all three summary routes (zero-findings, pre-review anchor, final summary). Status comes from manifest.terminal_state, falling back to the top-level status; completed_with_errors (which only occurs without a manifest) is treated as incomplete with coverage unavailable.
  • Counting follows the issue's acceptance criteria: reviewed = completed + reused over the selected denominator; waived is stated separately so the counts add up (a waiver is not a review); excluded stays outside the denominator; unfinished paths come from coverage.failed[] with their recorded classification/reason. Without coverage the banner says so instead of inventing counts or causes. Complete runs render byte-identically to before.
  • action.yml: Post review comments now runs before Fail job on OCR error and on a non-zero review exit too (if: ${{ !cancelled() }}), mirroring the GitLab example pipeline; the job still fails with the original OCR_EXIT_CODE. A budget-only partial keeps its historical zero exit, so it does not become a failing check. Checkpoint behavior is unchanged — advancement remains gated on terminal_state == "complete".

Design notes

  • Waived items make completed + reused + failed smaller than selected; the banner appends "; N waived" to the headline so the numbers still add up.
  • A report without a manifest whose status is completed_with_errors is treated as incomplete (⚠️, coverage unavailable) — it means subtask errors fired and no coverage was recorded.
  • The two fix(gitlab_ci): stop posting a check-mark LGTM on a failed review #1999-era GitLab tests pinned the exact pre-banner body for partial/failed with no coverage; they are updated to the new body shape with the same intent (never ✅/LGTM).

AI disclosure

Per the contributing guidelines: ZCode with the GLM model (bigmodel) was used to inspect the integration code, draft the change, and write the tests. The contributor has reviewed every line of the diff.

Testing

  • node scripts/github-actions/post-review-comments.test.js — all pass, including the new partial/failed banner cases (with and without findings, empty warnings, no-coverage, checkpoint not advancing) and exact-body checks that complete reviews render as before.
  • python3 -m unittest discover -s examples/gitlab_ci -p '*_test.py' — 162 tests OK, including the new banner cases.
  • node scripts/github-actions/action-contract.test.js — the new contract test publish before failing on a non-zero review exit passes. The 37 fixture failures that also fail on unmodified main are a local Windows limitation (the harness spawns /bin/bash directly, which Node cannot resolve on win32); CI runs them on Linux.
  • make check — passes (license-check, english-check, go mod tidy, gofmt, go vet) with Go 1.27.4.
  • The ocr review pre-commit review from AGENTS.md was not run: the ocr CLI is not installed in this environment.

…aries

A partial or failed review used to render like a complete one: both
publishers led with posting statistics or an LGTM glyph, and the GitHub
Action skipped publication entirely on a non-zero review exit. Summaries
now lead with a coverage banner built from the run's manifest, and the
Action publishes before failing with the original exit code.

Fixes alibaba#2103
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 4 issue(s) in this PR.

  • ✅ Successfully posted inline: 4 comment(s)

Comment on lines +342 to +347
const message = result.message
|| (warningBlock
? "No comments generated. See warnings below."
: "No comments generated. Looks good to me.");
const icon = warningBlock ? "⚠️" : "✅";
// A clean run is still a complete run: this path advances the checkpoint.
// Warnings are not an input to that decision.
|| (incomplete
? `Review did not complete (status=${resolveRunStatus(result) || "unknown"}).`
: warningBlock
? "No comments generated. See warnings below."
: "No comments generated. Looks good to me.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maintainability · medium
Nested ternary expression: this three-level nested ternary (incomplete ? ... : warningBlock ? ... : ...) reduces readability and violates common code quality guidelines that prohibit nested ternaries. Consider refactoring into a helper function or if/else chain for clarity.

For example:

let message;
if (result.message) {
  message = result.message;
} else if (incomplete) {
  message = `Review did not complete (status=${resolveRunStatus(result) || "unknown"}).`;
} else if (warningBlock) {
  message = "No comments generated. See warnings below.";
} else {
  message = "No comments generated. Looks good to me.";
}

// A clean run is still a complete run: this path advances the checkpoint.
// Warnings are not an input to that decision.
|| (incomplete
? `Review did not complete (status=${resolveRunStatus(result) || "unknown"}).`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maintainability · low
resolveRunStatus(result) is called twice in this block — once at line 341 to compute incomplete, and again here inside the template literal. Since it's a pure function, store the result in a variable to avoid the redundant call and improve readability.

Suggestion:

Suggested change
? `Review did not complete (status=${resolveRunStatus(result) || "unknown"}).`
? `Review did not complete (status=${runStatus || "unknown"}).`

Comment on lines +350 to +352
const lead = incomplete
? `${coverageBanner}\n\n${message}`
: `${warningBlock ? "⚠️" : "✅"} **OpenCodeReview**: ${message}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maintainability · low
The withBanner helper (line 328) was introduced to consistently prepend the coverage banner, but this no-comments incomplete path manually concatenates ${coverageBanner}\n\n${message} instead of using it. While the formatting here is slightly different (the banner is part of lead rather than prepended to the full body), this duplication means that if the separator convention or banner format changes, two places need updating. Consider either using withBanner here too (by restructuring lead) or adding a comment explaining why this path intentionally diverges.

Comment on lines +2451 to +2455
function formatUnfinishedCoverageItem(item) {
const path = item && item.path ? `\`${item.path}\`` : "`(unknown path)`";
const details = [item && item.classification, item && item.reason].filter(Boolean).join(": ");
return details ? `${path} (${details})` : path;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security · medium
The item.reason and item.classification values are interpolated directly into Markdown output without any escaping. While the comment states the CLI sanitizes these values, defense-in-depth suggests applying at least control-character stripping (e.g., sanitizeMetadata, which is already defined in this file and exported) at the rendering layer as well. This script consumes external JSON, and relying solely on upstream sanitization is fragile — a future CLI change or an alternative producer could bypass that assumption.

Similarly, item.path is wrapped in backticks but not sanitized; a path containing a backtick could break out of the inline code span.

Suggestion:

Suggested change
function formatUnfinishedCoverageItem(item) {
const path = item && item.path ? `\`${item.path}\`` : "`(unknown path)`";
const details = [item && item.classification, item && item.reason].filter(Boolean).join(": ");
return details ? `${path} (${details})` : path;
}
function formatUnfinishedCoverageItem(item) {
const rawPath = item && item.path ? sanitizeMetadata(item.path) : "(unknown path)";
const path = `\`${rawPath.replace(/`/g, "")}\``;
const classification = item && item.classification ? sanitizeMetadata(item.classification) : null;
const reason = item && item.reason ? sanitizeMetadata(item.reason) : null;
const details = [classification, reason].filter(Boolean).join(": ");
return details ? `${path} (${details})` : path;
}

Render unfinished-coverage fields through the existing control-character
sanitizer and drop backticks before embedding paths in code spans, so a
hostile report cannot break the summary layout. Hoist the run status
lookup, replace the nested ternary fallback with an if/else chain, and
reuse withBanner on the zero-findings path.

This branch has not been deployed

No deployments
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.

fix(ci): show incomplete review coverage in GitHub PR and GitLab MR summaries

1 participant