tools/ holds model tools. These 15 files register none: they launch and
track Chromium, hold the per-task browser sessions and run the CDP
supervisor the browser tools call. They move to a new root package:
tools/browser_session*.py -> browser/session*.py
tools/browser_launcher{,_holders} -> browser/launcher{,_holders}.py
tools/browser_lightpanda.py -> browser/lightpanda.py
tools/browser_supervisor*.py -> browser/supervisor*.py
tools/browser_real_profile_logins -> browser/real_profile_logins.py
tools/bot_desktop/browser.py -> browser/desktop_profile.py
browser/__init__.py is a docstring only. tools/browser_tool.py and every
tool file stay. 38 tests and one helper move to tests/browser/; its
conftest.py imports the autouse fixtures of tests/tools/conftest.py they
ran under.
Old-path files, each a MOVES key, a REQUIRED_NAMES row and a file
written by scripts/move/generate_shims.py:
- tools.browser_supervisor and tools.browser_supervisor_capture are on
the published plugin API (hermes_cli/data/plugin_api.json), so a
plugin's import gives the same module object.
- tools.browser_session and tools.browser_session_cloud are imported
inside functions on every turn by a process started on v0.22.7 to
v0.23.5 (the per-turn browser cleanup), which keeps running its old
code after an update swaps the checkout.
Function bodies are unchanged and every import stays where it was.
Loggers follow their modules: every moved file keeps
getLogger(__name__), and the two literal supervisor loggers name
browser.supervisor. browser joins the tools entry of
hermes_logging.COMPONENT_PREFIXES, so `hermes logs --component tools`
shows the same lines. browser also joins packages.find,
FIRST_PARTY_MODULE_ROOTS, _KNOWN_LOGGER_ROOTS, the plugin isolation
audit, six check scripts, the P33 profile-scope pattern, the gateway's
stop-path preload list and the test fixtures that list root packages.
The import and docs rewrites were made by scripts/move/rewrite_imports.py
and rewrite_docs.py; split imports, imports inside child-process code
strings, boundary-lint baseline keys, two resolution-allowlist rows and
docs globs were fixed by hand.
Pinned catalog plugins import these moved modules by the old name, so each has a key in
hermes_agent/compat/moves.py and the plugin guide lists it with the release
that may remove it (no earlier than v0.27.0):
tools.browser_session_cdp
tools.browser_session_lifecycle
45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
"""Tests for the Chromium first-launch timeout floor and the sandbox-bypass host probe."""
|
|
|
|
import pytest
|
|
|
|
from browser import launcher as browser_launcher, session_cloud as browser_session_cloud
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _fresh_cache():
|
|
browser_session_cloud.reset_caches()
|
|
yield
|
|
browser_session_cloud.reset_caches()
|
|
|
|
|
|
class TestOpenCommandTimeout:
|
|
def test_first_open_uses_longer_floor(self, monkeypatch):
|
|
monkeypatch.setattr(browser_session_cloud, "command_timeout", lambda: 30)
|
|
assert browser_launcher._launch_timeout(None) == browser_launcher._MIN_FIRST_LAUNCH_TIMEOUT_S
|
|
|
|
def test_respects_config_above_floor(self, monkeypatch):
|
|
monkeypatch.setattr(browser_session_cloud, "command_timeout", lambda: 180)
|
|
assert browser_launcher._launch_timeout(None) == 180
|
|
|
|
|
|
class TestSandboxBypass:
|
|
|
|
def test_apparmor_userns_triggers_bypass(self, monkeypatch, tmp_path):
|
|
monkeypatch.setattr(browser_launcher, "running_in_docker", lambda: False)
|
|
# Non-root, so only the AppArmor sysctl can answer True.
|
|
monkeypatch.setattr(browser_launcher.os, "geteuid", lambda: 1000, raising=False)
|
|
sysctl = tmp_path / "apparmor_restrict_unprivileged_userns"
|
|
sysctl.write_text("1\n", encoding="utf-8")
|
|
|
|
import builtins
|
|
|
|
real_open = builtins.open
|
|
|
|
def _open(path, *args, **kwargs):
|
|
if "apparmor_restrict_unprivileged_userns" in str(path):
|
|
return real_open(sysctl, *args, **kwargs)
|
|
return real_open(path, *args, **kwargs)
|
|
|
|
monkeypatch.setattr(builtins, "open", _open)
|
|
assert browser_launcher.needs_chromium_sandbox_bypass() is True
|