28 行
1 KiB
Python
28 行
1 KiB
Python
import pytest
|
|
|
|
from adapters.astrbot_command_adapter import ChatCommandContext
|
|
from backend.services.chat_command_guard_service import ChatCommandGuardService
|
|
|
|
|
|
class Audit:
|
|
def record(self, **kwargs): pass
|
|
|
|
|
|
class Guard(ChatCommandGuardService):
|
|
def __init__(self):
|
|
self.audit = Audit()
|
|
def _daily_count(self, user_id): return 0
|
|
def _daily_group_count(self, group_id): return 0
|
|
|
|
|
|
CHAT = ChatCommandContext("user-1", "group-1", "qq:group:1", "aiocqhttp", "msg-1")
|
|
|
|
|
|
def test_guard_enforces_resolution_and_concurrency():
|
|
guard = Guard()
|
|
config = {"chat_access": {"allow_2k": True, "allow_4k": False, "user_concurrency_limit": 1}}
|
|
guard.check_generation(config, CHAT, size="2560x1440", active_jobs=[])
|
|
with pytest.raises(ValueError, match="4K"):
|
|
guard.check_generation(config, CHAT, size="3840x2160", active_jobs=[])
|
|
with pytest.raises(ValueError, match="用户并发"):
|
|
guard.check_generation(config, CHAT, size="1920x1080", active_jobs=[{"request": {"metadata": {"user_id": "user-1"}}}])
|