Files
dogfather-universe/server/mess-serverziele.mjs
T
DogFatherGitandClaude Opus 5.5 9e9c30ac4a Server-Ziele, Stufe 1: Werbekarte mit Spendenbalken fuer BLUE MOON
Filipes Bauauftrag „BLUE MOON · Server-Ziele" (urspruenglich an RH Studio
adressiert, jetzt in der Reaction). Stufe 1 ohne KI:

Regie, neuer Reiter „Ziele":
- Ziel anlegen mit Bild per Datei, Strg+V oder Hineinziehen; der Browser
  verkleinert auf <=1600 px WebP (gemessen 115 KB aus 1,8 MB), vergroessert nie
- Ausschnitt per Tipp ins Bild + Zoom -- aus einem Shop-Screenshot wird das Produkt
- Live-Vorschau des Formulars mit derselben Karte wie im Stream
- +1/+5/+10 €, eigener Betrag, Zurueck (nur Buchungen von Hand), Gekauft ✓,
  Archivieren, Reihenfolge; Loeschen nur ohne Geld
- Anzeige: Aus / Ein Ziel / Alle im Wechsel (10-30 s), Ecke, Groesse

Spenden: jede BESTAETIGTE Spende zaehlt ins erste offene aktive Ziel --
genau einmal (eindeutiger Index ueber spende_id; Nochmal zeigen, zweite
Bestaetigung und Probe zaehlen nicht). Abschaltbar.

Die Karte (serverziel.js/.css) an drei Orten: Saal-Leinwand, OBS-Tafel,
Regie-Vorschau. Nur transform/opacity bewegt (Wache mit Gegenprobe), keine
Schrift unter 11,5 px, am Handy eine kleine Zeile. Im Saal misst sie, was
schon ueber der Leinwand liegt (Schild, Ton-Knopf, Kameras, Werbeband) und
weicht aus. Kein Shop-Link verlaesst die Regie (TikTok-Regel).

Neuer Datenordner zielbilder/ -- in sicherung-holen.sh, gefunden von
pruef-sicherung-ordner. mess-reaktion liest „Geld sonstwo" jetzt sichtbar
(innerText statt textContent) und hat eine Gegenprobe in jedem Lauf.

Pruefungen: pruef-serverziele 84/0 (3 Sabotagen rot), mess-serverziele
37/0 (Gegenprobe Ausweichen rot), pruef-reaktion 638/0, -schmal 56/0,
-stil 46/0, pruef-spenden 218/0, css-klassen 0, portnummern 41/0,
sicherung-ordner 10/0, mess-zocken 74/0, mess-reaktion ohne ACHTUNG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 01:53:33 +01:00

549 lines
31 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* =====================================================================
DIE SERVER-ZIELE IM BROWSER (27.10.2026)
pruef-serverziele.mjs prueft den Server. Hier wird geprueft, was ein
Mensch SIEHT -- an den drei Orten, an denen die Karte steht:
1. die Regie: Screenshot einfuegen (Strg+V), Ausschnitt setzen,
speichern, Betrag buchen, Anzeige umstellen -- der ganze Weg
mit echten Klicks, nicht ueber die Schnittstelle
2. der Saal am Rechner und am Handy: Steht die Karte in der Ecke,
ist jede Schrift mindestens 11,5 px, laeuft „+5 €" bei einer
Buchung, kommt beim Zuschauer KEIN Fehler in die Konsole?
3. die Buehnenquelle (tafel.html) fuer OBS / TikTok Studio
Dazu Bildschirmfotos zum Ansehen (server/mess-serverziele-*.png).
Aufrufen mit: node server/mess-serverziele.mjs [pfad/zum/screenshot.png]
Ohne Pfad baut sich das Werkzeug einen nachgemachten Shop-Screenshot
im Browser -- es haengt an keiner Datei, die es morgen nicht mehr gibt.
===================================================================== */
import { mkdtempSync, rmSync, readFileSync, existsSync } 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(), "mess-ziele-"));
process.env.WORKSPACE_DB = join(ordner, "workspace.db");
const PORT = await eigenerPort(import.meta);
const HTTPS_PORT = await eigenerPort(import.meta, "mess-serverziele (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;
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, "mess-serverziele");
await new Promise((r) => setTimeout(r, 1000));
const CREW = "crew.dogfather-universe.com";
let fehler = 0, geprueft = 0;
const ok = (b, t) => { geprueft++; console.log((b ? " ok " : " FEHL ") + t); if (!b) fehler++; };
const melde = (t) => console.log(t);
function nichtNachsehbar(grund) {
console.log(`\n -- NICHT NACHSEHBAR\n ${grund}\n`
+ " Das ist KEIN Befund am Code -- es heisst nur, dass gerade niemand nachsehen konnte.\n");
try { rmSync(ordner, { recursive: true, force: true }); } catch { /* egal */ }
process.exit(3);
}
/* ---------- 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-Z90-000001", gast: "CODE-Z91-000001" };
anlegen("DogFather", "admin", CODES.admin);
anlegen("Nachtfalter", "gast", CODES.gast);
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, code: CODES[wer], alter_ok: true } });
return [].concat(a.kopf["set-cookie"] || []).map((z) => z.split(";")[0]).join("; ");
}
const k = { admin: await anmelden("admin"), gast: await anmelden("gast") };
if (!k.admin || !k.gast) nichtNachsehbar("Die Anmeldung klappt nicht.");
/* DER SAAL MUSS OFFEN SEIN, sonst gibt es keine Leinwand -- und jede
Messung darauf misst einen Kasten von 0×0 (so geschehen beim ersten
Lauf: drei Haken gruen, ohne eine Karte gesehen zu haben). Erst
Vorbereitung, dann live, mit einem Video; die Antworten werden
gelesen, nicht angenommen. */
await roh("/workspace/api/reaktion", { method: "PUT", keks: k.admin,
rumpf: { titel: "Zockabend", video: "https://www.youtube.com/watch?v=dQw4w9WgXcQ" } });
for (const st of ["vorbereitung", "live"]) {
const a = await roh("/workspace/api/reaktion/stand", { method: "POST", keks: k.admin, rumpf: { stand: st } });
if (a.code >= 400) nichtNachsehbar(`Der Saal laesst sich nicht auf „${st}“ stellen (HTTP ${a.code} ${a.text.slice(0, 80)}).`);
}
{
const l = await roh("/workspace/api/reaktion", { keks: k.gast });
if (l.j?.stand !== "live") nichtNachsehbar(`Der Saal steht auf „${l.j?.stand}“, nicht auf live.`);
}
/* ---------- Vorbau und Browser ------------------------------------------ */
const sd = join(ordner, "p.key"), zd = join(ordner, "p.crt");
try { zertifikatBauen(sd, zd, CREW); } catch (f) { nichtNachsehbar(`Kein Zertifikat: ${f?.message}`); }
const vorbau = httpsServer({ key: readFileSync(sd), cert: readFileSync(zd) }, (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}`;
let pw = null;
try {
pw = await import("file:///C:/Users/qciga/Documents/Obelix/Analyse/node_modules/playwright/index.mjs");
} catch (f) { nichtNachsehbar(`Playwright ist nicht da: ${f?.message}`); }
const browser = await pw.chromium.launch({
args: [`--host-resolver-rules=MAP ${CREW} 127.0.0.1`, "--ignore-certificate-errors"],
});
async function alsWer(wer, breite, hoehe, extra = {}) {
const kontext = await browser.newContext({
viewport: { width: breite, height: hoehe }, hasTouch: breite <= 860,
ignoreHTTPSErrors: true, ...extra,
});
if (k[wer]) {
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") konsole.push(m.text()); });
seite.on("response", (a) => {
if (a.status() >= 400 && !/ytimg\.com|youtube/.test(a.url())) {
konsole.push(`${a.status()} ${a.url().replace(/^https?:\/\/[^/]+/, "")}`);
}
});
return { kontext, seite, konsole };
}
const bild = async (seite, name, opt = {}) => {
await seite.screenshot({ path: join(HIER, `mess-serverziele-${name}.png`), ...opt });
melde(` Bild: server/mess-serverziele-${name}.png`);
};
/** Alle sichtbaren Schriften in einem Kasten: kleinste Groesse. */
const kleinsteSchrift = (seite, wo) => seite.evaluate((wo) => {
const w = document.querySelector(wo);
if (!w) return { n: 0, min: 0 };
let n = 0, min = Infinity, wer = "";
for (const e of w.querySelectorAll("*")) {
const hatText = [...e.childNodes].some((c) => c.nodeType === 3 && c.textContent.trim());
if (!hatText) continue;
const r = e.getBoundingClientRect(), c = getComputedStyle(e);
if (r.width < 1 || r.height < 1 || c.display === "none" || c.visibility === "hidden") continue;
const px = parseFloat(c.fontSize);
n++;
if (px < min) { min = px; wer = `${e.className} „${e.textContent.trim().slice(0, 20)}“`; }
}
return { n, min: n ? Math.round(min * 100) / 100 : 0, wer };
}, wo);
/* =======================================================================
1. DIE REGIE: SCREENSHOT EINFUEGEN, AUSSCHNITT, SPEICHERN
======================================================================= */
melde("=== 1. Regie ===");
const echtesBild = process.argv[2] && existsSync(process.argv[2]) ? readFileSync(process.argv[2]) : null;
melde(` Bild: ${echtesBild ? `echter Screenshot (${Math.round(echtesBild.length / 1024)} KB)` : "nachgemachter Shop-Screenshot"}`);
const regie = await alsWer("admin", 1440, 900);
{
const { seite, konsole } = regie;
await seite.goto(`${BASIS}/workspace/reaktion.html`, { waitUntil: "networkidle" });
await seite.evaluate(() => document.fonts.ready);
await seite.waitForTimeout(1200);
await seite.click("#reiter-ziele");
const geladen = await seite.waitForFunction(() =>
document.querySelector("#zr-ziele .zr-ziele__leer, #zr-ziele .zr-ziel"), null, { timeout: 10000 })
.then(() => true, () => false);
ok(geladen, "der Reiter „Ziele“ geht auf und laedt die Liste");
/* Strg+V: ein Bild in der Zwischenablage. */
const b64 = echtesBild ? echtesBild.toString("base64") : null;
await seite.evaluate(async (b64) => {
let blob;
if (b64) {
const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
blob = new Blob([bytes], { type: "image/png" });
} else {
/* Ein Shop-Screenshot zum Nachmachen: Kopfleiste, links ein
Produktbild (Werkstatt in Rot und Blau), rechts Preis und Text. */
const c = document.createElement("canvas");
c.width = 2400; c.height = 1250;
const g = c.getContext("2d");
g.fillStyle = "#0b1220"; g.fillRect(0, 0, 2400, 1250);
g.fillStyle = "#101a2e"; g.fillRect(0, 0, 2400, 120);
g.fillStyle = "#5fd0ff"; g.font = "bold 56px sans-serif"; g.fillText("QUASAR", 40, 80);
const v = g.createLinearGradient(40, 300, 1300, 1150);
v.addColorStop(0, "#c0392b"); v.addColorStop(1, "#1f4e79");
g.fillStyle = v; g.fillRect(40, 300, 1260, 720);
g.fillStyle = "#e8e8e8"; g.fillRect(300, 650, 700, 200);
g.fillStyle = "#222"; g.fillRect(380, 700, 160, 120); g.fillRect(760, 700, 160, 120);
g.fillStyle = "#fff"; g.font = "bold 90px sans-serif"; g.fillText("MECHANIC DOWNTOWN", 1400, 450);
g.fillStyle = "#5fd0ff"; g.font = "bold 80px sans-serif"; g.fillText("18.74 EUR", 1400, 900);
blob = await new Promise((r) => c.toBlob(r, "image/png"));
}
const dt = new DataTransfer();
dt.items.add(new File([blob], "screenshot.png", { type: "image/png" }));
document.dispatchEvent(new ClipboardEvent("paste", { clipboardData: dt, bubbles: true }));
}, b64);
const drin = await seite.waitForFunction(() =>
document.getElementById("zr-ablage-bild")?.dataset.leer === "nein", null, { timeout: 8000 })
.then(() => true, () => false);
ok(drin, "Strg+V legt den Screenshot in die Ablage");
/* Ausschnitt: ins Produktbild tippen (links-mitte), vergroessern.
ERST WENN DAS BILD GELADEN IST: Vorher ist der Kasten 0 Punkte hoch,
und der Tipp landet daneben (so geschehen im ersten Lauf -- der
Ausschnitt blieb auf 50 %, und die Pruefung sah es nicht, weil sie
nur fragte, OB ein Ausschnitt da ist). */
await seite.waitForFunction(() => {
const i = document.getElementById("zr-ablage-img");
return i?.complete && i.naturalWidth > 0 && i.getBoundingClientRect().height > 40;
}, null, { timeout: 8000 }).catch(() => {});
/* UEBER DAS ELEMENT, nicht ueber Seitenkoordinaten: Die Ablage liegt
unterhalb des sichtbaren Bereichs, und `mouse.click` tippte dort ins
Leere (zweiter Lauf). `locator.click` scrollt sie vorher ins Bild. */
const r = await seite.locator("#zr-ablage-bild").boundingBox();
await seite.locator("#zr-ablage-bild").click({ position: { x: r.width * 0.27, y: r.height * 0.53 } });
await seite.locator("#zr-zoom").evaluate((e) => { e.value = "1.8"; e.dispatchEvent(new Event("input", { bubbles: true })); });
await seite.fill("#zr-titel", "Mechanic Downtown");
await seite.fill("#zr-text", "Echte Werkstatt – das Layout lässt sich per Befehl umbauen.");
await seite.fill("#zr-ziel", "18,74");
await seite.fill("#zr-quelle", "https://www.quasar-store.com/product/mechanic-downtown");
await seite.waitForTimeout(400);
const vs = await seite.evaluate(() => {
const k = document.querySelector("#zr-vorschau .szk[data-sichtbar='ja']");
return {
titel: k?.querySelector(".szk__titel")?.textContent || "",
bild: !!k?.querySelector(".szk__bild img")?.src,
fx: k?.querySelector(".szk__bild")?.style.getPropertyValue("--fx"),
zoom: k?.querySelector(".szk__bild")?.style.getPropertyValue("--zoom"),
};
});
ok(vs.titel === "Mechanic Downtown" && vs.bild && vs.zoom === "1.8" && vs.fx === "27%",
`die Vorschau zeigt das Formular, bevor gespeichert ist (Titel, Bild, Ausschnitt ${vs.fx} / ${vs.zoom}×)`);
const passt = await seite.evaluate(() => {
const b = document.getElementById("zr-vorschau").getBoundingClientRect();
const k = document.querySelector("#zr-vorschau .szk[data-sichtbar='ja']")?.getBoundingClientRect();
return k ? { links: Math.round(k.left - b.left), rechts: Math.round(b.right - k.right), w: Math.round(k.width) } : null;
});
ok(passt && passt.w > 200 && passt.links >= 0 && passt.rechts >= 0,
`die Vorschau ist ganz zu sehen, nicht abgeschnitten (${JSON.stringify(passt)})`);
const svs = await kleinsteSchrift(seite, "#zr-vorschau");
ok(svs.n >= 4 && svs.min >= 11.5, `Vorschau: ${svs.n} Schriften, kleinste ${svs.min} px (${svs.wer})`);
/* DIE TAFEL STECKT IN DER SCROLLLEISTE DES PULTS -- ein Foto des
Elements setzt dort Bruchstuecke zusammen. Also hinscrollen und den
Bildschirm fotografieren. */
await seite.evaluate(() => document.getElementById("zr-form-titel").scrollIntoView({ block: "start" }));
await seite.waitForTimeout(300);
await bild(seite, "1-regie-formular");
await seite.evaluate(() => document.getElementById("zr-vorschau").scrollIntoView({ block: "start" }));
await seite.waitForTimeout(300);
await bild(seite, "1b-regie-vorschau");
await seite.click("#zr-speichern-aktiv");
const gespeichert = await seite.waitForFunction(() =>
[...document.querySelectorAll("#zr-ziele .zr-ziel__titel")].some((e) => e.textContent === "Mechanic Downtown"),
null, { timeout: 10000 }).then(() => true, () => false);
ok(gespeichert, "„Speichern und aktiv“ -- das Ziel steht in der Liste");
/* DAS BILD KOMMT NACH DEM ZIEL: erst wird angelegt, dann hochgeladen.
Auf den Titel zu warten und dann nach dem Bild zu fragen, war ein
Wettlauf -- zweimal gewonnen, beim dritten Mal verloren. Gewartet
wird auf das, was geprueft wird. */
await seite.waitForFunction(() =>
/zielbild/.test(document.querySelector("#zr-ziele .zr-ziel__daumen img")?.getAttribute("src") || ""),
null, { timeout: 10000 }).catch(() => {});
const daumen = await seite.evaluate(() =>
document.querySelector("#zr-ziele .zr-ziel__daumen img")?.getAttribute("src") || "");
ok(/^\/workspace\/api\/buehne\/zielbild\/[a-f0-9]{32}\.(webp|png)$/.test(daumen),
`das Bild ist hochgeladen und verkleinert (${daumen.split(".").pop()})`);
const groesse = await roh(daumen);
ok(groesse.code === 200 && groesse.text.length < 900_000,
`es ist klein genug fuer eine OBS-Quelle (${Math.round(groesse.text.length / 1024)} KB)`);
ok(await seite.evaluate(() => document.getElementById("zr-titel").value === ""), "das Formular ist danach leer");
/* Betrag mit dem Knopf. */
await seite.locator("#zr-ziele .zr-ziel").first().getByRole("button", { name: "+5 €" }).click();
const fuenf = await seite.waitForFunction(() =>
/^5,00 € \/ 18,74 €/.test(document.querySelector("#zr-ziele .zr-ziel__zahl")?.textContent || ""),
null, { timeout: 6000 }).then(() => true, () => false);
ok(fuenf, "„+5 €“ in der Liste -> 5,00 € / 18,74 €");
/* Anzeige: alle im Wechsel, oben rechts. */
await seite.getByRole("button", { name: "Alle im Wechsel" }).click();
await seite.getByRole("button", { name: "Oben rechts" }).click();
const an = await seite.waitForFunction(() =>
document.querySelector("#zr-anzeige [aria-pressed='true']")?.textContent === "Alle im Wechsel"
&& document.querySelector("#zr-platz [aria-pressed='true']")?.textContent === "Oben rechts",
null, { timeout: 6000 }).then(() => true, () => false);
ok(an, "Anzeige „Alle im Wechsel“, „Oben rechts“ -- gedrueckt steht, was gilt");
const sr = await kleinsteSchrift(seite, "#tafel-ziele");
ok(sr.n > 10 && sr.min >= 11.5, `Regie-Tafel: ${sr.n} Schriften, kleinste ${sr.min} px (${sr.wer})`);
await seite.evaluate(() => document.getElementById("zr-meldung").scrollIntoView({ block: "start" }));
await seite.waitForTimeout(300);
await bild(seite, "2-regie-oben");
await seite.evaluate(() => document.getElementById("zr-ziele").scrollIntoView({ block: "start" }));
await seite.waitForTimeout(300);
await bild(seite, "2b-regie-liste");
ok(konsole.length === 0, `keine Fehler in der Konsole der Regie (${konsole.slice(0, 3).join(" | ") || "keine"})`);
}
/* Ein zweites Ziel fuer den Wechsel -- ueber die Schnittstelle, ohne Bild:
auch der Platzhalter gehoert gemessen. */
const zweit = await roh("/workspace/api/serverziele", { method: "POST", keks: k.admin,
rumpf: { titel: "Mechaniker-Script", text: "Ein- und ausstempeln, echte Reparaturen.",
kategorie: "script", format: "kompakt", ziel: "24,99", aktiv: true } });
ok(zweit.code === 201, "ein zweites, kompaktes Ziel (ohne Bild)");
const A = (await roh("/workspace/api/serverziele", { keks: k.admin })).j.ziele
.find((z) => z.titel === "Mechanic Downtown")?.id;
/* =======================================================================
2. DER SAAL AM RECHNER
======================================================================= */
melde("\n=== 2. Saal am Rechner ===");
const zuschauer = await alsWer("gast", 1440, 900);
{
const { seite, konsole } = zuschauer;
await seite.goto(`${BASIS}/workspace/reaktion.html`, { waitUntil: "networkidle" });
await seite.evaluate(() => document.fonts.ready);
await seite.waitForTimeout(1500);
const lage = await seite.evaluate(() => {
const lw = document.getElementById("leinwand")?.getBoundingClientRect();
const w = document.querySelector("#leinwand .sziel");
const k = w?.querySelector(".szk[data-sichtbar='ja']");
const r = k?.getBoundingClientRect();
return {
lw: lw && { x: lw.x, y: lw.y, w: lw.width, h: lw.height },
k: r && { x: r.x, y: r.y, w: r.width, h: r.height },
an: w?.dataset.an, klein: w?.dataset.klein, platz: w?.dataset.platz,
cb: (() => { const q = (w?.offsetParent || document.body).getBoundingClientRect(); return { x: q.x, y: q.y, w: q.width, h: q.height }; })(),
hindernisse: (() => {
const raus = { n: 0, ueber: [] };
if (!r) return raus;
for (const sel of ["#schild", "#ton-an", "#kameras .kamera", ".werbung__band", ".werbung__ecke"]) {
for (const h of document.querySelectorAll(sel)) {
const q = h.getBoundingClientRect();
if (q.width < 2 || q.height < 2 || getComputedStyle(h).visibility === "hidden") continue;
raus.n++;
const schnitt = Math.min(r.right, q.right) - Math.max(r.left, q.left) > 1
&& Math.min(r.bottom, q.bottom) - Math.max(r.top, q.top) > 1;
if (schnitt) raus.ueber.push(sel);
}
}
return raus;
})(),
deck: k ? getComputedStyle(k).opacity : null, wurzelDeck: w ? getComputedStyle(w).opacity : null,
};
});
ok(lage.an === "ja" && lage.platz === "or" && lage.klein === "nein", `die Karte steht im Saal (oben rechts, volle Karte)`);
/* DIE GROESSE GEHOERT IN DIE BEDINGUNG: Ueber einem Kasten von 0×0
ist „liegt drin" immer wahr. */
const imBild = lage.lw?.w > 200 && lage.k?.w > 100 && lage.k.x >= lage.lw.x && lage.k.y >= lage.lw.y
&& lage.k.x + lage.k.w <= lage.lw.x + lage.lw.w + 0.5 && lage.k.y + lage.k.h <= lage.lw.y + lage.lw.h + 0.5;
ok(imBild, `ganz auf der Leinwand (Karte ${Math.round(lage.k?.w)}×${Math.round(lage.k?.h)} in ${Math.round(lage.lw?.w)}×${Math.round(lage.lw?.h)})`);
ok(lage.k?.w > 100 && (lage.cb.x + lage.cb.w) - (lage.k.x + lage.k.w) < 30,
`und zwar am rechten Rand (${Math.round((lage.cb.x + lage.cb.w) - (lage.k.x + lage.k.w))} px)`);
/* DAS EIGENTLICHE KRITERIUM: Nichts, was schon ueber der Leinwand
liegt, wird verdeckt -- Schild, Ton-Knopf, Kameras. */
ok(lage.k?.w > 100 && lage.hindernisse.n >= 1 && lage.hindernisse.ueber.length === 0,
`sie deckt nichts zu, was schon dort liegt (${lage.hindernisse.n} geprueft`
+ `${lage.hindernisse.ueber.length ? `, ueberdeckt: ${lage.hindernisse.ueber.join(", ")}` : ""})`);
ok(lage.k?.w > 100 && lage.k.w <= lage.lw.w * 0.42, `sie nimmt nicht das Bild ein (${Math.round(lage.k.w / lage.lw.w * 100)} % der Breite)`);
const sch = await kleinsteSchrift(seite, "#leinwand .sziel");
ok(sch.n >= 4 && sch.min >= 11.5, `Saal: ${sch.n} Schriften, kleinste ${sch.min} px (${sch.wer})`);
/* Eine Buchung: „+5 €“ muss erscheinen, der Balken wachsen. */
await seite.evaluate(() => {
window.__plus = [];
new MutationObserver((ms) => ms.forEach((m) => {
if (m.target.dataset?.an === "ja" && m.target.classList.contains("szk__plus")) window.__plus.push(m.target.textContent);
})).observe(document.getElementById("leinwand"), { subtree: true, attributes: true, attributeFilter: ["data-an"] });
});
const anteilVor = await seite.evaluate(() => document.querySelector("#leinwand .szk[data-sichtbar='ja'] .szk__fuell")
?.style.getPropertyValue("--anteil"));
await roh(`/workspace/api/serverziele/${A}/buchen`, { method: "POST", keks: k.admin, rumpf: { betrag: 5 } });
await seite.waitForTimeout(1800);
const nach = await seite.evaluate(() => {
const k = document.querySelector("#leinwand .szk[data-sichtbar='ja']");
return { plus: window.__plus, ziel: k?.dataset.ziel, anteil: k?.querySelector(".szk__fuell")?.style.getPropertyValue("--anteil"),
zahl: k?.querySelector(".szk__zahlen b")?.textContent };
});
ok(nach.plus.includes("+5 €"), `„+5 €“ erscheint beim Zuschauer (${JSON.stringify(nach.plus)})`);
ok(Number(nach.ziel) === A && nach.zahl === "10,00 € / 18,74 €",
`die Karte springt zum gebuchten Ziel und zaehlt hoch (${nach.zahl})`);
ok(Number(nach.anteil) > Number(anteilVor || 0),
`der Balken waechst (--anteil ${anteilVor} -> ${nach.anteil})`);
await bild(seite, "3-saal-rechner");
ok(konsole.length === 0, `keine Fehler in der Konsole des Zuschauers -- auch kein 403 der Regie (${konsole.slice(0, 3).join(" | ") || "keine"})`);
}
/* =======================================================================
3. DER WECHSEL
======================================================================= */
melde("\n=== 3. Wechsel ===");
{
await roh("/workspace/api/serverziele/anzeige", { method: "POST", keks: k.admin, rumpf: { wechsel_s: 10 } });
await zuschauer.seite.waitForTimeout(400);
const erst = await zuschauer.seite.evaluate(() => document.querySelector("#leinwand .szk[data-sichtbar='ja']")?.dataset.ziel);
await zuschauer.seite.waitForTimeout(10_800);
const dann = await zuschauer.seite.evaluate(() => document.querySelector("#leinwand .szk[data-sichtbar='ja']")?.dataset.ziel);
ok(erst && dann && erst !== dann, `nach 10 s steht das andere Ziel (${erst} -> ${dann})`);
const sichtbar = await zuschauer.seite.evaluate(() => document.querySelectorAll("#leinwand .szk[data-sichtbar='ja']").length);
ok(sichtbar === 1, `es steht immer GENAU eine Karte (${sichtbar})`);
await bild(zuschauer.seite, "4-saal-kompakt");
}
/* =======================================================================
4. DER SAAL AM HANDY
======================================================================= */
melde("\n=== 4. Saal am Handy ===");
{
const h = await alsWer("gast", 390, 844);
await h.seite.goto(`${BASIS}/workspace/reaktion.html`, { waitUntil: "networkidle" });
await h.seite.evaluate(() => document.fonts.ready);
await h.seite.waitForTimeout(1500);
const m = await h.seite.evaluate(() => {
const lw = document.getElementById("leinwand")?.getBoundingClientRect();
const w = document.querySelector("#leinwand .sziel");
const r = w?.querySelector(".szk[data-sichtbar='ja']")?.getBoundingClientRect();
const ueber = [];
let n = 0;
for (const sel of ["#schild", "#ton-an", "#kameras .kamera"]) {
for (const h of document.querySelectorAll(sel)) {
const q = h.getBoundingClientRect();
if (!r || q.width < 2 || q.height < 2 || getComputedStyle(h).visibility === "hidden") continue;
n++;
if (Math.min(r.right, q.right) - Math.max(r.left, q.left) > 1
&& Math.min(r.bottom, q.bottom) - Math.max(r.top, q.top) > 1) ueber.push(sel);
}
}
return { klein: w?.dataset.klein, lw: lw && { w: lw.width, h: lw.height }, k: r && { w: r.width, h: r.height },
n, ueber, gedraengt: w?.dataset.gedraengt };
});
ok(m.klein === "ja", `auf ${Math.round(m.lw?.w)} Punkten Breite steht die kleine Zeile`);
ok(m.k?.w > 80 && m.k.w <= m.lw.w * 0.6 && m.k.h <= m.lw.h * 0.35,
`sie deckt nicht das Bild zu (${Math.round(m.k?.w)}×${Math.round(m.k?.h)} auf ${Math.round(m.lw?.w)}×${Math.round(m.lw?.h)})`);
ok(m.k?.w > 80 && m.n >= 1 && m.ueber.length === 0,
`und deckt am Handy nichts zu, was schon dort liegt (${m.n} geprueft`
+ `${m.ueber.length ? `, ueberdeckt: ${m.ueber.join(", ")}; gedraengt=${m.gedraengt}` : ""})`);
const s = await kleinsteSchrift(h.seite, "#leinwand .sziel");
ok(s.n >= 2 && s.min >= 11.5, `Handy: ${s.n} Schriften, kleinste ${s.min} px (${s.wer})`);
await bild(h.seite, "5-saal-handy");
ok(h.konsole.length === 0, `keine Fehler in der Konsole (${h.konsole.slice(0, 3).join(" | ") || "keine"})`);
await h.kontext.close();
}
/* =======================================================================
5. DIE BUEHNENQUELLE (OBS / TIKTOK STUDIO)
======================================================================= */
melde("\n=== 5. Buehnenquelle ===");
{
const adr = await roh("/workspace/api/buehne/adressen", { keks: k.admin });
const s = (adr.j?.tafel || "").split("s=")[1] || "";
const t = await alsWer(null, 1920, 1080);
/* NICHT „networkidle": Die Quelle haelt einen Ereignisstrom offen,
das Netz wird nie still. Gewartet wird auf die Karte selbst. */
await t.seite.goto(`${BASIS}/workspace/tafel.html?s=${s}`, { waitUntil: "load" });
await t.seite.waitForSelector("body > .sziel[data-an='ja']", { timeout: 10000 }).catch(() => {});
await t.seite.evaluate(() => document.fonts.ready);
await t.seite.waitForTimeout(1500);
const m = await t.seite.evaluate(() => {
const w = document.querySelector("body > .sziel");
const r = w?.querySelector(".szk[data-sichtbar='ja']")?.getBoundingClientRect();
return { an: w?.dataset.an, r: r && { x: r.x, y: r.y, w: r.width, h: r.height }, grund: getComputedStyle(document.body).backgroundColor };
});
ok(m.an === "ja" && m.r?.w > 200 && 1920 - (m.r.x + m.r.w) < 40 && m.r.y < 40,
`die Karte steht in der Tafel oben rechts (${Math.round(m.r?.w)}×${Math.round(m.r?.h)})`);
ok(/rgba\(0, 0, 0, 0\)|transparent/.test(m.grund), `der Grund bleibt durchsichtig (${m.grund})`);
await t.seite.evaluate(() => {
window.__plus = [];
new MutationObserver((ms) => ms.forEach((x) => { if (x.target.dataset?.an === "ja" && x.target.classList.contains("szk__plus")) window.__plus.push(x.target.textContent); }))
.observe(document.body, { subtree: true, attributes: true, attributeFilter: ["data-an"] });
});
await roh(`/workspace/api/serverziele/${A}/buchen`, { method: "POST", keks: k.admin, rumpf: { betrag: "2,50" } });
await t.seite.waitForTimeout(1800);
const plus = await t.seite.evaluate(() => window.__plus);
ok(plus.includes("+2,50 €"), `die Buchung kommt in OBS an (${JSON.stringify(plus)})`);
await bild(t.seite, "6-tafel-obs");
ok(t.konsole.length === 0, `keine Fehler in der Quelle (${t.konsole.slice(0, 3).join(" | ") || "keine"})`);
await t.kontext.close();
}
/* =======================================================================
6. FINANZIERT UND WENIGER BEWEGUNG
======================================================================= */
melde("\n=== 6. Finanziert ===");
{
await roh(`/workspace/api/serverziele/${A}/buchen`, { method: "POST", keks: k.admin, rumpf: { betrag: "6,24" } });
await roh("/workspace/api/serverziele/anzeige", { method: "POST", keks: k.admin, rumpf: { anzeige: "einzel", gezeigt_id: A } });
const r = await alsWer("gast", 1440, 900, { reducedMotion: "reduce" });
await r.seite.goto(`${BASIS}/workspace/reaktion.html`, { waitUntil: "networkidle" });
await r.seite.evaluate(() => document.fonts.ready);
await r.seite.waitForTimeout(1500);
const m = await r.seite.evaluate(() => {
const k = document.querySelector("#leinwand .szk[data-sichtbar='ja']");
return { stand: k?.dataset.stand, marke: k && getComputedStyle(k.querySelector(".szk__marke")).display,
glanz: k && getComputedStyle(k.querySelector(".szk__glanz")).display,
schein: k && getComputedStyle(k.querySelector(".szk__schein")).animationName };
});
ok(m.stand === "finanziert" && m.marke !== "none", `18,74 € erreicht: „FINANZIERT ✓“ (${m.stand})`);
ok(m.glanz === "none" && m.schein === "none",
`mit „weniger Bewegung“: kein wandernder Glanz, kein Atmen (${m.glanz} / ${m.schein})`);
await bild(r.seite, "7-finanziert");
await r.kontext.close();
}
await regie.kontext.close();
await zuschauer.kontext.close();
await browser.close();
vorbau.close();
melde(`\n${geprueft} Messungen, ${fehler} Fehler`);
melde(fehler === 0 ? "ALLES IN ORDNUNG" : "NICHT IN ORDNUNG");
try { rmSync(ordner, { recursive: true, force: true }); } catch { /* egal */ }
process.exit(fehler === 0 ? 0 : 1);