mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-05-24 10:40:16 +00:00
fbe84d26e6
From PR #1337. Co-authored-by: Dennis Soong <dso2ng@gmail.com>
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
"""Regression tests for service worker API cache exclusion under subpath mounts.
|
|
|
|
The WebUI can be served at /hermes/. In that deployment API requests look like
|
|
/hermes/api/sessions, not /api/sessions. The service worker must treat those as
|
|
network-only; otherwise cache-first handling can serve a stale sidebar session
|
|
list until the browser cache/service-worker cache is cleared.
|
|
"""
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SW_SRC = (ROOT / "static" / "sw.js").read_text(encoding="utf-8")
|
|
|
|
|
|
def test_service_worker_excludes_subpath_mounted_api_routes_from_cache():
|
|
assert "url.pathname.includes('/api/')" in SW_SRC, (
|
|
"service worker must bypass cache for subpath-mounted API routes like "
|
|
"/hermes/api/sessions, not only root-mounted /api/*"
|
|
)
|
|
|
|
|
|
def test_service_worker_excludes_subpath_mounted_health_routes_from_cache():
|
|
assert "url.pathname.includes('/health')" in SW_SRC, (
|
|
"service worker must bypass cache for subpath-mounted health routes like "
|
|
"/hermes/health, not only root-mounted /health"
|
|
)
|
|
|
|
|
|
def test_service_worker_documents_api_routes_are_never_cached():
|
|
assert "API and streaming endpoints" in SW_SRC
|
|
assert "always go to network" in SW_SRC
|
|
|
|
|
|
def test_service_worker_does_not_intercept_its_own_script():
|
|
assert "url.pathname.endsWith('/sw.js')" in SW_SRC, (
|
|
"service worker must bypass /sw.js so a stale cached worker cannot block cache-version updates"
|
|
)
|