/* ===================================================================== WIE DIE CHAT-WACHE IM SAAL WIRKT (04.11.2026, Neuplan C11) `pruef-reaktion` (Abschnitt 32) prüft die Regeln am Server. Hier wird im echten Browser gemessen, was nur dort zu sehen ist: * Die Regie hat vier Stufen (Offen · Langsam · Team · Zu) und „Wache“, schaltet Regeln in der Tafel; das Protokoll nennt Stufe und Regeln. * Die Tafel liegt in der Chatspalte, nie über dem Video, der Chat darunter bleibt sichtbar. * Der Gast liest „Langsam“ im Feld, bevor er tippt; ein Link kommt mit einem Satz zurück und bleibt im Feld; eine Verwarnung erscheint „vom Team“ ohne Namen, mit Fokus auf „Verstanden“. * „Verwarnen …“ steht im Menü am Namen direkt nach „stumm“. * Am Handy passt der Kopf ohne seitliches Rollen, Tippziele 44 px. DREI AUSGÄNGE: 0 in Ordnung · 1 Befund · 3 konnte nicht nachsehen. Bilder: CW_BILDER= node server/pruef-chatwache-blick.mjs NIE DIE ECHTE DATENBANK – eigener Ordner, eigener Port. ===================================================================== */ import { mkdtempSync, rmSync, readFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join, dirname } from "node:path"; import { fileURLToPath } from "node:url"; import { request } from "node:http"; import { createServer as httpsServer } from "node:https"; import { zertifikatBauen } from "./helfer-openssl.mjs"; import { notbremse } from "./helfer-notbremse.mjs"; import { eigenerPort } from "./helfer-port.mjs"; const HIER = dirname(fileURLToPath(import.meta.url)); const ordner = mkdtempSync(join(tmpdir(), "pruef-chatwache-")); process.env.WORKSPACE_DB = join(ordner, "workspace.db"); const PORT = await eigenerPort(import.meta); const HTTPS_PORT = await eigenerPort(import.meta, "pruef-chatwache-blick (HTTPS)", 1); process.env.PORT = `${PORT}`; process.env.SITE_ACCESS_SECRET = "lokaler-test"; process.env.SITE_PUBLIC_LAUNCH_AT = "2020-01-01T00:00:00+01:00"; const express = (await import("express")).default; /* Der Sitzungskeks ist `secure`. Der Vorbau unten spricht https, der Server dahinter nicht -- ohne diesen Griff setzt er den Keks und der Browser verwirft ihn. */ const ec = express.response.cookie; express.response.cookie = function (n, w, o) { return ec.call(this, n, w, { ...(o || {}), secure: false }); }; await import("./index.js"); notbremse(300_000, "pruef-chatwache-blick"); await new Promise((r) => setTimeout(r, 1000)); const CREW = "crew.dogfather-universe.com"; /* ---------- Leute ------------------------------------------------------- */ const { DatabaseSync } = await import("node:sqlite"); const { scryptSync, randomBytes, createHmac } = await import("node:crypto"); const d = new DatabaseSync(process.env.WORKSPACE_DB); const kenn = randomBytes(32).toString("hex"); d.prepare("INSERT INTO einstellungen (schluessel, wert, geaendert, von)" + " VALUES (?,?,?,NULL) ON CONFLICT(schluessel) DO NOTHING") .run("code_kennung_schluessel", kenn, new Date().toISOString()); const ALT = new Date(Date.now() - 200 * 86400000).toISOString(); function anlegen(name, rolle, code) { const salt = randomBytes(16).toString("hex"); const hash = scryptSync(code, salt, 64, { N: 32768, r: 8, p: 1, maxmem: 96 * 1024 * 1024 }).toString("hex"); d.prepare("INSERT INTO personen (name, rolle, code_hash, code_salt, code_n," + " code_kennung, aktiv, erstellt) VALUES (?,?,?,?,?,?,1,?)") .run(name, rolle, hash, salt, 32768, createHmac("sha256", kenn).update(code).digest("hex"), ALT); } const CODES = { admin: "CODE-M00-000001", hand: "CODE-M01-000001", gast: "CODE-M02-000001", gast2: "CODE-M03-000001", }; /* VANVAN IST DIE RECHTE HAND und wird mitgemessen, nicht nur DogFather: Filipe hat "nur ich und vanvan" gesagt, und ob die zweite Haelfte davon stimmt, sieht man nur, wenn sie dabei ist. */ anlegen("DogFather", "admin", CODES.admin); anlegen("VanVan", "hand", CODES.hand); anlegen("Nachtfalter", "gast", CODES.gast); anlegen("Lenny", "gast", CODES.gast2); d.close(); function roh(pfad, { method = "GET", keks = "", rumpf = null } = {}) { return new Promise((fertig, schief) => { const daten = rumpf === null ? null : Buffer.from(JSON.stringify(rumpf)); const a = request({ host: "127.0.0.1", port: PORT, path: pfad, method, headers: { Host: CREW, Origin: `https://${CREW}`, ...(keks ? { Cookie: keks } : {}), ...(daten ? { "Content-Type": "application/json", "Content-Length": daten.length } : {}), }, }, (antwort) => { const teile = []; antwort.on("data", (s) => teile.push(s)); antwort.on("end", () => { const text = Buffer.concat(teile).toString("utf8"); let j = null; try { j = JSON.parse(text); } catch { /* kein JSON */ } fertig({ code: antwort.statusCode, text, j, kopf: antwort.headers }); }); }); a.on("error", schief); if (daten) a.write(daten); a.end(); }); } async function anmelden(wer) { const a = await roh("/workspace/api/anmelden", { method: "POST", rumpf: { rolle: wer === "gast2" ? "gast" : wer, code: CODES[wer], alter_ok: true }, }); return [].concat(a.kopf["set-cookie"] || []).map((z) => z.split(";")[0]).join("; "); } const k = { admin: await anmelden("admin"), hand: await anmelden("hand"), gast: await anmelden("gast"), gast2: await anmelden("gast2"), }; /* ---------- Zaehlwerk --------------------------------------------------- */ let fehler = 0; let geprueft = 0; const ok = (b, t) => { geprueft++; console.log((b ? " ok " : " FEHL ") + t); if (!b) fehler++; }; function nichtNachsehbar(grund) { console.log("\n -- NICHT NACHSEHBAR"); console.log(` ${grund}`); console.log(" Das ist KEIN Befund am Code -- es heisst nur, dass"); console.log(" gerade niemand nachsehen konnte.\n"); try { rmSync(ordner, { recursive: true, force: true }); } catch { /* egal */ } process.exit(3); } /* ---------- Die Buehne fuellen ------------------------------------------ */ /* ZWEI STUECKE IN DER WARTESCHLANGE, EINES MIT TERMIN UND EINES OHNE. Genau das ist die Aussage der linken Reihe ("was keinen hat, steht unten"), und mit nur einem Eintrag liesse sie sich nicht messen. */ for (const adresse of ["https://youtu.be/9bZkp7q19f0", "https://www.youtube.com/watch?v=kJQP7kiw5Fk"]) { const a = await roh("/workspace/api/reaktion/liste", { method: "POST", keks: k.admin, rumpf: { video: adresse }, }); if (a.code >= 400) nichtNachsehbar(`Die Warteschlange nimmt nichts an (HTTP ${a.code}).`); } const liste0 = (await roh("/workspace/api/reaktion", { keks: k.admin })).j?.liste || []; if (liste0.length !== 2) { nichtNachsehbar(`In der Warteschlange stehen ${liste0.length} Stuecke statt 2.`); } /* Der Termin liegt in der ZUKUNFT und wird relativ gerechnet. Ein festes Datum waere eine Zeitbombe: Es ist richtig, bis der Kalender es einholt -- und dann schlaegt "ueberfaellig" an, ohne dass etwas kaputt ist. */ { const a = await roh(`/workspace/api/reaktion/liste/${liste0[0].id}/wann`, { method: "PUT", keks: k.admin, rumpf: { wann: new Date(Date.now() + 3 * 86400000).toISOString() }, }); if (a.code >= 400) nichtNachsehbar(`Der Termin laesst sich nicht setzen (HTTP ${a.code}).`); } await roh("/workspace/api/reaktion", { method: "PUT", keks: k.admin, rumpf: { titel: "Wir schauen den neuen Trailer", video: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", beginnt_am: new Date(Date.now() + 7 * 60_000).toISOString(), }, }); /* ---------- Der Vorbau -------------------------------------------------- */ const schluesselDatei = join(ordner, "p.key"); const zertDatei = join(ordner, "p.crt"); try { zertifikatBauen(schluesselDatei, zertDatei, CREW); } catch (f) { nichtNachsehbar(`Kein Zertifikat zu bauen: ${f?.message}\n` + " openssl liegt bei Git in mingw64/bin -- im System-PATH\n" + " steht oft nur Git/cmd."); } const vorbau = httpsServer({ key: readFileSync(schluesselDatei), cert: readFileSync(zertDatei), }, (von, nach) => { const weiter = request({ host: "127.0.0.1", port: PORT, path: von.url, method: von.method, headers: { ...von.headers, host: `${CREW}:${HTTPS_PORT}` }, }, (antwort) => { nach.writeHead(antwort.statusCode || 502, antwort.headers); antwort.pipe(nach); }); weiter.on("error", () => { try { nach.writeHead(502); nach.end(); } catch { /* egal */ } }); von.pipe(weiter); }); await new Promise((r) => vorbau.listen(HTTPS_PORT, "127.0.0.1", r)); const BASIS = `https://${CREW}:${HTTPS_PORT}`; const IDS = {}; { const dd = new DatabaseSync(process.env.WORKSPACE_DB); for (const [w, n] of [["admin", "DogFather"], ["hand", "VanVan"], ["gast", "Nachtfalter"], ["gast2", "Lenny"]]) IDS[w] = dd.prepare("SELECT id FROM personen WHERE name = ?").get(n).id; dd.close(); } for (const st of ["vorbereitung", "live"]) await roh("/workspace/api/reaktion/stand", { method: "POST", keks: k.admin, rumpf: { stand: st } }); const standNun = (await roh("/workspace/api/reaktion", { keks: k.admin })).j?.stand; if (standNun !== "live") nichtNachsehbar(`Die Sendung geht nicht live (${standNun}).`); for (const [wer, text] of [["gast", "Guten Abend zusammen!"], ["gast2", "Bin auch da 🙂"], ["hand", "Willkommen im Saal"]]) { await roh("/workspace/api/reaktion/chat", { method: "POST", keks: k[wer], rumpf: { text } }); } let pw = null; try { pw = await import("file:///C:/Users/qciga/Documents/Obelix/Analyse/node_modules/playwright/index.mjs"); } catch (f) { nichtNachsehbar(`Playwright fehlt: ${f?.message}`); } const browser = await pw.chromium.launch({ args: [`--host-resolver-rules=MAP ${CREW} 127.0.0.1`, "--ignore-certificate-errors"] }); /* Bilder nur auf Wunsch: CW_BILDER= */ const BILDER = process.env.CW_BILDER || ""; async function als(wer, breite, hoehe) { const kontext = await browser.newContext({ viewport: { width: breite, height: hoehe }, hasTouch: breite <= 860, ignoreHTTPSErrors: true }); await kontext.addCookies((k[wer] || "").split("; ").filter(Boolean).map((z) => { const [n, ...r] = z.split("="); return { name: n, value: r.join("="), domain: CREW, path: "/" }; })); const seite = await kontext.newPage(); const konsole = []; seite.on("pageerror", (f) => konsole.push(String(f?.message || f))); seite.on("console", (m) => { if (m.type() === "error" && !/compute-pressure|youtube|ytimg|googlevideo|livekit|ERR_|net::|Kamera|getUserMedia|NotAllowed|NotFound/i.test(m.text()) && !/status of 4(03|29)/.test(m.text()) /* erwartete Ablehnungen der Regeln */) konsole.push(m.text()); }); await seite.goto(`${BASIS}/workspace/reaktion.html`, { waitUntil: "domcontentloaded" }); await seite.waitForSelector("body[data-stand]", { timeout: 20000 }); await seite.waitForTimeout(3000); /* Eröffnungsblende vorbei */ return { kontext, seite, konsole }; } /* ---- Regie: Langsam-Knopf und Wache ---- */ const regie = await als("admin", 1440, 900); await regie.seite.evaluate(() => { const p = document.getElementById("pult"); if (p && p.dataset.auf === "ja") document.getElementById("pult-griff")?.click(); }); await regie.seite.waitForTimeout(500); const knoepfe = await regie.seite.evaluate(() => ({ stufen: [...document.querySelectorAll("#chat-stufen .chatstufe")].map((b) => b.dataset.modus).join(","), wache: (() => { const k = document.getElementById("cw-knopf"); const r = k?.getBoundingClientRect(); return !!(k && !k.hidden && r.width > 0); })(), })); ok(knoepfe.stufen === "offen,langsam,team,zu", `die Regie hat vier Stufen (${knoepfe.stufen})`); ok(knoepfe.wache, "und den Knopf „Wache“ im Chatkopf"); await regie.seite.click('#chat-stufen .chatstufe[data-modus="langsam"]'); await regie.seite.waitForFunction(() => document.querySelector('#chat-stufen .chatstufe[data-modus="langsam"]')?.getAttribute("aria-pressed") === "true", null, { timeout: 8000 }).catch(() => {}); ok(await regie.seite.evaluate(() => document.querySelector('#chat-stufen .chatstufe[data-modus="langsam"]')?.getAttribute("aria-pressed") === "true"), "„Langsam“ ist angekommen und gedrückt"); await regie.seite.click("#cw-knopf"); await regie.seite.waitForSelector("#cw-tafel:not([hidden])", { timeout: 5000 }).catch(() => {}); const tafelGross = await regie.seite.evaluate(() => { const r = document.getElementById("cw-tafel").getBoundingClientRect(); const kopf = document.querySelector("#schiene .schiene__kopf").getBoundingClientRect(); return { h: r.height, oben: r.top - kopf.bottom }; }); ok(tafelGross.h >= 250 && Math.abs(tafelGross.oben) <= 2, `die offene Wache hat Platz (${Math.round(tafelGross.h)} px, direkt unter dem Kopf)`); await regie.seite.waitForTimeout(600); await regie.seite.click("#cw-links_nur_team"); await regie.seite.fill("#cw-woerter", "doof\nmist"); await regie.seite.click("#cw-woerter-speichern"); await regie.seite.waitForTimeout(900); const regeln = (await roh("/workspace/api/reaktion/chatregeln", { keks: k.admin })).j; ok(regeln?.links_nur_team === true && JSON.stringify(regeln?.woerter) === JSON.stringify(["doof", "mist"]), `die Regie schaltet Regeln in der Tafel (${JSON.stringify(regeln)})`); const tafel = await regie.seite.evaluate(() => { const t = document.getElementById("cw-tafel").getBoundingClientRect(); const lw = document.getElementById("leinwand")?.getBoundingClientRect(); const sch = document.getElementById("schiene").getBoundingClientRect(); const liste = document.getElementById("chat-liste").getBoundingClientRect(); const schnitt = !!(lw && t.left < lw.right && lw.left < t.right && t.top < lw.bottom && lw.top < t.bottom); const prot = [...document.querySelectorAll("#cw-protokoll li")].map((li) => li.textContent.trim()); return { schnitt, imChat: t.left >= sch.left - 1 && t.right <= sch.right + 1, chat: liste.height, prot }; }); console.log(" Tafel:", JSON.stringify(tafel)); ok(!tafel.schnitt && tafel.imChat, "die Wache liegt in der Chatspalte, nie über dem Video"); ok(tafel.chat >= 100, `der Chat darunter bleibt sichtbar (${Math.round(tafel.chat)} px)`); ok(tafel.prot.some((t) => /Chat-Stufe/.test(t)) && tafel.prot.some((t) => /Regeln des Abends/.test(t)), "im Protokoll stehen Stufe und Regeln mit Namen und Uhrzeit"); if (BILDER) await regie.seite.screenshot({ path: `${BILDER}/chatwache-regie-1440.png` }); /* ---- Gast: Langsam im Feld, Link abgewiesen, Verwarnung ---- */ const gast = await als("gast2", 1280, 800); const platz = await gast.seite.evaluate(() => document.getElementById("chat-feld")?.placeholder); ok(/Langsamer Chat/.test(platz || ""), `der Gast liest „Langsam“ im Feld, bevor er tippt („${platz}“)`); ok(await gast.seite.evaluate(() => document.getElementById("cw-knopf")?.hidden !== false), "der Saal sieht keinen Wache-Knopf"); /* Für die Link-Regel zurück auf „Offen“ – sonst greift zuerst die Langsam-Bremse (richtig so, aber nicht diese Frage). */ await roh("/workspace/api/reaktion/chatmodus", { method: "POST", keks: k.admin, rumpf: { modus: "offen" } }); await gast.seite.waitForFunction(() => !/Langsamer/.test(document.getElementById("chat-feld")?.placeholder || ""), null, { timeout: 8000 }).catch(() => {}); await gast.seite.fill("#chat-feld", "kommt alle auf www.spam.de"); await gast.seite.press("#chat-feld", "Enter"); await gast.seite.waitForTimeout(900); const linkFehler = await gast.seite.evaluate(() => ({ text: document.getElementById("fehler")?.textContent || "", feld: document.getElementById("chat-feld")?.value })); ok(/nur das Team/.test(linkFehler.text) && /spam/.test(linkFehler.feld || ""), `ein Link aus dem Saal kommt mit einem Satz zurück, der Text bleibt im Feld („${linkFehler.text}“)`); await roh("/workspace/api/reaktion/verwarnen", { method: "POST", keks: k.hand, rumpf: { person_id: IDS.gast2, grund: "Bitte keine Werbelinks." } }); await gast.seite.waitForSelector("#cw-verwarnt", { timeout: 8000 }).catch(() => {}); const verw = await gast.seite.evaluate(() => { const v = document.getElementById("cw-verwarnt"); const r = v?.getBoundingClientRect(); return { da: !!(v && r.height > 0), text: v?.textContent || "", rolle: v?.getAttribute("role"), fokus: document.activeElement?.classList.contains("cw-verwarnt__ok") }; }); ok(verw.da && /Bitte keine Werbelinks/.test(verw.text) && /Hinweis vom Team/.test(verw.text) && verw.rolle === "alert", `der Verwarnte liest den Satz – „vom Team“, ohne Namen (${verw.text.slice(0, 60)})`); ok(!/VanVan/.test(verw.text), "wer verwarnt hat, steht nicht dabei"); ok(verw.fokus, "„Verstanden“ hat den Fokus"); if (BILDER) await gast.seite.screenshot({ path: `${BILDER}/chatwache-gast-verwarnt-1280.png` }); await gast.seite.click(".cw-verwarnt__ok"); ok(await gast.seite.evaluate(() => !document.getElementById("cw-verwarnt")), "„Verstanden“ nimmt den Hinweis weg"); /* ---- Verwarnen über das Namensmenü (VanVan) ---- */ const vh = await als("hand", 1440, 900); await vh.seite.evaluate(() => { const p = document.getElementById("pult"); if (p && p.dataset.auf === "ja") document.getElementById("pult-griff")?.click(); }); await vh.seite.waitForTimeout(400); const name = vh.seite.locator('#chat-liste .beitrag[data-name="Nachtfalter"] .beitrag__name').first(); await name.click().catch(() => {}); await vh.seite.waitForSelector(".modmenue", { timeout: 4000 }).catch(() => {}); const menue = await vh.seite.evaluate(() => [...document.querySelectorAll(".modmenue .modmenue__knopf")].map((b) => b.textContent.trim())); ok(menue.includes("Verwarnen …") && menue.indexOf("Verwarnen …") === menue.indexOf("10 Minuten stumm") + 1, `„Verwarnen …“ steht im Menü am Namen, nach „stumm“ (${menue.join(" | ")})`); /* ---- Handy: Regie-Kopf mit vier Stufen und Wache ---- */ const handy = await als("admin", 390, 844); await handy.seite.evaluate(() => { const p = document.getElementById("pult"); if (p && p.dataset.auf === "ja") document.getElementById("pult-griff")?.click(); }); await handy.seite.waitForTimeout(500); await handy.seite.locator("#cw-knopf").scrollIntoViewIfNeeded().catch(() => {}); const hm = await handy.seite.evaluate(() => { const ziele = [...document.querySelectorAll("#chat-stufen .chatstufe, #cw-knopf")].map((b) => b.getBoundingClientRect()); return { quer: document.documentElement.scrollWidth - innerWidth, klein: Math.min(...ziele.map((r) => r.height)), rechts: Math.max(...ziele.map((r) => r.right)), breite: innerWidth }; }); console.log(" Handy:", JSON.stringify(hm)); ok(hm.quer <= 0 && hm.rechts <= hm.breite, `am Handy passen vier Stufen und die Wache, nichts rollt seitlich (${hm.quer} px, rechts ${Math.round(hm.rechts)})`); ok(hm.klein >= 44, `jedes Tippziel ist mindestens 44 px hoch (${Math.round(hm.klein)})`); if (BILDER) await handy.seite.screenshot({ path: `${BILDER}/chatwache-regie-390.png` }); /* DER TONHINWEIS LIEGT NIE AUF DEM YOUTUBE-BILD (älterer Fund, 04.11.2026): Er erscheint nur im Fehlerfall, also wird er hier erzwungen und gemessen. */ const ton = await handy.seite.evaluate(() => { const t = document.getElementById("tonwache"); const spieler = document.querySelector("#leinwand iframe, #leinwand #yt, .leinwand iframe"); if (!t || !spieler) return { kann: false }; t.hidden = false; const a = t.getBoundingClientRect(), b = spieler.getBoundingClientRect(); const schnitt = a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom; t.hidden = true; return { kann: true, schnitt, ton: [Math.round(a.top), Math.round(a.bottom)], bild: [Math.round(b.top), Math.round(b.bottom)] }; }); console.log(" Tonhinweis:", JSON.stringify(ton)); ok(ton.kann && !ton.schnitt, `der Tonhinweis liegt am Handy unter dem Video, nicht darauf (${JSON.stringify(ton)})`); for (const [wer, s] of [["Regie", regie], ["Gast", gast], ["VanVan", vh], ["Handy", handy]]) { ok(!s.konsole.length, `${wer}: keine Fehler in der Konsole (${s.konsole.slice(0, 3).join(" | ")})`); } await roh("/workspace/api/reaktion/chatregeln", { method: "PUT", keks: k.admin, rumpf: { links_nur_team: false, caps_bremse: false, neue_konten: false, woerter: [] } }); await browser.close(); vorbau.close(); console.log(`\n${geprueft} Pruefungen, ${fehler} Fehler`); try { rmSync(ordner, { recursive: true, force: true }); } catch { /* egal */ } process.exit(fehler ? 1 : 0);