diff --git a/hermes_cli/tools_config.py b/hermes_cli/tools_config.py index e957e4ccf6..f2d1aab584 100644 --- a/hermes_cli/tools_config.py +++ b/hermes_cli/tools_config.py @@ -11,6 +11,7 @@ the `platform_toolsets` key. import json as _json import logging +import os import sys from pathlib import Path from typing import Dict, List, Optional, Set @@ -676,6 +677,15 @@ def _get_platform_tools( # their own platform (e.g. `discord` + `discord` should stay OFF). if platform in default_off and platform not in _TOOLSET_PLATFORM_RESTRICTIONS: default_off.remove(platform) + # Home Assistant is already runtime-gated by its check_fn (requires + # HASS_TOKEN to register any tools). When a user has configured + # HASS_TOKEN, they've explicitly opted in — don't also strip it via + # _DEFAULT_OFF_TOOLSETS, which would silently drop HA from platforms + # (e.g. cron) that run through _get_platform_tools without an + # explicit saved toolset list. Without this, Norbert's HA cron jobs + # regressed after #14798 made cron honor per-platform tool config. + if "homeassistant" in default_off and os.getenv("HASS_TOKEN"): + default_off.remove("homeassistant") enabled_toolsets -= default_off # Recover non-configurable platform toolsets (e.g. discord, feishu_doc, diff --git a/tests/hermes_cli/test_tools_config.py b/tests/hermes_cli/test_tools_config.py index 9f91a0baf9..6f5bc644a5 100644 --- a/tests/hermes_cli/test_tools_config.py +++ b/tests/hermes_cli/test_tools_config.py @@ -41,6 +41,36 @@ def test_get_platform_tools_homeassistant_platform_keeps_homeassistant_toolset() assert "homeassistant" in enabled +def test_get_platform_tools_homeassistant_toolset_enabled_for_cron_when_hass_token_set(monkeypatch): + """HA toolset is runtime-gated by check_fn (requires HASS_TOKEN). + + When HASS_TOKEN is set, the user has explicitly opted in — _DEFAULT_OFF_TOOLSETS + shouldn't also strip HA from platforms (like cron) that run through + _get_platform_tools without an explicit saved toolset list. + + Regression guard for Norbert's HA cron breakage after #14798 made cron + honor per-platform tool config. + """ + monkeypatch.setenv("HASS_TOKEN", "fake-test-token") + + cron_enabled = _get_platform_tools({}, "cron") + assert "homeassistant" in cron_enabled + # moa must stay off — the original goal of #14798 + assert "moa" not in cron_enabled + + cli_enabled = _get_platform_tools({}, "cli") + assert "homeassistant" in cli_enabled + + +def test_get_platform_tools_homeassistant_toolset_off_for_cron_when_hass_token_missing(monkeypatch): + """Without HASS_TOKEN, HA stays off by default — preserves #14798's behavior + for users who never configured HA.""" + monkeypatch.delenv("HASS_TOKEN", raising=False) + + cron_enabled = _get_platform_tools({}, "cron") + assert "homeassistant" not in cron_enabled + + def test_get_platform_tools_preserves_explicit_empty_selection(): config = {"platform_toolsets": {"cli": []}}