Skip to content

[test-improver] Improve tests for proxy/graphql_rewrite#7696

Merged
lpcox merged 2 commits into
mainfrom
test-improver/proxy-graphql-rewrite-bd7fe99c73a06733
Jun 18, 2026
Merged

[test-improver] Improve tests for proxy/graphql_rewrite#7696
lpcox merged 2 commits into
mainfrom
test-improver/proxy-graphql-rewrite-bd7fe99c73a06733

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

File Analyzed

  • Test File: internal/proxy/graphql_rewrite_test.go
  • Package: internal/proxy
  • Changes: +24 lines (3 new test cases added to TestFindParentField)

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 like field { 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 like field(func(x)) { nodes { y } } where the argument list contains a nested call, causing the inner ) to increment parenDepth before the inner ( decrements it.
  • i+1 >= end guard (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

  • New cases follow the existing table-driven pattern with t.Run subtests and inline comments explaining which code path each case exercises.

Test Execution

=== RUN   TestFindParentField
=== RUN   TestFindParentField/simple_connection
=== RUN   TestFindParentField/connection_with_totalCount_before_nodes
=== RUN   TestFindParentField/nested_connection
=== RUN   TestFindParentField/connection_without_args
=== RUN   TestFindParentField/sibling_closed_block_before_nodes
=== RUN   TestFindParentField/nested_parentheses_in_field_arguments
=== RUN   TestFindParentField/no_field_name_before_enclosing_brace
--- PASS: TestFindParentField (0.00s)
ok  	github.com/github/gh-aw-mcpg/internal/proxy	coverage: 91.7% of statements

All existing tests continue to pass.

Why These Changes?

findParentField is responsible for identifying the GraphQL connection field that owns a nodes block — critical for the guard field injection logic. The three added test cases each target a distinct control-flow branch that had no coverage:

  1. The depth counter 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.
  2. The parenDepth counter for skipping argument lists was only tested with simple single-depth args; nested calls required a second test.
  3. The defensive 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.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 · 1.6K AIC · ⊞ 29.5K ·

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>
@lpcox lpcox marked this pull request as ready for review June 18, 2026 00:33
Copilot AI review requested due to automatic review settings June 18, 2026 00:33

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

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 before nodes.
  • 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

Comment thread internal/proxy/graphql_rewrite_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox June 18, 2026 00:37 View session
GitHub Advanced Security finished work on behalf of lpcox June 18, 2026 00:38
@lpcox lpcox merged commit 4754ba9 into main Jun 18, 2026
27 checks passed
@lpcox lpcox deleted the test-improver/proxy-graphql-rewrite-bd7fe99c73a06733 branch June 18, 2026 00:42
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