mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 14:12:58 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
114 lines
3.1 KiB
Python
114 lines
3.1 KiB
Python
"""Unit tests for docsgpt/api/answer/services/conversation_service.py.
|
|
|
|
Additional coverage beyond tests/api/answer/services/test_conversation_service.py:
|
|
- save_conversation: index-based update, metadata persistence, agent key tracking
|
|
- update_compression_metadata
|
|
- append_compression_message
|
|
- get_compression_metadata
|
|
- Edge cases: None token, empty summary, shared_with access
|
|
"""
|
|
|
|
from unittest.mock import MagicMock, Mock
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestConversationServiceGetExtended:
|
|
pass
|
|
|
|
def test_handles_exception_gracefully(self, mock_mongo_db):
|
|
from docsgpt.api.answer.services.conversation_service import (
|
|
ConversationService,
|
|
)
|
|
|
|
service = ConversationService()
|
|
# Pass an invalid ObjectId
|
|
result = service.get_conversation("not-an-objectid", "user_123")
|
|
assert result is None
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestSaveConversationExtended:
|
|
pass
|
|
|
|
def test_raises_for_none_token(self, mock_mongo_db):
|
|
from docsgpt.api.answer.services.conversation_service import (
|
|
ConversationService,
|
|
)
|
|
|
|
service = ConversationService()
|
|
with pytest.raises(ValueError, match="Invalid or missing authentication"):
|
|
service.save_conversation(
|
|
conversation_id=None,
|
|
question="Q",
|
|
response="A",
|
|
thought="",
|
|
sources=[],
|
|
tool_calls=[],
|
|
llm=Mock(),
|
|
model_id="m",
|
|
decoded_token=None,
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestUpdateCompressionMetadata:
|
|
pass
|
|
|
|
@pytest.mark.unit
|
|
class TestAppendCompressionMessage:
|
|
pass
|
|
|
|
@pytest.mark.unit
|
|
class TestGetCompressionMetadata:
|
|
pass
|
|
|
|
def test_returns_none_for_missing_conversation(self, mock_mongo_db):
|
|
from docsgpt.api.answer.services.conversation_service import (
|
|
ConversationService,
|
|
)
|
|
|
|
service = ConversationService()
|
|
result = service.get_compression_metadata("507f1f77bcf86cd799439011")
|
|
assert result is None
|
|
|
|
def test_handles_invalid_id(self, mock_mongo_db):
|
|
from docsgpt.api.answer.services.conversation_service import (
|
|
ConversationService,
|
|
)
|
|
|
|
service = ConversationService()
|
|
result = service.get_compression_metadata("invalid-id")
|
|
assert result is None
|
|
|
|
|
|
# =====================================================================
|
|
# Coverage gap tests (lines 233-237, 258, 261)
|
|
# =====================================================================
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestConversationServiceGaps:
|
|
pass
|
|
|
|
def test_append_compression_message_empty_summary_skips(self, mock_mongo_db):
|
|
"""Cover: empty summary does not insert."""
|
|
from docsgpt.api.answer.services.conversation_service import (
|
|
ConversationService,
|
|
)
|
|
|
|
service = ConversationService()
|
|
service.conversations_collection = MagicMock()
|
|
|
|
service.append_compression_message(
|
|
"507f1f77bcf86cd799439011", {"compressed_summary": ""}
|
|
)
|
|
service.conversations_collection.update_one.assert_not_called()
|