Skip to content

[test] Add tests for mcpresult.ExtractTextContent - #7060

Merged
lpcox merged 3 commits into
mainfrom
add-tests-mcpresult-extract-text-content-ea5516034a56cfbf
Jun 6, 2026
Merged

[test] Add tests for mcpresult.ExtractTextContent#7060
lpcox merged 3 commits into
mainfrom
add-tests-mcpresult-extract-text-content-ea5516034a56cfbf

Conversation

@github-actions

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

Copy link
Copy Markdown
Contributor

Test Coverage Improvement: ExtractTextContent

Function Analyzed

  • Package: internal/mcpresult
  • Function: ExtractTextContent
  • Previous Coverage: 0%
  • New Coverage: 100%
  • Complexity: Medium

Why This Function?

ExtractTextContent was selected because it had 0% coverage and meaningful complexity: it handles two distinct input slice types ([]interface{} vs []map[string]interface{}), filters content items by type (text/image/audio/resource/unknown), performs type assertions on the text field, and has several skip conditions. Covering all branches requires a rich test suite.

Tests Added

  • ✅ Happy path – single text item via []interface{} and []map[string]interface{}
  • ✅ Nil/missing content key and nil content value
  • ✅ Unsupported content types (string, int, map, bool → returns "")
  • ✅ Empty slices (both []interface{} and []map[string]interface{})
  • ✅ Item type filtering: "text" and "" kept; "image", "audio", "resource" skipped; unknown types kept per backward-compat
  • ✅ Non-map items in []interface{} are skipped
  • ✅ Items with empty text, missing text key, or non-string text value are skipped
  • ✅ Multi-item concatenation (including newlines and unicode)
  • ✅ Mixed type scenarios (text interspersed with skipped types)
  • ✅ Nil map input
  • ✅ Complex realistic scenario combining all edge cases

Coverage Report

Before: 0.0% coverage
After:  100.0% coverage
Improvement: +100%

Test Execution

All 37 sub-tests pass:

ok  github.com/github/gh-aw-mcpg/internal/mcpresult  0.003s  coverage: 100.0% of statements
github.com/github/gh-aw-mcpg/internal/mcpresult/text_content.go:8: ExtractTextContent  100.0%

Note: Tests use only the standard testing package. testify is the project convention but its module zip is unavailable in the network-restricted environment; the test patterns (table-driven, t.Parallel, descriptive names) match the project style otherwise.


Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • proxy.golang.org
  • sum.golang.org

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

network:
  allowed:
    - defaults
    - "proxy.golang.org"
    - "sum.golang.org"

See Network Configuration for more information.

Generated by Test Coverage Improver · sonnet46 3M ·

Adds comprehensive table-driven tests for ExtractTextContent in the
internal/mcpresult package. Coverage goes from 0% to 100%.

Tests cover all branches in the function:
- Missing/nil content key
- Unsupported content types (string, int, map, bool)
- Empty []interface{} and []map[string]interface{} slices
- Item type filtering: text/empty (kept), image/audio/resource (skipped),
  unknown types (kept per backward-compat comment)
- Non-map items in []interface{} (skipped)
- Empty or non-string text values (skipped)
- []map[string]interface{} typed slice path
- Multi-item concatenation and mixed-type scenarios
- Nil map input, unicode content, whitespace-only text

Note: tests use only the standard library testing package; testify is
unavailable in the network-restricted CI environment.

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

lpcox commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

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

Adds a comprehensive table-driven test suite for internal/mcpresult.ExtractTextContent, improving confidence in the function’s branching behavior across supported content shapes and edge cases.

Changes:

  • Added coverage for content being absent/nil, unsupported types, empty slices, and mixed item types.
  • Added coverage for both []interface{} and []map[string]interface{} input forms (including non-map items and invalid text fields).
  • Added a dedicated nil-map input test.
Show a summary per file
File Description
internal/mcpresult/text_content_test.go Adds comprehensive unit tests covering all ExtractTextContent branches and edge cases.

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

Copilot AI commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

@copilot fix the failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/27029273303/job/79888506961?pr=7060

Fixed in commit 9ea340b. The failing CI check was from gofmt in internal/mcpresult/text_content_test.go; I applied formatting only and re-ran make lint plus go test ./internal/mcpresult successfully.

Copilot finished work on behalf of lpcox June 6, 2026 15:49
Copilot AI requested a review from lpcox June 6, 2026 15:49
@lpcox

lpcox commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

@copilot fix the failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/27066749712/job/79888856571?pr=7060

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox
lpcox merged commit f62a133 into main Jun 6, 2026
16 checks passed
@lpcox
lpcox deleted the add-tests-mcpresult-extract-text-content-ea5516034a56cfbf branch June 6, 2026 16:03
Copilot stopped work on behalf of lpcox due to an error June 6, 2026 16:11
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.

3 participants