---
name: realtime-apps-qa
description: >-
  Playbook for testing realtime, multi-user, and multi-account web systems (tournaments, live quiz rooms, duels, matchmaking, and leaderboards like Med Royale). Simulates concurrent users, tests race conditions, verifies DB against UI state, and forces edge-case failure modes.
---

# ⚡ Realtime & Multi-Account Systems QA Playbook

Used for every feature that has two or more users acting on shared state at the same time (e.g., Med Royale, live tournaments, duel rooms).

---

## 📌 Core Rules & Setup

1. **Minimum 2–4 Concurrent Accounts:**
   - 2 accounts for simple duels / rooms.
   - 3–4 accounts for tournaments (to test brackets, byes, and elimination).
2. **Two Browser Profiles / Incognito:**
   - Open side-by-side to avoid cookie/auth bleed.
3. **Repeat ≥ 3 Times:**
   - Flaky RTDB/Firestore writes and transition glitches only appear on repetition.
4. **Assert Against Database:**
   - Never trust the screen alone. Query Firestore/RTDB directly after each action.
5. **Break It On Purpose:**
   - Tab away, refresh mid-phase, kill network connection, double-click rapidly.

---

## 🛡️ Failure Modes Matrix

| Scenario | Expected Behavior |
| :--- | :--- |
| **Player tab killed mid-FFA** | Room completes anyway; remaining players receive scores without hanging. |
| **Host closes page mid-round** | Phase transitions continue automatically via server-driven timers. |
| **Player joins after registration closes** | Immediate clean rejection message; no half-registered state. |
| **Rapid double-click on join/answer** | Exactly one write is processed (Idempotent). |
| **Wrong/missing answer** | Scored 0 without crash; leaderboard still computes accurately. |
| **Client vs Server winner race** | Server result wins exclusively (Server Authority). |
| **Page refresh mid-duel** | Player immediately reconnects to same active duel with preserved score. |

---

## 📋 Execution Checklist

```text
[ ] 1. In a staging/emulator environment, clean only the test state you created in Firestore / RTDB (never delete others' data or write to production without Sohail's explicit approval).
[ ] 2. Join Flow — All accounts register and join in correct order.
[ ] 3. Phase 1 (FFA) — All accounts submit answers; verify scores in DB.
[ ] 4. Transition — All players land on countdown/wait screen simultaneously.
[ ] 5. Phase 2 (Brackets) — Matchups generated correctly; byes handled cleanly.
[ ] 6. Duels — Both players see synchronized questions; results match on both screens.
[ ] 7. Finals — Champion displayed; eliminated players see clear elimination screen.
[ ] 8. Final DB Audit — Full dump of room document matches final UI state 100%.
```
