Add bodyRegex support for MockStdioResponsePlugin stdin matching#1530
Add bodyRegex support for MockStdioResponsePlugin stdin matching#1530garrytrinder merged 15 commits intomainfrom
Conversation
Add a new `bodyRegex` property to `MockStdioRequest` that allows users to match stdin bodies using regular expressions, in addition to the existing `bodyFragment` (case-insensitive contains) matching. When both `bodyFragment` and `bodyRegex` are specified on a mock, both conditions must match (AND logic). A mock is considered a startup mock only when neither property is set. Updated JSON schemas (v2.1.0 and v2.2.0) to include the new property. Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
|
@copilot could it be you missed this comment #1521 (comment) which contains the schema where the |
When both bodyFragment and bodyRegex are specified, bodyRegex takes precedence. The schema and docs now indicate they are mutually exclusive options for matching stdin body content. Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
You're right, I missed that. Updated the logic in f2e510a so |
|
@copilot since we're just adding this feature, don't modify v2.1.0 schemas as v2.1.0 is already shipped. The functionality would be included in v2.2.0 only |
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds support for regular expression pattern matching in the MockStdioResponsePlugin, addressing issue #1521 where the existing bodyFragment string.Contains matching could produce false positives (e.g., "initialized" matching both the "initialized" method and "notifications/initialized").
Changes:
- Adds
BodyRegexproperty toMockStdioRequestmodel for regex-based stdin body matching - Implements either/or matching logic where
bodyRegextakes precedence if bothbodyRegexandbodyFragmentare specified - Updates the v2.2.0 JSON schema with the new
bodyRegexproperty (correctly avoids modifying shipped v2.1.0 schema)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| DevProxy.Abstractions/Models/MockStdioResponse.cs | Adds BodyRegex property with XML documentation to MockStdioRequest class |
| DevProxy.Plugins/Mocking/MockStdioResponsePlugin.cs | Implements regex matching logic with 5-second timeout, updates startup mock detection, and adds GetMockKey helper for consistent mock tracking |
| schemas/v2.2.0/mockstdioresponseplugin.mocksfile.schema.json | Adds bodyRegex property definition to the schema with description |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot fix build issues |
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
BodyRegexproperty toMockStdioRequestmodelbodyRegex(regex) orbodyFragment(contains) —bodyRegextakes precedence if both specifiedbodyRegexRegex.IsMatchLogger(from BasePlugin) instead of_loggerOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.