feat: add prototype local state store
This commit is contained in:
parent
de20ff638a
commit
2fad1aaa66
2 changed files with 154 additions and 0 deletions
75
tests/platform/test_prototype_state.py
Normal file
75
tests/platform/test_prototype_state.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import pytest
|
||||
|
||||
from core.protocol import SettingsAction
|
||||
from sdk.interface import UserSettings
|
||||
from sdk.prototype_state import PrototypeStateStore
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_or_create_user_is_stable_per_surface_identity():
|
||||
store = PrototypeStateStore()
|
||||
|
||||
first = await store.get_or_create_user(
|
||||
external_id="@alice:example.org",
|
||||
platform="matrix",
|
||||
display_name="Alice",
|
||||
)
|
||||
second = await store.get_or_create_user(
|
||||
external_id="@alice:example.org",
|
||||
platform="matrix",
|
||||
)
|
||||
|
||||
assert first.user_id == "usr-matrix-@alice:example.org"
|
||||
assert first.is_new is True
|
||||
assert second.user_id == first.user_id
|
||||
assert second.is_new is False
|
||||
assert second.display_name == "Alice"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_settings_defaults_match_existing_mock_shape():
|
||||
store = PrototypeStateStore()
|
||||
|
||||
settings = await store.get_settings("usr-matrix-@alice:example.org")
|
||||
|
||||
assert isinstance(settings, UserSettings)
|
||||
assert settings.skills == {
|
||||
"web-search": True,
|
||||
"fetch-url": True,
|
||||
"email": False,
|
||||
"browser": False,
|
||||
"image-gen": False,
|
||||
"files": True,
|
||||
}
|
||||
assert settings.safety == {
|
||||
"email-send": True,
|
||||
"file-delete": True,
|
||||
"social-post": True,
|
||||
}
|
||||
assert settings.soul == {"name": "Лямбда", "instructions": ""}
|
||||
assert settings.plan == {"name": "Beta", "tokens_used": 0, "tokens_limit": 1000}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_settings_supports_toggle_skill_and_setters():
|
||||
store = PrototypeStateStore()
|
||||
|
||||
await store.update_settings(
|
||||
"usr-matrix-@alice:example.org",
|
||||
SettingsAction(action="toggle_skill", payload={"skill": "browser", "enabled": True}),
|
||||
)
|
||||
await store.update_settings(
|
||||
"usr-matrix-@alice:example.org",
|
||||
SettingsAction(action="set_soul", payload={"field": "instructions", "value": "Be concise"}),
|
||||
)
|
||||
await store.update_settings(
|
||||
"usr-matrix-@alice:example.org",
|
||||
SettingsAction(action="set_safety", payload={"trigger": "social-post", "enabled": False}),
|
||||
)
|
||||
|
||||
settings = await store.get_settings("usr-matrix-@alice:example.org")
|
||||
|
||||
assert settings.skills["browser"] is True
|
||||
assert settings.skills["web-search"] is True
|
||||
assert settings.soul["instructions"] == "Be concise"
|
||||
assert settings.safety["social-post"] is False
|
||||
Loading…
Add table
Add a link
Reference in a new issue