mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 13:57:43 +00:00
fix(cache): keep a mid-render domain map out of the finished one
26 roles resolve a domain in their metadata, so lookup('tls') and lookup('domains') run inside the applications render. Under the re-entry guard those calls receive the unrendered tree, whose service flags are still Jinja strings, and _as_bool reads "{{ 'svc-net-tor' in group_names }}" as false. The resulting map skipped onion injection for every app that does not enable tor literally, and it was cached, so it answered every later read in that process.
Before the applications carrier each worker rendered and poisoned its own cache the same way, which is why the shared Keycloak client registered 5 onion origins then and 65 now. The render state joins the cache key, so the render's own call sites still share one map while a later read builds the finished one.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b764b00ba3
commit
fa3797540a
3 files changed
+40
-2
No files matched your search
+32
@@ -18,6 +18,7 @@ from unittest.mock import patch
|
||||
|
||||
from utils.cache import _reset_cache_for_tests
|
||||
from utils.cache import domains as cache_domains
|
||||
from utils.cache.base import _RENDER_GUARD
|
||||
from utils.roles.mapping import ROLE_FILE_META_SERVICES, ROLE_FILE_META_USERS
|
||||
|
||||
from . import PROJECT_ROOT
|
||||
@@ -114,6 +115,37 @@ class TestCachingPerVariablesSignature(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(mocked.call_count, 2)
|
||||
|
||||
def test_a_map_built_during_the_render_never_becomes_the_finished_one(self):
|
||||
"""Under the guard the applications view is still unrendered, so its
|
||||
map must not answer a later read; it may still serve the render."""
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
roles = _seed_minimal_role(Path(tmp))
|
||||
variables = {"DOMAIN_PRIMARY": "infinito.test"}
|
||||
with patch(
|
||||
"utils.cache.applications.get_merged_applications",
|
||||
return_value={},
|
||||
) as mocked:
|
||||
_RENDER_GUARD.applications = True
|
||||
try:
|
||||
cache_domains.get_merged_domains(
|
||||
variables=variables, roles_dir=roles, templar=None
|
||||
)
|
||||
cache_domains.get_merged_domains(
|
||||
variables=variables, roles_dir=roles, templar=None
|
||||
)
|
||||
self.assertEqual(mocked.call_count, 1)
|
||||
finally:
|
||||
_RENDER_GUARD.applications = False
|
||||
cache_domains.get_merged_domains(
|
||||
variables=variables, roles_dir=roles, templar=None
|
||||
)
|
||||
self.assertEqual(mocked.call_count, 2)
|
||||
self.assertEqual(len(cache_domains._MERGED_DOMAINS_CACHE), 2)
|
||||
self.assertEqual(
|
||||
sorted(key[-1] for key in cache_domains._MERGED_DOMAINS_CACHE),
|
||||
[False, True],
|
||||
)
|
||||
|
||||
|
||||
class TestResetClearsDomainsCache(unittest.TestCase):
|
||||
def test_reset_evicts_cached_entry(self):
|
||||
|
||||
Reference in new issue
Block a user