test: trim timezone validation tests to two invariants; document the doctor check

Collapse the five contributor tests from #101345 into two: one for the
error class (unloadable IANA name, non-string value) and one for the
silent class (valid, blank, missing, None, and no tz database at all).
Same coverage, half the surface — the salvage bar is two invariant tests
per fix.

Docs: the `timezone` section now says `hermes doctor` reports a value the
runtime cannot load, so users know where the typo surfaces.
This commit is contained in:
teknium1
2026-09-15 11:40:47 -07:00
committed by Teknium
parent 7af3515c57
commit 5f20bb8b63
2 changed files with 15 additions and 25 deletions
+13 -25
View File
@@ -113,10 +113,6 @@ class TestVoiceSubmitModeValidation:
)
def _tz_issues(config):
return [i for i in validate_config_structure(config) if "timezone" in i.message]
def _has_tz_database() -> bool:
try:
import zoneinfo
@@ -126,43 +122,35 @@ def _has_tz_database() -> bool:
return False
def _tz_issues(config):
return [i for i in validate_config_structure(config) if "timezone" in i.message]
class TestTimezoneValidation:
"""An invalid ``timezone`` silently puts the agent clock and every cron
schedule on server-local time (hermes_time._get_zoneinfo falls back with
one log warning). validate_config_structure must report it."""
def test_valid_zone_passes(self):
assert _tz_issues({"timezone": "Asia/Tokyo", "model": {"provider": "nous"}}) == []
def test_missing_or_blank_is_not_reported(self):
assert _tz_issues({"model": {"provider": "nous"}}) == []
assert _tz_issues({"timezone": "", "model": {"provider": "nous"}}) == []
assert _tz_issues({"timezone": " ", "model": {"provider": "nous"}}) == []
assert _tz_issues({"timezone": None, "model": {"provider": "nous"}}) == []
one log warning). validate_config_structure must report it (#111725)."""
@pytest.mark.skipif(not _has_tz_database(), reason="no tz database in this interpreter")
def test_invalid_zone_is_reported(self):
def test_invalid_or_non_string_zone_is_an_error(self):
[issue] = _tz_issues({"timezone": "Asia/Tokio", "model": {"provider": "nous"}})
assert issue.severity == "error"
assert "Asia/Tokio" in issue.message
assert "IANA" in issue.hint
assert "HERMES_TIMEZONE" in issue.hint
def test_non_string_is_reported(self):
assert "IANA" in issue.hint and "HERMES_TIMEZONE" in issue.hint
[issue] = _tz_issues({"timezone": 9, "model": {"provider": "nous"}})
assert issue.severity == "error"
assert "string" in issue.message
assert issue.severity == "error" and "string" in issue.message
def test_silent_without_a_tz_database(self, monkeypatch):
# Bare Windows without tzdata: ZoneInfo cannot load anything, including
# UTC. A valid name must not be flagged just because it cannot be checked.
def test_valid_blank_missing_or_unverifiable_zone_is_silent(self, monkeypatch):
for cfg in ({"timezone": "Asia/Tokyo"}, {}, {"timezone": ""}, {"timezone": " "}, {"timezone": None}):
assert _tz_issues({**cfg, "model": {"provider": "nous"}}) == []
# Bare Windows without tzdata: ZoneInfo cannot load anything, including UTC.
# A name that cannot be checked must not be flagged.
import zoneinfo
def no_db(_key):
raise zoneinfo.ZoneInfoNotFoundError("no tz database")
monkeypatch.setattr(zoneinfo, "ZoneInfo", no_db)
assert _tz_issues({"timezone": "Asia/Tokyo", "model": {"provider": "nous"}}) == []
assert _tz_issues({"timezone": "Asia/Tokio", "model": {"provider": "nous"}}) == []
+2
View File
@@ -2596,6 +2596,8 @@ timezone: "America/New_York" # IANA timezone (default: "" = server-local time)
Supported values: any IANA timezone identifier (e.g. `America/New_York`, `Europe/London`, `Asia/Kolkata`, `UTC`). Leave empty or omit for server-local time.
`hermes doctor` (and the startup config check) reports a value the runtime cannot load — a typo such as `Asia/Tokio` would otherwise silently put the agent clock and every cron schedule on server-local time. `HERMES_TIMEZONE` overrides this key when set.
## Discord
Configure Discord-specific behavior for the messaging gateway: