Files
hermes-agent/tests/tools/test_allowlist_legacy_config.py
T
Teknium 7876d183c9 fix(approval): recover legacy list values without character grants
Recover legacy stringified lists with a warning. Reject malformed shapes and nonstring members without admitting approvals or rewriting user config on read.

Fixes #104779
Co-authored-by: liuhao1024 <sunsky.lau@gmail.com>
2026-09-07 08:13:38 -07:00

22 lines
1.0 KiB
Python

import yaml
from tools import approval
def test_legacy_string_allowlist_recovers_only_string_lists(tmp_path, monkeypatch, caplog):
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
description = "script execution via -e/-c flag"
for value in ([description], yaml.safe_dump([description])):
(tmp_path / "config.yaml").write_text(yaml.safe_dump({"command_allowlist": value}))
assert approval.load_permanent_allowlist() == {description}
assert approval.is_approved("probe", description)
assert "command_allowlist" in caplog.text
def test_malformed_allowlist_does_not_grant_approval(tmp_path, monkeypatch, caplog):
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
for value in ("plain text", "[bad", {"not": "a list"}, [True, "candidate"], "[true, candidate]", 42):
(tmp_path / "config.yaml").write_text(yaml.safe_dump({"command_allowlist": value}))
assert approval.load_permanent_allowlist() == set()
assert not approval.is_approved("probe", "candidate")
assert "command_allowlist" in caplog.text