feat(extensions): enforce collision policy for duplicate entity identities#2897
feat(extensions): enforce collision policy for duplicate entity identities#2897hopehadfield wants to merge 6 commits intoredhat-developer:mainfrom
Conversation
Code Review by Qodo
1. Strict equality false conflicts
|
|
Important This PR includes changes that affect public-facing API. Please ensure you are adding/updating documentation for new features or behavior. Changed Packages
|
Review Summary by QodoEnforce collision policy for duplicate entity identities
WalkthroughsDescription• Enforce collision policy for duplicate entity identities in extensions catalog • Keep first definition when duplicates are equivalent, warn user • Fail fast with error when duplicates have conflicting content • Add comprehensive unit tests for collision scenarios Diagramflowchart LR
A["Entity Processing"] --> B["Normalize Identity"]
B --> C["Check for Duplicates"]
C --> D{Duplicate Found?}
D -->|No| E["Add to Map"]
D -->|Yes| F{Content Equal?}
F -->|Yes| G["Warn & Skip"]
F -->|No| H["Throw Error"]
E --> I["Apply Annotations"]
G --> I
I --> J["Return Entities"]
File Changes1. workspaces/extensions/plugins/catalog-backend-module-extensions/src/providers/BaseEntityProvider.ts
|
|
@hopehadfield Could you add some examples to test your PR ? |
|
@debsmita1 I included a "How to Test" section in the PR, please let me know if you have any questions |
dzemanov
left a comment
There was a problem hiding this comment.
THank you @hopehadfield for these changes, I left some small comments.
| } | ||
|
|
||
| if (isDeepStrictEqual(existing.entity, fileData.content)) { | ||
| console.warn( |
There was a problem hiding this comment.
Do you want me to also migrate the existing console.warn/error calls in this provider in the same PR?
There was a problem hiding this comment.
Would be good to update it now if you have time
44d0d76 to
2911107
Compare
|
Thanks for the review @dzemanov! I've addressed your comments, please let me know if there's anything else required before merging |
|
|
| annotations: { | ||
| ...entity.metadata.annotations, | ||
| [ANNOTATION_LOCATION]: `file:${this.getProviderName()}`, | ||
| [ANNOTATION_ORIGIN_LOCATION]: `file:${this.getProviderName()}`, | ||
| }, |
There was a problem hiding this comment.
Should this be filename instead?
There was a problem hiding this comment.
Oh, I see it being used the same way here, so it's correct.
dzemanov
left a comment
There was a problem hiding this comment.
Tested that this works fine, thank you @hopehadfield!
Tested with:
- duplicate entities
- conflicting entities
setup:
extensions:
directory: /tmp/extensions-test
I see this optional configuration is not in config.d.ts, would be good to mention it there 😅. I can create a small following PR or we can add it in this PR.
It would be good to fix this test entity invalid name before merging this PR (I noticed it now thanks to catalog warn log).
If you have time, there are some sonar issues flagged that would be good to fix.
Otherwise, good to go!



Hey, I just made a Pull Request!
This change is being made as a result of RHIDP-12376. Multi-catalog ingestion can introduce duplicate entity identities; this change makes behaviour deterministic and prevents silent shadowing of conflicting definitions.
Manually validated runtime behavior in three scenarios:
✔️ Checklist
How to Test
Create a directory
/tmp/extensions-test, with subdirectoriesprimary/catalog-entities/pluginsandextra/community/catalog-entities/pluginsFor case A (equivalent duplicate), create an identical plugin yaml file on each path, for example:
/tmp/extensions-collision-test/primary/catalog-entities/plugins/github.yamland/tmp/extensions-collision-test/extra/community/catalog-entities/plugins/github.yamlboth containingAfter running
yarn start-backendyou should see in the logs that the duplicate entity was skipped, with the first definition being kept. The backend continues successfully.For case B (conflicting duplicate), update the
spec.ownerin/tmp/extensions-collision-test/extra/community/catalog-entities/plugins/github.yamltocommunityand restart the backend. You should see that the provider fails with a conflicting entities message surfaced in the logs.