mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
Firefox reads its host manifests from ~/.mozilla/native-messaging-hosts (Mozilla/NativeMessagingHosts on macOS) and names the extension by its gecko id in allowed_extensions, not an origin. With the extension now asking for nativeMessaging, Firefox joins the router without a pairing code, as Chromium does. hanzo-tools-browser 0.5.14.
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
import json
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
from hanzo_tools.browser import native_host
|
|
|
|
|
|
@pytest.fixture
|
|
def home(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("HOME", str(tmp_path))
|
|
monkeypatch.setattr(sys, "platform", "linux")
|
|
exe = tmp_path / ".local" / "bin" / "hanzo-zap-host"
|
|
exe.parent.mkdir(parents=True)
|
|
exe.write_text("")
|
|
monkeypatch.setattr(native_host, "_executable", lambda: str(exe))
|
|
return tmp_path
|
|
|
|
|
|
def test_every_installed_engine_gets_its_own_manifest(home):
|
|
(home / ".config" / "chromium").mkdir(parents=True)
|
|
(home / ".mozilla").mkdir()
|
|
written = native_host.install()
|
|
chromium = json.loads((home / ".config/chromium/NativeMessagingHosts/ai.hanzo.zap.json").read_text())
|
|
firefox = json.loads((home / ".mozilla/native-messaging-hosts/ai.hanzo.zap.json").read_text())
|
|
assert chromium["allowed_origins"] == ["chrome-extension://biingenefmanpecedoafkfajbnlgdmbl/"]
|
|
assert "allowed_extensions" not in chromium
|
|
assert firefox["allowed_extensions"] == ["[email protected]"]
|
|
assert "allowed_origins" not in firefox
|
|
assert len(written) == 2
|
|
assert native_host.install() == [] # idempotent
|
|
|
|
|
|
def test_an_engine_that_is_not_installed_is_left_alone(home):
|
|
assert native_host.install() == []
|
|
assert not (home / ".mozilla").exists()
|