SPB Git

Repository Public

check-fixture.mjs 5.6 KB 108 lines javascript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : sdk/web/scripts/check-fixture.mjs9 * Module           : sdk10 * Repository       : https://git.spboucher.ai/ka-maps-engine11 * Created          : 2026-12-0112 * Last Modified    : 2026-12-0113 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Vérifie un site d'essai (Next.js sur 5320, Vite + React sur 5330) dans trois navigateurs sans43// fenêtre : la carte se charge depuis le paquet installé, workers de même origine, aucune violation de44// CSP, aucune erreur de console. Pour Next.js : rendu serveur (geo.search) et en-tête CSP à nonce.45//46//   KA_FIXTURE_URL=… KA_FIXTURE_GLOBAL=__kaNext KA_FIXTURE_BRAND=louka [KA_FIXTURE_SERVER=1] node scripts/check-fixture.mjs47import { chromium, firefox, webkit } from '@playwright/test';4849const URL_ = process.env.KA_FIXTURE_URL ?? 'http://127.0.0.1:5320/';50const GLOBAL = process.env.KA_FIXTURE_GLOBAL ?? '__kaNext';51const BRAND = process.env.KA_FIXTURE_BRAND ?? 'louka';52const SERVER = process.env.KA_FIXTURE_SERVER === '1';53const GPU = ['--enable-unsafe-webgpu', '--enable-gpu', '--use-angle=metal', '--ignore-gpu-blocklist', '--enable-features=WebGPU'];54const browsers = {55  chromium: () => chromium.launch({ headless: true, channel: 'chromium', args: GPU }),56  firefox: () => firefox.launch({ headless: true, firefoxUserPrefs: { 'webgl.force-enabled': true } }),57  webkit: () => webkit.launch({ headless: true }),58};5960let failed = 0;61for (const [name, launch] of Object.entries(browsers)) {62  const browser = await launch();63  const page = await browser.newPage({ viewport: { width: 1100, height: 700 } });64  const errors = [];65  page.on('pageerror', (e) => errors.push(`pageerror: ${e.message}`));66  // Les 404 sont relevés par adresse (un favicon absent n'est pas une erreur du SDK).67  page.on('console', (m) => m.type() === 'error' && !/Failed to load resource/.test(m.text()) && errors.push(m.text()));68  page.on('response', (r) => r.status() >= 400 && !r.url().endsWith('/favicon.ico') && errors.push(`HTTP ${r.status()} ${r.url()}`));69  await page.addInitScript(() => {70    window.__csp = [];71    document.addEventListener('securitypolicyviolation', (e) => window.__csp.push(`${e.violatedDirective} ${e.blockedURI}`));72  });73  const res = await page.goto(URL_);74  const html = await res.text();75  const csp = res.headers()['content-security-policy'] ?? /http-equiv="Content-Security-Policy"\s+content="([^"]+)"/.exec(html)?.[1] ?? '';76  let state;77  try {78    await page.waitForFunction((g) => window[g]?.ready || window[g]?.error, GLOBAL, { timeout: 60000 });79    state = await page.evaluate((g) => {80      const k = window[g];81      if (!k.map) return { error: k.error, csp: window.__csp };82      const s = k.map.getStats();83      return { ready: k.ready, backend: s.backend, tiles: k.map.getPerf().tiles, workers: s.workers, layers: k.map.listLayers(), brand: k.map.getTheme().brand, canvases: document.querySelectorAll('canvas').length, csp: window.__csp };84    }, GLOBAL);85  } catch (e) {86    state = { error: `délai dépassé : ${e.message}`, csp: [] };87  }88  const serverGeo = /Adresse trouvée côté serveur : (?:<!-- -->)?([^<]+)/.exec(html)?.[1] ?? '';89  const checks = {90    ready: state.ready === true,91    tiles: state.tiles > 0,92    oneCanvas: state.canvases === 1,93    workers: state.workers?.mode === 'workers' && state.workers?.blobBootstrap === false && state.workers?.local === 0,94    layer: state.layers?.length === 1,95    brand: state.brand === BRAND,96    noCspViolation: state.csp.length === 0,97    cspStrict: csp.includes("'wasm-unsafe-eval'") && csp.includes("worker-src 'self'") && !csp.includes('blob:') && !csp.includes('unsafe-inline') && !csp.includes("'unsafe-eval'"),98    noConsoleError: errors.length === 0,99    ...(SERVER ? { serverRendered: serverGeo.includes('Sherbrooke'), noInlineStyle: !html.includes('style="') } : {}),100  };101  const ok = Object.values(checks).every(Boolean);102  const bad = Object.entries(checks).filter(([, v]) => !v).map(([k]) => k);103  console.log(`${ok ? 'OK   ' : 'ÉCHEC'} ${name} : ${JSON.stringify({ backend: state.backend, tiles: state.tiles, workers: state.workers && `${state.workers.alive}/${state.workers.workers} ${state.workers.mode}`, ...(SERVER ? { serverGeo } : {}), ...(ok ? {} : { échecs: bad, cspViolations: state.csp, error: state.error, errors }) })}`);104  if (!ok) failed++;105  await browser.close();106}107process.exit(failed ? 1 : 0);108
Files main
Menu

Theme