mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-11 05:06:36 +00:00
CI run 40979252521 WordPress#0 (swarm, variant 0, onion pick): the block editor canvas stayed transparent (rgba(0, 0, 0, 0) instead of --design-surface-1). The trace shows the canvas iframe requesting https://cdn.main.infinito.test/_shared/css/default.css and the onion page's CSP (style-src-elem 'self' http://cdn.<onion> ...) blocking it; the clearnet pass of the same spec was green. design.php writes WORDPRESS_DESIGN_CONFIG.tokens into the infinito_design option once for every network sibling, so an absolute CDN host pins the onion editor to clearnet.
The token sheet now uses the cdn lookup's relative_urls, rendering /_infinito/cdn/_shared/css/default.css. WordPress prefixes a relative style source with site_url(), which infinito-network-origins derives from the request host, and every generic vhost serves /_infinito/cdn/ (basic.conf.j2 includes cdn.conf.j2), so the canvas loads from the page's origin on both networks. Same approach as the Joomla TinyMCE fix 175e00218f. test_design_tokens.py renders the tokens through the real cdn lookup and fails on the old URL.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
from unittest import 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 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()
|