feat(api): folder_indexer.summarize_text via gpt-4o-mini
This commit is contained in:
30
tests/test_folder_indexer.py
Normal file
30
tests/test_folder_indexer.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Folder indexer LLM helpers."""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.core.folder_indexer import summarize_text, IndexResult
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
async def test_summarize_text_returns_summary_and_tokens():
|
||||
mock_resp = AsyncMock()
|
||||
mock_resp.content = "Kickoff notes covering scope and deadlines."
|
||||
mock_resp.usage_metadata = {"input_tokens": 320, "output_tokens": 18, "total_tokens": 338}
|
||||
with patch("app.core.folder_indexer._llm_text", new=AsyncMock(return_value=mock_resp)):
|
||||
result = await summarize_text(content="hello world", ext=".md", name="kickoff.md")
|
||||
assert isinstance(result, IndexResult)
|
||||
assert result.summary == "Kickoff notes covering scope and deadlines."
|
||||
assert result.tokens_used == 338
|
||||
|
||||
|
||||
async def test_summarize_text_truncates_summary_at_500_chars():
|
||||
mock_resp = AsyncMock()
|
||||
mock_resp.content = "x" * 1000
|
||||
mock_resp.usage_metadata = {"total_tokens": 100}
|
||||
with patch("app.core.folder_indexer._llm_text", new=AsyncMock(return_value=mock_resp)):
|
||||
result = await summarize_text(content="x", ext=".md", name="x.md")
|
||||
assert len(result.summary) <= 500
|
||||
Reference in New Issue
Block a user