Files
DocsGPT/tests/api/answer/test_empty_retrieval_visibility.py
Alex 574f96341e refactor: rename the application package to docsgpt
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.
2026-09-07 10:20:43 +01:00

59 lines
2.0 KiB
Python

"""An empty retrieval must be visible to both the model and the client.
Two independent suppressions made "searched your sources, found nothing"
indistinguishable from "no source was attached": the ``source`` SSE event was
skipped when the list was empty, and the prompt said nothing at all. Together
they let a retrieval failure surface as a confident, ungrounded answer.
"""
from __future__ import annotations
from unittest.mock import MagicMock, patch
import pytest
from docsgpt.agents.classic_agent import ClassicAgent
def _agent(**kwargs):
with patch("docsgpt.llm.llm_creator.LLMCreator.create_llm"), patch(
"docsgpt.llm.handlers.handler_creator.LLMHandlerCreator.create_handler"
):
return ClassicAgent(
endpoint="stream",
llm_name="openai",
model_id="gpt-4o",
api_key="k",
prompt="SYSTEM",
decoded_token={"sub": "u"},
tool_executor=MagicMock(),
**kwargs,
)
@pytest.mark.unit
class TestEmptyRetrievalNote:
def test_searched_sources_with_no_hits_tells_the_model(self):
agent = _agent(retrieved_docs=[], sources_were_searched=True)
user = agent._build_messages("SYSTEM", "What is the rebate?")[-1]["content"]
assert "were searched" in user
assert user.rstrip().endswith("What is the rebate?")
def test_no_sources_attached_stays_silent(self):
"""Nothing was searched, so there is nothing to report."""
agent = _agent(retrieved_docs=[], sources_were_searched=False)
user = agent._build_messages("SYSTEM", "What is the rebate?")[-1]["content"]
assert user == "What is the rebate?"
def test_documents_found_suppresses_the_note(self):
agent = _agent(
retrieved_docs=[{"filename": "a.pdf", "text": "the rebate is 4250"}],
sources_were_searched=True,
)
user = agent._build_messages("SYSTEM", "What is the rebate?")[-1]["content"]
assert "were searched" not in user
assert "<documents>" in user