Files
dogfather-universe/server/pruef-dogtag-buehne.mjs
T

345 lines
22 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.
/* =====================================================================
DOGTAGS — Schritte 4–6: Fährte und Auftritte im Saal (28.10.2026)
Ein Zuschauer im laufenden Zockabend, echter Browser, Wegwerf-Datenbank:
Fährte (frei von Schild und Ton-Knopf), Welpe, Jäger (nicht in den
HUD-Ecken), Aufstieg durch Spende (die Spendenkarte wartet), „Fährte
vollendet“ mit beiden Figuren, Fokus, Abstimmung, Abspann, Handy.
Jeder Moment wird fotografiert (server/pruef-dogtag-buehne-*.png).
Aufrufen mit: node server/pruef-dogtag-buehne.mjs
===================================================================== */
import { mkdtempSync, rmSync } 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 { readFileSync } from "node:fs";
import { createServer as httpsServer } from "node:https";
import { zertifikatBauen } from "./helfer-openssl.mjs";
const HIER = dirname(fileURLToPath(import.meta.url));
const ordner = mkdtempSync(join(tmpdir(), "ws-dogtag-buehne-"));
process.env.WORKSPACE_DB = join(ordner, "workspace.db");
import { notbremse } from "./helfer-notbremse.mjs";
const { eigenerPort } = await import("./helfer-port.mjs");
const PORT = await eigenerPort(import.meta, "die DogTag-Buehnen-Pruefung");
const HTTPS_PORT = await eigenerPort(import.meta, "die DogTag-Buehnen-Pruefung (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(420_000, "pruef-dogtag-buehne");
await new Promise((r) => setTimeout(r, 900));
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);
process.on("exit", () => { try { rmSync(ordner, { recursive: true, force: true }); } catch { /* egal */ } });
const { DatabaseSync } = await import("node:sqlite");
const { scryptSync, randomBytes, createHmac } = await import("node:crypto");
const d = new DatabaseSync(process.env.WORKSPACE_DB);
const nun = new Date().toISOString();
const kennSchluessel = randomBytes(32).toString("hex");
d.prepare("INSERT INTO einstellungen (schluessel, wert, geaendert, von) VALUES (?,?,?,NULL)"
+ " ON CONFLICT(schluessel) DO NOTHING").run("code_kennung_schluessel", kennSchluessel, nun);
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", kennSchluessel).update(code).digest("hex"), ALT);
}
const ROLLEN = [["admin", "Filipe"], ["g1", "Luna"], ["g2", "Kai"], ["g3", "Mo"]];
const CODES = {};
for (const [i, [rolle, name]] of ROLLEN.entries()) {
CODES[rolle] = `CODE-B${String(i).padStart(2, "0")}-000001`;
anlegen(name, rolle.startsWith("g") ? "gast" : rolle, CODES[rolle]);
}
const CREW = "crew.dogfather-universe.com";
function anmelden(rolle) {
return new Promise((fertig, schief) => {
const daten = Buffer.from(JSON.stringify({ rolle: rolle.startsWith("g") ? "gast" : rolle, code: CODES[rolle], alter_ok: true }));
const q = request({ host: "127.0.0.1", port: PORT, path: "/workspace/api/anmelden", method: "POST",
headers: { Host: CREW, Origin: `https://${CREW}`, "Content-Type": "application/json", "Content-Length": daten.length } },
(antw) => {
antw.resume();
antw.on("end", () => fertig([].concat(antw.headers["set-cookie"] || []).map((z) => z.split(";")[0]).join("; ")));
});
q.on("error", schief); q.write(daten); q.end();
});
}
const k = {};
for (const [rolle] of ROLLEN) k[rolle] = await anmelden(rolle);
ok(Object.values(k).every(Boolean), `alle ${Object.keys(k).length} Zugänge melden sich an`);
/* HTTPS, WEIL DIE SEITE ES VERLANGT: Sie laedt ihre Skripte mit
`upgrade-insecure-requests` -- ueber blankes http bleiben sie still
aus (gemessen: Status 0 fuer jedes Skript). Derselbe Vorbau wie in
mess-serverziele. */
const sd = join(ordner, "p.key"), zd = join(ordner, "p.crt");
zertifikatBauen(sd, zd, CREW);
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 { chromium } = await import("playwright");
const browser = await chromium.launch({ args: [`--host-resolver-rules=MAP ${CREW} 127.0.0.1`, "--ignore-certificate-errors"] });
const BASIS = `https://${CREW}:${HTTPS_PORT}`;
async function seiteAls(rolle, breite = 1400, hoehe = 900) {
const kontext = await browser.newContext({ viewport: { width: breite, height: hoehe }, hasTouch: breite <= 860 });
await kontext.addCookies(k[rolle].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)));
/* Auch fehlgeschlagene Abrufe zaehlen -- ein 403 im Hintergrund ist
genau die Sorte Fehler, die man im Browser nicht sieht. */
seite.on("response", (a) => { if (a.status() >= 400) konsole.push(`${a.status()} ${a.url().replace(/^https?:\/\/[^/]+/, "")}`); });
await seite.goto(`${BASIS}/workspace/reaktion.html`, { waitUntil: "domcontentloaded" });
return { kontext, seite, konsole };
}
const hoeheVon = (seite, sel) => seite.evaluate((s) => {
const e = document.querySelector(s); return e ? Math.round(e.getBoundingClientRect().height) : -1;
}, sel);
const W = await import("./workspace-dogtag.js");
const R = await import("./dogtag-tabellen.js");
const IDS = Object.fromEntries(d.prepare("SELECT id, name FROM personen").all().map((z) => [z.name, z.id]));
d.prepare("UPDATE reaktion SET stand = 'live', art = 'spiel', titel = 'Zockabend', gestartet_am = ?, host_id = ?, stand_seit = ? WHERE id = 1")
.run(new Date(Date.now() - 900_000).toISOString(), IDS.Filipe, nun);
d.prepare("UPDATE dogtag_einstellung SET sichtbar = 'alle', faehrte_laenge = 6 WHERE id = 1").run();
const tag = (n) => R.tagBerlin(Date.now() - n * 86400000);
const spende = (pid) => {
d.prepare("INSERT INTO spenden (betrag_cent, name, person_id, herkunft, stand, erstellt, bestaetigt_am) VALUES (100,'x',?,'gemeldet','bestaetigt',?,?)")
.run(pid, nun, nun);
return d.prepare("SELECT * FROM spenden WHERE id = last_insert_rowid()").get();
};
/* Kai ist Jäger: 130 Tage geheult, 4 Spenden (vor heute) */
for (let i = 1; i <= 130; i++) d.prepare("INSERT INTO dogtag_heulen (person_id, tag, erstellt) VALUES (?,?,?)").run(IDS.Kai, tag(i), nun);
for (let i = 0; i < 4; i++) spende(IDS.Kai);
/* Mo hat 25 DogTags und noch keine Spende: eine Spende macht ihn zum Jungwolf */
for (let i = 1; i <= 25; i++) d.prepare("INSERT INTO dogtag_heulen (person_id, tag, erstellt) VALUES (?,?,?)").run(IDS.Mo, tag(i), nun);
/* Der Topf ist leer — Topf-Heulen vom Aufbau oben bekommen eine Sendung. */
d.prepare("INSERT INTO dogtag_sendungen (gestartet_am, art, laenge, erstellt) VALUES (?,?,?,?)").run("2026-01-01T20:00:00.000Z", "video", 5, nun);
d.prepare("UPDATE dogtag_heulen SET topf_fuer = (SELECT id FROM dogtag_sendungen WHERE gestartet_am = ?) WHERE sendung_id IS NULL").run("2026-01-01T20:00:00.000Z");
function api(rolle, pfad, rumpf) {
return new Promise((fertig, schief) => {
const daten = rumpf === undefined ? null : Buffer.from(JSON.stringify(rumpf));
const q = request({ host: "127.0.0.1", port: PORT, path: pfad, method: daten ? "POST" : "GET",
headers: { Host: CREW, Origin: `https://${CREW}`, Cookie: k[rolle],
...(daten ? { "Content-Type": "application/json", "Content-Length": daten.length } : {}) } },
(antw) => {
const t = [];
antw.on("data", (x) => t.push(x));
antw.on("end", () => {
let j = null; try { j = JSON.parse(Buffer.concat(t).toString()); } catch { /* egal */ }
fertig({ code: antw.statusCode, j });
});
});
q.on("error", schief); if (daten) q.write(daten); q.end();
});
}
const imSaal = (id) => d.prepare("INSERT OR REPLACE INTO reaktion_dabei (person_id, seit, gesehen) VALUES (?,?,?)")
.run(id, new Date(Date.now() - 300_000).toISOString(), new Date().toISOString());
for (const n of ["Luna", "Kai", "Mo"]) imSaal(IDS[n]);
melde("\n=== Die Fährte im Saal ===");
const zu = await seiteAls("admin");
await zu.seite.waitForFunction(() => !document.getElementById("dtb-faehrte")?.hidden, null, { timeout: 12000 }).catch(() => {});
const lage = (seite) => seite.evaluate(() => {
const r = (e) => { if (!e) return null; const b = e.getBoundingClientRect(); return { x: b.left, y: b.top, r: b.right, b: b.bottom, w: b.width, h: b.height }; };
const f = r(document.getElementById("dtb-faehrte"));
const lw = r(document.getElementById("leinwand"));
const schild = r(document.getElementById("schild"));
const ueber = (a, b) => !!a && !!b && b.w > 2 && !(a.r <= b.x || a.x >= b.r || a.b <= b.y || a.y >= b.b);
return { f, lw, text: document.getElementById("dtb-faehrte")?.textContent || "",
drin: !!f && !!lw && f.x >= lw.x && f.r <= lw.r && f.y >= lw.y && f.b <= lw.b,
ueberSchild: ueber(f, schild), ueberTon: ueber(f, r(document.getElementById("ton-an"))) };
});
let L = await lage(zu.seite);
ok(L.f && L.f.h > 20 && L.text.includes("0 / 6"), `die Fährte steht im Bild („${L.text}“)`);
ok(L.drin && !L.ueberSchild && !L.ueberTon, `ganz in der Leinwand, nicht über „AUF SENDUNG“ oder dem Ton-Knopf (${JSON.stringify(L.f && [Math.round(L.f.x), Math.round(L.f.y)])})`);
melde("\n=== Ein Welpe heult ===");
let a = await api("g1", "/workspace/api/dogtag/heulen", {});
ok(a.code === 200 && a.j?.im_stream, `Luna heult (${a.code})`);
const abdruck = await zu.seite.waitForFunction(() => !!document.querySelector(".dtb-buehne .dtb-abdruck") && !!document.querySelector(".dtb-buehne .dtb-zeile"),
null, { timeout: 5000 }).then(() => true, () => false);
ok(abdruck, "ein Pfotenabdruck fliegt, „Luna heult mit“ steht unten");
await zu.seite.waitForFunction(() => document.getElementById("dtb-faehrte")?.textContent.includes("1 / 6"), null, { timeout: 5000 }).catch(() => {});
ok((await lage(zu.seite)).text.includes("1 / 6"), "die Fährte zählt mit (1 / 6)");
melde("\n=== Ein Jäger heult — nicht in den HUD-Ecken ===");
await zu.seite.waitForFunction(() => !document.querySelector(".dtb-buehne > *"), null, { timeout: 8000 }).catch(() => {});
a = await api("g2", "/workspace/api/dogtag/heulen", {});
ok(a.code === 200, `Kai (Jäger) heult (${a.code})`);
await zu.seite.waitForFunction(() => !!document.querySelector(".dtb-buehne .dtb-figur svg[data-rang='jaeger']"), null, { timeout: 5000 }).catch(() => {});
await zu.seite.waitForTimeout(900);
const jaeger = await zu.seite.evaluate(() => {
const f = document.querySelector(".dtb-buehne .dtb-figur");
const lw = document.getElementById("leinwand").getBoundingClientRect();
if (!f) return null;
const b = f.getBoundingClientRect();
return { mx: (b.left + b.right) / 2 - lw.left, my: (b.top + b.bottom) / 2 - lw.top, w: lw.width, h: lw.height,
name: f.textContent, schild: !!f.querySelector(".dtb-schild") };
});
const hinweis = await zu.seite.evaluate(() => {
const t = document.querySelector(".dtb-buehne .dtb-hinweis");
const lw = document.getElementById("leinwand").getBoundingClientRect();
if (!t) return null;
const b = t.getBoundingClientRect();
return { text: t.textContent, drin: b.left >= lw.left - 1 && b.right <= lw.right + 1 && b.top >= lw.top && b.bottom <= lw.bottom };
});
ok(!!hinweis && hinweis.drin && /Witterung/.test(hinweis.text), `der Meilenstein-Hinweis steht ganz im Bild („${hinweis?.text}“)`);
ok(!!jaeger && jaeger.schild && jaeger.name.includes("Kai"), `Kai erscheint mit Namensschild (${jaeger?.name})`);
ok(!!jaeger && jaeger.mx > jaeger.w * 0.15 && jaeger.mx < jaeger.w * 0.85, `Zocken: außerhalb der Eck-Streifen (Mitte bei ${Math.round((jaeger?.mx / jaeger?.w) * 100)} % der Breite)`);
await zu.seite.screenshot({ path: join(HIER, "pruef-dogtag-buehne-jaeger.png") });
melde("\n=== Aufstieg durch eine Spende — und die Spendenkarte wartet ===");
await zu.seite.waitForFunction(() => !document.querySelector(".dtb-buehne > *"), null, { timeout: 9000 }).catch(() => {});
W.dogtagSpende(spende(IDS.Mo));
const auf = await zu.seite.waitForFunction(() => /ist jetzt Jungwolf/.test(document.querySelector(".dtb-buehne .dtb-gross")?.textContent || ""),
null, { timeout: 8000 }).then(() => true, () => false);
ok(auf, "die Bühne: „MO — ist jetzt Jungwolf“");
const waehrend = await zu.seite.evaluate(() => {
const vor = document.getElementById("spendentafel").children.length;
try {
window.Spendenkarte.zeigen(document.getElementById("spendentafel"), {
id: "probe-1", name: "Probe", gruss: "", dogen_mille: 1000, betrag_cent: 1000,
stufe: { name: "Danke", vorlage: "herz", farbe: "#8ec9ff", dauer_ms: 2200 },
});
} catch (f) { return { fehler: String(f) }; }
return { vor, gross: window.DogTagBuehne.grosserLaeuft() };
});
await zu.seite.waitForTimeout(800);
const kartenWaehrend = await zu.seite.evaluate(() => document.getElementById("spendentafel").children.length);
ok(waehrend.gross === true && kartenWaehrend === 0, `während des Aufstiegs wartet die Spendenkarte (${kartenWaehrend} Karten, groß läuft: ${waehrend.gross})`);
await zu.seite.screenshot({ path: join(HIER, "pruef-dogtag-buehne-aufstieg.png") });
const kamDanach = await zu.seite.waitForFunction(() => document.getElementById("spendentafel").children.length > 0, null, { timeout: 14000 })
.then(() => true, () => false);
ok(kamDanach, "danach kommt die Spendenkarte");
const chatAuf = await zu.seite.evaluate(() => [...document.querySelectorAll("#chat-liste .beitrag--dogtag-system")].map((x) => x.textContent.trim()));
ok(chatAuf.some((t) => t === "Mo ist jetzt Jungwolf.") && chatAuf.some((t) => t === "Mo setzt einen Leuchtabdruck."),
`im Chat: Aufstieg und Leuchtabdruck (${chatAuf.join(" | ")})`);
melde("\n=== Fährte vollendet ===");
await zu.seite.waitForFunction(() => !document.querySelector(".dtb-buehne > *") && !document.getElementById("spendentafel").children.length,
null, { timeout: 15000 }).catch(() => {});
a = await api("admin", "/workspace/api/dogtag/faehrte", { laenge: 3 });
ok(a.code === 200 && a.j?.faehrte?.vollendet, `Länge 3: vollendet (${a.j?.faehrte?.abdruecke} von 3)`);
const voll = await zu.seite.waitForFunction(() => document.querySelectorAll(".dtb-buehne .dtb-figurbild[data-da='ja']").length === 2
&& /Fährte vollendet/i.test(document.querySelector(".dtb-buehne .dtb-gross")?.textContent || ""), null, { timeout: 8000 })
.then(() => true, () => false);
ok(voll, "„Fährte vollendet“ mit DogFather und Hasi Dog");
await zu.seite.waitForTimeout(700);
const figs = await zu.seite.evaluate(() => [...document.querySelectorAll(".dtb-buehne .dtb-figurbild")].map((i) => i.complete && i.naturalWidth > 100));
ok(figs.length === 2 && figs.every(Boolean), `beide Figuren sind geladen (${figs.join(",")})`);
await zu.seite.waitForTimeout(1200);
const textLage = await zu.seite.evaluate(() => {
const r = (e) => e && e.getBoundingClientRect();
const t = r(document.querySelector(".dtb-buehne .dtb-gross"));
const ton = r(document.getElementById("ton-an"));
const leiste = r(document.querySelector(".senderleiste, #senderleiste"));
const ueber = (a, b) => !!a && !!b && b.width > 2 && !(a.right <= b.left || a.left >= b.right || a.bottom <= b.top || a.top >= b.bottom);
return { ton: ueber(t, ton), leiste: ueber(t, leiste), h: Math.round(t?.height || 0) };
});
ok(textLage.h > 20 && !textLage.ton && !textLage.leiste, `„Fährte vollendet“ liegt nicht auf dem Ton-Knopf oder der Senderleiste (${JSON.stringify(textLage)})`);
await zu.seite.screenshot({ path: join(HIER, "pruef-dogtag-buehne-voll.png") });
const chatVoll = await zu.seite.evaluate(() => [...document.querySelectorAll("#chat-liste .beitrag--dogtag-system")].map((x) => x.textContent.trim()));
ok(!chatVoll.some((t) => /Noch 0/.test(t)), `kein „Noch 0 Abdrücke“ vor „vollendet“ (${chatVoll.filter((t) => /Beute/.test(t)).join(" | ") || "kein Endspurt"})`);
ok(chatVoll.includes("Hasi Dog eingeholt! Das Rudel wählt das nächste Spiel."), "im Chat: „Hasi Dog eingeholt! Das Rudel wählt das nächste Spiel.“");
melde("\n=== Fokus ===");
await zu.seite.waitForFunction(() => !document.querySelector(".dtb-buehne > *"), null, { timeout: 25000 }).catch(() => {});
a = await api("admin", "/workspace/api/dogtag/fokus", { an: true });
ok(a.code === 200 && a.j?.fokus === true, "Fokus an");
await zu.seite.waitForTimeout(600);
a = await api("g3", "/workspace/api/dogtag/heulen", {});
await zu.seite.waitForTimeout(2500);
const imFokus = await zu.seite.evaluate(() => ({ n: document.querySelectorAll(".dtb-buehne > *").length, q: window.DogTagBuehne.warteschlange() }));
ok(imFokus.n === 0 && imFokus.q.klein >= 1 && imFokus.q.fokus, `im Fokus läuft nichts, ${imFokus.q.klein} wartet`);
await api("admin", "/workspace/api/dogtag/fokus", { an: false });
const nachFokus = await zu.seite.waitForFunction(() => document.querySelectorAll(".dtb-buehne > *").length > 0, null, { timeout: 5000 })
.then(() => true, () => false);
ok(nachFokus, "nach dem Fokus läuft das Wartende nach");
melde("\n=== Abstimmung im Chat ===");
a = await api("admin", "/workspace/api/dogtag/abstimmung", { optionen: ["GTA RP", "Fortnite", "Minecraft"] });
const wahl = await zu.seite.waitForFunction(() => document.querySelectorAll("#dts-wahl .dts-wahl__option").length === 3
&& !document.getElementById("dts-wahl").hidden, null, { timeout: 5000 }).then(() => true, () => false);
ok(wahl, "die Abstimmung steht über dem Chatfeld");
await zu.seite.click("#dts-wahl .dts-wahl__option:nth-of-type(3)");
await zu.seite.waitForTimeout(800);
const gew = await zu.seite.evaluate(() => document.querySelector("#dts-wahl .dts-wahl__option[aria-pressed='true'] .dts-wahl__zahl")?.textContent);
ok(gew === "1", `meine Stimme ist da (${gew})`);
await zu.seite.locator("#schiene").screenshot({ path: join(HIER, "pruef-dogtag-buehne-wahl.png") });
melde("\n=== Rudel-Abspann ===");
await zu.seite.waitForFunction(() => !document.querySelector(".dtb-buehne > *"), null, { timeout: 15000 }).catch(() => {});
a = await api("admin", "/workspace/api/dogtag/abspann", {});
ok(a.code === 200 && a.j?.namen >= 3, `Abspann mit ${a.j?.namen} Namen`);
const absp = await zu.seite.waitForFunction(() => document.querySelectorAll(".dtb-buehne .dtb-abspann__zeile").length >= 3, null, { timeout: 5000 })
.then(() => true, () => false);
ok(absp, "die Namen laufen durchs Bild");
await zu.seite.waitForTimeout(2500);
await zu.seite.screenshot({ path: join(HIER, "pruef-dogtag-buehne-abspann.png") });
ok(zu.konsole.length === 0, `keine Fehler in der Konsole (${zu.konsole.join(" | ") || "keine"})`);
await zu.kontext.close();
melde("\n=== Am Handy (mit Ziel-Karte oben rechts) ===");
{
const z = await api("admin", "/workspace/api/serverziele", { titel: "Mechanic Downtown", ziel: "18,74", kategorie: "mlo" });
await api("admin", `/workspace/api/serverziele/${z.j?.id}`, { stand: "aktiv" });
const an = await api("admin", "/workspace/api/serverziele/anzeige", { anzeige: "einzel", gezeigt_id: z.j?.id, platz: "or" });
ok(z.code === 201 && an.code === 200, `Voraussetzung: eine Ziel-Karte steht oben rechts (${z.code}/${an.code})`);
}
for (const [lagename, b, h] of [["hoch", 390, 844], ["schmal", 360, 780], ["quer", 844, 390]]) {
const hy = await seiteAls("g1", b, h);
await hy.seite.waitForFunction(() => !document.getElementById("dtb-faehrte")?.hidden && document.getElementById("dtb-faehrte").getBoundingClientRect().height > 10,
null, { timeout: 12000 }).catch(() => {});
await hy.seite.waitForTimeout(1800);
const m = await lage(hy.seite);
const zk = await hy.seite.evaluate(() => {
const k = document.querySelector('.sziel[data-an="ja"] .szk[data-sichtbar="ja"]')?.getBoundingClientRect();
const f = document.getElementById("dtb-faehrte")?.getBoundingClientRect();
if (!k || !f) return { da: !!k, ueber: null };
return { da: true, ueber: !(f.right <= k.left || f.left >= k.right || f.bottom <= k.top || f.top >= k.bottom) };
});
ok(zk.da && zk.ueber === false, `Handy ${lagename}: Fährte und Ziel-Karte überdecken sich nicht (Karte da: ${zk.da})`);
const imChat = await hy.seite.evaluate(() => !!document.querySelector("#schiene #dtb-faehrte-platz #dtb-faehrte"));
if (lagename === "quer") {
ok(!imChat && !!m.f && m.drin && !m.ueberSchild && !m.ueberTon,
`Handy quer: Fährte im Bild, frei von Schild und Ton-Knopf (${m.f ? `${Math.round(m.f.x)},${Math.round(m.f.y)}` : "fehlt"})`);
} else {
const sicht = await hy.seite.evaluate(() => {
const f = document.getElementById("dtb-faehrte").getBoundingClientRect();
return { h: Math.round(f.height), w: Math.round(f.width), breit: document.documentElement.scrollWidth <= innerWidth };
});
ok(imChat && sicht.h > 20 && sicht.breit, `Handy ${lagename}: Fährte steht über dem Chat, wie im Entwurf (${sicht.w}×${sicht.h})`);
}
if (lagename === "hoch") await hy.seite.screenshot({ path: join(HIER, "pruef-dogtag-buehne-handy.png") });
await hy.kontext.close();
}
await browser.close();
vorbau.close();
melde(`\n${geprueft} Prüfungen, ${fehler} Fehler`);
console.log(fehler ? "NICHT IN ORDNUNG" : "ALLES IN ORDNUNG");
process.exit(fehler ? 1 : 0);