Files
hermes-agent/tests/agent/test_stream_chunk_byte_estimate.py
teknium1 b2ecd3518f test: purge low-value tests, lane py04 (294 removed)
Change-detectors, tautologies, source-reading tests, redundant duplicates,
mock-echo tests and dead/unrunnable tests. Per-test rationale in the lane
ledger (category + reason for every removal).
2026-09-23 03:15:26 -07:00

60 lines
1.4 KiB
Python

"""Tests for _estimate_chunk_bytes — the cheap per-chunk stream size proxy.
Replaced ``len(repr(chunk))`` in the streaming hot loop. Contract:
- proportional to delta payload length (content, reasoning, tool args);
- never raises on unknown shapes (returns the framing floor);
- monotonic accumulation stays positive.
"""
from openai.types.chat import ChatCompletionChunk
from openai.types.chat.chat_completion_chunk import (
Choice,
ChoiceDelta,
)
from agent.chat_completion_helpers import _estimate_chunk_bytes
def _chunk(delta):
return ChatCompletionChunk(
id="chatcmpl-1",
created=1730000000,
model="m",
object="chat.completion.chunk",
choices=[Choice(index=0, delta=delta, finish_reason=None)],
)
def test_reasoning_content_counted():
base = _estimate_chunk_bytes(_chunk(ChoiceDelta()))
class Delta:
content = None
reasoning_content = "thinking..."
reasoning = None
tool_calls = None
class Choice0:
delta = Delta()
class Chunk:
choices = [Choice0()]
assert _estimate_chunk_bytes(Chunk()) == base + len("thinking...")
def test_unknown_shape_returns_floor_never_raises():
class Weird:
pass
floor = _estimate_chunk_bytes(None)
assert floor > 0
assert _estimate_chunk_bytes(Weird()) == floor
assert _estimate_chunk_bytes(object()) == floor