-
Notifications
You must be signed in to change notification settings - Fork 424
[code-simplifier] simplify: dedup validateAllowedIssueFields and extract parseUnknownModelAICreditsFromAuditEntry #40725
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,20 +49,9 @@ function validateAllowedIssueFieldName(fieldName, allowedFields) { | |
| * @returns {void} | ||
| */ | ||
| function validateAllowedIssueFields(issueFields, allowedFields) { | ||
| if (!Array.isArray(issueFields) || issueFields.length === 0) { | ||
| return; | ||
| } | ||
| if (!Array.isArray(allowedFields) || allowedFields.length === 0) { | ||
| return; | ||
| } | ||
| const allowedFieldSet = new Set(allowedFields.map(f => f.toLowerCase())); | ||
| if (allowedFieldSet.has("*")) { | ||
| return; | ||
| } | ||
| if (!Array.isArray(issueFields) || issueFields.length === 0) return; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Behavioral change: falsy 💡 DetailsThe original // old
if (!allowedFieldSet.has(field.name.toLowerCase())) {
throw new Error(...);
}For The new delegate path starts with: // inside validateAllowedIssueFieldName
if (!fieldName) return; // empty string is falsy → silently passesSo a field with Suggested fix — add an explicit guard before delegating, or document that empty-named fields are now intentionally permitted: function validateAllowedIssueFields(issueFields, allowedFields) {
if (!Array.isArray(issueFields) || issueFields.length === 0) return;
for (const field of issueFields) {
validateAllowedIssueFieldName(field.name, allowedFields);
}
}If the callers are known to always produce non-empty
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in |
||
| for (const field of issueFields) { | ||
| if (!allowedFieldSet.has(field.name.toLowerCase())) { | ||
| throw new Error(`${ERR_VALIDATION}: issue field "${field.name}" is not in the allowed-fields list: ${allowedFields.join(", ")}`); | ||
| } | ||
| validateAllowedIssueFieldName(field.name, allowedFields); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/improve-codebase-architecture] The refactor moves
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in |
||
| } | ||
|
pelikhan marked this conversation as resolved.
|
||
| } | ||
|
|
||
|
|
||
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.
[/zoom-out] The
acc || parseUnknownModelAICreditsFromAuditEntry(entry)form matches the pattern at line 253 (parseMaxAICreditsExceededFromAuditLog's reducer) and is the right call: it short-circuits the entry-parse whenaccis alreadytrue. By contrast, line 189 (parseMaxAICreditsFromAuditLog) still uses the entry-first formfn(entry) || acc, which evaluatesfneven after the accumulator has been set. This PR inadvertently exposes that inconsistency — a follow-up to align line 189 would complete the pattern unification.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.
No change here. I kept the
ai_credits_context.cjsextraction as-is and left the line 189 reducer ordering for a separate follow-up so this PR stays scoped to the review feedback onallowed_issue_fields.cjs.