mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 08:00:13 +01:00
feat(web): Core Refactor Phase A — extract sampling and cache modules; add adaptive TTL + eviction heuristics, Redis PoC, and metrics wiring. Tests added for TTL, eviction, exports, splash-adaptive, card index, and service worker. Docs+roadmap updated.
This commit is contained in:
parent
c4a7fc48ea
commit
a029d430c5
49 changed files with 3889 additions and 701 deletions
23
code/tests/test_preview_eviction_basic.py
Normal file
23
code/tests/test_preview_eviction_basic.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import os
|
||||
from code.web.services.theme_preview import get_theme_preview, bust_preview_cache # type: ignore
|
||||
from code.web.services import preview_cache as pc # type: ignore
|
||||
|
||||
|
||||
def test_basic_low_score_eviction(monkeypatch):
|
||||
"""Populate cache past limit using distinct color filters to force eviction."""
|
||||
os.environ['THEME_PREVIEW_CACHE_MAX'] = '5'
|
||||
bust_preview_cache()
|
||||
colors_seq = [None, 'W', 'U', 'B', 'R', 'G'] # 6 unique keys (slug, limit fixed, colors vary)
|
||||
# Prime first key with an extra hit to increase protection
|
||||
first_color = colors_seq[0]
|
||||
get_theme_preview('Blink', limit=6, colors=first_color)
|
||||
get_theme_preview('Blink', limit=6, colors=first_color) # hit
|
||||
# Insert remaining distinct keys
|
||||
for c in colors_seq[1:]:
|
||||
get_theme_preview('Blink', limit=6, colors=c)
|
||||
# Cache limit 5, inserted 6 distinct -> eviction should have occurred
|
||||
assert len(pc.PREVIEW_CACHE) <= 5
|
||||
from code.web.services.preview_metrics import preview_metrics # type: ignore
|
||||
m = preview_metrics()
|
||||
assert m['preview_cache_evictions'] >= 1, 'Expected at least one eviction'
|
||||
assert m['preview_cache_evictions_by_reason'].get('low_score', 0) >= 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue