diff --git a/api/routes.py b/api/routes.py index 8c4bc834..863680c5 100644 --- a/api/routes.py +++ b/api/routes.py @@ -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) diff --git a/static/sw.js b/static/sw.js index 9e43db66..cb8e2071 100644 --- a/static/sw.js +++ b/static/sw.js @@ -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, diff --git a/tests/test_pwa_manifest_sw.py b/tests/test_pwa_manifest_sw.py index 40220dec..c5e46982 100644 --- a/tests/test_pwa_manifest_sw.py +++ b/tests/test_pwa_manifest_sw.py @@ -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):