mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
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>
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
import re
|
|
import unittest
|
|
|
|
from utils.cache.files import read_text
|
|
|
|
from . import PROJECT_ROOT
|
|
|
|
|
|
class TestJinjaIncludePaths(unittest.TestCase):
|
|
"""
|
|
Verifies that in all .j2 files in the project (root + subfolders):
|
|
- Every {% include 'string/path' %} or {% include "string/path" %} refers to an existing file.
|
|
- Any include using a variable or concatenation is ignored.
|
|
- Includes are resolved relative to project root, template directory, or file's parent.
|
|
"""
|
|
|
|
INCLUDE_STMT_RE = re.compile(r"{%\s*include\s+(.+?)\s*%}")
|
|
LITERAL_PATH_RE = re.compile(r"^[\'\"]([^\'\"]+)[\'\"]$")
|
|
|
|
def test_all_jinja_includes_exist(self):
|
|
template_paths = list(PROJECT_ROOT.glob("**/*.j2"))
|
|
self.assertTrue(
|
|
template_paths, "No .j2 templates found anywhere in the project"
|
|
)
|
|
|
|
missing = []
|
|
for tpl in template_paths:
|
|
text = read_text(str(tpl))
|
|
for stmt in self.INCLUDE_STMT_RE.finditer(text):
|
|
expr = stmt.group(1).strip()
|
|
m = self.LITERAL_PATH_RE.match(expr)
|
|
if not m:
|
|
continue
|
|
|
|
include_path = m.group(1)
|
|
abs_target = PROJECT_ROOT / include_path
|
|
rel_target = tpl.parent / include_path
|
|
|
|
role_templates_root = None
|
|
for parent in tpl.parents:
|
|
if parent.name == "templates":
|
|
role_templates_root = parent
|
|
break
|
|
role_target = None
|
|
if role_templates_root:
|
|
role_target = role_templates_root / include_path
|
|
|
|
if not (
|
|
abs_target.exists()
|
|
or rel_target.exists()
|
|
or (role_target and role_target.exists())
|
|
):
|
|
rel_tpl = tpl.relative_to(PROJECT_ROOT)
|
|
missing.append(
|
|
f"{rel_tpl}: included file '{include_path}' not found "
|
|
f"(checked in project root, {tpl.parent.relative_to(PROJECT_ROOT)} or templates folder)"
|
|
)
|
|
|
|
if missing:
|
|
self.fail("Broken {% include %} references:\n" + "\n".join(missing))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|