# tests/plugins/host_agent/test_agent_config.py """Unit tests for the agent's homegrown config parser.""" import pytest from plugins.host_agent.agent import read_config, ConfigError def test_parses_flat_key_value(tmp_path): p = tmp_path / "agent.conf" p.write_text( "url = https://roundtable.example\n" "token = abc123\n" "interval_seconds = 45\n" ) cfg = read_config(str(p)) assert cfg["url"] == "https://roundtable.example" assert cfg["token"] == "abc123" assert cfg["interval_seconds"] == 45 def test_ignores_blank_lines_and_comments(tmp_path): p = tmp_path / "agent.conf" p.write_text( "# top comment\n" "\n" "url = https://x\n" " # indented comment\n" "token = t\n" ) cfg = read_config(str(p)) # interval_seconds defaults to 30 when unset assert cfg["url"] == "https://x" assert cfg["token"] == "t" def test_parses_mounts_as_list(tmp_path): p = tmp_path / "agent.conf" p.write_text("url = x\ntoken = y\nmounts = /, /mnt/data, /srv\n") cfg = read_config(str(p)) assert cfg["mounts"] == ["/", "/mnt/data", "/srv"] def test_missing_required_fields_raises(tmp_path): p = tmp_path / "agent.conf" p.write_text("url = https://x\n") with pytest.raises(ConfigError, match="token"): read_config(str(p)) def test_malformed_line_raises(tmp_path): p = tmp_path / "agent.conf" p.write_text("url https://x\ntoken = y\n") with pytest.raises(ConfigError): read_config(str(p)) def test_default_interval_seconds(tmp_path): p = tmp_path / "agent.conf" p.write_text("url = x\ntoken = y\n") cfg = read_config(str(p)) assert cfg["interval_seconds"] == 30