Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Vision8 * File : test/e2e/smoke.mjs9 * Module : test10 * Repository : https://git.spboucher.ai/maclustr-vision11 * Project Website : https://camera.spboucher.ai12 * Created : 2026-11-3013 * Last Modified : 2026-11-3014 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@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// Parcours de bout en bout dans un vrai navigateur contre une instance en service.43// Usage : PLAYWRIGHT_DIR=<dossier contenant node_modules/playwright> MLV_URL=https://… MLV_KEY_FILE=<fichier 0600> \44// node test/e2e/smoke.mjs [webkit|chromium] [mobile|desktop]45// Les captures (images réelles des caméras) vont dans MLV_SHOTS (défaut /tmp/mlv-shots) : ne jamais les commiter.46import fs from 'node:fs';47import { createRequire } from 'node:module';48import path from 'node:path';4950const require = createRequire(path.resolve(process.env.PLAYWRIGHT_DIR || '.', 'x.js'));51const pw = require('playwright');52const engine = process.argv[2] || 'webkit';53const form = process.argv[3] || 'desktop';54const URL0 = process.env.MLV_URL || 'https://camera.spboucher.ai';55// MLV_KEY_FILE : parcours complet avec connexion ; MLV_SESSION_TOKEN : session opérateur temporaire (sans connaître la clé du propriétaire)56const KEY = process.env.MLV_KEY_FILE ? fs.readFileSync(process.env.MLV_KEY_FILE, 'utf8').trim() : null;57const TOKEN = process.env.MLV_SESSION_TOKEN || null;58const SHOTS = process.env.MLV_SHOTS || '/tmp/mlv-shots';59fs.mkdirSync(SHOTS, { recursive: true });60const results = [];61const ok = (name, pass, detail = '') => {62 results.push({ name, pass });63 console.log(`${pass ? 'OK ' : 'ÉCHEC'} ${name}${detail ? ' — ' + detail : ''}`);64};65const browser = await pw[engine].launch();66const ctx = await browser.newContext(form === 'mobile' ? { viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, isMobile: engine !== 'firefox', hasTouch: true } : { viewport: { width: 1440, height: 900 } });67const page = await ctx.newPage();68const errors = [];69page.on('console', (m) => m.type() === 'error' && errors.push(`${new URL(page.url()).pathname} :: ${m.text()} @ ${m.location().url || ''}`));70page.on('pageerror', (e) => errors.push(String(e)));71const shot = (n) => page.screenshot({ path: `${SHOTS}/${engine}-${form}-${n}.png`, caret: 'initial', animations: 'allow' });72const playing = async (sel) => {73 const a = await page.$$eval(sel, (vs) => vs.map((v) => v.currentTime));74 await page.waitForTimeout(2500);75 const b = await page.$$eval(sel, (vs) => vs.map((v) => ({ t: v.currentTime, w: v.videoWidth, h: v.videoHeight, rs: v.readyState })));76 return b.map((x, i) => ({ ...x, advancing: x.t > a[i] + 0.5 }));77};7879if (TOKEN) {80 await ctx.addCookies([{ name: '__Host-mlv', value: TOKEN, domain: new URL(URL0).hostname, path: '/', secure: true, httpOnly: true, sameSite: 'Strict' }]);81 await page.goto(URL0);82} else {83 await page.goto(URL0);84 await page.waitForSelector('input[type=password]');85 await shot('01-connexion');86 ok('écran de connexion', (await page.title()) === 'MacLustr Vision');87 await page.fill('input[type=password]', 'mlv_' + 'x'.repeat(43));88 await page.click('button[type=submit]');89 await page.waitForFunction(() => /refusée/.test(document.querySelector('#login-state')?.textContent || ''), null, { timeout: 8000 });90 ok('clé incorrecte refusée', true);91 await page.fill('input[type=password]', KEY);92 await page.click('button[type=submit]');93}94await page.waitForSelector('.mosaic .tile', { timeout: 15000 });95const tiles = await page.$$('.mosaic .tile');96ok('mosaïque affichée', tiles.length >= 1, `${tiles.length} caméra(s)`);97let live = [];98for (let i = 0; i < 10; i++) {99 live = await playing('.mosaic video');100 if (live.every((v) => v.advancing)) break;101}102ok('direct mosaïque : les flux avancent', live.length > 0 && live.every((v) => v.advancing), JSON.stringify(live));103ok('badge REC confirmé', (await page.$$('.badge.rec')).length === tiles.length, `${(await page.$$('.badge.rec')).length}/${tiles.length}`);104await shot('02-direct');105ok('pas de défilement horizontal', await page.evaluate(() => document.scrollingElement.scrollWidth <= window.innerWidth + 1));106107// page caméra108await page.click('.mosaic .tile .hit');109await page.waitForSelector('.cam-layout .tile');110let cam = [];111for (let i = 0; i < 12; i++) {112 cam = await playing('.cam-layout video');113 if (cam[0]?.advancing) break;114}115const kv = await page.$$eval('.kv dd', (d) => d.map((x) => x.textContent));116ok('page caméra : flux principal', !!cam[0]?.advancing, `${cam[0]?.w}×${cam[0]?.h} · ${kv[2]}`);117await shot('03-camera');118await page.click('.cam-layout summary');119const hlsBtn = await page.$('button:has-text("HLS"):not([disabled])');120if (hlsBtn) {121 await hlsBtn.click();122 let h = [];123 for (let i = 0; i < 14; i++) {124 h = await playing('.cam-layout video');125 if (h[0]?.advancing) break;126 }127 const kv2 = await page.$$eval('.kv dd', (d) => d.map((x) => x.textContent));128 ok('repli HLS', !!h[0]?.advancing && /HLS/.test(kv2[2] || ''), `${h[0]?.w}×${h[0]?.h} · ${kv2[2]}`);129} else console.log('— repli HLS non testable dans ce moteur (pas de HLS natif)');130ok('commandes PTZ présentes', (await page.$$('.ptz button')).length === 4);131// options avancées : palette de commandes, statistiques, zoom numérique132await page.keyboard.press(engine === 'webkit' ? 'Meta+k' : 'Control+k');133ok('palette de commandes', !!(await page.waitForSelector('.palette input', { timeout: 3000 }).catch(() => null)));134await page.keyboard.press('Escape');135await page.keyboard.press('i');136ok('statistiques techniques', !!(await page.waitForSelector('.tile .osd', { timeout: 5000 }).catch(() => null)));137await page.keyboard.press('i');138if (form === 'desktop') {139 await page.evaluate(() => window.scrollTo(0, 0));140 const bb = await (await page.$('.cam-layout .stage')).boundingBox();141 await page.evaluate(() => window.scrollTo(0, 0));142 await page.mouse.move(bb.x + bb.width / 2, bb.y + bb.height / 2);143 await page.waitForTimeout(300);144 await page.mouse.wheel(0, -400);145 ok('zoom numérique', !!(await page.waitForSelector('.tile .zoomtag', { timeout: 3000 }).catch(() => null)));146}147148// historique149await page.goto(URL0 + '/history');150await page.waitForSelector('.timeline-wrap canvas');151await page.waitForFunction(() => !document.querySelector('.player .veil'), null, { timeout: 20000 }).catch(() => {});152await page.click('button[aria-label="Lecture"]');153ok('piste d’activité et frise', !!(await page.$('.timeline-wrap canvas')) && (await page.$$('.legend span')).length >= 4);154let hist = [];155for (let i = 0; i < 16; i++) {156 hist = await playing('.player video');157 if (hist[0]?.advancing) break;158}159ok('historique : lecture d’un segment enregistré', !!hist[0]?.advancing, `${hist[0]?.w}×${hist[0]?.h}`);160await shot('04-historique');161162for (const [p, sel, n] of [['/events', '.list-item', '05-evenements'], ['/storage', '.stats', '06-stockage'], ['/system', '.stats', '07-systeme'], ['/settings', '.swatches', '08-reglages']]) {163 await page.goto(URL0 + p);164 const found = await page.waitForSelector(sel, { timeout: 12000 }).then(() => true, () => false);165 await page.waitForTimeout(600);166 await shot(n);167 ok(`écran ${p}`, found && (await page.evaluate(() => document.scrollingElement.scrollWidth <= window.innerWidth + 1)));168}169// verrouillage (seulement avec une vraie connexion : en mode jeton, la session de test est révoquée par l'opérateur)170if (!TOKEN) {171 await page.goto(URL0 + '/settings');172 await page.click('button:has-text("Verrouiller cet appareil")');173 await page.waitForSelector('input[type=password]');174 const after = await page.evaluate(() => fetch('/api/cameras').then((r) => r.status));175 ok('après verrouillage : API refusée', after === 401, `HTTP ${after}`);176}177const real = errors.filter((e) => !/401|Failed to load resource|Refused to apply a stylesheet|WebSocket connection/.test(e));178ok('aucune erreur console / CSP', real.length === 0, real.slice(0, 3).join(' | '));179await browser.close();180const failed = results.filter((r) => !r.pass).length;181console.log(`\n${results.length - failed}/${results.length} vérifications réussies (${engine}, ${form})`);182process.exit(failed ? 1 : 0);183