Repository navigation
Fix misleading mock sort comment and use stable sort in MockGeneratorPlugin - #1997
Open
waldekmastykarz wants to merge 1 commit into
Open
waldekmastykarz wants to merge 1 commit into
waldekmastykarz wants to merge 1 commit into
Conversation
…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
Contributor
There was a problem hiding this comment.
🟢 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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1974
Summary
The comment in
MockGeneratorPluginsaid 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
MockResponsePluginmatches those only on exact (case-insensitive) URL equality. Pattern matching is used only when a mock URL contains*.Changes
List.Sortwith a stableOrderByDescending(..., 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
MockGenerator_PreservesRecordedOrderForSameUrl. It fails with the old sort and passes with the fix.GenerationPluginsIntegrationTests: 7/7 pass.