Skip to content

Fix incorrect inspect property usage in scope detection#301472

Open
ShehabSherif0 wants to merge 2 commits intomicrosoft:mainfrom
ShehabSherif0:fix/inspect-property-scope-bugs
Open

Fix incorrect inspect property usage in scope detection#301472
ShehabSherif0 wants to merge 2 commits intomicrosoft:mainfrom
ShehabSherif0:fix/inspect-property-scope-bugs

Conversation

@ShehabSherif0
Copy link
Copy Markdown
Contributor

@ShehabSherif0 ShehabSherif0 commented Mar 13, 2026

Fixes #301471

Bug

Two IConfigurationValue property accesses introduced in bb18007 use the IInspectValue<T> object property instead of the scalar value property, causing incorrect scope detection.

1. themeConfiguration.ts - findAutoConfigurationTarget()

settings.userRemote is an IInspectValue<T> object ({value?, override?, overrides?}), not the scalar T value. It can be defined when only language-specific overrides exist in the remote config, even with no actual remote value set. This causes the function to incorrectly return USER_REMOTE, making theme settings target the wrong configuration scope.

Fix: settings.userRemote -> settings.userRemoteValue

2. commandLineAutoApprover.ts - source target detection

configInspectValue.workspaceFolder is an IInspectValue<T> object whose keys are {value, override, overrides}. The checkTarget function looks for tool-pattern keys (e.g., "git*") via hasOwnProperty, which never matches on IInspectValue. Workspace-folder-scoped auto-approve rules are never detected and fall through to a lower-priority scope.

Fix: configInspectValue.workspaceFolder -> configInspectValue.workspaceFolderValue

Root Cause

Both uses are from the same commit (bb18007). The IConfigurationValue<T> interface exposes both scalar values (userRemoteValue: T) and inspect objects (userRemote: IInspectValue<T>). The similar naming makes it easy to use the wrong one.

Testing

Added a regression test that stubs configurationService.inspect to return a workspaceFolderValue containing a rule key and asserts the matched rule reports sourceTarget as ConfigurationTarget.WORKSPACE_FOLDER.

Copilot AI review requested due to automatic review settings March 13, 2026 11:50
Copy link
Copy Markdown
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 incorrect use of IInspectValue<T> (inspect metadata objects) where scalar *Value properties should be used for configuration scope detection, preventing misclassification of configuration targets.

Changes:

  • Use settings.userRemoteValue (scalar) instead of settings.userRemote (inspect object) when auto-selecting theme configuration target.
  • Use configInspectValue.workspaceFolderValue (scalar) instead of configInspectValue.workspaceFolder (inspect object) when determining the source target for auto-approve rules.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/vs/workbench/services/themes/common/themeConfiguration.ts Fixes auto-target selection to correctly detect USER_REMOTE based on the scalar remote value.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/commandLineAnalyzer/autoApprove/commandLineAutoApprover.ts Fixes workspace-folder scope detection for auto-approve rule source targeting by using the scalar workspace-folder value.

You can also share your feedback on Copilot code review. Take the survey.

@ShehabSherif0
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

In findAutoConfigurationTarget() (themeConfiguration.ts), change
settings.userRemote to settings.userRemoteValue. The former is an
IInspectValue<T> object that can be defined when only language
overrides exist, causing the function to incorrectly return
USER_REMOTE when no actual remote value is set.

In commandLineAutoApprover.ts, change configInspectValue.workspaceFolder
to configInspectValue.workspaceFolderValue. The former is an
IInspectValue<T> object whose keys are {value, override, overrides},
so checkTarget() never finds tool-pattern keys on it, making
workspace-folder-scoped auto-approve rules undetectable.

Both properties were introduced in bb18007.
@ShehabSherif0
Copy link
Copy Markdown
Contributor Author

@sandy081 I have posted detailed reproduction steps and type-level analysis on the linked issue in response to your question.

Quick summary of the two fixes in this PR:

  1. commandLineAutoApprover.ts (active bug): configInspectValue.workspaceFolder is an IInspectValue object with keys {value, override, overrides}. The checkTarget function does hasOwnProperty(obj, "git*") on it, which always returns false. Changing to configInspectValue.workspaceFolderValue passes the scalar config object {"git*": true}, where hasOwnProperty works correctly. The other scopes in the same chain already use the correct *Value properties.

  2. themeConfiguration.ts (dead code): findAutoConfigurationTarget currently has zero callers, so no runtime impact. But settings.userRemote is IInspectValue<T> (can be non-undefined from language overrides alone) while settings.userRemoteValue is the scalar T value. Fixed for correctness.

A regression test is included that verifies workspace-folder-scoped rules get ConfigurationTarget.WORKSPACE_FOLDER as their sourceTarget.

@sandy081 sandy081 assigned Tyriar and meganrogge and unassigned sandy081 Mar 19, 2026
@meganrogge meganrogge added this to the 1.113.0 milestone Mar 19, 2026
meganrogge
meganrogge previously approved these changes Mar 19, 2026
Copy link
Copy Markdown
Collaborator

@meganrogge meganrogge left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM!

@meganrogge meganrogge enabled auto-merge (squash) March 19, 2026 15:04
dmitrivMS
dmitrivMS previously approved these changes Mar 19, 2026
@ShehabSherif0
Copy link
Copy Markdown
Contributor Author

ShehabSherif0 commented Mar 20, 2026

Hi @dmitrivMS @meganrogge thank you both for the approvals!

The CI is failing because of an issue in the regression test I added. The test config uses 'git*': true as the auto-approve pattern, but since git* isn't wrapped in /.../, the auto-approver treats it as a plain string. The * gets escaped to \* by escapeRegExpCharacters, producing the regex /^git\*\b/ - which only matches the literal text git*, not git status.

The fix is a one-character change: 'git*' -> 'git'. The pattern 'git' becomes /^git\b/, which correctly matches git status (space is a word boundary). The production code fix itself is unaffected.

I'm pushing this now - apologies that it'll reset the approval status. The diff should be trivially reviewable (single character removal in test data).

The test config 'git*' gets escaped to regex /^git\*\b/ which only matches
the literal string 'git*', not 'git status'. Changed to 'git' which produces
/^git\b/ and correctly matches 'git status' via word boundary.
auto-merge was automatically disabled March 20, 2026 08:48

Head branch was pushed to by a user without write access

@ShehabSherif0 ShehabSherif0 dismissed stale reviews from dmitrivMS and meganrogge via 0674d4c March 20, 2026 08:48
@Tyriar Tyriar removed their assignment Mar 24, 2026
@jrieken jrieken modified the milestones: 1.113.0, On Deck Mar 25, 2026
@ShehabSherif0
Copy link
Copy Markdown
Contributor Author

Please approve this @meganrogge it was supposed to be approved and merged before. Thank you!

@meganrogge meganrogge enabled auto-merge (squash) March 31, 2026 16:11
@meganrogge meganrogge modified the milestones: On Deck, 1.115.0 Mar 31, 2026
@alexr00 alexr00 removed this from the 1.115.0 milestone Apr 8, 2026
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.

Incorrect IInspectValue property used instead of scalar value in scope detection

9 participants