39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from chat.db.migrate import apply_migrations
|
|
from chat.db.connection import open_db
|
|
from chat.eventlog.log import append_event
|
|
from chat.eventlog.projector import project
|
|
from chat.state.entities import get_bot, list_bots, get_you
|
|
import chat.state.entities # registers handlers
|
|
|
|
|
|
def test_bot_authored_creates_bot_row(tmp_path):
|
|
db = tmp_path / "t.db"
|
|
apply_migrations(db)
|
|
with open_db(db) as conn:
|
|
append_event(conn, kind="bot_authored", payload={
|
|
"id": "bot_a", "name": "BotA",
|
|
"persona": "...", "voice_samples": ["sample"], "traits": ["shy"],
|
|
"backstory": "...",
|
|
"initial_relationship_to_you": "coworker",
|
|
"kickoff_prose": "you stay late",
|
|
})
|
|
project(conn)
|
|
bot = get_bot(conn, "bot_a")
|
|
assert bot is not None
|
|
assert bot["name"] == "BotA"
|
|
assert bot["traits"] == ["shy"]
|
|
assert "bot_a" in [b["id"] for b in list_bots(conn)]
|
|
|
|
|
|
def test_you_authored_creates_you_singleton(tmp_path):
|
|
db = tmp_path / "t.db"
|
|
apply_migrations(db)
|
|
with open_db(db) as conn:
|
|
append_event(conn, kind="you_authored", payload={
|
|
"name": "Me", "pronouns": "they/them", "persona": "engineer",
|
|
})
|
|
project(conn)
|
|
you = get_you(conn)
|
|
assert you is not None
|
|
assert you["name"] == "Me"
|