From 8be73f250072bcc9982e1d86dfb54518efad51de Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 12:35:38 +0000 Subject: [PATCH] Add tests for proxy.injectIntoFragment and proxy.findParentField edge cases Cover the two previously-untested branches in graphql_rewrite.go: - injectIntoFragment: no closing brace (braceEnd == -1 path) - findParentField: no enclosing brace found (returns empty string) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/proxy/graphql_rewrite_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/proxy/graphql_rewrite_test.go b/internal/proxy/graphql_rewrite_test.go index 65b0dfdde..f7ad9e73d 100644 --- a/internal/proxy/graphql_rewrite_test.go +++ b/internal/proxy/graphql_rewrite_test.go @@ -544,6 +544,24 @@ func TestInjectIntoFragment_NoOpeningBrace(t *testing.T) { assert.Equal(t, query, result) } +func TestInjectIntoFragment_NoClosingBrace(t *testing.T) { + // Malformed: fragment has an opening brace but no matching closing brace. + // injectIntoFragment should return the query unchanged when braceEnd == -1. + query := `fragment pr on PullRequest { title` + result := injectIntoFragment(query, "pr", "author{login}") + assert.Equal(t, query, result) +} + +func TestFindParentField_NoEnclosingBrace(t *testing.T) { + // When the query has no enclosing `{` before `nodes`, findParentField returns "". + // This covers the "no enclosing brace found" return path (line: return ""). + query := `nodes { number }` + idx := strings.Index(query, "nodes") + require.NotEqual(t, -1, idx) + got := findParentField(query, idx) + assert.Equal(t, "", got) +} + func countOccurrences(s, substr string) int { count := 0 for i := 0; i+len(substr) <= len(s); i++ {