mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-05 08:14:32 +00:00
* 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>
94 lines
3.0 KiB
Python
94 lines
3.0 KiB
Python
"""Smoke test for ``application.worker.ingest_worker``.
|
|
|
|
``ingest_worker`` does **not** write to Postgres directly. Its PG
|
|
side-effect (creating the ``sources`` row) goes through the
|
|
``upload_index`` HTTP callback to the backend, which writes to PG in
|
|
its own request context. That callback is intentionally out of scope
|
|
here — we can't reach it from the worker test without spinning up the
|
|
Flask app.
|
|
|
|
What we *can* smoke: the task body runs end-to-end, the pipeline gets
|
|
invoked with the expected job metadata, and ``upload_index`` is handed
|
|
a ``file_data`` payload that carries the caller-provided ``user``,
|
|
``job_name``, and ``retriever``. That's the contract the
|
|
backend-facing write depends on.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
from application.parser.schema.base import Document
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestIngestWorker:
|
|
def test_invokes_upload_index_with_expected_payload(
|
|
self, patch_worker_db, task_self, monkeypatch
|
|
):
|
|
from application import worker
|
|
|
|
# Storage: pretend a single file was uploaded at ``inputs/.../a.txt``.
|
|
from io import BytesIO
|
|
fake_storage = MagicMock(name="storage")
|
|
fake_storage.is_directory.return_value = False
|
|
fake_storage.get_file.return_value = BytesIO(b"hello")
|
|
monkeypatch.setattr(
|
|
worker.StorageCreator, "get_storage", lambda: fake_storage
|
|
)
|
|
|
|
# Reader: return a parsed doc.
|
|
fake_reader = MagicMock(name="reader")
|
|
fake_reader.load_data.return_value = [
|
|
Document(text="hello body", extra_info={"source": "a.txt"})
|
|
]
|
|
fake_reader.directory_structure = {
|
|
"a.txt": {
|
|
"type": "text/plain",
|
|
"size_bytes": 5,
|
|
"token_count": 2,
|
|
}
|
|
}
|
|
monkeypatch.setattr(
|
|
worker, "SimpleDirectoryReader", lambda *a, **kw: fake_reader
|
|
)
|
|
|
|
monkeypatch.setattr(
|
|
worker,
|
|
"embed_and_store_documents",
|
|
lambda docs, full_path, source_id, task: None,
|
|
)
|
|
|
|
captured: list[dict] = []
|
|
|
|
def _fake_upload(full_path, file_data):
|
|
captured.append(file_data)
|
|
|
|
monkeypatch.setattr(worker, "upload_index", _fake_upload)
|
|
|
|
result = worker.ingest_worker(
|
|
task_self,
|
|
directory="inputs",
|
|
formats=[".txt"],
|
|
job_name="job1",
|
|
file_path="inputs/eve/job1/a.txt",
|
|
filename="a.txt",
|
|
user="eve",
|
|
retriever="classic",
|
|
)
|
|
|
|
assert result["limited"] is False
|
|
assert result["user"] == "eve"
|
|
assert result["name_job"] == "job1"
|
|
|
|
assert len(captured) == 1
|
|
payload = captured[0]
|
|
assert payload["user"] == "eve"
|
|
assert payload["name"] == "job1"
|
|
assert payload["retriever"] == "classic"
|
|
assert payload["type"] == "local"
|
|
# A fresh source UUID is minted for the backend /upload_index route.
|
|
assert payload["id"]
|