"""Choosing a crowd, and reading one. Two screens and one rule each. The picker may only ever offer and accept models *this person* can reach — a control checked in the template and not in the route is advisory, and a crafted request walks past it. The transcript has to say which speaker a bubble is and which pass it belongs to, because nine bubbles for one question are otherwise indistinguishable from nine people talking at once. """ from __future__ import annotations import pytest from sqlalchemy import select from lembas.db.models import ( ROLE_ASSISTANT, ROLE_USER, Chat, Connection, Group, Model, User, ) from lembas.services import chat as chat_service from lembas.services import crowd as crowd_service from lembas.services import settings_store from lembas.services.crypto import encrypt @pytest.fixture(autouse=True) def crowd_on(db, registered): settings_store.update(db, {"enabled": True}, key=settings_store.CROWD) connection = Connection( name="Test", base_url="http://127.0.0.1:1", api_key_encrypted=encrypt("") ) db.add(connection) db.commit() for index, name in enumerate(("main-model", "second-model", "third-model")): db.add( Model( connection_id=connection.id, model_id=name, display_name=name, position=index, capabilities_json={"tools": True}, ) ) db.commit() def _user(db) -> User: return db.scalars(select(User).order_by(User.created_at)).first() def _chat(db) -> Chat: connection = db.scalars(select(Connection)).first() chat = Chat( user_id=_user(db).id, title="t", model_id="main-model", connection_id=connection.id ) db.add(chat) db.commit() return chat def _members(db, chat) -> list[str]: db.expire_all() return [ row.model_id for row in sorted(db.get(Chat, chat.id).crowd, key=lambda r: r.position) ] # --- Reachable where somebody would look -------------------------------------- # # The feature shipped in 1.6.0 switched on and unreachable: the only control was # inside the Chat settings panel, behind the ⋯ menu, in a chat that already # existed. The owner enabled it, went looking, and reported that there was nothing # to find. A control nobody can find is a feature nobody has, so these assert the # two places it has to be rather than the one place it was. def test_the_composer_offers_the_crowd_in_a_chat(client, db): """Beside the tool switches, where the comparable decisions are.""" chat = _chat(db) page = client.get(f"/chat/{chat.id}").text assert 'name="crowd_model_ids"' in page assert 'form="crowd-form"' in page assert '