* fetch: look for a newer intermediates list (update_intermediates) instead of only caching one Needs invisible-core with update_intermediates (the core release after 67.77.0). * launch: the UDP verdict travels in the prefs to the server; the core keeps none The core no longer remembers the UDP verdict of a proxy, so the launch's geo step hands it to the server in the prefs (invisible.server.udp_exit, taken out before the profile is written, never what a caller wrote) and op_launch gives it to launch_proxy_command. Every entry point keeps SessionGeo.udp_exit on its session. Tests that read the core's cache for the verdict now read it where it is written: the one function that renders the engine's proxy command is spied by conftest (tests/_udp_line.py). The tests that reset the core's cached seal drop the reset (the core reads the seal on every call). * Release 0.57.0: pins invisible-core 67.78.0 (no cache in memory in the core; fetch checks the intermediates list), same engine firefox-67 * launch: the UDP verdict is passed to launch_proxy_command by name (keyword-only in the core 67.78.0) * CHANGELOG 0.57.0: networkidle of a new document counts its quiet from the commit (core 67.78.0)
79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
"""A launch that fails before the browser starts must still stop the display.
|
|
|
|
`headless=True` starts the hidden surface - an Xvfb process on Linux, a Win32
|
|
desktop handle on Windows - inside `_resolve_headless`, and only `_teardown`
|
|
stops it. Composing the prefs, the proxy and the environment comes after that
|
|
and can raise (`build_env` refuses a font manifest the engine does not carry),
|
|
so it has to sit inside the `try` whose handler calls `_teardown`, or every
|
|
such failure leaves one display behind in the caller's process.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import types
|
|
|
|
import pytest
|
|
from invisible_core import SessionLocale
|
|
from invisible_core.launch import FontManifestMismatch
|
|
|
|
from invisible_playwright import _session, async_api, launcher
|
|
|
|
|
|
class RecordingDisplay:
|
|
def __init__(self) -> None:
|
|
self.started = 0
|
|
self.stopped = 0
|
|
|
|
def start(self) -> None:
|
|
self.started += 1
|
|
|
|
def stop(self) -> None:
|
|
self.stopped += 1
|
|
|
|
def launch_env(self):
|
|
return {}
|
|
|
|
|
|
@pytest.fixture
|
|
def display(monkeypatch):
|
|
vd = RecordingDisplay()
|
|
geo = types.SimpleNamespace(timezone="Europe/Rome",
|
|
locale=SessionLocale.of("it-IT"),
|
|
egress_ip=None, udp_exit=None,
|
|
geolocation_override=lambda: None)
|
|
|
|
def refuse(**_kw):
|
|
raise FontManifestMismatch("the engine does not carry these faces")
|
|
|
|
def no_playwright():
|
|
raise AssertionError("the launch must fail before Playwright starts")
|
|
|
|
monkeypatch.delenv(_session.TRUE_HEADLESS_ENV, raising=False)
|
|
monkeypatch.setattr(_session, "make_virtual_display", lambda: vd)
|
|
monkeypatch.setattr(_session, "resolve_executable", lambda _p: "firefox")
|
|
monkeypatch.setattr(_session, "build_env", refuse)
|
|
for mod in (launcher, async_api):
|
|
monkeypatch.setattr(mod, "prepare_session_geo", lambda *_a, **_k: geo)
|
|
monkeypatch.setattr(mod, "resolve_executable", lambda _p: "firefox")
|
|
monkeypatch.setattr(launcher, "sync_playwright", no_playwright)
|
|
monkeypatch.setattr(async_api, "async_playwright", no_playwright)
|
|
return vd
|
|
|
|
|
|
def test_the_sync_launch_stops_the_display_it_started(display):
|
|
session = launcher.InvisiblePlaywright(seed=7, headless=True)
|
|
with pytest.raises(FontManifestMismatch):
|
|
session.__enter__()
|
|
assert display.started == 1
|
|
assert display.stopped == 1, "the hidden display outlived a failed launch"
|
|
assert session._virtual_display is None
|
|
|
|
|
|
def test_the_async_launch_stops_the_display_it_started(display):
|
|
session = async_api.InvisiblePlaywright(seed=7, headless=True)
|
|
with pytest.raises(FontManifestMismatch):
|
|
asyncio.run(session.__aenter__())
|
|
assert display.started == 1
|
|
assert display.stopped == 1, "the hidden display outlived a failed launch"
|
|
assert session._virtual_display is None
|