diff --git a/tests/test_issue4766_sidebar_source_pushdown.py b/tests/test_issue4766_sidebar_source_pushdown.py index f804c464..a72087c6 100644 --- a/tests/test_issue4766_sidebar_source_pushdown.py +++ b/tests/test_issue4766_sidebar_source_pushdown.py @@ -101,6 +101,16 @@ def _extract_function(source_text, function_name): raise AssertionError(f"Could not extract {function_name}") +def _ensure_async(function_source, function_name): + if function_source.startswith("async function "): + return function_source + return function_source.replace( + f"function {function_name}", + f"async function {function_name}", + 1, + ) + + def _run_node(script): proc = subprocess.run([NODE, "-e", script], capture_output=True, text=True, check=True) return json.loads(proc.stdout) @@ -529,15 +539,13 @@ def test_scope_mismatch_error_path_respects_sidebar_source(): requested_source_fn = _extract_function(src, "_requestedSessionSidebarSource") exclude_hidden_fn = _extract_function(src, "_sessionListExcludeHiddenEnabled") query_fn = _extract_function(src, "_sessionListQueryString") - fetch_helper_fn = _extract_function(src, "_loadSidebarSessionListPayload").replace( - "function _loadSidebarSessionListPayload", - "async function _loadSidebarSessionListPayload", - 1, + fetch_helper_fn = _ensure_async( + _extract_function(src, "_loadSidebarSessionListPayload"), + "_loadSidebarSessionListPayload", ) - refresh_fn = _extract_function(src, "_runRenderSessionListRefresh").replace( - "function _runRenderSessionListRefresh", - "async function _runRenderSessionListRefresh", - 1, + refresh_fn = _ensure_async( + _extract_function(src, "_runRenderSessionListRefresh"), + "_runRenderSessionListRefresh", ) script = f""" global.window = {{ _showCliSessions: true }};