Endpoint resolution consults remembered remotes, so tests that assert the bare-domain :443 default failed on any machine with an explicit-port remote remembered for the same host, while passing in CI. That made a real behavior difference look like a local-only flake. Isolate the registry for the whole suite instead of patching the two affected tests, since any test touching endpoint resolution has the same hidden dependency. Tests that need remembered entries still override the path. Also replace the hardcoded personal remote host with a documentation domain.
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
"""
|
|
Shared pytest fixtures for browser-cli integration tests.
|
|
|
|
Tests that require a live browser connection use the `browser` fixture and
|
|
target the `testing` browser profile.
|
|
They are automatically skipped if the native host socket is not reachable.
|
|
"""
|
|
import time
|
|
import pytest
|
|
from browser_cli.client import send_command, BrowserNotConnected
|
|
from browser_cli.remote import pool as _remote_pool
|
|
|
|
TEST_BROWSER_PROFILE = "testing"
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _isolate_remote_registry(monkeypatch, tmp_path):
|
|
"""Point the remembered-remote registry at an empty throwaway file.
|
|
|
|
Endpoint resolution consults remembered remotes, so without this a developer
|
|
who has remembered ``host:8765`` sees different results than CI for the same
|
|
code. Tests that need remembered entries still monkeypatch the path themselves.
|
|
"""
|
|
monkeypatch.setattr(
|
|
"browser_cli.remote.registry.REMOTE_REGISTRY_PATH", tmp_path / "empty-remotes.json"
|
|
)
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _clear_remote_pool():
|
|
"""Close any pooled remote connections between tests so a connection opened
|
|
against one test's throwaway server can't leak into the next."""
|
|
yield
|
|
_remote_pool.close_all()
|
|
|
|
@pytest.fixture(scope="session")
|
|
def browser():
|
|
"""Returns a connected send_command callable for the testing profile, or skips the test."""
|
|
try:
|
|
send_command("tabs.list", profile=TEST_BROWSER_PROFILE)
|
|
except (BrowserNotConnected, RuntimeError) as e:
|
|
pytest.skip(
|
|
f"Browser 'testing' not connected — start Brave/Chrome with the extension loaded for that profile ({e})"
|
|
)
|
|
|
|
def _browser(command, args=None):
|
|
return send_command(command, args, profile=TEST_BROWSER_PROFILE)
|
|
|
|
return _browser
|
|
|
|
@pytest.fixture()
|
|
def http_tab(browser):
|
|
"""Opens a dedicated http/https tab for the current test and returns its tab info."""
|
|
created = browser("navigate.open", {"url": "https://example.com", "background": True})
|
|
tab_id = created["id"]
|
|
|
|
tab = None
|
|
try:
|
|
for _ in range(30):
|
|
tabs = browser("tabs.list")
|
|
tab = next((t for t in tabs if t.get("id") == tab_id and t.get("url", "").startswith("http")), None)
|
|
if tab is not None:
|
|
break
|
|
time.sleep(0.1)
|
|
if tab is None:
|
|
pytest.skip("Dedicated http/https test tab did not finish loading")
|
|
yield tab
|
|
finally:
|
|
try:
|
|
browser("tabs.close", {"tabId": tab_id})
|
|
except Exception:
|
|
pass
|