Skip to content

Fix misleading mock sort comment and use stable sort in MockGeneratorPlugin - #1997

Open
waldekmastykarz wants to merge 1 commit into
dotnet:mainfrom
waldekmastykarz:literate-parakeet
Open

waldekmastykarz wants to merge 1 commit into
dotnet:mainfrom
waldekmastykarz:literate-parakeet

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Closes #1974

Summary

The comment in MockGeneratorPlugin said mocks are sorted by URL length so the most specific comes first. The code actually sorts by descending ordinal URL.

The issue suggested that a shorter URL could shadow a longer one. That can't happen with generated mocks: they always use exact, wildcard-free URLs, and MockResponsePlugin matches those only on exact (case-insensitive) URL equality. Pattern matching is used only when a mock URL contains *.

Changes

  • Update the comment to describe what the sort actually does (groups mocks by URL for readability).
  • Replace the unstable List.Sort with a stable OrderByDescending(..., StringComparer.Ordinal). Previously, when the same URL was recorded many times, the mocks for that URL could be reordered relative to their recorded order. This affected which mock is served first.

Tests

  • Added MockGenerator_PreservesRecordedOrderForSameUrl. It fails with the old sort and passes with the fix.
  • GenerationPluginsIntegrationTests: 7/7 pass.

…Plugin. Closes dotnet#1974

The comment claimed mocks are sorted by URL length so that the most
specific comes first, but the code sorts by descending ordinal URL.
Generated mocks use exact URLs, so the order doesn't affect matching.
Update the comment to reflect this and replace the unstable List.Sort
with a stable OrderByDescending so repeated requests to the same URL
keep their recorded order.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e010e7fb-27f1-4b60-b3a6-1717b55ced91
Copilot AI balanced review requested due to automatic review settings October 21, 2026 14:46
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 21, 2026 14:46

Copilot AI 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.

🟢 Approval recommended

The localized change preserves existing URL ordering, adds focused regression coverage, and has no identified blocking issues.

No open issues 🎉

What changed in this PR

Makes generated mock ordering stable while preserving descending ordinal URL grouping.

Changes:

  • Corrects the misleading sort comment.
  • Preserves recorded order for mocks with identical URLs.
  • Adds regression coverage for URL grouping and stable ordering.
File Description
DevProxy.Plugins/​Generation/​MockGeneratorPlugin.cs Uses stable sorting and clarifies its purpose.
DevProxy.Integration.Tests/​GenerationPluginsIntegrationTests.cs Tests recorded order preservation within URL groups.

Review effort: Balanced

Copilot AI 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.

🟢 Approval recommended

The localized change preserves existing URL ordering, adds regression coverage for stability, and has no identified blocking issues.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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.

MockGeneratorPlugin doesn't sort mocks from most to least specific

2 participants