Skip to content

[test-improver] Improve tests for config package#6813

Merged
lpcox merged 1 commit into
mainfrom
test-improver/keywordFromLocation-coverage-33a15010e40c4efb
Jun 1, 2026
Merged

[test-improver] Improve tests for config package#6813
lpcox merged 1 commit into
mainfrom
test-improver/keywordFromLocation-coverage-33a15010e40c4efb

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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

Test Improvements: validation_schema_error_format_test.go

File Analyzed

  • Test File: internal/config/validation_schema_error_format_test.go
  • Package: internal/config
  • Lines Added: +63

Improvements Made

1. Increased Coverage

  • ✅ Added TestKeywordFromLocation — a direct table-driven test for the keywordFromLocation helper function
  • Previous Coverage: keywordFromLocation at 85.7% (6/7 statements)
  • New Coverage: keywordFromLocation at 100%
  • Improvement: +14.3% for the function; overall config package 96.0% → 96.1%

2. Better Testing Patterns

  • ✅ Table-driven test structure with descriptive subtests
  • ✅ Clear test case names documenting each branch of the function
  • ✅ Uses assert.Equal from testify (consistent with existing file conventions)

3. Coverage Gap Identified

The keywordFromLocation function extracts the terminal keyword from a slash-separated JSON Schema keyword-location path (e.g. "/properties/foo/type""type"). It had three branches:

  1. Empty after trimreturn "" ✅ covered indirectly
  2. No slash foundreturn keywordLocation ❌ never directly tested
  3. Slash foundreturn keywordLocation[lastSlash+1:] ✅ covered indirectly

The "no slash" branch (e.g. input "type" with no path separator) was never exercised by any test, leaving a gap. The new test directly covers all branches including this missing case.

Test Execution

All tests pass:

=== RUN   TestKeywordFromLocation
--- PASS: TestKeywordFromLocation (0.00s)
    --- PASS: TestKeywordFromLocation/empty_string_returns_empty
    --- PASS: TestKeywordFromLocation/whitespace-only_returns_empty
    --- PASS: TestKeywordFromLocation/trailing_slash_is_stripped_before_extraction
    --- PASS: TestKeywordFromLocation/single_keyword_with_no_slash_returns_full_string
    --- PASS: TestKeywordFromLocation/slash-prefixed_single_keyword_returns_keyword
    --- PASS: TestKeywordFromLocation/standard_nested_path_returns_terminal_keyword
    --- PASS: TestKeywordFromLocation/minimum_keyword_at_end_of_path
    --- PASS: TestKeywordFromLocation/maximum_keyword_at_end_of_path
    --- PASS: TestKeywordFromLocation/single_slash_returns_empty_string
PASS
ok  github.com/github/gh-aw-mcpg/internal/config  coverage: 96.1% of statements

Why These Changes?

The validation_schema_error_format_test.go file tests JSON Schema error formatting utilities. While the file already had good coverage for formatErrorContext, detailForKeyword, formatValidationErrorRecursive, and formatSchemaError, the internal keywordFromLocation helper was only exercised indirectly through those functions — and only via inputs that always contained slashes. The "no slash" branch was silently untested.

Adding a direct, focused test for keywordFromLocation with a complete set of cases (empty, whitespace, no-slash, slash-prefixed, nested, edge cases) makes the contract explicit and ensures the function behaves correctly across all inputs.


Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests

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 · sonnet46 7.1M ·

Add direct table-driven tests for the keywordFromLocation helper function
in the config/validation_schema.go package. The function previously had
85.7% coverage because the no-slash branch (returning the input as-is)
was never directly exercised by tests.

The new TestKeywordFromLocation function covers all branches:
- Empty string → returns empty string
- Whitespace-only → returns empty string after trim
- String with no slash → returns the full string (previously untested)
- String with trailing slash → slash stripped before extraction
- Slash-prefixed single keyword → returns the keyword
- Standard nested path → returns terminal keyword
- Edge case: single slash → returns empty string

Coverage improvement: keywordFromLocation 85.7% → 100%
Overall config package: 96.0% → 96.1%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review June 1, 2026 03:44
Copilot AI review requested due to automatic review settings June 1, 2026 03:44
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 improves unit test coverage in the internal/config package by adding direct, table-driven coverage for the keywordFromLocation helper used by JSON Schema validation error formatting.

Changes:

  • Added TestKeywordFromLocation to directly exercise all branches of keywordFromLocation, including the previously untested “no slash” path.
  • Expanded edge-case coverage for empty/whitespace inputs, trailing slashes, and root /.
Show a summary per file
File Description
internal/config/validation_schema_error_format_test.go Adds a focused table-driven test covering keywordFromLocation’s full behavior surface.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@lpcox lpcox merged commit 4837a83 into main Jun 1, 2026
23 checks passed
@lpcox lpcox deleted the test-improver/keywordFromLocation-coverage-33a15010e40c4efb branch June 1, 2026 04:15
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