Repository Public
1import { readFile } from "node:fs/promises";2import { expect, test } from "@playwright/test";3import { PREVIEW, PROD, S01 } from "./helpers";45test("recherche : accents, fautes de frappe, facettes, résultats horodatés", async ({ page }) => {6 await page.goto(PREVIEW + "/recherche");7 await expect(page.getByTestId("search")).toHaveAttribute("data-state", "pret");8 const input = page.getByTestId("search-input"), hits = page.getByTestId("search-hit");9 await input.fill("fenetre de contexte"); // no accent typed10 await expect(hits.first()).toContainText("Fenêtres de contexte");11 await expect(hits.first().locator("mark").first()).toHaveText(/Fenêtres|contexte/);12 await input.fill("tonaltié"); // transposed letters13 await expect(hits.first()).toContainText("tonalité");14 await expect(hits.first()).toHaveAttribute("data-type", /transcription|chapitre/);15 // Facet: transcripts only, each with a timestamp, clearly labelled as the test video16 await input.fill("hertz");17 await page.locator('[data-facet="transcription"]').click();18 await expect(page.getByTestId("search-status")).toContainText("filtres : Transcriptions");19 await expect(hits.first()).toContainText("vidéo de test technique");20 for (const h of await hits.all()) await expect(h).toHaveAttribute("data-type", "transcription");21 // A timestamped hit opens the player at that moment22 await input.fill("660 hertz chapitre");23 await hits.first().getByRole("link").click();24 await expect(page).toHaveURL(/\/regarder\?capsule=test-technique&t=60$/);25 await expect(page.getByTestId("player")).toHaveAttribute("data-status", "pret", { timeout: 20_000 });26 await expect.poll(() => page.getByTestId("video").evaluate((v: HTMLVideoElement) => v.currentTime)).toBeGreaterThanOrEqual(59);27 // Glossary and lab are searchable in preview; drafts (S02 and later) never are28 await page.goto(PREVIEW + "/recherche?q=hallucination");29 await expect(hits.first()).toHaveAttribute("data-type", "glossaire");30 const index = await (await page.request.get(PREVIEW + "/recherche/index.json")).json() as { docs: { id: string; session?: string; type: string }[] };31 expect(index.docs.filter((d) => d.type !== "seance" && d.session && d.session !== "S01")).toEqual([]);32 // Empty result, honestly worded33 await page.getByTestId("search-input").fill("licorne arc-en-ciel");34 await expect(page.getByTestId("search-empty")).toContainText("Aucun résultat");35});3637test("recherche en production : le plan seulement ; panne de l’index gérée", async ({ page }) => {38 await page.goto(PROD + "/recherche?q=agent");39 await expect(page.getByTestId("search-hit").first()).toBeVisible();40 for (const h of await page.getByTestId("search-hit").all()) await expect(h).toHaveAttribute("data-type", /seance|page/);41 await page.getByTestId("search-input").fill("hallucination");42 await expect(page.getByTestId("search-empty")).toBeVisible();43 // Index unreachable → explicit error with a retry44 let block = true;45 await page.route("**/recherche/index.json", (r) => (block ? r.abort() : r.continue()));46 await page.goto(PROD + "/recherche?q=agent");47 await expect(page.getByTestId("search-error")).toBeVisible();48 block = false;49 await page.getByRole("button", { name: "Réessayer" }).click();50 await expect(page.getByTestId("search-hit").first()).toBeVisible();51});5253test("glossaire : filtrage, liens croisés", async ({ page }) => {54 await page.goto(PREVIEW + "/glossaire");55 await expect(page.locator("[data-term]")).toHaveCount(14);56 await page.getByTestId("glossary-search").fill("token");57 await expect(page.locator("[data-term]")).toHaveCount(1);58 await expect(page.locator('[data-term="jeton"]')).toContainText(/unité de texte/i);59 await expect(page.locator('[data-term="jeton"]').getByRole("link", { name: "séance 1" })).toHaveAttribute("href", S01);60 await expect(page.locator('[data-term="jeton"]').getByRole("link", { name: "Découper un texte en jetons" })).toHaveAttribute("href", "/schemas/tokenisation");61});6263test("les neuf types d’exercices se corrigent, avec explication et nouvel essai", async ({ page }) => {64 await page.goto(PREVIEW + "/apercu");65 const q = (id: string) => page.locator(`[data-question="${id}"]`);66 const check = async (id: string, verdict: "true" | "false" | "null") => { await q(id).getByRole("button", { name: "Vérifier ma réponse" }).click(); await expect(q(id)).toHaveAttribute("data-verdict", verdict); await expect(q(id).getByTestId("feedback")).toContainText("Explication."); };67 await expect(page.locator("[data-question]")).toHaveCount(9);6869 await expect(q("demo-single").getByRole("button", { name: "Vérifier ma réponse" })).toBeDisabled(); // nothing chosen yet70 await q("demo-single").getByText("15 secondes").click(); await check("demo-single", "false");71 await expect(q("demo-single")).toContainText("Huit chapitres de 15 secondes"); // the distractor's own feedback72 await q("demo-single").getByRole("button", { name: /Réessayer cette question/ }).click();73 await q("demo-single").getByText("30 secondes").click(); await check("demo-single", "true");7475 await q("demo-vf").getByText("Faux", { exact: true }).click(); await check("demo-vf", "true");7677 for (const t of ["La position de lecture des vidéos", "Vos notes personnelles", "Vos tentatives aux quiz"]) await q("demo-multiple").getByText(t).click();78 await check("demo-multiple", "true");7980 // Ordering with the keyboard-operable arrows: bring 440 first, 550 second, 660 third.81 const order = q("demo-ordre");82 await order.getByRole("button", { name: "Monter « 440 Hz »" }).click();83 await order.getByRole("button", { name: "Monter « 550 Hz »" }).click();84 await order.getByRole("button", { name: "Monter « 550 Hz »" }).click();85 await expect(order.locator("ol > li")).toHaveText([/440/, /550/, /660/, /770/]);86 await check("demo-ordre", "true");8788 const match = q("demo-association");89 await match.getByLabel("Barre d’espace").selectOption({ label: "Lecture ou pause" });90 await match.getByLabel("Touche M").selectOption({ label: "Sourdine" });91 await match.getByLabel("Touche F").selectOption({ label: "Sous-titres" }); // deliberately wrong92 await match.getByLabel("Touche C").selectOption({ label: "Plein écran" }); // deliberately wrong93 await check("demo-association", "false");94 await expect(match.getByTestId("feedback")).toContainText("partiellement juste");95 await expect(match).toContainText("Réponse attendue : Plein écran");9697 await q("demo-numerique").getByLabel(/Votre réponse/).fill("24,0"); await check("demo-numerique", "true");9899 await q("demo-trous").getByLabel("Mot manquant numéro 1").fill("Mire");100 await q("demo-trous").getByLabel("Mot manquant numéro 2").fill("vtt");101 await check("demo-trous", "true");102103 await q("demo-debogage").getByLabel(/^Ligne 4/).check();104 await q("demo-debogage").getByText("total += note").click();105 await check("demo-debogage", "true");106107 await q("demo-reflexion").getByLabel("Votre réponse").fill("Sans compte, le serveur ne reconnaît pas la personne.");108 await check("demo-reflexion", "null");109 await expect(q("demo-reflexion")).toContainText("Réponse type");110111 await page.getByTestId("quiz-finish").click();112 await expect(page.getByTestId("quiz-score")).toHaveText("7"); // 7 of the 8 auto-graded questions; the reflection is not counted113 await expect(page.getByTestId("quiz-result")).toContainText("sur 8");114 await expect(page.getByTestId("quiz-result")).toContainText("1 question autoévaluée");115 await page.getByTestId("quiz-restart").click();116 await expect(page.locator("[data-verdict]")).toHaveCount(0);117 await expect(page.getByTestId("quiz-history")).toContainText("(1)");118});119120test("exporter, effacer, puis importer ses données locales", async ({ page }, testInfo) => {121 await page.goto(`${PREVIEW}${S01}/regarder`);122 await expect(page.getByTestId("player")).toHaveAttribute("data-status", "pret", { timeout: 20_000 });123 await page.getByRole("tab", { name: /Notes/ }).click();124 await page.getByTestId("notes-area").fill("Note à transporter d’un appareil à l’autre.");125 await expect(page.getByTestId("notes-status")).toContainText("enregistrées");126 // Notes export (Markdown)127 const [md] = await Promise.all([page.waitForEvent("download"), page.getByTestId("notes-export").click()]);128 expect(md.suggestedFilename()).toBe("atlas-ia-S01-notes.md");129 expect(await readFile(await md.path(), "utf8")).toContain("Note à transporter");130 // Transcript export (plain text)131 await page.getByRole("tab", { name: /Transcription/ }).click();132 const [txt] = await Promise.all([page.waitForEvent("download"), page.getByTestId("transcript-export").click()]);133 expect(await readFile(await txt.path(), "utf8")).toContain("[0:30] Changement de chapitre : la tonalité passe à 550 hertz.");134135 await page.goto(PREVIEW + "/confidentialite");136 await expect(page.locator('[data-count="Séances annotées"]')).toHaveText("1");137 const [json] = await Promise.all([page.waitForEvent("download"), page.getByTestId("data-export").click()]);138 const file = testInfo.outputPath("export.json");139 await json.saveAs(file);140 expect(JSON.parse(await readFile(file, "utf8"))).toMatchObject({ app: "atlas-ia", kind: "etat-local", state: { v: 1 } });141142 await page.getByTestId("clear-data").click(); await page.getByTestId("clear-confirm").click();143 await expect(page.locator('[data-count="Séances annotées"]')).toHaveText("0");144145 // A file that is not an export is refused with an explanation146 await page.getByTestId("data-file").setInputFiles({ name: "autre.json", mimeType: "application/json", buffer: Buffer.from('{"app":"autre"}') });147 await expect(page.getByTestId("data-message")).toHaveText("Ce fichier ne provient pas d’un export ATLAS IA.");148 // The real export is accepted149 await page.getByTestId("data-file").setInputFiles(file);150 await page.getByTestId("import-merge").click();151 await expect(page.getByTestId("data-message")).toContainText("importées et fusionnées");152 await expect(page.locator('[data-count="Séances annotées"]')).toHaveText("1");153 await page.goto(`${PREVIEW}${S01}/regarder`);154 await page.getByRole("tab", { name: /Notes/ }).click();155 await expect(page.getByTestId("notes-area")).toHaveValue("Note à transporter d’un appareil à l’autre.");156});157158test("thème clair ou sombre : suit le système, se règle, se retient", async ({ browser }) => {159 for (const scheme of ["dark", "light"] as const) {160 const context = await browser.newContext({ colorScheme: scheme });161 const page = await context.newPage();162 await page.goto(PROD + "/");163 await expect(page.locator("html")).toHaveAttribute("data-theme", scheme);164 await context.close();165 }166 const context = await browser.newContext({ colorScheme: "light" });167 const page = await context.newPage();168 await page.goto(PROD + "/");169 await page.getByTestId("theme-toggle").click(); // système → clair170 await page.getByTestId("theme-toggle").click(); // clair → sombre171 await expect(page.locator("html")).toHaveAttribute("data-theme", "dark");172 await page.goto(PROD + "/programme");173 await expect(page.locator("html")).toHaveAttribute("data-theme", "dark");174 await context.close();175});176177test("hors ligne : le site le dit, puis se rétablit", async ({ page, context }) => {178 await page.goto(PROD + "/programme");179 await expect(page.getByTestId("offline-banner")).toHaveCount(0);180 await context.setOffline(true);181 await expect(page.getByTestId("offline-banner")).toContainText("Vous êtes hors ligne.");182 await page.getByTestId("catalog-search").fill("git"); // what is already loaded keeps working183 await expect(page.locator('li[data-session="S17"]')).toBeVisible();184 await context.setOffline(false);185 await expect(page.getByTestId("offline-banner")).toHaveCount(0);186});187188test("mouvement réduit : aucune animation ni transition perceptible", async ({ browser }) => {189 const context = await browser.newContext({ reducedMotion: "reduce" });190 const page = await context.newPage();191 await page.goto(PROD + "/");192 const longest = await page.evaluate(() => Math.max(...[...document.querySelectorAll("*")].map((el) => { const s = getComputedStyle(el); return Math.max(...`${s.transitionDuration},${s.animationDuration}`.split(",").map((d) => parseFloat(d) * (d.trim().endsWith("ms") ? 1 : 1000))); })));193 expect(longest).toBeLessThan(1);194 expect(await page.evaluate(() => getComputedStyle(document.documentElement).scrollBehavior)).toBe("auto");195 await context.close();196});197198test("schémas interactifs : les réglages recalculent le modèle", async ({ page }) => {199 // 1. Tokenisation: three methods, three different counts for the same text200 await page.goto(PREVIEW + "/schemas/tokenisation");201 const counts = await Promise.all(["mots", "sous-mots", "caracteres"].map((m) => page.getByTestId(`tok-count-${m}`).innerText()));202 expect(new Set(counts).size).toBe(3);203 await page.getByTestId("tok-input").fill("chat");204 await expect(page.getByTestId("tok-count-mots")).toHaveText("1");205 await expect(page.getByTestId("tok-count-caracteres")).toHaveText("4");206 await page.getByTestId("text-equivalent").locator("summary").click();207 await expect(page.getByTestId("text-equivalent")).toContainText("Texte : « chat »");208209 // 2. Attention: weights sum to 1; the causal mask hides later tokens210 await page.goto(PREVIEW + "/schemas/attention");211 await expect(page.getByTestId("att-sum")).toHaveText("1,00");212 await expect(page.getByTestId("att-score-3")).toHaveText("masqué (−∞)");213 await expect(page.getByTestId("att-weight-3")).toHaveText("0,00");214 await page.getByTestId("att-causal").uncheck();215 await expect(page.getByTestId("att-score-3")).not.toHaveText("masqué (−∞)");216 await expect(page.getByTestId("att-sum")).toHaveText("1,00");217218 // 6. Agent loop: with a budget of 6 steps the agent stops without success219 await page.goto(PREVIEW + "/schemas/boucle-agent");220 await page.getByTestId("loop-budget").fill("6");221 for (let i = 0; i < 6; i++) await page.getByTestId("loop-step").click();222 await expect(page.getByTestId("loop-step")).toBeDisabled();223 await expect(page.getByTestId("verdict")).toHaveAttribute("data-tone", "warn");224 await expect(page.getByTestId("verdict")).toContainText("budget de 6 étapes épuisé");225226 // 8. Shell: exit codes and filesystem effects, typed at the keyboard227 await page.goto(PREVIEW + "/schemas/terminal-shell");228 const term = page.getByTestId("term-input");229 await term.fill("mkdir essais"); await term.press("Enter");230 await expect(page.getByTestId("term-tree")).toContainText("essais/");231 await expect(page.getByTestId("term-code")).toContainText("0");232 await term.fill("python"); await term.press("Enter");233 await expect(page.getByTestId("term-code")).toContainText("127");234 await expect(page.getByTestId("term-output")).toContainText("python : commande introuvable");235236 // 11. Git: merging is impossible until tests pass and a human approves237 await page.goto(PREVIEW + "/schemas/flux-git");238 const git = (a: string) => page.locator(`[data-git="${a}"]`);239 await git("branche").click(); await git("commit-defaut").click(); await git("pr").click(); await git("tests").click(); await git("approuver").click();240 await expect(git("fusionner")).toBeDisabled();241 await expect(page.getByTestId("verdict")).toHaveAttribute("data-tone", "bad");242 await git("corriger").click(); await git("tests").click(); await git("approuver").click();243 await expect(git("fusionner")).toBeEnabled();244 await git("fusionner").click();245 await expect(page.getByTestId("git-log")).toContainText("Commit de fusion");246247 // 14. Prompt injection: least privilege stops the attack at the tool call248 await page.goto(PREVIEW + "/schemas/injection-requetes");249 await expect(page.getByTestId("verdict")).toHaveAttribute("data-tone", "bad");250 await page.getByTestId("inj-mark").check();251 await expect(page.getByTestId("verdict")).toHaveAttribute("data-tone", "warn"); // marking alone guarantees nothing252 await page.getByTestId("inj-least").check();253 await expect(page.getByTestId("verdict")).toHaveAttribute("data-tone", "ok");254255 // Every diagram renders, offers a text equivalent and is reachable from the index256 await page.goto(PREVIEW + "/schemas");257 const links = await page.locator("[data-diagram-link]").evaluateAll((els) => els.map((e) => e.getAttribute("href")!));258 expect(links).toHaveLength(15);259 for (const href of links) {260 await page.goto(PREVIEW + href);261 await expect(page.getByTestId("diagram")).toBeVisible();262 await expect(page.getByTestId("text-equivalent")).toHaveCount(1);263 }264});265266test("schémas : utilisables au clavier seul", async ({ page }) => {267 await page.goto(PREVIEW + "/schemas/pipeline-rag");268 await page.getByTestId("step-next").focus();269 await page.keyboard.press("Enter");270 await expect(page.getByTestId("step-text")).toContainText("Recevoir la question");271 await page.keyboard.press("Space");272 await expect(page.getByTestId("step-text")).toContainText("Convertir la question en vecteur");273 // Radio group of failure modes: arrow keys move the selection274 await page.getByRole("radio", { name: "Aucune panne" }).focus();275 await page.keyboard.press("ArrowRight");276 await expect(page.getByRole("radio", { name: "Information absente ou périmée" })).toBeChecked();277 await expect(page.getByTestId("verdict")).toHaveAttribute("data-tone", "bad");278});279