Skip to content

fix: reuse template for oci plugins tests#2613

Merged
SkArchon merged 3 commits intomainfrom
milinda/oci-cleanup
Mar 9, 2026
Merged

fix: reuse template for oci plugins tests#2613
SkArchon merged 3 commits intomainfrom
milinda/oci-cleanup

Conversation

@SkArchon
Copy link
Copy Markdown
Contributor

@SkArchon SkArchon commented Mar 9, 2026

This PR reuses the OCI plugins template for OCI integration tests.

Summary by CodeRabbit

  • Tests
    • Test infrastructure now populates OCI image references at runtime via a callback, improving how plugin images are resolved during tests.
    • Removed a deprecated OCI-specific test template and its embedded test data to streamline test fixtures and reduce duplication.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 9, 2026

Walkthrough

Replaces an OCI-specific embedded plugin JSON template with a general plugins template in router tests and injects OCI image references at runtime via a new addOCIImageReferences function; removes the embedded OCI plugins template from the test environment.

Changes

Cohort / File(s) Summary
Router OCI Plugin Test
router-tests/router_oci_plugin_test.go
Swaps OCI-specific template usage for a general plugins template; adds ModifyRouterConfig callback addOCIImageReferences and the top-level addOCIImageReferences(routerConfig) function to set ImageReference for projects and courses; adds nodev1 import alias.
Test environment embed cleanup
router-tests/testenv/testenv.go
Removes exported ConfigWithOCIPluginsJSONTemplate and its //go:embed testdata/configWithOCIPlugins.json directive (deleted embedded OCI plugins JSON template).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'fix: reuse template for oci plugins tests' accurately describes the main change: refactoring OCI plugin tests to reuse a general template instead of an OCI-specific one.

✏️ 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)

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

Router image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-2b22e5e71bad39ba5346702ab55e215f9e93e29c

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.

🧹 Nitpick comments (1)
router-tests/router_oci_plugin_test.go (1)

116-135: Centralize the OCI image map and fail fast on template drift.

This helper duplicates repo/tag literals already used by the test setup, and it silently ignores any new plugin datasource added to ConfigWithPluginsJSONTemplate. A small lookup table plus an explicit failure on unexpected plugin names will make future template changes much easier to catch.

♻️ Proposed refactor
+var ociPluginRepositories = map[string]string{
+	"projects": "test-org/projects",
+	"courses":  "test-org/courses",
+}
+
+const ociPluginReference = "v1"
+
 func addOCIImageReferences(routerConfig *nodev1.RouterConfig) {
 	for _, ds := range routerConfig.EngineConfig.DatasourceConfigurations {
 		plugin := ds.GetCustomGraphql().GetGrpc().GetPlugin()
 		if plugin == nil {
 			continue
 		}
-		switch plugin.Name {
-		case "projects":
-			plugin.ImageReference = &nodev1.ImageReference{
-				Repository: "test-org/projects",
-				Reference:  "v1",
-			}
-		case "courses":
-			plugin.ImageReference = &nodev1.ImageReference{
-				Repository: "test-org/courses",
-				Reference:  "v1",
-			}
+		repository, ok := ociPluginRepositories[plugin.Name]
+		if !ok {
+			panic(fmt.Sprintf("unexpected plugin in OCI test template: %s", plugin.Name))
+		}
+		plugin.ImageReference = &nodev1.ImageReference{
+			Repository: repository,
+			Reference:  ociPluginReference,
+		}
 		}
 	}
 }

Also worth reusing the same constants/map in the buildAndPushPluginImage calls so the push side and pull side can't drift.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@router-tests/router_oci_plugin_test.go` around lines 116 - 135, The helper
addOCIImageReferences duplicates hardcoded repo/tag literals and ignores unknown
plugins; create a single lookup map (e.g., map[string]nodev1.ImageReference)
that maps plugin names to their ImageReference and replace the switch in
addOCIImageReferences to look up entries in that map, returning or calling
t.Fatalf (fail fast) if a plugin name is not found (to detect template drift
relative to ConfigWithPluginsJSONTemplate); also reuse the same lookup
constants/map in buildAndPushPluginImage calls so the image push and test-time
image references are sourced from the same canonical data.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@router-tests/router_oci_plugin_test.go`:
- Around line 116-135: The helper addOCIImageReferences duplicates hardcoded
repo/tag literals and ignores unknown plugins; create a single lookup map (e.g.,
map[string]nodev1.ImageReference) that maps plugin names to their ImageReference
and replace the switch in addOCIImageReferences to look up entries in that map,
returning or calling t.Fatalf (fail fast) if a plugin name is not found (to
detect template drift relative to ConfigWithPluginsJSONTemplate); also reuse the
same lookup constants/map in buildAndPushPluginImage calls so the image push and
test-time image references are sourced from the same canonical data.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 955c3db5-6668-43ea-b781-07eec4122ecc

📥 Commits

Reviewing files that changed from the base of the PR and between ea70e91 and 63cbc23.

📒 Files selected for processing (3)
  • router-tests/router_oci_plugin_test.go
  • router-tests/testenv/testdata/configWithOCIPlugins.json
  • router-tests/testenv/testenv.go
💤 Files with no reviewable changes (1)
  • router-tests/testenv/testenv.go

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.

🧹 Nitpick comments (1)
router-tests/router_oci_plugin_test.go (1)

116-135: Make the modifier fail fast on template drift.

Line 117 dereferences routerConfig.EngineConfig directly, and the helper silently does nothing if either expected plugin name disappears from the shared template. Using generated getters and asserting both rewrites happened gives a much clearer failure than a nil panic or an indirect startup error.

Suggested hardening
 func addOCIImageReferences(routerConfig *nodev1.RouterConfig) {
-	for _, ds := range routerConfig.EngineConfig.DatasourceConfigurations {
+	matched := map[string]bool{
+		"projects": false,
+		"courses":  false,
+	}
+
+	for _, ds := range routerConfig.GetEngineConfig().GetDatasourceConfigurations() {
 		plugin := ds.GetCustomGraphql().GetGrpc().GetPlugin()
 		if plugin == nil {
 			continue
 		}
 		switch plugin.Name {
 		case "projects":
+			matched["projects"] = true
 			plugin.ImageReference = &nodev1.ImageReference{
 				Repository: "test-org/projects",
 				Reference:  "v1",
 			}
 		case "courses":
+			matched["courses"] = true
 			plugin.ImageReference = &nodev1.ImageReference{
 				Repository: "test-org/courses",
 				Reference:  "v1",
 			}
 		}
 	}
+
+	if !matched["projects"] || !matched["courses"] {
+		panic("expected projects and courses plugins in ConfigWithPluginsJSONTemplate")
+	}
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@router-tests/router_oci_plugin_test.go` around lines 116 - 135, The helper
addOCIImageReferences currently dereferences routerConfig.EngineConfig and
silently returns if plugins are missing; update it to fail fast by (1) using the
generated getter routerConfig.GetEngineConfig() and guarding against nil, (2)
iterating datasource configurations via GetDatasourceConfigurations(), checking
each plugin via GetCustomGraphql().GetGrpc().GetPlugin(), setting ImageReference
on matches for "projects" and "courses", and (3) verifying both rewrites
occurred (e.g. track booleans for projects/courses) and return an error or call
t.Fatalf/panic when either expected plugin is absent or not rewritten so the
test fails immediately instead of causing a nil panic or indirect startup error.
Ensure references to addOCIImageReferences, routerConfig.GetEngineConfig,
GetDatasourceConfigurations, GetCustomGraphql, GetGrpc, GetPlugin, plugin.Name,
and plugin.ImageReference are used to locate and implement the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@router-tests/router_oci_plugin_test.go`:
- Around line 116-135: The helper addOCIImageReferences currently dereferences
routerConfig.EngineConfig and silently returns if plugins are missing; update it
to fail fast by (1) using the generated getter routerConfig.GetEngineConfig()
and guarding against nil, (2) iterating datasource configurations via
GetDatasourceConfigurations(), checking each plugin via
GetCustomGraphql().GetGrpc().GetPlugin(), setting ImageReference on matches for
"projects" and "courses", and (3) verifying both rewrites occurred (e.g. track
booleans for projects/courses) and return an error or call t.Fatalf/panic when
either expected plugin is absent or not rewritten so the test fails immediately
instead of causing a nil panic or indirect startup error. Ensure references to
addOCIImageReferences, routerConfig.GetEngineConfig,
GetDatasourceConfigurations, GetCustomGraphql, GetGrpc, GetPlugin, plugin.Name,
and plugin.ImageReference are used to locate and implement the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 63ac4d46-4807-4c2a-96f7-de7752cdc125

📥 Commits

Reviewing files that changed from the base of the PR and between 63cbc23 and 9f6daed.

📒 Files selected for processing (1)
  • router-tests/router_oci_plugin_test.go

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.39%. Comparing base (f29f5aa) to head (d932a4d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2613      +/-   ##
==========================================
- Coverage   64.25%   62.39%   -1.87%     
==========================================
  Files         301      244      -57     
  Lines       42658    25775   -16883     
  Branches     4558        0    -4558     
==========================================
- Hits        27410    16082   -11328     
+ Misses      15227     8318    -6909     
- Partials       21     1375    +1354     

see 545 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SkArchon SkArchon merged commit 0d9169d into main Mar 9, 2026
41 of 44 checks passed
@SkArchon SkArchon deleted the milinda/oci-cleanup branch March 9, 2026 19:58
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.

2 participants