SPB Git

Repository Public

studio.spec.ts 14.4 KB 258 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : studio/e2e/studio.spec.ts9 * Module           : studio10 * 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// Parcours principaux, sans fenêtre : activation par clé d'accès (authentificateur WebAuthn virtuel),43// édition d'une couleur, enregistrement, publication à 10 %, vérification du manifeste par tranche,44// passage à 100 %, retour arrière, reconnexion, configuration d'application, exploitation.45import { type CDPSession, expect, type Page, test } from '@playwright/test';46import { readdirSync, readFileSync } from 'node:fs';47import { dirname, join } from 'node:path';48import { fileURLToPath } from 'node:url';4950const here = dirname(fileURLToPath(import.meta.url));51const state = () => JSON.parse(readFileSync(join(here, '.state.json'), 'utf8'));52const shots = join(here, '..', 'test-results', 'shots');53test.describe.configure({ mode: 'serial' });5455let page: Page;56let cdp: CDPSession;57const problems: string[] = [];5859async function manifest(q: string) {60  await new Promise((r) => setTimeout(r, 450)); // le service relit la révision toutes les 200 ms61  return (await (await fetch(`${state().maps}/v1/manifest.json?${q}`)).json()) as any;62}63async function versionsByBucket(app = 'louka', platform = 'web') {64  const out: number[] = [];65  await new Promise((r) => setTimeout(r, 450));66  for (let b = 0; b < 100; b++) {67    const m = (await (await fetch(`${state().maps}/v1/manifest.json?app=${app}&platform=${platform}&engine=0.1.0&bucket=${b}`)).json()) as any;68    out.push(m.themes.find((t: any) => t.id === 'signature').version);69  }70  return out;71}7273test.beforeAll(async ({ browser }) => {74  const ctx = await browser.newContext();75  await ctx.addInitScript(() => localStorage.setItem('kms-apercu', 'serveur')); // ce parcours vérifie l'aperçu par rendu serveur ; le SDK Web a son propre essai76  page = await ctx.newPage();77  page.on('console', (m) => { if (m.type() === 'error' && !/401|422|404/.test(m.text())) problems.push(m.text()); });78  page.on('pageerror', (e) => problems.push(String(e)));79  cdp = await ctx.newCDPSession(page);80  await cdp.send('WebAuthn.enable');81  await cdp.send('WebAuthn.addVirtualAuthenticator', { options: { protocol: 'ctap2', transport: 'internal', hasResidentKey: true, hasUserVerification: true, isUserVerified: true, automaticPresenceSimulation: true } });82});8384test('sans session : écran de connexion, API fermée', async () => {85  const r = await page.goto('/themes/signature');86  expect(r!.headers()['content-security-policy']).toContain("default-src 'none'");87  await expect(page.getByRole('heading', { name: 'Connexion' })).toBeVisible();88  expect((await page.request.get('/api/themes')).status()).toBe(401);89  expect((await page.request.get('/api/audit')).status()).toBe(401);90  expect((await page.request.post('/api/themes/signature/rollback', { data: { version: 1 } })).status()).toBe(403);91  await page.screenshot({ path: join(shots, '01-connexion.png') });92});9394test("activation : lien à usage unique + clé d'accès", async () => {95  await page.goto(`/activer#${state().tokens[0]}`);96  await expect(page.getByText('Bienvenue, Simone Essai')).toBeVisible();97  await page.getByRole('button', { name: "Créer ma clé d'accès" }).click();98  await expect(page.getByRole('heading', { name: 'Thèmes', exact: true })).toBeVisible();99  await expect(page.getByRole('link', { name: 'Signature' })).toBeVisible();100  await expect(page.locator('tbody tr')).toHaveCount(readThemeCount());101  const cookies = await page.context().cookies();102  const c = cookies.find((x) => x.name === 'kms')!;103  expect(c.httpOnly).toBe(true);104  expect(c.sameSite).toBe('Strict');105  await page.screenshot({ path: join(shots, '02-themes.png') });106  // le lien ne sert plus107  const again = await page.request.post('/api/auth/invite', { data: { token: state().tokens[0] }, headers: { origin: state().origin } });108  expect(again.status()).toBe(404);109});110function readThemeCount() {111  return readdirSync(join(here, '..', '..', 'themes')).filter((f: string) => f.endsWith('.json')).length;112}113114test('éditeur : aperçus 2D et 3D rendus par le moteur, couleur invalide refusée avec son chemin', async () => {115  await page.getByRole('link', { name: 'Signature' }).click();116  await expect(page.getByRole('heading', { name: /Signature/ })).toBeVisible();117  for (const mode of ['2d', '3d']) {118    const img = page.locator(`[data-testid=preview-${mode}] img`);119    await expect(img).toHaveAttribute('src', /^blob:/, { timeout: 20_000 });120    expect(await img.evaluate((i: HTMLImageElement) => i.naturalWidth)).toBeGreaterThan(200);121  }122  const water = page.getByLabel('palette water', { exact: true });123  await water.fill('#12');124  await water.blur();125  await expect(page.getByTestId('dirty')).toBeVisible();126  await page.getByTestId('save').click();127  await expect(page.getByRole('alert').filter({ hasText: 'Document refusé' })).toContainText('palette.water');128  await expect(page.getByTestId('dirty')).toBeVisible();129});130131test('éditeur : changer une couleur, l’aperçu suit, enregistrer le brouillon', async () => {132  const img = page.locator('[data-testid=preview-2d] img');133  const before = await img.getAttribute('src');134  const water = page.getByLabel('palette water', { exact: true });135  await water.fill('#7fa8c9');136  await water.blur();137  await expect(img).not.toHaveAttribute('src', before!, { timeout: 20_000 });138  await expect(page.locator('[data-testid=preview-2d] .err')).toHaveCount(0);139  await page.getByLabel('Note de révision').first().fill('eau plus bleue');140  await page.getByTestId('save').click();141  await expect(page.getByRole('status').filter({ hasText: 'Brouillon enregistré' })).toBeVisible();142  await expect(page.getByTestId('dirty')).toHaveCount(0);143  await page.screenshot({ path: join(shots, '03-editeur-palette.png'), fullPage: true });144  for (const tab of ['Routes', 'Bâtiments et lumière', 'Couches', 'Étiquettes', 'Marqueurs', 'JSON']) {145    await page.getByRole('tab', { name: tab }).click();146    await page.screenshot({ path: join(shots, `04-onglet-${tab.split(' ')[0].toLowerCase()}.png`) });147  }148  await page.getByRole('button', { name: 'Valider (schéma + moteur)' }).click();149  await expect(page.getByRole('status').filter({ hasText: 'Document valide' })).toBeVisible();150});151152test('publication à 10 % : le manifeste ne sert la version 2 qu’aux tranches visées', async () => {153  await page.getByRole('tab', { name: 'Versions et diffusion' }).click();154  await expect(page.getByTestId('diff')).toContainText('palette.water');155  await expect(page.getByTestId('diff')).toContainText('#7fa8c9');156  await page.getByTestId('publish-note').fill('eau plus bleue');157  await page.getByTestId('publish-percent').selectOption('10');158  await page.getByTestId('publish').click();159  await expect(page.getByRole('status').filter({ hasText: 'Publié — version 2' })).toBeVisible();160  await expect(page.getByTestId('ch-louka-web')).toContainText('stable v1');161  await expect(page.getByTestId('ch-louka-web')).toContainText('v2 à 10 %');162  await page.screenshot({ path: join(shots, '05-versions.png'), fullPage: true });163164  const v = await versionsByBucket();165  expect(v.filter((x) => x === 2).length).toBe(10);166  expect(v.filter((x) => x === 1).length).toBe(90);167  // les tranches servies sont exactement celles que le Studio annonce168  const announced = (await (await page.request.get('/api/themes/signature/buckets?percent=10')).json()).served as number[];169  expect(v.map((x, b) => (x === 2 ? b : -1)).filter((b) => b >= 0)).toEqual(announced);170  // sans tranche : version stable ; le document candidat porte bien la nouvelle couleur171  const m = await manifest('app=louka&platform=web&engine=0.1.0');172  expect(m.themes.find((t: any) => t.id === 'signature').version).toBe(1);173  const doc2 = (await (await fetch(`${state().maps}/v1/themes/signature/2.json`)).json()) as any;174  expect(doc2.palette.water).toBe('#7fa8c9');175  const doc1 = (await (await fetch(`${state().maps}/v1/themes/signature/1.json`)).json()) as any;176  expect(doc1.palette.water).not.toBe('#7fa8c9');177});178179test('passage à 100 %, puis retour arrière en une action', async () => {180  await page.getByTestId('rollout-version').selectOption('2');181  await page.getByTestId('rollout-percent').selectOption('100');182  await page.getByTestId('rollout').click();183  await expect(page.getByTestId('ch-louka-web')).toContainText('stable v2');184  expect(new Set(await versionsByBucket('immoka', 'ios'))).toEqual(new Set([2]));185186  page.once('dialog', (d) => d.accept());187  await page.getByTestId('rollback-1').click();188  await expect(page.getByRole('status').filter({ hasText: 'Retour à la version 1' })).toBeVisible();189  await expect(page.getByTestId('ch-louka-web')).toContainText('stable v1');190  expect(new Set(await versionsByBucket())).toEqual(new Set([1]));191  expect(new Set(await versionsByBucket('valoplex', 'android'))).toEqual(new Set([1]));192  await expect(page.getByTestId('versions').locator('tbody tr')).toHaveCount(2);193});194195test('déconnexion puis reconnexion avec la même clé', async () => {196  await page.getByRole('button', { name: 'Se déconnecter' }).click();197  await expect(page.getByRole('heading', { name: 'Connexion' })).toBeVisible();198  expect((await page.request.get('/api/themes')).status()).toBe(401);199  await page.getByRole('button', { name: "Se connecter avec une clé d'accès" }).click();200  await expect(page.getByRole('navigation', { name: 'Sections' })).toBeVisible();201});202203test('configuration d’application : enregistrée, servie par le manifeste', async () => {204  await page.getByRole('link', { name: 'Applications' }).click();205  await page.getByRole('tab', { name: 'Immo-Ka' }).click();206  await expect(page.getByLabel('marque accent', { exact: true })).toHaveValue(JSON.parse(readFileSync(join(here, '..', '..', 'themes', 'brands', 'immoka.json'), 'utf8')).palette.accent);207  await page.getByLabel('zoom maximum').fill('18');208  await page.getByLabel('marque accent', { exact: true }).fill('#225577');209  await page.getByLabel('marque accent', { exact: true }).blur();210  await expect(page.locator('[data-testid=preview-2d] img')).toHaveAttribute('src', /^blob:/, { timeout: 20_000 });211  await page.getByTestId('save-app').click();212  await expect(page.getByRole('status').filter({ hasText: 'Configuration enregistrée' })).toBeVisible();213  await page.screenshot({ path: join(shots, '06-applications.png'), fullPage: true });214  const m = await manifest('app=immoka&platform=web');215  expect(m.config.zoom.max).toBe(18);216  const brand = (await (await fetch(m.brand.url)).json()) as any;217  expect(brand.palette.accent).toBe('#225577');218  expect((await manifest('app=louka&platform=web')).config.zoom.max).toBe(20);219});220221test('exploitation : santé, sonde de tuiles, données, journal', async () => {222  await page.getByRole('link', { name: 'Exploitation' }).click();223  await expect(page.getByTestId('health').locator('tbody tr')).toHaveCount(4);224  await expect(page.getByTestId('health')).toContainText('en service');225  await page.screenshot({ path: join(shots, '07-sante.png'), fullPage: true });226  await page.getByRole('tab', { name: 'Performance' }).click();227  await expect(page.getByRole('heading', { name: /Requêtes/ })).toBeVisible();228  await page.screenshot({ path: join(shots, '08-performance.png'), fullPage: true });229  await page.getByRole('tab', { name: 'Tuiles' }).click();230  await page.getByTestId('probe').click();231  await expect(page.getByTestId('probe-results').locator('tbody tr')).toHaveCount(10, { timeout: 60_000 });232  await expect(page.getByRole('status').filter({ hasText: 'Sonde du' })).toContainText('0 échec');233  await page.screenshot({ path: join(shots, '09-tuiles.png'), fullPage: true });234  await page.getByRole('tab', { name: 'Usage' }).click();235  await expect(page.getByTestId('usage')).toBeVisible();236  await page.getByRole('tab', { name: 'Données et imports' }).click();237  await expect(page.getByTestId('data-versions')).toBeVisible(); // la base d'essai n'a pas le schéma meta : contenu vérifié en production238  await expect(page.getByText('Lecture seule')).toBeVisible();239  await page.screenshot({ path: join(shots, '10-donnees.png'), fullPage: true });240  await page.getByRole('link', { name: 'Journal' }).click();241  const audit = page.getByTestId('audit');242  for (const a of ['auth.register', 'theme.draft', 'theme.publish', 'theme.rollout', 'theme.rollback', 'auth.login', 'app.config', 'ops.tile-probe']) await expect(audit).toContainText(a);243  await page.screenshot({ path: join(shots, '11-journal.png') });244});245246test('clavier, tablette, console propre', async () => {247  await page.getByRole('link', { name: 'Thèmes' }).click();248  await page.keyboard.press('Tab');249  const focused = await page.evaluate(() => document.activeElement?.tagName);250  expect(['A', 'BUTTON', 'INPUT']).toContain(focused);251  await page.setViewportSize({ width: 820, height: 1180 });252  await page.getByRole('link', { name: 'Signature' }).click();253  await expect(page.locator('[data-testid=preview-2d] img')).toHaveAttribute('src', /^blob:/, { timeout: 20_000 });254  expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth + 1)).toBe(true);255  await page.screenshot({ path: join(shots, '12-tablette.png') });256  expect(problems).toEqual([]);257});258
Files main
Menu

Theme