Download tests/test_chat.py from Codexcoder/sovereign-integration: direct link, hf CLI and curl.
- Browser
- Download file 2.64 kB
-
https://huggingface.co/datasets/Codexcoder/sovereign-integration/resolve/main/tests/test_chat.py
- Command line
-
hf download hf://datasets/Codexcoder/sovereign-integration/tests/test_chat.py
-
curl -L -o test_chat.py https://huggingface.co/datasets/Codexcoder/sovereign-integration/resolve/main/tests/test_chat.py
2.64 kB
| """DeepSeek V4 chat module tests — client, sessions, local echo, API surface.""" | |
| import os | |
| import sys | |
| from pathlib import Path | |
| import pytest | |
| ROOT = Path(__file__).resolve().parent.parent | |
| sys.path.insert(0, str(ROOT)) | |
| def _clear_key(monkeypatch): | |
| """Force local mode in every test.""" | |
| monkeypatch.delenv("DEEPSEEK_API_KEY", raising=False) | |
| def test_client_local_mode_defaults(): | |
| from chat.core import DeepSeekV4Client, DEFAULT_MODEL | |
| client = DeepSeekV4Client() | |
| assert client.local_mode is True | |
| assert client.model == DEFAULT_MODEL | |
| assert client.base_url == "https://api.deepseek.com/v1" | |
| def test_session_flow(): | |
| from chat.core import ChatSession, SOVEREIGN_SYSTEM_PROMPT | |
| s = ChatSession() | |
| assert s.session_id.startswith("ses_") | |
| s.add("system", SOVEREIGN_SYSTEM_PROMPT) | |
| s.add("user", "hello") | |
| s.add("assistant", "hi") | |
| api_msgs = s.to_api() | |
| assert [m["role"] for m in api_msgs] == ["system", "user", "assistant"] | |
| assert len(s.messages) == 3 | |
| def test_session_history_bounded(): | |
| from chat.core import ChatSession | |
| s = ChatSession(max_history=6) | |
| for i in range(20): | |
| s.add("user", f"msg {i}") | |
| assert len(s.messages) <= 6 | |
| def test_local_echo_completion(): | |
| from chat.core import ChatSession, DeepSeekV4Client | |
| s = ChatSession() | |
| s.add("user", "What modules exist?") | |
| result = DeepSeekV4Client().complete(s) | |
| assert result["mode"] == "local" | |
| assert "Sovereign local echo" in result["content"] | |
| assert "no DEEPSEEK_API_KEY" in result["content"] | |
| assert result["model"] == "sovereign/deepseek-v4-sovereign" | |
| def test_client_env_config(monkeypatch): | |
| from chat.core import DeepSeekV4Client | |
| monkeypatch.setenv("DEEPSEEK_API_BASE", "https://example.com/v1") | |
| monkeypatch.setenv("DEEPSEEK_MODEL", "custom-model") | |
| client = DeepSeekV4Client() | |
| assert client.base_url == "https://example.com/v1" | |
| assert client.model == "custom-model" | |
| assert client.local_mode is True # no key | |
| def test_list_models(): | |
| from chat.core import DeepSeekV4Client | |
| models = DeepSeekV4Client().list_models() | |
| ids = {m["id"] for m in models} | |
| assert "sovereign/deepseek-v4-sovereign" in ids | |
| assert "deepseek-v4-flash-0731" in ids | |
| def test_api_routes(): | |
| from chat.api.routes import router | |
| paths = {route.path for route in router.routes} | |
| assert "/api/v1/chat/sessions" in paths | |
| assert "/api/v1/chat/sessions/{session_id}" in paths | |
| assert "/api/v1/chat/send" in paths | |
| assert "/api/v1/chat/models" in paths | |
| assert "/api/v1/chat/status" in paths | |