Skip to content

fix: revert removal of ConvertFromV1 and add tests#2011

Merged
frewilhelm merged 3 commits into
open-component-model:mainfrom
frewilhelm:revert-convert-removal
Mar 18, 2026
Merged

fix: revert removal of ConvertFromV1 and add tests#2011
frewilhelm merged 3 commits into
open-component-model:mainfrom
frewilhelm:revert-convert-removal

Conversation

@frewilhelm

@frewilhelm frewilhelm commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

#1992 removed ConvertFromV1 because it appeared unused. However, it is actually used in

resolverConfig, err := resolverruntime.ConvertFromV1(repositoryScheme, resolverConfigV1)

Some tests were added too, so it does not appear unused.

Summary by CodeRabbit

  • Refactor
    • Improved legacy v1 resolver configuration conversion with clearer error handling, explicit priority mapping (with sensible defaults), preserved resolver ordering, and retention of resolver types.
  • Deprecated
    • v1 resolvers marked deprecated; repository aliases are dropped and a warning is logged when encountered.
  • Tests
    • Added comprehensive unit tests for nil/invalid inputs, priority behavior, repository resolution, ordering, and error cases.

Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com>
@coderabbitai

coderabbitai Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a Go converter to translate legacy v1 resolver configurations into runtime.Config (handles nil input, drops aliases, maps resolver priorities with defaults, constructs repositories via a runtime.Scheme, and returns conversion errors). Unit tests cover success and error scenarios.

Changes

Cohort / File(s) Summary
V1 runtime converter
bindings/go/configuration/ocm/v1/runtime/convert_v1.go
Adds ConvertFromV1(repositoryScheme *runtime.Scheme, config *resolverv1.Config) (*Config, error) and an unexported convertResolvers helper. Implements nil handling, deprecation warning for v1, alias dropping, repository construction via provided runtime.Scheme, priority mapping (use default when nil), and error propagation on failures.
V1 runtime converter tests
bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go
Adds unit tests exercising nil input, no-resolvers/aliases, alias-dropping, explicit/default priority mapping, repository prefix preservation, resolver ordering, and error cases (nil resolver element, nil repository, unknown repository type).

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ConvertFromV1
  participant Scheme
  participant RepoConverter
  participant Logger

  Caller->>ConvertFromV1: call ConvertFromV1(repositoryScheme, config)
  ConvertFromV1->>Logger: log deprecation/warnings (if aliases)
  alt config == nil
    ConvertFromV1-->>Caller: return nil, nil
  else
    loop for each resolver in config.Resolvers
      ConvertFromV1->>Scheme: create new Repository instance
      Scheme-->>ConvertFromV1: repositoryObj
      ConvertFromV1->>RepoConverter: convert repositoryObj -> runtime.Repository
      RepoConverter-->>ConvertFromV1: runtime.Repository / error
      ConvertFromV1->>ConvertFromV1: map Priority (use default if nil)
    end
    ConvertFromV1-->>Caller: assembled runtime.Config or error
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hop through old v1 hills at dawn,

Turning legacy fields into runtime brawn,
Aliases dropped, priorities aligned,
Repos stitched by Scheme’s kind mind,
Tests cheer—conversion sings, I'm gone.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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 accurately summarizes the main change: reverting the removal of ConvertFromV1 and adding tests for it.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@github-actions github-actions Bot added the kind/bugfix Bug label Mar 18, 2026
@frewilhelm

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@github-actions github-actions Bot added the size/m Medium label Mar 18, 2026
@coderabbitai

coderabbitai Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
bindings/go/configuration/ocm/v1/runtime/convert_v1.go (1)

20-22: Consider using slog.Warn for aliases deprecation notice.

Since aliases are being silently dropped and this could lead to unexpected behavior for users relying on them, slog.Warn might be more appropriate than slog.Info to ensure visibility.

💡 Suggested change
 	if len(config.Aliases) > 0 {
-		slog.Info("aliases are not supported in ocm v2, ignoring")
+		slog.Warn("aliases are not supported in ocm v2, ignoring")
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/go/configuration/ocm/v1/runtime/convert_v1.go` around lines 20 - 22,
The current conversion path checks config.Aliases and logs with slog.Info when
aliases are dropped; change this to use slog.Warn so users see a
deprecation/ignored-aliases warning. Locate the check referencing config.Aliases
and the slog.Info call (in convert_v1.go), replace the Info call with slog.Warn
and keep the message content (or make it slightly more explicit) so dropped
aliases are more visible during runtime.
bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go (2)

38-141: Good test coverage. Consider adding edge case tests for nil elements.

The tests comprehensively cover the main scenarios. However, given the potential nil pointer issues in convertResolvers, consider adding tests for:

  • A resolver slice containing a nil element
  • A resolver with a nil Repository field

These would help document expected behavior and catch regressions if nil handling is added.

💡 Suggested additional test cases
func TestConvertFromV1_NilResolverInSlice(t *testing.T) {
	input := &resolverv1.Config{
		Type: runtime.NewVersionedType(resolverv1.ConfigType, resolverv1.Version),
		Resolvers: []*resolverv1.Resolver{
			nil,
		},
	}
	_, err := ConvertFromV1(testScheme, input)
	assert.Error(t, err)
}

func TestConvertFromV1_NilRepositoryReturnsError(t *testing.T) {
	input := &resolverv1.Config{
		Type: runtime.NewVersionedType(resolverv1.ConfigType, resolverv1.Version),
		Resolvers: []*resolverv1.Resolver{
			{Repository: nil, Priority: ptr(10)},
		},
	}
	_, err := ConvertFromV1(testScheme, input)
	assert.Error(t, err)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go` around lines 38
- 141, Add unit tests to cover nil-element edge cases in ConvertFromV1: create
two tests that call ConvertFromV1(testScheme, input) where input.Resolvers
contains (1) a nil element and (2) a resolver whose Repository is nil, and
assert that ConvertFromV1 returns an error in both cases; this exercises
convertResolvers/ConvertFromV1 error paths and prevents silent nil-pointer or
unexpected-success behavior (referencing ConvertFromV1 and the
resolverv1.Resolver Repository field to locate where to add the tests).

31-36: Minor: Raw JSON construction could break with special characters.

If baseURL contains characters like " or \, the inline JSON construction would produce invalid JSON. For test purposes this is likely acceptable since test inputs are controlled, but using json.Marshal would be more robust.

💡 More robust alternative
+import "encoding/json"

 func rawTestRepo(baseURL string) *runtime.Raw {
+	data, _ := json.Marshal(map[string]string{
+		"type":    "test-repo/v1",
+		"baseURL": baseURL,
+	})
 	return &runtime.Raw{
 		Type: runtime.NewVersionedType("test-repo", "v1"),
-		Data: []byte(`{"type":"test-repo/v1","baseURL":"` + baseURL + `"}`),
+		Data: data,
 	}
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go` around lines 31
- 36, The rawTestRepo helper builds JSON by concatenating strings which breaks
if baseURL contains quotes or backslashes; update rawTestRepo to construct a
small struct (e.g., with fields Type and BaseURL) and use json.Marshal to
produce the Data byte slice, then set the Type field to
runtime.NewVersionedType("test-repo","v1") and Data to the marshaled bytes so
runtime.Raw.Data is valid JSON for any baseURL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bindings/go/configuration/ocm/v1/runtime/convert_v1.go`:
- Around line 43-50: The loop over resolvers may dereference a nil pointer; add
explicit nil checks for both `resolver` and `resolver.Repository` before calling
`resolver.Repository.GetType()` and `repositoryScheme.Convert`, and return an
informative error if either is nil (e.g., include the loop index `i` and which
field is missing). Update the block around the `for i, resolver := range
resolvers` loop to validate `resolver != nil` and `resolver.Repository != nil`
prior to calling `repositoryScheme.NewObject(resolver.Repository.GetType())` and
`repositoryScheme.Convert(...)`, returning the error rather than allowing a nil
pointer panic.

---

Nitpick comments:
In `@bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go`:
- Around line 38-141: Add unit tests to cover nil-element edge cases in
ConvertFromV1: create two tests that call ConvertFromV1(testScheme, input) where
input.Resolvers contains (1) a nil element and (2) a resolver whose Repository
is nil, and assert that ConvertFromV1 returns an error in both cases; this
exercises convertResolvers/ConvertFromV1 error paths and prevents silent
nil-pointer or unexpected-success behavior (referencing ConvertFromV1 and the
resolverv1.Resolver Repository field to locate where to add the tests).
- Around line 31-36: The rawTestRepo helper builds JSON by concatenating strings
which breaks if baseURL contains quotes or backslashes; update rawTestRepo to
construct a small struct (e.g., with fields Type and BaseURL) and use
json.Marshal to produce the Data byte slice, then set the Type field to
runtime.NewVersionedType("test-repo","v1") and Data to the marshaled bytes so
runtime.Raw.Data is valid JSON for any baseURL.

In `@bindings/go/configuration/ocm/v1/runtime/convert_v1.go`:
- Around line 20-22: The current conversion path checks config.Aliases and logs
with slog.Info when aliases are dropped; change this to use slog.Warn so users
see a deprecation/ignored-aliases warning. Locate the check referencing
config.Aliases and the slog.Info call (in convert_v1.go), replace the Info call
with slog.Warn and keep the message content (or make it slightly more explicit)
so dropped aliases are more visible during runtime.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a4b2e8fc-00ba-4be2-8e78-5ed762871e0a

📥 Commits

Reviewing files that changed from the base of the PR and between 651cc58 and 3dcd96c.

📒 Files selected for processing (2)
  • bindings/go/configuration/ocm/v1/runtime/convert_v1.go
  • bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go

Comment thread bindings/go/configuration/ocm/v1/runtime/convert_v1.go
Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com>
@frewilhelm frewilhelm marked this pull request as ready for review March 18, 2026 14:46
@frewilhelm frewilhelm requested a review from a team as a code owner March 18, 2026 14:46

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
bindings/go/configuration/ocm/v1/runtime/convert_v1.go (1)

50-55: Wrap conversion errors with resolver index context.

Returning raw errors here makes triage harder; include resolver index/type so failures are actionable.

♻️ Proposed improvement
 		convertedRepo, err := repositoryScheme.NewObject(resolver.Repository.GetType())
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("resolver[%d]: create repository object for type %q: %w", i, resolver.Repository.GetType(), err)
 		}
 		if err := repositoryScheme.Convert(resolver.Repository, convertedRepo); err != nil {
-			return nil, err
+			return nil, fmt.Errorf("resolver[%d]: convert repository type %q: %w", i, resolver.Repository.GetType(), err)
 		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/go/configuration/ocm/v1/runtime/convert_v1.go` around lines 50 - 55,
When converting resolver.Repository using repositoryScheme.NewObject and
repositoryScheme.Convert, wrap any returned errors with contextual information
(resolver index and resolver.Repository.GetType()) instead of returning raw err;
capture the error, build a new error message like "failed to convert resolver %d
(type %s): %w" and return that (using error wrapping e.g. fmt.Errorf) so
failures from repositoryScheme.NewObject and repositoryScheme.Convert include
resolver index and type for easier triage.
bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go (1)

38-161: Add a regression test for nil repositoryScheme.

Current coverage is strong, but it does not assert behavior when repositoryScheme is nil and Resolvers is non-empty—the remaining panic path from the converter.

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

In `@bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go` around lines 38
- 161, Add a regression test named
TestConvertFromV1_NilRepositorySchemeReturnsError that verifies ConvertFromV1
handles a nil repositoryScheme without panicking: save the current
repositoryScheme, set repositoryScheme = nil, defer restoring it, build an input
resolverv1.Config with one resolver (use rawTestRepo("registry.example.com")),
call ConvertFromV1(testScheme, input) and assert that it returns an error
(assert.Error); reference ConvertFromV1, repositoryScheme, rawTestRepo and the
new test function name to locate where to add this test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bindings/go/configuration/ocm/v1/runtime/convert_v1.go`:
- Around line 37-55: The function convertResolvers dereferences repositoryScheme
(calling repositoryScheme.NewObject and repositoryScheme.Convert) without
checking for nil, which can panic; add an early nil check at the top of
convertResolvers that returns a descriptive error if repositoryScheme == nil,
e.g. "repositoryScheme is nil", so callers get an error instead of a panic;
ensure this check runs before any use of repositoryScheme (before calling
repositoryScheme.NewObject or repositoryScheme.Convert) and keep existing nil
checks for individual resolvers and resolver.Repository intact.

---

Nitpick comments:
In `@bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go`:
- Around line 38-161: Add a regression test named
TestConvertFromV1_NilRepositorySchemeReturnsError that verifies ConvertFromV1
handles a nil repositoryScheme without panicking: save the current
repositoryScheme, set repositoryScheme = nil, defer restoring it, build an input
resolverv1.Config with one resolver (use rawTestRepo("registry.example.com")),
call ConvertFromV1(testScheme, input) and assert that it returns an error
(assert.Error); reference ConvertFromV1, repositoryScheme, rawTestRepo and the
new test function name to locate where to add this test.

In `@bindings/go/configuration/ocm/v1/runtime/convert_v1.go`:
- Around line 50-55: When converting resolver.Repository using
repositoryScheme.NewObject and repositoryScheme.Convert, wrap any returned
errors with contextual information (resolver index and
resolver.Repository.GetType()) instead of returning raw err; capture the error,
build a new error message like "failed to convert resolver %d (type %s): %w" and
return that (using error wrapping e.g. fmt.Errorf) so failures from
repositoryScheme.NewObject and repositoryScheme.Convert include resolver index
and type for easier triage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d5667b51-2d03-4a4a-b6c5-2202e2b0df01

📥 Commits

Reviewing files that changed from the base of the PR and between 3dcd96c and f1089cd.

📒 Files selected for processing (2)
  • bindings/go/configuration/ocm/v1/runtime/convert_v1.go
  • bindings/go/configuration/ocm/v1/runtime/convert_v1_test.go

Comment thread bindings/go/configuration/ocm/v1/runtime/convert_v1.go
Signed-off-by: Frederic Wilhelm <frederic.wilhelm@sap.com>

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

🧹 Nitpick comments (2)
bindings/go/configuration/ocm/v1/runtime/convert_v1.go (2)

53-59: Consider adding resolver index to scheme error messages for consistency.

Errors from NewObject and Convert (lines 55, 58) don't include the resolver index, unlike the nil check errors above (lines 48, 51). Adding the index would make debugging easier when conversions fail with multiple resolvers.

💡 Suggested change
 		convertedRepo, err := repositoryScheme.NewObject(resolver.Repository.GetType())
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("resolver at index %d: failed to create repository object: %w", i, err)
 		}
 		if err := repositoryScheme.Convert(resolver.Repository, convertedRepo); err != nil {
-			return nil, err
+			return nil, fmt.Errorf("resolver at index %d: failed to convert repository: %w", i, err)
 		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/go/configuration/ocm/v1/runtime/convert_v1.go` around lines 53 - 59,
The NewObject and Convert error returns in convert_v1.go do not include the
resolver index like the earlier nil-checks; update the error handling around
repositoryScheme.NewObject(resolver.Repository.GetType()) and
repositoryScheme.Convert(resolver.Repository, convertedRepo) to wrap or format
the returned error with the resolver index (e.g., include fmt.Errorf("resolver
%d: %w", idx, err) or equivalent) so the returned errors consistently identify
which resolver failed during conversion.

20-22: Consider using slog.Warn for dropped aliases.

Since aliases are silently ignored and data is effectively being dropped during conversion, slog.Warn would be more semantically appropriate than slog.Info to alert users that their configuration is not fully honored.

💡 Suggested change
 	if len(config.Aliases) > 0 {
-		slog.Info("aliases are not supported in ocm v2, ignoring")
+		slog.Warn("aliases are not supported in ocm v2, ignoring")
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/go/configuration/ocm/v1/runtime/convert_v1.go` around lines 20 - 22,
The code in convert_v1.go currently logs dropped aliases with slog.Info when
checking config.Aliases; change that call to slog.Warn (or slog.Logger.Warn if
using an instance) so dropped aliases are signaled as a warning rather than
info, and keep or slightly clarify the message like "aliases are not supported
in ocm v2, ignoring" to indicate data is being dropped; update the call site
that checks if len(config.Aliases) > 0 to use the warning-level logger.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@bindings/go/configuration/ocm/v1/runtime/convert_v1.go`:
- Around line 53-59: The NewObject and Convert error returns in convert_v1.go do
not include the resolver index like the earlier nil-checks; update the error
handling around repositoryScheme.NewObject(resolver.Repository.GetType()) and
repositoryScheme.Convert(resolver.Repository, convertedRepo) to wrap or format
the returned error with the resolver index (e.g., include fmt.Errorf("resolver
%d: %w", idx, err) or equivalent) so the returned errors consistently identify
which resolver failed during conversion.
- Around line 20-22: The code in convert_v1.go currently logs dropped aliases
with slog.Info when checking config.Aliases; change that call to slog.Warn (or
slog.Logger.Warn if using an instance) so dropped aliases are signaled as a
warning rather than info, and keep or slightly clarify the message like "aliases
are not supported in ocm v2, ignoring" to indicate data is being dropped; update
the call site that checks if len(config.Aliases) > 0 to use the warning-level
logger.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e37d235c-ecf6-45a5-94fc-1c3a1146efe9

📥 Commits

Reviewing files that changed from the base of the PR and between f1089cd and b59ad15.

📒 Files selected for processing (1)
  • bindings/go/configuration/ocm/v1/runtime/convert_v1.go

@frewilhelm frewilhelm enabled auto-merge (squash) March 18, 2026 15:29
@frewilhelm frewilhelm merged commit 050a324 into open-component-model:main Mar 18, 2026
20 checks passed
@frewilhelm frewilhelm deleted the revert-convert-removal branch March 30, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants