Skip to content

Conversation

Copy link

Copilot AI commented Jul 1, 2025

This PR enhances the existing RootPathFilter configuration to support glob-style pattern matching, helping 1ES PT seamlessly route files for validation when customers download pipeline artifacts.

Changes

Enhanced RootPathFilter

  • Modified existing RootPathFilter to automatically detect and support glob patterns
  • Supports common glob patterns:
    • * - matches any characters except path separators
    • ** - matches any characters including path separators (recursive)
  • Falls back to legacy path prefix matching when no glob patterns are detected
  • Maintains full backward compatibility - existing configurations continue to work unchanged

Pattern Matching Implementation

  • Implemented PathPatternMatcher utility class using .NET's built-in Microsoft.Extensions.FileSystemGlobbing
  • Cross-platform compatible (handles both Windows and Unix path separators)
  • Leverages Microsoft's well-tested globbing functionality for reliability

Documentation Updates

  • Updated help text in ValidationArgs.cs to document glob pattern support
  • Added comprehensive documentation in IConfiguration.cs comments
  • Clear indication of both legacy and new pattern matching capabilities

Example Usage

{
  "RootPathFilter": "src/**/*.cs;bin/*.dll;tests/**/test*.json"
}

Or with legacy path prefixes:

{
  "RootPathFilter": "src/;bin/"
}

This allows flexible file matching instead of rigid path prefix matching, enabling more precise control over which files are validated while maintaining full backward compatibility.

Backward Compatibility

  • All existing RootPathFilter configurations continue to work exactly as before
  • No breaking changes to the API or configuration format
  • Glob patterns are detected automatically - no configuration changes needed
  • Single configuration property handles both use cases seamlessly

Fixes #1040.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Consider changing RootPathFilter to accept pattern matching Add RootPathPatterns configuration for glob-style pattern matching Jul 1, 2025
Copilot AI requested a review from pragnya17 July 1, 2025 22:56
Copilot AI requested a review from pragnya17 July 2, 2025 18:35
@github-actions
Copy link

github-actions bot commented Jul 2, 2025

This PR changes files in the API project. Does it change any of the API interfaces in any way? Please note that this includes the following types of changes:

  • Changing the signature of an existing interface method
  • Adding a new method to an existing interface
  • Adding a required data member to a class that an existing interface method consumes

Because any of these changes can potentially break a downstream consumer with customized interface implementations, these changes need to be treated as breaking changes. Please do one of the following:

Option 1 - Publish this as a breaking change

  1. Update the documentation to show the new functionality
  2. Bump the major version in the next release
  3. Be sure to highlight the breaking changes in the release notes

Option 2 - Refactor the changes to be non-breaking

  1. Review this commit, which adds a new interface in a backward-compatible way
  2. Refactor the change to follow this pattern so that existing interfaces are left completely intact
  3. Bump the minor version in the next release

@pragnya17
Copy link
Contributor

/azp run

@pragnya17
Copy link
Contributor

There are several PathPatternMatcher tests that are failing, can you diagnose and fix them?

Copy link
Author

Copilot AI commented Jul 2, 2025

There are several PathPatternMatcher tests that are failing, can you diagnose and fix them?

Fixed the PathPatternMatcher tests. The issue was with cross-platform path compatibility and improper handling of the double wildcard (**) pattern. The ** pattern now correctly matches zero or more directory segments, and all path handling is normalized for cross-platform compatibility. All PathPatternMatcher tests are now passing. Commit: b3b21d9

@pragnya17
Copy link
Contributor

/azp run

@github-actions
Copy link

github-actions bot commented Jul 9, 2025

This PR changes files in the API project. Does it change any of the API interfaces in any way? Please note that this includes the following types of changes:

  • Changing the signature of an existing interface method
  • Adding a new method to an existing interface
  • Adding a required data member to a class that an existing interface method consumes

Because any of these changes can potentially break a downstream consumer with customized interface implementations, these changes need to be treated as breaking changes. Please do one of the following:

Option 1 - Publish this as a breaking change

  1. Update the documentation to show the new functionality
  2. Bump the major version in the next release
  3. Be sure to highlight the breaking changes in the release notes

Option 2 - Refactor the changes to be non-breaking

  1. Review this commit, which adds a new interface in a backward-compatible way
  2. Refactor the change to follow this pattern so that existing interfaces are left completely intact
  3. Bump the minor version in the next release

@github-actions
Copy link

This PR changes files in the API project. Does it change any of the API interfaces in any way? Please note that this includes the following types of changes:

  • Changing the signature of an existing interface method
  • Adding a new method to an existing interface
  • Adding a required data member to a class that an existing interface method consumes

Because any of these changes can potentially break a downstream consumer with customized interface implementations, these changes need to be treated as breaking changes. Please do one of the following:

Option 1 - Publish this as a breaking change

  1. Update the documentation to show the new functionality
  2. Bump the major version in the next release
  3. Be sure to highlight the breaking changes in the release notes

Option 2 - Refactor the changes to be non-breaking

  1. Review this commit, which adds a new interface in a backward-compatible way
  2. Refactor the change to follow this pattern so that existing interfaces are left completely intact
  3. Bump the minor version in the next release

@pragnya17
Copy link
Contributor

/azp run

@pragnya17
Copy link
Contributor

I actually want to remove adding to the IConfiguration, and just modify the existing RootPathFilter to support the glob-style matching pattern. could you please do that>

@github-actions
Copy link

This PR changes files in the API project. Does it change any of the API interfaces in any way? Please note that this includes the following types of changes:

  • Changing the signature of an existing interface method
  • Adding a new method to an existing interface
  • Adding a required data member to a class that an existing interface method consumes

Because any of these changes can potentially break a downstream consumer with customized interface implementations, these changes need to be treated as breaking changes. Please do one of the following:

Option 1 - Publish this as a breaking change

  1. Update the documentation to show the new functionality
  2. Bump the major version in the next release
  3. Be sure to highlight the breaking changes in the release notes

Option 2 - Refactor the changes to be non-breaking

  1. Review this commit, which adds a new interface in a backward-compatible way
  2. Refactor the change to follow this pattern so that existing interfaces are left completely intact
  3. Bump the minor version in the next release

Copy link
Author

Copilot AI commented Jul 23, 2025

I actually want to remove adding to the IConfiguration, and just modify the existing RootPathFilter to support the glob-style matching pattern. could you please do that>

Done! I've refactored the implementation to remove the separate RootPathPatterns property and instead enhanced the existing RootPathFilter to support glob-style pattern matching automatically.

The RootPathFilter now:

  • Detects glob patterns (*, **, ?) automatically and switches to pattern matching mode
  • Falls back to legacy path prefix matching when no glob patterns are detected
  • Maintains full backward compatibility with existing configurations

All tests pass and the implementation is much cleaner with a single configuration property handling both use cases. Commit: 5fd117a

if (patterns.Count > 0)
{
skipValidation = false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

re-evaluate if this is needed

Copy link
Author

Choose a reason for hiding this comment

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

Simplified the logic by replacing the if block with a direct assignment: skipValidation = patterns.Count == 0. This achieves the same behavior with cleaner code.

}
}

// Only skip validation if we actually have valid paths
Copy link
Contributor

Choose a reason for hiding this comment

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

re-evaluate if this is necessary

Copy link
Author

Choose a reason for hiding this comment

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

Simplified the logic by replacing the if block with a direct assignment: skipValidation = validPaths.Count == 0. This achieves the same behavior with cleaner code.

}

[TestMethod]
public void PathPatternMatcher_ComplexPattern_MatchesCorrectly()
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a test case here that ensures 0 directories are matched when given **

Copy link
Author

Choose a reason for hiding this comment

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

Added test case PathPatternMatcher_DoubleWildcard_MatchesZeroDirectories that verifies ** pattern correctly matches paths with zero intermediate directories (e.g., src/**/*.txt matches src/file.txt).

…t for ** matching zero directories

Co-authored-by: pragnya17 <[email protected]>
Copilot AI requested a review from pragnya17 July 23, 2025 19:45
@github-actions
Copy link

This PR changes files in the API project. Does it change any of the API interfaces in any way? Please note that this includes the following types of changes:

  • Changing the signature of an existing interface method
  • Adding a new method to an existing interface
  • Adding a required data member to a class that an existing interface method consumes

Because any of these changes can potentially break a downstream consumer with customized interface implementations, these changes need to be treated as breaking changes. Please do one of the following:

Option 1 - Publish this as a breaking change

  1. Update the documentation to show the new functionality
  2. Bump the major version in the next release
  3. Be sure to highlight the breaking changes in the release notes

Option 2 - Refactor the changes to be non-breaking

  1. Review this commit, which adds a new interface in a backward-compatible way
  2. Refactor the change to follow this pattern so that existing interfaces are left completely intact
  3. Bump the minor version in the next release

1 similar comment
@github-actions
Copy link

This PR changes files in the API project. Does it change any of the API interfaces in any way? Please note that this includes the following types of changes:

  • Changing the signature of an existing interface method
  • Adding a new method to an existing interface
  • Adding a required data member to a class that an existing interface method consumes

Because any of these changes can potentially break a downstream consumer with customized interface implementations, these changes need to be treated as breaking changes. Please do one of the following:

Option 1 - Publish this as a breaking change

  1. Update the documentation to show the new functionality
  2. Bump the major version in the next release
  3. Be sure to highlight the breaking changes in the release notes

Option 2 - Refactor the changes to be non-breaking

  1. Review this commit, which adds a new interface in a backward-compatible way
  2. Refactor the change to follow this pattern so that existing interfaces are left completely intact
  3. Bump the minor version in the next release

/// <summary>
/// Provides pattern matching functionality for file paths using glob-style patterns.
/// </summary>
public static class PathPatternMatcher
Copy link
Contributor

Choose a reason for hiding this comment

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

.NET already provides cross-platform support for globbing that we should leverage unless there's some reason that it doesn't do what we need it to do. See https://learn.microsoft.com/en-us/dotnet/core/extensions/file-globbing for details and syntax.

Copy link
Author

Choose a reason for hiding this comment

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

Great suggestion! I've refactored the PathPatternMatcher to use .NET's built-in Microsoft.Extensions.FileSystemGlobbing library instead of the custom implementation. This provides better reliability, cross-platform support, and leverages Microsoft's well-tested globbing functionality.

Key changes:

  • Added Microsoft.Extensions.FileSystemGlobbing dependency
  • Replaced custom regex-based pattern matching with .NET's Matcher class
  • Enhanced cross-platform path handling for both Windows and Unix paths
  • Updated tests to reflect .NET globbing behavior (note: ? wildcard not supported by .NET implementation)
  • All tests passing with improved maintainability

Commit: 806585d

/// Gets or sets if you're downloading only a part of the drop using the '-r' or 'root' parameter
/// in the drop client, specify the same string value here in order to skip
/// validating paths that are not downloaded.
/// Supports both path prefixes (legacy) and glob-style patterns (* and **) for flexible file path matching.
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment like this should appear in the help text in ValidationArgs.cs, as well as in the docs. If you change the help text, you can then run the tool and copy/paste directly into the docs. Be careful of your terminal width, since the line breaks will shift and we want to keep them as stable as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot can you address this comment

Copy link
Author

Choose a reason for hiding this comment

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

Updated the help text in ValidationArgs.cs to document the glob-style pattern support for RootPathFilter. The help text now clearly indicates that both path prefixes (legacy) and glob-style patterns (* and **) are supported for flexible file path matching. Commit: ba7f30d

Copilot AI changed the title Add RootPathPatterns configuration for glob-style pattern matching Enhance RootPathFilter to support glob-style pattern matching Aug 7, 2025
Copilot AI requested a review from pragnya17 August 7, 2025 21:42
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.

Consider changing RootPathFilter to accept pattern matching

3 participants