Two silent failures sitting between Phase A and a working invitation. The compose file never passed MAIL_* through. Compose does not give a container the contents of .env — it only substitutes into the compose file — so the settings could be filled in correctly and read by nobody, with the app reporting mail as unconfigured and the values sitting right there on disk. test_deployment.py now fails the build whenever .env.example and docker-compose.yml drift apart, which is how this happened and how it would happen again. The app's code is baked into the image (COPY apps /srv/apps), so a pull followed by --force-recreate runs the old code and says nothing. Added scripts/deploy-board.sh: rebuild, sync the compose file, restart, print the log, and name any setting present in .env.example and missing from the live .env. It never touches .env itself. Also: "no mail server configured" is now told apart from "the mail server refused". They want different things done about them, and the first one sent an admin looking for an SMTP error that never existed. The new-member form says so before it is filled in rather than after. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""Guards on the gap between what the app reads and what the server hands it.
|
|
|
|
This is the one class of bug the rest of the suite cannot see. Every test here
|
|
runs against a Flask config built in-process, so a setting can be documented in
|
|
`.env.example`, read in `app.py`, and still reach the container as nothing at
|
|
all — because Compose does not pass `.env` to a container, it only substitutes
|
|
into the compose file. The symptom is a feature reporting itself unconfigured
|
|
with the settings sitting right there on disk, which is a miserable thing to
|
|
debug from the outside.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
INFRA = Path(__file__).resolve().parents[3] / "infra" / "board"
|
|
ENV_EXAMPLE = INFRA / ".env.example"
|
|
COMPOSE = INFRA / "docker-compose.yml"
|
|
|
|
SETTING = re.compile(r"^([A-Z][A-Z0-9_]*)=", re.MULTILINE)
|
|
|
|
|
|
def documented() -> set[str]:
|
|
return set(SETTING.findall(ENV_EXAMPLE.read_text(encoding="utf-8")))
|
|
|
|
|
|
def test_every_documented_setting_reaches_the_container():
|
|
compose = COMPOSE.read_text(encoding="utf-8")
|
|
missing = sorted(
|
|
name for name in documented()
|
|
if f"${{{name}}}" not in compose and f"${{{name}:-" not in compose
|
|
)
|
|
assert not missing, (
|
|
"these are in .env.example but never substituted into "
|
|
f"docker-compose.yml, so the container never sees them: {missing}"
|
|
)
|
|
|
|
|
|
def test_the_mail_settings_are_optional_at_the_compose_level():
|
|
"""`${MAIL_HOST}` without a default makes Compose warn on every command for
|
|
a server that has deliberately not configured mail. Running without it is a
|
|
supported state, so it must be a quiet one."""
|
|
compose = COMPOSE.read_text(encoding="utf-8")
|
|
for name in sorted(n for n in documented() if n.startswith("MAIL_")):
|
|
assert f"${{{name}:-" in compose, f"{name} has no default in docker-compose.yml"
|