Fix darc update-subscription to error when immutable fields are changed#5348
Conversation
When updating a subscription via popup, validate that immutable fields (Id, TargetRepository, TargetBranch, SourceEnabled) have not been changed. If any of these fields are modified, the operation will fail with an error listing all the immutable fields that were changed. Fixes the issue where changes to these fields were silently ignored. Co-authored-by: dkurepa <[email protected]>
Tests verify that the validation correctly: - Detects changes to Id, TargetRepository, TargetBranch, and SourceEnabled - Returns error code when immutable fields are changed - Logs clear error messages for each immutable field violation - Allows updates when only mutable fields are changed - Handles multiple immutable field changes simultaneously Co-authored-by: dkurepa <[email protected]>
| @@ -0,0 +1,275 @@ | |||
| // Licensed to the .NET Foundation under one or more agreements. | |||
There was a problem hiding this comment.
Done in commit 0b7fc8d
| @@ -1,7 +1,8 @@ | |||
| // Licensed to the .NET Foundation under one or more agreements. | |||
| // The .NET Foundation licenses this file to you under the MIT license. | |||
There was a problem hiding this comment.
@copilot it's easier to do these checks in the UpdateSubscriptionOperation rather than in the popup, because you have the original subscription there already. So remove all of the changes, and just add the checks in UpdateSubscriptionOperation before the assignments to values that are used to create the SubscriptionUpdate
There was a problem hiding this comment.
Done in commit 0b7fc8d. Moved validation to UpdateSubscriptionOperation after the popup values are extracted, where the original subscription is already available. The validation checks TargetRepository, TargetBranch, and SourceEnabled before creating the SubscriptionUpdate object.
…tion Per review feedback, moved validation logic to UpdateSubscriptionOperation where the original subscription is already available. This is simpler and avoids the need to store the subscription in the popup class. - Reverted all changes to UpdateSubscriptionPopUp.cs - Deleted UpdateSubscriptionPopUpTests.cs - Added validation in UpdateSubscriptionOperation after popup values are extracted - Validates TargetRepository, TargetBranch, and SourceEnabled fields - Returns error with clear messages if any immutable fields are changed Co-authored-by: dkurepa <[email protected]>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a confusing UX issue where darc update-subscription would silently ignore changes to immutable fields and report success. The fix adds proper validation to detect and reject attempts to modify fields that cannot be changed due to how Maestro++ tracks pull requests.
- Added validation logic to detect changes to immutable subscription fields
- Enhanced error reporting to clearly list which fields cannot be modified
- Updated documentation to explicitly specify all immutable fields and the new error behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Microsoft.DotNet.Darc/Darc/Operations/UpdateSubscriptionOperation.cs | Added validation logic to check for changes to immutable fields (TargetRepository, TargetBranch, SourceEnabled) and return appropriate error messages |
| docs/Darc.md | Updated documentation to clarify all immutable fields and that changes will result in an error rather than being silently ignored |
Problem
When updating a subscription using
darc update-subscriptionwith the popup editor, changes to immutable fields were silently ignored. The command would report success, but fields likeTargetBranch,TargetRepository, andSourceEnabledwould not be updated, leading to user confusion.As noted in the documentation, these fields cannot be modified because of how Maestro++ tracks pull requests, but the tool was not validating or enforcing this restriction.
Example of the problem:
Solution
Added validation in
UpdateSubscriptionOperationafter popup values are extracted to detect and reject changes to immutable fields:When users attempt to modify any of these fields, the operation now fails with a clear error message listing all immutable fields that were changed.
After this fix:
Changes
Testing
Fixes #4248
Fixes #4725
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.