test: unit suite for the gateway invariants plus an integration slice
Covers routing, failover, the circuit breaker, structured-output retries, the cache-prefix validator, cost computation including cached-token pricing, the daily budget breaker, the quota protocol, the task state machine and log redaction. HTTP is mocked -- no unit test spends money. The integration test runs the real slice against PostgreSQL and Redis with a faked provider.
This commit is contained in:
Executable
+36
@@ -0,0 +1,36 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
# Unit tests never touch a real database, Redis or LLM provider. Setting these
|
||||
# before any import keeps `packages.shared.config` deterministic.
|
||||
os.environ.setdefault("APP_ENV", "local")
|
||||
os.environ.setdefault("JWT_SECRET", "unit-test-secret-value-not-used-in-any-real-env")
|
||||
os.environ.setdefault("DEEPSEEK_API_KEY", "unit-test-placeholder")
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def repo_root() -> Path:
|
||||
return REPO_ROOT
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def prompts_dir(tmp_path: Path) -> Iterator[Path]:
|
||||
"""A minimal on-disk prompt tree with a clean, cacheable system prefix."""
|
||||
root = tmp_path / "prompts"
|
||||
(root / "agent_chat").mkdir(parents=True)
|
||||
(root / "agent_chat" / "v1.txt").write_text(
|
||||
"[system]\n你是穿搭顾问助手。只回答穿搭相关问题。\n\n[user]\n{user_input}\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(root / "agent_chat" / "v2.txt").write_text(
|
||||
"[system]\n你是穿搭顾问助手。回答要具体可执行。\n\n[user]\n{user_input}\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
yield root
|
||||
Reference in New Issue
Block a user