mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(store): address review nits in test file and embeddings.py
- Move `import types` and `from typing import Any` to top-level in content_handlers_test.py - Replace `# type: ignore[index]` with proper Any cast in immutable mapping test - Fix docstring for batch_size=0 test: DB IS queried (assertion proves it), result is empty due to islice - Lift `from backend.blocks import get_blocks` to top-level import in embeddings.py
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
Tests for content handlers (blocks, store agents, documentation).
|
||||
"""
|
||||
|
||||
import types
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
@@ -102,8 +104,6 @@ def test_get_enabled_blocks_cached():
|
||||
|
||||
def test_get_enabled_blocks_returns_immutable_mapping():
|
||||
"""The returned mapping is a MappingProxyType — mutation raises TypeError."""
|
||||
import types
|
||||
|
||||
blocks = {"b1": _make_block_class(name="B1")}
|
||||
with patch(
|
||||
"backend.api.features.store.content_handlers.get_blocks", return_value=blocks
|
||||
@@ -111,7 +111,8 @@ def test_get_enabled_blocks_returns_immutable_mapping():
|
||||
result = _get_enabled_blocks()
|
||||
assert isinstance(result, types.MappingProxyType)
|
||||
with pytest.raises(TypeError):
|
||||
result["new_key"] = object() # type: ignore[index]
|
||||
result_any: Any = result
|
||||
result_any["new_key"] = object()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -232,7 +233,7 @@ async def test_block_handler_get_missing_items_splits_camelcase():
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_block_handler_get_missing_items_batch_size_zero():
|
||||
"""batch_size=0 returns an empty list without querying the database."""
|
||||
"""batch_size=0 returns an empty list; the DB is still queried to find missing IDs."""
|
||||
handler = BlockHandler()
|
||||
|
||||
blocks = {"b1": _make_block_class(name="B1")}
|
||||
|
||||
@@ -15,6 +15,7 @@ from prisma.enums import ContentType
|
||||
from tiktoken import encoding_for_model
|
||||
|
||||
from backend.api.features.store.content_handlers import CONTENT_HANDLERS
|
||||
from backend.blocks import get_blocks
|
||||
from backend.data.db import execute_raw_with_schema, query_raw_with_schema
|
||||
from backend.util.clients import get_openai_client
|
||||
from backend.util.json import dumps
|
||||
@@ -662,8 +663,6 @@ async def cleanup_orphaned_embeddings() -> dict[str, Any]:
|
||||
)
|
||||
current_ids = {row["id"] for row in valid_agents}
|
||||
elif content_type == ContentType.BLOCK:
|
||||
from backend.blocks import get_blocks
|
||||
|
||||
current_ids = set(get_blocks().keys())
|
||||
elif content_type == ContentType.DOCUMENTATION:
|
||||
# Use DocumentationHandler to get section-based content IDs
|
||||
|
||||
Reference in New Issue
Block a user