Skip to content

fix(core): make isWithinRoot case-insensitive on Windows - #29247

Open
mydd7 wants to merge 2 commits into
google-gemini:mainfrom
mydd7:win-root-case
Open

fix(core): make isWithinRoot case-insensitive on Windows#29247
mydd7 wants to merge 2 commits into
google-gemini:mainfrom
mydd7:win-root-case

Conversation

@mydd7

@mydd7 mydd7 commented Sep 8, 2026

Copy link
Copy Markdown

Summary

isWithinRoot() compared paths with case-sensitive === / startsWith. On Windows that rejects valid in-root paths when the drive letter or folder casing differs (c:\... vs C:\...), which breaks ACP/IDE FS routing and ignore-path normalization.

Reuse isSubpath(), which already does a case-insensitive check on Windows (and Darwin).

Details

isSubpath() already uses path.win32 and case-insensitive relative() on Windows. isWithinRoot() was a second containment helper that did not.

macOS /private alias handling is unchanged; it now also goes through isSubpath().

Related Issues

Fixes #29000

How to Validate

  1. On Windows, call isWithinRoot('C:\\Users\\proj\\file.ts', 'c:\\Users\\proj') — should be true.
  2. packages/core tests: isWithinRoot on Windows (drive-letter casing, path-component casing, different drive).
  3. Existing isWithinRoot cases still pass on POSIX.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@mydd7
mydd7 requested a review from a team as a code owner September 8, 2026 16:52
@google-cla

google-cla Bot commented Sep 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the size/m A medium sized PR label Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 48
  • Additions: +25
  • Deletions: -23
  • Files changed: 2

@mydd7

mydd7 commented Sep 8, 2026

Copy link
Copy Markdown
Author

CLA check is red until the Google CLA is signed at https://cla.developers.google.com/

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where path validation in the core package was failing on Windows due to case-sensitive comparisons. By migrating the logic to use the established isSubpath utility, the implementation now correctly accounts for Windows' case-insensitive file system behavior, improving the reliability of IDE file system routing and path normalization.

Highlights

  • Path comparison logic: Refactored the isWithinRoot function to utilize the existing isSubpath utility, ensuring consistent and robust cross-platform path handling.
  • Windows compatibility: Enabled case-insensitive path comparisons on Windows to prevent false negatives caused by drive letter or folder casing discrepancies.
  • Testing: Added comprehensive unit tests to verify that isWithinRoot correctly handles case-insensitive paths on Windows while maintaining existing behavior on other platforms.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mydd7

mydd7 commented Sep 8, 2026

Copy link
Copy Markdown
Author

I signed the CLA.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors the isWithinRoot utility in packages/core/src/utils/fileUtils.ts to use the isSubpath helper, simplifying the path comparison and macOS symlink handling. It also introduces Windows-specific unit tests. The feedback points out that mocking process.platform inside a block already skipped on non-Windows platforms is redundant and that stubbing the global process object is risky and should be removed.

Comment on lines +180 to +192
const mockPlatform = (platform: string) => {
vi.stubGlobal(
'process',
Object.create(process, {
platform: {
get: () => platform,
},
}),
);
};

beforeEach(() => mockPlatform('win32'));
afterEach(() => vi.unstubAllGlobals());

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.

high

Since this describe block is already skipped on non-Windows platforms using describe.skipIf(process.platform !== 'win32'), the tests inside will only ever execute on Windows. Consequently, mocking process.platform to 'win32' is completely redundant.

Furthermore, stubbing the global process object using Object.create(process, ...) can be risky in Vitest/Node.js environments as it can interfere with other native properties or event listeners on process. Removing this redundant mocking simplifies the test and avoids potential side-effects.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed the stub. The suite is already skipIf non-win32, so the mock was redundant.

@github-actions github-actions Bot added the size/s A small PR label Sep 8, 2026
@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality size/m A medium sized PR size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(windows): isWithinRoot() path containment check is case-sensitive, so valid in-root paths (e.g. different drive-letter casing) are rejected

1 participant