mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-19 04:15:32 +00:00
Pg 4 (#2390)
* feat: postgres tests * feat: mongo cutoff * feat: mongo cutoff * feat: adjust docs and compose files * fix: mini code mongo removals * fix: tests and k8s mongo stuff * feat: test fixes * fix: ruff * fix: vale * Potential fix for pull request finding 'CodeQL / Clear-text logging of sensitive information' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix: mini suggestions * vale lint fix 2 * fix: codeql columns thing * fix: test mongo * fix: tests coverage * feat: better tests 4 * feat: more tests * feat: decent coverage * fix: ruff fixes * fix: remove mongo mock * feat: enhance workflow engine and API routes; add document retrieval and source handling * feat: e2e tests * fix: mcp, mongo and more * fix: mini codeql warning * fix: agent chunk view * fix: mini issues * fix: more pg fixes * feat: postgres prep on start * feat: qa tests * fix: mini improvements * fix: tests --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Siddhant Rai <siddhant.rai.5686@gmail.com>
This commit is contained in:
312 files changed
+763725
-25159
No files matched your search
@@ -756,24 +756,12 @@ class TestUploadFileToGoogle:
|
||||
llm._upload_file_to_google({"path": "/nonexistent"})
|
||||
|
||||
def test_upload_and_caches_uri(self, llm, monkeypatch):
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
mock_attachments = MagicMock()
|
||||
mock_db = MagicMock()
|
||||
mock_db.__getitem__ = MagicMock(return_value=mock_attachments)
|
||||
mock_mongo_client = {"docsgpt": mock_db}
|
||||
mock_mongodb = MagicMock()
|
||||
mock_mongodb.get_client.return_value = mock_mongo_client
|
||||
|
||||
monkeypatch.setattr(
|
||||
"application.core.mongo_db.MongoDB.get_client",
|
||||
mock_mongodb.get_client,
|
||||
)
|
||||
# The attachment-id cache write goes through AttachmentsRepository
|
||||
# now; failures there are swallowed with a logged warning, so the
|
||||
# test just verifies the upload URI is returned end-to-end.
|
||||
monkeypatch.setattr(
|
||||
"application.llm.google_ai.settings",
|
||||
types.SimpleNamespace(
|
||||
GOOGLE_API_KEY="k", API_KEY="k", MONGO_DB_NAME="docsgpt"
|
||||
),
|
||||
types.SimpleNamespace(GOOGLE_API_KEY="k", API_KEY="k"),
|
||||
)
|
||||
result = llm._upload_file_to_google({"path": "/tmp/file.pdf", "_id": "abc"})
|
||||
# process_file returns fn(path) which calls client.files.upload -> "gs://fake-uri"
|
||||
|
||||
+10
-38
@@ -1153,28 +1153,17 @@ class TestUploadFileToOpenai2:
|
||||
with pytest.raises(FileNotFoundError, match="File not found"):
|
||||
llm._upload_file_to_openai({"path": "/nonexistent.pdf"})
|
||||
|
||||
def test_upload_success_with_id_caching(self, llm, monkeypatch):
|
||||
"""Cover lines 498-514: successful upload with MongoDB caching."""
|
||||
from unittest.mock import MagicMock
|
||||
def test_upload_success_with_id_caching(self, llm):
|
||||
"""Successful upload returns the uploaded file id.
|
||||
|
||||
The attachment-id cache write goes through AttachmentsRepository;
|
||||
failures there are swallowed with a logged warning, so this just
|
||||
asserts the upload return value flows through.
|
||||
"""
|
||||
llm.storage = types.SimpleNamespace(
|
||||
file_exists=lambda p: True,
|
||||
process_file=lambda path, fn, **kw: "file-uploaded-id",
|
||||
)
|
||||
|
||||
mock_collection = MagicMock()
|
||||
mock_db = MagicMock()
|
||||
mock_db.__getitem__ = MagicMock(return_value=mock_collection)
|
||||
mock_client = MagicMock()
|
||||
mock_client.__getitem__ = MagicMock(return_value=mock_db)
|
||||
mock_mongo_cls = MagicMock()
|
||||
mock_mongo_cls.get_client.return_value = mock_client
|
||||
|
||||
monkeypatch.setattr(
|
||||
"application.core.mongo_db.MongoDB",
|
||||
mock_mongo_cls,
|
||||
)
|
||||
|
||||
result = llm._upload_file_to_openai(
|
||||
{"path": "/file.pdf", "_id": "attachment-id"}
|
||||
)
|
||||
@@ -1400,38 +1389,21 @@ class TestUploadFileToOpenaiLine469:
|
||||
class TestUploadFileToOpenaiLines489To517:
|
||||
"""Cover lines 489-517: full upload path."""
|
||||
|
||||
def test_full_upload_with_mongo_caching(self, llm, monkeypatch):
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
def test_full_upload_with_attachment_caching(self, llm):
|
||||
# AttachmentsRepository cache-write errors are swallowed; verify
|
||||
# the uploaded file id returns through.
|
||||
llm.storage = types.SimpleNamespace(
|
||||
file_exists=lambda p: True,
|
||||
process_file=lambda path, fn, **kw: "file-new-id",
|
||||
)
|
||||
|
||||
mock_collection = MagicMock()
|
||||
mock_db = MagicMock()
|
||||
mock_db.__getitem__ = MagicMock(return_value=mock_collection)
|
||||
mock_client = MagicMock()
|
||||
mock_client.__getitem__ = MagicMock(return_value=mock_db)
|
||||
mock_mongo_cls = MagicMock()
|
||||
mock_mongo_cls.get_client.return_value = mock_client
|
||||
|
||||
monkeypatch.setattr("application.core.mongo_db.MongoDB", mock_mongo_cls)
|
||||
|
||||
result = llm._upload_file_to_openai({"path": "/doc.pdf", "_id": "att-1"})
|
||||
assert result == "file-new-id"
|
||||
|
||||
def test_upload_without_id_skips_caching(self, llm, monkeypatch):
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
def test_upload_without_id_skips_caching(self, llm):
|
||||
llm.storage = types.SimpleNamespace(
|
||||
file_exists=lambda p: True,
|
||||
process_file=lambda path, fn, **kw: "file-no-cache",
|
||||
)
|
||||
|
||||
mock_mongo_cls = MagicMock()
|
||||
monkeypatch.setattr("application.core.mongo_db.MongoDB", mock_mongo_cls)
|
||||
|
||||
result = llm._upload_file_to_openai({"path": "/doc.pdf"})
|
||||
assert result == "file-no-cache"
|
||||
|
||||
|
||||
Reference in new issue
Block a user