mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
"""DB seed coverage — channel/agent/membership/messages bootstrap."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
import pytest
|
|
from roboco.db.seed import (
|
|
create_agents,
|
|
create_channel_memberships,
|
|
create_channels,
|
|
create_initial_messages,
|
|
)
|
|
|
|
if TYPE_CHECKING:
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_channels_seeds_defaults(
|
|
db_session: AsyncSession,
|
|
) -> None:
|
|
channel_ids = await create_channels(db_session)
|
|
assert "backend-cell" in channel_ids
|
|
assert "frontend-cell" in channel_ids
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_channels_idempotent(db_session: AsyncSession) -> None:
|
|
"""Running twice doesn't create duplicates."""
|
|
first = await create_channels(db_session)
|
|
second = await create_channels(db_session)
|
|
# Same slugs, same IDs.
|
|
for slug, ch_id in first.items():
|
|
assert second[slug] == ch_id
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_agents_seeds_defaults(db_session: AsyncSession) -> None:
|
|
agent_ids = await create_agents(db_session)
|
|
assert len(agent_ids) > 0
|
|
# Agents include be-dev-1, be-qa, etc.
|
|
assert any("be-" in slug or "fe-" in slug for slug in agent_ids)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_agents_idempotent(db_session: AsyncSession) -> None:
|
|
first = await create_agents(db_session)
|
|
second = await create_agents(db_session)
|
|
for slug, aid in first.items():
|
|
assert second[slug] == aid
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_channel_memberships(db_session: AsyncSession) -> None:
|
|
channel_ids = await create_channels(db_session)
|
|
agent_ids = await create_agents(db_session)
|
|
# Should not raise.
|
|
await create_channel_memberships(db_session, channel_ids, agent_ids)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_initial_messages(db_session: AsyncSession) -> None:
|
|
"""Initial-message seeding wraps multiple ops; smoke-test it doesn't raise."""
|
|
channel_ids = await create_channels(db_session)
|
|
agent_ids = await create_agents(db_session)
|
|
await create_channel_memberships(db_session, channel_ids, agent_ids)
|
|
# Initial messages may or may not be seeded depending on config — just
|
|
# confirm the call doesn't raise.
|
|
try:
|
|
await create_initial_messages(db_session, channel_ids, agent_ids)
|
|
except Exception: # noqa: BLE001
|
|
# Some setups may not have everything wired; accept silent skip.
|
|
pass
|