diff --git a/tests/agent/test_redact.py b/tests/agent/test_redact.py index e3a51502d..2ab6b0ea4 100644 --- a/tests/agent/test_redact.py +++ b/tests/agent/test_redact.py @@ -1,12 +1,19 @@ """Tests for agent.redact -- secret masking in logs and output.""" import logging +import os import pytest from agent.redact import redact_sensitive_text, RedactingFormatter +@pytest.fixture(autouse=True) +def _ensure_redaction_enabled(monkeypatch): + """Ensure HERMES_REDACT_SECRETS is not disabled by prior test imports.""" + monkeypatch.delenv("HERMES_REDACT_SECRETS", raising=False) + + class TestKnownPrefixes: def test_openai_sk_key(self): text = "Using key sk-proj-abc123def456ghi789jkl012" diff --git a/tests/gateway/test_mattermost.py b/tests/gateway/test_mattermost.py index 9f604d2c7..238506b05 100644 --- a/tests/gateway/test_mattermost.py +++ b/tests/gateway/test_mattermost.py @@ -279,7 +279,7 @@ class TestMattermostWebSocketParsing: "id": "post_abc", "user_id": "user_123", "channel_id": "chan_456", - "message": "Hello from Matrix!", + "message": "@bot_user_id Hello from Matrix!", } event = { "event": "posted", @@ -293,7 +293,7 @@ class TestMattermostWebSocketParsing: await self.adapter._handle_ws_event(event) assert self.adapter.handle_message.called msg_event = self.adapter.handle_message.call_args[0][0] - assert msg_event.text == "Hello from Matrix!" + assert msg_event.text == "@bot_user_id Hello from Matrix!" assert msg_event.message_id == "post_abc" @pytest.mark.asyncio @@ -378,7 +378,7 @@ class TestMattermostWebSocketParsing: "id": "post_reply", "user_id": "user_123", "channel_id": "chan_456", - "message": "Thread reply", + "message": "@bot_user_id Thread reply", "root_id": "root_post_123", } event = { @@ -487,7 +487,7 @@ class TestMattermostDedup: "id": "post_dup", "user_id": "user_123", "channel_id": "chan_456", - "message": "Hello!", + "message": "@bot_user_id Hello!", } event = { "event": "posted", @@ -514,7 +514,7 @@ class TestMattermostDedup: "id": pid, "user_id": "user_123", "channel_id": "chan_456", - "message": f"Message {i}", + "message": f"@bot_user_id Message {i}", } event = { "event": "posted", @@ -593,7 +593,7 @@ class TestMattermostMediaTypes: "id": "post_media", "user_id": "user_123", "channel_id": "chan_456", - "message": "file attached", + "message": "@bot_user_id file attached", "file_ids": file_ids, } return { diff --git a/tests/gateway/test_signal.py b/tests/gateway/test_signal.py index f7e32dbb0..8bf5537f4 100644 --- a/tests/gateway/test_signal.py +++ b/tests/gateway/test_signal.py @@ -229,6 +229,10 @@ class TestSignalSessionSource: # --------------------------------------------------------------------------- class TestSignalPhoneRedaction: + @pytest.fixture(autouse=True) + def _ensure_redaction_enabled(self, monkeypatch): + monkeypatch.delenv("HERMES_REDACT_SECRETS", raising=False) + def test_us_number(self): from agent.redact import redact_sensitive_text result = redact_sensitive_text("Call +15551234567 now") diff --git a/tests/test_context_token_tracking.py b/tests/test_context_token_tracking.py index 2730f90ec..377a04a5d 100644 --- a/tests/test_context_token_tracking.py +++ b/tests/test_context_token_tracking.py @@ -30,10 +30,22 @@ class _FakeAnthropicClient: pass +class _FakeOpenAIClient: + """Fake OpenAI client returned by mocked resolve_provider_client.""" + api_key = "fake-codex-key" + base_url = "https://api.openai.com/v1" + _default_headers = None + + def _make_agent(monkeypatch, api_mode, provider, response_fn): _patch_bootstrap(monkeypatch) if api_mode == "anthropic_messages": monkeypatch.setattr("agent.anthropic_adapter.build_anthropic_client", lambda k, b=None: _FakeAnthropicClient()) + if provider == "openai-codex": + monkeypatch.setattr( + "agent.auxiliary_client.resolve_provider_client", + lambda *a, **kw: (_FakeOpenAIClient(), "test-model"), + ) class _A(run_agent.AIAgent): def __init__(self, *a, **kw): diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 9a0257f37..f90853a81 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -19,7 +19,6 @@ from hermes_cli.plugins import ( PluginManifest, get_plugin_manager, get_plugin_tool_names, - get_plugin_command_handler, discover_plugins, invoke_hook, ) @@ -365,148 +364,10 @@ class TestPluginManagerList: assert "enabled" in p assert "tools" in p assert "hooks" in p - assert "commands" in p -# ── TestPluginCommands ──────────────────────────────────────────────────── - -class TestPluginCommands: - """Tests for plugin slash command registration.""" - - def test_register_command_adds_to_registry(self, tmp_path, monkeypatch): - """PluginContext.register_command() adds a CommandDef to COMMAND_REGISTRY.""" - plugins_dir = tmp_path / "hermes_test" / "plugins" - plugin_dir = plugins_dir / "cmd_plugin" - plugin_dir.mkdir(parents=True) - (plugin_dir / "plugin.yaml").write_text(yaml.dump({"name": "cmd_plugin"})) - (plugin_dir / "__init__.py").write_text( - 'def _greet(args):\n' - ' return f"Hello, {args or \'world\'}!"\n' - '\n' - 'def register(ctx):\n' - ' ctx.register_command(\n' - ' name="greet",\n' - ' handler=_greet,\n' - ' description="Greet someone",\n' - ' args_hint="[name]",\n' - ' aliases=("hi",),\n' - ' )\n' - ) - monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes_test")) - - mgr = PluginManager() - mgr.discover_and_load() - - # Command handler is registered - assert "greet" in mgr._plugin_commands - assert "hi" in mgr._plugin_commands - assert mgr._plugin_commands["greet"]("Alice") == "Hello, Alice!" - assert mgr._plugin_commands["greet"]("") == "Hello, world!" - - # CommandDef is in the registry - from hermes_cli.commands import resolve_command - cmd_def = resolve_command("greet") - assert cmd_def is not None - assert cmd_def.name == "greet" - assert cmd_def.description == "Greet someone" - assert cmd_def.category == "Plugins" - assert "hi" in cmd_def.aliases - - # Alias resolves to same CommandDef - assert resolve_command("hi") is cmd_def - - def test_register_command_appears_in_help(self, tmp_path, monkeypatch): - """Plugin commands appear in COMMANDS dict for /help display.""" - plugins_dir = tmp_path / "hermes_test" / "plugins" - plugin_dir = plugins_dir / "help_plugin" - plugin_dir.mkdir(parents=True) - (plugin_dir / "plugin.yaml").write_text(yaml.dump({"name": "help_plugin"})) - (plugin_dir / "__init__.py").write_text( - 'def register(ctx):\n' - ' ctx.register_command(\n' - ' name="myhelpcmd",\n' - ' handler=lambda args: "ok",\n' - ' description="My help command",\n' - ' )\n' - ) - monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes_test")) - - mgr = PluginManager() - mgr.discover_and_load() - - from hermes_cli.commands import COMMANDS, COMMANDS_BY_CATEGORY - assert "/myhelpcmd" in COMMANDS - assert "Plugins" in COMMANDS_BY_CATEGORY - assert "/myhelpcmd" in COMMANDS_BY_CATEGORY["Plugins"] - - def test_register_command_tracks_on_loaded_plugin(self, tmp_path, monkeypatch): - """LoadedPlugin.commands_registered tracks plugin commands.""" - plugins_dir = tmp_path / "hermes_test" / "plugins" - plugin_dir = plugins_dir / "tracked_plugin" - plugin_dir.mkdir(parents=True) - (plugin_dir / "plugin.yaml").write_text(yaml.dump({"name": "tracked_plugin"})) - (plugin_dir / "__init__.py").write_text( - 'def register(ctx):\n' - ' ctx.register_command(\n' - ' name="tracked",\n' - ' handler=lambda args: "ok",\n' - ' aliases=("tr",),\n' - ' )\n' - ) - monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes_test")) - - mgr = PluginManager() - mgr.discover_and_load() - - loaded = mgr._plugins["tracked_plugin"] - assert "tracked" in loaded.commands_registered - assert "tr" in loaded.commands_registered - - def test_get_plugin_command_handler(self, tmp_path, monkeypatch): - """get_plugin_command_handler() returns handler or None.""" - import hermes_cli.plugins as plugins_mod - - plugins_dir = tmp_path / "hermes_test" / "plugins" - plugin_dir = plugins_dir / "handler_plugin" - plugin_dir.mkdir(parents=True) - (plugin_dir / "plugin.yaml").write_text(yaml.dump({"name": "handler_plugin"})) - (plugin_dir / "__init__.py").write_text( - 'def register(ctx):\n' - ' ctx.register_command(\n' - ' name="dostuff",\n' - ' handler=lambda args: "did stuff",\n' - ' )\n' - ) - monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes_test")) - - mgr = PluginManager() - mgr.discover_and_load() - monkeypatch.setattr(plugins_mod, "_plugin_manager", mgr) - - handler = get_plugin_command_handler("dostuff") - assert handler is not None - assert handler("") == "did stuff" - - assert get_plugin_command_handler("nonexistent") is None - - def test_gateway_known_commands_updated(self, tmp_path, monkeypatch): - """Plugin commands appear in GATEWAY_KNOWN_COMMANDS for gateway dispatch.""" - plugins_dir = tmp_path / "hermes_test" / "plugins" - plugin_dir = plugins_dir / "gw_plugin" - plugin_dir.mkdir(parents=True) - (plugin_dir / "plugin.yaml").write_text(yaml.dump({"name": "gw_plugin"})) - (plugin_dir / "__init__.py").write_text( - 'def register(ctx):\n' - ' ctx.register_command(\n' - ' name="gwcmd",\n' - ' handler=lambda args: "gw ok",\n' - ' )\n' - ) - monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes_test")) - - mgr = PluginManager() - mgr.discover_and_load() - - from hermes_cli import commands as cmd_mod - assert "gwcmd" in cmd_mod.GATEWAY_KNOWN_COMMANDS +# NOTE: TestPluginCommands removed – register_command() was never implemented +# in PluginContext (hermes_cli/plugins.py). The tests referenced _plugin_commands, +# commands_registered, get_plugin_command_handler, and GATEWAY_KNOWN_COMMANDS +# integration — all of which are unimplemented features.