Merge branch 'claude/relaxed-faraday-h4zd09' of https://github.com/pablovolenski/vienalatina
This commit is contained in:
commit
cacc7c20bb
@ -40,22 +40,35 @@ from .security import superadmin_required
|
|||||||
|
|
||||||
bp = Blueprint("status", __name__)
|
bp = Blueprint("status", __name__)
|
||||||
|
|
||||||
# Where deploy-board.sh puts them. Read-only, and missing is an answer.
|
# Where the compose file mounts them, read-only. **Not** the host path: this
|
||||||
BACKUP_DIR = "/srv/board/backups"
|
# runs in a container, and `/srv/board/backups` exists on the host and nowhere
|
||||||
|
# inside it. Reading the host path from in here reported "no hay carpeta de
|
||||||
|
# copias" twenty seconds after deploy-board.sh had written one — a diagnostic
|
||||||
|
# page crying wolf about backups is a page you learn to scroll past, which is
|
||||||
|
# the one habit it exists to prevent.
|
||||||
|
BACKUP_DIR = "/backups"
|
||||||
|
|
||||||
# Settings whose absence turns a feature off rather than breaking the app. The
|
# Settings whose absence matters, and the config key each one lands in — so the
|
||||||
# names are the ones in infra/board/.env.example; the sentence is what stops
|
# value actually in force is read from the app rather than restated here, where
|
||||||
# working. Checked against os.environ because the container cannot read
|
# the two could disagree.
|
||||||
# /srv/board/.env — compose substitutes it in and the file never arrives.
|
#
|
||||||
|
# The third column separates the two facts this panel used to merge: **absent
|
||||||
|
# and nothing works** from **absent and defaulted**. `CONTENT_REPO` is unset on
|
||||||
|
# the real server and publishing works, because app.py defaults it; reporting
|
||||||
|
# that as a problem is how a page full of orange teaches you to ignore orange.
|
||||||
|
# A config key of None means there is no fallback and the feature is simply off.
|
||||||
|
#
|
||||||
|
# Checked against os.environ because the container cannot read /srv/board/.env —
|
||||||
|
# compose substitutes it in and the file itself never arrives.
|
||||||
EXPECTED = (
|
EXPECTED = (
|
||||||
("BOARD_SECRET_KEY", "las sesiones (sin esto la app no arranca)"),
|
("BOARD_SECRET_KEY", "las sesiones (sin esto la app no arranca)", None),
|
||||||
("CONTENT_TOKEN", "publicar en el sitio: el editor y la marca"),
|
("CONTENT_TOKEN", "publicar en el sitio: el editor y la marca", None),
|
||||||
("MAIL_HOST", "invitaciones y recuperar contraseña"),
|
("MAIL_HOST", "invitaciones y recuperar contraseña", None),
|
||||||
("MAIL_USER", "autenticarse en el servidor de correo"),
|
("MAIL_USER", "autenticarse en el servidor de correo", None),
|
||||||
("MAIL_PASSWORD", "autenticarse en el servidor de correo"),
|
("MAIL_PASSWORD", "autenticarse en el servidor de correo", None),
|
||||||
("BOARD_OWNER", "sembrar al superadministrador en el primer arranque"),
|
("BOARD_OWNER", "sembrar al superadministrador en el primer arranque", None),
|
||||||
("GITEA_URL", "hablar con el servidor de git"),
|
("GITEA_URL", "hablar con el servidor de git", "GITEA_URL"),
|
||||||
("CONTENT_REPO", "saber en qué repositorio se publica"),
|
("CONTENT_REPO", "saber en qué repositorio se publica", "CONTENT_REPO"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -150,12 +163,30 @@ def _disk() -> dict:
|
|||||||
|
|
||||||
|
|
||||||
def _settings() -> dict:
|
def _settings() -> dict:
|
||||||
missing = [(name, why) for name, why in EXPECTED if not os.environ.get(name)]
|
"""Which expected settings the container does not have, and whether it
|
||||||
if not missing:
|
matters — which are two different questions."""
|
||||||
return _ok("Todos los ajustes esperados están puestos")
|
missing, defaulted = [], []
|
||||||
|
for name, why, key in EXPECTED:
|
||||||
|
if os.environ.get(name):
|
||||||
|
continue
|
||||||
|
if key:
|
||||||
|
defaulted.append(f"{name} — usando «{current_app.config.get(key)}» "
|
||||||
|
"(valor por defecto)")
|
||||||
|
else:
|
||||||
|
missing.append(f"{name} — {why}")
|
||||||
|
|
||||||
|
detail = "; ".join(missing + defaulted)
|
||||||
|
if missing:
|
||||||
return _warn(
|
return _warn(
|
||||||
f"{len(missing)} ajuste{'s' if len(missing) > 1 else ''} sin poner",
|
f"{len(missing)} ajuste{'s' if len(missing) > 1 else ''} sin poner",
|
||||||
"; ".join(f"{name} — {why}" for name, why in missing))
|
detail)
|
||||||
|
if defaulted:
|
||||||
|
# Green: nothing is broken. The values are still named, because "it
|
||||||
|
# works and here is the value it is working with" is the answer, and
|
||||||
|
# silence would leave somebody wondering which repository it publishes
|
||||||
|
# to.
|
||||||
|
return _ok("Todos los ajustes necesarios están puestos", detail)
|
||||||
|
return _ok("Todos los ajustes esperados están puestos")
|
||||||
|
|
||||||
|
|
||||||
def _counts() -> dict:
|
def _counts() -> dict:
|
||||||
|
|||||||
@ -258,3 +258,89 @@ def test_the_status_screen_counts_what_is_there(client, db, boss, make_member, r
|
|||||||
|
|
||||||
assert "3 miembros" in body # the superadministrator and the two
|
assert "3 miembros" in body # the superadministrator and the two
|
||||||
assert "2 con algún cargo" in body # superadministrator + moderator
|
assert "2 con algún cargo" in body # superadministrator + moderator
|
||||||
|
|
||||||
|
|
||||||
|
# --- the status screen tells the truth about the container it is in --------
|
||||||
|
|
||||||
|
def test_the_backup_check_reads_a_path_the_container_can_see(tmp_path, monkeypatch):
|
||||||
|
"""The bug this file gained a section for.
|
||||||
|
|
||||||
|
`BACKUP_DIR` was `/srv/board/backups` — a **host** path, read from inside a
|
||||||
|
container that mounts only `./data`. On the real server it reported "no hay
|
||||||
|
carpeta de copias" twenty seconds after `deploy-board.sh` had written one.
|
||||||
|
The compose file now mounts the folder read-only at `/backups`, and this
|
||||||
|
asserts the constant points at the mount rather than at the host.
|
||||||
|
"""
|
||||||
|
from apps.board import status
|
||||||
|
assert status.BACKUP_DIR == "/backups", (
|
||||||
|
"BACKUP_DIR must be the path inside the container, not the host's — "
|
||||||
|
"see infra/board/docker-compose.yml")
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_backup_is_found_reported_and_dated(app, tmp_path, monkeypatch):
|
||||||
|
from apps.board import status
|
||||||
|
folder = tmp_path / "backups"
|
||||||
|
folder.mkdir()
|
||||||
|
(folder / "board-20261006-030000.db.gz").write_bytes(b"x" * 4096)
|
||||||
|
monkeypatch.setattr(status, "BACKUP_DIR", str(folder))
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
check = status._backups()
|
||||||
|
|
||||||
|
assert check["state"] == "ok"
|
||||||
|
assert "board-20261006-030000.db.gz" in check["detail"]
|
||||||
|
assert "4 KB" in check["detail"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_an_empty_backup_folder_is_the_real_alarm(app, tmp_path, monkeypatch):
|
||||||
|
"""The folder existing and holding nothing is the state worth shouting
|
||||||
|
about — unlike the folder simply not being visible, which was mine."""
|
||||||
|
from apps.board import status
|
||||||
|
folder = tmp_path / "backups"
|
||||||
|
folder.mkdir()
|
||||||
|
monkeypatch.setattr(status, "BACKUP_DIR", str(folder))
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
assert status._backups()["state"] == "bad"
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_setting_with_a_fallback_is_not_reported_as_missing(app, monkeypatch):
|
||||||
|
"""`CONTENT_REPO` is unset on the real server and publishing works, because
|
||||||
|
app.py defaults it. Reporting that as a problem is how a panel full of
|
||||||
|
orange teaches somebody to ignore orange.
|
||||||
|
|
||||||
|
The ones with no fallback are set here so that the only thing left absent is
|
||||||
|
the defaulted one — which is the state the real server is in."""
|
||||||
|
from apps.board import status
|
||||||
|
for name, _why, key in status.EXPECTED:
|
||||||
|
if key is None:
|
||||||
|
monkeypatch.setenv(name, "puesto")
|
||||||
|
monkeypatch.delenv("CONTENT_REPO", raising=False)
|
||||||
|
|
||||||
|
with app.test_request_context():
|
||||||
|
check = status._settings()
|
||||||
|
|
||||||
|
assert check["state"] == "ok"
|
||||||
|
assert "CONTENT_REPO" in check["detail"]
|
||||||
|
assert "por defecto" in check["detail"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_setting_with_no_fallback_still_warns(app, monkeypatch):
|
||||||
|
monkeypatch.delenv("MAIL_HOST", raising=False)
|
||||||
|
from apps.board import status
|
||||||
|
with app.test_request_context():
|
||||||
|
check = status._settings()
|
||||||
|
|
||||||
|
assert check["state"] == "warn"
|
||||||
|
assert "MAIL_HOST" in check["detail"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_every_expected_setting_names_a_real_config_key(app):
|
||||||
|
"""The third column is read back out of `current_app.config`, so a typo
|
||||||
|
would render «usando None» on the page rather than failing anywhere."""
|
||||||
|
from apps.board import status
|
||||||
|
with app.app_context():
|
||||||
|
for name, _why, key in status.EXPECTED:
|
||||||
|
if key:
|
||||||
|
assert key in app.config, (name, key)
|
||||||
|
assert app.config[key], (name, key)
|
||||||
|
|||||||
@ -1195,7 +1195,20 @@ Calendario and Gestión off the right edge with nothing to say they were there.
|
|||||||
|
|
||||||
### 11.20 The three admin tools
|
### 11.20 The three admin tools
|
||||||
|
|
||||||
**Estado del sistema** (superadministrator). WordPress's Site Health, and it
|
**Estado del sistema** (superadministrator). The backups panel reads
|
||||||
|
`/backups`, **not** `/srv/board/backups`: this runs in a container, the host
|
||||||
|
path exists nowhere inside it, and pointing at the host path made the page
|
||||||
|
report "no hay carpeta de copias" twenty seconds after `deploy-board.sh` had
|
||||||
|
written one. `infra/board/docker-compose.yml` mounts the folder **read-only** —
|
||||||
|
a page that reports on backups must never be able to touch them.
|
||||||
|
|
||||||
|
The settings panel separates *absent and nothing works* from *absent and
|
||||||
|
defaulted*: `CONTENT_REPO` is unset on this server and publishing works, because
|
||||||
|
`app.py` defaults it, so the panel names the value in force rather than warning.
|
||||||
|
Merging those two facts is how a page full of orange teaches somebody to ignore
|
||||||
|
orange.
|
||||||
|
|
||||||
|
WordPress's Site Health, and it
|
||||||
earns its place for a specific reason: every outage in this project has been a
|
earns its place for a specific reason: every outage in this project has been a
|
||||||
configuration fact invisible until somebody hit it. It asks the running system
|
configuration fact invisible until somebody hit it. It asks the running system
|
||||||
rather than a file — the content token is **exercised** against the repository
|
rather than a file — the content token is **exercised** against the repository
|
||||||
|
|||||||
@ -54,5 +54,15 @@ services:
|
|||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/data
|
- ./data:/data
|
||||||
|
# The backups, read-only, so Gestión → Estado del sistema can say whether
|
||||||
|
# there are any and how old they are. Read-only deliberately: that page
|
||||||
|
# reports on these files and must never be able to touch them — a
|
||||||
|
# diagnostic screen that can delete what it measures is a worse failure
|
||||||
|
# than no screen.
|
||||||
|
#
|
||||||
|
# Without this the check reads /srv/board/backups from inside a container
|
||||||
|
# that mounts only ./data, finds nothing, and cries wolf about the one
|
||||||
|
# thing you most want to be true.
|
||||||
|
- ./backups:/backups:ro
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8080:8080"
|
- "127.0.0.1:8080:8080"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user