Repository Public
1import { execFileSync, spawn } from "node:child_process";2import { existsSync, mkdirSync, openSync, readFileSync, writeFileSync } from "node:fs";3import { resolve } from "node:path";4import { writeDeckRepo } from "../tests/fixtures/deck-fixture";5import { SLIDES_ENV, STUDIO, STUDIO_ENV } from "../playwright.config";6import { buildCourseRepo, buildMedia } from "./studio-fixtures";78/**9 * Runs once, after the three servers are up. Checks the builds, then prepares the studio journey:10 * synthetic media (generated by ffmpeg, never committed), a snapshot of the course repository derived from11 * the committed manifest, a one-time enrolment link produced by the operator's command line, and the media12 * worker as a real, separate process (stopped by PID in the global teardown).13 */14export default async function globalSetup() {15 const missing = [16 [".next/BUILD_ID", "pnpm build"],17 ["data/media/S01/test-technique/master.m3u8", "pnpm media:test-capsule"],18 [".next-preview/BUILD_ID", "pnpm build:preview"],19 ].filter(([file]) => !existsSync(resolve(file!)));20 if (missing.length) throw new Error(`Préparation incomplète. Lancer dans l'ordre : ${missing.map(([, cmd]) => cmd).join(" ; ")}`);2122 prepareSlides();2324 const tmp = resolve("e2e/.tmp/studio"), env = { ...process.env, ...STUDIO_ENV } as NodeJS.ProcessEnv;25 mkdirSync(resolve(tmp, "fixtures"), { recursive: true });26 buildMedia(resolve(tmp, "fixtures"));27 buildCourseRepo(resolve(STUDIO.repo), resolve(tmp, "fixtures"));2829 // The first passkey is enrolled with a link that only the server's shell can produce.30 const link = execFileSync("node_modules/.bin/tsx", ["scripts/studio.ts", "enrol", "--name", "Enseignant d’essai"], { env, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();31 if (!link.startsWith(`${STUDIO.base}/admin/enrolement?jeton=`)) throw new Error(`Lien d'enrôlement inattendu : ${link.slice(0, 60)}`);3233 const log = openSync(resolve(tmp, "worker.log"), "a");34 const worker = spawn("node_modules/.bin/tsx", ["scripts/worker.ts"], { env, stdio: ["ignore", log, log], detached: false });35 writeFileSync(resolve(tmp, "state.json"), JSON.stringify({ enrol: link, workerPid: worker.pid }));36 worker.unref();37 if (!JSON.parse(readFileSync(resolve(tmp, "state.json"), "utf8")).workerPid) throw new Error("Le processus de traitement n'a pas démarré.");38}3940/**41 * Slide decks for e2e/slides.spec.ts, through the very commands an operator runs: build packs from a small42 * repository with hand-made PDFs (poppler), import three, publish the slides of two. Without poppler the43 * spec is skipped, and says so.44 */45function prepareSlides() {46 const tmp = resolve("e2e/.tmp/slides"), env = { ...process.env, ...SLIDES_ENV } as NodeJS.ProcessEnv, tsx = "node_modules/.bin/tsx";47 mkdirSync(tmp, { recursive: true });48 try { for (const c of ["pdfinfo", "pdftotext", "pdftocairo"]) execFileSync(c, ["-v"], { stdio: "ignore" }); }49 catch { writeFileSync(resolve(tmp, "state.json"), JSON.stringify({ ready: false })); return; }50 writeDeckRepo(resolve(tmp, "repo"), ["S01", "S02", "S03"]);51 execFileSync(tsx, ["scripts/slides.ts", "--from", resolve(tmp, "repo"), "--out", resolve(tmp, "packs")], { env, stdio: "ignore" });52 execFileSync(tsx, ["scripts/studio.ts", "slides-import", ...["S01", "S02", "S03"].map((s) => resolve(tmp, "packs", `${s}-slides.tar.gz`))], { env, stdio: "ignore" });53 execFileSync(tsx, ["scripts/studio.ts", "slides-publish", "S01", "S02"], { env, stdio: "ignore" });54 const dir = (s: string) => (JSON.parse(readFileSync(resolve(tmp, "packs", s, "deck.json"), "utf8")) as { dir: string }).dir;55 writeFileSync(resolve(tmp, "state.json"), JSON.stringify({ ready: true, dirs: { S01: dir("S01"), S02: dir("S02"), S03: dir("S03") } }));56}57