Skip to content

fix(ctf): allow constructing components with source blobs#2043

Merged
jakobmoellerdev merged 4 commits into
open-component-model:mainfrom
jakobmoellerdev:fixup-sources
Mar 23, 2026
Merged

fix(ctf): allow constructing components with source blobs#2043
jakobmoellerdev merged 4 commits into
open-component-model:mainfrom
jakobmoellerdev:fixup-sources

Conversation

@jakobmoellerdev

@jakobmoellerdev jakobmoellerdev commented Mar 22, 2026

Copy link
Copy Markdown
Member

What this PR does / why we need it

  • aligns it with the resources which also have version defaulting in the schema. logic already had this but schema wasnt aware
  • Introduces a test for validating component construction with source blobs to CTF.
  • Ensures source blobs are persisted and verified in the CTF repository.

Which issue(s) this PR fixes

previously one could not properly add local blob based sources because the wrong type was used for local blobs (we need to get rid of runtime localblob eventually and only keep supporting v2 local blob since thats what we use everywhere in the lib, introducing a second type here back in the day was a mistake since we put it as part of the descriptor library)

Testing

Simply run a go work init and run add cv

How to test the changes

Required files to test the changes:

component-constructor.yaml

components:
  - name: "ocm.software/source-test"
    version: "1.0.0"
    provider:
      name: ocm.software/sourcerer
    sources:
    - name: source1
      type: blob
      input:
        type: utf8
        text: foobar

Commands that test the change:

ocm add cv
Verification
  • I have tested the changes locally by running ocm

Summary by CodeRabbit

Release Notes

  • Schema Changes

    • The "version" field is now optional for source specifications in component constructor configurations, allowing more flexible source definition.
  • Tests

    • Added comprehensive test coverage for source blob conversion workflows in component construction, ensuring proper persistence and retrieval of source artifacts.

aligns it with the resources which also have version defaulting in the schema. logic already had this but schema wasnt aware

Signed-off-by: Jakob Möller <contact@jakob-moeller.com>
- Introduces a test for validating component construction with source blobs to CTF.
- Ensures source blobs are persisted and verified in the CTF repository.

Signed-off-by: Jakob Möller <contact@jakob-moeller.com>
@coderabbitai

coderabbitai Bot commented Mar 22, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Three changes update the constructor implementation: replacing descriptor.LocalBlob with v2.LocalBlob in blob assignment, adding a comprehensive test for source blob to CTF conversion workflow, and removing the "version" requirement from the source schema to make it optional.

Changes

Cohort / File(s) Summary
Constructor Type Update
bindings/go/constructor/construct.go
Changed localBlob constructor instantiation from &descriptor.LocalBlob{} to &v2.LocalBlob{} in the addColocatedSourceLocalBlob function.
Source to CTF Conversion Test
bindings/go/constructor/construct_test.go
Added new test TestConstructWithSourceBlobToCTF that validates source blob conversion to CTF format using mocked source input provider and real CTF repository, with assertions on descriptor persistence and source access attributes.
Schema Requirement Update
bindings/go/constructor/spec/v1/resources/schema-2020-12.json
Removed "version" from the required properties array in commonSourceProperties.required, making it optional alongside the already-optional "version" field.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Blob types hop to v2 today,
Sources dance without "version" sway,
CTF conversion passes with glee,
The schema breathes wild and free!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 accurately describes the main fix: enabling construction of components with source blobs by correcting the localBlob type and making version optional in the schema.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit 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.

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting to disable sequence diagrams in the walkthrough.

@jakobmoellerdev jakobmoellerdev marked this pull request as ready for review March 22, 2026 12:07
@jakobmoellerdev jakobmoellerdev requested a review from a team as a code owner March 22, 2026 12:07

@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/constructor/construct_test.go (2)

797-807: Assert concrete access type to guard against localblob regressions.

NotNil is good, but a type assertion to *v2.LocalBlob gives a stronger regression check for this exact bug class.

Proposed assertion upgrade
 source := desc.Component.Sources[0]
 assert.Equal(t, "test-source", source.Name)
 assert.Equal(t, "git", source.Type)
 assert.NotNil(t, source.Access)
+localBlob, ok := source.Access.(*v2.LocalBlob)
+require.True(t, ok, "source access should be v2.LocalBlob")
+assert.Equal(t, "application/octet-stream", localBlob.MediaType)
@@
 assert.Equal(t, "ocm.software/test-ctf-source", retrieved.Component.Name)
 assert.Len(t, retrieved.Component.Sources, 1)
 assert.NotNil(t, retrieved.Component.Sources[0].Access)
+retrievedBlob, ok := retrieved.Component.Sources[0].Access.(*v2.LocalBlob)
+require.True(t, ok, "persisted source access should be v2.LocalBlob")
+assert.Equal(t, "application/octet-stream", retrievedBlob.MediaType)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindings/go/constructor/construct_test.go` around lines 797 - 807, The
current tests only assert that source.Access and
retrieved.Component.Sources[0].Access are non-nil; strengthen them by asserting
the concrete type is *v2.LocalBlob to guard against localblob regressions: add
type assertions or use the test helper (e.g., require.IsType / assert.IsType or
a direct type assertion and require.NoError) on source.Access and on
retrieved.Component.Sources[0].Access to confirm they are *v2.LocalBlob
(referencing the variables source and retrieved.Component.Sources[0].Access in
construct_test.go).

752-765: Cover the optional source version path in this test.

To validate the schema/defaulting change end-to-end, omit sources[].version in the fixture and assert it defaults as expected.

Proposed test hardening
 yamlData := `
 components:
   - name: ocm.software/test-ctf-source
     version: v1.0.0
     provider:
       name: test-provider
     resources: []
     sources:
       - name: test-source
-        version: v1.0.0
         type: git
         input:
           type: mock/v1
 `
@@
 source := desc.Component.Sources[0]
 assert.Equal(t, "test-source", source.Name)
 assert.Equal(t, "git", source.Type)
+assert.Equal(t, "v1.0.0", source.Version)
 assert.NotNil(t, source.Access)
@@
 assert.Equal(t, "ocm.software/test-ctf-source", retrieved.Component.Name)
 assert.Len(t, retrieved.Component.Sources, 1)
+assert.Equal(t, "v1.0.0", retrieved.Component.Sources[0].Version)
 assert.NotNil(t, retrieved.Component.Sources[0].Access)

Also applies to: 797-807

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

In `@bindings/go/constructor/construct_test.go` around lines 752 - 765, The test
fixture currently includes an explicit sources[].version; update the yamlData
fixture(s) to omit the version field for the source (remove the "version:
v1.0.0" under sources -> name: test-source) so the code exercises the
optional-source-version defaulting path, then extend the assertions in the test
that calls the constructor/validation (references: yamlData variable and the
test around lines referencing construction/assertion) to assert that the source
version was defaulted to the expected value; apply the same change to the second
similar fixture referenced around lines 797-807 so both test cases cover the
optional version path.
🤖 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/constructor/construct_test.go`:
- Around line 797-807: The current tests only assert that source.Access and
retrieved.Component.Sources[0].Access are non-nil; strengthen them by asserting
the concrete type is *v2.LocalBlob to guard against localblob regressions: add
type assertions or use the test helper (e.g., require.IsType / assert.IsType or
a direct type assertion and require.NoError) on source.Access and on
retrieved.Component.Sources[0].Access to confirm they are *v2.LocalBlob
(referencing the variables source and retrieved.Component.Sources[0].Access in
construct_test.go).
- Around line 752-765: The test fixture currently includes an explicit
sources[].version; update the yamlData fixture(s) to omit the version field for
the source (remove the "version: v1.0.0" under sources -> name: test-source) so
the code exercises the optional-source-version defaulting path, then extend the
assertions in the test that calls the constructor/validation (references:
yamlData variable and the test around lines referencing construction/assertion)
to assert that the source version was defaulted to the expected value; apply the
same change to the second similar fixture referenced around lines 797-807 so
both test cases cover the optional version path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 444a9253-0dfd-428a-937b-0db42104f8e6

📥 Commits

Reviewing files that changed from the base of the PR and between 270a228 and 1dac5e6.

📒 Files selected for processing (3)
  • bindings/go/constructor/construct.go
  • bindings/go/constructor/construct_test.go
  • bindings/go/constructor/spec/v1/resources/schema-2020-12.json

Comment thread bindings/go/constructor/construct.go
@fabianburth

Copy link
Copy Markdown
Contributor

Do we need (or already have) a follow up for transferring?

@jakobmoellerdev

Copy link
Copy Markdown
Member Author

I think the transfer will need to get extended with a proper transformer for a localblob source. but should be straight forward. I will tackle this once the transfer module is migrated.

@jakobmoellerdev jakobmoellerdev enabled auto-merge (squash) March 23, 2026 09:25
@jakobmoellerdev jakobmoellerdev merged commit f43b71d into open-component-model:main Mar 23, 2026
16 checks passed
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