From 30e230fae9b595af67edc9ba8c0dcf43e78cc927 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 25 Apr 2026 02:39:15 +0100 Subject: [PATCH] Disable GUI asset caching --- src/repixelizer/gui.py | 9 ++++++++ tests/test_gui.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/repixelizer/gui.py b/src/repixelizer/gui.py index b116827..61cc3ae 100644 --- a/src/repixelizer/gui.py +++ b/src/repixelizer/gui.py @@ -374,6 +374,15 @@ def create_app(): jobs: dict[str, GuiJob] = {} static_dir = _static_dir() + @app.middleware("http") + async def disable_gui_asset_caching(request, call_next): + response = await call_next(request) + if request.url.path == "/" or request.url.path.startswith("/app"): + response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0" + response.headers["Pragma"] = "no-cache" + response.headers["Expires"] = "0" + return response + @app.get("/api/health") def health() -> dict[str, str]: return {"status": "ok"} diff --git a/tests/test_gui.py b/tests/test_gui.py index 46e880b..e71ead5 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -2,6 +2,7 @@ from __future__ import annotations import importlib.util import io +import asyncio from pathlib import Path import numpy as np @@ -16,6 +17,39 @@ from repixelizer.params import SolverHyperParams from repixelizer.types import InferenceCandidate, InferenceResult, PhaseFieldSourceAnalysis, SolverArtifacts +async def _get_response_headers(app, path: str) -> tuple[int, dict[str, str]]: + messages: list[dict[str, object]] = [] + + async def receive(): + return {"type": "http.request", "body": b"", "more_body": False} + + async def send(message): + messages.append(message) + + scope = { + "type": "http", + "asgi": {"version": "3.0"}, + "http_version": "1.1", + "method": "GET", + "scheme": "http", + "path": path, + "raw_path": path.encode("ascii"), + "query_string": b"", + "headers": [], + "client": ("127.0.0.1", 12345), + "server": ("testserver", 80), + "root_path": "", + } + await app(scope, receive, send) + start = next(message for message in messages if message["type"] == "http.response.start") + status = int(start["status"]) + headers = { + key.decode("latin-1").lower(): value.decode("latin-1") + for key, value in start.get("headers", []) + } + return status, headers + + def test_run_pipeline_rgba_emits_observer_events_for_gui() -> None: source = make_emblem(20, 20) fake = fake_pixelize(source, upscale=8, phase_x=0.15, phase_y=0.2, blur_radius=0.45, seed=3) @@ -88,6 +122,21 @@ def test_create_job_upload_field_validates_without_forward_ref_errors() -> None: assert value.filename == "tiny.png" +def test_gui_static_assets_disable_browser_caching() -> None: + from repixelizer.gui import create_app + + app = create_app() + html_status, html_headers = asyncio.run(_get_response_headers(app, "/app/")) + js_status, js_headers = asyncio.run(_get_response_headers(app, "/app/app.js")) + + assert html_status == 200 + assert js_status == 200 + assert html_headers["cache-control"] == "no-store, no-cache, must-revalidate, max-age=0" + assert js_headers["cache-control"] == "no-store, no-cache, must-revalidate, max-age=0" + assert html_headers["pragma"] == "no-cache" + assert js_headers["pragma"] == "no-cache" + + def test_infer_lattice_emits_search_progress_events(monkeypatch) -> None: class _FakeCuda: @staticmethod