cmux/tests/regression_helpers.py
Lawrence Chen e49e572505
Fix browser Cmd+F overlay clipping in portal mode (#916)
* Fix browser Cmd+F overlay clipping in portal mode

* Fix browser Cmd+F panel update regression

* Fix browser find overlay lifecycle and focus

* Extract regression test helpers for browser find guards

* Restore new-tab Cmd+F overlay and harden test helper

* Fix browser Cmd+F focus handoff race

* Fix browser Cmd+F focus loss across page load

* Address review feedback on browser find focus guards

* Add Cmd+F pane-switch regression UI tests

* Run Cmd+F pane-switch regressions from existing UI suite

* Restore browser find focus on pane refocus

* Stabilize Cmd+F pane-switch regressions with focus-state recorder

* Make autofocus race UI test wait on deterministic page signal

* Fix cmuxTests WebViewRepresentable init after browser search state param
2026-03-05 15:36:47 -08:00

51 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Shared helpers for static regression tests."""
from __future__ import annotations
import shutil
import subprocess
from pathlib import Path
def repo_root() -> Path:
git = shutil.which("git")
if git is None:
return Path(__file__).resolve().parents[1]
try:
result = subprocess.run(
[git, "rev-parse", "--show-toplevel"],
capture_output=True,
text=True,
check=False,
timeout=2,
)
except (subprocess.TimeoutExpired, OSError):
return Path(__file__).resolve().parents[1]
if result.returncode == 0:
return Path(result.stdout.strip())
return Path(__file__).resolve().parents[1]
def extract_block(source: str, signature: str) -> str:
# Targeted helper for this regression suite: assumes braces in the matched
# block are structural (not inside strings/comments/character literals).
start = source.find(signature)
if start < 0:
raise ValueError(f"Missing signature: {signature}")
brace_start = source.find("{", start)
if brace_start < 0:
raise ValueError(f"Missing opening brace for: {signature}")
depth = 0
for idx in range(brace_start, len(source)):
char = source[idx]
if char == "{":
depth += 1
elif char == "}":
depth -= 1
if depth == 0:
return source[brace_start : idx + 1]
raise ValueError(f"Unbalanced braces for: {signature}")