mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
Service-level tests now exercise provider, permissions, project, journal, messaging, work_session, metrics, kanban, extraction, learning, notification, dashboard, llm_routing, a2a, task, repository_base, audit, db_seed, branch_name, indexed_document, query_helpers, agent. API route tests cover provider, journal, project, sessions, dashboard, work_session, tasks, a2a, groups, notifications, agents, channels, messages, kanban, api_resources. Pure-function helpers covered: handlers, deps_helpers, middleware, middleware_docs, transcription, pr templates, agents_config, errors, logging, journal/notification/channel/a2a access, task_lifecycle, streaming, converters, crypto, schemas (common + websocket), events, permissions extras. pyproject ruff per-file-ignores extended for tests so PLR2004 (status code magic values), PLC0415 (lazy imports), PLR0913 (fixture params), ARG001 (unused fixture deps), SIM105, and E501 don't fight test idioms.
109 lines
2.7 KiB
Python
109 lines
2.7 KiB
Python
"""StreamBuffer + TranscriptionConfig coverage."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime, timedelta
|
|
from uuid import uuid4
|
|
|
|
from roboco.models.transcription import StreamBuffer, TranscriptionConfig
|
|
|
|
|
|
def _buffer() -> StreamBuffer:
|
|
return StreamBuffer(
|
|
agent_id=uuid4(),
|
|
channel_id=uuid4(),
|
|
session_id=uuid4(),
|
|
)
|
|
|
|
|
|
def test_append_accumulates() -> None:
|
|
buf = _buffer()
|
|
buf.append("hello ")
|
|
buf.append("world")
|
|
assert buf.content == "hello world"
|
|
assert buf.chunks == ["hello ", "world"]
|
|
|
|
|
|
def test_clear_returns_content_and_resets() -> None:
|
|
buf = _buffer()
|
|
buf.append("data")
|
|
out = buf.clear()
|
|
assert out == "data"
|
|
assert buf.content == ""
|
|
assert buf.chunks == []
|
|
assert buf.is_complete is False
|
|
|
|
|
|
def test_char_count() -> None:
|
|
buf = _buffer()
|
|
buf.append("12345")
|
|
assert buf.char_count == 5
|
|
|
|
|
|
def test_age_property_positive() -> None:
|
|
buf = _buffer()
|
|
assert buf.age >= timedelta(0)
|
|
|
|
|
|
def test_idle_time_property_positive() -> None:
|
|
buf = _buffer()
|
|
assert buf.idle_time >= timedelta(0)
|
|
|
|
|
|
def test_is_ready_when_complete() -> None:
|
|
buf = _buffer()
|
|
buf.is_complete = True
|
|
assert buf.is_ready_for_extraction() is True
|
|
|
|
|
|
def test_is_ready_when_max_chars_exceeded() -> None:
|
|
buf = _buffer()
|
|
buf.append("a" * 6000)
|
|
assert buf.is_ready_for_extraction(max_chars=5000) is True
|
|
|
|
|
|
def test_is_ready_when_idle_after_min_chars() -> None:
|
|
buf = _buffer()
|
|
buf.append("a" * 100) # Above min_chars
|
|
# Force last_chunk_at to be old.
|
|
buf.last_chunk_at = datetime.now(UTC) - timedelta(seconds=10)
|
|
assert buf.is_ready_for_extraction(idle_threshold=timedelta(seconds=2)) is True
|
|
|
|
|
|
def test_is_ready_with_sentence_ending() -> None:
|
|
buf = _buffer()
|
|
buf.append("a" * 50)
|
|
buf.append(".")
|
|
assert buf.is_ready_for_extraction() is True
|
|
|
|
|
|
def test_is_ready_with_question_mark() -> None:
|
|
buf = _buffer()
|
|
buf.append("a" * 50)
|
|
buf.append("?")
|
|
assert buf.is_ready_for_extraction() is True
|
|
|
|
|
|
def test_is_not_ready_below_min_chars() -> None:
|
|
buf = _buffer()
|
|
buf.append("short.")
|
|
assert buf.is_ready_for_extraction(min_chars=50) is False
|
|
|
|
|
|
def test_has_sentence_ending_empty_returns_false() -> None:
|
|
buf = _buffer()
|
|
assert buf._has_sentence_ending() is False
|
|
|
|
|
|
def test_transcription_config_defaults() -> None:
|
|
cfg = TranscriptionConfig()
|
|
assert cfg.min_chars_for_extraction == 50
|
|
assert cfg.max_chars_before_flush == 5000
|
|
assert cfg.idle_threshold_seconds == 2.0
|
|
|
|
|
|
def test_transcription_config_custom() -> None:
|
|
cfg = TranscriptionConfig(min_chars_for_extraction=10, max_buffers_per_agent=5)
|
|
assert cfg.min_chars_for_extraction == 10
|
|
assert cfg.max_buffers_per_agent == 5
|