mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
fix(cron): keep homeassistant toolset enabled when HASS_TOKEN is set (#16208)
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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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": []}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user