Skip to content

feat(scm-multi-platform-detection): Implementing scoped matching#117720

Merged
Abdkhan14 merged 4 commits into
masterfrom
abdk/multi-platform-detection-v8
Jun 18, 2026
Merged

feat(scm-multi-platform-detection): Implementing scoped matching#117720
Abdkhan14 merged 4 commits into
masterfrom
abdk/multi-platform-detection-v8

Conversation

@Abdkhan14

@Abdkhan14 Abdkhan14 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Refactored _TreeIndex and _build_tree_index to track full paths separately for files (files_full_paths_by_basename) and directories (dirs_full_paths_by_basename), enabling location-aware detection across monorepo subtrees.

Added _parent_dir and _rule_parent_dirs to compute which parent directories a given rule is satisfiable in. Added _rule_existence_fires_in_scope to check whether a rule fires within a specific directory scope. These feed into _framework_matches_scoped, which replaces the old flat matcher — for every rules it intersects per-rule parent dir sets, so a framework only fires when all its conditions are co-located in the same subtree. This prevents false positives from scattered files (e.g. .csproj in one service and appsettings.json in another incorrectly matching dotnet-aspnetcore).

Added unit tests in test_multi_platform_detection.py covering all four new/modified functions.

@Abdkhan14 Abdkhan14 requested review from a team as code owners June 15, 2026 19:21
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 15, 2026
@Abdkhan14 Abdkhan14 marked this pull request as draft June 15, 2026 20:19
@Abdkhan14 Abdkhan14 marked this pull request as ready for review June 16, 2026 17:35
Comment on lines +446 to +447
files_basenames = set(files_full_paths_by_basename.keys())
dirs_basenames = set(dirs_full_paths_by_basename.keys())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The some-only branch rebuilds both basename sets on every call, which the old tree_files = index.files materialization (removed here) was avoiding. Could we hoist them into detect_platforms_multi and pass them in so they're built once?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yep, adding this in now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the change for this in the stacked branch already: #117745

…ed reads (#117745)

Unified `_rule_parent_dirs` and _framework_matches_scoped to handle all
rule types — existence, match_content, and match_package — in a single
pass each. Both now accept content_by_path and manifests_by_path;
passing empty dicts for these in the existence pass makes
content/package rules silently return empty sets with no special-casing
needed.

Added content reads to detect_platforms_multi as a second
high-confidence pass. After existence matching, `_collect_needed_paths`
identifies candidate files, up to `MAX_CONTENT_READS` = 5 are fetched
using the existing `_get_repo_file_content` and _parse_package_manifest
helpers, sorted shallowest-first so root manifests are always within the
cap. Supersession runs after both passes so content-detected frameworks
can supersede existence matches.

Added `TestCollectNeededPaths` and `TestDetectPlatformsMulti` covering
the major branches: content-only detection, package-only detection, the
shallow-first cap, content-driven supersession, and the zero-reads case.

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5ab1180. Configure here.


# every+some: at least one some rule must fire within a scope where all
# every rules are already satisfied.
return any(scope in scopes_for(rule) for scope in scopes for rule in some)

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.

Android scope mismatch every some

Medium Severity

Scoped matching for frameworks with both every and some requires the same parent-directory scope for every rule and at least one some rule. For Android, match_dir app at the repo root yields scope "", while a typical app/build.gradle match yields scope app, so the framework never matches despite a valid Gradle Android layout.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5ab1180. Configure here.

@Abdkhan14 Abdkhan14 Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will take a look at this separately. Doesn't necessarily break all android detection, there's a test on a real repo

@Abdkhan14 Abdkhan14 merged commit bb6beaa into master Jun 18, 2026
64 checks passed
@Abdkhan14 Abdkhan14 deleted the abdk/multi-platform-detection-v8 branch June 18, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants