Skip to content

fix(core): normalize line endings in diff context snippets - #29132

Open
mikemikimike wants to merge 2 commits into
google-gemini:mainfrom
mikemikimike:fix/crlf-diff-context-29130
Open

fix(core): normalize line endings in diff context snippets#29132
mikemikimike wants to merge 2 commits into
google-gemini:mainfrom
mikemikimike:fix/crlf-diff-context-29130

Conversation

@mikemikimike

Copy link
Copy Markdown

Summary

  • Normalize CRLF and CR line endings before computing diff context snippets.
  • Add a regression test covering a CRLF file with one changed line.

Fixes #29130

Testing

  • npm run test:ci
  • npm run typecheck --workspace @google/gemini-cli-core
  • npm exec prettier -- --check packages/core/src/tools/diff-utils.ts packages/core/src/tools/diff-utils.test.ts
  • npm exec eslint packages/core/src/tools/diff-utils.ts packages/core/src/tools/diff-utils.test.ts
  • git diff --check

@mikemikimike
mikemikimike requested a review from a team as a code owner August 30, 2026 10:33
@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 addresses an issue where inconsistent line endings caused incorrect diff context generation. By normalizing line endings to LF before processing, the tool now correctly identifies logical changes without being affected by platform-specific newline characters.

Highlights

  • Line Ending Normalization: Updated the diff utility to normalize CRLF and CR line endings to LF before performing line-by-line comparisons.
  • Regression Testing: Added a new test case to ensure that CRLF line endings do not cause false positives when calculating diff context snippets.
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.

@github-actions github-actions Bot added the size/s A small PR label Aug 30, 2026
@github-actions

github-actions Bot commented Aug 30, 2026

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 28
  • Additions: +26
  • Deletions: -2
  • Files changed: 2

@github-actions

github-actions Bot commented Aug 30, 2026

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 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 normalizes line endings to \n in diff-utils.ts before performing line diffing to prevent CRLF differences from being flagged as changes, and adds a corresponding unit test. The reviewer pointed out a potential inconsistency where normalizedNew is normalized to \n but newLines is still split using /\r?\n/ on the original content, which could lead to mismatched line counts or out-of-bounds errors. The reviewer suggested splitting normalizedNew by \n instead.

Comment thread packages/core/src/tools/diff-utils.ts
@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Aug 30, 2026
@mikemikimike
mikemikimike marked this pull request as draft August 30, 2026 10:41
@mikemikimike

Copy link
Copy Markdown
Author

Updated the fix based on review feedback.

  • Use normalizedNew.split('\\n') so diff indexes and extracted lines use the same normalized representation.
  • Add a regression test for standalone CR line endings.

Local validation:

  • npx vitest run packages/core/src/tools/diff-utils.test.ts --coverage=false — 9/9 passed.
  • Docker: pathReader.test.ts — 22/22 passed.
  • Docker: sandboxManager.integration.test.ts — 34/34 passed with bubblewrap and privileged namespace support.
  • Core typecheck — passed.
  • Core build — passed.
  • Prettier and ESLint for the changed files — passed.

The broader Core suite was also exercised in Docker; its remaining environment-sensitive failures were isolated to sandbox namespace availability before bubblewrap was installed. The targeted suites above pass after the environment was corrected.

@mikemikimike
mikemikimike force-pushed the fix/crlf-diff-context-29130 branch from fee11de to 871dc21 Compare August 30, 2026 21:36
@mikemikimike
mikemikimike marked this pull request as ready for review August 30, 2026 21:36

@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 updates the diff utility functions in packages/core/src/tools/diff-utils.ts to normalize line endings (CRLF and CR to LF) before computing line differences and splitting the content. This ensures that changing only the line-ending style does not incorrectly trigger diffs. Corresponding unit tests have been added to packages/core/src/tools/diff-utils.test.ts to verify CRLF and CR line-ending handling. There are no review comments, so I have no feedback to provide.

@mikemikimike

Copy link
Copy Markdown
Author

当前 head 已落实该建议:newLines 改为基于 normalizedNew.split('\n'),并补充 standalone CR 回归测试。关闭此旧线程。

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/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): getDiffContextSnippet produces full-file diff on CRLF line endings due to unnormalized line breaks

2 participants