Skip to content

executor: 100% unit test coverage & fix dead blocks#744

Open
chris-ramon wants to merge 1 commit into
masterfrom
executor-tests
Open

executor: 100% unit test coverage & fix dead blocks#744
chris-ramon wants to merge 1 commit into
masterfrom
executor-tests

Conversation

@chris-ramon
Copy link
Copy Markdown
Member

@chris-ramon chris-ramon commented Jun 6, 2026

Details

  • executor: 100% unit test coverage & fix dead blocks
executor.go: 98.7% → 100.0% coverage
Lines	Issue	Fix
368-370	typeFromAST error check unreachable for *ast.Named + latent nil-ptr bug (conditionalType.Name() panics when type not in schema)	err != nil || conditionalType == nil
389-391	Same pattern in InlineFragment branch	err != nil || conditionalType == nil
497-499	Dead len(tOptions) == 0 — strings.Split never returns empty slice in Go	Removed the check
Tests added: TestDoesFragmentConditionMatch_FragmentDefinitionTypeNotFound and TestDoesFragmentConditionMatch_InlineFragmentTypeNotFound — both reference a type name not in the schema, hitting the new conditionalType == nil guard.

Test Plan

  • Unit tests.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed fragment condition matching to properly handle cases where type derivation fails or returns null values.
    • Improved robustness of struct-field tag matching for field resolution logic.
  • Tests

    • Added extensive test coverage for executor edge cases including fragment handling, directive behavior, field resolution strategies, variable coercion, and subscription execution scenarios.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 6, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR improves executor robustness by fixing fragment condition matching to handle nil-derived types and simplifying tag-matching logic, then validates the changes and executor behavior broadly through two new comprehensive test suites covering edge cases, error paths, and complex execution scenarios.

Changes

Executor Internals: Fixes and Test Coverage

Layer / File(s) Summary
Fragment Condition Matching and Tag Parsing Fixes
executor.go
Fragment condition matching for both FragmentDefinition and InlineFragment now explicitly checks if the derived type is nil (in addition to error checks) before returning a match decision. DefaultResolveFn tag-matching removed its empty-option guard, simplifying the comparison logic.
Executor Internal Unit Tests
executor_internal_test.go
Comprehensive unit test suite for core executor functions: execution context construction, operation root type resolution, field collection, directive inclusion, fragment condition matching for definitions and inline fragments (covering nil conditions, exact matches, interface/union membership, type resolution failures), field key derivation, type resolution, error handling for nil parent types and NonNull fields, and interface-based field resolution through FieldResolver.
Executor Extended Integration Tests
executor_extended_test.go
Extensive integration test coverage validating: execution context error paths, operation root type handling, nested dethunking through lists/maps with thunk functions, fragment condition matching across type hierarchies, @skip/@include directive interactions, field resolution via struct tags and reflect.Map access, selection planning and completion behavior, abstract type resolution, and full subscription execution paths including multiple operations, fragment spreads, and meta-field handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 The fragments now match with a nil-aware eye,
No false positives when types can't derive,
Tag matching flows simple, straight and clean,
While tests grow thorough—the best I've seen!
Subscriptions, abstracts, and directives aligned,
A robustness victory, well-designed! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main objectives of the PR: achieving 100% unit test coverage for the executor and fixing unreachable/error-prone code paths (dead blocks).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch executor-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
executor.go (1)

367-390: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Mirror the new nil-type guard in planner fragment matching to avoid a remaining panic path.

Line 368 and Line 389 correctly handle conditionalType == nil, but planFragmentMatches (plan.go:509-534) still only checks err != nil and then dereferences conditionalType.Name(). That leaves the same nil-pointer risk in the planning path for missing type conditions.

Suggested mirror fix (plan.go)
 func planFragmentMatches(schema Schema, typeConditionAST *ast.Named, runtime *Object) bool {
 	if typeConditionAST == nil {
 		return true
 	}
 	conditionalType, err := typeFromAST(schema, typeConditionAST)
-	if err != nil {
+	if err != nil || conditionalType == nil {
 		return false
 	}
 	if conditionalType == runtime {
 		return true
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@executor.go` around lines 367 - 390, The planner's planFragmentMatches
function still calls typeFromAST and only checks err, then dereferences
conditionalType (conditionalType.Name()) causing a nil-pointer risk; update
planFragmentMatches (in plan.go) to mirror executor.go by checking both err !=
nil and conditionalType == nil after calling typeFromAST(eCtx.Schema,
typeConditionAST) and return false (or the same safe value used in executor)
before any use of conditionalType, and ensure subsequent type comparisons and
IsPossibleType calls use the non-nil conditionalType variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@executor_internal_test.go`:
- Line 732: Remove the unused type declaration customMap from the file to
satisfy linting; locate the type definition "type customMap
map[string]interface{}" and delete that line (or the entire declaration) since
nothing references customMap in executor_internal_test.go.

---

Outside diff comments:
In `@executor.go`:
- Around line 367-390: The planner's planFragmentMatches function still calls
typeFromAST and only checks err, then dereferences conditionalType
(conditionalType.Name()) causing a nil-pointer risk; update planFragmentMatches
(in plan.go) to mirror executor.go by checking both err != nil and
conditionalType == nil after calling typeFromAST(eCtx.Schema, typeConditionAST)
and return false (or the same safe value used in executor) before any use of
conditionalType, and ensure subsequent type comparisons and IsPossibleType calls
use the non-nil conditionalType variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 83cee6f6-7acb-45b3-8558-6479d8e36116

📥 Commits

Reviewing files that changed from the base of the PR and between 2e39e53 and d617417.

📒 Files selected for processing (3)
  • executor.go
  • executor_extended_test.go
  • executor_internal_test.go

Comment thread executor_internal_test.go
// DefaultResolveFn – reflect.Map with func() interface{} value
// ---------------------------------------------------------------------------

type customMap map[string]interface{}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Remove unused customMap declaration to keep lint clean.

Line 732 declares customMap but nothing references it in this file.

🧰 Tools
🪛 golangci-lint (2.12.2)

[error] 732-732: type customMap is unused

(unused)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@executor_internal_test.go` at line 732, Remove the unused type declaration
customMap from the file to satisfy linting; locate the type definition "type
customMap map[string]interface{}" and delete that line (or the entire
declaration) since nothing references customMap in executor_internal_test.go.

Source: Linters/SAST tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant