Files
hermes-agent/tests/hermes_cli/test_setup_blank_slate.py
kshitijk4poor 680fa8a92d test(config): one parametrized every-seeder test + template parity, drop duplicates
The stack's regression tests pasted the same platform-parity loop into four
files and added eight cases for one invariant ("a seeded config must not
pin a global display key"), over the AGENTS.md invariant-test budget.

- assert_keeps_platform_display_defaults() in test_display_config.py is the
  single parity helper.
- test_shipped_template_keeps_every_platform_default moves out of
  TestYAMLNormalisation (it was attached there only by indentation) into
  TestInstallerSeededConfigThroughGatewayResolver, reuses _seed_like_installer
  and absorbs the _resolve_gateway_display_bool qqbot hop.
- test_config_edit_seed's test becomes the one parametrized every-seeder test:
  config edit (template / no template), `hermes setup agent` with Enter (the
  W1 leak fixed in this stack), _apply_default_agent_settings and blank slate.
  The per-file copies in test_setup_agent_settings / test_setup_blank_slate
  are removed.
- Dropped test_template_seeded_home_keeps_qqbot_reasoning_off (duplicate; its
  dead HERMES_HOME set + raising=False patch went with it) and
  test_show_reasoning_stays_a_known_config_key (change-detector for the
  rejected #121232 approach). The explicit opt-in control (#7148) stays.

On origin/main's production files the template test and all five seeder
cases fail; the control passes.
2026-09-24 17:59:37 +05:30

122 lines
5.7 KiB
Python

"""Tests for Blank Slate setup mode (hermes_cli/setup.py).
Blank Slate is the third first-time setup option: everything off except the
bare minimum needed to run an agent (provider/model + file + terminal). These
tests pin the config the writers produce and the invariant that the toolset
resolver + tool-schema builder yield exactly the file/terminal tools.
"""
from hermes_cli.setup_quick import _blank_slate_minimal_toolsets, _blank_slate_minimize_config
from hermes_cli import setup_quick
class TestBlankSlateMinimalToolsets:
def test_no_disabled_bundle_overlaps_kept_tools(self):
"""Invariant: ``disabled_toolsets`` is applied at *tool* granularity and
a single tool can belong to several toolsets, so no disabled entry may
share a tool with a kept toolset — it would silently strip that tool
from the blank-slate agent (#57315, #58281).
"""
from toolsets import resolve_toolset
cfg = {}
_blank_slate_minimal_toolsets(cfg)
kept_tools = set()
for ts in cfg["platform_toolsets"]["cli"]:
kept_tools.update(resolve_toolset(ts))
for ts in cfg["agent"]["disabled_toolsets"]:
overlap = set(resolve_toolset(ts)) & kept_tools
assert not overlap, (
f"disabled toolset '{ts}' overlaps kept tools {sorted(overlap)}; "
"it would silently strip them from the blank-slate agent"
)
def test_tool_schema_survives_disabled_toolsets_from_config(self, monkeypatch):
"""Regression: disabled_toolsets must not erase the minimal Blank Slate
surface when passed to model_tools. Before the fix, posture toolsets
like ``coding`` in disabled_toolsets caused model_tools to subtract
terminal, read_file, write_file, etc. (#57315).
vision_analyze is additionally check_fn-gated on a resolvable vision
backend; mock the requirement check so the toolset logic is exercised
independent of the test host's provider credentials.
"""
import model_tools
from tools.registry import registry as _tool_registry
_entry = _tool_registry.get_entry("vision_analyze")
monkeypatch.setattr(_entry, "check_fn", lambda: True)
# This test pins disabled_toolsets SUBTRACTION, not deferral policy —
# assemble with the legacy everything-eager override so the expected
# list stays deferral-independent (#97979 defers process_manage by
# default, which would swap it for the three bridge tools here).
from tools.tool_search import ToolSearchConfig
_legacy = ToolSearchConfig.from_raw({"enabled": "on", "defer": []})
monkeypatch.setattr("tools.tool_search.load_config", lambda: _legacy)
monkeypatch.setattr("tools.tool_search.load_config_readonly", lambda: _legacy)
from hermes_cli.tools_config import _get_platform_tools
cfg = {}
_blank_slate_minimal_toolsets(cfg)
_blank_slate_minimize_config(cfg)
enabled = sorted(_get_platform_tools(cfg, "cli"))
disabled = cfg.get("agent", {}).get("disabled_toolsets") or []
defs = model_tools.get_tool_definitions(
enabled_toolsets=enabled,
disabled_toolsets=disabled,
quiet_mode=True,
)
names = sorted(
{(d.get("function") or {}).get("name") or d.get("name") for d in defs}
)
assert {"terminal", "read_file", "write_file", "patch", "search_files"} <= set(names)
class TestBlankSlateMinimizeConfig:
def test_optional_features_turned_off(self):
cfg = {}
_blank_slate_minimize_config(cfg)
assert cfg["compression"]["enabled"] is False
assert cfg["memory"]["memory_enabled"] is False
assert cfg["memory"]["user_profile_enabled"] is False
assert cfg["checkpoints"]["enabled"] is False
assert cfg["smart_model_routing"]["enabled"] is False
class TestBlankSlateFork:
"""The post-baseline fork: finish now vs walk through configurations."""
def _patch_common(self, monkeypatch):
import hermes_cli.setup as s
# Neutralize side-effecting setup steps and I/O.
monkeypatch.setattr(s, "setup_model_provider", lambda cfg, **k: None)
monkeypatch.setattr(s, "setup_terminal_backend", lambda cfg, **k: None)
monkeypatch.setattr(s, "save_config", lambda cfg: None)
monkeypatch.setattr(s, "_print_setup_summary", lambda cfg, home: None)
monkeypatch.setattr(s, "print_header", lambda *a, **k: None)
monkeypatch.setattr(s, "print_info", lambda *a, **k: None)
monkeypatch.setattr(s, "print_success", lambda *a, **k: None)
monkeypatch.setattr(s, "print_warning", lambda *a, **k: None)
def test_finish_now_skips_walkthrough(self, monkeypatch, tmp_path):
import hermes_cli.setup as s
self._patch_common(monkeypatch)
# Fork prompt returns 0 = finish now.
monkeypatch.setattr(s, "prompt_choice", lambda *a, **k: 0)
walked = {"called": False}
monkeypatch.setattr(setup_quick, "_blank_slate_walkthrough",
lambda cfg, home: walked.__setitem__("called", True))
opted_out = {"value": None}
monkeypatch.setattr("tools.skills_sync_bundled_ops.set_bundled_skills_opt_out",
lambda enabled: opted_out.__setitem__("value", enabled))
cfg = {}
setup_quick._run_blank_slate_setup(cfg, tmp_path, is_existing=False)
# Minimal baseline was applied, walkthrough was NOT run.
assert cfg["platform_toolsets"]["cli"] == ["file", "skills", "terminal", "vision"]
assert walked["called"] is False
# Finish-now path records the skill opt-out (no bundled skills).
assert opted_out["value"] is True