2026-02-08 22:47:01 +00:00
|
|
|
"""Regression tests for frontend build configuration.
|
|
|
|
|
|
|
|
|
|
Prevents re-introducing JS obfuscation plugins that break vendor libraries
|
|
|
|
|
(e.g., Mapbox GL WebGL shaders corrupted by string encoding/splitting).
|
|
|
|
|
"""
|
|
|
|
|
import json
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
2026-02-21 15:52:37 +00:00
|
|
|
import pytest
|
|
|
|
|
|
2026-02-08 22:47:01 +00:00
|
|
|
FRONTEND_DIR = Path(__file__).resolve().parents[2] / "frontend"
|
|
|
|
|
|
2026-02-21 15:52:37 +00:00
|
|
|
_skip_no_frontend = pytest.mark.skipif(
|
|
|
|
|
not FRONTEND_DIR.is_dir(),
|
|
|
|
|
reason="frontend/ directory not present (e.g. backend-only Docker build)",
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-08 22:47:01 +00:00
|
|
|
|
2026-02-21 15:52:37 +00:00
|
|
|
@_skip_no_frontend
|
2026-02-08 22:47:01 +00:00
|
|
|
class TestViteConfig:
|
|
|
|
|
"""Validate vite.config.ts doesn't contain dangerous build plugins."""
|
|
|
|
|
|
|
|
|
|
def test_no_obfuscator_plugin_in_vite_config(self) -> None:
|
|
|
|
|
"""JS obfuscation breaks Mapbox GL's WebGL shaders and must not be used.
|
|
|
|
|
|
|
|
|
|
vite-plugin-obfuscator processes ALL output chunks (including vendor
|
|
|
|
|
libraries) and corrupts string literals used for WebGL shader source,
|
|
|
|
|
causing the map to render as a blank screen.
|
|
|
|
|
"""
|
|
|
|
|
config = (FRONTEND_DIR / "vite.config.ts").read_text()
|
|
|
|
|
assert "obfuscat" not in config.lower(), (
|
|
|
|
|
"vite.config.ts must not use JS obfuscation plugins — "
|
|
|
|
|
"they corrupt Mapbox GL's WebGL shaders and break the map"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_no_obfuscator_in_package_json(self) -> None:
|
|
|
|
|
"""Ensure obfuscator packages are not listed as dependencies."""
|
|
|
|
|
pkg = json.loads((FRONTEND_DIR / "package.json").read_text())
|
|
|
|
|
all_deps = {
|
|
|
|
|
**pkg.get("dependencies", {}),
|
|
|
|
|
**pkg.get("devDependencies", {}),
|
|
|
|
|
}
|
|
|
|
|
for dep_name in all_deps:
|
|
|
|
|
assert "obfuscat" not in dep_name.lower(), (
|
|
|
|
|
f"package.json must not include obfuscator packages (found {dep_name})"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_source_maps_disabled(self) -> None:
|
|
|
|
|
"""Production builds must not emit source maps."""
|
|
|
|
|
config = (FRONTEND_DIR / "vite.config.ts").read_text()
|
|
|
|
|
assert "sourcemap: false" in config or "sourcemap:false" in config, (
|
|
|
|
|
"vite.config.ts must have sourcemap: false to prevent "
|
|
|
|
|
"shipping .map files in production"
|
|
|
|
|
)
|