fix: handle multiple brace groups in applyTo glob patterns#155
Merged
sergio-sisternes-epam merged 1 commit intomicrosoft:mainfrom Mar 4, 2026
Conversation
_expand_glob_pattern() used str.format() which misinterpreted the second
brace group in patterns like **/*.{test,spec}.{ts,js,mts,mjs} as a
Python format placeholder, raising KeyError.
Replace with recursive brace expansion that correctly handles any number
of brace groups by expanding one group at a time.
Fixes microsoft#153
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes apm compile failures when an instruction’s applyTo glob contains multiple brace groups (e.g., **/*.{test,spec}.{ts,js,mts,mjs}) by replacing the previous str.format()-based expansion with a recursive brace expansion.
Changes:
- Implement recursive brace expansion in
ContextOptimizer._expand_glob_pattern()to support any number of{...}groups. - Add unit tests covering single/multiple/no brace-group patterns and single-item brace groups.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/apm_cli/compilation/context_optimizer.py |
Reworks _expand_glob_pattern() to recursively expand brace groups, preventing KeyError on multi-group patterns. |
tests/unit/compilation/test_context_optimizer.py |
Adds targeted tests validating brace expansion behavior, including the multi-group regression case. |
You can also share your feedback on Copilot code review. Take the survey.
danielmeppiel
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
_expand_glob_pattern()incontext_optimizer.pyusedstr.format()to expand brace alternatives inapplyTopatterns. When a pattern contained multiple brace groups (e.g.,**/*.{test,spec}.{ts,js,mts,mjs}),str.format()treated the second group as a Python format placeholder, raising aKeyErrorand failing compilation.Replaced with a recursive brace expansion that finds the first
{...}group, expands it into one variant per alternative, and recursively processes remaining brace groups. This correctly handles any number of brace groups.Fixes #153
Type of change
Testing
Added 4 test cases in
TestExpandGlobPattern:test_single_brace_group— single{a,b}expansiontest_multiple_brace_groups— two brace groups (the failing case from [BUG] Compilation fails on applyTo patterns with multiple brace groups #153)test_no_brace_group— passthrough for patterns without bracestest_single_item_brace_group—{a}expands to justaAll 37 tests pass (33 existing + 4 new). Also validated end-to-end:
apm compile --verboseon a project usingapplyTo: "**/*.{test,spec}.{ts,js,mts,mjs}"completes successfully, correctly matching 3 directories.