Skip to content

feat!: add digest support for component references#2086

Merged
fabianburth merged 9 commits into
open-component-model:mainfrom
fabianburth:feat/constructor-reference-digest-part1
Mar 27, 2026
Merged

feat!: add digest support for component references#2086
fabianburth merged 9 commits into
open-component-model:mainfrom
fabianburth:feat/constructor-reference-digest-part1

Conversation

@fabianburth

@fabianburth fabianburth commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Description

  • Add Digest field to Reference type in constructor runtime and spec/v1 packages
  • Update conversion functions between runtime, v1, and descriptor types
  • Add JSON schema support and generate deepcopy methods

Due to the changes to the schema (additionalProperties: false), this can be considered a breaking change.

Test plan

  • Unit tests in constructor_test.go
  • tested manually
  • CI passes

@fabianburth fabianburth requested a review from a team as a code owner March 27, 2026 13:31
@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

Adds an optional Digest to references across spec/runtime/descriptor layers, propagates it through conversion helpers, implements digest verification during reference processing (new ErrDigestMismatch), and updates deep-copy logic and tests to handle the Digest field.

Changes

Cohort / File(s) Summary
Constructor processing
bindings/go/constructor/construct.go
Added package-level ErrDigestMismatch. Implemented digest verification in processReference and adjusted error wrapping/identity formatting in processDescriptor when invoking reference hooks.
Runtime types & deepcopy
bindings/go/constructor/runtime/constructor.go, bindings/go/constructor/runtime/zz_generated.deepcopy.go
Added exported Digest type and optional Reference.Digest field. Generated DeepCopy methods for Digest and updated Reference.DeepCopyInto to deep-copy the digest pointer.
Runtime ↔ descriptor conversions
bindings/go/constructor/runtime/convert_desc.go
Mapped runtime Digest to/from descriptor.Reference.Digest when the digest pointer is non-nil.
v1 conversions & helpers
bindings/go/constructor/runtime/convert_v1.go, bindings/go/constructor/spec/v1/convert.go
Added ConvertFromV1Digest/ConvertToV1Digest. Updated conversions to propagate digest fields between v1, runtime, and descriptor representations when present.
v1 spec types & schema
bindings/go/constructor/spec/v1/constructor.go, bindings/go/constructor/spec/v1/resources/schema-2020-12.json
Added Digest *Digest to v1.Reference (json:"digest,omitempty"). Adjusted Resource JSON tags (sourceRefssrcRefs, relationrelation,omitempty). Set additionalProperties: false on component schema.
Spec deepcopy & tests
bindings/go/constructor/spec/v1/zz_generated.deepcopy.go, bindings/go/constructor/spec/v1/constructor_test.go
Deep copy for v1.Reference now clones optional Digest. Updated tests and JSON fixtures to assert digest omission when nil and inclusion when non-nil.
Repo metadata
.gitignore
Added .claude to ignored files.

Sequence Diagram(s)

sequenceDiagram
    participant Spec as Spec (v1)
    participant Conv as Converter
    participant Descriptor as Descriptor
    participant Constructor as Constructor.Process
    Spec->>Conv: ConvertToRuntimeReference (may include digest)
    Conv->>Descriptor: ConvertToDescriptorReference (propagate digest)
    Descriptor->>Constructor: processReference(descriptor.Reference)
    Constructor->>Constructor: calculate digest from component
    alt Provided digest present
        Constructor->>Constructor: compare calculated vs provided digest
        alt match
            Constructor->>Constructor: set ref.Digest = calculated
        else mismatch
            Constructor-->>Constructor: return ErrDigestMismatch (wrapped)
        end
    end
    Constructor->>Constructor: call OnEndReferenceConstruct hook (identity formatting adjusted)
    Constructor-->>Descriptor: continue processing / return result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hopped through fields of hash and name,
Carried digests home, then checked their claim,
Copied with care, no pointer astray,
Wrapped mismatches neat if rules betray,
A rabbit's tiny audit — now all aligned!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.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
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding digest support for component references, which is the primary focus of this changeset.
Description check ✅ Passed The description is directly related to the changeset, outlining the addition of Digest fields to Reference types, conversion function updates, schema support, and deepcopy generation.

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

@github-actions github-actions Bot added the size/m Medium label Mar 27, 2026
@fabianburth fabianburth changed the title feat(constructor): add digest support for component references feat: add digest support for component references Mar 27, 2026
@github-actions github-actions Bot added the kind/feature new feature, enhancement, improvement, extension label Mar 27, 2026

@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

🤖 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/constructor/construct.go`:
- Around line 352-359: When OnEndReferenceConstruct
(c.opts.OnEndReferenceConstruct) returns an error while there is already an
original reference error (err, e.g. ErrDigestMismatch from processReference),
preserve both by joining them instead of returning only the hook error; create a
combined error (use errors.Join(hookErr, err) or equivalent) and return it
wrapped with context in the fmt.Errorf call for the OnEndReferenceConstruct
failure for reference.ToIdentity(), so upstream errors.Is(err,
ErrDigestMismatch) still works; keep the existing separate check that returns
the processing error (the "error processing reference %q at index %d" branch)
when there is no hook error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4388fb5-0aee-47c5-a523-723f4ef3dc2c

📥 Commits

Reviewing files that changed from the base of the PR and between c6de48f and 1641448.

📒 Files selected for processing (10)
  • bindings/go/constructor/construct.go
  • bindings/go/constructor/runtime/constructor.go
  • bindings/go/constructor/runtime/convert_desc.go
  • bindings/go/constructor/runtime/convert_v1.go
  • bindings/go/constructor/runtime/zz_generated.deepcopy.go
  • bindings/go/constructor/spec/v1/constructor.go
  • bindings/go/constructor/spec/v1/constructor_test.go
  • bindings/go/constructor/spec/v1/convert.go
  • bindings/go/constructor/spec/v1/resources/schema-2020-12.json
  • bindings/go/constructor/spec/v1/zz_generated.deepcopy.go

Comment thread bindings/go/constructor/construct.go
Signed-off-by: Fabian Burth <fabian.burth@sap.com>
@fabianburth fabianburth force-pushed the feat/constructor-reference-digest-part1 branch from eb89216 to f07e102 Compare March 27, 2026 13:51

@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

🤖 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/constructor/construct.go`:
- Around line 603-616: The current digest equality in construct.go treats any
non-nil reference.Digest as a complete triple and compares all three fields,
causing valid partial digests (e.g., only Value set) to incorrectly trigger
ErrDigestMismatch; update the logic in the function containing this block to
either (a) validate that a supplied reference.Digest is complete by explicitly
checking that HashAlgorithm, NormalisationAlgorithm and Value are all non-empty
and return a clear error if any are missing, or (b) perform per-field
comparisons only for fields that are populated on the incoming reference.Digest
(compare HashAlgorithm only if reference.Digest.HashAlgorithm != "", etc.) and
ignore unset fields when comparing against referencedComponentDigest; refer to
the symbols reference.Digest and referencedComponentDigest to locate and adjust
the equality check accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 678a8733-ac0d-4ee0-b4b3-058c95ffbad7

📥 Commits

Reviewing files that changed from the base of the PR and between 1641448 and eb8a665.

📒 Files selected for processing (2)
  • .gitignore
  • bindings/go/constructor/construct.go
✅ Files skipped from review due to trivial changes (1)
  • .gitignore

Comment thread bindings/go/constructor/construct.go
Signed-off-by: Fabian Burth <fabian.burth@sap.com>
…fy the reason

Signed-off-by: Fabian Burth <fabian.burth@sap.com>
@fabianburth fabianburth changed the title feat: add digest support for component references feat!: add digest support for component references Mar 27, 2026
@github-actions github-actions Bot added the !BREAKING-CHANGE! Breaking change in API or ocm-cli or spec label Mar 27, 2026
@fabianburth fabianburth merged commit d1b943b into open-component-model:main Mar 27, 2026
32 checks passed
@fabianburth fabianburth deleted the feat/constructor-reference-digest-part1 branch March 27, 2026 15:18
@coderabbitai coderabbitai Bot mentioned this pull request Mar 27, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!BREAKING-CHANGE! Breaking change in API or ocm-cli or spec kind/feature new feature, enhancement, improvement, extension size/m Medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants