2026-04-23 15:44:12 +05:30
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from app.agents.new_chat.filesystem_backends import build_backend_resolver
|
|
|
|
|
from app.agents.new_chat.filesystem_selection import (
|
|
|
|
|
ClientPlatform,
|
|
|
|
|
FilesystemMode,
|
|
|
|
|
FilesystemSelection,
|
2026-04-24 05:59:21 +05:30
|
|
|
LocalFilesystemMount,
|
2026-04-23 15:44:12 +05:30
|
|
|
)
|
2026-04-24 01:44:23 +05:30
|
|
|
from app.agents.new_chat.middleware.multi_root_local_folder_backend import (
|
|
|
|
|
MultiRootLocalFolderBackend,
|
|
|
|
|
)
|
2026-04-23 15:44:12 +05:30
|
|
|
|
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _RuntimeStub:
|
|
|
|
|
state = {"files": {}}
|
|
|
|
|
|
|
|
|
|
|
2026-04-24 01:44:23 +05:30
|
|
|
def test_backend_resolver_returns_multi_root_backend_for_single_root(tmp_path: Path):
|
2026-04-23 15:44:12 +05:30
|
|
|
selection = FilesystemSelection(
|
|
|
|
|
mode=FilesystemMode.DESKTOP_LOCAL_FOLDER,
|
|
|
|
|
client_platform=ClientPlatform.DESKTOP,
|
2026-04-24 05:59:21 +05:30
|
|
|
local_mounts=(LocalFilesystemMount(mount_id="tmp", root_path=str(tmp_path)),),
|
2026-04-23 15:44:12 +05:30
|
|
|
)
|
|
|
|
|
resolver = build_backend_resolver(selection)
|
|
|
|
|
|
|
|
|
|
backend = resolver(_RuntimeStub())
|
2026-04-24 01:44:23 +05:30
|
|
|
assert isinstance(backend, MultiRootLocalFolderBackend)
|
2026-04-23 15:44:12 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_backend_resolver_uses_cloud_mode_by_default():
|
|
|
|
|
resolver = build_backend_resolver(FilesystemSelection())
|
|
|
|
|
backend = resolver(_RuntimeStub())
|
|
|
|
|
# StateBackend class name check keeps this test decoupled
|
|
|
|
|
# from internal deepagents runtime class identity.
|
|
|
|
|
assert backend.__class__.__name__ == "StateBackend"
|
2026-04-24 01:44:23 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_backend_resolver_returns_multi_root_backend_for_multiple_roots(tmp_path: Path):
|
|
|
|
|
root_one = tmp_path / "resume"
|
|
|
|
|
root_two = tmp_path / "notes"
|
|
|
|
|
root_one.mkdir()
|
|
|
|
|
root_two.mkdir()
|
|
|
|
|
selection = FilesystemSelection(
|
|
|
|
|
mode=FilesystemMode.DESKTOP_LOCAL_FOLDER,
|
|
|
|
|
client_platform=ClientPlatform.DESKTOP,
|
2026-04-24 05:59:21 +05:30
|
|
|
local_mounts=(
|
|
|
|
|
LocalFilesystemMount(mount_id="resume", root_path=str(root_one)),
|
|
|
|
|
LocalFilesystemMount(mount_id="notes", root_path=str(root_two)),
|
|
|
|
|
),
|
2026-04-24 01:44:23 +05:30
|
|
|
)
|
|
|
|
|
resolver = build_backend_resolver(selection)
|
|
|
|
|
|
|
|
|
|
backend = resolver(_RuntimeStub())
|
|
|
|
|
assert isinstance(backend, MultiRootLocalFolderBackend)
|