Skip to content

[test] Add tests for proxy.response_transform missing branches#5564

Merged
lpcox merged 2 commits into
mainfrom
test/response-transform-coverage-093af0db3c14d84f
May 12, 2026
Merged

[test] Add tests for proxy.response_transform missing branches#5564
lpcox merged 2 commits into
mainfrom
test/response-transform-coverage-093af0db3c14d84f

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Test Coverage Improvement: response_transform.go

Function Analyzed

  • Package: internal/proxy
  • File: internal/proxy/response_transform.go
  • Functions: rewrapSearchResponse, rebuildGraphQLResponse, deepCloneJSON, unwrapSingleObject
  • Previous Coverage: Partial — several branches unreachable by existing tests
  • New Coverage: All previously-uncovered branches now exercised
  • Complexity: Medium — multiple type-assertion guards and conditional key lookups

Why This Function?

response_transform.go contains the core response-shaping logic for DIFC-filtered API responses. The existing tests in proxy_test.go covered the happy paths but left several defensive branches untested:

Function Uncovered branch
rewrapSearchResponse filteredItems is not []interface{}
rewrapSearchResponse original uses "repositories" key (code-search)
rewrapSearchResponse original has neither "items" nor "repositories"
rebuildGraphQLResponse original map has no "data" field
deepCloneJSON top-level []interface{} input
deepCloneJSON primitive / nil input (default branch)
unwrapSingleObject nil filteredData

Tests Added

  • TestRewrapSearchResponse_Repositories — GitHub code-search repositories key
  • TestRewrapSearchResponse_FilteredItemsNotSlice — type-assertion guard for non-slice filtered data
  • TestRewrapSearchResponse_NeitherItemsNorRepositories — original has no known collection key
  • TestRebuildGraphQLResponse_NoDataField — original map missing data key
  • TestDeepCloneJSON_Slice — top-level slice deep-copy isolation
  • TestDeepCloneJSON_Primitive — primitive and nil pass-through
  • TestUnwrapSingleObject_NilFilteredData — nil filtered data returns nil

Coverage Impact

All previously-unreachable branches in response_transform.go are now directly exercised. The file had no dedicated test file before this PR; the new response_transform_test.go provides focused unit tests independent of the broader integration scenarios in proxy_test.go.

Note: The network-restricted CI environment prevented running go test -coverprofile to produce numeric before/after percentages, but the branch analysis above identifies exactly which code paths were previously dead from a test perspective.


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

Warning

Firewall blocked 7 domains

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

  • go.opentelemetry.io
  • go.yaml.in
  • golang.org
  • google.golang.org
  • gopkg.in
  • proxy.golang.org
  • releaseassets.githubusercontent.com

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

network:
  allowed:
    - defaults
    - "go.opentelemetry.io"
    - "go.yaml.in"
    - "golang.org"
    - "google.golang.org"
    - "gopkg.in"
    - "proxy.golang.org"
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by Test Coverage Improver · ● 3.1M ·

Add response_transform_test.go covering branches in rewrapSearchResponse,
rebuildGraphQLResponse, deepCloneJSON, and unwrapSingleObject that were
not exercised by the existing proxy_test.go tests:

- rewrapSearchResponse: 'repositories' key path, filteredItems not []interface{},
  original with neither 'items' nor 'repositories' key
- rebuildGraphQLResponse: original map with no 'data' field
- deepCloneJSON: top-level []interface{} input, primitive/nil inputs
- unwrapSingleObject: nil filteredData

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review May 12, 2026 22:49
Copilot AI review requested due to automatic review settings May 12, 2026 22:49
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

Adds focused unit tests for internal/proxy/response_transform.go to exercise defensive branches that weren’t previously covered by the existing proxy tests, improving confidence in response-shaping behavior for search, GraphQL, and JSON cloning helpers.

Changes:

  • Add targeted tests for rewrapSearchResponse uncommon envelopes and type-guard branches.
  • Add a test for rebuildGraphQLResponse when the original payload lacks a data field.
  • Add tests for deepCloneJSON top-level slice + primitive/nil inputs, and unwrapSingleObject nil filtered data.
Show a summary per file
File Description
internal/proxy/response_transform_test.go New unit tests covering previously-unexercised branches in response transformation helpers.

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: 2

Comment on lines +11 to +12
// "repositories" key when the original search envelope uses that field name
// (e.g. GitHub code-search responses: {"total_count": N, "repositories": [...]}).
Comment on lines +1 to +8
package proxy

import (
"testing"

"github.com/github/gh-aw-mcpg/internal/difc"
"github.com/stretchr/testify/assert"
)
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 12, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

@copilot address review feedback

Addressed in 7fefe11. I updated internal/proxy/response_transform_test.go to (1) reword the repositories test comment to avoid asserting a specific API shape, and (2) clarify that this file complements existing helper tests in proxy_test.go with defensive-branch coverage.

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