~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
fix(web): serve theme CSS from bundled themes (#7039)
LearningCircuit242d340c2b8c
diff --git a/.github/scripts/package_artifact_policy.py b/.github/scripts/package_artifact_policy.pyindex 48eee9d4f6..4a8ad6d327 100644--- a/.github/scripts/package_artifact_policy.py+++ b/.github/scripts/package_artifact_policy.py@@ -112,6 +112,14 @@ def _logical_path(name: str, *, sdist_root: str | None) -> PurePosixPath | None:def _path_policy_error(path: PurePosixPath) -> str | None:+ if path.parts[-5:] == (+ "local_deep_research",+ "web",+ "static",+ "css",+ "themes.css",+ ):+ return "generated theme CSS must not be packaged"lowered = tuple(part.lower() for part in path.parts)forbidden = sorted(FORBIDDEN_COMPONENTS.intersection(lowered))if forbidden:diff --git a/changelog.d/+theme-css-readonly-install.bugfix.md b/changelog.d/+theme-css-readonly-install.bugfix.mdnew file mode 100644index 0000000000..5b14d43324--- /dev/null+++ b/changelog.d/+theme-css-readonly-install.bugfix.md@@ -0,0 +1 @@+Serve theme CSS from bundled theme files so pip installations work when the application cannot write into its installed package.diff --git a/pyproject.toml b/pyproject.tomlindex 54b5b81e76..2d613ea788 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -247,7 +247,9 @@ version = { source = "file", path = "src/local_deep_research/__version__.py" }# PDM includes tests/ in source distributions by default. The complete test# suite is maintained in Git and CI, but is not needed to build or install the# package; shipping it made the v1.10.7 sdist roughly twice the necessary size.-excludes = ["tests/"]+# themes.css is generated on boot in a writable source checkout and must not+# make release artifacts depend on whether a build ran after an app test.+excludes = ["tests/", "src/local_deep_research/web/static/css/themes.css"][[tool.pdm.source]]url = "https://download.pytorch.org/whl/cpu"diff --git a/src/local_deep_research/web/static_files.py b/src/local_deep_research/web/static_files.pyindex c59ae593d1..5d1e8dab6b 100644--- a/src/local_deep_research/web/static_files.py+++ b/src/local_deep_research/web/static_files.py@@ -1,9 +1,10 @@"""Shared asset lookup for current and legacy static URLs."""import re+from functools import lru_cachefrom pathlib import Path-from fastapi.responses import FileResponse+from fastapi.responses import FileResponse, Responsefrom ..security.path_validator import PathValidator@@ -13,17 +14,35 @@ _REVALIDATE = "public, max-age=0, must-revalidate"_IMMUTABLE = "public, max-age=31536000, immutable"-def static_file_response(path: str) -> FileResponse | None:+@lru_cache(maxsize=1)+def _combined_theme_css() -> str:+ from .themes import theme_registry++ return theme_registry.get_combined_css()+++def static_file_response(path: str) -> FileResponse | Response | None:"""Serve a contained asset, preferring Vite output over source files.- The root is always the app's ``STATIC_DIR``, read per call; there is- deliberately no directory parameter, so no caller can point this- helper at another tree (e.g. the shared research-outputs directory).+ Except for CSS composed from bundled themes, the root is always the+ app's ``STATIC_DIR``, read per call. There is deliberately no directory+ parameter, so no caller can point this helper at another tree (e.g. the+ shared research-outputs directory).Explicit ``dist/`` URLs and implicit build paths use the same cachepolicy. Invalid paths, failed lookups and symlink escapes are misses;callers retain their route's existing 404 response format."""+ # A clean wheel does not contain this generated file, and an installed+ # package may be read-only for the service user. Serve it from the bundled+ # theme sources instead of relying on the best-effort startup write.+ if path == "css/themes.css":+ return Response(+ _combined_theme_css(),+ media_type="text/css",+ headers={"Cache-Control": _REVALIDATE},+ )+from .fastapi_app import STATIC_DIRtry:diff --git a/tests/ci/test_package_artifact_policy.py b/tests/ci/test_package_artifact_policy.pyindex 9337a8d78b..7f0af20027 100644--- a/tests/ci/test_package_artifact_policy.py+++ b/tests/ci/test_package_artifact_policy.py@@ -111,6 +111,22 @@ def test_sdist_rejects_development_only_content(tmp_path, member):assert member in result.stderr[email protected]("artifact_type", ["wheel", "sdist"])+def test_generated_theme_css_is_not_shipped(tmp_path, artifact_type):+ path = "src/local_deep_research/web/static/css/themes.css"+ if artifact_type == "wheel":+ artifact = tmp_path / "local_deep_research-1.0.0-py3-none-any.whl"+ _write_wheel(artifact, {path.removeprefix("src/"): b"generated\n"})+ else:+ artifact = tmp_path / "local_deep_research-1.0.0.tar.gz"+ _write_sdist(artifact, {path: b"generated\n"})++ result = _run_policy(artifact)++ assert result.returncode == 1+ assert "generated theme CSS" in result.stderr++def test_disguised_binary_content_is_rejected(tmp_path):artifact = tmp_path / "local_deep_research-1.0.0-py3-none-any.whl"_write_wheel(@@ -210,10 +226,13 @@ def test_dist_directory_rejects_extra_or_missing_artifacts(tmp_path):assert "expected exactly one sdist" in result.stderr-def test_pdm_build_excludes_the_full_test_tree_from_sdists():+def test_pdm_build_excludes_tests_and_generated_theme_css():config = tomllib.loads(PYPROJECT.read_text(encoding="utf-8"))- assert config["tool"]["pdm"]["build"]["excludes"] == ["tests/"]+ assert config["tool"]["pdm"]["build"]["excludes"] == [+ "tests/",+ "src/local_deep_research/web/static/css/themes.css",+ ]@pytest.mark.parametrize(diff --git a/tests/web/test_static_file_serving.py b/tests/web/test_static_file_serving.pyindex 220af6e8ec..a2825e4f44 100644--- a/tests/web/test_static_file_serving.py+++ b/tests/web/test_static_file_serving.py@@ -55,6 +55,7 @@ import errnoimport mimetypesimport osimport re+import statfrom email.utils import parsedate_to_datetimefrom pathlib import Pathfrom types import SimpleNamespace@@ -818,8 +819,8 @@ class TestDistBranches:def test_static_file_response_can_only_serve_static_dir(isolated_static):"""The shared helper takes no directory, so no caller can point it at- another tree (e.g. the research-outputs directory) and bypass the- reports-dir fence that allowlists ``static_files.py``."""+ another tree (e.g. research outputs) and bypass that directory's fence.+ Its fixed theme CSS response comes from bundled theme sources only."""import inspectfrom local_deep_research.web.static_files import static_file_response@@ -829,6 +830,33 @@ def test_static_file_response_can_only_serve_static_dir(isolated_static):assert static_file_response("../outside/secret.txt") is None[email protected]("prefix", ["static", "redirect-static"])+def test_theme_css_works_without_a_writable_package_directory(+ isolated_static, prefix+):+ """A clean wheel has no generated CSS, and installed code may be read-only."""+ from local_deep_research.web.themes import theme_registry++ css_path = isolated_static.static_dir / "css" / "themes.css"+ assert not css_path.exists()++ css_dir = css_path.parent+ original_mode = stat.S_IMODE(css_dir.stat().st_mode)+ css_dir.chmod(0o555)+ try:+ response = isolated_static.client.get(f"/{prefix}/css/themes.css")+ finally:+ css_dir.chmod(original_mode)++ assert response.status_code == 200+ assert response.text == theme_registry.get_combined_css()+ assert response.headers["content-type"] == "text/css; charset=utf-8"+ assert response.headers["cache-control"] == (+ "public, max-age=0, must-revalidate"+ )+ assert not css_path.exists()++# ---------------------------------------------------------------------------# Legacy /redirect-static shim# ---------------------------------------------------------------------------