Skip to content

Conversation

@roji
Copy link
Member

@roji roji commented Jul 20, 2025

While work on some tests I managed to reproduce the problem where changing the number of lines caused the rewriter to fail. The rewriter has logic to count the number of newlines in the old and new baselines, and apply the diff to any additional rewrites that need to occur later in the same file. The newline counting looked at either \r or \n, which I think was the source of the problem: there seems to have been a \r\n (Windows - though I think we're supposed to normalize newlines on commit), so this was counted as two newlines, skewing the count.

I'm fixing this by simply not looking at \r at all, and just counting \n. The only problem this could cause is with very old MacOS versions, where \r alone was used as the newline - but that really should no longer be relevant any more.

Fixes #35823

Disregard \r when counting newlines

Fixes dotnet#35823
@roji roji requested review from a team and Copilot July 20, 2025 10:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in the SQL baseline rewriting functionality where changing the number of lines caused the rewriter to fail due to incorrect newline counting. The issue was caused by counting both \r and \n characters separately, which led to Windows-style \r\n line endings being counted as two newlines instead of one.

  • Fixed newline counting to only count \n characters, ignoring \r entirely
  • Added logic to prevent duplicate processing of the same line number (e.g., when theory tests execute multiple times)
  • Enhanced the QueryBaselineRewritingFileInfo class with a ProcessedLines tracking mechanism

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/EFCore.Relational.Specification.Tests/TestUtilities/TestSqlLoggerFactory.cs Fixed newline counting logic and added duplicate line processing prevention
test/EFCore.Cosmos.FunctionalTests/TestUtilities/TestSqlLoggerFactory.cs Applied the same newline counting fix and duplicate prevention as the relational tests
Comments suppressed due to low confidence (1)

@roji roji enabled auto-merge (squash) July 20, 2025 10:18
@roji roji merged commit 48e0367 into dotnet:main Jul 20, 2025
7 checks passed
@roji roji deleted the BaselineRewriter branch July 20, 2025 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Baseline rewriter doesn't handle multiple baseline changes in a single file affecting the number of lines.

3 participants