Files
computer-playbook/tests/integration/roles/playwright/test_env_service_flags.py
T
kevinveenbirkenbachandClaude Opus 5 5137465c6f style: delete every comment the comments-valid policy rejects
3529 invalid comments in 528 files, grandfathered in while the linter
only saw the working-tree diff. Removal ran through the linter's own
collectors, so detection and deletion cannot drift: a comment whose
opener line is blank before it and whose closer line is blank after it
loses all its lines, anything else loses only the comment region, and a
line left holding a bare delimiter goes with it.

Five files keep their comments behind a nocheck marker instead. Four are
upstream configs whose inline docs are upstream's own (mautrix, systemd
journald, nextcloud-oidc-login, MediaWiki). In littlejs the
commented-out entries ARE the deactivation mechanism for an example
tile, so deleting them would delete configuration.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 03:22:02 +02:00

68 lines
2.3 KiB
Python

"""Guard: roles that already emit `<SERVICE>_SERVICE_ENABLED` flags in
their Playwright env template MUST follow the strict "true"/"false"
literal contract from the env-flag rules.
Every `<SERVICE>_SERVICE_ENABLED=...` line MUST resolve at deploy time
to either the literal "true" or "false" string. No other value is
permitted. This test only checks the template source to catch drift
(e.g. a developer writing `... else '0'` by mistake) — it does not
execute Jinja; the deploy-time rendering is the authoritative check.
"""
import os
import re
import unittest
from pathlib import Path
from . import PROJECT_ROOT
ROLES_DIR = str(PROJECT_ROOT / "roles")
SERVICE_FLAG_LINE = re.compile(
r"^([A-Z][A-Z0-9_]+)_SERVICE_ENABLED\s*=\s*(.*)$",
re.MULTILINE,
)
def _iter_env_templates():
for role in sorted(os.listdir(ROLES_DIR)):
tmpl = str(Path(ROLES_DIR) / role / "templates" / "playwright.env.j2")
if Path(tmpl).is_file():
yield role, tmpl
class TestPlaywrightEnvServiceFlags(unittest.TestCase):
def test_every_flag_renders_strict_true_or_false(self):
offenders = []
for role, path in _iter_env_templates():
with Path(path).open(encoding="utf-8") as f:
content = f.read()
for match in SERVICE_FLAG_LINE.finditer(content):
rhs = match.group(2).strip()
if rhs in ("true", "false"):
continue
looks_like_ternary = "{{" in rhs and (
("'true'" in rhs and "'false'" in rhs)
or ('"true"' in rhs and '"false"' in rhs)
)
if looks_like_ternary:
continue
looks_like_string_lower = "{{" in rhs and re.search(
r"\|\s*string\s*\|\s*lower\b", rhs
)
if looks_like_string_lower:
continue
offenders.append(f"{role}: {match.group(1)}_SERVICE_ENABLED = {rhs}")
self.assertEqual(
offenders,
[],
msg=(
"Playwright env service flags MUST resolve to literal "
'"true" or "false". Offenders:\n' + "\n".join(offenders)
),
)
if __name__ == "__main__":
unittest.main()