Skip to content

test: add unit tests for pkg/version package#198

Open
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
mason5052:test/version-package-coverage
Open

test: add unit tests for pkg/version package#198
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
mason5052:test/version-package-coverage

Conversation

@mason5052
Copy link
Contributor

Description of Change

Problem: The pkg/version package has no unit test coverage. The package provides binary version, name, and development mode detection used throughout the application.

Solution: Add comprehensive unit tests for all three exported functions (GetBinaryVersion, IsDevelopMode, GetBinaryName) covering all code paths including default values, custom values, and combined version-revision formatting.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Security update
  • Test update
  • Documentation update
  • Configuration change

Areas Affected

  • Core Services (Frontend UI / Backend API)
  • AI Agents (Researcher / Developer / Executor)
  • Security Tools Integration
  • Memory System (Vector Store / Knowledge Base)
  • Monitoring Stack (Grafana / OpenTelemetry)
  • Analytics & Reporting
  • External Integrations (LLM Providers / Search Engines / Security APIs)
  • Documentation
  • Infrastructure / DevOps

Testing and Verification

Test Configuration

  • PentAGI Version: v1.2.0 (master)
  • Go Version: 1.24.1
  • Host OS: Windows 11

Test Steps

  1. Run go test ./pkg/version/... -v

Test Results

=== RUN   TestGetBinaryVersion_Default
--- PASS: TestGetBinaryVersion_Default (0.00s)
=== RUN   TestGetBinaryVersion_WithVersion
--- PASS: TestGetBinaryVersion_WithVersion (0.00s)
=== RUN   TestGetBinaryVersion_WithVersionAndRevision
--- PASS: TestGetBinaryVersion_WithVersionAndRevision (0.00s)
=== RUN   TestGetBinaryVersion_WithRevisionOnly
--- PASS: TestGetBinaryVersion_WithRevisionOnly (0.00s)
=== RUN   TestIsDevelopMode_True
--- PASS: TestIsDevelopMode_True (0.00s)
=== RUN   TestIsDevelopMode_False
--- PASS: TestIsDevelopMode_False (0.00s)
=== RUN   TestGetBinaryName_Default
--- PASS: TestGetBinaryName_Default (0.00s)
=== RUN   TestGetBinaryName_Custom
--- PASS: TestGetBinaryName_Custom (0.00s)
PASS
ok  	pentagi/pkg/version	4.393s

Checklist

  • Code follows project coding standards
  • Tests added for changes
  • All tests pass
  • go fmt and go vet run
  • Changes are backward compatible

Add comprehensive unit tests for GetBinaryVersion, IsDevelopMode, and
GetBinaryName functions covering all code paths including default values,
custom values, and combined version-revision formatting.
Copilot AI review requested due to automatic review settings March 12, 2026 17:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds initial unit test coverage for the backend/pkg/version package, which provides binary name/version and “develop mode” detection used across the application.

Changes:

  • Adds unit tests for GetBinaryVersion() covering default, version-only, revision-only, and version+revision cases.
  • Adds unit tests for IsDevelopMode() for both develop and non-develop scenarios.
  • Adds unit tests for GetBinaryName() covering default and custom binary names.

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

Comment on lines +9 to +15
func TestGetBinaryVersion_Default(t *testing.T) {
PackageVer = ""
PackageRev = ""

result := GetBinaryVersion()
assert.Equal(t, "develop", result)
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

This test mutates package-level globals (PackageVer/PackageRev) but doesn’t restore their previous values at the end. That makes tests order-dependent and can leak state into subsequent tests in this package. Consider capturing the original values at the start and restoring them via defer (or t.Cleanup) so the test is isolated.

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +24
func TestGetBinaryVersion_WithVersion(t *testing.T) {
PackageVer = "1.2.0"
PackageRev = ""
defer func() { PackageVer = "" }()

result := GetBinaryVersion()
assert.Equal(t, "1.2.0", result)
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

This test sets both PackageVer and PackageRev, but the cleanup only resets PackageVer and also doesn’t restore the prior PackageRev value. To avoid cross-test leakage, save the old values of both globals and restore both in the deferred cleanup.

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +51
func TestIsDevelopMode_True(t *testing.T) {
PackageVer = ""

assert.True(t, IsDevelopMode())
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

PackageVer is mutated here without any cleanup. If another test relies on a different PackageVer value, this can cause flakiness depending on execution order. Save/restore the previous value (defer or t.Cleanup) to keep this test isolated.

Copilot uses AI. Check for mistakes.
Comment on lines +60 to +65
func TestGetBinaryName_Default(t *testing.T) {
PackageName = ""

result := GetBinaryName()
assert.Equal(t, "pentagi", result)
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

PackageName is assigned here but not restored afterwards. Restoring the previous value at the end of the test avoids leaking state into other tests in this package (especially if future tests start running in parallel).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants