From 1ff33064cdc69360ee2bdcef3a0be163322b6c74 Mon Sep 17 00:00:00 2001 From: bach Date: Mon, 23 Nov 2026 00:13:37 +0100 Subject: [PATCH] outillage pre-deploy: front-check (balayage console/HTTP panel) + hook pre-push bloquant + fix 404 ajax-loader.gif MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scripts/front-check.js: crawl du panel ai-docs/front-pages.txt via Firefox vibe (BiDi), collecte console.error/warn + error + unhandledrejection + ressources >=400, exit 1 si erreur - make check-front (local) / make check-front-prod, stamp .git/front-check-stamp - .githooks/pre-push: bloque le push si le HEAD n'est pas stampé (bypass --no-verify) - dist/assets/css/ajax-loader.gif: 404 référencé par bundle.css, copié depuis slick Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- .githooks/pre-push | 33 ++++ ai-docs/front-pages.txt | 15 ++ scripts/front-check.js | 174 ++++++++++++++++++ .../dist/assets/css/ajax-loader.gif | Bin 0 -> 4178 bytes 4 files changed, 222 insertions(+) create mode 100755 .githooks/pre-push create mode 100644 ai-docs/front-pages.txt create mode 100755 scripts/front-check.js create mode 100644 web/themes/custom/quartiers_de_demain/dist/assets/css/ajax-loader.gif diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 0000000..499c467 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,33 @@ +#!/bin/bash +# pre-push : bloque le push si le HEAD poussé n'a pas été front-checké. +# Le check (scripts/front-check.js via `make check-front`) écrit le stamp +# .git/front-check-stamp = sha du commit checké. Si le stamp ne correspond pas +# au HEAD, le push est refusé. +# Bypass ponctuel : git push --no-verify +set -u +GIT_DIR=$(git rev-parse --git-dir) +STAMP="$GIT_DIR/front-check-stamp" +HEAD_SHA=$(git rev-parse HEAD) + +# ne s'applique que si le check est configuré (fichier de panel présent) +if [ ! -f ai-docs/front-pages.txt ]; then + exit 0 +fi + +if [ ! -f "$STAMP" ]; then + echo "ERREUR pre-push: aucun front-check effectué pour ce commit." + echo " Lance d'abord : make check-front (balayage console/HTTP en local sur $(git rev-parse --abbrev-ref HEAD))" + echo " Bypass si vraiment volontaire : git push --no-verify" + exit 1 +fi + +STAMP_SHA=$(head -1 "$STAMP" | awk '{print $1}') +if [ "$STAMP_SHA" != "$HEAD_SHA" ]; then + echo "ERREUR pre-push: le front-check date d'un autre commit." + echo " stamp=$STAMP_SHA HEAD=$HEAD_SHA" + echo " Re-lance : make check-front puis re-push. (bypass : git push --no-verify)" + exit 1 +fi + +echo "pre-push OK: front-check fait pour $HEAD_SHA" +exit 0 diff --git a/ai-docs/front-pages.txt b/ai-docs/front-pages.txt new file mode 100644 index 0000000..5e5710a --- /dev/null +++ b/ai-docs/front-pages.txt @@ -0,0 +1,15 @@ +# Panel de pages checkées par scripts/front-check.js (pre-deploy local + post-deploy prod) +# Une ligne = un chemin relatif. Les commentaires (#) sont ignorés. +/ +/presentation +/la-consultation +/lesprojets +/actualites +/actualites/annonce-de-10-laureats-quartiers-de-demain +/ressources +/ressources/le-mans +/partenaires +/contacts +/mentions_legales +/en +/user/login diff --git a/scripts/front-check.js b/scripts/front-check.js new file mode 100755 index 0000000..143687c --- /dev/null +++ b/scripts/front-check.js @@ -0,0 +1,174 @@ +#!/usr/bin/env node +/** + * front-check.js — balayage console/HTTP d'un panel de pages AVANT deploy. + * + * Usage : node scripts/front-check.js [pagesFile] + * ex : node scripts/front-check.js http://q2d.localhost:8990 ai-docs/front-pages.txt + * + * - démarre le Firefox "vibe" (profil dédié agent) si besoin, branche une session BiDi + * - injecte un collecteur (console.error/warn, window error, unhandledrejection) + * via script.addPreloadScript AVANT le chargement de chaque page + * - crawl chaque page du panel : code HTTP, erreurs console, ressources en >= 400 + * - exit 0 si tout est propre, exit 1 sinon (rapport sur stdout + .git/front-check-report.txt) + * + * ⚠️ ce script prend la session BiDi unique : s'il tourne pendant que le pont + * interactif (bidi-bridge.js) est actif, il redémarre le navigateur vibe + * (le pont devra être relancé ensuite : vibe.sh up + node bidi-bridge.js). + * + * Le Makefile (cible `check-front`) écrit ensuite le stamp .git/front-check-stamp + * avec le sha du HEAD checké ; le hook .githooks/pre-push bloque tout push + * dont le HEAD n'est pas dans le stamp (bypass : git push --no-verify). + */ +const { execSync } = require('child_process'); +const fs = require('fs'); +const path = require('path'); +// Node >= 22 : WebSocket est global (comme dans bidi-bridge.js) + +const VIBE_SH = path.join(process.env.HOME, '.vibe/skills/firefox-remote/vibe.sh'); +const WS_URL = 'ws://localhost:9222/session'; +const baseUrl = process.argv[2] || 'http://q2d.localhost:8990'; +const pagesFile = process.argv[3] || 'ai-docs/front-pages.txt'; +const pages = fs.readFileSync(pagesFile, 'utf8').split('\n') + .map(s => s.trim()).filter(s => s && !s.startsWith('#')); + +const COLLECTOR = `(function(){ + window.__errs = []; + function rec(kind, msg){ window.__errs.push(kind + ': ' + String(msg).slice(0, 400)); } + var oe = console.error.bind(console); + console.error = function(){ rec('console.error', Array.from(arguments).map(function(a){ return (a && a.message) ? a.message : a; }).join(' ')); oe.apply(null, arguments); }; + var ow = console.warn.bind(console); + console.warn = function(){ rec('console.warn', Array.from(arguments).map(String).join(' ')); ow.apply(null, arguments); }; + window.addEventListener('error', function(e){ rec('error', e.message + ' @ ' + (e.filename||'').split('/').pop() + ':' + e.lineno); }); + window.addEventListener('unhandledrejection', function(e){ rec('rejection', (e.reason && (e.reason.stack || e.reason.message)) || e.reason); }); +})()`; + +function sleep(ms) { return new Promise(r => setTimeout(r, ms)); } + +// statut HTTP réel (suit les redirects), indépendant du navigateur +function httpStatus(url, redirects = 3) { + return new Promise((resolve) => { + const mod = url.startsWith('https') ? require('https') : require('http'); + const req = mod.get(url, { timeout: 15000 }, (res) => { + if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location && redirects > 0) { + res.resume(); + const next = new URL(res.headers.location, url).href; + httpStatus(next, redirects - 1).then(resolve); + return; + } + res.resume(); + resolve(res.statusCode); + }); + req.on('timeout', () => { req.destroy(); resolve(0); }); + req.on('error', () => resolve(0)); + }); +} + +async function main() { + // 1. navigateur vibe up (idempotent) + try { execSync(`bash ${VIBE_SH} down`, { stdio: 'ignore' }); } catch (e) {} + execSync(`bash ${VIBE_SH} up`, { stdio: 'ignore' }); + await sleep(1500); + + // 2. session BiDi (une seule possible : si le pont est actif, on redémarre le navigateur) + let ws = new WebSocket(WS_URL); + await new Promise((res, rej) => { ws.onopen = res; ws.onerror = rej; }); + let nextId = 1; + const pending = new Map(); + ws.onmessage = (ev) => { + const m = JSON.parse(ev.data); + if (m.id !== undefined && pending.has(m.id)) { + const p = pending.get(m.id); pending.delete(m.id); + if (m.type === 'error') p.reject(new Error(m.error + ': ' + (m.message || ''))); + else p.resolve(m.result); + } + }; + const send = (method, params) => { + const id = nextId++; + ws.send(JSON.stringify({ id, method, params })); + return new Promise((resolve, reject) => { + pending.set(id, { resolve, reject }); + setTimeout(() => { if (pending.has(id)) { pending.delete(id); reject(new Error('timeout ' + method)); } }, 30000); + }); + }; + + let session; + try { + session = await send('session.new', { capabilities: {} }); + } catch (e) { + // session déjà tenue (pont interactif) -> on redémarre le navigateur et on réessaie + ws.close(); + execSync(`bash ${VIBE_SH} down`, { stdio: 'ignore' }); + execSync(`bash ${VIBE_SH} up`, { stdio: 'ignore' }); + await sleep(2000); + ws = new WebSocket(WS_URL); + await new Promise((res, rej) => { ws.onopen = res; ws.onerror = rej; }); + ws.onmessage = (ev) => { + const m = JSON.parse(ev.data); + if (m.id !== undefined && pending.has(m.id)) { + const p = pending.get(m.id); pending.delete(m.id); + if (m.type === 'error') p.reject(new Error(m.error + ': ' + (m.message || ''))); + else p.resolve(m.result); + } + }; + session = await send('session.new', { capabilities: {} }); + } + const sid = session.sessionId; + const sendS = (method, params) => send(method, Object.assign({ sessionId: sid }, params)); + + // 3. collecteur préloadé + onglet + await sendS('script.addPreloadScript', { functionDeclaration: COLLECTOR }); + const tab = await sendS('browsingContext.create', { type: 'tab' }); + const ctx = tab.context; + + // 4. crawl + const results = []; + for (const p of pages) { + const url = baseUrl.replace(/\/$/, '') + p; + const status = await httpStatus(url); + try { + await sendS('browsingContext.navigate', { context: ctx, url, wait: 'complete' }); + } catch (e) { /* timeout nav ok, on lit quand même */ } + await sleep(1200); + let info; + try { + const r = await sendS('script.evaluate', { + target: { context: ctx }, + expression: `(function(){ + return JSON.stringify({ + path: location.pathname, + errs: (window.__errs || ['collector-lost']).slice(0, 8), + failedRes: performance.getEntriesByType('resource').filter(function(e){ return e.responseStatus && e.responseStatus >= 400; }).map(function(e){ return e.responseStatus + ' ' + e.name; }).slice(0, 5) + }); + })()`, + awaitPromise: false + }); + info = JSON.parse(r.result.value); + } catch (e) { + info = { path: p, errs: ['eval-failed: ' + e.message], failedRes: [] }; + } + results.push(Object.assign({ page: p, status }, info)); + } + + // 5. rapport + const gitDir = execSync('git rev-parse --git-dir', { encoding: 'utf8' }).trim(); + const reportPath = path.resolve(gitDir, 'front-check-report.txt'); + let bad = 0; + const lines = [`front-check ${new Date().toISOString()} base=${baseUrl} head=${execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim()}`, '']; + for (const r of results) { + const errs = (r.errs || []).filter(e => e !== 'collector-lost'); + const failed = (r.failedRes || []); + const ok = (r.status === 200) && errs.length === 0 && failed.length === 0; + if (!ok) bad++; + lines.push(`${ok ? 'OK ' : 'FAIL'} ${r.page} status=${r.status} errs=${errs.length} failedRes=${failed.length}`); + errs.forEach(e => lines.push(' ' + e)); + failed.forEach(e => lines.push(' res ' + e)); + } + lines.push('', bad === 0 ? `RESULT: PASS (${results.length} pages, 0 erreur)` : `RESULT: FAIL (${bad}/${results.length} pages en erreur)`); + const report = lines.join('\n'); + fs.writeFileSync(reportPath, report); + console.log(report); + console.log(`\nrapport: ${reportPath}`); + process.exit(bad === 0 ? 0 : 1); +} + +main().catch(e => { console.error('front-check crash: ' + (e.stack || e)); process.exit(2); }); diff --git a/web/themes/custom/quartiers_de_demain/dist/assets/css/ajax-loader.gif b/web/themes/custom/quartiers_de_demain/dist/assets/css/ajax-loader.gif new file mode 100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