mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 22:13:08 +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.
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
"""Fixtures for Celery worker smoke tests.
|
|
|
|
These tests exercise the task *bodies* in ``docsgpt.worker`` against a
|
|
real Postgres schema (via the ephemeral ``pg_conn`` fixture from the root
|
|
``tests/conftest.py``). External I/O — storage, the embedding pipeline,
|
|
the retriever, the LLM, the backend HTTP callback — is mocked, but every
|
|
PG write is allowed to hit the real ephemeral DB so the assertions can
|
|
read the resulting rows back.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from contextlib import contextmanager
|
|
from typing import Iterator
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from sqlalchemy import Connection
|
|
|
|
|
|
@pytest.fixture
|
|
def patch_worker_db(pg_conn, monkeypatch):
|
|
"""Redirect ``db_session`` / ``db_readonly`` in ``docsgpt.worker``.
|
|
|
|
Both helpers yield the per-test transactional ``pg_conn``, so any
|
|
writes a task performs are visible to the test and roll back on
|
|
teardown. Without this patch the worker would open its own pooled
|
|
engine and punch past the per-test transaction.
|
|
"""
|
|
|
|
@contextmanager
|
|
def _use_pg_conn() -> Iterator[Connection]:
|
|
yield pg_conn
|
|
|
|
monkeypatch.setattr("docsgpt.worker.db_session", _use_pg_conn)
|
|
monkeypatch.setattr("docsgpt.worker.db_readonly", _use_pg_conn)
|
|
|
|
|
|
@pytest.fixture
|
|
def task_self():
|
|
"""Minimal stand-in for the Celery task ``self`` passed to workers.
|
|
|
|
``update_state`` and ``request.retries`` are the only attributes the
|
|
worker bodies touch in our tests. Defaulting ``retries`` to 0 makes
|
|
every fixture instance behave like a fresh first attempt, which is
|
|
what the queued-event publishes are gated on. Tests covering the
|
|
retry path override this to a positive int.
|
|
"""
|
|
task = MagicMock(name="celery_task_self")
|
|
task.request.retries = 0
|
|
return task
|