// Parcours de l'app dans un vrai navigateur (Chromium sans écran, Playwright), // en thème sombre puis clair, avec des captures 412×915 dans build/shots/. // Lancé par `make test-browser` dans l'image Docker de Playwright : // node parcours.cjs // Le script sert lui-même l'app (serveur statique minimal) et mesure le poids // transféré au premier chargement (brut et compressé gzip). // // La date est figée au mercredi 18 novembre 2026, 9 h, puis le temps s'écoule // normalement : le planning de la semaine est donc toujours le même. const http = require("node:http"); const fs = require("node:fs"); const path = require("node:path"); const zlib = require("node:zlib"); const { chromium } = require("/tools/node_modules/playwright"); const appDir = path.resolve(process.argv[2] ?? "app"); const outDir = path.resolve(process.argv[3] ?? "build/shots"); const START = new Date("2026-11-18T09:00:00"); const TYPES = { ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8", ".json": "application/json", ".webmanifest": "application/manifest+json", ".svg": "image/svg+xml", ".woff2": "font/woff2", ".md": "text/markdown; charset=utf-8", ".txt": "text/plain; charset=utf-8", }; /** Octets servis au chargement : chemin → {brut, gzip}. */ const served = new Map(); const server = http.createServer((req, res) => { const url = new URL(req.url, "http://localhost"); const file = path.join(appDir, decodeURIComponent(url.pathname === "/" ? "/index.html" : url.pathname)); if (!file.startsWith(appDir) || !fs.existsSync(file) || fs.statSync(file).isDirectory()) { res.writeHead(404).end(); return; } const body = fs.readFileSync(file); if (!served.has(url.pathname)) served.set(url.pathname, { raw: body.length, gzip: zlib.gzipSync(body, { level: 9 }).length }); res.writeHead(200, { "Content-Type": TYPES[path.extname(file)] ?? "application/octet-stream", "Cache-Control": "no-cache" }); res.end(body); }); let failures = 0; /** Page en cours, pour une capture si le parcours s'interrompt. */ let lastPage = null; /** @param {string} scheme @param {boolean} cond @param {string} msg */ function check(scheme, cond, msg) { if (cond) console.log(`ok [${scheme}] ${msg}`); else { failures++; console.log(`ÉCHEC [${scheme}] ${msg}`); } } (async () => { await new Promise((r) => server.listen(0, "127.0.0.1", r)); const base = `http://127.0.0.1:${server.address().port}/`; fs.mkdirSync(outDir, { recursive: true }); const browser = await chromium.launch(); for (const scheme of ["dark", "light"]) { const ctx = await browser.newContext({ viewport: { width: 412, height: 915 }, colorScheme: scheme, deviceScaleFactor: 1, locale: "fr-FR", acceptDownloads: true, permissions: ["clipboard-read", "clipboard-write"], }); await ctx.clock.install({ time: START }); await ctx.clock.resume(); const page = await ctx.newPage(); lastPage = page; const errors = []; page.on("pageerror", (e) => errors.push(String(e))); page.on("console", (m) => { if (m.type() === "error") errors.push(m.text()); }); const ok = (cond, msg) => check(scheme, cond, msg); const shot = (name, full = false) => page.screenshot({ path: `${outDir}/${scheme}-${name}.png`, fullPage: full }); const settle = () => page.waitForTimeout(250); const go = async (hash) => { await page.goto(base + hash); await page.waitForSelector("h1"); await settle(); }; const button = (name, opts = {}) => page.getByRole("button", { name, ...opts }); const inDialog = (name) => page.locator("dialog[open]").getByRole("button", { name }); // ---- premier lancement --------------------------------------------------------- served.clear(); await go("#/"); await page.waitForLoadState("networkidle"); if (scheme === "dark") { const raw = [...served.values()].reduce((n, x) => n + x.raw, 0); const gz = [...served.values()].reduce((n, x) => n + x.gzip, 0); const report = `Premier chargement (onboarding) : ${served.size} fichiers, ${(raw / 1024).toFixed(1)} Ko bruts, ${(gz / 1024).toFixed(1)} Ko en gzip -9.\n` + [...served].sort((a, b) => b[1].raw - a[1].raw).map(([p, x]) => ` ${p} ${x.raw} o (gzip ${x.gzip} o)`).join("\n") + "\n"; fs.writeFileSync(`${outDir}/poids.txt`, report); console.log(report.split("\n")[0]); } ok(await button("Créer mon programme").isVisible(), "onboarding : action principale visible"); await shot("01-onboarding", true); await button("Créer mon programme").click(); await settle(); ok(await page.getByText("Copié. Colle-le dans ton IA.").isVisible(), "texte d'accueil copié"); // ---- programme d'exemple : proposition, aperçu, adoption ----------------------- await button("Programme d'exemple").click(); await settle(); ok(await page.getByText("Un programme t'attend").isVisible(), "la proposition passe avant tout"); ok(await page.getByText("Nouveau programme ·").isVisible(), "aperçu : nouveau programme"); await shot("02-proposition"); await button("Adopter").click(); await settle(); ok(await page.getByText("Pas de planning").isVisible(), "accueil sans planning : rotation annoncée"); ok(await page.locator(".hud").isVisible(), "HUD de niveau affiché"); // ---- semaine : jours, jour imposé, semaine suivante, .ics ------------------------ await go("#/semaine"); for (const d of ["lundi", "mercredi", "vendredi", "samedi"]) await page.getByRole("button", { name: d, exact: true }).click(); await settle(); ok(await page.locator(".week__row").count() === 7, "semaine : sept jours"); ok(await page.locator(".week__row", { hasText: "Séance" }).count() === 3, "trois séances de force placées"); ok(await page.locator(".week__row", { hasText: "Cardio" }).count() === 1, "le cardio remplit le samedi"); await page.locator(".week__day").nth(6).click(); await button("Repos", { exact: true }).click(); await settle(); ok(await page.locator(".week__row").nth(6).getByText("Repos imposé").isVisible(), "dimanche : repos imposé"); await shot("03-semaine", true); const ics = page.waitForEvent("download"); await button("Télécharger le .ics").click(); const icsText = fs.readFileSync(await (await ics).path(), "utf8"); ok(/BEGIN:VCALENDAR/.test(icsText) && /DTSTART:20261120T180000/.test(icsText), "export .ics : vendredi 18 h"); await button("Semaine suivante").click(); await settle(); ok(await page.getByText("réglage propre à cette semaine").count() === 0, "semaine suivante : suit le réglage par défaut"); await page.getByRole("button", { name: "mardi", exact: true }).click(); await settle(); ok(await page.getByText("réglage propre à cette semaine").isVisible(), "semaine suivante : réglage propre"); await button("Cette semaine").click(); // ---- accueil planifié : carte du jour, retard --------------------------------------- await go("#/"); ok(await page.getByText("En retard cette semaine").isVisible(), "lundi en retard"); ok(await page.getByRole("link", { name: "Commencer" }).isVisible(), "aujourd'hui : séance à commencer"); await shot("04-accueil"); await shot("04b-accueil-long", true); await button("Autre activité").click(); ok(await page.getByLabel("Le", { exact: true }).isVisible(), "autre activité : date au choix"); await button("Autre activité").click(); // ---- séance A (le retard de lundi), faite aujourd'hui --------------------------- await page.locator(".block--today").getByRole("link", { name: "Faire" }).click(); await page.waitForSelector(".screen--session"); await settle(); await page.locator("summary", { hasText: "Squat barre" }).click(); const squat = page.locator("details[open]", { hasText: "Squat barre" }).last(); const load = squat.getByLabel("Charge"); await load.fill("60"); await load.press("Tab"); for (let i = 1; i <= 3; i++) { await squat.getByRole("button", { name: new RegExp(`^Série ${i} : à faire`) }).click(); await squat.locator(".effort[data-effort=ok]").click(); await page.locator(".timer").getByRole("button", { name: "Terminer" }).click(); } ok(await page.locator(".combo").innerText().then((t) => /COMBO ×3/i.test(t)), "combo ×3 après trois séries"); await squat.getByRole("button", { name: /^Série 4 : à faire/ }).click(); await squat.getByRole("button", { name: "Une répétition de moins" }).click(); await shot("05-serie"); await squat.locator(".effort[data-effort=hard]").click(); await settle(); ok(await page.locator(".timer").isVisible(), "le repos démarre au ressenti"); ok(await squat.getByRole("button", { name: "Série 4 : 7 répétitions, dur" }).count() === 1, "série 4 : 7 répétitions, dur"); await shot("06-repos"); await page.locator(".timer").getByRole("button", { name: "Terminer" }).click(); // Gainage : chrono de 2 s, qui coche la série. await page.locator("summary", { hasText: "Gainage" }).click(); const plank = page.locator("details[open]", { hasText: "Gainage" }).last(); const secs = plank.getByLabel("Durée"); await secs.fill("2"); await secs.press("Tab"); await plank.getByRole("button", { name: /Lancer la série/ }).click(); await page.waitForTimeout(3000); ok(await plank.locator(".set-btn--done").count() === 1, "le chrono coche la série au temps"); await plank.locator(".effort[data-effort=ok]").click(); await page.locator(".timer").getByRole("button", { name: "Terminer" }).click(); await button("Terminer la séance").click(); await page.waitForSelector("dialog[open]"); await inDialog("Enregistrer quand même").click(); await page.waitForSelector(".screen--finish"); await page.waitForTimeout(1200); ok(await page.getByText("Bien joué.").isVisible(), "écran de fin de séance"); ok(await page.locator(".reward__gain").innerText().then((t) => /\+\d+ XP/.test(t.replace(/\s/g, " "))), "XP gagnée affichée"); ok(await page.locator(".reward__big .big-number").innerText().then((t) => t.replace(/\s/g, "") === "1860"), "1 860 kg soulevés (31 répétitions × 60 kg)"); await shot("07-fin-de-seance", true); await page.getByRole("link", { name: "Continuer" }).click(); await settle(); ok(await page.getByText("En retard cette semaine").count() === 0, "le retard de lundi est rattrapé"); // ---- progression de la charge (double progression) --------------------------------- // Une séance A complète au haut de la fourchette : le conseil apparaît. await page.evaluate(async () => { const { store } = await import("./main.js"); const s = store.getState(); const a = s.program.sessions.find((x) => x.key === "A"); store.dispatch("SessionLogged", { date: "2026-11-18", kind: "strength", ref: "A", name: a.name, warmup: null, exercises: [{ id: "squat", name: "Squat barre", target: "4 × 8", tracking: "load", loadKg: 60, seconds: null, plannedSets: 4, sets: Array.from({ length: 4 }, () => ({ reps: 8, effort: "easy" })) }], }); }); await go("#/seance/A"); await page.locator("summary", { hasText: "Squat barre" }).click(); ok(await page.getByText("Prêt à monter").isVisible(), "conseil de progression : prêt à monter"); ok(await page.locator(".exercise--warmup").getByText("50 kg × 5 reps").count() === 0 && await page.locator(".exercise--warmup").getByText("30 kg × 8 reps").isVisible(), "séries d'approche chiffrées depuis 60 kg"); await shot("08-conseil"); await button("Adopter 62,5 kg").click(); ok(await page.locator("details[open]", { hasText: "Squat barre" }).last().getByLabel("Charge").inputValue().then((v) => v === "62,5"), "charge adoptée : 62,5 kg"); await page.evaluate(() => localStorage.removeItem("ia-fit.draft")); // ---- activités ------------------------------------------------------------------- await go("#/activites"); await page.getByLabel("Nom").fill("Foot en salle"); await button("Bas du corps").click(); await button("Intense").click(); await button("Enregistrer l'activité").click(); await settle(); ok(await page.locator(".row", { hasText: "Foot en salle" }).isVisible(), "activité ajoutée"); await shot("09-activites", true); // ---- poids ----------------------------------------------------------------------- await go("#/poids"); await page.locator(".import > summary").click(); await page.getByLabel(/Une pesée par ligne/).fill(["2026-08-01 86,2", "15/08/2026 ; 85,4", "2026-09-01 84,9", "2026-09-20 84,1", "2026-10-10 83,6", "2026-10-30 83,0", "pas une pesée", "2026-11-12 82,4"].join("\n")); await button("Lire").click(); ok(await page.getByText("7 pesées lisibles.").isVisible(), "import : 7 pesées lisibles, 1 ignorée"); await button("Importer 7 pesées").click(); await page.getByLabel("Poids (kg)").fill("82,1"); await button("Enregistrer", { exact: true }).click(); await settle(); ok(await page.locator(".stat__value").first().innerText().then((t) => t.startsWith("82,1")), "pesée du jour : 82,1 kg"); ok(await page.locator(".chart svg path.chart__line").count() === 1, "courbe tracée"); await button("Tout").click(); await shot("10-poids", true); // ---- profil et mode ---------------------------------------------------------------- await go("#/profil"); await page.getByLabel("Objectif").fill("Prendre de la force sans me blesser"); await page.getByLabel("Matériel").fill("Barre\nBanc\nHaltères"); await button("Enregistrer le profil").click(); ok(await page.getByText("Profil enregistré.").isVisible(), "profil enregistré"); await button("Maintien").click(); ok(await button("Maintien").getAttribute("aria-pressed") === "true", "mode maintien"); await shot("11-profil", true); await button("Progression", { exact: true }).click(); // ---- analyses, progression ------------------------------------------------------- await go("#/analyses"); ok(await page.locator(".chart svg").count() === 1, "assiduité : barres"); await shot("12-analyses", true); await page.getByRole("link", { name: /Squat barre/ }).click(); await settle(); ok(await page.locator(".chart__line").count() >= 1, "squat : courbe de charge"); await shot("13-analyse-squat", true); await go("#/progression"); ok(await page.getByText("Premier pas").isVisible(), "succès « Premier pas »"); await shot("14-progression", true); // ---- données : export, texte pour l'IA, import ---------------------------------- await go("#/donnees"); const dl = page.waitForEvent("download"); await button("Exporter une sauvegarde").click(); const snapshot = fs.readFileSync(await (await dl).path(), "utf8"); ok(JSON.parse(snapshot).format === "ia-fit-snapshot", "sauvegarde exportée"); await button("Copier le texte pour mon IA").click(); const brief = await page.evaluate(() => navigator.clipboard.readText()); ok(brief.startsWith("# IA-Fit : fais évoluer mon programme"), "texte pour l'IA copié"); // Un long texte : posé d'un coup plutôt que tapé. await page.locator("#imp-text").evaluate((el, text) => { el.value = text; }, snapshot); await button("Lire le texte").click(); ok(await page.getByText("Sauvegarde IA-Fit", { exact: true }).isVisible(), "import : instantané reconnu"); await shot("15-donnees", true); await button("Fusionner avec mes données").click(); ok(await page.getByText("Rien de nouveau").isVisible(), "fusion : rien de nouveau"); // ---- proposition par lien : aperçu, refus, lien rouvert --------------------------- const link = await page.evaluate(async () => { const { store } = await import("./main.js"); const program = structuredClone(store.getState().program); program.sessions[0].exercises[0].sets = 5; program.sessions[0].exercises[0].reps = "5"; program.sessions[1].exercises.pop(); program.sessions[2].exercises.push({ ref: "plank", sets: 2, reps: "45 s", rest: 60 }); return "#import-json=" + encodeURIComponent(JSON.stringify({ program, reason: "Plus lourd sur le squat, moins de volume en B." })); }); await go(link); ok(await page.getByText("Par rapport à ton programme").isVisible(), "lien : aperçu des changements"); ok(await page.locator(".diff__lines li[data-change=removed]").count() === 1, "aperçu : un exercice retiré"); ok(await page.locator(".diff__lines li[data-change=added]").count() === 1, "aperçu : un exercice ajouté"); await shot("16-proposition-lien", true); await button("Refuser").click(); await settle(); await go(link); ok(await page.getByText("Déjà refusée").isVisible(), "lien rouvert : déjà refusée"); await shot("17-deja-refusee"); await button("La réexaminer").click(); await settle(); await button("Adopter").click(); await settle(); ok(await page.evaluate(async () => (await import("./main.js")).store.getState().program.sessions[0].exercises[0].sets) === 5, "proposition réexaminée puis adoptée"); // ---- historique : correction et retrait ------------------------------------------ await go("#/historique"); await page.locator(".history__item").first().click(); await settle(); await shot("18-correction"); await button("Enregistrer les modifications").click(); await settle(); ok(await page.locator(".history__item").count() >= 1, "historique listé"); // ---- semaine : Retirer, Non fait, Annuler ---------------------------------------- await go("#/semaine"); const monday = page.locator(".week__row").first(); ok(await monday.getByText("✓ Fait").isVisible(), "lundi fait (décalé)"); // Deux séances A ce mercredi : chacune remplit le créneau de lundi tour à tour. for (let i = 0; i < 3 && await monday.getByRole("button", { name: "Retirer" }).count(); i++) { await monday.getByRole("button", { name: "Retirer" }).click(); await inDialog("Retirer").click(); await settle(); } await monday.getByRole("button", { name: "Non fait" }).click(); await settle(); ok(await monday.getByText("✕ Non fait").isVisible(), "lundi marqué non fait"); await monday.getByRole("button", { name: "Annuler" }).click(); await settle(); ok(await monday.getByRole("button", { name: "Faite" }).isVisible(), "lundi : de nouveau à faire"); // ---- réinitialisation -------------------------------------------------------------- await go("#/donnees"); await button("Tout effacer").click(); await inDialog("Continuer").click(); await inDialog("Tout effacer").click(); await settle(); ok(await button("Créer mon programme").isVisible(), "réinitialisation : retour à l'onboarding"); ok(errors.length === 0, "aucune erreur dans la console" + (errors.length ? " : " + errors.join(" | ") : "")); await ctx.close(); } await browser.close(); server.close(); console.log(failures ? `\n${failures} échec(s).` : "\nParcours : OK"); process.exit(failures ? 1 : 0); })().catch(async (e) => { console.error(e); if (lastPage) await lastPage.screenshot({ path: `${outDir}/erreur.png`, fullPage: true }).catch(() => {}); process.exit(1); });