|
# retoor <retoor@molodetz.nl>
|
|
|
|
from devplacepy.services.devii.interaction.capabilities import (
|
|
CHANNEL_CLI,
|
|
CHANNEL_SITE_CHAT,
|
|
CHANNEL_TELEGRAM,
|
|
CHANNEL_UNKNOWN,
|
|
channel_id_for_session,
|
|
context_for,
|
|
fragment_for,
|
|
interactions_enabled,
|
|
)
|
|
|
|
|
|
def test_session_channel_mapping():
|
|
assert channel_id_for_session("main") == CHANNEL_SITE_CHAT
|
|
assert channel_id_for_session("docs") == CHANNEL_SITE_CHAT
|
|
assert channel_id_for_session("telegram") == CHANNEL_TELEGRAM
|
|
assert channel_id_for_session("cli") == CHANNEL_CLI
|
|
assert channel_id_for_session("nope") == CHANNEL_UNKNOWN
|
|
|
|
|
|
def test_site_context_exposes_ui_prompt(local_db):
|
|
ctx = context_for(CHANNEL_SITE_CHAT, owner_kind="user", owner_id="u1")
|
|
assert ctx.capabilities["rich_widgets"] is True
|
|
assert "ui_prompt" in ctx.tools
|
|
assert "ui_cancel" in ctx.tools
|
|
assert "ui_notify" in ctx.tools
|
|
assert "interactions_get" in ctx.tools
|
|
assert "interactions_set" in ctx.tools
|
|
|
|
|
|
def test_open_interaction_gates_to_cancel_only(local_db):
|
|
ctx = context_for(
|
|
CHANNEL_SITE_CHAT,
|
|
open_interaction_id="ix-abc",
|
|
owner_kind="user",
|
|
owner_id="u1",
|
|
)
|
|
assert "ui_cancel" in ctx.tools
|
|
assert "ui_prompt" not in ctx.tools
|
|
assert "interactions_get" in ctx.tools
|
|
|
|
|
|
def test_unknown_channel_has_no_ui_prompt(local_db):
|
|
ctx = context_for(CHANNEL_UNKNOWN, owner_kind="user", owner_id="u1")
|
|
assert "ui_prompt" not in ctx.tools
|
|
assert ctx.capabilities["confirm"] is False
|
|
assert "interactions_get" in ctx.tools
|
|
|
|
|
|
def test_fragment_is_compact(local_db):
|
|
text = fragment_for(context_for(CHANNEL_TELEGRAM, owner_kind="guest"))
|
|
assert "CHANNEL: telegram" in text
|
|
assert "TOOLS: ui_prompt" in text
|
|
assert "INTERACTION: none" in text
|
|
assert len(text) < 600
|
|
|
|
|
|
def test_interactions_enabled_default(local_db):
|
|
assert interactions_enabled("guest", "") is True
|