[test-improver] Improve tests for version.BuildVersionString by github-actions[bot] · Pull Request #8386 · github/gh-aw-mcpg · GitHub
Skip to content

[test-improver] Improve tests for version.BuildVersionString#8386

Merged
lpcox merged 1 commit into
mainfrom
test-improver/version-build-string-coverage-a9e2b0bb6d792dd5
Jul 1, 2026
Merged

[test-improver] Improve tests for version.BuildVersionString#8386
lpcox merged 1 commit into
mainfrom
test-improver/version-build-string-coverage-a9e2b0bb6d792dd5

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

File analyzed

internal/version/version_test.go (and production internal/version/version.go)

Problem

BuildVersionString had two uncovered branches — the inner bodies executed when debug.ReadBuildInfo() returns a non-empty vcs.revision (lines 92–94) or vcs.time (lines 100–102). These are the "auto-detect from binary build info" fallback paths that run when the caller passes empty gitCommit or buildDate.

BuildVersionString  89.5%  (package total 95.1%)

Changes

internal/version/version.go

Extracted debug.ReadBuildInfo into a package-level variable:

var readBuildInfo = debug.ReadBuildInfo

BuildVersionString now calls readBuildInfo() instead of debug.ReadBuildInfo() directly. This is a zero-cost indirection — the variable holds the exact same function pointer at runtime, but allows tests to inject a deterministic replacement without any API changes.

internal/version/version_test.go

Added TestBuildVersionString_FallbackFromBuildInfo with five subtests that override readBuildInfo and restore it via t.Cleanup:

Subtest What it covers
uses truncated vcs.revision when gitCommit is empty line 93 — commit appended from build info
uses vcs.time when buildDate is empty line 101 — date appended from build info
uses both vcs fields when both are empty lines 93 + 101 together
build info unavailable (ok=false) else branch — nothing appended
build info available but no vcs settings inner if not taken — nothing appended

Coverage

Metric Before After
BuildVersionString 89.5% 100%
Package total 95.1% 100%

Test output

ok  github.com/github/gh-aw-mcpg/internal/version   0.003s  coverage: 100.0% of statements

All existing tests continue to pass.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • index.crates.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "index.crates.io"

See Network Configuration for more information.

Generated by Test Improver · 82.2 AIC · ⊞ 5.6K ·

Add tests for the two branches in BuildVersionString where empty
gitCommit or buildDate fall back to debug.ReadBuildInfo(). These
branches were previously uncovered (lines 92-94, 100-102).

To enable injection without API changes, extract debug.ReadBuildInfo
into a package-level var readBuildInfo. Tests override this var to
supply deterministic mock build info, covering:
- vcs.revision used when gitCommit is empty
- vcs.time used when buildDate is empty
- both fields used when both are empty
- build info unavailable (ok=false)
- build info available but no vcs settings

Coverage: BuildVersionString 89.5% → 100%, package 95.1% → 100%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review July 1, 2026 14:43
Copilot AI review requested due to automatic review settings July 1, 2026 14:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves test coverage for internal/version.BuildVersionString by making the build-info fallback paths deterministic under test, while keeping the public API unchanged.

Changes:

  • Introduced a package-level readBuildInfo variable (defaulting to debug.ReadBuildInfo) so tests can inject build info.
  • Added TestBuildVersionString_FallbackFromBuildInfo to cover vcs.revision and vcs.time fallback branches (including “no build info” and “no vcs settings” cases).
Show a summary per file
File Description
internal/version/version.go Adds a test seam (readBuildInfo) and updates fallback calls to use it.
internal/version/version_test.go Adds deterministic subtests to cover the build-info fallback branches and reach 100% coverage.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@lpcox lpcox merged commit 33b68cd into main Jul 1, 2026
23 checks passed
@lpcox lpcox deleted the test-improver/version-build-string-coverage-a9e2b0bb6d792dd5 branch July 1, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants