Spec 15 — Tests for infra-code

Purpose

pdf-service has tests (tests/test_pdf_service.py). queue-exporter and dns-manager.py do not, despite being prod-critical (Grafana alert quality depends on queue-exporter; DNS for both VPSes depends on dns-manager.py). Cheap to add, prevents silent breakage on refactor.


Rulebook

  1. Every Python tool under monitoring/exporters/, infra-src/, and scripts/*.py has at least a smoke test.
  2. Pure-Python tools get pytest; bash scripts get bats-core or are exempt.
  3. Test runs in CI on every PR touching the relevant file. No “tests exist but aren’t run” theater.

Implementation plan

  1. Add monitoring/exporters/queue-exporter/tests/test_app.py:
    • Mock Supabase REST responses, assert exporter parses them correctly
    • Test /metrics endpoint format
    • Test error handling (Supabase 500 → exporter doesn’t crash, exports _errors_total)
  2. Add scripts/tests/test_dns_manager.py:
    • Mock Cloudflare API, test add/upsert/delete/list code paths
    • Use responses or vcrpy to record/replay
  3. Add .github/workflows/python-tests.yml:
    • Triggers on PR touching **/*.py
    • Runs pytest with coverage report posted as PR comment
  4. Add pyproject.toml at repo root for shared pytest/ruff config.

Acceptance criteria

  • pytest monitoring/exporters/queue-exporter/ passes
  • pytest scripts/tests/ passes
  • Coverage report ≥70% for both tools
  • PR introducing a deliberate regression (e.g. removing error handling) fails CI

Cost impact

0 €.

Back-out plan

Delete test files + workflow.

Risks / open questions

  • Q: Bash scripts too? A: Out of scope for this spec. Bats-core is fine to add later when shell scripts grow.