Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions hindsight-api-slim/tests/test_openrouter_null_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def _make_chat_response(content: str | None) -> MagicMock:
- response.model_dump() (returns dict without 'error' key)
- choice.message.tool_calls/refusal (otherwise truthy MagicMock in error msg)
- usage.completion_tokens_details (otherwise reasoning-token math crashes, #2378)
- usage.cached_tokens / usage.prompt_tokens_details (otherwise the cached-
token extraction reads an auto-MagicMock and metrics' `cached_input_tokens
> 0` raises "'>' not supported between MagicMock and int" — only when the
metrics path runs, which makes it an intermittent xdist failure)
"""
choice = MagicMock()
choice.finish_reason = "stop"
Expand All @@ -53,6 +57,10 @@ def _make_chat_response(content: str | None) -> MagicMock:
response.usage.completion_tokens = 0 if content is None else 5
response.usage.total_tokens = 10 if content is None else 15
response.usage.completion_tokens_details = None
# Cover both cached-token extraction paths (response_usage.cached_tokens and
# usage.prompt_tokens_details.cached_tokens) so neither leaks a MagicMock.
response.usage.cached_tokens = 0
response.usage.prompt_tokens_details = None
response.choices = [choice]
return response

Expand Down