mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-05-25 11:10:18 +00:00
fix: consolidate __CACHE_VERSION__ → __WEBUI_VERSION__ (#1509)
__CACHE_VERSION__ (sw.js) and __WEBUI_VERSION__ (index.html) are functionally identical — both resolve to quote(WEBUI_VERSION, safe='') at request time. Two names exist for historical reasons (different files added at different times). Rename __CACHE_VERSION__ → __WEBUI_VERSION__ in: - static/sw.js (CACHE_NAME + VQ constant + comment) - api/routes.py (substitution string) - tests/test_pwa_manifest_sw.py (all assertions) Single canonical name. No behavior change — same ?v=vX.Y.Z query strings on the same URLs.
This commit is contained in:
+1
-1
@@ -1188,7 +1188,7 @@ def handle_get(handler, parsed) -> bool:
|
||||
from api.updates import WEBUI_VERSION
|
||||
version_token = quote(WEBUI_VERSION, safe="")
|
||||
text = sw_path.read_text(encoding="utf-8").replace(
|
||||
"__CACHE_VERSION__", version_token
|
||||
"__WEBUI_VERSION__", version_token
|
||||
)
|
||||
data = text.encode("utf-8")
|
||||
handler.send_response(200)
|
||||
|
||||
+3
-3
@@ -7,18 +7,18 @@
|
||||
|
||||
// Cache version is injected by the server at request time (routes.py /sw.js handler).
|
||||
// Bumps automatically whenever the git commit changes — no manual edits needed.
|
||||
const CACHE_NAME = 'hermes-shell-__CACHE_VERSION__';
|
||||
const CACHE_NAME = 'hermes-shell-__WEBUI_VERSION__';
|
||||
|
||||
// Static assets that form the app shell.
|
||||
//
|
||||
// Versioned assets (CSS + JS) include `?v=__CACHE_VERSION__` to match the
|
||||
// Versioned assets (CSS + JS) include `?v=__WEBUI_VERSION__` to match the
|
||||
// query string the page sends — see index.html. Without the version query
|
||||
// here, every cache lookup against `?v=...` URLs would miss and fall through
|
||||
// to network, defeating the pre-cache.
|
||||
//
|
||||
// Unversioned assets (`./`, manifest.json, favicons) are referenced from
|
||||
// index.html without a cache-bust query, so they stay unversioned here too.
|
||||
const VQ = '?v=__CACHE_VERSION__';
|
||||
const VQ = '?v=__WEBUI_VERSION__';
|
||||
const SHELL_ASSETS = [
|
||||
'./',
|
||||
'./static/style.css' + VQ,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Covers:
|
||||
- manifest.json is valid JSON with required PWA fields
|
||||
- sw.js has the `__CACHE_VERSION__` placeholder the server replaces at request time
|
||||
- sw.js has the `__WEBUI_VERSION__` placeholder the server replaces at request time
|
||||
- sw.js offline-fallback uses a resolved promise (not `caches.match() || fallback`
|
||||
which is broken — Promise objects are always truthy in `||` checks, so the
|
||||
fallback Response would never be used)
|
||||
@@ -52,8 +52,8 @@ class TestManifest:
|
||||
class TestServiceWorker:
|
||||
def test_sw_has_cache_version_placeholder(self):
|
||||
src = SW.read_text(encoding="utf-8")
|
||||
assert "__CACHE_VERSION__" in src, (
|
||||
"sw.js must contain __CACHE_VERSION__ placeholder for the server "
|
||||
assert "__WEBUI_VERSION__" in src, (
|
||||
"sw.js must contain __WEBUI_VERSION__ placeholder for the server "
|
||||
"handler at /sw.js to replace with WEBUI_VERSION at request time"
|
||||
)
|
||||
|
||||
@@ -117,8 +117,8 @@ class TestPWARoutes:
|
||||
idx = src.find('"/sw.js"')
|
||||
assert idx != -1, "routes.py must handle /sw.js"
|
||||
block = src[idx:idx + 1000]
|
||||
assert "__CACHE_VERSION__" in block, (
|
||||
"sw.js route must replace __CACHE_VERSION__ with the current WEBUI_VERSION"
|
||||
assert "__WEBUI_VERSION__" in block, (
|
||||
"sw.js route must replace __WEBUI_VERSION__ with the current WEBUI_VERSION"
|
||||
)
|
||||
assert "WEBUI_VERSION" in block, (
|
||||
"sw.js route must import and use WEBUI_VERSION for cache busting"
|
||||
@@ -185,7 +185,7 @@ class TestIndexHtmlIntegration:
|
||||
|
||||
def test_sw_shell_assets_match_versioned_asset_urls(self):
|
||||
"""The service worker's SHELL_ASSETS pre-cache list must use the same
|
||||
`?v=__CACHE_VERSION__` suffix on JS+CSS that index.html sends, so that
|
||||
`?v=__WEBUI_VERSION__` suffix on JS+CSS that index.html sends, so that
|
||||
the pre-cached entries actually serve when the page requests them.
|
||||
|
||||
Without this, every `cache.match()` for a versioned asset URL (e.g.
|
||||
@@ -208,13 +208,13 @@ class TestIndexHtmlIntegration:
|
||||
"terminal.js",
|
||||
"onboarding.js",
|
||||
):
|
||||
# Either inline `?v=__CACHE_VERSION__` or via the VQ constant
|
||||
# Either inline `?v=__WEBUI_VERSION__` or via the VQ constant
|
||||
# produces a URL string the cache lookup can match.
|
||||
has_inline = f"{asset}?v=__CACHE_VERSION__" in src
|
||||
has_inline = f"{asset}?v=__WEBUI_VERSION__" in src
|
||||
has_concat = f"{asset}' + VQ" in src or f"{asset}\" + VQ" in src
|
||||
assert has_inline or has_concat, (
|
||||
f"sw.js SHELL_ASSETS entry for {asset} must carry "
|
||||
"?v=__CACHE_VERSION__ to match the URL the page requests"
|
||||
"?v=__WEBUI_VERSION__ to match the URL the page requests"
|
||||
)
|
||||
|
||||
def test_index_route_url_encodes_asset_version(self):
|
||||
|
||||
Reference in New Issue
Block a user