fix: replace substring matching with path-component matching in exclusions#159
Merged
danielmeppiel merged 3 commits intomicrosoft:mainfrom Mar 4, 2026
Conversation
…sions
Replace `ignore in str(current_path)` with `part in (...) for part in
relative_parts` in _analyze_project_structure() to prevent false positive
exclusions. Directories like 'rebuild/', 'redistribution/', or
'apm_modules_guide/' were incorrectly excluded because their names
contain exclusion tokens ('build', 'dist', 'apm_modules') as substrings.
Fixes microsoft#158
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes incorrect directory exclusion behavior in ContextOptimizer._analyze_project_structure() by switching from substring-based checks to exact path-component matching, preventing false-positive exclusions like rebuild/ being excluded due to build.
Changes:
- Replace substring matching on
str(current_path)with path-component matching oncurrent_path.relative_to(base_dir).partsfor default exclusions. - Add unit tests covering false-positive cases (e.g.,
rebuild/,redistribution/,node_modules_compat/) and ensuring exact-name exclusions still apply.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/apm_cli/compilation/context_optimizer.py |
Updates default exclusion logic in _analyze_project_structure() to use path-component matching. |
tests/unit/compilation/test_context_optimizer.py |
Adds regression tests to ensure substring false-positives are not excluded while exact matches still are. |
You can also share your feedback on Copilot code review. Take the survey.
- Reuse already-computed relative_path instead of calling relative_to() a second time, avoiding unguarded ValueError (review comment 1) - Extract DEFAULT_EXCLUDED_DIRNAMES frozenset constant shared by _analyze_project_structure and _should_exclude_subdir (review comment 2) - Update docs/cli-reference.md and docs/compilation.md to clarify that exclusions match on exact path components (review comment 3)
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
Replace substring matching (
ignore in str(current_path)) with path-component matching (part in (...) for part in relative_parts) in_analyze_project_structure(). The substring approach caused false-positive exclusions for directories whose names contain an exclusion token (e.g.rebuild/matchingbuild,redistribution/matchingdist,apm_modules_guide/matchingapm_modules).Fixes #158
Type of change
Testing
New tests (
TestSubstringExclusionFalsePositives, 3 cases):test_directory_containing_exclusion_token_not_excluded— verifiesrebuild/,apm_modules_guide/,redistribution/,node_modules_compat/are not excludedtest_exact_exclusion_names_still_excluded— verifiesbuild/,dist/,node_modules/,__pycache__/are still excludedtest_nested_exclusion_name_still_excluded— verifiessrc/build/is still excludedAll 40 tests pass.