Files
romm/backend/tests/test_env_template.py
alexcastgonz e15463f4a7 docs: list the ROM patcher env vars in env.template (#5265)
* docs: list the ROM patcher env vars in env.template

ROM_PATCHER_TIMEOUT, ROM_PATCHER_MAX_FILE_SIZE_BYTES and
ROM_PATCHER_MAX_CONCURRENCY are read by the config but were missing
from env.template, so the generated env var reference in the docs
does not list them. A test now checks that every env var the config
reads is in env.template.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say ROM_PATCHER_MAX_CONCURRENCY is per API worker; skip the env.template test without it

Each API worker process has its own patch semaphore, so the limit applies
per worker, not server-wide. The dev container only mounts backend/, so
the env.template test now skips there instead of failing on a missing file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 14:27:04 -04:00

48 lines
1.5 KiB
Python

"""Guards that env.template, which generates the docs' env var reference, lists every setting."""
import ast
from pathlib import Path
import pytest
REPO_ROOT = Path(__file__).resolve().parents[2]
CONFIG_MODULE = REPO_ROOT / "backend" / "config" / "__init__.py"
ENV_TEMPLATE = REPO_ROOT / "env.template"
ENV_READERS = {"_get_env", "_get_env_list", "_get_env_set"}
# Set by pytest itself, not by users.
NOT_USER_SETTINGS = {"PYTEST_VERSION"}
def _env_vars_read_by_config() -> set[str]:
names = set()
for node in ast.walk(ast.parse(CONFIG_MODULE.read_text())):
if (
isinstance(node, ast.Call)
and isinstance(node.func, ast.Name)
and node.func.id in ENV_READERS
and node.args
and isinstance(node.args[0], ast.Constant)
and isinstance(node.args[0].value, str)
):
names.add(node.args[0].value)
return names - NOT_USER_SETTINGS
def _env_vars_in_template() -> set[str]:
names = set()
for line in ENV_TEMPLATE.read_text().splitlines():
key, sep, _ = line.lstrip("# ").partition("=")
if sep and key.isupper():
names.add(key)
return names
# The dev container only mounts backend/, so env.template isn't there.
@pytest.mark.skipif(
not ENV_TEMPLATE.exists(), reason="env.template is not in this checkout"
)
def test_env_template_lists_every_env_var_the_config_reads() -> None:
missing = _env_vars_read_by_config() - _env_vars_in_template()
assert not missing, f"env.template is missing {sorted(missing)}"