Skip to content

Fix incorrect inspect property usage in scope detection - #301472

Merged
Dmitriy Vasyura (dmitrivMS) merged 2 commits into
microsoft:mainfrom
ShehabSherif0:fix/inspect-property-scope-bugs
May 5, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 2 commits into
microsoft:mainfrom
ShehabSherif0:fix/inspect-property-scope-bugs

Conversation

@ShehabSherif0

@ShehabSherif0 Shehab Sherif (ShehabSherif0) commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

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

Copilot AI 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.

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

Sandeep Somavarapu (@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.

@meganrogge Megan Rogge (meganrogge) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! LGTM!

@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) March 19, 2026 15:04
@ShehabSherif0

Shehab Sherif (ShehabSherif0) commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi Dmitriy Vasyura (@dmitrivMS) Megan Rogge (@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

@Tyriar Daniel Imms (Tyriar) removed their assignment Mar 24, 2026
@jrieken Johannes Rieken (jrieken) modified the milestones: 1.113.0, On Deck Mar 25, 2026
@ShehabSherif0

Copy link
Copy Markdown
Contributor Author

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

@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) March 31, 2026 16:11
@alexr00 Alex Ross (alexr00) removed this from the 1.115.0 milestone Apr 8, 2026
@gjsjohnmurray

Copy link
Copy Markdown
Contributor

What is preventing this from getting merged?

@dmitrivMS

Copy link
Copy Markdown
Collaborator

John Murray (@gjsjohnmurray) Strange... it was stuck waiting for approvals while it should have had 2 already.

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Hmm... now it's stuck on the checks. Shehab Sherif (@ShehabSherif0) if you merge from main and retrigger, perhaps it will help to clear those...

auto-merge was automatically disabled May 5, 2026 02:45

Pull request was closed

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Ok, doing Close/Reopen to retrigger checks.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) enabled auto-merge (squash) May 5, 2026 02:49
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 44a5af2 into microsoft:main May 5, 2026
55 of 67 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.120.0 milestone May 5, 2026
@dmitrivMS

Copy link
Copy Markdown
Collaborator

John Murray (@gjsjohnmurray) Merged!

@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jun 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

10 participants