ria-toolkit-oss/tests/agent/test_config.py
2026-04-16 11:13:43 -04:00

64 lines
1.9 KiB
Python

from ria_toolkit_oss.agent import config as agent_config
def test_round_trip(tmp_path):
p = tmp_path / "agent.json"
cfg = agent_config.AgentConfig(
hub_url="https://hub.example.com",
agent_id="agent-1",
token="t",
name="bench",
insecure=True,
)
agent_config.save(cfg, path=p)
loaded = agent_config.load(path=p)
assert loaded == cfg
def test_load_missing_returns_empty(tmp_path):
loaded = agent_config.load(path=tmp_path / "none.json")
assert loaded == agent_config.AgentConfig()
def test_tx_fields_round_trip(tmp_path):
p = tmp_path / "agent.json"
cfg = agent_config.AgentConfig(
hub_url="https://hub.example.com",
agent_id="agent-1",
token="t",
tx_enabled=True,
tx_max_gain_db=-10.0,
tx_max_duration_s=60.0,
tx_allowed_freq_ranges=[[2.4e9, 2.5e9], [5.7e9, 5.8e9]],
)
agent_config.save(cfg, path=p)
loaded = agent_config.load(path=p)
assert loaded.tx_enabled is True
assert loaded.tx_max_gain_db == -10.0
assert loaded.tx_max_duration_s == 60.0
assert loaded.tx_allowed_freq_ranges == [[2.4e9, 2.5e9], [5.7e9, 5.8e9]]
def test_tx_fields_default_when_absent(tmp_path):
# Old configs written before TX existed should load cleanly with safe defaults.
p = tmp_path / "agent.json"
p.write_text('{"hub_url": "x", "agent_id": "a", "token": "t"}')
cfg = agent_config.load(path=p)
assert cfg.tx_enabled is False
assert cfg.tx_max_gain_db is None
assert cfg.tx_max_duration_s is None
assert cfg.tx_allowed_freq_ranges is None
def test_extra_keys_preserved(tmp_path):
p = tmp_path / "agent.json"
p.write_text('{"hub_url": "x", "custom": 42}')
cfg = agent_config.load(path=p)
assert cfg.hub_url == "x"
assert cfg.extra == {"custom": 42}
agent_config.save(cfg, path=p)
import json
data = json.loads(p.read_text())
assert data["custom"] == 42