Skip to content

Conversation

Pratham-Mishra04
Copy link
Collaborator

Add Mocker Plugin for Bifrost

This PR introduces a new Mocker plugin for Bifrost that allows intercepting and mocking AI provider responses. The plugin provides flexible rule-based mocking capabilities for testing, development, and simulation purposes.

Features

  • Rule-based mocking with priority ordering and probability controls
  • Support for custom success and error responses
  • Template-based responses with variable substitution
  • Configurable latency simulation
  • Comprehensive statistics tracking
  • High-performance design optimized for benchmarking

Implementation Details

  • Added core plugin implementation with pre-compiled regex patterns for performance
  • Implemented weighted response selection for simulating varied behaviors
  • Added support for provider/model matching and message content regex matching
  • Included detailed validation for configuration parameters
  • Added atomic counters for high-performance statistics tracking
  • Created comprehensive test suite with various mocking scenarios

Documentation

  • Added detailed README with configuration reference, examples, and best practices
  • Included performance optimization guidelines and troubleshooting tips
  • Provided comprehensive API documentation for all configuration options

The plugin is designed to be lightweight when disabled and highly performant for benchmarking scenarios, with minimal overhead in the no-match path.

Copy link
Contributor

coderabbitai bot commented Jun 21, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive documentation guide for the Mocker plugin, covering installation, configuration, advanced usage, performance tuning, and troubleshooting.
    • Added a fully featured Mocker plugin for flexible, rule-based AI response mocking with support for latency simulation, error injection, dynamic templating, and statistics tracking.
  • Tests

    • Added extensive unit and benchmark tests to validate plugin behavior, performance, and configuration.
  • Chores

    • Established a new Go module with all required dependencies for the Mocker plugin.
  • Documentation

    • Improved code block formatting in multiple documentation files for better readability.

Summary by CodeRabbit

  • New Features

    • Introduced a powerful mocking plugin for intercepting and simulating AI provider responses with flexible, rule-based configurations, latency simulation, and dynamic templating.
    • Added detailed usage statistics and monitoring capabilities for mock interactions.
  • Documentation

    • Added comprehensive user guide covering installation, configuration, advanced features, troubleshooting, and best practices for the mocking plugin.
  • Tests

    • Implemented extensive unit and benchmark tests to ensure plugin correctness and performance under various scenarios.
  • Chores

    • Added Go module definition and dependency management for the plugin.

Walkthrough

This update introduces a new, fully documented and benchmarked mocking plugin for the Bifrost framework. The changes add the MockerPlugin implementation, comprehensive documentation, Go module configuration, benchmark tests, and unit tests that validate and measure the plugin's rule-based request interception, mocking, error simulation, latency injection, and statistics tracking features.

Changes

File(s) Change Summary
plugins/mocker/README.md Added detailed documentation covering installation, configuration, usage, advanced features, performance, best practices, and troubleshooting for the Mocker plugin.
plugins/mocker/go.mod Introduced a Go module file with dependencies and a local replace directive for development.
plugins/mocker/main.go Implemented the MockerPlugin with rule-based request mocking, latency simulation, error injection, statistics, and configuration validation.
plugins/mocker/benchmark_test.go Added multiple benchmark tests for different rule-matching scenarios and response types in the plugin's PreHook method.
plugins/mocker/plugin_test.go Added comprehensive unit tests for plugin functionality, configuration validation, statistics, and template substitution.
docs/mcp.md Changed code block fences in Troubleshooting section to use text language specifier for better formatting.
docs/plugins.md Changed example plugin directory structure code block to use text language specifier.
tests/transports-integrations/README.md Changed code blocks for ASCII diagrams and lists to use text language specifier for improved rendering.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Bifrost
    participant MockerPlugin

    Client->>Bifrost: Send Request
    Bifrost->>MockerPlugin: PreHook(request)
    alt Rule matches and triggers mock
        MockerPlugin->>MockerPlugin: Simulate latency (optional)
        MockerPlugin->>MockerPlugin: Generate mock response or error
        MockerPlugin-->>Bifrost: ShortCircuit(mock response/error)
    else No rule matches
        MockerPlugin-->>Bifrost: Passthrough or default behavior
    end
    Bifrost->>Client: Return response or error
Loading

Possibly related PRs

Suggested reviewers

  • danpiths
  • akshaydeo

Poem

A plugin hops in, with rules to mock and bend,
Simulating errors, with latency to send.
Benchmarks and tests, all stats in a row,
With docs for each feature, so you’ll always know.
Bifrost’s new rabbit, brings joy to the flow!

((\
( -.-)
o_(")(")

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch 06-21-feat_mocker_plugin_added

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator Author

Pratham-Mishra04 commented Jun 21, 2025

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57ebad0 and 338fd40.

⛔ Files ignored due to path filters (1)
  • plugins/mocker/go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • plugins/mocker/README.md (1 hunks)
  • plugins/mocker/benchmark_test.go (1 hunks)
  • plugins/mocker/go.mod (1 hunks)
  • plugins/mocker/main.go (1 hunks)
  • plugins/mocker/plugin_test.go (1 hunks)
🧰 Additional context used
🪛 LanguageTool
plugins/mocker/README.md

[uncategorized] ~213-~213: When ‘Match-specific’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... | []string | No | [] | Match specific providers: ["openai", "anthropic"] | ...

(SPECIFIC_HYPHEN)


[uncategorized] ~214-~214: When ‘Match-specific’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... | []string | No | [] | Match specific models: ["gpt-4", "claude-3"] | ...

(SPECIFIC_HYPHEN)


[uncategorized] ~591-~591: Do not mix variants of the same word (‘regexp’ and ‘regex’) within a single text.
Context: ...ing plugin initialization - Before: regexp.Compile() on every request (~1000x slo...

(EN_WORD_COHERENCY)


[uncategorized] ~841-~841: Possible missing preposition found.
Context: ...l rules should have higher priority - Group related rules: Keep similar functiona...

(AI_HYDRA_LEO_MISSING_TO)

🪛 markdownlint-cli2 (0.17.2)
plugins/mocker/README.md

646-646: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


654-654: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


694-694: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


726-726: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


1057-1057: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🪛 golangci-lint (1.64.8)
plugins/mocker/plugin_test.go

549-549: func boolPtr is unused

(unused)

🔇 Additional comments (4)
plugins/mocker/go.mod (1)

3-3: Verify Go version - appears to be invalid

Go version 1.24.1 doesn't exist yet. The latest stable Go version is 1.23.x. This appears to be either a typo or configuration error.

What is the latest stable version of Go programming language?

Consider updating to a valid Go version:

-go 1.24.1
+go 1.23.0
⛔ Skipped due to learnings
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#81
File: tests/core-providers/go.mod:3-4
Timestamp: 2025-06-16T03:55:16.949Z
Learning: Go 1.24 was released in February 2025 and is stable and available for use in go.mod files.
plugins/mocker/README.md (2)

256-260: Excellent warning about time.Duration usage!

The warning about using Go's time.Duration constants instead of raw integers is crucial for preventing hard-to-debug issues. The examples clearly show the correct usage.


591-591: Maintain consistency between 'regexp' and 'regex' terminology

The documentation uses both 'regexp' and 'regex' which could be confusing. Consider using 'regex' consistently throughout.

-- **Before**: `regexp.Compile()` on every request (~1000x slower)
+- **Before**: `regex.Compile()` on every request (~1000x slower)

Likely an incorrect or invalid review comment.

plugins/mocker/benchmark_test.go (1)

1-296: Well-structured benchmark suite with comprehensive coverage

The benchmark tests effectively cover all major performance scenarios:

  • Simple string matching (fastest path)
  • Regex pattern matching
  • Multiple rule evaluation with priorities
  • No-match passthrough (minimal overhead)
  • Template variable substitution

Good practices observed:

  • Proper use of b.ResetTimer() and b.ReportAllocs()
  • Realistic test data setup
  • Coverage of both common and edge cases

@Pratham-Mishra04 Pratham-Mishra04 marked this pull request as ready for review June 21, 2025 11:25
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-21-feat_mocker_plugin_added branch from 338fd40 to 0e076bf Compare June 22, 2025 18:53
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-21-feat_plugin_schema_and_docs_enhancement branch from 57ebad0 to 1a9edd9 Compare June 22, 2025 18:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (4)
plugins/mocker/README.md (1)

646-646: Add language specifiers to fenced code blocks

Also applies to: 654-654

plugins/mocker/plugin_test.go (1)

549-551: Remove unused boolPtr helper

plugins/mocker/main.go (2)

865-865: Consider using a helper function for string pointer creation


884-892: Optimize rule sorting algorithm

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 338fd40 and 0e076bf.

⛔ Files ignored due to path filters (1)
  • plugins/mocker/go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • plugins/mocker/README.md (1 hunks)
  • plugins/mocker/benchmark_test.go (1 hunks)
  • plugins/mocker/go.mod (1 hunks)
  • plugins/mocker/main.go (1 hunks)
  • plugins/mocker/plugin_test.go (1 hunks)
🧰 Additional context used
🪛 LanguageTool
plugins/mocker/README.md

[uncategorized] ~213-~213: When ‘Match-specific’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... | []string | No | [] | Match specific providers: ["openai", "anthropic"] | ...

(SPECIFIC_HYPHEN)


[uncategorized] ~214-~214: When ‘Match-specific’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... | []string | No | [] | Match specific models: ["gpt-4", "claude-3"] | ...

(SPECIFIC_HYPHEN)


[uncategorized] ~591-~591: Do not mix variants of the same word (‘regexp’ and ‘regex’) within a single text.
Context: ...ing plugin initialization - Before: regexp.Compile() on every request (~1000x slo...

(EN_WORD_COHERENCY)


[uncategorized] ~841-~841: Possible missing preposition found.
Context: ...l rules should have higher priority - Group related rules: Keep similar functiona...

(AI_HYDRA_LEO_MISSING_TO)

🪛 markdownlint-cli2 (0.17.2)
plugins/mocker/README.md

646-646: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


654-654: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


694-694: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


726-726: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


1057-1057: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🪛 golangci-lint (1.64.8)
plugins/mocker/plugin_test.go

549-549: func boolPtr is unused

(unused)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Graphite / mergeability_check
  • GitHub Check: Graphite / mergeability_check
🔇 Additional comments (7)
plugins/mocker/go.mod (1)

3-3: Fix invalid Go version

Go version 1.24.1 doesn't exist. The latest stable version is 1.22.x. This will cause module initialization errors.

Apply this fix:

-go 1.24.1
+go 1.22
⛔ Skipped due to learnings
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#81
File: tests/core-providers/go.mod:3-4
Timestamp: 2025-06-16T04:27:53.538Z
Learning: In Go module files, `go 1.24.1` (with patch version) can work fine in some setups, contrary to the general rule that go directives should only include major.minor versions.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#81
File: tests/core-providers/go.mod:3-4
Timestamp: 2025-06-16T03:55:16.949Z
Learning: Go 1.24 was released in February 2025 and is stable and available for use in go.mod files.
plugins/mocker/README.md (1)

1-1060: Excellent comprehensive documentation!

The README provides thorough coverage of installation, configuration, usage examples, performance optimization, and troubleshooting. The structure is clear and includes helpful quick start examples.

plugins/mocker/benchmark_test.go (1)

12-295: Well-structured benchmark suite

The benchmarks effectively cover various scenarios including simple rules, regex matching, multiple rules, no-match cases, and template processing. Good use of ResetTimer() and ReportAllocs() for accurate measurements.

plugins/mocker/plugin_test.go (1)

14-551: Comprehensive test coverage

The test suite provides excellent coverage including:

  • Plugin lifecycle (enable/disable)
  • Default behaviors and custom rules
  • Success and error responses
  • Template processing
  • Statistics tracking
  • Configuration validation

The BaseAccount mock implementation is well-designed for testing purposes.

plugins/mocker/main.go (3)

198-220: Excellent performance optimization with pre-compiled regex

Pre-compiling regex patterns during initialization is a great optimization that significantly improves runtime performance. The error handling for invalid regex patterns is also properly implemented.


433-485: Well-designed PreHook implementation with atomic operations

The PreHook method efficiently handles request interception with:

  • Early return for disabled plugin
  • Atomic counters for lock-free statistics
  • Priority-based rule matching
  • Probability-based activation
  • Proper latency simulation

The use of atomic operations for counters is a smart optimization for high-throughput scenarios.


566-620: Efficient message extraction with string builder

The extractMessageContentFast method is well-optimized:

  • Fast path for single messages
  • Efficient string builder for multiple messages
  • Proper handling of both text and chat completion inputs

@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-21-feat_plugin_schema_and_docs_enhancement branch from 1a9edd9 to 3ed1607 Compare June 23, 2025 18:26
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-21-feat_mocker_plugin_added branch from 0e076bf to 298ed94 Compare June 23, 2025 18:26
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 06-21-feat_mocker_plugin_added branch from 298ed94 to 9f9ab0f Compare June 23, 2025 18:30
@akshaydeo akshaydeo changed the base branch from 06-21-feat_plugin_schema_and_docs_enhancement to graphite-base/106 June 23, 2025 18:32
@akshaydeo akshaydeo force-pushed the 06-21-feat_mocker_plugin_added branch from 9f9ab0f to 4842487 Compare June 23, 2025 18:32
@graphite-app graphite-app bot changed the base branch from graphite-base/106 to main June 23, 2025 18:33
@akshaydeo akshaydeo force-pushed the 06-21-feat_mocker_plugin_added branch from 4842487 to 0ac12f0 Compare June 23, 2025 18:33
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (3)
plugins/mocker/benchmark_test.go (1)

47-47: Add missing stringPtr helper function

The stringPtr function is used throughout the benchmarks but not defined in this file. This will cause compilation errors.

Add this helper function at the beginning of the file:

 package mocker

 import (
 	"context"
 	"strconv"
 	"testing"

 	bifrost "github.com/maximhq/bifrost/core"
 	"github.com/maximhq/bifrost/core/schemas"
 )
+
+// stringPtr returns a pointer to the string value
+func stringPtr(s string) *string {
+	return &s
+}

 // BenchmarkMockerPlugin_PreHook_SimpleRule benchmarks simple rule matching

Also applies to: 75-75, 100-100, 175-175, 229-229, 261-261, 280-280

plugins/mocker/README.md (1)

1299-1299: Add language specifier to fenced code block

-```
+```text
plugins/mocker/main.go (1)

905-905: Consider using a helper function for string pointer creation

For consistency with other parts of the codebase, consider extracting the inline function to a helper:

+// stringPtr returns a pointer to the string value
+func stringPtr(s string) *string {
+    return &s
+}

 // ... in handleDefaultBehavior method ...
-								ContentStr: func() *string { s := "Mock plugin default response"; return &s }(),
+								ContentStr: stringPtr("Mock plugin default response"),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 298ed94 and 0ac12f0.

⛔ Files ignored due to path filters (1)
  • plugins/mocker/go.sum is excluded by !**/*.sum
📒 Files selected for processing (8)
  • docs/mcp.md (7 hunks)
  • docs/plugins.md (1 hunks)
  • plugins/mocker/README.md (1 hunks)
  • plugins/mocker/benchmark_test.go (1 hunks)
  • plugins/mocker/go.mod (1 hunks)
  • plugins/mocker/main.go (1 hunks)
  • plugins/mocker/plugin_test.go (1 hunks)
  • tests/transports-integrations/README.md (3 hunks)
🧰 Additional context used
🪛 LanguageTool
plugins/mocker/README.md

[uncategorized] ~214-~214: When ‘Match-specific’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... | []string | No | [] | Match specific providers: ["openai", "anthropic"] | ...

(SPECIFIC_HYPHEN)


[uncategorized] ~215-~215: When ‘Match-specific’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... | []string | No | [] | Match specific models: ["gpt-4", "claude-3"] | ...

(SPECIFIC_HYPHEN)


[uncategorized] ~833-~833: Do not mix variants of the same word (‘regexp’ and ‘regex’) within a single text.
Context: ...ing plugin initialization - Before: regexp.Compile() on every request (~1000x slo...

(EN_WORD_COHERENCY)


[uncategorized] ~914-~914: You might be missing the article “the” here.
Context: ...lective mocking - Zero allocations when plugin is disabled #### **High-Speed Simple R...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~1083-~1083: Possible missing preposition found.
Context: ...l rules should have higher priority - Group related rules: Keep similar functiona...

(AI_HYDRA_LEO_MISSING_TO)

🪛 markdownlint-cli2 (0.17.2)
plugins/mocker/README.md

391-391: Bare URL used
null

(MD034, no-bare-urls)


936-936: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


968-968: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


1299-1299: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🪛 golangci-lint (1.64.8)
plugins/mocker/main.go

1008-1008: Error return value of fmt.Sscanf is not checked

(errcheck)


1009-1009: Error return value of fmt.Sscanf is not checked

(errcheck)


1018-1018: Error return value of fmt.Sscanf is not checked

(errcheck)

🔇 Additional comments (16)
docs/plugins.md (1)

479-486: Document Formatting Improvement: Specify code block language
Updated the plugin directory structure snippet to use a text-fenced code block for consistent markdown rendering.

tests/transports-integrations/README.md (3)

9-14: Document Formatting Improvement: Specify ASCII diagram as text
Updated the architecture overview ASCII diagram to use a text-fenced code block for improved consistency.


53-72: Document Formatting Improvement: Specify directory listing as text
Updated the directory structure example to use a text-fenced code block for consistent rendering.


440-452: Document Formatting Improvement: Specify quick reference as text
Updated the test categories quick-reference list to use a text-fenced code block for better readability.

docs/mcp.md (6)

1344-1346: Document Formatting Improvement: Specify error snippet as text
Converted the STDIO connection failure message to a text-fenced code block for consistent formatting.


1357-1359: Document Formatting Improvement: Specify error snippet as text
Converted the HTTP connection failure message to a text-fenced code block for improved clarity.


1370-1372: Document Formatting Improvement: Specify error snippet as text
Converted the SSE connection error message to a text-fenced code block for consistent styling.


1386-1388: Document Formatting Improvement: Specify error snippet as text
Converted the duplicate tool registration error message to a text-fenced code block for uniform documentation.


1400-1402: Document Formatting Improvement: Specify warning snippet as text
Converted the "No MCP tools found" warning to a text-fenced code block for consistent documentation styling.


1413-1415: Document Formatting Improvement: Specify warning snippet as text
Converted the "Restricted tool available" warning to a text-fenced code block for clarity.

plugins/mocker/go.mod (1)

1-6: New module initialization: Mocker plugin
Declared the plugins/mocker module with Go version 1.24.1 and added a local replace for the core package.

plugins/mocker/plugin_test.go (1)

1-539: Well-structured and comprehensive test coverage

The test file provides excellent coverage of the plugin functionality including:

  • Plugin initialization and configuration validation
  • Disabled plugin behavior
  • Default mock rules
  • Custom success and error responses
  • Template variable substitution
  • Statistics tracking
  • Various edge cases

The BaseAccount implementation is a good approach for testing without real API keys.

plugins/mocker/README.md (1)

1-1302: Excellent and comprehensive documentation

The README provides:

  • Clear quick start examples
  • Detailed configuration reference with tables
  • Advanced features like faker support and weighted responses
  • Performance optimization guidelines
  • Troubleshooting section with common issues
  • Well-organized examples for various use cases

The documentation will greatly help users understand and effectively use the Mocker plugin.

plugins/mocker/main.go (3)

40-44: Excellent performance optimizations

The implementation includes several performance optimizations that make it suitable for high-throughput scenarios:

  1. Pre-compiled regex patterns (line 42) - Avoids expensive regex compilation on each request
  2. Pre-calculated normalized weights (lines 43, 230-269) - O(log n) binary search for response selection
  3. Atomic counters for statistics (lines 55-58) - Lock-free operations for minimal contention
  4. Efficient string operations with strings.Builder (lines 656-665)

These optimizations align well with the benchmarking goals mentioned in the PR objectives.

Also applies to: 230-269, 823-850


15-15: Comprehensive faker integration

The faker integration using jaswdr/faker library is well-implemented with:

  • Support for various data types (personal info, addresses, companies, etc.)
  • Parameterized methods (e.g., {{faker.integer:10,50}})
  • Graceful fallback for unrecognized methods
  • Clear documentation in the README

This feature significantly enhances the mocking capabilities for realistic test data generation.

Also applies to: 947-1043


271-473: Thorough configuration validation

The validation logic is comprehensive and user-friendly:

  • Clear error messages with context
  • Reasonable bounds checking
  • Validation of regex patterns at configuration time
  • Proper validation of all nested structures

This prevents runtime errors and provides early feedback on configuration issues.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
plugins/mocker/main.go (1)

1003-1016: Handle errors from fmt.Sscanf in faker value generation

The error return values from fmt.Sscanf are ignored, which could lead to unexpected behavior if parsing fails.

 case "integer":
     min, max := 1, 100 // defaults
     if len(parts) > 1 {
         params := strings.Split(parts[1], ",")
         if len(params) >= 2 {
-            fmt.Sscanf(params[0], "%d", &min)
-            fmt.Sscanf(params[1], "%d", &max)
+            if _, err := fmt.Sscanf(params[0], "%d", &min); err != nil {
+                min = 1 // fallback to default on parse error
+            }
+            if _, err := fmt.Sscanf(params[1], "%d", &max); err != nil {
+                max = 100 // fallback to default on parse error
+            }
         }
     }
     return fmt.Sprintf("%d", p.faker.IntBetween(min, max))
 case "float":
     min, max := 0, 100 // defaults as integers
     if len(parts) > 1 {
         params := strings.Split(parts[1], ",")
         if len(params) >= 2 {
-            fmt.Sscanf(params[0], "%d", &min)
-            fmt.Sscanf(params[1], "%d", &max)
+            if _, err := fmt.Sscanf(params[0], "%d", &min); err != nil {
+                min = 0 // fallback to default on parse error
+            }
+            if _, err := fmt.Sscanf(params[1], "%d", &max); err != nil {
+                max = 100 // fallback to default on parse error
+            }
         }
     }

Also applies to: 1017-1030

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac12f0 and 947487a.

⛔ Files ignored due to path filters (1)
  • plugins/mocker/go.sum is excluded by !**/*.sum
📒 Files selected for processing (8)
  • docs/mcp.md (7 hunks)
  • docs/plugins.md (1 hunks)
  • plugins/mocker/README.md (1 hunks)
  • plugins/mocker/benchmark_test.go (1 hunks)
  • plugins/mocker/go.mod (1 hunks)
  • plugins/mocker/main.go (1 hunks)
  • plugins/mocker/plugin_test.go (1 hunks)
  • tests/transports-integrations/README.md (3 hunks)
🧰 Additional context used
🪛 LanguageTool
plugins/mocker/README.md

[uncategorized] ~214-~214: When ‘Match-specific’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... | []string | No | [] | Match specific providers: ["openai", "anthropic"] | ...

(SPECIFIC_HYPHEN)


[uncategorized] ~215-~215: When ‘Match-specific’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... | []string | No | [] | Match specific models: ["gpt-4", "claude-3"] | ...

(SPECIFIC_HYPHEN)


[uncategorized] ~833-~833: Do not mix variants of the same word (‘regexp’ and ‘regex’) within a single text.
Context: ...ing plugin initialization - Before: regexp.Compile() on every request (~1000x slo...

(EN_WORD_COHERENCY)


[uncategorized] ~914-~914: You might be missing the article “the” here.
Context: ...lective mocking - Zero allocations when plugin is disabled #### **High-Speed Simple R...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~1083-~1083: Possible missing preposition found.
Context: ...l rules should have higher priority - Group related rules: Keep similar functiona...

(AI_HYDRA_LEO_MISSING_TO)

🪛 markdownlint-cli2 (0.17.2)
plugins/mocker/README.md

391-391: Bare URL used
null

(MD034, no-bare-urls)


936-936: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


968-968: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


1299-1299: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🔇 Additional comments (14)
docs/plugins.md (1)

479-486: Consistent code block language annotation: Switching to ```text enhances readability and aligns with other documentation updates.

tests/transports-integrations/README.md (3)

9-14: Consistent code block language annotation: Updating the ASCII diagram to use ```text ensures proper rendering and consistency across docs.


53-60: Consistent code block language annotation: Using ```text for the directory structure listing maintains uniform formatting with similar examples.


439-452: Consistent code block language annotation: Annotating the Quick Reference section with ```text improves clarity and matches other docs formatting.

docs/mcp.md (6)

1344-1346: Consistent code block language annotation: Switching to ```text for this STDIO error example improves readability.


1357-1359: Consistent code block language annotation: Annotating the HTTP error message with ```text ensures uniform formatting.


1370-1372: Consistent code block language annotation: Using ```text for the SSE error example aligns with other troubleshooting code blocks.


1386-1388: Consistent code block language annotation: Marking this tool registration error example as ```text enhances consistency.


1398-1402: Consistent code block language annotation: The "No tools available" warning example benefits from ```text annotation for clarity.


1413-1415: Consistent code block language annotation: Annotating the restricted tool warning with ```text maintains formatting uniformity.

plugins/mocker/plugin_test.go (1)

1-538: Comprehensive test coverage!

The test file provides excellent coverage of the Mocker plugin functionality including disabled state, default behavior, custom rules, error responses, template substitution, statistics tracking, and configuration validation. The BaseAccount mock implementation is clean and the test structure follows best practices.

plugins/mocker/benchmark_test.go (1)

1-296: Well-designed performance benchmarks!

The benchmark suite effectively measures performance across key scenarios including simple rules, regex matching, multiple rule evaluation, passthrough behavior, and template processing. Good use of b.ResetTimer() and b.ReportAllocs() for accurate measurements. The consistent use of bifrost.Ptr is the correct approach.

plugins/mocker/README.md (1)

1-1298: Excellent comprehensive documentation!

The README provides thorough coverage of all plugin features including quick start examples, detailed configuration reference, advanced features with faker support, performance optimization guidelines, and troubleshooting tips. The faker documentation is particularly well done with all available methods documented. Great work on creating user-friendly documentation!

plugins/mocker/main.go (1)

1-1083: Excellent implementation with outstanding performance optimizations!

The MockerPlugin implementation demonstrates exceptional attention to performance with pre-compiled regex patterns, pre-calculated normalized weights for O(log n) response selection, atomic counters, minimal locking, and efficient string operations. The comprehensive validation, clean architecture, and thorough inline documentation make this a high-quality plugin implementation.

@akshaydeo akshaydeo merged commit 5c253f6 into main Jun 24, 2025
2 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.

2 participants