import pytest @pytest.fixture def built(static_dir): """Minimal stand-in for the frontend build output.""" (static_dir / "assets").mkdir() (static_dir / "icons").mkdir() (static_dir / "index.html").write_text("spa") (static_dir / "sw.js").write_text("self.addEventListener('fetch', () => {})") (static_dir / "workbox-abc123.js").write_text("// workbox") (static_dir / "manifest.webmanifest").write_text('{"name": "LAN-Clipboard"}') (static_dir / "assets" / "index-abc123.js").write_text("console.log(1)") (static_dir / "icons" / "icon-192.png").write_bytes(b"\\x89PNG") @pytest.mark.parametrize("path", ["/", "/clips/1", "/index.html", "/sw.js"]) def test_entry_points_are_revalidated(built, client, path): assert client.get(path).headers["cache-control"] == "no-cache" @pytest.mark.parametrize("path", ["/assets/index-abc123.js", "/workbox-abc123.js"]) def test_hashed_files_are_immutable(built, client, path): assert client.get(path).headers["cache-control"] == "public, max-age=31536000, immutable" def test_icons_are_cached_for_a_day(built, client): assert client.get("/icons/icon-192.png").headers["cache-control"] == "public, max-age=86400" def test_manifest_content_type(built, client): response = client.get("/manifest.webmanifest") assert response.status_code == 200 assert response.headers["content-type"].startswith("application/manifest+json") assert response.headers["cache-control"] == "no-cache" def test_service_worker_is_javascript(built, client): assert "javascript" in client.get("/sw.js").headers["content-type"]