Repository navigation
Conversation
…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
|
🔍 OpenCodeReview found 4 issue(s) in this PR.
|
| 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."); |
There was a problem hiding this comment.
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"}).` |
There was a problem hiding this comment.
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:
| ? `Review did not complete (status=${resolveRunStatus(result) || "unknown"}).` | |
| ? `Review did not complete (status=${runStatus || "unknown"}).` |
| const lead = incomplete | ||
| ? `${coverageBanner}\n\n${message}` | ||
| : `${warningBlock ? "⚠️" : "✅"} **OpenCodeReview**: ${message}`; |
There was a problem hiding this comment.
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.
| 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; | ||
| } |
There was a problem hiding this comment.
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:
| 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.
Fixes #2103
Summary
Both CI integrations reported findings without ever saying whether the review actually finished. A
partialorfailedreport now identifies itself at the top of the PR/MR summary: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 frommanifest.terminal_state, falling back to the top-levelstatus;completed_with_errors(which only occurs without a manifest) is treated as incomplete with coverage unavailable.completed + reusedover theselecteddenominator;waivedis stated separately so the counts add up (a waiver is not a review);excludedstays outside the denominator; unfinished paths come fromcoverage.failed[]with their recordedclassification/reason. Without coverage the banner says so instead of inventing counts or causes. Complete runs render byte-identically to before.action.yml:Post review commentsnow runs beforeFail job on OCR errorand on a non-zero review exit too (if: ${{ !cancelled() }}), mirroring the GitLab example pipeline; the job still fails with the originalOCR_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 onterminal_state == "complete".Design notes
completed + reused + failedsmaller thanselected; the banner appends "; N waived" to the headline so the numbers still add up.completed_with_errorsis treated as incomplete (partial/failedwith 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 testpublish before failing on a non-zero review exitpasses. The 37 fixture failures that also fail on unmodifiedmainare a local Windows limitation (the harness spawns/bin/bashdirectly, 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.ocr reviewpre-commit review from AGENTS.md was not run: theocrCLI is not installed in this environment.