mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-12 16:15:14 +00:00
rabbit fixes
This commit is contained in:
1 parent
cdbc4695ea
commit
f4331cd3a3
31 files changed
+470
-87
No files matched your search
@@ -810,3 +810,40 @@ class TestUpdateChunkGraphLinks:
|
||||
graph_store.remap_chunk.assert_called_once_with(
|
||||
str(src["id"]), "chunk-old", "chunk-new"
|
||||
)
|
||||
|
||||
def test_default_fallback_failed_delete_returns_500_without_duplicate(self, app, pg_conn):
|
||||
"""A failed old-chunk delete rolls the new chunk back and fails the request."""
|
||||
from docsgpt.vectorstore.base import BaseVectorStore
|
||||
|
||||
class _FallbackStore(BaseVectorStore):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.deleted = []
|
||||
|
||||
def search(self, *args, **kwargs):
|
||||
return []
|
||||
|
||||
def add_texts(self, texts, metadatas=None, *args, **kwargs):
|
||||
return []
|
||||
|
||||
def get_chunks(self):
|
||||
return [{"doc_id": "chunk-old", "text": "old", "metadata": {}}]
|
||||
|
||||
def add_chunk(self, text, metadata=None):
|
||||
return "chunk-new"
|
||||
|
||||
def delete_chunk(self, chunk_id):
|
||||
self.deleted.append(chunk_id)
|
||||
return chunk_id != "chunk-old"
|
||||
|
||||
user = "u-upd-graph-fallback-fail"
|
||||
src = self._graph_source(pg_conn, user)
|
||||
graph_store = MagicMock()
|
||||
store = _FallbackStore()
|
||||
store_proxy = MagicMock(wraps=store)
|
||||
|
||||
response = self._put(app, pg_conn, src, user, graph_store, store_proxy)
|
||||
|
||||
assert response.status_code == 500
|
||||
assert store.deleted == ["chunk-old", "chunk-new"]
|
||||
graph_store.remap_chunk.assert_not_called()
|
||||
@@ -282,6 +282,27 @@ class TestSourceGraphNodes:
|
||||
sid, query="ada", type_key="person", offset=200, limit=100
|
||||
)
|
||||
|
||||
def test_caps_search_query_length(self, app, pg_conn):
|
||||
from docsgpt.api.user.sources.routes import SourceGraphNodes
|
||||
|
||||
user = "u-graph-nodes-long-q"
|
||||
sid = _graphrag_source(pg_conn, user)
|
||||
store = _node_list_store()
|
||||
|
||||
with _patch_db(pg_conn), patch(
|
||||
"docsgpt.graphrag.store.GraphStore", return_value=store
|
||||
), app.test_request_context(
|
||||
f"/api/sources/{sid}/graph/nodes?q=%20{'a' * 500}"
|
||||
):
|
||||
from flask import request
|
||||
request.decoded_token = {"sub": user}
|
||||
response = SourceGraphNodes().get(sid)
|
||||
|
||||
assert response.status_code == 200
|
||||
store.list_nodes.assert_called_once_with(
|
||||
sid, query="a" * 200, type_key=None, offset=0, limit=25
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"qs, page, per_page",
|
||||
[
|
||||
|
||||
Reference in new issue
Block a user