mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-04-25 19:28:23 +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
57 lines
2.4 KiB
Python
57 lines
2.4 KiB
Python
"""Test for issue #1016: checkpointer should not return None."""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
from langgraph.checkpoint.memory import InMemorySaver
|
|
|
|
from deerflow.config.app_config import AppConfig
|
|
|
|
|
|
class TestCheckpointerNoneFix:
|
|
"""Tests that checkpointer context managers return InMemorySaver instead of None."""
|
|
|
|
@pytest.mark.anyio
|
|
async def test_async_make_checkpointer_returns_in_memory_saver_when_not_configured(self):
|
|
"""make_checkpointer should return InMemorySaver when config.checkpointer is None."""
|
|
from deerflow.agents.checkpointer.async_provider import make_checkpointer
|
|
|
|
# Mock AppConfig.get to return a config with checkpointer=None
|
|
mock_config = MagicMock()
|
|
mock_config.checkpointer = None
|
|
|
|
with patch.object(AppConfig, "current", return_value=mock_config):
|
|
async with make_checkpointer() as checkpointer:
|
|
# Should return InMemorySaver, not None
|
|
assert checkpointer is not None
|
|
assert isinstance(checkpointer, InMemorySaver)
|
|
|
|
# Should be able to call alist() without AttributeError
|
|
# This is what LangGraph does and what was failing in issue #1016
|
|
result = []
|
|
async for item in checkpointer.alist(config={"configurable": {"thread_id": "test"}}):
|
|
result.append(item)
|
|
|
|
# Empty list is expected for a fresh checkpointer
|
|
assert result == []
|
|
|
|
def test_sync_checkpointer_context_returns_in_memory_saver_when_not_configured(self):
|
|
"""checkpointer_context should return InMemorySaver when config.checkpointer is None."""
|
|
from deerflow.agents.checkpointer.provider import checkpointer_context
|
|
|
|
# Mock AppConfig.get to return a config with checkpointer=None
|
|
mock_config = MagicMock()
|
|
mock_config.checkpointer = None
|
|
|
|
with patch.object(AppConfig, "current", return_value=mock_config):
|
|
with checkpointer_context() as checkpointer:
|
|
# Should return InMemorySaver, not None
|
|
assert checkpointer is not None
|
|
assert isinstance(checkpointer, InMemorySaver)
|
|
|
|
# Should be able to call list() without AttributeError
|
|
result = list(checkpointer.list(config={"configurable": {"thread_id": "test"}}))
|
|
|
|
# Empty list is expected for a fresh checkpointer
|
|
assert result == []
|