[test-improver] Improve tests for proxy/graphql_rewrite#7696
Merged
lpcox merged 2 commits intoJun 18, 2026
Conversation
Add three test cases to TestFindParentField covering previously uncovered
branches in findParentField (graphql_rewrite.go):
- 'sibling closed block before nodes': exercises the depth-- branch when
scanning backward over a balanced {…} block at the same level before
reaching the enclosing { of the parent field.
- 'nested parentheses in field arguments': exercises the parenDepth++
branch when a field's argument list contains nested calls like func(x).
- 'no field name before enclosing brace': exercises the i+1 >= end guard
that returns when the enclosing { has no identifier before it.
Coverage for findParentField: 81.8% → 97.0%
Overall proxy package: 91.1% → 91.7%
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Improves unit test coverage for the GraphQL query rewrite helper findParentField in internal/proxy, which is used to safely inject guard fields into nodes { ... } selections.
Changes:
- Added a test case covering backward-scan brace depth decrement (
depth--) when encountering a closed sibling selection set beforenodes. - Added a test case intended to cover nested-parentheses handling in argument scanning (
parenDepth++). - Added a test case covering the defensive guard that returns
""when no identifier precedes the enclosing{(top-level anonymous selection set).
Show a summary per file
| File | Description |
|---|---|
| internal/proxy/graphql_rewrite_test.go | Adds 3 table-driven cases to increase coverage of findParentField branch behavior. |
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: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
File Analyzed
internal/proxy/graphql_rewrite_test.gointernal/proxyTestFindParentField)Improvements Made
Increased Coverage
Three previously uncovered branches in
findParentField(graphql_rewrite.go) are now tested:depth--branch (line 206): added "sibling closed block before nodes" — a query likefield { sub { x } nodes { y } }where scanning backward crosses a balanced{...}block at the same nesting level before reaching the enclosing{of the parent field.parenDepth++branch (line 229): added "nested parentheses in field arguments" — a query likefield(func(x)) { nodes { y } }where the argument list contains a nested call, causing the inner)to incrementparenDepthbefore the inner(decrements it.i+1 >= endguard (lines 245–248): added "no field name before enclosing brace" — a query like{ nodes { y } }where the enclosing{is the top-level anonymous selection set with no identifier before it, returning"".Previous coverage: 81.8%
New coverage: 97.0%
Improvement: +15.2 percentage points
Overall proxy package: 91.1% → 91.7%
Cleaner Test Structure
t.Runsubtests and inline comments explaining which code path each case exercises.Test Execution
All existing tests continue to pass.
Why These Changes?
findParentFieldis responsible for identifying the GraphQL connection field that owns anodesblock — critical for the guard field injection logic. The three added test cases each target a distinct control-flow branch that had no coverage:depthcounter that tracks balanced{...}blocks when scanning backward was only tested in its increment path; the decrement path needed a query with a sibling closed block.parenDepthcounter for skipping argument lists was only tested with simple single-depth args; nested calls required a second test.return ""when no identifier precedes the enclosing brace had no test at all.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.ioSee Network Configuration for more information.