Skip to content

[test-coverage] Add comprehensive tests for MCP config and args utilities (+0.0% overall, 3 functions to 100%)#2766

Merged
dsyme merged 4 commits intomainfrom
test-coverage-mcp-config-utils-1761791810-323ccdb797030143
Oct 31, 2025
Merged

[test-coverage] Add comprehensive tests for MCP config and args utilities (+0.0% overall, 3 functions to 100%)#2766
dsyme merged 4 commits intomainfrom
test-coverage-mcp-config-utils-1761791810-323ccdb797030143

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

This PR adds comprehensive unit tests for three utility functions in pkg/workflow/ that previously had low or zero coverage.

Changes Made

New Test File

pkg/workflow/mcp_config_utils_test.go - 302 lines with 3 test functions covering:

  1. TestMapToolConfig_GetAny (8 test cases)

    • Existing keys with various types (string, number, boolean, array, object)
    • Non-existent keys
    • Empty config
    • Nil values
  2. TestGetTypeString (17 test cases)

    • Nil value
    • All numeric types (int, int64, float64, float32)
    • Boolean values (true/false)
    • String values (including empty strings)
    • Objects (map[string]any, including empty)
    • Arrays of various types (strings, ints, any, objects, empty)
    • Unknown types (structs)
  3. TestWriteArgsToYAMLInline (9 test cases)

    • No args
    • Single and multiple simple args
    • Args with spaces, quotes, special characters
    • Args with backslashes
    • Empty string args
    • Unicode args

Test Coverage Results

Function Before After Improvement
MapToolConfig.GetAny() 0.0% 100.0% +100.0%
getTypeString() 54.5% 100.0% +45.5%
writeArgsToYAMLInline() 33.3% 100.0% +66.7%
Overall Repository 66.2% 66.2% +0.0%

Replicating the Test Coverage Measurements

# Install dependencies (if needed)
make deps

# Build the project
make build

# Run tests with coverage (before)
git checkout main
go test -count=1 -timeout=5m -coverprofile=coverage-before.out -covermode=atomic ./...
go tool cover -func=coverage-before.out | grep total
# Output: total: (statements) 66.2%

# Run tests with coverage (after)
git checkout test-coverage-mcp-config-utils-1761791810
go test -count=1 -timeout=5m -coverprofile=coverage-after.out -covermode=atomic ./...
go tool cover -func=coverage-after.out | grep total
# Output: total: (statements) 66.2%

# Compare specific functions
echo "=== BEFORE ==="
go tool cover -func=coverage-before.out | grep -E "(GetAny|getTypeString|writeArgsToYAMLInline)"
echo "=== AFTER ==="
go tool cover -func=coverage-after.out | grep -E "(GetAny|getTypeString|writeArgsToYAMLInline)"

Expected output shows all three functions improving to 100.0% coverage.

Problems Found

None - these are pure utility functions with straightforward logic.

Actions Taken

  1. Created comprehensive test cases for three utility functions
  2. Ensured tests cover all code paths including edge cases
  3. Verified all tests pass successfully
  4. Formatted code with make fmt
  5. All tests pass with 100% coverage for targeted functions

Future Improvement Areas

Based on current coverage analysis, the following areas have low/partial coverage:

Zero Coverage Functions (0%):

  • pkg/cli/add_command.go - Workflow addition commands
  • pkg/cli/audit.go - Audit command implementations
  • pkg/cli/interactive.go - Interactive prompts

Low Coverage Functions (< 30%):

  • pkg/cli/remove_command.go:RemoveWorkflows() (5.3%)
  • pkg/workflow/compiler_jobs.go:buildCustomJobs() (7.1%)
  • pkg/cli/run_command.go:RunWorkflowOnGitHub() (8.7%)
  • pkg/workflow/validation.go:collectPackagesFromWorkflow() (29.7%)

📋 Full Command History

Bash Commands Run

# Phase determination
cd /home/runner/work/gh-aw/gh-aw

# Create branch
git checkout -b test-coverage-mcp-config-utils-1761791810

# Run new tests individually
go test -v -run "^TestMapToolConfig_GetAny$" ./pkg/workflow/
go test -v -run "^TestGetTypeString$" ./pkg/workflow/
go test -v -run "^TestWriteArgsToYAMLInline$" ./pkg/workflow/

# Generate coverage report
go test -count=1 -timeout=5m -coverprofile=coverage-final.out -covermode=atomic ./...
go tool cover -func=coverage-final.out | grep total

# Compare before/after
echo "=== BEFORE ==="
go tool cover -func=coverage.out | grep -E "(GetAny|getTypeString|writeArgsToYAMLInline)"
echo "=== AFTER ==="
go tool cover -func=coverage-final.out | grep -E "(GetAny|getTypeString|writeArgsToYAMLInline)"

# Format code
make fmt

# Commit changes
git add pkg/workflow/mcp_config_utils_test.go
git commit -m "test: add comprehensive tests for MCP config and args utility functions..."

Web Searches Performed

None

Web Pages Fetched

None

AI generated by Daily Test Coverage Improver

AI generated by Daily Test Coverage Improver

- Added tests for MapToolConfig.GetAny (0% → 100% coverage)
- Added tests for getTypeString (54.5% → 100% coverage)
- Added tests for writeArgsToYAMLInline (33.3% → 100% coverage)

All three utility functions now have complete test coverage with edge cases
including nil values, empty collections, special characters, and type variants.
@dsyme dsyme closed this Oct 30, 2025
@dsyme dsyme reopened this Oct 30, 2025
@dsyme dsyme marked this pull request as ready for review October 31, 2025 01:40
Copilot AI review requested due to automatic review settings October 31, 2025 01:40
@github-actions
Copy link
Copy Markdown
Contributor Author

Agentic Changeset Generator triggered by this pull request.

@dsyme dsyme merged commit c236f33 into main Oct 31, 2025
21 checks passed
@dsyme dsyme deleted the test-coverage-mcp-config-utils-1761791810-323ccdb797030143 branch October 31, 2025 01:42
Copy link
Copy Markdown
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.

Pull Request Overview

This PR adds comprehensive unit tests for MCP configuration utility functions in the workflow package. The tests ensure proper functionality of type handling, configuration access, and YAML argument formatting.

  • Adds test coverage for MapToolConfig.GetAny() method with various data types
  • Adds test coverage for getTypeString() helper function with all supported and edge case types
  • Adds test coverage for writeArgsToYAMLInline() function including special character handling

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

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