sidechat_manager: Use data-testid for sidebar button\n\nReliable selector hatch-chat-switcher-trigger instead of\nflaky text matching.

This commit is contained in:
operator-main
2026-10-04 03:20:42 +00:00
parent c57a05963a
commit 4524907663
+11 -7
View File
@@ -31,6 +31,8 @@ def ensure_sidebar(ws, max_retries=3):
""" """
Ensure the sidebar is open. Returns True if open, False otherwise. Ensure the sidebar is open. Returns True if open, False otherwise.
Retries with backoff if the open button isn't found immediately. Retries with backoff if the open button isn't found immediately.
Uses data-testid="hatch-chat-switcher-trigger" (reliable selector).
Fixed 2026-10-04: was using text matching which was flaky.
""" """
for attempt in range(max_retries): for attempt in range(max_retries):
# Check if sidebar is already open (Side chats text visible) # Check if sidebar is already open (Side chats text visible)
@@ -40,13 +42,15 @@ def ensure_sidebar(ws, max_retries=3):
if is_open: if is_open:
return True return True
# Try to open it # Try to open it via data-testid (reliable)
_ev(ws, """(() => { clicked = _ev(ws, """(() => {
const btn = [...document.querySelectorAll('button')].find(b => const btn = document.querySelector('[data-testid="hatch-chat-switcher-trigger"]');
(b.textContent||'').includes('Open chat and side chats') if (btn) { btn.click(); return true; }
); // Fallback: text matching
if (btn) btn.click(); const fb = [...document.querySelectorAll('button')].find(b =>
return !!btn; (b.textContent||'').includes('Open chat and side chats'));
if (fb) { fb.click(); return true; }
return false;
})()""") })()""")
time.sleep(2 * (attempt + 1)) # Exponential backoff: 2s, 4s, 6s time.sleep(2 * (attempt + 1)) # Exponential backoff: 2s, 4s, 6s