Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 27, 2025

This PR implements validation to prevent misconfigured VMR codeflow subscriptions that could lead to conflicts and operational issues, while also improving the API design by unifying subscription querying methods.

Problem

Currently, it's possible to create conflicting codeflow subscriptions that can cause problems:

  1. Backflow conflicts: Multiple VMR→repository subscriptions targeting the same repository branch
  2. Forward flow conflicts: Multiple repository→VMR subscriptions flowing into the same VMR branch and target directory

These misconfigurations can lead to race conditions, merge conflicts, and unexpected behavior in the dependency flow system.

Solution

Comprehensive Validation

Added validation with a shared service architecture:

  • ICodeflowSubscriptionValidationService: Common interface in Maestro.Common
  • CodeflowSubscriptionValidationService: Single implementation containing all validation logic
  • Server-side validation: SubscriptionsController validates on Create() and UpdateSubscription()
  • Client-side validation: DARC CLI validates in AddSubscriptionOperation and UpdateSubscriptionOperation
  • Shared base class: SubscriptionOperationBase eliminates duplication between Add/Update operations

Validation Rules

Backflow subscriptions (VMR → repository, sourceDirectory set):

  • Only one backflow subscription allowed per target repository + target branch combination

Forward flow subscriptions (repository → VMR, targetDirectory set):

  • Only one forward flow subscription allowed per VMR repository + VMR branch + target directory combination

API Improvement

Replaced the specific GetCodeflowSubscriptionsAsync method with a more generic GetSubscriptionsAsync that accepts additional optional parameters:

Task<IEnumerable<Subscription>> GetSubscriptionsAsync(
    string sourceRepo = null,
    string targetRepo = null,
    int? channelId = null,
    bool? sourceEnabled = null,        // New
    string sourceDirectory = null,     // New
    string targetDirectory = null);    // New

This provides a cleaner, more flexible API that supports both general subscription filtering and specific codeflow validation needs without code duplication.

Error Messages

Clear, actionable error messages help users understand and resolve conflicts:

A backflow subscription 'abc123' already exists for the same target repository and branch. 
Only one backflow subscription is allowed per target repository and branch combination.

Benefits

  • Maintainable: Validation logic exists in one place
  • Consistent: Same validation behavior across all entry points
  • Clean API: Generic subscription querying without method duplication
  • No breaking changes: Existing functionality remains unaffected

Fixes #5204.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Prevent wrong codeflow subscription configurations Prevent wrong codeflow subscription configurations Aug 27, 2025
Copilot finished work on behalf of premun August 27, 2025 09:02
@Copilot Copilot AI requested a review from premun August 27, 2025 09:02
Copy link
Member

@premun premun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot deduplicate the newly added logic so that it's re-used across darc and the controllers

Copy link
Contributor Author

Copilot AI commented Aug 27, 2025

@copilot deduplicate the newly added logic so that it's re-used across darc and the controllers

I've deduplicated the validation logic as requested. Created a shared ICodeflowSubscriptionValidationService in Maestro.Common that both DARC CLI and the API controller now use. This eliminates the duplicate validation methods and ensures consistent behavior across both entry points. The shared service uses a simple SubscriptionInfo data structure to avoid circular dependencies.

Changes in commit 092a101:

  • Added shared validation service interface and implementation
  • Updated both DARC operations to use the shared service
  • Updated SubscriptionsController to use the shared service
  • Removed all duplicate validation methods
  • Registered service in DI for both DARC CLI and API

@Copilot Copilot AI changed the title Prevent wrong codeflow subscription configurations Prevent wrong codeflow subscription configurations with deduplicated validation Aug 27, 2025
@Copilot Copilot AI requested a review from premun August 27, 2025 09:44
Copilot finished work on behalf of premun August 27, 2025 09:44
premun

This comment was marked as outdated.

Copy link
Member

@premun premun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Can you create a common abstract parent for AddSubscriptionOperation.cs and UpdateSubscriptionOperation.cs and put the ValidateCodeflowSubscriptionConflicts there to deduplicate it between these two classes?

Copy link
Contributor Author

Copilot AI commented Aug 27, 2025

@copilot Can you create a common abstract parent for AddSubscriptionOperation.cs and UpdateSubscriptionOperation.cs and put the ValidateCodeflowSubscriptionConflicts there to deduplicate it betw...

Created SubscriptionOperationBase abstract class that both AddSubscriptionOperation and UpdateSubscriptionOperation now extend. Moved the ValidateCodeflowSubscriptionConflicts method to the base class to eliminate the duplication between the two operation classes. This follows the DRY principle and ensures consistent validation behavior.

Changes in commit 03f97b0.

@Copilot Copilot AI requested a review from premun August 27, 2025 09:55
Copilot finished work on behalf of premun August 27, 2025 09:55
@Copilot Copilot AI changed the title Prevent wrong codeflow subscription configurations with deduplicated validation Prevent wrong codeflow subscription configurations with unified validation and generic API Aug 27, 2025
Copilot finished work on behalf of premun August 27, 2025 10:17
@Copilot Copilot AI requested a review from premun August 27, 2025 10:17
Copilot finished work on behalf of premun August 27, 2025 10:41
@Copilot Copilot AI requested a review from premun August 27, 2025 10:41
@premun premun marked this pull request as ready for review August 27, 2025 10:48
@Copilot Copilot AI review requested due to automatic review settings August 27, 2025 10:48
Copy link
Contributor

@Copilot Copilot AI left a 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 implements validation to prevent conflicting VMR codeflow subscriptions and improves the API design by unifying subscription querying methods. The solution adds comprehensive validation to detect and prevent two types of conflicts: backflow conflicts (multiple VMR→repository subscriptions targeting the same repository branch) and forward flow conflicts (multiple repository→VMR subscriptions flowing into the same VMR branch and target directory).

  • Server-side and client-side validation through a shared service architecture
  • Unified API with enhanced GetSubscriptionsAsync method accepting additional filtering parameters
  • Clear error messages and consistent validation behavior across all entry points

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ProductConstructionService/ProductConstructionService.Api/Api/v2020_02_20/Controllers/SubscriptionsController.cs Adds server-side validation logic for detecting codeflow subscription conflicts in Create and UpdateSubscription endpoints
src/Microsoft.DotNet.Darc/DarcLib/IBasicBarClient.cs Extends GetSubscriptionsAsync interface with additional filtering parameters for sourceEnabled, sourceDirectory, and targetDirectory
src/Microsoft.DotNet.Darc/DarcLib/BarApiClient.cs Implements the enhanced GetSubscriptionsAsync method with new filtering parameters
src/Microsoft.DotNet.Darc/Darc/Operations/SubscriptionOperationBase.cs New base class containing shared validation logic for subscription operations
src/Microsoft.DotNet.Darc/Darc/Operations/AddSubscriptionOperation.cs Refactored to inherit from SubscriptionOperationBase and includes client-side validation
src/Microsoft.DotNet.Darc/Darc/Operations/UpdateSubscriptionOperation.cs Refactored to inherit from SubscriptionOperationBase and includes client-side validation
src/Maestro/Maestro.DataProviders/SqlBarClient.cs Updates data provider to support new filtering parameters in GetSubscriptionsAsync
test/Microsoft.DotNet.Darc.Tests/Operations/GetSubscriptionsOperationTests.cs Updates test mocks to accommodate the new GetSubscriptionsAsync signature
test/Microsoft.DotNet.Darc.Tests/Operations/GetBuildOperationTests.cs Updates test mocks to accommodate the new GetSubscriptionsAsync signature

@premun premun changed the title Prevent wrong codeflow subscription configurations with unified validation and generic API Prevent wrong codeflow subscription configurations Aug 27, 2025
@Copilot Copilot AI requested a review from dkurepa August 27, 2025 15:33
Copilot finished work on behalf of dkurepa August 27, 2025 15:33
Copilot finished work on behalf of dkurepa August 27, 2025 15:37
@dkurepa dkurepa merged commit 380c21e into main Aug 27, 2025
9 checks passed
@dkurepa dkurepa deleted the copilot/fix-5204 branch August 27, 2025 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent wrong codeflow subscription configurations
4 participants