tools/ holds model tools. These three files register none: they send a message to a platform for `hermes send` and for cron delivery, through gateway adapters and gateway config. They move to the gateway package: tools/send_message_tool.py -> gateway/outbound/send.py tools/send_message_senders.py -> gateway/outbound/senders.py tools/send_message_targets.py -> gateway/outbound/targets.py Twelve test files move with them to tests/gateway/outbound/. Every importer changes its import line in place. Nothing stays at the old paths: none of the three names is on the plugin API list, the shipped-release list or the old-updater list. Behaviour is unchanged. The logger name stays tools.send_message_tool in the three files and in the QQ Bot sender that shares it, so the lines stay under `hermes logs --component tools`. The boundary-lint baseline changes 12 keys and no count, because its keys carry the module path of the underscore names five bundled plugins import. The import and docs rewrites were made by scripts/move/rewrite_imports.py and rewrite_docs.py.
57 lines
2.4 KiB
Python
57 lines
2.4 KiB
Python
"""Multiplex invariant: tool-side profile credentials / targets never leak from the default profile.
|
|
|
|
Under ``gateway.multiplex_profiles`` ``os.environ`` holds the DEFAULT profile's ``.env``; a secondary
|
|
profile's turn runs with a secret scope that may not define a var at all. Every reader below must
|
|
then see "unset", never the default profile's value (`agent/secret_scope.py::get_secret` contract).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from agent import secret_scope
|
|
|
|
|
|
@pytest.fixture
|
|
def secondary_scope(monkeypatch):
|
|
"""Multiplex ON with a secondary profile's (empty) secret scope installed."""
|
|
secret_scope.set_multiplex_active(True)
|
|
token = secret_scope.set_secret_scope({})
|
|
try:
|
|
yield
|
|
finally:
|
|
secret_scope.reset_secret_scope(token)
|
|
secret_scope.set_multiplex_active(False)
|
|
|
|
|
|
def test_scoped_tool_credential_gates_ignore_default_profile_environ(monkeypatch, secondary_scope, tmp_path):
|
|
from tools import browser_use_cli, read_extract, tool_backend_helpers
|
|
|
|
monkeypatch.setenv("FIRECRAWL_API_KEY", "fc-default")
|
|
monkeypatch.setenv("MODAL_TOKEN_ID", "id-default")
|
|
monkeypatch.setenv("MODAL_TOKEN_SECRET", "secret-default")
|
|
monkeypatch.setenv("BROWSER_USE_API_KEY", "bu-default")
|
|
monkeypatch.setattr(tool_backend_helpers.Path, "home", lambda: tmp_path) # no ~/.modal.toml
|
|
|
|
enabled, api_key, _ = read_extract._hosted_ocr_config()
|
|
assert (enabled, api_key) == (False, None)
|
|
assert tool_backend_helpers.has_direct_modal_credentials() is False
|
|
assert browser_use_cli.is_legacy_browser_use_cloud_config({"cloud_provider": "browser-use"}) is False
|
|
|
|
|
|
def test_weixin_home_channel_resolves_from_profile_scope_not_environ(monkeypatch, secondary_scope):
|
|
from gateway.outbound import send as send_message_tool
|
|
|
|
class _NoHome:
|
|
def get_home_channel(self, platform):
|
|
return None
|
|
|
|
monkeypatch.setenv("WEIXIN_HOME_CHANNEL", "wx-default-chat")
|
|
chat_id, _thread, err = send_message_tool._home_chat_id(_NoHome(), None, "weixin")
|
|
assert chat_id is None and err
|
|
# The secondary's own .env value is honoured.
|
|
token = secret_scope.set_secret_scope({"WEIXIN_HOME_CHANNEL": "wx-secondary-chat"})
|
|
try:
|
|
assert send_message_tool._home_chat_id(_NoHome(), None, "weixin") == ("wx-secondary-chat", None, None)
|
|
finally:
|
|
secret_scope.reset_secret_scope(token)
|