Skip to content

Commit ff2b5fb

Browse files
Ambient Code Botclaude
andcommitted
ci: fix diff-cover path resolution for mono-repo coverage
Each sub-package's coverage.xml records filenames relative to the package directory (e.g. "jumpstarter_cli_common/oidc.py"), but diff-cover resolves paths relative to the git root. This mismatch caused diff-cover to miss coverage data from per-package test runs, resulting in artificially low coverage percentages on changed lines. Fix by injecting the correct <source> element into each coverage.xml before running diff-cover, allowing it to reconstruct absolute paths that match the git diff output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e307bdb commit ff2b5fb

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

.github/workflows/python-tests.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ jobs:
122122
run: |
123123
make test
124124
125+
- name: Fix coverage.xml source paths for diff-cover
126+
if: github.event_name == 'pull_request'
127+
working-directory: python
128+
run: |
129+
# Each package's coverage.xml records filenames relative to the
130+
# package directory (e.g. "my_pkg/foo.py"), but diff-cover resolves
131+
# paths from the git root. Inject the correct <source> element so
132+
# diff-cover can map coverage data back to git diff paths.
133+
for f in $(find packages -name coverage.xml 2>/dev/null); do
134+
pkg_dir="$(cd "$(dirname "$f")" && pwd)"
135+
python3 -c "
136+
import xml.etree.ElementTree as ET, sys
137+
tree = ET.parse(sys.argv[1])
138+
sources = tree.getroot().find('sources')
139+
for s in sources.findall('source'):
140+
sources.remove(s)
141+
el = ET.SubElement(sources, 'source')
142+
el.text = sys.argv[2]
143+
tree.write(sys.argv[1], xml_declaration=True)
144+
" "$f" "$pkg_dir"
145+
done
146+
125147
- name: Check coverage on changed lines
126148
if: github.event_name == 'pull_request'
127149
working-directory: python

0 commit comments

Comments
 (0)