Skip to content

fix(repos): a {a,b} brace in a manifest glob lists alternatives - #1613

Open
antonwolfy wants to merge 5 commits into
intel:mainfrom
antonwolfy:fix/manifest-glob-braces
Open

antonwolfy wants to merge 5 commits into
intel:mainfrom
antonwolfy:fix/manifest-glob-braces

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A glob of a repo manifest (guidance.globs, guidance.also_scan, useful.edit) with a {a,b} brace matches no file on main: match_posix_glob (imported as match_glob in repos/manifest.py) escapes every character but *, ? and **/, so {, , and } are literal. The issue names match_glob in repos/manifest.py:483, which main no longer defines, but the bug is the same in pattern_glob.py.

call on main result
match_glob('src/{a,b}.h', 'src/a.h') False
match_glob('**/{AGENTS,CLAUDE}.md', 'AGENTS.md') False
match_glob('**/{AGENTS,CLAUDE}.md', 'x/CLAUDE.md') False
match_glob('a{,b}', 'ab') False

So repo scan warns that such a glob matches no file, and the guidance arms and useful.edit never see the files it names. The code-span side of the repository scan already reads a brace as alternatives (#1485, repos/l0/braces.py).

The issue's first option is taken: expand a comma brace into alternatives before matching, in the one function every manifest glob goes through. The other option (document braces as literal) would leave **/{AGENTS,CLAUDE}.md unusable, though the scan already reads that spelling in a code span.

Past 16 alternatives (the cap l0 uses) each outermost comma brace is read as *, as l0 reads a code span past its cap; the replacement stays inside one path segment, also beside another brace or a * (src/{a,b,c,d,e}{f,g,h,i}.h does not match src/deep/x.h). This over-matches rather than dropping the glob, so a manifest with a long brace list still finds its files.

glob_paths (repo_glob.py) is left alone. Its only callers are repo_config.py (the defaults.skills patterns and the suite patterns, where {skill} is already a placeholder replaced before matching), and no page of dokimi/docs describes those fields, so no documented manifest or config glob reaches it.

Closes #1484

Changes

  • dokimi/brace_alternatives.py (new, foundation layer): expand, over_cap, pairs and the caps, moved out of repos/l0/braces.py since pattern_glob sits below repos.l0 and cannot import it. braces.py imports them and keeps the code-span parts (pathlike, starred, judge, defined_in).
  • pattern_glob.match_posix_glob: a closed brace with a comma lists alternatives (nested braces and an empty alternative a{,b} too); a brace with no comma or no } stays literal; past the cap each outermost comma brace is a single-segment wildcard of its own, never merged with a neighbouring * or brace into **. Braces nested deeper than MAX_DEPTH (32) are not expanded and the glob matches only its own literal text (brace_alternatives.too_deep measures the nesting of matched braces on its own, so it tells that case apart whatever the alternative count, also when a pattern exceeds both caps). The compiled pattern is cached per glob, since the expansion would otherwise run on every path.
  • dokimi/docs/repo-evaluation-contract.md (manifest rules) and dokimi/docs/architecture.md (module list) say a {a,b} brace lists alternatives.
  • tests/test_import_architecture.py: the new module is in the foundation layer.
  • tests/test_pattern_glob_braces.py (new): the alternatives, the literal cases, the cap.
  • Changelog fragment (Fixed).

Risk

A manifest glob that held a literal {a,b} (a directory named {a,b}) now matches a and b instead. A glob with no comma brace matches exactly as before; the existing match_glob and match_posix_glob tests pass unchanged. A glob past the cap matches more than before (it matched nothing). The user-given CLI patterns (pattern_glob.expand) are not changed.

Open PRs that change the same files: #1576 changes one line of the LAYERS tuple in dokimi/tests/test_import_architecture.py right next to the line this PR changes (it adds dokimi.spend_preview), so the two conflict textually in that line, and whichever merges second takes a one-line rebase. The other open PRs that touch dokimi/docs/repo-evaluation-contract.md or dokimi/docs/architecture.md merge cleanly.

Testing

On a Linux review host, at 98833fe7 (on main 01ff2d6):

  • make ci-local: 36 passed, 2 failed, 16 skipped (docker and network steps, jobs that do not run on a PR, matrix legs of other platforms, semgrep, micromamba). The 2 failures are ci.yml:test / Run tests and Repeat changed tests, both on tests/test_import_architecture.py::test_package_uses_the_new_modules (dokimi.runs.resolve imports dokimi.utils). That one test fails on this branch's base (01ff2d6) and is fixed by the merged fix(runs): import InputError from dokimi.files, not dokimi.utils #1609; this PR does not touch it. The run: 35430 tests passed, 1 failed, 28 skipped; changed-line coverage 100% (99 lines).
  • On main's code tests/test_pattern_glob_braces.py gives 10 failed, 12 passed, first on match_glob('**/{AGENTS,CLAUDE}.md', 'AGENTS.md') returning False (the test's import of MAX_ALTERNATIVES is replaced by 16 in that copy).
  • With the placeholder of a replaced brace set back to a plain *, test_a_brace_past_the_cap_next_to_a_brace_or_a_star_stays_within_one_segment fails (src/{a,b,c,d,e}{f,g,h,i}.h matched src/deep/x.h).
  • Mutants: 9 breaks of the new code, each fails the test file (no expansion, a comma-less brace unwrapped, the cap ignored, the cap's * crossing a /, every brace starred, an unclosed { paired, no nesting, an empty alternative dropped, the character after a starred brace skipped).
  • Braces nested past the depth cap ({ * 33 + a,b + } * 33) are read with their braces literal, not as a wildcard: test_braces_nested_past_the_depth_cap_stay_literal_not_a_star checks the pattern matches only itself and not unrelated.md, and that 32 levels still expand. It fails on the previous head's code (the glob matched unrelated.md) and with the too_deep branch removed.
  • A pattern past both caps ({ * 33 + 17 alternatives + } * 33, also with an overflowing {...} brace before it) is read with its braces literal: test_braces_nested_past_the_depth_cap_stay_literal_also_past_the_alternative_cap checks it matches only itself and not unrelated.md. With too_deep back to reading the depth from the capped expansion, that test fails.
  • The mutation job of ci-local lists 13 survivors, all in the moved code of brace_alternatives.py, which tests/test_repo_l0_braces.py exercises and the job does not run for that module; none is in pattern_glob.py.
  • Merged together with fix/pinned-manifest-identifier on main 0eeae5f: pytest -n auto 35684 passed, 28 skipped, mypy clean, ruff check clean.
  • At 19e8d60a, which only moves one constant above a comment in pattern_glob.py: tests/test_pattern_glob.py 53 passed; make ci-local was not rerun for it.
  • Not run: the other Python versions and platforms, the Docker steps.

Open questions

None.

Revert

A plain revert restores the old behaviour: a brace in a manifest glob is literal again, and repos/l0/braces.py holds the expansion. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes (the full run has 1 failure, test_package_uses_the_new_modules, which fails on the base and is fixed by the merged fix(runs): import InputError from dokimi.files, not dokimi.utils #1609)
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…l#1484)

`match_posix_glob`, the one match behind `guidance.globs`, `guidance.also_scan` and `useful.edit`, escaped the `{`, `,` and `}` of `**/{AGENTS,CLAUDE}.md` or `src/{a,b}.h` as literal characters, so such a glob matched no file and `repo scan` warned that it matched nothing.

It now matches when any alternative of a closed comma brace does (nested braces and an empty alternative `a{,b}` too). A brace with no comma or no closing `}` stays literal, and a glob that would spell more than 16 alternatives reads each such brace as `*`, as the repository scan reads a code span. The expansion moved from `repos/l0/braces.py` to the new `brace_alternatives.py`, a foundation module both import. `glob_paths` is left as it is: no documented manifest field reaches it.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner December 4, 2026 15:30
Copilot AI balanced review requested due to automatic review settings December 4, 2026 15:30
@antonwolfy antonwolfy self-assigned this Dec 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The brace-cap fallback can turn adjacent wildcard replacements into recursive matches, violating single-segment behavior and selecting unintended files.

1 open issue
What changed in this PR

1 new finding.

This PR adds brace alternatives to manifest glob matching, sharing expansion logic with repository code-span scanning.

Changes:

  • Supports nested and empty alternatives, with capped expansion and cached matching.
  • Extracts shared brace utilities into a foundation module.
  • Adds regression tests and documents the matching rules.
File Description
dokimi/​tests/​test_pattern_glob_braces.py Tests alternatives, literal braces, and cap fallback.
dokimi/​tests/​test_import_architecture.py Registers the shared foundation module.
dokimi/​dokimi/​repos/​l0/​braces.py Reuses extracted brace utilities.
dokimi/​dokimi/​pattern_glob.py Adds brace-aware matching and regex caching.
dokimi/​dokimi/​brace_alternatives.py Provides shared, bounded brace expansion.
dokimi/​docs/​repo-evaluation-contract.md Defines manifest glob behavior.
dokimi/​docs/​architecture.md Documents the shared module.
dokimi/​changelog.d/​20261204_100000_manifest-glob-braces.md Records the matching fix.

Review effort: Balanced

Comment thread dokimi/dokimi/pattern_glob.py Resolved
@exai-bot

exai-bot commented Dec 4, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s).

CI at 98833fe: 26 passing, 4 skipped.

Test notes (2)
  • dokimi/dokimi/brace_alternatives.py:62: With while ends and ends[-1] < i: changed to while ends and ends[-1] <= i:, the tests still pass: dokimi/tests/test_pattern_glob_braces.py. A value exactly at the boundary gives the same result either way here, so no test says which one is meant.
  • dokimi/dokimi/brace_alternatives.py:67: With return depth > MAX_DEPTH changed to return depth >= MAX_DEPTH, the tests still pass: dokimi/tests/test_pattern_glob_braces.py. A value exactly at the boundary gives the same result either way here, so no test says which one is meant.
Review details
  • Commit reviewed: 98833fe against merge base 9c9756f
  • Coverage: 2 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 51k tokens (30k from cache), 21s
  • Tool calls: 5 (4 file_read, 1 local_check_results)
  • small change set: 2 files

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 10 of 80 small breaks of the lines this PR changes, and not every break was tried

At 98833fe: 69 caught · 10 missed · 1 waived

Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Where Operator Change no test notices Tests reaching the line
dokimi/dokimi/brace_alternatives.py:10 bump-int 16 → 17 2
dokimi/dokimi/brace_alternatives.py:11 bump-int 32 → 33 2
dokimi/dokimi/brace_alternatives.py:58 bump-int 0 → 1 8
dokimi/dokimi/brace_alternatives.py:75 bump-int 1 → 2 13
dokimi/dokimi/brace_alternatives.py:82 delete-statement count *= len(options) → pass 10
dokimi/dokimi/brace_alternatives.py:84 delete-statement raise _TooMany → pass 1
dokimi/dokimi/brace_alternatives.py:86 drop-clause has_comma or comma → (comma) 10
dokimi/dokimi/brace_alternatives.py:99 delete-statement raise _TooMany → pass 3
dokimi/dokimi/brace_alternatives.py:100 swap-addsub closed[i] + 1 → closed[i] - 1 10
dokimi/dokimi/brace_alternatives.py:75 flip-bool False → True 13

Not checked:

  • 49 more breaks of covered changed lines were over the limit and not tried
  • 4 changed lines were not mutated

Marked harmless with mutation-ok:

Where Operator Change Reason
dokimi/dokimi/pattern_glob.py:156 bump-int 1024 → 1025 the size bounds the cache, it changes no match

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

@codecov-commenter

codecov-commenter commented Dec 4, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.45%. Comparing base (01ff2d6) to head (98833fe).
⚠️ Report is 10 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1613      +/-   ##
==========================================
- Coverage   96.46%   96.45%   -0.01%     
==========================================
  Files         561      567       +6     
  Lines       74345    75066     +721     
  Branches    12840    12964     +124     
==========================================
+ Hits        71716    72404     +688     
- Misses       1609     1632      +23     
- Partials     1020     1030      +10     
Files with missing lines Coverage Δ
dokimi/dokimi/brace_alternatives.py 100.00% <100.00%> (ø)
dokimi/dokimi/pattern_glob.py 100.00% <100.00%> (ø)
dokimi/dokimi/repos/l0/braces.py 100.00% <100.00%> (ø)

... and 56 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…e a star or brace

Settles review thread 4801928326: the cap fallback wrote each replaced brace as `*`, so a brace next to another brace or a `*` formed `**` and matched across directories. The fallback now marks a replaced brace with a placeholder that compiles to `[^/]*` on its own. Tests cover adjacent braces and neighbouring stars.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
The _STAR constant sat between the `#:` comment and _ABSENT, so the comment documented _STAR. Move _STAR above the comment.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Comment thread dokimi/dokimi/pattern_glob.py Resolved
A comma brace nested deeper than MAX_DEPTH made expand return None, and match_posix_glob then starred the whole pattern, so a 33-deep brace matched any root file. The depth limit is now told apart from the alternative count (brace_alternatives.too_deep): a too-deep pattern is read with its braces literal, as MAX_DEPTH documents ("not expanded"). Settles the review thread on pattern_glob.py:157.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Comment thread dokimi/dokimi/brace_alternatives.py Resolved
…he alternative cap

Settles review thread 4806007759: too_deep stopped at the alternative-count overflow raised before the depth check, so a pattern with 33 nested braces and 17 alternatives was read as a star and matched unrelated files. too_deep now measures the nesting of matched braces on its own, independent of the capped expansion; a test combines both limits, also with an overflowing brace before the deep one.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change class: CONTRACT (head 98833fe)

  • Contract: changed. dispatch dokimi/dokimi/brace_alternatives.py:44; errors dokimi/dokimi/brace_alternatives.py:73
  • Responsibility: candidate. delegate _glob_regex in dokimi/dokimi/pattern_glob.py; policy dokimi/docs/architecture.md
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

No new blocking findings on 98833fe7.

Reviewed the diff, edge cases and prior threads. Focused tests: 25 passed on head. The full local suite was outside coverage.

This branch has not been deployed

No deployments
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.

manifest globs (guidance.globs, also_scan, useful.edit) do not expand a {a,b} brace

5 participants