Skip to content

Commit 3e96694

Browse files
committed
fix(tests): adopt master beta gate + new advanced handler keys (homeassistant-ai#1164)
Three failures surfaced after rebasing onto upstream/master: 1. ``test_returns_all_handler_keys`` expected the pre-homeassistant-ai#1164 handler set. Add ``get_advanced_settings`` / ``save_advanced_settings`` to the expected keys. 2. ``test_tools_filesystem.TestFeatureFlag::test_enabled_with_*`` broke because the master beta gate now forces every beta sub-flag False at runtime when ``ENABLE_BETA_FEATURES`` is unset. Set both env vars together in the enabling tests so they exercise the sub-flag bool parsing in isolation, and add an explicit test for the gated behavior so a future regression in ``_apply_feature_flag_overrides`` surfaces here too. 3. ``test_yaml_config_tool.enable_flag`` fixture sets ``ENABLE_YAML_CONFIG_EDITING`` but didn't set the master, so the cached settings landed with the sub-flag forced False — would have broken next-up after the filesystem tests. Set ``ENABLE_BETA_FEATURES`` alongside.
1 parent 7f400f1 commit 3e96694

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

tests/src/unit/test_stdio_settings_sidecar.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def test_returns_all_handler_keys(self) -> None:
9898
"policy_post_deny",
9999
"policy_get_tool_schema",
100100
"policy_get_value_source",
101+
# Advanced settings handlers (#1164).
102+
"get_advanced_settings",
103+
"save_advanced_settings",
101104
}
102105

103106
def test_get_tools_reads_cache_when_server_is_none(

tests/src/unit/test_tools_filesystem.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ def test_filesystem_constants_include_dashboards():
4545

4646

4747
class TestFeatureFlag:
48-
"""Test feature flag functionality."""
48+
"""Test feature flag functionality.
49+
50+
``HAMCP_ENABLE_FILESYSTEM_TOOLS`` is a beta sub-flag (#1164). The
51+
master ``ENABLE_BETA_FEATURES`` gate force-sets it False at runtime
52+
when the master is off, so every enabling test must set both env
53+
vars to exercise the sub-flag's bool parsing in isolation.
54+
"""
4955

5056
def test_disabled_by_default(self):
5157
"""Feature should be disabled by default."""
@@ -56,22 +62,30 @@ def test_disabled_by_default(self):
5662

5763
def test_enabled_with_true(self):
5864
"""Feature should be enabled when set to 'true'."""
59-
with patch.dict(os.environ, {FEATURE_FLAG: "true"}):
65+
with patch.dict(
66+
os.environ, {FEATURE_FLAG: "true", "ENABLE_BETA_FEATURES": "true"}
67+
):
6068
assert is_filesystem_tools_enabled() is True
6169

6270
def test_enabled_with_1(self):
6371
"""Feature should be enabled when set to '1'."""
64-
with patch.dict(os.environ, {FEATURE_FLAG: "1"}):
72+
with patch.dict(
73+
os.environ, {FEATURE_FLAG: "1", "ENABLE_BETA_FEATURES": "true"}
74+
):
6575
assert is_filesystem_tools_enabled() is True
6676

6777
def test_enabled_with_yes(self):
6878
"""Feature should be enabled when set to 'yes'."""
69-
with patch.dict(os.environ, {FEATURE_FLAG: "yes"}):
79+
with patch.dict(
80+
os.environ, {FEATURE_FLAG: "yes", "ENABLE_BETA_FEATURES": "true"}
81+
):
7082
assert is_filesystem_tools_enabled() is True
7183

7284
def test_enabled_with_on(self):
7385
"""Feature should be enabled when set to 'on'."""
74-
with patch.dict(os.environ, {FEATURE_FLAG: "on"}):
86+
with patch.dict(
87+
os.environ, {FEATURE_FLAG: "on", "ENABLE_BETA_FEATURES": "true"}
88+
):
7589
assert is_filesystem_tools_enabled() is True
7690

7791
def test_disabled_with_false(self):
@@ -86,11 +100,25 @@ def test_disabled_with_empty_string(self):
86100

87101
def test_case_insensitive(self):
88102
"""Feature flag should be case insensitive."""
89-
with patch.dict(os.environ, {FEATURE_FLAG: "TRUE"}):
103+
with patch.dict(
104+
os.environ, {FEATURE_FLAG: "TRUE", "ENABLE_BETA_FEATURES": "true"}
105+
):
90106
assert is_filesystem_tools_enabled() is True
91-
with patch.dict(os.environ, {FEATURE_FLAG: "True"}):
107+
with patch.dict(
108+
os.environ, {FEATURE_FLAG: "True", "ENABLE_BETA_FEATURES": "true"}
109+
):
92110
assert is_filesystem_tools_enabled() is True
93111

112+
def test_master_off_forces_sub_flag_off(self):
113+
"""Master beta gate (#1164) forces this sub-flag False even when
114+
the sub-flag env var is true. Lock the behavior so a future
115+
regression in ``_apply_feature_flag_overrides`` would surface
116+
in the filesystem-tools tests, not just the config tests.
117+
"""
118+
with patch.dict(os.environ, {FEATURE_FLAG: "true"}):
119+
os.environ.pop("ENABLE_BETA_FEATURES", None)
120+
assert is_filesystem_tools_enabled() is False
121+
94122

95123
class TestIsMcpToolsAvailable:
96124
"""Test _is_mcp_tools_available function."""

tests/src/unit/test_yaml_config_tool.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ def enable_flag(monkeypatch):
1313
If anything in the test process imported the module before this fixture ran,
1414
the cached settings have ENABLE_YAML_CONFIG_EDITING=False and our env var is
1515
ignored. Reset the cache before AND after to keep tests hermetic.
16+
17+
The master beta gate (#1164) also force-sets every beta sub-flag
18+
False at runtime when ``ENABLE_BETA_FEATURES`` is unset, so set
19+
both env vars together — otherwise the cached settings would land
20+
with ``enable_yaml_config_editing=False`` regardless of the
21+
sub-flag env var.
1622
"""
1723
from ha_mcp import config as ha_mcp_config
1824

1925
monkeypatch.setenv("ENABLE_YAML_CONFIG_EDITING", "true")
26+
monkeypatch.setenv("ENABLE_BETA_FEATURES", "true")
2027
monkeypatch.setattr(ha_mcp_config, "_settings", None)
2128
yield
2229
# Reset the cache so other tests don't see our enabled flag.

0 commit comments

Comments
 (0)