mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-04-26 11:48:10 +00:00
- Freeze all config models (AppConfig + 15 sub-configs) with frozen=True - Purify from_file() — remove 9 load_*_from_dict() side-effect calls - Replace mtime/reload/push/pop machinery with single ContextVar + init_app_config() - Delete 10 sub-module globals and their getters/setters/loaders - Migrate 50+ consumers from get_*_config() to get_app_config().xxx - Expand DeerFlowContext: app_config + thread_id + agent_name (frozen dataclass) - Wire into Gateway runtime (worker.py) and DeerFlowClient via context= parameter - Remove sandbox_id from runtime.context — flows through ThreadState.sandbox only - Middleware/tools access runtime.context directly via Runtime[DeerFlowContext] generic - resolve_context() retained at server entry points for LangGraph Server fallback
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
"""Tests for automatic thread title generation."""
|
|
|
|
import pytest
|
|
|
|
from deerflow.agents.middlewares.title_middleware import TitleMiddleware
|
|
from deerflow.config.title_config import TitleConfig
|
|
|
|
|
|
class TestTitleConfig:
|
|
"""Tests for TitleConfig."""
|
|
|
|
def test_default_config(self):
|
|
"""Test default configuration values."""
|
|
config = TitleConfig()
|
|
assert config.enabled is True
|
|
assert config.max_words == 6
|
|
assert config.max_chars == 60
|
|
assert config.model_name is None
|
|
|
|
def test_custom_config(self):
|
|
"""Test custom configuration."""
|
|
config = TitleConfig(
|
|
enabled=False,
|
|
max_words=10,
|
|
max_chars=100,
|
|
model_name="gpt-4",
|
|
)
|
|
assert config.enabled is False
|
|
assert config.max_words == 10
|
|
assert config.max_chars == 100
|
|
assert config.model_name == "gpt-4"
|
|
|
|
def test_config_validation(self):
|
|
"""Test configuration validation."""
|
|
# max_words should be between 1 and 20
|
|
with pytest.raises(ValueError):
|
|
TitleConfig(max_words=0)
|
|
with pytest.raises(ValueError):
|
|
TitleConfig(max_words=21)
|
|
|
|
# max_chars should be between 10 and 200
|
|
with pytest.raises(ValueError):
|
|
TitleConfig(max_chars=5)
|
|
with pytest.raises(ValueError):
|
|
TitleConfig(max_chars=201)
|
|
|
|
|
|
class TestTitleMiddleware:
|
|
"""Tests for TitleMiddleware."""
|
|
|
|
def test_middleware_initialization(self):
|
|
"""Test middleware can be initialized."""
|
|
middleware = TitleMiddleware()
|
|
assert middleware is not None
|
|
assert middleware.state_schema is not None
|