Files
hermes-agent/tests/hermes_cli/test_shared_metrics_tools_toggle.py
emozilla d7c48548a9 feat(shared-metrics): offer two consent answers, drop collect-only
The first-run offer on Desktop, the dashboard and the terminal had a
third answer ("Keep on this computer" / "Collect locally only" / "Local
only") that collected stats nobody reads: no surface shows them to the
user, and data from before an opt-in is never sent. Every surface now
offers "Share with Nous" or "No thanks", and each answer sets `enabled`
and `send` together. Desktop Settings > Privacy and `hermes setup
telemetry` become one on/off choice to match.

Profiles that already chose collect-only keep that answer and are not
asked again: they saw the question and declined to send. Nothing is sent
for them; the Desktop switch reads off and the `hermes tools` row says
"collecting locally".

Copy that described collection as a separate local choice is rewritten
in every locale that carries it (de, es, fr, ja, ru, zh, zh-hant, ar).
2026-10-21 00:32:21 -04:00

90 lines
3.0 KiB
Python

"""Tests for the `hermes tools` shared-metrics consent toggle.
AGENTS.md requires outbound telemetry to be reachable from a config gate, the
setup prompt, AND `hermes tools`. These cover the third surface.
"""
from __future__ import annotations
from hermes_cli.tools_config import (
_configure_shared_metrics_interactive,
_shared_metrics_menu_label,
_shared_metrics_state,
)
def _config(**shared):
return {"telemetry": {"shared_metrics": shared}}
class TestState:
def test_missing_telemetry_section_is_off(self):
assert _shared_metrics_state({}) == (False, False)
def test_malformed_section_does_not_raise(self):
assert _shared_metrics_state({"telemetry": "nonsense"}) == (False, False)
def test_reads_both_flags(self):
assert _shared_metrics_state(_config(enabled=True, send=True)) == (True, True)
class TestMenuLabel:
def test_sending_state_names_the_destination(self):
label = _shared_metrics_menu_label(_config(enabled=True, send=True))
assert "(sending to Nous)" in label
def test_retired_collect_only_answer_is_named_rather_than_read_off(self):
label = _shared_metrics_menu_label(_config(enabled=True, send=False))
assert "(collecting locally)" in label
def test_off(self):
assert "(off)" in _shared_metrics_menu_label(_config(enabled=False, send=False))
class TestToggle:
def test_enabling_send_persists(self, monkeypatch):
config = _config(enabled=True)
saved = {}
monkeypatch.setattr(
"hermes_cli.setup.prompt_yes_no", lambda *_a, **_k: True
)
monkeypatch.setattr(
"hermes_cli.setup._record_send_consent_change", lambda **_k: None
)
monkeypatch.setattr(
"hermes_cli.tools_config.save_config",
lambda cfg: saved.update({"cfg": cfg}),
)
_configure_shared_metrics_interactive(config)
assert config["telemetry"]["shared_metrics"]["send"] is True
assert saved, "a consent change must be written to disk"
def test_no_write_when_nothing_changed(self, monkeypatch):
config = _config(enabled=False, send=False)
saved = []
monkeypatch.setattr(
"hermes_cli.setup.prompt_yes_no", lambda *_a, **_k: False
)
monkeypatch.setattr(
"hermes_cli.tools_config.save_config", lambda cfg: saved.append(cfg)
)
_configure_shared_metrics_interactive(config)
assert saved == []
def test_disabling_collection_also_disables_sending(self, monkeypatch):
"""The toggle must not leave send=true with nothing to send."""
config = _config(enabled=True, send=True)
monkeypatch.setattr(
"hermes_cli.setup.prompt_yes_no", lambda *_a, **_k: False
)
monkeypatch.setattr(
"hermes_cli.tools_config.save_config", lambda cfg: None
)
_configure_shared_metrics_interactive(config)
shared = config["telemetry"]["shared_metrics"]
assert shared["enabled"] is False
assert shared["send"] is False