mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 12:13:05 +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.
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
"""Tests for privacy-preserving v1 client session correlation."""
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
from docsgpt.api.v1.session_store import (
|
|
delete_conversation,
|
|
identify_session,
|
|
load_conversation,
|
|
save_conversation,
|
|
)
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_session_key_is_prompt_and_agent_scoped():
|
|
headers = {"X-Session-ID": "raw-secret-session"}
|
|
main = {"messages": [{"role": "system", "content": "coding"}]}
|
|
title = {"messages": [{"role": "system", "content": "title"}]}
|
|
one = identify_session(headers, main, "agent-1")
|
|
assert one != identify_session(headers, title, "agent-1")
|
|
assert one != identify_session(headers, main, "agent-2")
|
|
assert "raw-secret-session" not in one.key
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_explicit_docsgpt_session_precedes_generic_header():
|
|
data = {
|
|
"docsgpt": {"session_id": "explicit"},
|
|
"messages": [{"role": "user", "content": "hi"}],
|
|
}
|
|
explicit = identify_session({"X-Session-ID": "generic"}, data, "agent")
|
|
expected = identify_session(
|
|
{"X-DocsGPT-Session-ID": "explicit"},
|
|
{"messages": data["messages"]},
|
|
"agent",
|
|
)
|
|
assert explicit == expected
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_openai_user_field_is_not_a_chat_session():
|
|
data = {
|
|
"user": "stable-end-user-id",
|
|
"messages": [{"role": "user", "content": "hi"}],
|
|
}
|
|
assert identify_session({}, data, "agent") is None
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_save_and_load_use_bounded_redis_ttl(monkeypatch):
|
|
redis = MagicMock()
|
|
redis.get.return_value = b"conv-1"
|
|
monkeypatch.setattr(
|
|
"docsgpt.api.v1.session_store.get_redis_instance", lambda: redis
|
|
)
|
|
monkeypatch.setattr(
|
|
"docsgpt.api.v1.session_store.settings.V1_SESSION_TTL_SECONDS", 123
|
|
)
|
|
session = identify_session({"X-Session-ID": "s"}, {"messages": []}, "a")
|
|
save_conversation(session, "conv-1")
|
|
redis.set.assert_called_once_with(session.key, "conv-1", ex=123)
|
|
assert load_conversation(session) == "conv-1"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_delete_conversation_invalidates_stale_mapping(monkeypatch):
|
|
redis = MagicMock()
|
|
monkeypatch.setattr(
|
|
"docsgpt.api.v1.session_store.get_redis_instance", lambda: redis
|
|
)
|
|
session = identify_session({"X-Session-ID": "s"}, {"messages": []}, "a")
|
|
delete_conversation(session)
|
|
redis.delete.assert_called_once_with(session.key)
|