mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-05 07:39:47 +00:00
Some checks failed
CI / Python packages / Build and verify distributions (push) Waiting to run
CI / Python quality / GitHub Actions (push) Waiting to run
CI / Python quality / Pre-commit (push) Waiting to run
CI / Python tests / Unit Tests - py3.11 (push) Waiting to run
CI / Python tests / Unit Tests - py3.12 (push) Waiting to run
CI / Python tests / Unit Tests - py3.13 (push) Waiting to run
CI / Python tests / Unit Tests - py3.14 (push) Waiting to run
CI / Windows / CLI smoke - py3.11 (push) Waiting to run
Deploy / Documentation / Build documentation (push) Waiting to run
Deploy / Documentation / deploy (push) Blocked by required conditions
CI and Release / Docker / Build and test / amd64 (push) Waiting to run
CI and Release / Docker / Build and test / arm64 (push) Waiting to run
CI and Release / Docker / Publish multi-platform tags (push) Blocked by required conditions
Security / CodeQL / Analyze javascript-typescript (push) Waiting to run
Security / CodeQL / Analyze python (push) Waiting to run
CI / ReMe Studio / Studio checks (push) Has been cancelled
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
"""Unit tests for CompressorStep without LLM dependencies."""
|
|
|
|
import pytest
|
|
|
|
from agentscope.message import TextBlock, ThinkingBlock
|
|
from agentscope.model import ChatResponse
|
|
|
|
from reme.steps.evolve.compressor import CompressorStep
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_response_text_handles_non_streaming_chat_response():
|
|
"""A plain ChatResponse must not crash the async-iteration check.
|
|
|
|
Regression: ``ChatResponse`` inherits agentscope's ``DictMixin`` whose
|
|
instance ``__getattr__`` raises ``KeyError``, so ``hasattr(result,
|
|
"__aiter__")`` raised instead of returning False and every compression
|
|
failed with ``KeyError: '__aiter__'``.
|
|
"""
|
|
|
|
result = ChatResponse(
|
|
content=[
|
|
{"type": "thinking", "thinking": "internal reasoning"},
|
|
{"type": "text", "text": "compressed "},
|
|
{"type": "text", "text": "output"},
|
|
],
|
|
is_last=True,
|
|
)
|
|
|
|
text = await CompressorStep._response_text(result) # pylint: disable=protected-access
|
|
|
|
assert text == "compressed output"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_response_text_handles_pydantic_content_blocks():
|
|
"""Real LLM responses carry pydantic block models, not dicts.
|
|
|
|
Regression: ``block.get(...)`` crashed with ``'ThinkingBlock' object has
|
|
no attribute 'get'`` on responses from reasoning models.
|
|
"""
|
|
|
|
result = ChatResponse(
|
|
content=[
|
|
ThinkingBlock(type="thinking", thinking="internal reasoning"),
|
|
TextBlock(type="text", text="compressed output"),
|
|
],
|
|
is_last=True,
|
|
)
|
|
|
|
text = await CompressorStep._response_text(result) # pylint: disable=protected-access
|
|
|
|
assert text == "compressed output"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_response_text_consumes_streaming_chunks_and_keeps_last():
|
|
"""An async generator of ChatResponses is drained and the last chunk wins."""
|
|
|
|
async def stream():
|
|
yield ChatResponse(content=[{"type": "text", "text": "partial"}], is_last=False)
|
|
yield ChatResponse(content=[{"type": "text", "text": "final text"}], is_last=True)
|
|
|
|
text = await CompressorStep._response_text(stream()) # pylint: disable=protected-access
|
|
|
|
assert text == "final text"
|