~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
"""Light palettes must stay readable on cards, inputs and tinted status panels."""
import re
from pathlib import Path
import pytest
from local_deep_research.web.themes import theme_registry
from local_deep_research.web.themes.loader import ThemeLoader
from local_deep_research.web.themes.schema import (
LIGHT_THEME_REQUIRED_VARIABLES,
)
# Use the same discovery and classification as the rendered theme selector.
LIGHT_THEMES = sorted(
(
theme
for theme in theme_registry.themes.values()
if theme.type == "light"
),
key=lambda theme: theme.id,
)
def test_light_themes_are_discovered():
"""An empty LIGHT_THEMES would make the parametrized check below skip
("got empty parameter set") instead of failing, e.g. if frontmatter
parsing broke and every theme fell back to type "dark"."""
assert "sepia" in {theme.id for theme in LIGHT_THEMES}
assert len(LIGHT_THEMES) >= 2
def _rgb(color):
return tuple(int(color[index : index + 2], 16) for index in (1, 3, 5))
def _luminance(rgb):
channels = [channel / 255 for channel in rgb]
linear = [
channel / 12.92
if channel <= 0.04045
else ((channel + 0.055) / 1.055) ** 2.4
for channel in channels
]
return sum(
value * weight
for value, weight in zip(linear, (0.2126, 0.7152, 0.0722))
)
def _contrast(foreground, background):
dark, light = sorted((_luminance(foreground), _luminance(background)))
return (light + 0.05) / (dark + 0.05)
@pytest.mark.parametrize("theme", LIGHT_THEMES, ids=lambda theme: theme.id)
def test_light_theme_text_contrast(theme):
"""Normal text needs 4.5:1 even on the darkest input/card surface."""
assert theme.css_path is not None
# Ignore commented-out declarations: the browser does, so a token that
# only exists inside /* */ must count as missing here too.
css = re.sub(
r"/\*.*?\*/",
"",
theme.css_path.read_text(encoding="utf-8"),
flags=re.DOTALL,
)
colors = {
key: _rgb(value)
for key, value in re.findall(r"--([\w-]+):\s*(#[\da-fA-F]{6});", css)
}
# Dark palettes inherit these from styles.css; light palettes must not.
missing = [
var
for var in LIGHT_THEME_REQUIRED_VARIABLES
if var.removeprefix("--") not in colors
]
assert not missing, (
f"light theme {theme.id} must define {missing} as #rrggbb "
"(see LIGHT_THEME_REQUIRED_VARIABLES in web/themes/schema.py)"
)
# Tints are drawn from the --*-rgb twins; they must match the hex tokens
# this test checks, or a darkened hex would pass while pills render the
# old color.
triplets = {
key: tuple(int(part) for part in value.split(","))
for key, value in re.findall(
r"--([\w-]+)-rgb:\s*(\d+\s*,\s*\d+\s*,\s*\d+)\s*;", css
)
}
for token in (
"accent-primary",
"accent-secondary",
"accent-tertiary",
"success-color",
"warning-color",
"error-color",
):
assert token in triplets, f"{theme.id} must define --{token}-rgb"
assert triplets[token] == colors[token], (
f"{theme.id}: --{token}-rgb {triplets[token]} does not match "
f"--{token} {colors[token]}"
)
backgrounds = [
colors[f"bg-{surface}"]
for surface in ("primary", "secondary", "tertiary")
]
# Essential control boundaries must remain visible independently of text.
for background in backgrounds:
assert _contrast(colors["control-border"], background) >= 3.0
text_tokens = (
"text-primary",
"text-secondary",
"text-muted",
"accent-primary",
"accent-secondary",
"accent-tertiary",
"success-color",
"warning-color",
"error-color",
)
for token in text_tokens:
for background in backgrounds:
assert _contrast(colors[token], background) >= 4.5, token
# Alerts, status pills and selected controls tint the surface with their
# own ink (rgba(var(--token-rgb), alpha) behind color: var(--token)).
# This models the strongest *flat, same-rule* tint of that shape found in
# the component CSS for each token (a stronger tint lowers contrast, so
# weaker flat tints of that shape are covered too). Most of these surfaces
# (status pills, settings alerts) only appear with data or after an
# action, so the rendered axe run cannot be relied on for them. The
# browser composites to 8-bit channels, so check the rounded blend too.
#
# Known gaps, NOT modelled here (pre-existing, accent-primary ink on a
# stronger gradient tint of itself, most below 4.5:1 on bg-tertiary but
# rendered on lighter card surfaces):
# notes.css .ldr-note-tag (20% gradient stop),
# notes.css .ldr-similarity-badge (15%),
# note_detail.html .ldr-note-tag / .ldr-wiki-link (15%, :hover 25%),
# note_detail.html .ldr-suggested-tag:hover (success-color, 25%).
# Tints whose ink and background come from different rules are modelled
# only where listed in SPLIT_RULE_HIGHLIGHTS below.
strongest_self_tint = {
"accent-primary": 0.12, # .ldr-tag
"accent-tertiary": 0.2, # .ldr-status-indicator, settings alert
"success-color": 0.2, # .ldr-status-indicator, settings alert
"warning-color": 0.2, # settings .ldr-alert-warning
"error-color": 0.2, # .ldr-status-indicator, settings alert
}
for token, alpha in strongest_self_tint.items():
ink = colors[token]
for background in backgrounds:
tinted = tuple(
alpha * fg + (1 - alpha) * bg for fg, bg in zip(ink, background)
)
for surface in (tinted, tuple(round(c) for c in tinted)):
assert _contrast(ink, surface) >= 4.5, (
f"{token} on a {alpha:.0%} tint of its own color"
)
# Existing filled controls use white labels; warning badges have a token.
for token in (
"accent-primary",
"accent-secondary",
"accent-tertiary",
"success-color",
"error-color",
):
assert _contrast((255, 255, 255), colors[token]) >= 4.5, (
f"label on {token}"
)
assert _contrast(colors["text-on-warning"], colors["warning-color"]) >= 4.5
assert _contrast(colors["text-on-error"], colors["error-color"]) >= 4.5
assert _contrast(colors["text-on-success"], colors["success-color"]) >= 4.5
CSS_ROOT = (
Path(__file__).resolve().parents[2]
/ "src"
/ "local_deep_research"
/ "web"
/ "static"
/ "css"
)
# Search-match highlights whose ink, list surface, row tint and highlight
# tint come from different rules (and files). Each entry names
# (file, selector, property) for: the ink, the list surface, the
# hover/active row tint the highlight stacks on, and the highlight tint.
SPLIT_RULE_HIGHLIGHTS = {
"custom dropdown filter highlight": {
"ink": (
"styles.css",
".ldr-custom-dropdown-item .ldr-highlight",
"color",
),
"surface": (
"custom_dropdown.css",
".ldr-custom-dropdown-list",
"background-color",
),
"row_tint": (
"custom_dropdown.css",
".ldr-custom-dropdown-item.active",
"background-color",
),
"tint": (
"custom_dropdown.css",
".ldr-custom-dropdown-item .ldr-highlight",
"background-color",
),
},
"note wiki-link picker highlight": {
"ink": ("notes.css", ".ldr-wiki-link-item-title", "color"),
"surface": ("notes.css", ".ldr-wiki-link-dropdown", "background"),
"row_tint": ("notes.css", ".ldr-wiki-link-item.active", "background"),
"tint": (
"notes.css",
".ldr-wiki-link-item-title .ldr-highlight",
"background",
),
},
}
def _css_values(filename, selector, prop):
"""Every value ``prop`` takes in a rule listing ``selector``."""
css = re.sub(
r"/\*.*?\*/",
"",
(CSS_ROOT / filename).read_text(encoding="utf-8"),
flags=re.DOTALL,
)
values = []
for match in re.finditer(r"([^{}]*)\{([^{}]*)\}", css):
selectors = [
" ".join(part.split()) for part in match.group(1).split(",")
]
if selector not in selectors:
continue
for decl in match.group(2).split(";"):
name, sep, value = decl.partition(":")
if sep and name.strip().lower() == prop:
values.append(" ".join(value.split()))
assert values, f"{filename}: no {prop} in a rule for {selector!r}"
return values
def _token(filename, selector, prop):
tokens = {
match.group(1)
for value in _css_values(filename, selector, prop)
for match in [re.match(r"var\(--([\w-]+)", value)]
if match
}
assert len(tokens) == 1, (
f"{filename} {selector} {prop}: expected one var(--token), "
f"got {_css_values(filename, selector, prop)}"
)
return tokens.pop()
def _accent_tint(filename, selector, prop):
"""Strongest rgba(var(--accent-primary-rgb), a) alpha for the rule."""
alphas = []
for value in _css_values(filename, selector, prop):
match = re.fullmatch(
r"rgba\(\s*var\(--accent-primary-rgb\)\s*,\s*([\d.]+)\s*\)"
r"(?:\s*!important)?",
value,
)
assert match, (
f"{filename} {selector} {prop}: {value!r} is not a flat "
"accent-primary tint; update SPLIT_RULE_HIGHLIGHTS"
)
alphas.append(float(match.group(1)))
return max(alphas)
def _blend(foreground, background, alpha):
return tuple(
alpha * fg + (1 - alpha) * bg for fg, bg in zip(foreground, background)
)
@pytest.mark.parametrize("theme", LIGHT_THEMES, ids=lambda theme: theme.id)
@pytest.mark.parametrize("name", sorted(SPLIT_RULE_HIGHLIGHTS))
def test_split_rule_highlight_contrast(theme, name):
"""A search-match highlight must stay 4.5:1 on its tint, including when
the tint stacks on the hovered/active row's own accent tint."""
spec = SPLIT_RULE_HIGHLIGHTS[name]
css = re.sub(
r"/\*.*?\*/",
"",
theme.css_path.read_text(encoding="utf-8"),
flags=re.DOTALL,
)
colors = {
key: _rgb(value)
for key, value in re.findall(r"--([\w-]+):\s*(#[\da-fA-F]{6});", css)
}
ink = colors[_token(*spec["ink"])]
surface = colors[_token(*spec["surface"])]
accent = colors["accent-primary"]
row_alpha = _accent_tint(*spec["row_tint"])
tint_alpha = _accent_tint(*spec["tint"])
for under in (surface, _blend(accent, surface, row_alpha)):
for rounded in (False, True):
base = tuple(round(c) for c in under) if rounded else under
tinted = _blend(accent, base, tint_alpha)
if rounded:
tinted = tuple(round(c) for c in tinted)
ratio = _contrast(ink, tinted)
assert ratio >= 4.5, (
f"{name}: {ratio:.2f}:1 on a {tint_alpha:.0%} accent tint "
f"(row tint {row_alpha:.0%}) in {theme.id}"
)
def test_declared_custom_properties_matches_real_declarations_only():
"""The loader's light-theme warning relies on this declaration scan."""
loader = ThemeLoader(Path(__file__).parent)
declared = loader.declared_custom_properties(
'[data-theme="x"] { --control-border: #111; --text-on-warning: #fff; }'
"\n.y {\n --a: #111;\n border: 1px solid var(--used-only);\n"
" --control-border-hover: #222;\n}\n"
"/* --commented-out: #333; */",
)
assert declared == {
"--control-border",
"--text-on-warning",
"--a",
"--control-border-hover",
}