Skip to content

fix(caching): update test expectations for cache analytics#1416

Merged
jensneuse merged 3 commits intofeat/add-caching-supportfrom
jensneuse/pull-fix-tests
Mar 4, 2026
Merged

fix(caching): update test expectations for cache analytics#1416
jensneuse merged 3 commits intofeat/add-caching-supportfrom
jensneuse/pull-fix-tests

Conversation

@jensneuse
Copy link
Copy Markdown
Member

@jensneuse jensneuse commented Mar 4, 2026

Summary

Updates test framework and test expectations to handle cache analytics fields that are now populated during planning.

Key Changes:

  • Add clearCacheAnalytics() mechanism to datasourcetesting framework to strip CacheAnalytics from response nodes by default (tests using WithEntityCaching() opt-in)
  • Update entity caching test expectations in datasource federation tests to match new cache analytics values
  • Fix field alias handling in test expectations (OriginalName, HasAliases)
  • Add comprehensive L2 cache analytics test case to federation_caching_test.go

Tests: All v2 and execution tests pass (282 insertions, 1 deletion across 4 files).

Co-Authored-By: Claude Haiku 4.5 noreply@anthropic.com

Summary by CodeRabbit

  • Tests

    • Added end-to-end cache analytics tests for root-field caching (argument-driven keys and root-field-only scenarios) and expanded coverage of L2 hit/miss behavior across query variants.
    • Expanded federation tests to validate alias/original-name behavior and propagation of cache analytics metadata in nested fields.
    • Test harness now strips cache analytics by default unless entity caching is explicitly enabled.
  • Bug Fixes

    • Standardized a query-missing error message for clearer reporting.

…aliases

- Add clearCacheAnalytics() mechanism to strip CacheAnalytics from response
  nodes in test framework by default (similar to clearCacheKeyTemplates)
- Tests using WithEntityCaching() opt-in to preserve cache analytics
- Update federation_caching_test.go with additional L2 cache analytics test
- Fix OriginalName and HasAliases fields in datasource test expectations
- Add CacheAnalytics and CacheAnalyticsHash values to entity caching tests

All v2 and execution tests now pass.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2a9c40ef-8fb1-4167-a61f-9c589bf5b16d

📥 Commits

Reviewing files that changed from the base of the PR and between a24f2a2 and 963fa19.

📒 Files selected for processing (1)
  • v2/pkg/engine/datasource/service_datasource/schema.go

📝 Walkthrough

Walkthrough

Adds end-to-end cache-analytics tests for root-field caching, enriches test fixtures with aliasing and cache-analytics metadata, and adds helpers to strip CacheAnalytics from test plans by default unless entity caching is enabled.

Changes

Cohort / File(s) Summary
Cache analytics E2E tests
execution/engine/federation_caching_test.go
Adds subtests for root-field L2 analytics with/without arguments and with/without entity caching; exercises L2 reads/writes, FieldHashes, EntityTypes, and subgraph call patterns.
Datasource federation & unit tests
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go, v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_test.go
Augments test fixtures with aliasing and analytics metadata: adds HasAliases, OriginalName, CacheAnalytics, CacheAnalyticsHash, KeyFields, and nested Children structures across objects and fields.
Test plan helpers
v2/pkg/engine/datasourcetesting/datasourcetesting.go
Introduces recursive helpers to clear CacheAnalytics from Plan nodes and integrates this clearing into test execution so analytics are removed by default unless WithEntityCaching() is used.
Minor test formatting
v2/pkg/engine/resolve/resolve_test.go
Removed an extra blank line (formatting only).
Schema error message change
v2/pkg/engine/datasource/service_datasource/schema.go
Minor string change in error message text casing.
Manifest
go.mod
Module file updated (dependency/manifest lines changed).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: updating test expectations to reflect cache analytics functionality enhancements.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jensneuse/pull-fix-tests

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

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go`:
- Around line 1800-1803: CI reports a gci formatting failure in the composite
literal that contains the fields Path, Nullable, HasAliases, Fields (the struct
literal where Path: []string{"shippingInfo"}, Nullable: true, HasAliases: true,
Fields: []*resolve.Field{...}); fix it by running the repo’s auto-formatters
(e.g., gofmt/gci or the configured gci formatter or golangci-lint run --fix) to
correct spacing/indentation and import ordering, then stage and commit the
resulting changes so the file passes CI.
- Around line 1984-1991: The CacheAnalytics.KeyFields currently contains
malformed token fragments "{a" and "b}" which break the resolve.KeyField shape;
update the resolve.ObjectCacheAnalytics.KeyFields so composite key parts are
represented as a nested resolve.KeyField for the "info" field (i.e., a single
KeyField with Name "info" that contains nested Fields for "a" and "b") rather
than separate string fragments, leaving the top-level id KeyField intact; locate
the CacheAnalytics struct in the graphql_datasource_federation_test.go and
replace the malformed entries with a proper nested resolve.KeyField for "info"
(using the Fields slice) to restore correct cache analytics/hash behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 800da69c-863e-4477-b9c1-ebc1f7dede0f

📥 Commits

Reviewing files that changed from the base of the PR and between 20bf2d4 and cf0a9a4.

📒 Files selected for processing (4)
  • execution/engine/federation_caching_test.go
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_test.go
  • v2/pkg/engine/datasourcetesting/datasourcetesting.go

Comment thread v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go Outdated
Comment on lines +1984 to +1991
CacheAnalytics: &resolve.ObjectCacheAnalytics{
KeyFields: []resolve.KeyField{
{Name: "id"},
{Name: "info"},
{Name: "{a"},
{Name: "b}"},
},
},
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.

⚠️ Potential issue | 🟠 Major

Use structured nested KeyFields in CacheAnalytics (current values are malformed).

At Line 1988 and Line 1989, "{a" / "b}" are token fragments, not key fields. This breaks the resolve.KeyField shape and can produce wrong cache analytics/hash behavior for composite keys.

🔧 Proposed fix
  CacheAnalytics: &resolve.ObjectCacheAnalytics{
      KeyFields: []resolve.KeyField{
          {Name: "id"},
-         {Name: "info"},
-         {Name: "{a"},
-         {Name: "b}"},
+         {
+             Name: "info",
+             Children: []resolve.KeyField{
+                 {Name: "a"},
+                 {Name: "b"},
+             },
+         },
      },
  },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
CacheAnalytics: &resolve.ObjectCacheAnalytics{
KeyFields: []resolve.KeyField{
{Name: "id"},
{Name: "info"},
{Name: "{a"},
{Name: "b}"},
},
},
CacheAnalytics: &resolve.ObjectCacheAnalytics{
KeyFields: []resolve.KeyField{
{Name: "id"},
{
Name: "info",
Children: []resolve.KeyField{
{Name: "a"},
{Name: "b"},
},
},
},
},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go`
around lines 1984 - 1991, The CacheAnalytics.KeyFields currently contains
malformed token fragments "{a" and "b}" which break the resolve.KeyField shape;
update the resolve.ObjectCacheAnalytics.KeyFields so composite key parts are
represented as a nested resolve.KeyField for the "info" field (i.e., a single
KeyField with Name "info" that contains nested Fields for "a" and "b") rather
than separate string fragments, leaving the top-level id KeyField intact; locate
the CacheAnalytics struct in the graphql_datasource_federation_test.go and
replace the malformed entries with a proper nested resolve.KeyField for "info"
(using the Fields slice) to restore correct cache analytics/hash behavior.

Copy link
Copy Markdown
Contributor

@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.

♻️ Duplicate comments (1)
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go (1)

1984-1991: ⚠️ Potential issue | 🟠 Major

Fix malformed Account cache analytics key fields (composite key is tokenized incorrectly).

At Line 1987-Line 1989, "{a" and "b}" are token fragments, not structured nested key fields. This can break analytics/hash semantics for composite keys and should use Children under info instead.

🔧 Proposed fix
  CacheAnalytics: &resolve.ObjectCacheAnalytics{
      KeyFields: []resolve.KeyField{
          {Name: "id"},
-         {Name: "info"},
-         {Name: "{a"},
-         {Name: "b}"},
+         {
+             Name: "info",
+             Children: []resolve.KeyField{
+                 {Name: "a"},
+                 {Name: "b"},
+             },
+         },
      },
  },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go`
around lines 1984 - 1991, Account's CacheAnalytics KeyFields contains token
fragments "{a" and "b}" instead of a nested structure; update the
resolve.ObjectCacheAnalytics for Account to represent the composite key under
the "info" field using Children on the resolve.KeyField for "info" (i.e., remove
the malformed KeyField entries with Name "{a" and "b}" and add a
resolve.KeyField{Name: "info", Children: []resolve.KeyField{{Name: "a"}, {Name:
"b"}}} so the composite key fields are nested correctly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In
`@v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go`:
- Around line 1984-1991: Account's CacheAnalytics KeyFields contains token
fragments "{a" and "b}" instead of a nested structure; update the
resolve.ObjectCacheAnalytics for Account to represent the composite key under
the "info" field using Children on the resolve.KeyField for "info" (i.e., remove
the malformed KeyField entries with Name "{a" and "b}" and add a
resolve.KeyField{Name: "info", Children: []resolve.KeyField{{Name: "a"}, {Name:
"b"}}} so the composite key fields are nested correctly).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 422e3b89-25e7-48e1-b7c7-e98db786d62b

📥 Commits

Reviewing files that changed from the base of the PR and between cf0a9a4 and a24f2a2.

📒 Files selected for processing (3)
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_test.go
  • v2/pkg/engine/resolve/resolve_test.go
💤 Files with no reviewable changes (1)
  • v2/pkg/engine/resolve/resolve_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_test.go

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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