Skip to content

feat(bundle): add cross-document mapping-reference validation - #92

Merged
jpower432 merged 1 commit into
gemaraproj:mainfrom
sonupreetam:feat/validate-mapping-references
Jul 9, 2026
Merged

jpower432 merged 1 commit into
gemaraproj:mainfrom
sonupreetam:feat/validate-mapping-references

Conversation

@sonupreetam

@sonupreetam sonupreetam commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Integrate mapping-reference validation into the assembler, reusing parseFile's existing parsing rather than duplicating it
  • parseFile now captures mappingRefs alongside refIDs/refURLs
  • After the full dependency graph is resolved, validateMappingRefs checks that every URL-less mapping-reference.id matches at least one metadata.id in the assembled set
  • Results are surfaced via Bundle.Warnings for consumers to inspect after assembly

Context

When a mapping-reference has no url, its id is expected to match a target artifact's metadata.id for bundle-local resolution. Currently there is no validation that catches a mismatch — it only surfaces as a resolution failure in downstream consumers like complypack.

This catches authoring errors early — for example, a policy whose mapping-reference.id is "csc" when the catalog it references has metadata.id "container-security-controls".

References with a URL are skipped since they are resolved externally by the assembler (fetch errors are already hard errors).

Related

Test plan

  • URL-less ref matching a known metadata.id produces no warning
  • URL-less ref not matching any metadata.id produces a warning
  • Ref with URL is not validated against metadata.ids
  • URL-less ref resolved via import's metadata.id produces no warning
  • Multiple warnings across source and imports (both produce warnings in one call)
  • MappingWarning.String() includes file, artifact ID, and reference ID
  • Full repository test suite passes (go test ./...)

@sonupreetam
sonupreetam requested a review from a team as a code owner July 8, 2026 14:05
@jpower432

Copy link
Copy Markdown
Contributor

@sonupreetam Thanks for the PR. I see that this has some duplicate parsing logic that also exists in the Assembler. What do you think of moving the logic there and doing incremental validation as it builds the bundle?

@sonupreetam
sonupreetam force-pushed the feat/validate-mapping-references branch 2 times, most recently from 3a3e0ba to 73dfae8 Compare July 8, 2026 19:14
@sonupreetam

Copy link
Copy Markdown
Contributor Author

Thanks @jpower432, You're right about the duplication. I've reworked on it.

For surfacing the results, I went with a Bundle.Warnings field so consumers can inspect them after assembly. That said, this modifies Bundle's public API, open to other approaches if you'd prefer.

A couple of open questions:

  1. Surfacing warnings in grc: grc in gemara-publish-action doesn't currently read Bundle.Warnings, so these are only available to library consumers (they'd check b.Warnings after calling Assemble). I would like to also update grc to surface them. Or should we keep this as a library-only concern for now and let consumers opt in?

  2. Orphaned import reference-ids: While looking at this, I noticed the assembler silently skips any import whose reference-id doesn't match any mapping-reference.id in the same artifact, so the import is quietly dropped. The CUE schema comments say reference-id "identifies an element from a MappingReference in the artifact's metadata," so the intent is that it's mandatory, but neither CUE nor the assembler enforces it today (_uniqueRefIds in metadata.cue enforces uniqueness of mapping-reference IDs but doesn't cross-check against import reference-ids). This is a separate concern from Cross-document validation: warn when mapping-reference.id has no matching artifact #91 should I file it as a follow-up issue for it?

@jpower432

Copy link
Copy Markdown
Contributor
  1. Surfacing warnings in grc: grc in gemara-publish-action doesn't currently read Bundle.Warnings, so these are only available to library consumers (they'd check b.Warnings after calling Assemble). I would like to also update grc to surface them. Or should we keep this as a library-only concern for now and let consumers opt in?

It seems reasonable to me to surface these in the grc tool. User can always ignore the warning, but it is nice to have them when something goes wrong.

  1. Orphaned import reference-ids: While looking at this, I noticed the assembler silently skips any import whose reference-id doesn't match any mapping-reference.id in the same artifact, so the import is quietly dropped. The CUE schema comments say reference-id "identifies an element from a MappingReference in the artifact's metadata," so the intent is that it's mandatory, but neither CUE nor the assembler enforces it today (_uniqueRefIds in metadata.cue enforces uniqueness of mapping-reference IDs but doesn't cross-check against import reference-ids). This is a separate concern from Cross-document validation: warn when mapping-reference.id has no matching artifact #91 should I file it as a follow-up issue for it?

I suspect it would be more straight forward to add that type of validation to the SDK since there are different mapping types. Perhaps, the assembler should error on this mismatch by default and we provide an argument to allow "continue-on-error". WDYT?

@jpower432 jpower432 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.

Approving with two nits.

Comment thread bundle/assemble.go Resolved
Comment thread bundle/assemble_test.go Resolved
Extend parseFile to capture mapping-references and validate URL-less
reference IDs against the collected metadata.id set after the full
dependency graph is resolved. Warnings are surfaced via Bundle.Warnings.

Closes gemaraproj#91

Signed-off-by: sonupreetam <spreetam@redhat.com>
@sonupreetam

Copy link
Copy Markdown
Contributor Author

Thank you very much @jpower432, both nits addressed.

On the design questions:

It seems reasonable to me to surface these in the grc tool.

Agreed, opened a draft PR (gemaraproj/gemara-publish-action#14) to have grc print Bundle.Warnings to stderr after assembly.

I suspect it would be more straight forward to add that type of validation to the SDK since there are different mapping types.

Agreed. I can file a follow-up issue for that.

Perhaps, the assembler should error on this mismatch by default and we provide an argument to allow "continue-on-error". WDYT?

That makes sense to me. An AssembleOption like WithContinueOnError() would keep the default strict (error on orphaned reference-id) while letting callers opt into lenient mode when needed. Worth noting this would be a breaking change for existing callers whose bundles currently assemble despite having orphaned reference-ids. Happy to do that in a follow-up PR here.

@jpower432
jpower432 merged commit caad3d5 into gemaraproj:main Jul 9, 2026
7 checks passed
@sonupreetam
sonupreetam deleted the feat/validate-mapping-references branch July 9, 2026 14:09
sonupreetam added a commit to sonupreetam/gemara-publish-action that referenced this pull request Jul 10, 2026
Print mapping-reference validation warnings to stderr so users see
diagnostics when URL-less reference IDs don't match any artifact
metadata.id in the bundle.

Depends on gemaraproj/go-gemara#92.
Closes gemaraproj#13

Signed-off-by: sonupreetam <spreetam@redhat.com>
jpower432 pushed a commit to gemaraproj/gemara-publish-action that referenced this pull request Jul 16, 2026
* feat(grc): surface Bundle.Warnings after assembly

Print mapping-reference validation warnings to stderr so users see
diagnostics when URL-less reference IDs don't match any artifact
metadata.id in the bundle.

Depends on gemaraproj/go-gemara#92.
Closes #13

Signed-off-by: sonupreetam <spreetam@redhat.com>

* chore(grc): bump go-gemara to v0.8.0

Pulls in Bundle.Warnings from go-gemara#92.

Signed-off-by: sonupreetam <spreetam@redhat.com>

* fix(grc): bump go-gemara to include oras-go v2.6.2 CVE fix

Pulls in go-gemara main (2c7da20) which includes:
- fix(deps): bump oras-go/v2 to v2.6.2 for CVE-2026-50163 (#102)
- feat(bundle): error by default on unmatched mapping-reference IDs (#98)

This resolves the Kusari Inspector failure on PR #14.

Signed-off-by: sonupreetam <spreetam@redhat.com>

---------

Signed-off-by: sonupreetam <spreetam@redhat.com>
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.

Cross-document validation: warn when mapping-reference.id has no matching artifact

2 participants