Skip to content

Implement differential code coverage - #96738

Merged
alexbakharew merged 81 commits into
masterfrom
abakharew/differential-code-coverage
Mar 7, 2026
Merged

alexbakharew merged 81 commits into
masterfrom
abakharew/differential-code-coverage

Conversation

@alexbakharew

@alexbakharew alexbakharew commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Documentation entry for user-facing changes

Extend LLVM Coverage job to be able to see difference in coverage between master and current branches. The job is designed to fail once the coverage value is degraded. The uncovered code blocks will shown in log.

In Praktika report there will be links to 2 reports: one report for all repository coverage and one only for changed files in current PR.


Note

Medium Risk
CI workflow and coverage artifact plumbing changes can break coverage generation or job dependencies, and the small MergeTree key-condition fix could affect partition pruning edge cases for Date/DateTime conversions.

Overview
Implements differential LLVM coverage in CI. Replaces the old merge-only coverage job with a new llvm_coverage_job.py that generates full and diff HTML reports against a master baseline, computes coverage deltas, and surfaces uncovered changed-line blocks.

Expands and rewires LLVM coverage inputs. PR and master workflows add a dedicated build_llvm_coverage_build job, add LLVM-coverage variants of unit/integration/stateless tests (including special S3/AsyncInsert/old-analyzer runs), update artifact naming to be parameter-based, and drop the standalone HTML report artifact in favor of uploading report directories/files.

Adds reporting hooks and dependencies. Introduces a post-hook that posts a fresh tagged PR comment and writes coverage results to CIDB, adds gh/SSH/requests tooling to the test image, stores merge-base metadata, and fixes KeyCondition.cpp to unwrap nullable results before Date/DateTime overflow checks.

Written by Cursor Bugbot for commit beabaa1. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.3.1.499

@clickhouse-gh

clickhouse-gh Bot commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [beabaa1]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Feb 12, 2026
@alexbakharew alexbakharew changed the title Add .info file to LLVM Coverage report Implement differential code coverage Feb 12, 2026
Comment thread ci/jobs/llvm_coverage_job.py Resolved
Comment thread ci/jobs/scripts/print_uncovered_code.py Resolved
# Baseline coverage percentages for the current branch (from the merged report)
b_line_cov, b_function_cov, b_branch_cov = get_lcov_summary_percentages(
f"{TEMP_DIR}/base_llvm_coverage.info"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing file existence check crashes coverage job

High Severity

generate_diff_coverage_report.sh exits 0 early without creating base_llvm_coverage.info when no baseline coverage is found in S3 (line 28) or no changed files are detected (line 50). However, llvm_coverage_job.py unconditionally calls get_lcov_summary_percentages() on base_llvm_coverage.info right after, which uses strict=True and will raise an exception when the file doesn't exist. This crashes the entire LLVM coverage job for any PR where no ancestor commit has coverage data in S3.

Additional Locations (1)

Fix in Cursor Fix in Web

Comment thread ci/jobs/llvm_coverage_job.py Resolved

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

# Baseline coverage percentages for the current branch (from the merged report)
b_line_cov, b_function_cov, b_branch_cov = get_lcov_summary_percentages(
f"{TEMP_DIR}/base_llvm_coverage.info"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Crash when base coverage file is unavailable

High Severity

generate_diff_coverage_report.sh exits with code 0 (success) when it can't find a base coverage file among the 30 ancestor commits (line 28) or when no changed files are reported (line 50). Despite these early exits, llvm_coverage_job.py unconditionally calls get_lcov_summary_percentages on base_llvm_coverage.info, which doesn't exist. Since Shell.get_output uses strict=True, this raises an unhandled exception that crashes the entire LLVM Coverage job. This will happen for every PR until sufficient master branch coverage data accumulates in S3.

Additional Locations (1)

Fix in Cursor Fix in Web

Comment thread ci/praktika/gh.py
output = Shell.get_output(cmd_list, verbose=verbose)
if output:
try:
for comment in json.loads(output):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Paginated GitHub API response breaks JSON parsing

Low Severity

post_fresh_comment uses gh api --paginate with --jq, which applies the jq expression per page and concatenates the results. When there are multiple pages of PR comments, the output becomes multiple JSON arrays like [...][...], which is not valid JSON. json.loads will fail, and the exception handler silently swallows the error, meaning old coverage comments won't be deleted — leading to duplicate comments accumulating on the PR.

Fix in Cursor Fix in Web

@clickhouse-gh

clickhouse-gh Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.20% 83.90% +0.70%
Functions 23.60% 23.90% +0.30%
Branches 75.30% 76.40% +1.10%

PR changed lines: PR changed-lines coverage: 95.24% (20/21)
Diff coverage report
Uncovered code

@alexbakharew
alexbakharew enabled auto-merge March 7, 2026 11:58
@alexbakharew
alexbakharew added this pull request to the merge queue Mar 7, 2026
Merged via the queue into master with commit 2633209 Mar 7, 2026
312 of 313 checks passed
@alexbakharew
alexbakharew deleted the abakharew/differential-code-coverage branch March 7, 2026 19:22
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 7, 2026
@alexey-milovidov

alexey-milovidov commented Mar 9, 2026 •

Copy link
Copy Markdown
Member

@alexbakharew, it broken CI in PRs with no code changes. I'm fixing it in #99032.

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

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants