53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
from pathlib import Path
|
|
|
|
from apa_browser_adapter import (
|
|
REPO_ROOT,
|
|
chrome_debug_port,
|
|
resolve_chrome_profile_base,
|
|
resolve_chrome_profile_dir,
|
|
)
|
|
|
|
|
|
def test_default_chrome_profile_is_outside_repo():
|
|
profile = resolve_chrome_profile_base(requested="")
|
|
assert profile == (REPO_ROOT.parent / "rpa-chrome-profile").resolve()
|
|
assert REPO_ROOT.resolve() not in profile.parents
|
|
assert profile != REPO_ROOT.resolve()
|
|
|
|
|
|
def test_env_path_inside_repo_is_rejected(tmp_path, monkeypatch):
|
|
inside = REPO_ROOT / "rpa_contract" / "screenshots" / "chrome-profile"
|
|
monkeypatch.delenv("RPA_CHROME_PROFILE", raising=False)
|
|
profile = resolve_chrome_profile_base(requested=str(inside))
|
|
assert profile == (REPO_ROOT.parent / "rpa-chrome-profile").resolve()
|
|
assert not _is_relative_to(profile, REPO_ROOT)
|
|
|
|
|
|
def test_env_path_outside_repo_is_kept(tmp_path):
|
|
outside = tmp_path / "custom-chrome"
|
|
outside.mkdir()
|
|
profile = resolve_chrome_profile_base(requested=str(outside))
|
|
assert profile == outside.resolve()
|
|
|
|
|
|
def test_chrome_profile_dir_is_stable_per_flow():
|
|
first = resolve_chrome_profile_dir("CONTRACT_CREATE")
|
|
second = resolve_chrome_profile_dir("CONTRACT_CREATE")
|
|
assert first == second
|
|
assert first == (REPO_ROOT.parent / "rpa-chrome-profile" / "CONTRACT_CREATE").resolve()
|
|
assert not _is_relative_to(first, REPO_ROOT)
|
|
|
|
|
|
def test_chrome_debug_port_is_stable_per_flow(monkeypatch):
|
|
monkeypatch.delenv("RPA_CHROME_DEBUG_PORT", raising=False)
|
|
assert chrome_debug_port("CONTRACT_CREATE") == 9333
|
|
assert chrome_debug_port("CONTRACT_CREATE") == chrome_debug_port("CONTRACT_CREATE")
|
|
|
|
|
|
def _is_relative_to(path: Path, root: Path) -> bool:
|
|
try:
|
|
path.resolve().relative_to(root.resolve())
|
|
except ValueError:
|
|
return False
|
|
return True
|