diff --git a/docs/releases/console-3.1.33.md b/docs/releases/console-3.1.33.md new file mode 100644 index 0000000..8cd53d0 --- /dev/null +++ b/docs/releases/console-3.1.33.md @@ -0,0 +1,6 @@ +# Console 3.1.33 — content-versioned browser resources + +- The existing static file response owner fingerprints Console JS, translations and CSS in served HTML. Changing a file changes its URL even if the release label was reused. +- Retain no-store headers and existing asset endpoints. No UI controls or installation logic are duplicated. +- This hardens browser refresh after deployment; it does not prove the cause of the reported missing update button in an existing browser session. +- Tests verify stable URLs for unchanged content and invalidation for a same-version JavaScript change. diff --git a/stage-releases.json b/stage-releases.json index aec3052..8756f90 100644 --- a/stage-releases.json +++ b/stage-releases.json @@ -14,7 +14,7 @@ "version": "1.0.1" }, "stage_ui": { - "version": "3.1.32" + "version": "3.1.33" }, "stage_avahi": { "version": "1.0.0" diff --git a/stage_ui/console_core/backend/app.py b/stage_ui/console_core/backend/app.py index 77de4f1..32c197d 100644 --- a/stage_ui/console_core/backend/app.py +++ b/stage_ui/console_core/backend/app.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import glob +import hashlib import base64 import importlib.util import ipaddress @@ -60,7 +61,7 @@ APP_DIR = "/opt/iomatex-console" PUBLIC_DIR = os.path.join(APP_DIR, "public") PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d") CONFIG_PATH = "/etc/iomatex/console.json" -UI_VERSION = "V 3.1.32" +UI_VERSION = "V 3.1.33" STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health" ZONEINFO_ROOT = "/usr/share/zoneinfo" @@ -2977,6 +2978,17 @@ def get_itscreen_binary_candidates(): return [path for path in candidates if os.path.exists(path)] +def fingerprint_console_assets(html, directory): + """Invalidate browser assets on content changes, including same-version deploys.""" + text = html.decode("utf-8") + for name in ("console.js", "console.i18n.js", "console.css"): + with open(os.path.join(directory, name), "rb") as stream: + fingerprint = hashlib.sha256(stream.read()).hexdigest()[:16] + pattern = r'(["\'])/' + re.escape(name) + r'(?:\?[^"\']*)?(["\'])' + text = re.sub(pattern, lambda match: match[1] + "/" + name + "?sha=" + fingerprint + match[2], text) + return text.encode("utf-8") + + def client_update_request(action=None): """Console adapter only: the privileged updater owns feeds and installation.""" if action not in (None, "check_only", "update"): @@ -3474,6 +3486,8 @@ class Handler(BaseHTTPRequestHandler): except FileNotFoundError: self.send_error(404) return + if os.path.basename(path) == "index.html": + data = fingerprint_console_assets(data, os.path.dirname(path)) self.send_response(200) self.send_header("Content-Type", content_type) self.send_header("Content-Length", str(len(data))) diff --git a/stage_ui/console_core/backend/test_console_assets.py b/stage_ui/console_core/backend/test_console_assets.py new file mode 100644 index 0000000..1a97512 --- /dev/null +++ b/stage_ui/console_core/backend/test_console_assets.py @@ -0,0 +1,34 @@ +import ast +import hashlib +import os +from pathlib import Path +import re +import tempfile +import unittest + +source = Path(__file__).with_name('app.py').read_text() +node = next(n for n in ast.parse(source).body if isinstance(n, ast.FunctionDef) and n.name == 'fingerprint_console_assets') +namespace = dict(hashlib=hashlib, os=os, re=re) +exec(compile(ast.Module(body=[node], type_ignores=[]), '', 'exec'), namespace) + +class AssetVersionTest(unittest.TestCase): + def test_same_release_changed_content_gets_new_url(self): + with tempfile.TemporaryDirectory() as directory: + for name in ('console.js', 'console.i18n.js', 'console.css'): + Path(directory, name).write_text('original') + html = b'' + render = lambda: namespace['fingerprint_console_assets'](html, directory) + first = render() + self.assertIn(b'?sha=', first) + self.assertNotIn(b'rev=old', first) + self.assertEqual(first, render()) + Path(directory, 'console.js').write_text('new same-version bundle') + self.assertNotEqual(first, render()) + self.assertEqual(first.split(b' - +
@@ -109,7 +109,7 @@
- - + + diff --git a/stage_ui/version.json b/stage_ui/version.json index 3627f51..052a750 100644 --- a/stage_ui/version.json +++ b/stage_ui/version.json @@ -1,3 +1,3 @@ { - "version": "3.1.32" + "version": "3.1.33" }