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
- Every Python tool under
monitoring/exporters/,infra-src/, andscripts/*.pyhas at least a smoke test. - Pure-Python tools get pytest; bash scripts get bats-core or are exempt.
- Test runs in CI on every PR touching the relevant file. No “tests exist but aren’t run” theater.
Implementation plan
- Add
monitoring/exporters/queue-exporter/tests/test_app.py:- Mock Supabase REST responses, assert exporter parses them correctly
- Test
/metricsendpoint format - Test error handling (Supabase 500 → exporter doesn’t crash, exports
_errors_total)
- Add
scripts/tests/test_dns_manager.py:- Mock Cloudflare API, test add/upsert/delete/list code paths
- Use
responsesorvcrpyto record/replay
- Add
.github/workflows/python-tests.yml:- Triggers on PR touching
**/*.py - Runs pytest with coverage report posted as PR comment
- Triggers on PR touching
- Add
pyproject.tomlat 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.