Repository Public
1import { execFileSync } from "node:child_process";2import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";3import { join } from "node:path";4import { stringify } from "yaml";56/** Sentinel words that exist nowhere else: tests look for them (or for their absence) on the public site. */7export const WORDS = { lab1: "ornithorynque", lab2: "hippocampe", caption: "saxifrage", importedLab: "coquelicot", newSession: "Séance ajoutée par le dépôt" };89const ff = (args: string[]) => execFileSync("ffmpeg", ["-hide_banner", "-loglevel", "error", "-y", ...args], { stdio: "ignore" });1011/** Small synthetic media generated on the spot (a test pattern and a tone): nothing of it is committed. */12export function buildMedia(dir: string) {13 // 8 s, 640×360, 25 fps, with audio — small enough to encode in a second or two.14 ff(["-f", "lavfi", "-i", "testsrc=size=640x360:rate=25:duration=8", "-f", "lavfi", "-i", "sine=frequency=440:duration=8", "-c:v", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "64k", "-shortest", join(dir, "capsule.mp4")]);15 const cue = (i: number, text: string) => `${i + 1}\n00:00:0${i * 2}.000 --> 00:00:0${i * 2 + 2}.000\n${text}\n`;16 writeFileSync(join(dir, "captions.fr.vtt"), `WEBVTT\n\n${[`Ceci est une vidéo d’essai : une mire et une tonalité.`, `Le mot ${WORDS.caption} sert à vérifier la recherche.`, "Troisième réplique de la vidéo d’essai.", "Fin de la vidéo d’essai."].map((t, i) => cue(i, t)).join("\n")}`);17 // Overlapping cues and a cue that ends before it starts: must be refused.18 writeFileSync(join(dir, "captions-invalides.vtt"), "WEBVTT\n\n00:00:00.000 --> 00:00:04.000\nPremière.\n\n00:00:02.000 --> 00:00:05.000\nChevauche la première.\n\n00:00:07.000 --> 00:00:06.000\nFinit avant de commencer.\n");19 // A web page named like a video, and a program named like a PDF: disguised files.20 writeFileSync(join(dir, "pas-une-video.mp4"), "<!doctype html><html><body><script>alert('x')</script>Ceci n'est pas une vidéo.</body></html>");21 writeFileSync(join(dir, "pas-un-pdf.pdf"), Buffer.concat([Buffer.from([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1, 0]), Buffer.alloc(200)]));22 writeFileSync(join(dir, "diapositives.pdf"), "%PDF-1.4\n1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj\n2 0 obj<</Type/Pages/Kids[]/Count 0>>endobj\ntrailer<</Root 1 0 R>>\n%%EOF\n");23 writeFileSync(join(dir, "diapositives-v2.pdf"), "%PDF-1.4\n% deuxième version\n1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj\n2 0 obj<</Type/Pages/Kids[]/Count 0>>endobj\ntrailer<</Root 1 0 R>>\n%%EOF\n");24}2526interface M { course: Record<string, string>; author: Record<string, string>; parts: unknown[]; sessions: { id: string; aliases: string[]; part: string; level: string; title: string; short: string; dependsOn: string[]; tags: string[]; outcomes: string[] }[] }2728/**29 * A snapshot of the course repository, written from the committed manifest so that the plan is the real one,30 * with what an import must cope with: a session whose title changed (S01, with its material rewritten), a new31 * session (S25), a session still being written (S02: half a metadata file) and 22 sessions without any32 * directory. Also packed as .tar.gz, the way a snapshot is uploaded in production.33 */34export function buildCourseRepo(repo: string, fixtures: string) {35 const m = JSON.parse(readFileSync("content/course.manifest.json", "utf8")) as M;36 rmSync(repo, { recursive: true, force: true });37 const sessions = m.sessions.map((s) => ({ id: s.id, slug: s.aliases[0] ?? s.id.toLowerCase(), part: s.part, level: s.level, title: s.id === "S01" ? `${s.title} (révisé dans le dépôt)` : s.title, short: s.short, depends_on: s.dependsOn, tags: s.tags, outcomes: s.outcomes }));38 sessions.push({ id: "S25", slug: "added-by-repo", part: m.sessions[m.sessions.length - 1]!.part, level: "avancé", title: WORDS.newSession, short: "Séance du dépôt", depends_on: ["S01"], tags: ["essai"], outcomes: ["Vérifier qu’une séance ajoutée arrive en brouillon."] });39 const c = m.course, a = m.author;40 const s1 = join(repo, "sessions", `S01-${sessions[0]!.slug}`), s2 = join(repo, "sessions", `S02-${sessions[1]!.slug}`);41 for (const d of [join(s1, "quizzes"), join(s1, "labs", "solution"), s2]) mkdirSync(d, { recursive: true });42 writeFileSync(join(repo, "course.yaml"), stringify({43 course: { id: c.id, title: c.title, short_title: c.shortTitle, tagline: c.tagline, subtitle: c.subtitle, language: "fr-CA", version: c.version, endorsement_notice: c.endorsementNotice },44 author: { name: a.name, role: a.role, institution: a.institution, institution_short: a.institutionShort, department: a.department }, parts: m.parts, sessions,45 }));46 writeFileSync(join(s1, "metadata.yaml"), "id: S01\nstatus: implemented\nlast_reviewed: '2026-11-22'\neffort_minutes: {presentation: [50, 60], lab: [45, 60]}\ndeliverables: {video_recorded: false}\n");47 writeFileSync(join(s1, "quizzes", "questions.yaml"), stringify({ session: "S01", title: "Quiz du dépôt", passing_score: 1, questions: [48 { id: "R1", type: "choix-unique", prompt: "Question venue du dépôt : laquelle est juste ?", options: [{ id: "A", text: "La première" }, { id: "B", text: "La seconde" }], answer: "B", explanation: "La seconde, par construction de l’essai." },49 { id: "R2", type: "vrai-faux", prompt: "Cette question vient du dépôt.", options: [{ id: "A", text: "Vrai" }, { id: "B", text: "Faux" }], answer: "A", explanation: "Oui." },50 ] }));51 writeFileSync(join(s1, "labs", "instructions.md"), `# Laboratoire du dépôt\n\nConsigne importée : cultiver un ${WORDS.importedLab}.\n`);52 writeFileSync(join(s1, "labs", "solution", "corrige.md"), "CORRIGE-QUI-NE-DOIT-JAMAIS-ETRE-LU");53 writeFileSync(join(s2, "metadata.yaml"), "id: S02\nstatus: implem"); // someone is writing this file right now54 execFileSync("tar", ["-czf", join(fixtures, "depot-du-cours.tar.gz"), "-C", repo, "."], { stdio: "ignore" });55}56