-
Notifications
You must be signed in to change notification settings - Fork 37.3k
chat: fix URL approval settings merge #286218
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
Conversation
When approving requests and responses for a domain separately, the second approval would overwrite the first instead of merging them. This happened because _approvePattern was replacing the entire settings object rather than merging the new approval flags with existing ones. Now when approving a pattern, we preserve any existing approvals and merge the new approval flags using OR logic, so both approveRequest and approveResponse can be true simultaneously. - Modified _approvePattern to check for and merge existing settings - Uses OR logic to combine new flags with existing approvals - Preserves both request and response approvals when set separately Fixes #286107 (Commit message generated by Copilot)
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.
Pull request overview
This PR fixes a bug in the chat URL fetching approval system where approving requests and responses for the same domain separately would overwrite previous approvals instead of merging them. The fix implements proper merge logic that preserves existing approvals when adding new ones.
Key Changes:
- Added merge logic to combine existing URL approval settings with new approvals using OR operations
- Properly handles both boolean and object-based approval settings when merging
- Ensures that once a request or response is approved for a pattern, it remains approved
| // Merge with existing settings for this pattern | ||
| const existingSettings = approvedUrls[pattern]; | ||
| let existingRequest = false; | ||
| let existingResponse = false; | ||
| if (typeof existingSettings === 'boolean') { | ||
| existingRequest = existingSettings; | ||
| existingResponse = existingSettings; | ||
| } else if (existingSettings) { | ||
| existingRequest = existingSettings.approveRequest ?? false; | ||
| existingResponse = existingSettings.approveResponse ?? false; | ||
| } | ||
|
|
||
| const mergedRequest = approveRequest || existingRequest; | ||
| const mergedResponse = approveResponse || existingResponse; | ||
|
|
||
| // Create the approval settings | ||
| let value: boolean | IUrlApprovalSettings; | ||
| if (approveRequest === approveResponse) { | ||
| value = approveRequest; | ||
| if (mergedRequest === mergedResponse) { | ||
| value = mergedRequest; | ||
| } else { | ||
| value = { approveRequest, approveResponse }; | ||
| value = { approveRequest: mergedRequest, approveResponse: mergedResponse }; | ||
| } |
Copilot
AI
Jan 6, 2026
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.
The merge logic for URL approval settings should have test coverage. This bug fix addresses a critical issue where sequential approvals would overwrite each other instead of merging. Consider adding tests that verify:
- Approving requests then responses results in both being approved
- Approving responses then requests results in both being approved
- The boolean optimization works (when both are true, stores as
trueinstead of{approveRequest: true, approveResponse: true}) - Merging works correctly when starting from a boolean value
When approving requests and responses for a domain separately, the second approval would overwrite the first instead of merging them.
Fixes #286107