66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
"""matrix-synapse — UPGRADE overlay (Phase 1e HC3): real application-data continuity.
|
|
|
|
ops.pre_upgrade seeds REAL Matrix state before the upgrade: two users, a room, and a message. It
|
|
persists only the test metadata to `/data/ccci-upgrade-state.json` in the Synapse app volume. The
|
|
orchestrator then performs the upgrade once (generic tier asserts reconverge/serving/moved). This
|
|
overlay ADDS: after upgrade, the same Matrix user can still log in and read the pre-upgrade message
|
|
from the same room.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
|
|
from harness import http as harness_http, lifecycle # noqa: E402
|
|
|
|
|
|
UPGRADE_STATE = "/data/ccci-upgrade-state.json"
|
|
|
|
|
|
def _login(domain: str, username: str, password: str) -> str:
|
|
s, body = harness_http.http_post(
|
|
f"https://{domain}/_matrix/client/v3/login",
|
|
data={
|
|
"type": "m.login.password",
|
|
"identifier": {"type": "m.id.user", "user": username},
|
|
"password": password,
|
|
},
|
|
)
|
|
assert s == 200, f"login {username} HTTP {s}: {body!r}"
|
|
token = (body or {}).get("access_token")
|
|
assert isinstance(token, str) and token, f"login returned no access_token: {body!r}"
|
|
return token
|
|
|
|
|
|
def _auth(token: str) -> dict:
|
|
return {"Authorization": f"Bearer {token}"}
|
|
|
|
|
|
def _upgrade_state(domain: str) -> dict:
|
|
raw = lifecycle.exec_in_app(domain, ["cat", UPGRADE_STATE]).strip()
|
|
state = json.loads(raw)
|
|
assert isinstance(state, dict), f"upgrade state is not a dict: {state!r}"
|
|
return state
|
|
|
|
|
|
def test_upgrade_preserves_data(live_app):
|
|
state = _upgrade_state(live_app)
|
|
user_b = state["user_b"]
|
|
password = state["password"]
|
|
room_id = state["room_id"]
|
|
marker = state["marker"]
|
|
|
|
token = _login(live_app, user_b, password)
|
|
s, body = harness_http.http_get(
|
|
f"https://{live_app}/_matrix/client/v3/rooms/{room_id}/messages?dir=b&limit=20",
|
|
headers=_auth(token),
|
|
)
|
|
assert s == 200, f"read messages HTTP {s}: {body!r}"
|
|
chunk = (body or {}).get("chunk", [])
|
|
bodies = [e.get("content", {}).get("body", "") for e in chunk if isinstance(e, dict)]
|
|
assert marker in bodies, (
|
|
f"post-upgrade user {user_b!r} did not see pre-upgrade marker {marker!r}; "
|
|
f"room={room_id!r} messages={bodies[:10]}"
|
|
)
|