-
-
Notifications
You must be signed in to change notification settings - Fork 436
core: fix config save will have duplicated config #1122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Thank you for your submission. We really appreciate it! Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request comment same as the below format. I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
WalkthroughThese changes modify schema handling and configuration management across two modules. In loader.ts, schema construction now attaches description metadata when a config scope is present. In settings.ts, the requestConfig method adds deduplication logic to prevent duplicate schema entries with the same meta.description from being added to the settings array. Both changes preserve existing function signatures and external behavior. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/hydrooj/src/settings.ts`:
- Around line 155-157: The current replacement logic in the settings updater
uses this.settings.findIndex((v) => v.meta?.description === s.meta?.description)
which treats undefined===undefined as a match and can remove unrelated entries;
change the predicate to only compare when s.meta?.description is defined (e.g.,
const desc = s.meta?.description; const exist = desc !== undefined ?
this.settings.findIndex(v => v.meta?.description === desc) : -1) so entries
without a description aren't matched, then keep the splice/push behavior
(referencing this.settings, s, meta?.description, findIndex, splice, push).
| const exist = this.settings.findIndex((v) => v.meta?.description === s.meta?.description); | ||
| if (exist !== -1) this.settings.splice(exist, 1); | ||
| this.settings.push(s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against undefined description matching.
When s.meta?.description is undefined (e.g., schemas without a configScope), the comparison undefined === undefined evaluates to true, potentially removing unrelated schemas that also lack descriptions.
🐛 Proposed fix
- const exist = this.settings.findIndex((v) => v.meta?.description === s.meta?.description);
- if (exist !== -1) this.settings.splice(exist, 1);
+ if (s.meta?.description) {
+ const exist = this.settings.findIndex((v) => v.meta?.description === s.meta.description);
+ if (exist !== -1) this.settings.splice(exist, 1);
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const exist = this.settings.findIndex((v) => v.meta?.description === s.meta?.description); | |
| if (exist !== -1) this.settings.splice(exist, 1); | |
| this.settings.push(s); | |
| if (s.meta?.description) { | |
| const exist = this.settings.findIndex((v) => v.meta?.description === s.meta.description); | |
| if (exist !== -1) this.settings.splice(exist, 1); | |
| } | |
| this.settings.push(s); |
🤖 Prompt for AI Agents
In `@packages/hydrooj/src/settings.ts` around lines 155 - 157, The current
replacement logic in the settings updater uses this.settings.findIndex((v) =>
v.meta?.description === s.meta?.description) which treats undefined===undefined
as a match and can remove unrelated entries; change the predicate to only
compare when s.meta?.description is defined (e.g., const desc =
s.meta?.description; const exist = desc !== undefined ?
this.settings.findIndex(v => v.meta?.description === desc) : -1) so entries
without a description aren't matched, then keep the splice/push behavior
(referencing this.settings, s, meta?.description, findIndex, splice, push).
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.