mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-02 14:58:24 +00:00
Finish Phase 2 of the config refactor: production code no longer calls AppConfig.current() anywhere. AppConfig now flows as an explicit parameter down every consumer lane. Call-site migrations -------------------- - Memory subsystem (queue/updater/storage): MemoryConfig captured at enqueue time so the Timer closure survives the ContextVar boundary. - Sandbox layer: tools.py, security.py, sandbox_provider.py, local_sandbox_provider, aio_sandbox_provider all take app_config explicitly. Module-level caching in tools.py's path helpers is removed — pure parameter flow. - Skills layer: manager.py + loader.py + lead_agent.prompt cache refresh all thread app_config; cache worker closes over it. - Community tools (tavily, jina, firecrawl, exa, ddg, image_search, infoquest, aio_sandbox): read runtime.context.app_config. - Subagents registry: get_subagent_config / list_subagents / get_available_subagent_names require app_config. - Runtime worker: requires RunContext.app_config; no fallback. - Gateway routers (uploads, skills): add Depends(get_config). - Channels feishu: uses AppConfig.from_file() (pure) at its sync boundary. - LangGraph Server bootstrap (make_lead_agent): falls back to AppConfig.from_file() — pure load, not ambient lookup. Context resolution ------------------ - resolve_context(runtime) now raises on non-DeerFlowContext runtime.context. Every entry point attaches typed context; dict/None shapes are rejected loudly instead of being papered over with an ambient AppConfig lookup. AppConfig lifecycle ------------------- - AppConfig.current() kept as a deprecated slot that raises RuntimeError, purely so legacy tests that still run `patch.object(AppConfig, "current")` don't trip AttributeError at teardown. Production never calls it. - conftest autouse fixture no longer monkey-patches `current` — it only stubs `from_file()` so tests don't need a real config.yaml. Design refs ----------- - docs/plans/2026-04-12-config-refactor-plan.md (Phase 2: P2-6..P2-10) - docs/plans/2026-04-12-config-refactor-design.md §8 All 2338 non-e2e tests pass. Zero AppConfig.current() call sites remain in backend/packages or backend/app (docstrings in deps.py excepted).
58 lines
2.5 KiB
Python
58 lines
2.5 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.runtime.checkpointer.async_provider import make_checkpointer
|
|
|
|
# Mock AppConfig.current to return a config with checkpointer=None and database=None
|
|
mock_config = MagicMock()
|
|
mock_config.checkpointer = None
|
|
mock_config.database = None
|
|
|
|
with patch.object(AppConfig, "current", return_value=mock_config):
|
|
async with make_checkpointer(AppConfig.current()) 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.runtime.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(AppConfig.current()) 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 == []
|