Files
QQbot/tests/test_personality_scope_priority.py
Mimikko-zeus a754e7843f Refactor configuration and enhance AI capabilities
Updated .env.example to improve clarity and added new configuration options for memory and reliability settings. Refactored main.py to streamline the bot's entry point and improved error handling. Enhanced README to reflect new features and command structure. Removed deprecated cmd_zip_skill and skills_creator modules to clean up the codebase. Updated AIClient and MemorySystem for better performance and flexibility in handling user interactions.
2026-03-03 21:56:33 +08:00

45 lines
1.8 KiB
Python

from pathlib import Path
from src.ai.personality import PersonalityProfile, PersonalitySystem, PersonalityTrait
def _profile(name: str) -> PersonalityProfile:
return PersonalityProfile(
name=name,
description=f"{name} profile",
traits=[PersonalityTrait.FRIENDLY],
speaking_style="plain",
)
def test_scope_priority_session_over_group_over_user_over_global(tmp_path: Path):
cfg = tmp_path / "personalities.json"
state = tmp_path / "personality_state.json"
system = PersonalitySystem(config_path=cfg, state_path=state)
system.add_personality("p_global", _profile("global"))
system.add_personality("p_user", _profile("user"))
system.add_personality("p_group", _profile("group"))
system.add_personality("p_session", _profile("session"))
assert system.set_personality("p_global", scope="global")
assert system.set_personality("p_user", scope="user", scope_id="u1")
assert system.set_personality("p_group", scope="group", scope_id="g1")
assert system.set_personality("p_session", scope="session", scope_id="g1:u1")
profile = system.get_active_personality(user_id="u1", group_id="g1", session_id="g1:u1")
assert profile is not None
assert profile.name == "session"
profile_no_session = system.get_active_personality(user_id="u1", group_id="g1", session_id="other")
assert profile_no_session is not None
assert profile_no_session.name == "group"
profile_user_only = system.get_active_personality(user_id="u1", group_id=None, session_id=None)
assert profile_user_only is not None
assert profile_user_only.name == "user"
profile_global = system.get_active_personality(user_id="u2", group_id=None, session_id=None)
assert profile_global is not None
assert profile_global.name == "global"