From 7f3b12107be38f1c2bab3d526135068ff24ef8e4 Mon Sep 17 00:00:00 2001 From: Serge L Date: Sun, 5 Apr 2026 02:54:25 -0400 Subject: [PATCH] fix: resolve flaky chats system test race condition (#1375) Wait for the chat to fully load after click before triggering a page refresh, ensuring last_viewed_chat is persisted server-side. Co-authored-by: Claude Opus 4.6 --- test/system/chats_test.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/system/chats_test.rb b/test/system/chats_test.rb index ff4a42f98..379621107 100644 --- a/test/system/chats_test.rb +++ b/test/system/chats_test.rb @@ -32,17 +32,23 @@ class ChatsTest < ApplicationSystemTestCase test "sidebar shows last viewed chat" do with_env_overrides OPENAI_ACCESS_TOKEN: "test-token" do @user.update!(ai_enabled: true) + chat_title = @user.chats.first.title visit root_url - click_on @user.chats.first.title + click_on chat_title + + # Wait for the chat to actually load before refreshing + within "#chat-container" do + assert_selector "h1", text: chat_title + end # Page refresh visit root_url # After page refresh, we're still on the last chat we were viewing within "#chat-container" do - assert_selector "h1", text: @user.chats.first.title + assert_selector "h1", text: chat_title end end end