Skip to content

[plugin-coverage] resolve config/codeowners blob sha at the reported commit#2311

Merged
nikita-tkachenko-datadog merged 3 commits into
masterfrom
nikita.tkachenko/coverage-config-blob-sha-at-reported-commit
May 11, 2026
Merged

[plugin-coverage] resolve config/codeowners blob sha at the reported commit#2311
nikita-tkachenko-datadog merged 3 commits into
masterfrom
nikita.tkachenko/coverage-config-blob-sha-at-reported-commit

Conversation

@nikita-tkachenko-datadog

Copy link
Copy Markdown
Contributor

Summary

  • Coverage uploads previously took the blob SHA of code-coverage.datadog.{yml,yaml} and CODEOWNERS from local HEAD (git rev-parse HEAD:<path>), while the commit SHA on the same payload comes from CI env vars (GIT_HEAD_SHA || GIT_SHA). Those two values aren't tied to each other — when they diverge, the splitter receives a (commit, path, blob_sha) triple where the file isn't actually in the reported commit's tree.
  • This causes downstream ci-coverage-splitter to call source-code-query.GetCodeContent with that triple, get NotFound: resource not found, retry 10× (NotFound is treated as transient), then reject/stash the event. Coverage silently disappears for that build.
  • Fix: resolve the blob SHA against the same commit that ends up on the wire (git rev-parse <reportedCommit>:<path>). The triple becomes internally consistent by construction; if the file isn't at that commit, getRepoFile returns undefined and the splitter falls back to its gitdb lookup as before.

Why local HEAD and the reported commit diverge in practice

  • GitHub Actions PR builds check out the synthetic refs/pull/N/merge ref; HEAD's tree contains files brought in by merging with the base, but GITHUB_SHA (and therefore the reported commit) is the PR head. Files added on base only land in the merge tree, not at the PR head.
  • DD_GIT_COMMIT_SHA / --git-commit-sha overrides the commit reported on the payload but not the blob computation.
  • CI generates/commits the config locally before upload — local HEAD has it, but that commit isn't pushed and doesn't match the reported commit.
  • Any detached-HEAD setup where env vars and the working tree don't agree.

Repro that motivated this

A real prod failure: ci-coverage-splitter rejected events for github.com/gojitsucom/mobile-warehouse-flutter with

*fmt.wrapError: failed to split coverage data for event:
  failed to get code content: rpc error: code = NotFound desc = resource not found
  • Reported commit_sha: c0f9b4840cca576286661e5af25b666261e56919 — gitdb tree at that commit has 2,015 files, none named code-coverage.datadog.yml.
  • Reported (path, blob_sha): code-coverage.datadog.yml, dbf70404459f7c35ee75ae1621e8a4af4c128af2.
  • Sibling commit f71ded839e08d43c221fa827c39801320c343d1c does contain code-coverage.datadog.yml, and its blob SHA there is exactly dbf70404459f7c35ee75ae1621e8a4af4c128af2 — i.e. the upload was generated when local HEAD pointed at f71ded8… while CI declared c0f9b484… as the commit.

After this change, the blob sha is taken from c0f9b484…:code-coverage.datadog.yml, which doesn't exist → getRepoFile returns undefined → splitter falls back to gitdb (which won't find it either, but that path is handled gracefully and doesn't reject the event).

Test plan

  • yarn build clean
  • yarn lint clean
  • yarn test packages/plugin-coverage packages/base/src/commands/git-metadata — all 160 tests pass
  • Manual end-to-end on a CI provider where local HEAD differs from the reported commit (e.g., a GitHub Actions PR build) and confirm:
    • when the file exists at the reported commit, it is shipped and resolved correctly downstream;
    • when it doesn't, getRepoFile returns undefined (no event rejection downstream).

🤖 Generated with Claude Code

…commit

Coverage uploads previously computed the blob SHA of code-coverage.datadog.{yml,yaml}
and CODEOWNERS via `git rev-parse HEAD:<path>`, while the commit SHA reported in
the same payload comes from CI env vars (GIT_HEAD_SHA || GIT_SHA). When local HEAD
and the reported commit diverge — common on GitHub Actions PR builds (synthetic
merge ref vs PR head SHA), with DD_GIT_COMMIT_SHA overrides, or any detached-HEAD
setup — the resulting (commit, path, blob_sha) triple is internally inconsistent:
the file may exist at HEAD but not at the reported commit.

The downstream ci-coverage-splitter then asks source-code-query for that triple
and gets NotFound (rpc error: code = NotFound desc = resource not found), causing
the event to be rejected/stashed and coverage to silently disappear for the build.

Resolve the blob SHA against the same commit that goes on the wire so the triple
is consistent by construction. If the file isn't present at that commit,
`getRepoFile` returns undefined and the splitter falls back to its gitdb lookup
as before.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@nikita-tkachenko-datadog nikita-tkachenko-datadog added the software-delivery Related to [coverage, deployment, dora, junit, measure, tag, trace] label May 7, 2026
nikita-tkachenko-datadog and others added 2 commits May 7, 2026 14:42
The fallback `spanTags[GIT_HEAD_SHA] || spanTags[GIT_SHA]` is what ends up on
the wire (api.ts spreads `...payload.spanTags`, splitter reads it as
`coalesce(HeadSHA, SHA)`). Three call sites in upload.ts had it inline; extract
a tiny helper so they can't drift from each other or from the wire format.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- getGitFileHash: lock in HEAD-by-default and ref-forwarding behavior
- getRepoFile: short-circuit when git or ref is missing, resolve against
  the provided ref, and fall through to the next candidate path on miss

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@nikita-tkachenko-datadog
nikita-tkachenko-datadog marked this pull request as ready for review May 8, 2026 09:00
@nikita-tkachenko-datadog
nikita-tkachenko-datadog requested review from a team as code owners May 8, 2026 09:00
@nikita-tkachenko-datadog
nikita-tkachenko-datadog merged commit 3c2fc74 into master May 11, 2026
28 checks passed
@nikita-tkachenko-datadog
nikita-tkachenko-datadog deleted the nikita.tkachenko/coverage-config-blob-sha-at-reported-commit branch May 11, 2026 12:37
@Drarig29 Drarig29 mentioned this pull request May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

software-delivery Related to [coverage, deployment, dora, junit, measure, tag, trace]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants