Skip to content

fix: handle multiple brace groups in applyTo glob patterns#155

Merged
sergio-sisternes-epam merged 1 commit intomicrosoft:mainfrom
sergio-sisternes-epam:fix/153-multi-brace-glob-expansion
Mar 4, 2026
Merged

fix: handle multiple brace groups in applyTo glob patterns#155
sergio-sisternes-epam merged 1 commit intomicrosoft:mainfrom
sergio-sisternes-epam:fix/153-multi-brace-glob-expansion

Conversation

@sergio-sisternes-epam
Copy link
Collaborator

@sergio-sisternes-epam sergio-sisternes-epam commented Mar 4, 2026

Description

_expand_glob_pattern() in context_optimizer.py used str.format() to expand brace alternatives in applyTo patterns. 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 a KeyError and 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

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Added 4 test cases in TestExpandGlobPattern:

All 37 tests pass (33 existing + 4 new). Also validated end-to-end: apm compile --verbose on a project using applyTo: "**/*.{test,spec}.{ts,js,mts,mjs}" completes successfully, correctly matching 3 directories.

_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
Copilot AI review requested due to automatic review settings March 4, 2026 15:39
Copy link
Contributor

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

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.

@sergio-sisternes-epam sergio-sisternes-epam added this to the 0.8.0 milestone Mar 4, 2026
@sergio-sisternes-epam sergio-sisternes-epam added the bug Something isn't working label Mar 4, 2026
@sergio-sisternes-epam sergio-sisternes-epam merged commit 3e5998a into microsoft:main Mar 4, 2026
22 checks passed
@sergio-sisternes-epam sergio-sisternes-epam deleted the fix/153-multi-brace-glob-expansion branch March 4, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Compilation fails on applyTo patterns with multiple brace groups

3 participants