mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-07-28 22:39:26 +00:00
- Added a `--strict` option to `validate_config.py` to fail on "Unknown section" messages, aimed at CI validation of example configs. - Updated GitHub Actions workflow to validate shipped example configs against the canonical section list using the new strict mode. - Expanded the `CANONICAL_NON_COMMAND_SECTIONS` in `config_validation.py` to include additional sections for improved validation accuracy. - Introduced a regression test to ensure example configs do not trigger unknown section warnings, maintaining consistency with the canonical list.
67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
"""Tests for the validate_config.py CLI entry point, in particular --strict."""
|
|
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
|
|
VALID_CONFIG = """[Connection]
|
|
connection_type = serial
|
|
serial_port = /dev/ttyUSB0
|
|
|
|
[Bot]
|
|
bot_name = TestBot
|
|
db_path = {db_path}
|
|
|
|
[Channels]
|
|
monitor_channels = general
|
|
respond_to_dms = true
|
|
|
|
[Keywords]
|
|
test = ack
|
|
"""
|
|
|
|
CONFIG_WITH_UNKNOWN_SECTION = VALID_CONFIG + """
|
|
[TotallyMadeUpSection]
|
|
foo = bar
|
|
"""
|
|
|
|
|
|
def _run_validate_config(config_path: Path, *extra_args: str) -> subprocess.CompletedProcess:
|
|
return subprocess.run(
|
|
[sys.executable, "validate_config.py", "--config", str(config_path), *extra_args],
|
|
cwd=REPO_ROOT,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=30,
|
|
)
|
|
|
|
|
|
class TestValidateConfigCli:
|
|
def test_unknown_section_does_not_fail_without_strict(self, tmp_path):
|
|
config = tmp_path / "config.ini"
|
|
config.write_text(CONFIG_WITH_UNKNOWN_SECTION.format(db_path=str(tmp_path / "meshcore_bot.db")))
|
|
result = _run_validate_config(config)
|
|
assert result.returncode == 0
|
|
assert "Unknown section [TotallyMadeUpSection]" in result.stderr
|
|
|
|
def test_unknown_section_fails_with_strict(self, tmp_path):
|
|
config = tmp_path / "config.ini"
|
|
config.write_text(CONFIG_WITH_UNKNOWN_SECTION.format(db_path=str(tmp_path / "meshcore_bot.db")))
|
|
result = _run_validate_config(config, "--strict")
|
|
assert result.returncode == 1
|
|
assert "Unknown section [TotallyMadeUpSection]" in result.stderr
|
|
|
|
def test_valid_config_passes_with_strict(self, tmp_path):
|
|
config = tmp_path / "config.ini"
|
|
config.write_text(VALID_CONFIG.format(db_path=str(tmp_path / "meshcore_bot.db")))
|
|
result = _run_validate_config(config, "--strict")
|
|
assert result.returncode == 0
|
|
|
|
def test_error_still_fails_regardless_of_strict(self, tmp_path):
|
|
config = tmp_path / "config.ini"
|
|
config.write_text("[Bot]\nbot_name = Test\n")
|
|
result = _run_validate_config(config)
|
|
assert result.returncode == 1
|