Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Page header: load the bundled Vue (vendor/js/vue.global.js); vue.global.prod.js is not in the image, so the account/admin headers stayed empty. Test that every referenced vendor file is downloaded at build
Murtaza Nasird5037b088599
diff --git a/static/js/global-header.js b/static/js/global-header.jsindex 7582601e..6005934c 100644--- a/static/js/global-header.js+++ b/static/js/global-header.js@@ -26,7 +26,7 @@ function ensureVue() {if (window.Vue) return Promise.resolve();return new Promise((resolve, reject) => {const script = document.createElement('script');- script.src = '/static/vendor/js/vue.global.prod.js';+ script.src = '/static/vendor/js/vue.global.js'; // the build saves the production Vue under this namescript.onload = resolve;script.onerror = reject;document.head.appendChild(script);diff --git a/tests/test_vendor_refs.py b/tests/test_vendor_refs.pynew file mode 100644index 00000000..22274971--- /dev/null+++ b/tests/test_vendor_refs.py@@ -0,0 +1,55 @@+"""Every vendor file the code references is one the image build downloads.++static/vendor/ is not in git: scripts/download_offline_deps.py fetches it+when the image is built. A reference to a vendor file that script does not+download works on a developer machine that happens to have the file, and+returns 404 in the released image. (v0.10.8 loaded vendor/js/vue.global.prod.js+for the shared page header, so the account and admin headers stayed empty.)+"""++import importlib.util+import os+import re++ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+REF = re.compile(r"vendor/(js|css|fonts|webfonts)/([A-Za-z0-9_.\-]+)")+++def _downloaded():+ spec = importlib.util.spec_from_file_location("deps", os.path.join(ROOT, "scripts", "download_offline_deps.py"))+ mod = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(mod)+ names = set()+ for group in mod.DEPENDENCIES.values():+ if isinstance(group, dict):+ names.update(group.keys())+ return names+++def _references():+ refs = {}+ for top in ("templates", os.path.join("static", "js"), os.path.join("static", "css")):+ for dirpath, _, files in os.walk(os.path.join(ROOT, top)):+ if "vendor" in dirpath.split(os.sep):+ continue+ for name in files:+ if not name.endswith((".html", ".js", ".css")):+ continue+ path = os.path.join(dirpath, name)+ text = open(path, encoding="utf-8", errors="ignore").read()+ for kind, fname in REF.findall(text):+ refs.setdefault(f"{kind}/{fname}", set()).add(os.path.relpath(path, ROOT))+ return refs+++def test_referenced_vendor_files_are_downloaded_by_the_build():+ downloaded = _downloaded()+ missing = {ref: sorted(where) for ref, where in _references().items()+ if ref.split("/", 1)[0] == "js" and ref.split("/", 1)[1] not in downloaded}+ assert not missing, f"vendor files referenced but not downloaded at build: {missing}"+++def test_the_page_header_loads_the_downloaded_vue_build():+ text = open(os.path.join(ROOT, "static", "js", "global-header.js"), encoding="utf-8").read()+ assert "vendor/js/vue.global.js" in text+ assert "vue.global.prod.js" not in text