From 4921b269450b9c1648057559224d465fb1c58d62 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sun, 26 Apr 2026 12:55:58 -0700 Subject: [PATCH] fix(cron): keep homeassistant toolset enabled when HASS_TOKEN is set (#16208) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After #14798 made cron honor per-platform `hermes tools` config, the `_DEFAULT_OFF_TOOLSETS` filter silently stripped `homeassistant` from cron jobs for users who'd been relying on the previous blanket toolset. Norbert's HA cron reports regressed as a result. The HA toolset is already runtime-gated by its `check_fn` (requires HASS_TOKEN to register any tools). When HASS_TOKEN is set the user has explicitly opted in — `_DEFAULT_OFF_TOOLSETS` adds nothing in that case, so stop double-gating and restore HA for cron / cli / other platforms without an explicit saved toolset list. moa and rl stay off by default (original #14798 goal preserved). Fixes HA cron regression reported by Norbert. --- hermes_cli/tools_config.py | 10 +++++++++ tests/hermes_cli/test_tools_config.py | 30 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) 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": []}}