Skip to content

Conversation

@github-actions
Copy link
Contributor

Daily Test Coverage Improver - Audit Report Helper Functions

This PR adds comprehensive unit tests for three previously untested helper functions in pkg/cli/audit_report.go.

Summary of Changes

Added unit tests for:

  • calculateDirectorySize() - Directory size calculation utility
  • parseDurationString() - Duration string parsing utility
  • truncateString() - String truncation with ellipsis

Problems Found

During coverage analysis, I identified three pure utility functions in pkg/cli/audit_report.go that had 0% test coverage:

  • calculateDirectorySize() (line 281)
  • parseDurationString() (line 298)
  • truncateString() (line 550)

These are low-hanging fruit for coverage improvement as they:

  • Have no external dependencies
  • Contain pure logic that's easy to test
  • Don't require complex mocking

Actions Taken

Created pkg/cli/audit_report_helpers_test.go with:

TestCalculateDirectorySize (4 test cases)

  • Empty directory
  • Single file
  • Multiple files in nested directories
  • Nonexistent directory (error handling)

TestParseDurationString (7 test cases)

  • Valid durations (seconds, minutes, hours)
  • Complex duration strings (1h30m45s)
  • Invalid input handling
  • Empty string handling
  • Zero duration

TestTruncateString (8 test cases)

  • String shorter than max length
  • String equal to max length
  • String longer than max length
  • Edge cases (max length ≤ 3)
  • Empty string
  • Unicode string handling

Test Coverage Results

Metric Before After Change
Overall Coverage 65.3% 65.4% +0.1%
calculateDirectorySize() 0.0% 100.0% +100.0%
parseDurationString() 0.0% 100.0% +100.0%
truncateString() 0.0% 100.0% +100.0%

Replicating the Test Coverage Measurements

# Before measurements
cd /home/runner/work/gh-aw/gh-aw
go test -coverprofile=coverage-before.out -covermode=atomic ./...
go tool cover -func=coverage-before.out | tail -1
# Output: total: (statements) 65.3%

# After measurements
go test -coverprofile=coverage-after.out -covermode=atomic ./...
go tool cover -func=coverage-after.out | tail -1
# Output: total: (statements) 65.4%

# Check specific function coverage
go tool cover -func=coverage-after.out | grep "audit_report.go" | grep -E "(calculateDirectorySize|parseDurationString|truncateString)"
# All three functions show 100.0% coverage

Possible Other Areas for Future Improvement

Based on my coverage analysis, here are high-value targets for future test additions:

Low-Complexity Pure Functions (0% coverage):

  1. pkg/cli/ci.go:IsRunningInCI() - Simple environment check
  2. pkg/constants/constants.go - Constant definitions (easily testable)
  3. pkg/cli/audit_report.go:renderOverview() - Console rendering (can be tested with output capture)
  4. pkg/cli/audit_report.go:renderMetrics() - Metrics rendering

Medium-Complexity Functions (low coverage):
5. pkg/cli/audit_report.go:extractDownloadedFiles() - 27.8% coverage
6. pkg/workflow/validation.go:collectPackagesFromWorkflow() - 29.7% coverage
7. pkg/cli/logs.go:downloadRunArtifacts() - 33.3% coverage

These represent opportunities for incremental coverage improvements without requiring extensive mocking infrastructure.

Verification

All tests run successfully:

cd /home/runner/work/gh-aw/gh-aw
make test-unit
# All tests pass

Bash Commands Run
# Created new branch
git checkout -b test-coverage-audit-report-helpers-1761532712

# Created test file
# pkg/cli/audit_report_helpers_test.go

# Ran tests
go test -v -run "TestCalculateDirectorySize|TestParseDurationString|TestTruncateString" ./pkg/cli/

# Generated coverage
go test -coverprofile=coverage-new.out -covermode=atomic ./...

# Compared coverage
go tool cover -func=coverage.out | tail -1
go tool cover -func=coverage-new.out | tail -1

# Verified specific function coverage
go tool cover -func=coverage-new.out | grep "audit_report.go" | grep -E "(calculateDirectorySize|parseDurationString|truncateString)"

# Formatted code
make fmt

# Attempted linting (golangci-lint not available in runner)
make lint

# Committed changes
git add pkg/cli/audit_report_helpers_test.go
git commit -m "Add unit tests for audit report helper functions..."
Web Searches Performed

None - this work was based on static code analysis of the existing codebase.

Web Pages Fetched

None - this work was based on static code analysis of the existing codebase.


AI generated by Daily Test Coverage Improver

AI generated by Daily Test Coverage Improver

- Added comprehensive tests for calculateDirectorySize()
- Added comprehensive tests for parseDurationString()
- Added comprehensive tests for truncateString()

Coverage improvement: 65.3% → 65.4% overall
Functions improved from 0% to 100% coverage
@pelikhan pelikhan marked this pull request as ready for review October 27, 2025 12:34
Copilot AI review requested due to automatic review settings October 27, 2025 12:34
Copy link
Contributor

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pelikhan pelikhan merged commit fd14c3b into main Oct 27, 2025
5 checks passed
@pelikhan pelikhan deleted the test-coverage-audit-report-helpers-1761532712-3cc6c978db889ba9 branch October 27, 2025 12:34
@github-actions
Copy link
Contributor Author

Agentic Changeset Generator triggered by this pull request.

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