fix(ctf): allow constructing components with source blobs#2043
Conversation
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>
📝 WalkthroughWalkthroughThree changes update the constructor implementation: replacing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment Tip You can disable sequence diagrams in the walkthrough.Disable the |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
bindings/go/constructor/construct_test.go (2)
797-807: Assert concrete access type to guard against localblob regressions.
NotNilis good, but a type assertion to*v2.LocalBlobgives 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[].versionin 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
📒 Files selected for processing (3)
bindings/go/constructor/construct.gobindings/go/constructor/construct_test.gobindings/go/constructor/spec/v1/resources/schema-2020-12.json
|
Do we need (or already have) a follow up for transferring? |
|
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. |
What this PR does / why we need it
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
Commands that test the change:
Verification
ocmSummary by CodeRabbit
Release Notes
Schema Changes
Tests