Erroneous coverage report in merge request Changes tab

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

Documentation reference (https://docs.gitlab.com/ci/testing/code_coverage/#view-coverage-results), specifically this part:

Merge request diff: Review which lines are covered by tests. Available with Cobertura and JaCoCo reports.

Knowing that, I have a come across many case where the coverage report is wrongly displayed.

Steps to reproduce

See simple example project below for more details.

In a nutshell:

  • Make sure you have a project with coverage collection in the pipeline. I use python with the coverage package, but I assume anything that can produce the cobertura format can cause the problem.
  • Create a branch with some code changes (we'll call it branch1).
  • Create another change in the main with the following rule:
    • Same file as change in branch1.
    • Add or remove code lines above the change done in branch1. The goal here is to shift line numbers.
  • Create a MR for branch1.
  • Go to the "Changes" tab in the MR.

Example Project

mathieugouin/project2!6 (diffs)

What is the current bug behavior?

Because of the line shift in main, the coverage report is completely irrelevant. See how line7 is marked as non-covered, which is impossible.

I understand that the diff view present the diff of what "would" happen after the merge. It presents changes in main as if they were already merged in the source branch. This makes the line number not match the line numbers provided by the coverage tool.

image

What is the expected correct behavior?

Have proper coverage report line up properly in the diff view.

Output of checks

This bug happens on GitLab.com

Edited by 🤖 GitLab Bot 🤖