Skip to content

Add per-mock rate to MockResponsePlugin - #2027

Open
waldekmastykarz wants to merge 1 commit into
dotnet:mainfrom
waldekmastykarz:per-mock-failure-rate
Open

waldekmastykarz wants to merge 1 commit into
dotnet:mainfrom
waldekmastykarz:per-mock-failure-rate

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Closes #103

Adds an optional rate property (integer 0-100, default 100) to mock entries in the mocks file.

  • When a mock matches (and passes its nth check), Dev Proxy rolls 1-100. If the roll is greater than rate, the mock is skipped and the request falls through to the next matching mock, the next plugin, or the real API.
  • Out-of-range values log a warning when the mocks file loads and are ignored, so the mock is always applied.
  • Only MockResponsePlugin (and plugins that inherit its matching) honors rate.
  • Bumps the version to 4.1.0 and adds rate to schemas/v4.1.0/mockresponseplugin.mocksfile.schema.json.
  • Adds integration tests for no rate, rate of 0, 50 and 100, invalid values, fallthrough to the next mock, and nth combined with rate.

Adds an optional rate (0-100, default 100) to mock entries. When the
roll fails, the mock is skipped and the request falls through to the
next matching mock, plugin, or the real API. Out-of-range rates log a
warning and are ignored. Bumps version to 4.1.0 and adds rate to the
v4.1.0 mocks file schema.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 31, 2026 09:01
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 31, 2026 09:01

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

Schema validation rejects an entire mocks file for out-of-range rates, preventing the warning fallback and unrelated valid mocks from loading; the schema needs adjustment and a schema-enabled loading test.

1 open issue
What changed in this PR

Adds per-mock response probabilities to Dev Proxy, addressing the failure-rate request in #103 while preserving always-apply behavior when rate is omitted.

Changes:

  • Adds rate-based mock selection after nth matching, with fallthrough and warnings for out-of-range values.
  • Adds integration coverage for default, boundary, invalid, partial-rate, and fallthrough behavior.
  • Updates version metadata to 4.1.0, adds versioned schemas, and refreshes bundled schema references.
File Description
scripts/​version.ps1 Updates beta version.
scripts/​local-setup.ps1 Updates local setup version.
scripts/​Dockerfile_local Updates local image version.
schemas/​v4.1.0/​websocketmockresponseplugin.schema.json Adds versioned WebSocket configuration schema.
schemas/​v4.1.0/​websocketmockresponseplugin.mocksfile.schema.json Adds versioned WebSocket mocks schema.
schemas/​v4.1.0/​typespecgeneratorplugin.schema.json Adds versioned TypeSpec configuration schema.
schemas/​v4.1.0/​rewriteplugin.schema.json Adds versioned rewrite configuration schema.
schemas/​v4.1.0/​rewriteplugin.rewritesfile.schema.json Adds versioned rewrite rules schema.
schemas/​v4.1.0/​rc.schema.json Adds versioned main configuration schema.
schemas/​v4.1.0/​ratelimitingplugin.schema.json Adds versioned rate-limiting configuration schema.
schemas/​v4.1.0/​ratelimitingplugin.customresponsefile.schema.json Adds versioned throttling response schema.
schemas/​v4.1.0/​openapispecgeneratorplugin.schema.json Adds versioned OpenAPI generator schema.
schemas/​v4.1.0/​openaitelemetryplugin.schema.json Adds versioned telemetry configuration schema.
schemas/​v4.1.0/​openaitelemetryplugin.pricesfile.schema.json Adds versioned model pricing schema.
schemas/​v4.1.0/​mockstdioresponseplugin.schema.json Adds versioned stdio configuration schema.
schemas/​v4.1.0/​mockstdioresponseplugin.mocksfile.schema.json Adds versioned stdio mocks schema.
schemas/​v4.1.0/​mockresponseplugin.schema.json Adds versioned HTTP mock configuration schema.
schemas/​v4.1.0/​mockresponseplugin.mocksfile.schema.json Defines optional per-mock rate.
schemas/​v4.1.0/​mockrequestplugin.schema.json Adds versioned mock request configuration schema.
schemas/​v4.1.0/​mockrequestplugin.mockfile.schema.json Adds versioned mock request schema.
schemas/​v4.1.0/​minimalpermissionsplugin.schema.json Adds versioned permissions configuration schema.
schemas/​v4.1.0/​minimalpermissionsguidanceplugin.schema.json Adds versioned permissions guidance schema.
schemas/​v4.1.0/​minimalcsompermissionsplugin.schema.json Adds versioned CSOM permissions configuration schema.
schemas/​v4.1.0/​minimalcsompermissions.types.schema.json Adds versioned CSOM types schema.
schemas/​v4.1.0/​latencyplugin.schema.json Adds versioned latency configuration schema.
schemas/​v4.1.0/​languagemodelratelimitingplugin.schema.json Adds versioned token rate-limiting schema.
schemas/​v4.1.0/​languagemodelratelimitingplugin.customresponsefile.schema.json Adds versioned token-limit response schema.
schemas/​v4.1.0/​languagemodelfailureplugin.schema.json Adds versioned language-model failure schema.
schemas/​v4.1.0/​httpfilegeneratorplugin.schema.json Adds versioned HTTP file generator schema.
schemas/​v4.1.0/​hargeneratorplugin.schema.json Adds versioned HAR generator schema.
schemas/​v4.1.0/​graphrandomerrorplugin.schema.json Adds versioned Graph error configuration schema.
schemas/​v4.1.0/​graphminimalpermissionsplugin.schema.json Adds versioned Graph permissions schema.
schemas/​v4.1.0/​graphminimalpermissionsguidanceplugin.schema.json Adds versioned Graph permissions guidance schema.
schemas/​v4.1.0/​genericrandomerrorplugin.schema.json Adds versioned random-error configuration schema.
schemas/​v4.1.0/​genericrandomerrorplugin.errorsfile.schema.json Adds versioned error responses schema.
schemas/​v4.1.0/​executionsummaryplugin.schema.json Adds versioned execution summary schema.
schemas/​v4.1.0/​devtoolsplugin.schema.json Adds versioned DevTools configuration schema.
schemas/​v4.1.0/​crudapiplugin.schema.json Adds versioned CRUD configuration schema.
schemas/​v4.1.0/​crudapiplugin.apifile.schema.json Adds versioned CRUD API definition schema.
schemas/​v4.1.0/​cachingguidanceplugin.schema.json Adds versioned caching guidance schema.
schemas/​v4.1.0/​authplugin.schema.json Adds versioned authentication configuration schema.
schemas/​v4.1.0/​apicenterproductionversionplugin.schema.json Adds versioned API Center production-version schema.
schemas/​v4.1.0/​apicenteronboardingplugin.schema.json Adds versioned API Center onboarding schema.
schemas/​v4.1.0/​apicenterminimalpermissionsplugin.schema.json Adds versioned API Center permissions schema.
install.iss Updates stable installer metadata.
install-beta.iss Updates beta installer metadata.
Dockerfile_beta Updates beta image version argument.
Dockerfile Updates stable image version argument.
DevProxy/​packages.lock.json Updates the abstractions project dependency version.
DevProxy/​devproxyrc.yaml Updates editor schema annotations.
DevProxy/​devproxyrc.json Updates default configuration schema references.
DevProxy/​DevProxy.csproj Updates application version.
DevProxy/​devproxy-errors.yaml Updates editor schema annotation.
DevProxy/​devproxy-errors.json Updates error responses schema reference.
DevProxy/​config/​spo-csom-types.json Updates CSOM types schema reference.
DevProxy/​config/​microsoft-graph.json Updates Graph configuration schema references.
DevProxy/​config/​microsoft-graph-rate-limiting.json Updates rate-limiting configuration schema reference.
DevProxy/​config/​m365.json Updates M365 configuration schema references.
DevProxy/​config/​m365-mocks.json Updates M365 mocks schema reference.
DevProxy/​config-templates/​devproxyrc.yaml Updates template editor schema annotation.
DevProxy/​config-templates/​devproxyrc.json Updates template schema reference.
DevProxy.Proxy.Kestrel/​DevProxy.Proxy.Kestrel.csproj Updates proxy engine version.
DevProxy.Plugins/​Mocking/​WebSocketMockResponsePlugin.cs Updates default WebSocket mocks schema URL.
DevProxy.Plugins/​Mocking/​MockStdioResponsePlugin.cs Updates default stdio mocks schema URL.
DevProxy.Plugins/​Mocking/​MockResponsesLoader.cs Warns about out-of-range mock rates.
DevProxy.Plugins/​Mocking/​MockResponsePlugin.cs Adds probabilistic selection and updates schema URL.
DevProxy.Plugins/​DevProxy.Plugins.csproj Updates plugins version.
DevProxy.Integration.Tests/​ManipulationAndMockingIntegrationTests.cs Adds rate and fallthrough integration tests.
DevProxy.Abstractions/​Models/​MockResponse.cs Adds nullable Rate property.
DevProxy.Abstractions/​DevProxy.Abstractions.csproj Updates abstractions version.

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

No active review issues require resolution for the per-mock response probability change.

No open issues 🎉

1 resolved since last review

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.

Enhancement: define failure rate for each mocked response

2 participants