Skip to content

test(core-tools): resolve macOS symlink path mismatches in tests - #27990

Closed
luisfelipe-alt wants to merge 1 commit into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_495551283
Closed

luisfelipe-alt wants to merge 1 commit into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_495551283

Conversation

@luisfelipe-alt

Copy link
Copy Markdown
Contributor

Summary

This PR resolves macOS-specific test failures in EditTool and WriteFileTool caused by path resolution mismatches. On macOS, /var is 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:

  1. Mock Workspace Context (packages/core/src/test-utils/mockWorkspaceContext.ts):

    • Updated createMockWorkspaceContext to resolve all input directories to their real paths using fs.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 in edit.test.ts and boundary failures in write-file.test.ts.
  2. WriteFileTool Tests (packages/core/src/tools/write-file.test.ts):

    • Updated three specific test cases to resolve expected paths to their real paths using resolveToRealPath before asserting:
      • 'should throw an error if path is a directory': Resolves dirAsFilePath to its real path before asserting the thrown error message.
      • 'should return error if reading an existing file fails (e.g. permissions)': Resolves filePath to its real path before asserting that fsService.readTextFile was called with it.
      • 'should return $errorType error when write fails with $errorCode': Resolves filePath to its real path before constructing the expectedMessage used in assertions.
  3. EditTool Tests (packages/core/src/tools/at-reference-resolution.test.ts):

    • Added comprehensive integration tests to verify that EditTool successfully 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:

npx vitest run packages/core/src/tools/edit.test.ts
npx vitest run packages/core/src/tools/write-file.test.ts
npx vitest run packages/core/src/tools/at-reference-resolution.test.ts

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:

npx vitest run packages/core/src/tools/write-file.test.ts packages/core/src/tools/at-reference-resolution.test.ts

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 typecheck

Expected Output: Zero linting or type-checking errors.

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
    • Windows
      • npm run
      • npx
    • Linux
      • npm run
      • npx

@luisfelipe-alt
luisfelipe-alt requested review from a team as code owners June 17, 2026 17:25
@github-actions github-actions Bot added the size/xl An extra large PR label Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 172
  • Additions: +150
  • Deletions: -22
  • Files changed: 7

@github-actions

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@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 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 @, preventing unintended directory creation and improving overall path sanitization.

Highlights

  • macOS Path Resolution Fixes: Resolved macOS-specific test failures in EditTool and WriteFileTool by addressing path resolution mismatches, particularly the /var vs /private/var symbolic link behavior.
  • Mock Workspace Context Enhancement: Updated createMockWorkspaceContext to use fs.realpathSync for all input directories, ensuring mock environments correctly reflect real paths on macOS.
  • Tool Path Resolution Logic: Integrated resolveToRealPath and resolveDefensiveToolPath into EditTool, ReadFileTool, and WriteFileTool to consistently resolve file paths to their canonical forms and handle @ prefixed paths.
  • New Integration Tests: Added comprehensive integration tests in at-reference-resolution.test.ts to validate EditTool and WriteFileTool behavior with @ prefixed paths, path traversal, and symlink loops.
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. ↩

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

Comment thread packages/core/src/utils/paths.ts Outdated
@luisfelipe-alt
luisfelipe-alt force-pushed the bugfix/WT-engineer_495551283 branch from 8a15bc5 to c723772 Compare June 17, 2026 17:53
@github-actions github-actions Bot added the size/m A medium sized PR label Jun 17, 2026
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Jun 17, 2026
@luisfelipe-alt
luisfelipe-alt force-pushed the bugfix/WT-engineer_495551283 branch from c723772 to 09eac4a Compare June 17, 2026 18:11
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

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

@luisfelipe-alt
luisfelipe-alt force-pushed the bugfix/WT-engineer_495551283 branch from 09eac4a to 00be057 Compare June 17, 2026 18:41
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

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

@gemini-cli

gemini-cli Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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.

@gemini-cli

gemini-cli Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized PR size/xl An extra large PR status/need-issue Pull requests that need to have an associated issue. status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant