# tests/core/test_settings.py
import pytest
from core.settings import SettingsManager
from core.store import InMemoryStore
from core.protocol import SettingsAction
from sdk.mock import MockPlatformClient


@pytest.fixture
def mgr():
    return SettingsManager(MockPlatformClient(), InMemoryStore())


async def test_get_returns_defaults(mgr):
    settings = await mgr.get("u1")
    assert "web-search" in settings.skills


async def test_apply_toggle_skill(mgr):
    action = SettingsAction(action="toggle_skill", payload={"skill": "browser", "enabled": True})
    await mgr.apply("u1", action)
    settings = await mgr.get("u1")
    assert settings.skills.get("browser") is True


async def test_apply_invalidates_cache(mgr):
    s1 = await mgr.get("u1")
    initial = s1.skills.get("browser", False)
    action = SettingsAction(action="toggle_skill", payload={"skill": "browser", "enabled": not initial})
    await mgr.apply("u1", action)
    s2 = await mgr.get("u1")
    assert s2.skills.get("browser") == (not initial)
