smodusermc commited on
Commit
2931047
·
verified ·
1 Parent(s): e4b9b5d

Update tests/test_migration.py

Browse files
Files changed (1) hide show
  1. tests/test_migration.py +20 -2
tests/test_migration.py CHANGED
@@ -173,6 +173,19 @@ for need in ("idx_messages_client_dedupe", "idx_messages_conversation"):
173
  if need not in idx:
174
  failures.append(f"missing index {need}")
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  con.close()
177
 
178
  # ------------------------------------------------------------------
@@ -184,11 +197,16 @@ n2 = con.execute("SELECT COUNT(*) FROM messages").fetchone()[0]
184
  c2 = con.execute("SELECT COUNT(*) FROM conversations").fetchone()[0]
185
  u2 = con.execute("SELECT COUNT(*) FROM users").fetchone()[0]
186
  rc2 = con.execute("SELECT read_at FROM read_receipts WHERE user_id=1 AND message_id=1").fetchone()[0]
 
 
 
187
  con.close()
188
- if n2 != n_msgs or c2 != convs or u2 != n_users:
189
- failures.append(f"second run duplicated/lost data: msgs {n_msgs}->{n2}, convs {convs}->{c2}, users {n_users}->{u2}")
190
  if rc2 != 1700000002000:
191
  failures.append(f"read_at re-multiplied on second run: {rc2}")
 
 
192
 
193
  print("\n==== RESULT ====")
194
  if failures:
 
173
  if need not in idx:
174
  failures.append(f"missing index {need}")
175
 
176
+ # Pending invites must survive a restart (they are not auto-accepted by the
177
+ # migration, which would defeat the invite requirement for DMs/groups).
178
+ con.execute(
179
+ "INSERT INTO conversations (type, title, created_by, is_group) VALUES ('dm', '', 1, 1)"
180
+ )
181
+ gid = con.execute("SELECT last_insert_rowid()").fetchone()[0]
182
+ con.execute(
183
+ "INSERT INTO conversation_members (conversation_id, user_id, joined_at, status, role) "
184
+ "VALUES (?, ?, strftime('%s','now'), 'pending', 'member')",
185
+ (gid, 2)
186
+ )
187
+ con.commit()
188
+ convs_before_second = con.execute("SELECT COUNT(*) FROM conversations").fetchone()[0]
189
  con.close()
190
 
191
  # ------------------------------------------------------------------
 
197
  c2 = con.execute("SELECT COUNT(*) FROM conversations").fetchone()[0]
198
  u2 = con.execute("SELECT COUNT(*) FROM users").fetchone()[0]
199
  rc2 = con.execute("SELECT read_at FROM read_receipts WHERE user_id=1 AND message_id=1").fetchone()[0]
200
+ pend = con.execute(
201
+ "SELECT status FROM conversation_members WHERE conversation_id=? AND user_id=2", (gid,)
202
+ ).fetchone()
203
  con.close()
204
+ if n2 != n_msgs or c2 != convs_before_second or u2 != n_users:
205
+ failures.append(f"second run duplicated/lost data: msgs {n_msgs}->{n2}, convs {convs_before_second}->{c2}, users {n_users}->{u2}")
206
  if rc2 != 1700000002000:
207
  failures.append(f"read_at re-multiplied on second run: {rc2}")
208
+ if not pend or pend[0] != "pending":
209
+ failures.append(f"pending invite was not preserved across restart: {pend}")
210
 
211
  print("\n==== RESULT ====")
212
  if failures: