feat(js): harden global HTTP and module import contracts

This commit is contained in:
2026-04-20 22:41:07 +02:00
parent f189ef9df6
commit 7c47e818f2
12 changed files with 181 additions and 266 deletions

View File

@@ -21,20 +21,20 @@ fail() {
failures=$((failures + 1))
}
alert_hits="$(rg -n "window\\.alert\\s*\\(" web/js modules/helpdesk/web/js -g '*.js' || true)"
alert_hits="$(rg -n "window\\.alert\\s*\\(" web/js modules/*/web/js -g '*.js' || true)"
if [[ -n "${alert_hits}" ]]; then
fail "window.alert usage detected:"
echo "${alert_hits}" >&2
else
ok "No window.alert usage in web/js and modules/helpdesk/web/js"
ok "No window.alert usage in web/js and modules/*/web/js"
fi
fetch_hits="$(rg -n "\\bfetch\\s*\\(" modules/helpdesk/web/js -g '*.js' || true)"
fetch_hits="$(rg -n "\\bfetch\\s*\\(" web/js modules/*/web/js -g '*.js' -g '!web/js/core/app-http.js' -g '!web/js/core/app-telemetry.js' || true)"
if [[ -n "${fetch_hits}" ]]; then
fail "Direct fetch(...) usage detected in helpdesk JS:"
fail "Direct fetch(...) usage detected outside approved HTTP infrastructure:"
echo "${fetch_hits}" >&2
else
ok "Helpdesk JS uses centralized app-http (no direct fetch)"
ok "Frontend JS uses centralized app-http (except app-http/app-telemetry infrastructure)"
fi
runtime_files=(
@@ -83,14 +83,14 @@ while IFS= read -r line; do
continue
fi
echo "${file}: invalid import path -> ${import_path}" >&2
echo "${file}: invalid module import path -> ${import_path}" >&2
import_violations=$((import_violations + 1))
done < <(rg -n "^\\s*import\\s+(?:[^'\\\"]+\\s+from\\s+)?['\\\"][^'\\\"]+['\\\"]" modules/helpdesk/web/js -g '*.js')
done < <(rg -n "^\\s*import\\s+(?:[^'\\\"]+\\s+from\\s+)?['\\\"][^'\\\"]+['\\\"]" modules/*/web/js -g '*.js')
if [[ "${import_violations}" -gt 0 ]]; then
fail "Helpdesk import policy violations: ${import_violations}"
fail "Module import policy violations: ${import_violations}"
else
ok "Helpdesk import policy valid (core imports absolute /js/...; local imports relative)"
ok "Module import policy valid (core imports absolute /js/...; local imports relative)"
fi
if [[ "${failures}" -gt 0 ]]; then