@@ -330,3 +330,47 @@ def test_issue_1441_mixing_user_and_bot_installations(self):
330330 self .assertIsNone (installation )
331331 installation = store .find_installation (enterprise_id = None , team_id = "T111" )
332332 self .assertIsNone (installation )
333+
334+ def test_find_returns_latest_save_within_the_same_second (self ):
335+ store = SQLite3InstallationStore (database = "logs/test.db" , client_id = "111.222" )
336+ store .delete_all (enterprise_id = "E333" , team_id = "T333" )
337+
338+ for suffix in ["old" , "new" ]:
339+ store .save (
340+ Installation (
341+ app_id = "A333" ,
342+ enterprise_id = "E333" ,
343+ team_id = "T333" ,
344+ user_id = "U333" ,
345+ bot_id = "B333" ,
346+ bot_token = f"xoxb-{ suffix } " ,
347+ bot_scopes = ["chat:write" ],
348+ bot_user_id = "U444" ,
349+ user_token = f"xoxp-{ suffix } " ,
350+ )
351+ )
352+ store .save (
353+ Installation (
354+ app_id = "A333" ,
355+ enterprise_id = "E333" ,
356+ team_id = "T333" ,
357+ user_id = "U555" ,
358+ user_token = "xoxp-user-only" ,
359+ )
360+ )
361+ with store .connect () as conn :
362+ for table in ["slack_installations" , "slack_bots" ]:
363+ conn .execute (f"update { table } set installed_at = '2026-11-19 10:00:00' where enterprise_id = 'E333'" )
364+
365+ bot = store .find_bot (enterprise_id = "E333" , team_id = "T333" )
366+ self .assertEqual (bot .bot_token , "xoxb-new" )
367+
368+ installation = store .find_installation (enterprise_id = "E333" , team_id = "T333" )
369+ self .assertEqual (installation .user_token , "xoxp-user-only" )
370+ self .assertEqual (installation .bot_token , "xoxb-new" )
371+
372+ installation = store .find_installation (enterprise_id = "E333" , team_id = "T333" , user_id = "U333" )
373+ self .assertEqual (installation .user_token , "xoxp-new" )
374+ self .assertEqual (installation .bot_token , "xoxb-new" )
375+
376+ store .delete_all (enterprise_id = "E333" , team_id = "T333" )
0 commit comments