Skip to content

Count intercepted requests for mock nth - #1987

Merged
waldekmastykarz merged 3 commits into
dotnet:mainfrom
waldekmastykarz:fix-1958-mock-nth-counting
Oct 26, 2026
Merged

waldekmastykarz merged 3 commits into
dotnet:mainfrom
waldekmastykarz:fix-1958-mock-nth-counting

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Closes #1958

nth on mocks counted applied mocks, so without a fallback mock for the same URL the counter never advanced and the nth mock never fired.

Now MockResponsePlugin and MockStdioResponsePlugin count every intercepted request/message matching the mock (method, URL, body / stdin pattern), whether or not a mock is applied. Existing setups with a fallback mock behave the same.

Tests: added integration tests for nth with and without a fallback mock (exact and wildcard URL). DevProxy.Integration.Tests: 96/96 pass.

MockResponsePlugin and MockStdioResponsePlugin only advanced the nth
counter when a mock was applied. Without a fallback mock for the same
URL, the counter never advanced and nth mocks never fired. The counter
now advances for every intercepted request matching the mock, whether
or not a mock is applied.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 476a98f9-0a66-4679-a5cd-03dc3f03e45d
Copilot AI balanced review requested due to automatic review settings October 21, 2026 13:56
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 21, 2026 13:56

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.

🟡 Changes recommended

Shared counter keys allow unrelated HTTP or stdin matchers to consume each other's occurrences.

2 open issues
What changed in this PR

Updates HTTP and stdin mock counting so nth advances on matching intercepted traffic, even when no mock is applied, addressing #1958.

Changes:

  • Separates request matching from occurrence selection.
  • Counts matching requests and messages before selecting a mock.
  • Adds HTTP tests covering fallback behavior and exact/wildcard URLs.
File Description
DevProxy.Plugins/​Mocking/​MockStdioResponsePlugin.cs Counts matching stdin messages before mock selection.
DevProxy.Plugins/​Mocking/​MockResponsePlugin.cs Counts matching HTTP requests before mock selection.
DevProxy.Integration.Tests/​ManipulationAndMockingIntegrationTests.cs Adds regression coverage for HTTP nth behavior.

Review effort: Balanced

Comment thread DevProxy.Plugins/Mocking/MockResponsePlugin.cs Outdated
Comment thread DevProxy.Plugins/Mocking/MockStdioResponsePlugin.cs

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.

🔵 Needs a closer look

Shared counter keys still let distinct matchers advance each other’s occurrence counts.

2 open issues

Review effort: Balanced

Address Copilot feedback on dotnet#1987 with HTTP and stdio regression coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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 focused changes address the reported defect, include regression coverage for counter grouping, and have no unresolved review findings.

No open issues 🎉

2 resolved since last review

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

Static review found no blocking issues in the focused counter changes or regression coverage; tests were not rerun during this review.

No open issues 🎉

Review effort: Balanced

@waldekmastykarz
waldekmastykarz merged commit 94a9579 into dotnet:main Oct 26, 2026
4 checks passed
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.

Mock nth counts applied mocks, not intercepted requests

2 participants