Files
kevinveenbirkenbachandClaude Opus 5.5 326f063bd3 fix(codescan): clear the mechanical CodeQL notes and lint them away (WIP)
Work-in-progress commit on the collective code-scanning sidetree, so main
can be merged in; the single quality-high gate runs on the integration
branch before the pull request.

Fixes the CodeQL notes py/import-and-import-from, py/unused-import,
py/unused-global-variable, py/empty-except, py/mixed-tuple-returns and
py/unused-local-variable across 194 files, and adds one lint per rule under
tests/lint/repository/python/ so none of them can come back:
test_import_and_import_from, test_unused_imports_hidden_from_ruff,
test_unused_global_variables, test_empty_except, test_mixed_tuple_returns,
test_unused_local_variables, plus test_modules_import.

Accepted security finding: MEDUSA-MP-SCAN-2056 (low) on
utils/i18n/client.py:21, an import line matched by a keyword heuristic;
operator-confirmed false positive.

🎯 Fix: 85 %
💥 Break: 8 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 78
🚦 Gate: ⛔ fix 85 % < 90, break 8 % > 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 18:44:29 +00:00

71 lines
2.2 KiB
Python

from __future__ import annotations
import unittest
import unittest.mock
from ansible.parsing.dataloader import DataLoader
from ansible.plugins.loader import lookup_loader
from ansible.plugins.lookup import LookupBase
from ansible.template import Templar
from plugins.lookup.cdn import LookupModule as CdnLookup
from utils.roles.mapping import ROLE_FILE_VARS_MAIN
from . import PROJECT_ROOT
VARS = PROJECT_ROOT / "roles" / "web-app-wordpress" / ROLE_FILE_VARS_MAIN
CDN_ROOT = "/var/www/public/cdn"
CDN_URL = "https://cdn.example.test/"
class _Stub(LookupBase):
def __init__(self, answer):
super().__init__()
self._answer = answer
def run(self, terms, variables=None, **kwargs):
return [self._answer(*terms)]
def render_tokens() -> list[str]:
"""Render ``WORDPRESS_DESIGN_CONFIG.tokens`` through the real ``cdn`` lookup.
Returns:
The token stylesheet URLs the deploy writes into the ``infinito_design``
option, with the CDN served at ``CDN_URL`` from ``CDN_ROOT``.
"""
stubs = {"nginx": lambda _key: CDN_ROOT, "tls": lambda _app, _key: CDN_URL}
real_get = lookup_loader.get
def get(name, *args, **kwargs):
if name == "cdn":
lookup = CdnLookup()
lookup._loader = kwargs.get("loader")
lookup._templar = None
return lookup
if name in stubs:
return _Stub(stubs[name])
return real_get(name, *args, **kwargs)
declared = DataLoader().load_from_file(str(VARS), trusted_as_template=True)
templar = Templar(loader=DataLoader(), variables={})
with unittest.mock.patch.object(lookup_loader, "get", side_effect=get):
return [
templar.template(token)
for token in declared["WORDPRESS_DESIGN_CONFIG"]["tokens"]
]
class TestEditorCanvasTokens(unittest.TestCase):
def test_the_token_sheets_load_from_the_page_host(self) -> None:
self.assertEqual(
render_tokens(),
["/_infinito/cdn/_shared/css/default.css"],
"the option is written once for every network sibling, so an absolute CDN "
"host sends the onion editor canvas to clearnet",
)
if __name__ == "__main__":
unittest.main()