Repository navigation
test(core-tools): resolve macOS symlink path mismatches in tests - #27990
luisfelipe-alt wants to merge 1 commit into
Conversation
|
📊 PR Size: size/M
|
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
Summary of ChangesHello, 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 introduces critical fixes to path resolution within the core tools, specifically targeting inconsistencies observed on macOS due to symbolic links. By ensuring that file paths are consistently resolved to their real, canonical forms across both production code and test environments, it eliminates platform-specific test failures and enhances the robustness of file operations. The changes also refine how tools handle special path prefixes like Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces defensive path resolution and sanitization for file-manipulation tools (EditTool, ReadFileTool, WriteFileTool) to handle LLM-generated paths prefixed with '@' or '@/'. It adds helper functions 'resolveDefensiveToolPath' and 'resolveToRealPath' to resolve paths to their real counterparts on disk, along with a comprehensive test suite. Feedback on the changes highlights a potential vulnerability where returning paths containing null bytes ('\0') unmodified can cause downstream synchronous file system operations to crash with a TypeError; sanitizing these paths by stripping null bytes is recommended.
8a15bc5 to
c723772
Compare
c723772 to
09eac4a
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request improves path resolution and sanitization across the codebase. Specifically, resolveDefensiveToolPath in packages/core/src/utils/paths.ts has been updated to strip null bytes globally from file paths rather than returning the path unmodified. Safe real-path resolution has also been introduced in mockWorkspaceContext.ts to resolve root and additional directories, and test assertions in write-file.test.ts have been updated to use resolveToRealPath. New unit tests have been added to verify these path resolution and sanitization behaviors. No review comments were provided, so there is no feedback to address.
09eac4a to
00be057
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances path sanitization and resolution. It updates resolveDefensiveToolPath to globally strip null bytes from file paths before resolving them, and adds corresponding unit tests. It also updates several test suites and mock contexts to resolve temporary and root directories to their real paths using fs.realpathSync, preventing test failures related to symlinked temporary directories. Finally, it adds tests for EditTool handling of @/ and @\ prefixed paths in nested subdirectories. There are no review comments to address, so no feedback is provided.
00be057 to
ee9b2cc
Compare
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
|
This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Summary
This PR resolves macOS-specific test failures in
EditToolandWriteFileToolcaused by path resolution mismatches. On macOS,/varis a symbolic link pointing to/private/var. While the production code correctly resolves paths to their real paths (starting with/private/var), the mock workspace context and some test assertions expected the unresolved paths (starting with/var), leading to boundary validation and assertion failures.Details
We applied targeted, platform-aware fixes to align the test environment with the production path resolution behavior:
Mock Workspace Context (
packages/core/src/test-utils/mockWorkspaceContext.ts):createMockWorkspaceContextto resolve all input directories to their real paths usingfs.realpathSync. This ensures that on macOS, any directory starting with/var/...is correctly resolved to/private/var/..., matching the behavior of the production code and fixing 30 failures inedit.test.tsand boundary failures inwrite-file.test.ts.WriteFileTool Tests (
packages/core/src/tools/write-file.test.ts):resolveToRealPathbefore asserting:'should throw an error if path is a directory': ResolvesdirAsFilePathto its real path before asserting the thrown error message.'should return error if reading an existing file fails (e.g. permissions)': ResolvesfilePathto its real path before asserting thatfsService.readTextFilewas called with it.'should return $errorType error when write fails with $errorCode': ResolvesfilePathto its real path before constructing theexpectedMessageused in assertions.EditTool Tests (
packages/core/src/tools/at-reference-resolution.test.ts):EditToolsuccessfully creates new files in nested subdirectories when the path is prefixed with@/or@\and the first segment does not exist, without creating a literal@directory.Related Issues
How to Validate
Step 1: Run the modified test suites on macOS
Run the following commands on a macOS machine to verify that all tests pass successfully:
Expected Output: All 125+ tests pass successfully with zero failures.
Step 2: Run the test suites on Linux/Windows (Regression Check)
Run the same commands on Linux or Windows to ensure zero regressions:
Expected Output: All 63 tests pass successfully with zero failures.
Step 3: Run linting and type checking
Verify that the codebase remains fully compliant with the project's engineering standards:
npm run lint && npm run typecheckExpected Output: Zero linting or type-checking errors.
Pre-Merge Checklist