test(05-01): add restart reconciliation regression coverage
- add startup reconciliation tests for recovery, idempotence, and startup ordering - extend restart persistence coverage for legacy platform_chat_id backfill
This commit is contained in:
parent
9a0316076a
commit
a75b26a1cb
2 changed files with 260 additions and 3 deletions
|
|
@ -1,16 +1,18 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from types import SimpleNamespace
|
||||
|
||||
from core.store import SQLiteStore
|
||||
from adapter.matrix.bot import build_runtime
|
||||
from adapter.matrix.reconciliation import reconcile_startup_state
|
||||
from adapter.matrix.store import (
|
||||
PLATFORM_CHAT_SEQ_KEY,
|
||||
get_room_meta,
|
||||
get_selected_agent_id,
|
||||
next_platform_chat_id,
|
||||
set_room_meta,
|
||||
set_selected_agent_id,
|
||||
)
|
||||
from core.store import SQLiteStore
|
||||
from sdk.mock import MockPlatformClient
|
||||
|
||||
|
||||
async def test_selected_agent_id_survives_restart(tmp_path):
|
||||
|
|
@ -73,3 +75,55 @@ async def test_missing_durable_store_starts_clean(tmp_path):
|
|||
store = SQLiteStore(db)
|
||||
assert await get_selected_agent_id(store, "@nobody:example.org") is None
|
||||
assert await get_room_meta(store, "!nonexistent:example.org") is None
|
||||
|
||||
|
||||
async def test_startup_reconciliation_backfills_legacy_platform_chat_id_before_restart_routes(
|
||||
tmp_path,
|
||||
):
|
||||
db = str(tmp_path / "state.db")
|
||||
store = SQLiteStore(db)
|
||||
await set_room_meta(
|
||||
store,
|
||||
"!chat2:example.org",
|
||||
{
|
||||
"room_type": "chat",
|
||||
"chat_id": "C2",
|
||||
"display_name": "Чат 2",
|
||||
"matrix_user_id": "@alice:example.org",
|
||||
"space_id": "!space:example.org",
|
||||
},
|
||||
)
|
||||
|
||||
runtime = build_runtime(platform=MockPlatformClient(), store=store)
|
||||
client = SimpleNamespace(
|
||||
user_id="@bot:example.org",
|
||||
rooms={
|
||||
"!space:example.org": SimpleNamespace(
|
||||
room_id="!space:example.org",
|
||||
name="Lambda - Alice",
|
||||
display_name="Lambda - Alice",
|
||||
users={
|
||||
"@bot:example.org": SimpleNamespace(user_id="@bot:example.org"),
|
||||
"@alice:example.org": SimpleNamespace(user_id="@alice:example.org"),
|
||||
},
|
||||
space_parents=set(),
|
||||
),
|
||||
"!chat2:example.org": SimpleNamespace(
|
||||
room_id="!chat2:example.org",
|
||||
name="Чат 2",
|
||||
display_name="Чат 2",
|
||||
users={
|
||||
"@bot:example.org": SimpleNamespace(user_id="@bot:example.org"),
|
||||
"@alice:example.org": SimpleNamespace(user_id="@alice:example.org"),
|
||||
},
|
||||
space_parents={"!space:example.org"},
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
await reconcile_startup_state(client, runtime)
|
||||
|
||||
store2 = SQLiteStore(db)
|
||||
room_meta = await get_room_meta(store2, "!chat2:example.org")
|
||||
assert room_meta is not None
|
||||
assert room_meta["platform_chat_id"] == "1"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue