vibe.llm_providers.mock

Mock LLM provider used for tests and local development.

ConfigurableMockProvider

Easily configurable mock provider that emits tool calls based on simple configuration.

Uses a file-based configuration registry so configuration persists across process boundaries (important for Flask's live_server in tests).

Configure using configure_mock_provider() before starting tests.

This provider works natively with Message and Tool objects.

Features: - Message capture for test assertions (self.calls) - Text chunk emission - Tool call streaming with various argument types - Support for recovery scenarios (premature finalize, no follow-up)

convert_messages_to_provider_format

convert_messages_to_provider_format(messages: list[Message], tools: list[Tool] | None = None) -> list[Message]

Convert internal messages to provider format.

For MockProvider, we don't need to convert anything - we work with typed messages natively. Just return as-is.

stream_generate

stream_generate(messages: list[Message], sequence_number: int, *, session_id: str, assistant_name: str, endpoint_name: str, turn_id: str, previous_response_id: str | None = None, tool_outputs: list[ToolOutput] | None = None, unanswered_predefined_questions: list[dict[str, Any]] | None = None) -> Generator[StreamChunk, None, None]

Stream mock LLM responses for testing.

Parameters:
  • messages (list[Message]) –

    Conversation history as typed Message objects (content ignored by mock)

  • sequence_number (int) –

    Turn sequence number for conversation ordering

  • session_id (str) –

    Session identifier for logging and correlation

  • assistant_name (str) –

    Assistant display name for logging

  • endpoint_name (str) –

    LLM endpoint identifier for logging and metrics

  • turn_id (str) –

    Unique turn identifier for request/response correlation

  • previous_response_id (str | None, default: None ) –

    Not used by mock provider

  • tool_outputs (list[ToolOutput] | None, default: None ) –

    Not used by mock provider

  • unanswered_predefined_questions (list[dict[str, Any]] | None, default: None ) –

    Not used by mock provider

Yields:
  • StreamChunk

    StreamChunk objects containing configured mock responses

Note

The mock provider ignores message content and generates responses based on configuration from configure_mock_provider().

get_usage_stats

get_usage_stats() -> UsageStats | None

Return usage stats with actual token counts.

For chunked mode, each chunk counts as 1 token. For non-chunked mode, each text emission counts as 1 token.

get_capabilities

get_capabilities() -> ProviderCapabilities

Return mock provider capabilities, respecting global config for streaming_tools.

configure_mock_provider

configure_mock_provider(*responses: AssistantMessage, port: int = 0, validate_messages: bool = False, chunk_size: int = 0, chunk_delay: int = 0, tools: bool = True, streaming_tools: bool = True) -> None

Configure the mock provider for tests using a file-based approach.

This writes configuration to a port-specific temp file that both the test process and the live_server process can read. Using port-based file names ensures test isolation when running tests in parallel.

Parameters:
  • *responses (AssistantMessage, default: () ) –

    Ordered AssistantMessage objects. The first positional argument corresponds to sequence 1, the second to sequence 2, and so on. For convenience, an iterable of AssistantMessage instances can also be passed as the first argument (legacy form).

  • port (int, default: 0 ) –

    The live_server port. For Selenium/live_server tests, pass live_server.port to enable test isolation. For Flask test client tests (same process), can be omitted (defaults to 0) since they don't need cross-process isolation.

  • validate_messages (bool, default: False ) –

    Enable message structure validation (default: False)

  • chunk_size (int, default: 0 ) –

    Optional chunk size (in characters) for streaming tool arguments. When > 0, arguments are streamed in pieces to simulate providers like OpenAI.

  • chunk_delay (int, default: 0 ) –

    Optional delay between chunk emissions (milliseconds). Only applies when chunk_size is greater than zero.

  • tools (bool, default: True ) –

    When True (default), emit tool call chunks (TOOL_CALL_START, etc.). When False, format responses as JSON action text and stream as TEXT chunks only. This simulates non-tool-mode providers like Mistral without tool support.

  • streaming_tools (bool, default: True ) –

    When True (default), provider uses streaming tools (insert_blocks plural). When False, provider uses non-streaming singular tools (insert_block, upsert_block).

Examples:

Selenium/live_server test (cross-process, requires port for isolation):

configure_mock_provider( AssistantMessage(tool_calls=[ ToolCall("update_chat", {"content": "Hello!"}), ToolCall("ask_question", { "mode": "predefined", "question_id": "name", "answer_type": "text" }) ]), AssistantMessage(tool_calls=[ToolCall("finalize")]), port=live_server.port, )

Flask test client test (same process, port optional):

configure_mock_provider( AssistantMessage(tool_calls=[ToolCall("update_chat", {"message": "Hi"})]), tools=False, chunk_size=10 # Stream in 10-char chunks )

clear_mock_provider_config

clear_mock_provider_config(port: int | None = None) -> None

Clear the mock provider configuration.

Parameters:
  • port (int | None, default: None ) –

    The live_server port. If None, clears ALL mock config files (for cleanup).