Agent Harness
Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
Принят владельцем вручную — без оценки ИИ. Очки за вклад не начислены. Оценка восстановлена по объёму правки.
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | // scroll the whole page slowly so every tile gets a poster |
| +добавлено | await p.evaluate(async () => { |
| +добавлено | const h = document.body.scrollHeight; |
| +добавлено | for (let y = 0; y < h; y += 200) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 250)); } |
| +добавлено | }); |
| +добавлено | await p.waitForTimeout(6000); |
| +добавлено | const r = await p.evaluate(() => { |
| +добавлено | const out = []; |
| +добавлено | for (const fig of document.querySelectorAll(".tile")) { |
| +добавлено | const cv = fig.querySelector("canvas"); |
| +добавлено | if (!cv.width) { out.push([fig.querySelector("b").textContent, "no-canvas"]); continue; } |
| +добавлено | const ctx = cv.getContext("2d"); |
| +добавлено | const d = ctx.getImageData(0, 0, cv.width, cv.height).data; |
| +добавлено | let lit = 0; |
| +добавлено | for (let i = 0; i < d.length; i += 4) if (d[i] + d[i + 1] + d[i + 2] > 150) lit++; |
| +добавлено | const frac = lit / (d.length / 4); |
| +добавлено | if (frac < 0.004) out.push([fig.querySelector("b").textContent, +(frac * 100).toFixed(2)]); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(700); |
| +добавлено | await p.evaluate(() => window.__arena.cast(0)); |
| +добавлено | await p.waitForTimeout(250); |
| +добавлено | await p.screenshot({ path: "<HOME>/Projects/pixelfx/arena/shots/crop-bar.png", clip: { x: 0, y: 620, width: 1280, height: 100 } }); |
| +добавлено | await p.screenshot({ path: "<HOME>/Projects/pixelfx/arena/shots/crop-top.png", clip: { x: 480, y: 0, width: 320, height: 80 } }); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch(); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(800); |
| +добавлено | const log = await p.evaluate(async () => { |
| +добавлено | const out = []; |
| +добавлено | window.__arena.reset(); |
| +добавлено | await new Promise((r) => setTimeout(r, 100)); |
| +добавлено | out.push(["before", window.__arena.dummyHp, window.__arena.live]); |
| +добавлено | window.__arena.cast(0); |
| +добавлено | for (let i = 0; i < 12; i++) { |
| +добавлено | await new Promise((r) => setTimeout(r, 60)); |
| +добавлено | out.push([i, window.__arena.dummyHp, window.__arena.live, window.__arena.locked]); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log(log.map((r) => r.join(" ")).join("\n")); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch(); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(800); |
| +добавлено | const log = await p.evaluate(async () => { |
| +добавлено | const out = []; |
| +добавлено | window.__arena.reset(); |
| +добавлено | await new Promise((r) => setTimeout(r, 100)); |
| +добавлено | window.__arena.cast(0); |
| +добавлено | for (let i = 0; i < 12; i++) { |
| +добавлено | await new Promise((r) => setTimeout(r, 60)); |
| +добавлено | out.push([i, window.__arena.dummyHp, JSON.stringify(window.__arena.acts)]); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log(log.map((r) => r.join(" ")).join("\n")); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch(); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("pageerror", (e) => console.log("PAGEERROR:", e.message, "\n", e.stack?.split("\n").slice(0,4).join("\n"))); |
| +добавлено | p.on("console", (m) => console.log(m.type(), m.text())); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1500); |
| +добавлено | console.log("arena:", await p.evaluate(() => typeof window.__arena)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("response", (r) => { if (r.status() >= 400) console.log(r.status(), r.url()); }); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1500); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(2000); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ args: ["--force-device-scale-factor=1", "--js-flags=--expose-gc"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1200); |
| +добавлено | const r = await p.evaluate(async () => { |
| +добавлено | const a = window.__arena; |
| +добавлено | const samples = []; |
| +добавлено | let prev = performance.now(), t0 = prev; |
| +добавлено | const watch = () => { |
| +добавлено | const now = performance.now(), d = now - prev; prev = now; |
| +добавлено | samples.push([+(now - t0).toFixed(0), +d.toFixed(1), performance.memory ? performance.memory.usedJSHeapSize : 0]); |
| +добавлено | requestAnimationFrame(watch); |
| +добавлено | }; |
| +добавлено | requestAnimationFrame(watch); |
| +добавлено | // frost nova three times in a row |
| +добавлено | for (let k = 0; k < 3; k++) { |
| +добавлено | a.reset(); |
| +добавлено | await new Promise((r) => setTimeout(r, 200)); |
| +добавлено | a.cast(2); |
| +добавлено | await new Promise((r) => setTimeout(r, 4000)); |
| +добавлено | } |
| +добавлено | return samples.filter((s) => s[1] > 20).concat([["heapMax", 0, Math.max(...samples.map((s) => s[2]))]]); |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | await p.goto("http://localhost:4173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(2500); |
| +добавлено | const grab = () => p.evaluate(() => { const c = document.querySelector(".tile canvas"); return c.toDataURL(); }); |
| +добавлено | const still = [await grab(), (await p.waitForTimeout(400), await grab())]; |
| +добавлено | await p.hover(".tile"); |
| +добавлено | const a = await grab(); await p.waitForTimeout(280); const bb = await grab(); |
| +добавлено | console.log("poster identical over 400ms:", still[0] === still[1]); |
| +добавлено | console.log("hovered animates over 280ms:", a !== bb); |
| +добавлено | await p.mouse.move(0, 700); await p.waitForTimeout(300); |
| +добавлено | const c1 = await grab(); await p.waitForTimeout(400); const c2 = await grab(); |
| +добавлено | console.log("after leaving, back to a still poster:", c1 === c2); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | p.on("console", (m) => m.type() === "error" && console.log("CONSOLE-ERR", m.text())); |
| +добавлено | await p.addInitScript(() => { |
| +добавлено | window.__frames = []; let prev = 0, t0 = 0; |
| +добавлено | const tick = (t) => { if (!t0) t0 = t; if (prev) window.__frames.push([+(t - t0).toFixed(0), +(t - prev).toFixed(1)]); prev = t; requestAnimationFrame(tick); }; |
| +добавлено | requestAnimationFrame(tick); |
| +добавлено | }); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(2500); |
| +добавлено | const stats = (label) => p.evaluate((label) => { |
| +добавлено | const f = window.__frames.slice(); const all = f.map((x) => x[1]).sort((a, b) => a - b); |
| +добавлено | const r = { label, n: f.length, p50: all[Math.floor(all.length * 0.5)], p90: all[Math.floor(all.length * 0.9)], p99: all[Math.floor(all.length * 0.99)], max: all[all.length - 1], over20: all.filter((x) => x > 20).length }; |
| +добавлено | window.__frames.length = 0; return r; |
| +добавлено | }, label); |
| +добавлено | console.log(JSON.stringify(await stats("top (moves)"))); |
| +добавлено | // into the heavy full-screen weather section |
| +добавлено | await p.evaluate(() => document.getElementById("weather")?.scrollIntoView()); |
| +добавлено | await p.waitForTimeout(2000); |
| +добавлено | console.log(JSON.stringify(await stats("weather visible"))); |
| +добавлено | // scroll through every section |
| +добавлено | await p.evaluate(async () => { |
| +добавлено | const h = document.body.scrollHeight; |
| +добавлено | for (let y = 0; y < h; y += 300) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 40)); } |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(await stats("whole page scroll"))); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | { |
| +добавлено | "dependencies": { |
| +добавлено | "playwright-core": "^1.64.1" |
| +добавлено | } |
| +добавлено | } |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | await p.addInitScript(() => { |
| +добавлено | window.__frames = []; let prev = 0, t0 = 0; |
| +добавлено | const tick = (t) => { if (!t0) t0 = t; if (prev) window.__frames.push([+(t - t0).toFixed(1), +(t - prev).toFixed(2)]); prev = t; requestAnimationFrame(tick); }; |
| +добавлено | requestAnimationFrame(tick); |
| +добавлено | }); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1500); |
| +добавлено | await p.waitForTimeout(12000); |
| +добавлено | const r = await p.evaluate(() => { |
| +добавлено | const f = window.__frames.slice(); |
| +добавлено | const sp = f.filter((x) => x[1] > 20); |
| +добавлено | const all = f.map((x) => x[1]).sort((a, b) => a - b); |
| +добавлено | return { n: f.length, p50: all[Math.floor(all.length * 0.5)], p99: all[Math.floor(all.length * 0.99)], max: all[all.length - 1], spikes: sp.slice(0, 20) }; |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | await p.addInitScript(() => { |
| +добавлено | window.__frames = []; let prev = 0, t0 = 0; |
| +добавлено | const tick = (t) => { if (!t0) t0 = t; if (prev) window.__frames.push([+(t - t0).toFixed(0), +(t - prev).toFixed(1)]); prev = t; requestAnimationFrame(tick); }; |
| +добавлено | requestAnimationFrame(tick); |
| +добавлено | window.__casts = []; |
| +добавлено | }); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1500); |
| +добавлено | const r = await p.evaluate(async () => { |
| +добавлено | const a = window.__arena; |
| +добавлено | a.reset(); window.__frames.length = 0; |
| +добавлено | const t0 = performance.now(); |
| +добавлено | const casts = []; |
| +добавлено | const names = ["SLASH","FIRE","FROST","BOLT","HEAL"]; |
| +добавлено | let i = 0; |
| +добавлено | while (performance.now() - t0 < 20000) { |
| +добавлено | if (a.phase !== "fight") a.reset(); |
| +добавлено | if (!a.locked) { const k = i++ % 5; if (a.cast(k)) casts.push([(performance.now() - t0).toFixed(0), names[k]]); } |
| +добавлено | await new Promise((res) => requestAnimationFrame(res)); |
| +добавлено | } |
| +добавлено | const f = window.__frames.slice(); |
| +добавлено | return { casts, spikes: f.filter((x) => x[1] > 20) }; |
| +добавлено | }); |
| +добавлено | console.log("casts:", JSON.stringify(r.casts)); |
| +добавлено | console.log("spikes:", JSON.stringify(r.spikes)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | // Sustained frame pacing at 1280 x 720 with no screenshot in the window: a scripted battle that keeps casting |
| +добавлено | // whenever the hero is free, sampled from rAF timestamps. Prints what the counter and the raw timeline say. |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | |
| +добавлено | const RUN_MS = 20000; |
| +добавлено | |
| +добавлено | (async () => { |
| +добавлено | const browser = await chromium.launch({ channel: "chrome", args: ["--force-device-scale-factor=1", "--enable-gpu-rasterization", "--ignore-gpu-blocklist"] }); |
| +добавлено | const page = await browser.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | await page.addInitScript(() => { |
| +добавлено | window.__frames = []; |
| +добавлено | let prev = 0; |
| +добавлено | const tick = (t) => { if (prev) window.__frames.push(t - prev); prev = t; requestAnimationFrame(tick); }; |
| +добавлено | requestAnimationFrame(tick); |
| +добавлено | }); |
| +добавлено | const errs = []; |
| +добавлено | page.on("pageerror", (e) => errs.push(e.message)); |
| +добавлено | page.on("console", (m) => m.type() === "error" && errs.push(m.text())); |
| +добавлено | |
| +добавлено | await page.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await page.waitForTimeout(1500); |
| +добавлено | |
| +добавлено | // the battle driver: cast whatever is free, in a rotation that keeps several effects on screen at once |
| +добавлено | const result = await page.evaluate(async (RUN_MS) => { |
| +добавлено | const a = window.__arena; |
| +добавлено | a.reset(); |
| +добавлено | window.__frames.length = 0; |
| +добавлено | const order = [0, 1, 2, 3, 4]; |
| +добавлено | let i = 0; |
| +добавлено | const t0 = performance.now(); |
| +добавлено | const costs = [], hud = [], worst = []; |
| +добавлено | while (performance.now() - t0 < RUN_MS) { |
| +добавлено | if (a.phase !== "fight") a.reset(); |
| +добавлено | if (!a.locked) a.cast(order[i++ % order.length]); |
| +добавлено | await new Promise((r) => requestAnimationFrame(r)); |
| +добавлено | if ((i & 15) === 0) { costs.push(a.cost); hud.push(a.fps); worst.push(a.worst); } |
| +добавлено | } |
| +добавлено | const f = window.__frames.slice().sort((x, y) => x - y); |
| +добавлено | const at = (q) => f[Math.min(f.length - 1, Math.floor(f.length * q))]; |
| +добавлено | const med = (xs) => xs.slice().sort((x, y) => x - y)[xs.length >> 1]; |
| +добавлено | return { |
| +добавлено | frames: f.length, |
| +добавлено | fps: { p50: +(1000 / at(0.5)).toFixed(2), p95: +(1000 / at(0.95)).toFixed(2), p99: +(1000 / at(0.99)).toFixed(2), min: +(1000 / f[f.length - 1]).toFixed(2) }, |
| +добавлено | ms: { p50: +at(0.5).toFixed(2), p95: +at(0.95).toFixed(2), max: +f[f.length - 1].toFixed(2), over20: f.filter((x) => x > 20).length, over33: f.filter((x) => x > 33).length }, |
| +добавлено | cost: { step: +med(costs.map((c) => c.step)).toFixed(3), draw: +med(costs.map((c) => c.draw)).toFixed(3), present: +med(costs.map((c) => c.present)).toFixed(3) }, |
| +добавлено | hudFps: { min: Math.min(...hud).toFixed(1), med: med(hud).toFixed(1), max: Math.max(...hud).toFixed(1) }, |
| +добавлено | hudWorst: Math.min(...worst), |
| +добавлено | }; |
| +добавлено | }, RUN_MS); |
| +добавлено | |
| +добавлено | console.log(JSON.stringify(result, null, 2)); |
| +добавлено | console.log("errors:", errs.length ? errs.join(" | ") : "(none)"); |
| +добавлено | await browser.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1200); |
| +добавлено | const r = await p.evaluate(async () => { |
| +добавлено | const core = await import("/src/core/index.js"); |
| +добавлено | const { effects } = await import("/src/fx/index.js"); |
| +добавлено | const ids = ["transitions/blinds", "transitions/crt-off", "transitions/slash-wipe", "transitions/star-iris", "impacts/impact-frame", "explosions/plasma-explosion", "explosions/small-explosion"]; |
| +добавлено | const out = []; |
| +добавлено | for (const id of ids) { |
| +добавлено | const mod = effects[id], meta = { fps: 30, bg: "dark", loop: false, duration: 1, tags: [], options: {}, ...mod.meta }; |
| +добавлено | const [w, h] = meta.size, f = core.createFrame(w, h); |
| +добавлено | const row = [id, meta.duration]; |
| +добавлено | for (const q of [0.1, 0.2, 0.3, 0.42, 0.5, 0.62, 0.75, 0.9]) { |
| +добавлено | const inst = core.createFx(mod, { x: meta.origin[0], y: meta.origin[1] }); |
| +добавлено | inst.update(meta.duration * q); |
| +добавлено | core.clearFrame(f); inst.draw(f); |
| +добавлено | let ink = 0, lum = 0; |
| +добавлено | for (let i = 0; i < f.color.length; i++) { const c = f.color[i]; if (c >>> 24) { ink++; lum += (c & 255) + ((c >>> 8) & 255) + ((c >>> 16) & 255); } } |
| +добавлено | row.push(`${q}:${ink}/${lum ? Math.round(lum / Math.max(1, ink)) : 0}`); |
| +добавлено | } |
| +добавлено | out.push(row); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log(r.map((x) => x.join(" ")).join("\n")); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.evaluate(() => document.getElementById("transitions").scrollIntoView()); |
| +добавлено | await p.waitForTimeout(4000); |
| +добавлено | const r = await p.evaluate(() => { |
| +добавлено | const figs = [...document.querySelectorAll(".tile")].filter((f) => /Slash wipe|Blinds|CRT off|Star iris/.test(f.querySelector("b").textContent)); |
| +добавлено | return figs.map((f) => { |
| +добавлено | const cv = f.querySelector("canvas"), ctx = cv.getContext("2d"); |
| +добавлено | const d = ctx.getImageData(0, 0, cv.width, cv.height).data; |
| +добавлено | let lit = 0, maxc = 0; |
| +добавлено | for (let i = 0; i < d.length; i += 4) { const s = d[i] + d[i + 1] + d[i + 2]; if (s > 100) lit++; if (s > maxc) maxc = s; } |
| +добавлено | return [f.querySelector("b").textContent, cv.width, cv.height, lit, maxc]; |
| +добавлено | }); |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.evaluate(() => document.getElementById("transitions").scrollIntoView()); |
| +добавлено | await p.waitForTimeout(3000); |
| +добавлено | const r = await p.evaluate(() => { |
| +добавлено | const out = []; |
| +добавлено | for (const fig of document.querySelectorAll(".tile")) { |
| +добавлено | const name = fig.querySelector("b").textContent; |
| +добавлено | if (!/Slash wipe|Blinds|CRT off|Star iris|Iris|Diamond|Glitch/.test(name)) continue; |
| +добавлено | const cv = fig.querySelector("canvas"); |
| +добавлено | out.push([name, cv.width, cv.height, fig.className]); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r, null, 1)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1500); |
| +добавлено | const r = await p.evaluate(async () => { |
| +добавлено | const { effects } = await import("/src/fx/index.js"); |
| +добавлено | const mod = effects["transitions/slash-wipe"]; |
| +добавлено | const meta = { fps: 30, bg: "dark", loop: false, duration: 1, tags: [], options: {}, ...mod.meta }; |
| +добавлено | return { id: "transitions/slash-wipe", size: meta.size, origin: meta.origin, duration: meta.duration, bg: meta.bg, hasCreate: !!mod.create, hasDraw: !!mod.draw, hasAct: !!mod.act }; |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.evaluate(() => document.getElementById("transitions").scrollIntoView()); |
| +добавлено | await p.waitForTimeout(3000); |
| +добавлено | const r = await p.evaluate(() => { |
| +добавлено | const out = []; |
| +добавлено | for (const fig of document.querySelectorAll(".tile")) { |
| +добавлено | const name = fig.querySelector("b").textContent; |
| +добавлено | if (!/Slash wipe|Blinds|CRT off|Iris|Diamond/.test(name)) continue; |
| +добавлено | const cv = fig.querySelector("canvas"); |
| +добавлено | const d = cv.getContext("2d").getImageData(0, 0, cv.width, cv.height).data; |
| +добавлено | let lit = 0; for (let i = 0; i < d.length; i += 4) if (d[i] + d[i + 1] + d[i + 2] > 100) lit++; |
| +добавлено | out.push([name, cv.width, cv.height, lit]); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r, null, 0)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("pageerror", (e) => console.log("PAGEERR", e.message)); |
| +добавлено | p.on("console", (m) => console.log("CONSOLE", m.type(), m.text())); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.evaluate(() => document.getElementById("transitions").scrollIntoView()); |
| +добавлено | await p.waitForTimeout(3000); |
| +добавлено | const r = await p.evaluate(() => { |
| +добавлено | const { tiles, queue } = window.__lib; |
| +добавлено | const t = tiles.find((x) => x.fx.id === "transitions/slash-wipe"); |
| +добавлено | return { queued: queue.length, player: !!t.player, visible: t.visible, queuedFlag: t.queued, inQueue: queue.includes(t), hover: t.hover, cw: t.cv.width }; |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome", args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | const logs = []; |
| +добавлено | p.on("console", (m) => logs.push(`${m.type()}: ${m.text()}`)); |
| +добавлено | p.on("pageerror", (e) => logs.push(`pageerror: ${e.message}`)); |
| +добавлено | p.on("response", (r) => r.status() >= 400 && logs.push(`http ${r.status()} ${r.url()}`)); |
| +добавлено | p.on("request", (r) => { const u = new URL(r.url()); if (!/^(localhost|127\.0\.0\.1)$/.test(u.hostname)) logs.push(`external ${r.url()}`); }); |
| +добавлено | await p.addInitScript(() => { window.__frames = []; let prev = 0; const t = (x) => { if (prev) window.__frames.push(x - prev); prev = x; requestAnimationFrame(t); }; requestAnimationFrame(t); }); |
| +добавлено | await p.goto("http://localhost:4173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(2500); |
| +добавлено | for (const k of ["Digit1", "Digit3", "Digit4", "Digit2", "Digit5"]) { await p.keyboard.press(k); await p.waitForTimeout(1500); await p.evaluate(() => window.__arena.reset()); await p.waitForTimeout(200); } |
| +добавлено | const r = await p.evaluate(() => { const f = window.__frames.slice().sort((a,b)=>a-b); const at = (q) => f[Math.floor(f.length*q)]; return { frames: f.length, fpsP50: +(1000/at(0.5)).toFixed(1), fpsP95: +(1000/at(0.95)).toFixed(1), max: +f[f.length-1].toFixed(1), canvas: (() => { const c = document.getElementById("game"); return [c.width, c.height, c.style.width, c.style.height]; })() }; }); |
| +добавлено | console.log("production build:", JSON.stringify(r)); |
| +добавлено | await p.goto("http://localhost:4173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(2500); |
| +добавлено | console.log("library tiles:", await p.evaluate(() => document.querySelectorAll(".tile").length)); |
| +добавлено | await p.click(".tile"); |
| +добавлено | await p.waitForTimeout(800); |
| +добавлено | console.log("dialog:", await p.evaluate(() => document.getElementById("detail").open)); |
| +добавлено | console.log("console:", logs.length ? logs.join(" | ") : "(clean)"); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1200); |
| +добавлено | const r = await p.evaluate(async () => { |
| +добавлено | const mod = await import("/src/fx/ice/frost-nova.js"); |
| +добавлено | const core = await import("/src/core/index.js"); |
| +добавлено | const frame = core.createFrame(320, 180); |
| +добавлено | const inst = core.createFx(mod, { x: 112, y: 150, seed: 3 }); |
| +добавлено | const out = []; |
| +добавлено | for (let i = 0; i < 105; i++) { |
| +добавлено | inst.update(1 / 30); |
| +добавлено | const t0 = performance.now(); |
| +добавлено | core.clearFrame(frame); |
| +добавлено | inst.draw(frame, "back"); inst.draw(frame, "front"); |
| +добавлено | out.push(+(performance.now() - t0).toFixed(2)); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log("frost-nova per frame ms:", JSON.stringify(r)); |
| +добавлено | const b2 = await p.evaluate(async () => { |
| +добавлено | const mod = await import("/src/fx/lightning/lightning-strike.js"); |
| +добавлено | const core = await import("/src/core/index.js"); |
| +добавлено | const frame = core.createFrame(320, 180); |
| +добавлено | const inst = core.createFx(mod, { x: 178, y: 150, seed: 5 }); |
| +добавлено | const out = []; |
| +добавлено | for (let i = 0; i < 90; i++) { inst.update(1 / 30); const t0 = performance.now(); core.clearFrame(frame); inst.draw(frame, "back"); inst.draw(frame, "front"); out.push(+(performance.now() - t0).toFixed(2)); } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log("lightning per frame ms:", JSON.stringify(b2)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | const OUT = "<HOME>/Projects/pixelfx/arena/shots"; |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1200); |
| +добавлено | await p.evaluate(async () => { |
| +добавлено | const h = document.body.scrollHeight; |
| +добавлено | for (let y = 0; y < h; y += 150) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 120)); } |
| +добавлено | }); |
| +добавлено | await p.waitForTimeout(500); |
| +добавлено | await p.evaluate(() => document.getElementById("transitions").scrollIntoView()); |
| +добавлено | await p.waitForTimeout(3000); |
| +добавлено | // any tile in view still empty? |
| +добавлено | const empty = await p.evaluate(() => { |
| +добавлено | const out = []; |
| +добавлено | for (const fig of document.querySelectorAll(".tile")) { |
| +добавлено | const r = fig.getBoundingClientRect(); |
| +добавлено | if (r.bottom < 0 || r.top > innerHeight) continue; |
| +добавлено | const cv = fig.querySelector("canvas"); |
| +добавлено | const d = cv.getContext("2d").getImageData(0, 0, cv.width, cv.height).data; |
| +добавлено | let lit = 0; for (let i = 0; i < d.length; i += 4) if (d[i] + d[i + 1] + d[i + 2] > 90) lit++; |
| +добавлено | if (!cv.width || lit < 20) out.push([fig.querySelector("b").textContent, cv.width, lit]); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log("empty in view:", JSON.stringify(empty)); |
| +добавлено | await p.screenshot({ path: OUT + "/library-transitions.png" }); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | // Drives the arena in Chromium at exactly 1280 x 720: measures real frame pacing, takes the screenshots, |
| +добавлено | // and fails loudly on console errors. |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | const path = require("path"); |
| +добавлено | |
| +добавлено | const OUT = "<HOME>/Projects/pixelfx/arena/shots"; |
| +добавлено | |
| +добавлено | (async () => { |
| +добавлено | const browser = await chromium.launch({ args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const page = await browser.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | // an independent frame sampler, installed before the app: rAF timestamps, no dependence on the game's own meter |
| +добавлено | await page.addInitScript(() => { |
| +добавлено | window.__frames = []; |
| +добавлено | let prev = 0; |
| +добавлено | const tick = (t) => { if (prev) window.__frames.push(t - prev); prev = t; requestAnimationFrame(tick); }; |
| +добавлено | requestAnimationFrame(tick); |
| +добавлено | }); |
| +добавлено | const logs = []; |
| +добавлено | page.on("console", (m) => logs.push(`${m.type()}: ${m.text()}`)); |
| +добавлено | page.on("pageerror", (e) => logs.push(`pageerror: ${e.message}`)); |
| +добавлено | page.on("requestfailed", (r) => logs.push(`requestfailed: ${r.url()} ${r.failure()?.errorText}`)); |
| +добавлено | |
| +добавлено | await page.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await page.waitForTimeout(1500); |
| +добавлено | |
| +добавлено | const shot = async (name) => { await page.screenshot({ path: path.join(OUT, name) }); }; |
| +добавлено | const stats = () => page.evaluate(() => { |
| +добавлено | const f = window.__frames.slice(-180).sort((a, b) => a - b); |
| +добавлено | const at = (q) => f[Math.min(f.length - 1, Math.floor(f.length * q))] || 0; |
| +добавлено | return { |
| +добавлено | frames: f.length, p50: +at(0.5).toFixed(2), p95: +at(0.95).toFixed(2), max: +f[f.length - 1]?.toFixed(2), |
| +добавлено | fps50: +(1000 / at(0.5)).toFixed(1), fps95: +(1000 / at(0.95)).toFixed(1), |
| +добавлено | cost: window.__arena.cost, hud: window.__arena.fps, worst: window.__arena.worst, |
| +добавлено | box: (() => { const r = document.getElementById("game").getBoundingClientRect(); return [r.width, r.height]; })(), |
| +добавлено | }; |
| +добавлено | }); |
| +добавлено | const clearFrames = () => page.evaluate(() => (window.__frames.length = 0)); |
| +добавлено | |
| +добавлено | // 1) idle arena, no effects |
| +добавлено | await clearFrames(); |
| +добавлено | await page.waitForTimeout(1600); |
| +добавлено | console.log("idle :", JSON.stringify(await stats())); |
| +добавлено | await shot("arena-idle.png"); |
| +добавлено | |
| +добавлено | // 2) each skill, cast as soon as the hero is free; a screenshot at the peak of each |
| +добавлено | const names = ["slash", "fireball", "frost", "bolt", "heal"]; |
| +добавлено | for (let i = 0; i < names.length; i++) { |
| +добавлено | await page.evaluate(() => window.__arena.reset()); |
| +добавлено | await page.waitForTimeout(120); |
| +добавлено | await clearFrames(); |
| +добавлено | const ok = await page.evaluate((i) => window.__arena.cast(i), i); |
| +добавлено | await page.waitForTimeout(i === 1 ? 300 : i === 2 ? 420 : i === 3 ? 620 : 240); |
| +добавлено | await shot(`skill-${names[i]}.png`); |
| +добавлено | const s = await page.evaluate(() => ({ hp: window.__arena.dummyHp, hero: window.__arena.heroHp, phase: window.__arena.phase, live: window.__arena.live })); |
| +добавлено | console.log(`${names[i].padEnd(9)}: cast=${ok} ${JSON.stringify(s)}`); |
| +добавлено | await page.waitForTimeout(700); |
| +добавлено | console.log(` ${JSON.stringify(await stats())}`); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // 3) the busiest frame: frost nova, then a fireball in the air, then a bolt landing |
| +добавлено | await page.evaluate(() => window.__arena.reset()); |
| +добавлено | await page.waitForTimeout(150); |
| +добавлено | await page.evaluate(() => window.__arena.cast(2)); |
| +добавлено | await page.waitForTimeout(700); |
| +добавлено | await page.evaluate(() => window.__arena.cast(1)); |
| +добавлено | await page.waitForTimeout(200); |
| +добавлено | await clearFrames(); |
| +добавлено | await page.evaluate(() => window.__arena.cast(3)); |
| +добавлено | await page.waitForTimeout(500); |
| +добавлено | console.log("busy :", JSON.stringify(await stats())); |
| +добавлено | await shot("arena-battle.png"); |
| +добавлено | |
| +добавлено | // 4) 6 quiet seconds: the counter has to sit at 60 with nothing on screen |
| +добавлено | await page.waitForTimeout(5000); |
| +добавлено | await clearFrames(); |
| +добавлено | await page.waitForTimeout(1800); |
| +добавлено | console.log("settled:", JSON.stringify(await stats())); |
| +добавлено | await shot("arena-settled.png"); |
| +добавлено | |
| +добавлено | // 5) library page |
| +добавлено | await page.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await page.waitForTimeout(2500); |
| +добавлено | const lib = await page.evaluate(() => ({ |
| +добавлено | tiles: document.querySelectorAll(".tile").length, |
| +добавлено | visible: [...document.querySelectorAll(".tile")].filter((t) => !t.hidden).length, |
| +добавлено | count: document.getElementById("count")?.textContent, |
| +добавлено | })); |
| +добавлено | console.log("library:", JSON.stringify(lib)); |
| +добавлено | await shot("library-grid.png"); |
| +добавлено | // click a tile: playback opens |
| +добавлено | await page.click(".tile"); |
| +добавлено | await page.waitForTimeout(900); |
| +добавлено | const det = await page.evaluate(() => ({ open: document.getElementById("detail")?.open, name: document.getElementById("d-name")?.textContent })); |
| +добавлено | console.log("detail :", JSON.stringify(det)); |
| +добавлено | await shot("library-detail.png"); |
| +добавлено | await page.waitForTimeout(400); |
| +добавлено | // scroll the grid further down to prove it scrolls |
| +добавлено | await page.evaluate(() => document.getElementById("detail").close()); |
| +добавлено | await page.evaluate(() => window.scrollTo(0, 2600)); |
| +добавлено | await page.waitForTimeout(1400); |
| +добавлено | await shot("library-scrolled.png"); |
| +добавлено | |
| +добавлено | console.log("\n--- console ---"); |
| +добавлено | const bad = logs.filter((l) => !/^debug: \[vite\]/.test(l)); |
| +добавлено | console.log(bad.length ? bad.join("\n") : "(clean: no errors, no warnings)"); |
| +добавлено | await browser.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | const OUT = "<HOME>/Projects/pixelfx/arena/shots"; |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | const errs = []; |
| +добавлено | p.on("pageerror", (e) => errs.push(e.message)); |
| +добавлено | p.on("console", (m) => m.type() === "error" && errs.push(m.text())); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(900); |
| +добавлено | |
| +добавлено | // kill the dummy with bolts, waiting out each cooldown |
| +добавлено | for (let i = 0; i < 12; i++) { |
| +добавлено | const st = await p.evaluate(() => ({ phase: window.__arena.phase, locked: window.__arena.locked, ready: window.__arena.ready })); |
| +добавлено | if (st.phase !== "fight") break; |
| +добавлено | if (!st.locked) await p.evaluate(() => window.__arena.cast(3)); |
| +добавлено | await p.waitForTimeout(700); |
| +добавлено | } |
| +добавлено | await p.waitForTimeout(300); |
| +добавлено | const win = await p.evaluate(() => ({ phase: window.__arena.phase, dummy: window.__arena.dummyHp })); |
| +добавлено | console.log("win:", JSON.stringify(win)); |
| +добавлено | await p.screenshot({ path: OUT + "/arena-win.png" }); |
| +добавлено | |
| +добавлено | // lose: stand still and let the dummy work |
| +добавлено | await p.evaluate(() => window.__arena.reset()); |
| +добавлено | await p.waitForTimeout(45000); |
| +добавлено | const lose = await p.evaluate(() => ({ phase: window.__arena.phase, hero: window.__arena.heroHp, fps: window.__arena.fps })); |
| +добавлено | console.log("lose:", JSON.stringify(lose)); |
| +добавлено | await p.screenshot({ path: OUT + "/arena-lose.png" }); |
| +добавлено | console.log("errors:", errs.length ? errs.join(" | ") : "(none)"); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | const OUT = "<HOME>/Projects/pixelfx/arena/shots"; |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome", args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:4173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1500); |
| +добавлено | // victory: slash the dummy down, waiting out each skill until it is free |
| +добавлено | await p.evaluate(() => window.__arena.reset()); |
| +добавлено | for (let i = 0; i < 60; i++) { |
| +добавлено | const st = await p.evaluate(() => ({ phase: window.__arena.phase, ready: window.__arena.ready })); |
| +добавлено | if (st.phase !== "fight") break; |
| +добавлено | if (st.ready[0]) await p.keyboard.press("Digit1"); |
| +добавлено | await p.waitForTimeout(180); |
| +добавлено | } |
| +добавлено | await p.waitForTimeout(600); |
| +добавлено | console.log("win:", JSON.stringify(await p.evaluate(() => ({ phase: window.__arena.phase, dummy: window.__arena.dummyHp })))); |
| +добавлено | await p.screenshot({ path: OUT + "/arena-win.png" }); |
| +добавлено | // defeat: reset and stand still |
| +добавлено | await p.evaluate(() => window.__arena.reset()); |
| +добавлено | await p.waitForTimeout(42000); |
| +добавлено | console.log("lose:", JSON.stringify(await p.evaluate(() => ({ phase: window.__arena.phase, hero: window.__arena.heroHp })))); |
| +добавлено | await p.screenshot({ path: OUT + "/arena-lose.png" }); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | // A 60 Hz screen cannot be had here (this display runs at 144 Hz), so the headroom is shown the hard way: |
| +добавлено | // throttle the CPU 4x and see whether the counter still sits above 60. |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome", args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | const cdp = await p.context().newCDPSession(p); |
| +добавлено | await p.addInitScript(() => { window.__frames = []; let prev = 0; const t = (x) => { if (prev) window.__frames.push(x - prev); prev = x; requestAnimationFrame(t); }; requestAnimationFrame(t); }); |
| +добавлено | await p.goto("http://localhost:4173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1500); |
| +добавлено | for (const rate of [1, 2, 4, 6]) { |
| +добавлено | await cdp.send("Emulation.setCPUThrottlingRate", { rate }); |
| +добавлено | await p.waitForTimeout(600); |
| +добавлено | await p.evaluate(() => (window.__frames.length = 0)); |
| +добавлено | const start = Date.now(); |
| +добавлено | let i = 0; |
| +добавлено | while (Date.now() - start < 5000) { |
| +добавлено | const st = await p.evaluate(() => ({ phase: window.__arena.phase, ready: window.__arena.ready })); |
| +добавлено | if (st.phase !== "fight") await p.evaluate(() => window.__arena.reset()); |
| +добавлено | if (st.ready[i % 5]) { await p.keyboard.press(`Digit${1 + (i % 5)}`); i++; } |
| +добавлено | await p.waitForTimeout(80); |
| +добавлено | } |
| +добавлено | const r = await p.evaluate(() => { |
| +добавлено | const f = window.__frames.slice().sort((a, b) => a - b), at = (q) => f[Math.floor(f.length * q)]; |
| +добавлено | return { fpsP50: +(1000 / at(0.5)).toFixed(1), fpsP95: +(1000 / at(0.95)).toFixed(1), worst: +(1000 / f[f.length - 1]).toFixed(1), over20ms: f.filter((x) => x > 20).length, n: f.length, counter: Math.round(window.__arena.fps), cost: window.__arena.cost }; |
| +добавлено | }); |
| +добавлено | console.log(`cpu x${rate}:`, JSON.stringify(r)); |
| +добавлено | } |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1500); |
| +добавлено | const r = await p.evaluate(async () => { |
| +добавлено | const core = await import("/src/core/index.js"); |
| +добавлено | const { effects } = await import("/src/fx/index.js"); |
| +добавлено | const out = []; |
| +добавлено | for (const [id, mod] of Object.entries(effects)) { |
| +добавлено | const meta = { fps: 30, bg: "dark", loop: false, duration: 1, tags: [], options: {}, ...mod.meta }; |
| +добавлено | const [w, h] = meta.size; |
| +добавлено | const t0 = performance.now(); |
| +добавлено | const f = core.createFrame(w, h); |
| +добавлено | const bd = core.backdrop(meta.bg, w, h, h); |
| +добавлено | const inst = (mod.act ? core.createAct : core.createFx)({ ...mod, meta }, { x: meta.origin[0], y: meta.origin[1] }); |
| +добавлено | inst.update(0.4); |
| +добавлено | inst.draw(f); |
| +добавлено | out.push([id, +(performance.now() - t0).toFixed(1)]); |
| +добавлено | } |
| +добавлено | return out.sort((a, b) => b[1] - a[1]).slice(0, 12); |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1200); |
| +добавлено | // a person's pass down the page, then back up to transitions |
| +добавлено | await p.evaluate(async () => { |
| +добавлено | const h = document.body.scrollHeight; |
| +добавлено | for (let y = 0; y < h; y += 120) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 100)); } |
| +добавлено | }); |
| +добавлено | await p.waitForTimeout(1200); |
| +добавлено | await p.evaluate(() => document.getElementById("transitions").scrollIntoView()); |
| +добавлено | await p.waitForTimeout(2500); |
| +добавлено | const r = await p.evaluate(() => { |
| +добавлено | const out = []; |
| +добавлено | for (const fig of document.querySelectorAll(".tile")) { |
| +добавлено | const rect = fig.getBoundingClientRect(); |
| +добавлено | if (rect.bottom < 0 || rect.top > innerHeight) continue; |
| +добавлено | const cv = fig.querySelector("canvas"); |
| +добавлено | const d = cv.getContext("2d").getImageData(0, 0, cv.width, cv.height).data; |
| +добавлено | let lit = 0; for (let i = 0; i < d.length; i += 4) if (d[i] + d[i + 1] + d[i + 2] > 60) lit++; |
| +добавлено | out.push([fig.querySelector("b").textContent, cv.width, lit]); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r)); |
| +добавлено | await p.screenshot({ path: "<HOME>/Projects/pixelfx/arena/shots/library-transitions.png" }); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | // End-to-end check of the arena and the library at exactly 1280 x 720 in real Chrome: |
| +добавлено | // console must be clean, the canvas must be 1280 x 720, frame pacing is measured from rAF timestamps with no |
| +добавлено | // screenshot in the window, every skill must actually deal its damage, hit stop must really stop the world, and |
| +добавлено | // the screenshots are saved for the report. |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | const path = require("path"); |
| +добавлено | |
| +добавлено | const BASE = "http://localhost:5173/arena/"; |
| +добавлено | const OUT = "<HOME>/Projects/pixelfx/arena/shots"; |
| +добавлено | |
| +добавлено | (async () => { |
| +добавлено | const browser = await chromium.launch({ channel: "chrome", args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const page = await browser.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 }); |
| +добавлено | const logs = []; |
| +добавлено | page.on("console", (m) => logs.push(`${m.type()}: ${m.text()}`)); |
| +добавлено | page.on("pageerror", (e) => logs.push(`pageerror: ${e.message}`)); |
| +добавлено | page.on("requestfailed", (r) => logs.push(`requestfailed: ${r.url()}`)); |
| +добавлено | page.on("response", (r) => { if (r.status() >= 400) logs.push(`http ${r.status()}: ${r.url()}`); }); |
| +добавлено | page.on("request", (r) => { const u = new URL(r.url()); if (u.hostname !== "localhost" && u.hostname !== "127.0.0.1") logs.push(`external: ${r.url()}`); }); |
| +добавлено | await page.addInitScript(() => { |
| +добавлено | window.__frames = []; |
| +добавлено | let prev = 0; |
| +добавлено | const tick = (t) => { if (prev) window.__frames.push(t - prev); prev = t; requestAnimationFrame(tick); }; |
| +добавлено | requestAnimationFrame(tick); |
| +добавлено | }); |
| +добавлено | |
| +добавлено | const pace = () => page.evaluate(() => { |
| +добавлено | const f = window.__frames.slice().sort((a, b) => a - b); |
| +добавлено | const at = (q) => f[Math.min(f.length - 1, Math.floor(f.length * q))]; |
| +добавлено | return { |
| +добавлено | frames: f.length, |
| +добавлено | msP50: +at(0.5).toFixed(2), msP95: +at(0.95).toFixed(2), msMax: +f[f.length - 1].toFixed(2), |
| +добавлено | fpsP50: +(1000 / at(0.5)).toFixed(1), fpsP95: +(1000 / at(0.95)).toFixed(1), |
| +добавлено | framesDropped: f.filter((x) => x > 20).length, |
| +добавлено | }; |
| +добавлено | }); |
| +добавлено | const clear = () => page.evaluate(() => (window.__frames.length = 0)); |
| +добавлено | const shot = (n) => page.screenshot({ path: path.join(OUT, n) }); |
| +добавлено | const st = () => page.evaluate(() => ({ dummy: window.__arena.dummyHp, hero: window.__arena.heroHp, phase: window.__arena.phase, live: window.__arena.live, frozen: window.__arena.frozen, acts: window.__arena.acts })); |
| +добавлено | |
| +добавлено | // ---------- the arena |
| +добавлено | await page.goto(BASE, { waitUntil: "networkidle" }); |
| +добавлено | await page.waitForTimeout(2000); |
| +добавлено | |
| +добавлено | const box = await page.evaluate(() => { |
| +добавлено | const r = document.getElementById("game").getBoundingClientRect(), c = document.getElementById("game"); |
| +добавлено | return { css: `${r.width}x${r.height}`, buffer: `${c.width}x${c.height}`, dpr: devicePixelRatio }; |
| +добавлено | }); |
| +добавлено | console.log("canvas :", JSON.stringify(box)); |
| +добавлено | |
| +добавлено | await clear(); |
| +добавлено | await page.waitForTimeout(3000); |
| +добавлено | console.log("idle :", JSON.stringify(await pace())); |
| +добавлено | |
| +добавлено | // ---- every skill: press the key, photograph the peak, then confirm the damage it dealt |
| +добавлено | const plan = [ |
| +добавлено | { i: 0, key: "Digit1", name: "1 slash", peak: 180, expect: 18 }, |
| +добавлено | { i: 1, key: "Digit2", name: "2 fire", peak: 460, expect: 24 }, |
| +добавлено | { i: 2, key: "Digit3", name: "3 frost", peak: 420, expect: 32 }, |
| +добавлено | { i: 3, key: "Digit4", name: "4 bolt", peak: 700, expect: 30 }, |
| +добавлено | { i: 4, key: "Digit5", name: "5 heal", peak: 300, expect: 0 }, |
| +добавлено | ]; |
| +добавлено | // the hero is one body: a key is refused while an act is still playing, so wait until the slot is free |
| +добавлено | const waitReady = (i) => page.evaluate(async (i) => { |
| +добавлено | for (let k = 0; k < 400; k++) { if (window.__arena.ready[i]) return true; await new Promise((r) => setTimeout(r, 25)); } |
| +добавлено | return false; |
| +добавлено | }, i); |
| +добавлено | for (const p of plan) { |
| +добавлено | await page.evaluate(() => window.__arena.reset()); |
| +добавлено | // for the heal, let the dummy land a couple of blows first so there is something to restore |
| +добавлено | if (p.expect === 0) { await page.waitForTimeout(7200); await page.evaluate(() => window.__arena.cast(0)); } |
| +добавлено | await waitReady(p.i); |
| +добавлено | const before = await st(); |
| +добавлено | await page.keyboard.press(p.key); |
| +добавлено | // the heal is read as the biggest single step up in the hero's health, sampled from the key press onwards |
| +добавлено | // (the dummy keeps swinging while it plays, so the net change afterwards is not the heal) |
| +добавлено | const watch = p.expect === 0 ? page.evaluate(async () => { |
| +добавлено | let prev = window.__arena.heroHp, best = 0; |
| +добавлено | for (let i = 0; i < 140; i++) { |
| +добавлено | await new Promise((r) => requestAnimationFrame(r)); |
| +добавлено | const hp = window.__arena.heroHp; |
| +добавлено | if (hp > prev) best = Math.max(best, hp - prev); |
| +добавлено | prev = hp; |
| +добавлено | } |
| +добавлено | return best; |
| +добавлено | }) : null; |
| +добавлено | await page.waitForTimeout(p.peak); |
| +добавлено | await shot(`skill-${p.name[0]}.png`); |
| +добавлено | await page.waitForTimeout(p.expect === 0 ? 0 : 1600); |
| +добавлено | const after = await st(); |
| +добавлено | const dealt = p.expect === 0 ? await watch : before.dummy - after.dummy; |
| +добавлено | console.log(`${p.name.padEnd(8)}: dummy ${before.dummy}->${after.dummy}, hero ${before.hero}->${after.hero}, ${p.expect === 0 ? `healed +${dealt} (expected +30)` : `dealt ${dealt} (expected ${p.expect})`}`); |
| +добавлено | await page.waitForTimeout(300); |
| +добавлено | } |
| +добавлено | |
| +добавлено | // ---- the hit stop: during a slash's hit the act reports frozen and the world does not advance |
| +добавлено | await page.evaluate(() => window.__arena.reset()); |
| +добавлено | await page.waitForTimeout(150); |
| +добавлено | const stop = await page.evaluate(async () => { |
| +добавлено | window.__arena.cast(0); |
| +добавлено | let seen = 0, t0 = 0, t1 = 0; |
| +добавлено | for (let i = 0; i < 90; i++) { |
| +добавлено | await new Promise((r) => requestAnimationFrame(r)); |
| +добавлено | const a = window.__arena.acts[0]; |
| +добавлено | if (a && a.frozen) { seen++; if (!t0) t0 = a.t; t1 = a.t; } |
| +добавлено | } |
| +добавлено | return { frozenFrames: seen, actClockDuringFreeze: +(t1 - t0).toFixed(4) }; |
| +добавлено | }); |
| +добавлено | console.log("hitstop:", JSON.stringify(stop)); |
| +добавлено | |
| +добавлено | // ---- 8 s of continuous combat, no screenshot inside the window |
| +добавлено | await page.evaluate(() => window.__arena.reset()); |
| +добавлено | await clear(); |
| +добавлено | const hud = []; |
| +добавлено | const start = Date.now(); |
| +добавлено | let i = 0; |
| +добавлено | while (Date.now() - start < 8000) { |
| +добавлено | const s = await page.evaluate(() => ({ phase: window.__arena.phase, ready: window.__arena.ready, hud: window.__arena.fps })); |
| +добавлено | hud.push(s.hud); |
| +добавлено | if (s.phase !== "fight") await page.evaluate(() => window.__arena.reset()); |
| +добавлено | if (s.ready[i % 5]) { await page.keyboard.press(`Digit${1 + (i % 5)}`); i++; } |
| +добавлено | await page.waitForTimeout(90); |
| +добавлено | } |
| +добавлено | console.log("combat :", JSON.stringify(await pace()), `counter min ${Math.min(...hud).toFixed(0)}`); |
| +добавлено | await shot("arena-battle.png"); |
| +добавлено | |
| +добавлено | // ---------- the library |
| +добавлено | await page.goto(BASE + "library.html", { waitUntil: "networkidle" }); |
| +добавлено | await page.waitForTimeout(2500); |
| +добавлено | console.log("library:", JSON.stringify(await page.evaluate(() => ({ tiles: document.querySelectorAll(".tile").length, counter: document.getElementById("count").textContent })))); |
| +добавлено | await shot("library-grid.png"); |
| +добавлено | |
| +добавлено | await clear(); |
| +добавлено | await page.evaluate(async () => { |
| +добавлено | const h = document.body.scrollHeight; |
| +добавлено | for (let y = 0; y < h; y += 240) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 60)); } |
| +добавлено | }); |
| +добавлено | await page.waitForTimeout(300); |
| +добавлено | console.log("scroll :", JSON.stringify(await pace())); |
| +добавлено | // and the settle: after a scroll stops, the posters fill in |
| +добавлено | await page.evaluate(() => document.getElementById("transitions").scrollIntoView()); |
| +добавлено | await page.waitForTimeout(3500); |
| +добавлено | await shot("library-transitions.png"); |
| +добавлено | const empty = await page.evaluate(() => { |
| +добавлено | const out = []; |
| +добавлено | for (const fig of document.querySelectorAll(".tile")) { |
| +добавлено | const r = fig.getBoundingClientRect(); |
| +добавлено | if (r.bottom < 0 || r.top > innerHeight) continue; |
| +добавлено | const cv = fig.querySelector("canvas"); |
| +добавлено | const d = cv.getContext("2d").getImageData(0, 0, cv.width, cv.height).data; |
| +добавлено | let lit = 0; |
| +добавлено | for (let k = 0; k < d.length; k += 4) if (d[k] + d[k + 1] + d[k + 2] > 90) lit++; |
| +добавлено | if (!cv.width || lit < 20) out.push(fig.querySelector("b").textContent); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log("blank tiles in view after settle:", empty.length ? empty.join(", ") : "none"); |
| +добавлено | |
| +добавлено | // the click: live playback in the dialog |
| +добавлено | await page.evaluate(() => window.scrollTo(0, 0)); |
| +добавлено | await page.waitForTimeout(600); |
| +добавлено | await page.hover(".tile"); |
| +добавлено | await page.waitForTimeout(800); |
| +добавлено | await shot("library-hover.png"); |
| +добавлено | await page.click(".tile"); |
| +добавлено | await page.waitForTimeout(1000); |
| +добавлено | console.log("detail :", JSON.stringify(await page.evaluate(() => ({ open: document.getElementById("detail").open, name: document.getElementById("d-name").textContent, id: document.getElementById("d-id").textContent })))); |
| +добавлено | await shot("library-detail.png"); |
| +добавлено | |
| +добавлено | const bad = logs.filter((l) => !l.startsWith("debug: [vite]") && !l.startsWith("info:")); |
| +добавлено | console.log("\n--- console ---"); |
| +добавлено | console.log(bad.length ? bad.join("\n") : "(clean: no errors, no warnings, no external requests)"); |
| +добавлено | await browser.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 2 }); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1500); |
| +добавлено | await p.screenshot({ path: "<HOME>/Projects/pixelfx/arena/shots/wall-crop.png", clip: { x: 200, y: 100, width: 500, height: 320 } }); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ channel: "chrome" }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | await p.goto("http://localhost:5173/arena/library.html", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(1200); |
| +добавлено | const r = await p.evaluate(async () => { |
| +добавлено | const core = await import("/src/core/index.js"); |
| +добавлено | const ids = ["weather/fog", "weather/blizzard", "transitions/burn-away", "weather/storm", "weather/rain", "impacts/impact-frame"]; |
| +добавлено | const out = []; |
| +добавлено | for (const id of ids) { |
| +добавлено | const mod = await import("/src/fx/" + id + ".js"); |
| +добавлено | const meta = { fps: 30, bg: "dark", loop: false, duration: 1, tags: [], options: {}, ...mod.meta }; |
| +добавлено | const [w, h] = meta.size; |
| +добавлено | const ts = []; |
| +добавлено | for (let pass = 0; pass < 3; pass++) { |
| +добавлено | const t0 = performance.now(); |
| +добавлено | const f = core.createFrame(w, h); |
| +добавлено | core.backdrop(meta.bg, w, h, h); |
| +добавлено | const inst = (mod.act ? core.createAct : core.createFx)({ ...mod, meta }, { x: meta.origin[0], y: meta.origin[1] }); |
| +добавлено | inst.update(meta.duration * 0.42); |
| +добавлено | inst.draw(f); |
| +добавлено | ts.push(+(performance.now() - t0).toFixed(1)); |
| +добавлено | } |
| +добавлено | out.push([id, ts]); |
| +добавлено | } |
| +добавлено | return out; |
| +добавлено | }); |
| +добавлено | console.log(JSON.stringify(r, null, 0)); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | const { chromium } = require("playwright-core"); |
| +добавлено | const OUT = "<HOME>/Projects/pixelfx/arena/shots"; |
| +добавлено | (async () => { |
| +добавлено | const b = await chromium.launch({ args: ["--force-device-scale-factor=1"] }); |
| +добавлено | const p = await b.newPage({ viewport: { width: 1280, height: 720 } }); |
| +добавлено | p.on("pageerror", (e) => console.log("ERR", e.message)); |
| +добавлено | await p.goto("http://localhost:5173/arena/", { waitUntil: "networkidle" }); |
| +добавлено | await p.waitForTimeout(900); |
| +добавлено | await p.evaluate(() => window.__arena.reset()); |
| +добавлено | for (let i = 0; i < 40; i++) { |
| +добавлено | const st = await p.evaluate(() => ({ phase: window.__arena.phase, locked: window.__arena.locked, dummy: window.__arena.dummyHp })); |
| +добавлено | if (st.phase !== "fight") { console.log("decided at", i, st.phase, st.dummy); break; } |
| +добавлено | if (!st.locked && st.dummy > 0) await p.evaluate(() => window.__arena.cast(0)); |
| +добавлено | await p.waitForTimeout(350); |
| +добавлено | } |
| +добавлено | await p.waitForTimeout(400); |
| +добавлено | console.log("final:", JSON.stringify(await p.evaluate(() => ({ phase: window.__arena.phase, dummy: window.__arena.dummyHp })))); |
| +добавлено | await p.screenshot({ path: OUT + "/arena-win.png" }); |
| +добавлено | await b.close(); |
| +добавлено | })(); |
| +добавлено | services: |
| +добавлено | db: |
| +добавлено | image: postgres:16 |
| +добавлено | container_name: app-db |
| +добавлено | restart: unless-stopped |
| +добавлено | environment: |
| +добавлено | POSTGRES_USER: app |
| +добавлено | POSTGRES_PASSWORD: ${DB_PASSWORD:?задай в .env} |
| +добавлено | POSTGRES_DB: app |
| +добавлено | ports: |
| +добавлено | - "5432:5432" |
| +добавлено | volumes: |
| +добавлено | - pgdata:/var/lib/postgresql/data |
| +добавлено | healthcheck: |
| +добавлено | test: ["CMD-SHELL", "pg_isready -U app -d app"] |
| +добавлено | interval: 5s |
| +добавлено | timeout: 3s |
| +добавлено | retries: 10 |
| +добавлено | volumes: |
| +добавлено | pgdata: |
| +добавлено | create extension if not exists pgcrypto; |
| +добавлено | create extension if not exists citext; |
| +добавлено | |
| +добавлено | create table if not exists users ( |
| +добавлено | id uuid primary key default gen_random_uuid(), |
| +добавлено | email citext unique not null, |
| +добавлено | name text not null default '', |
| +добавлено | pass_hash text not null, |
| +добавлено | created_at timestamptz not null default now() |
| +добавлено | ); |
| +добавлено | |
| +добавлено | create table if not exists sessions ( |
| +добавлено | token_hash text primary key, |
| +добавлено | user_id uuid not null references users(id) on delete cascade, |
| +добавлено | created_at timestamptz not null default now(), |
| +добавлено | expires_at timestamptz not null |
| +добавлено | ); |
| +добавлено | |
| +добавлено | create index if not exists sessions_user_idx on sessions(user_id); |
| +добавлено | create index if not exists sessions_expiry_idx on sessions(expires_at); |
| +добавлено | { |
| +добавлено | "name": "auth-postgres", |
| +добавлено | "type": "module", |
| +добавлено | "private": true, |
| +добавлено | "dependencies": { "pg": "^8.13.0" }, |
| +добавлено | "scripts": { "start": "node server.mjs" } |
| +добавлено | } |
| +добавлено | // Auth-сервер: Node + pg, ноль фреймворков. Сессии в httpOnly-cookie. |
| +добавлено | // env: DATABASE_URL=postgres://app:...@127.0.0.1:5432/app, PORT=8141 |
| +добавлено | import http from 'node:http'; |
| +добавлено | import crypto from 'node:crypto'; |
| +добавлено | import pg from 'pg'; |
| +добавлено | |
| +добавлено | const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL }); |
| +добавлено | const PORT = Number(process.env.PORT || 8141); |
| +добавлено | const SESSION_DAYS = 30; |
| +добавлено | |
| +добавлено | // scrypt: храним salt:hash в hex, сравниваем timingSafeEqual |
| +добавлено | const hashPass = (pass) => { |
| +добавлено | const salt = crypto.randomBytes(16); |
| +добавлено | const hash = crypto.scryptSync(pass, salt, 64); |
| +добавлено | return `${salt.toString('hex')}:${hash.toString('hex')}`; |
| +добавлено | }; |
| +добавлено | const checkPass = (pass, stored) => { |
| +добавлено | const [saltHex, hashHex] = stored.split(':'); |
| +добавлено | const hash = crypto.scryptSync(pass, Buffer.from(saltHex, 'hex'), 64); |
| +добавлено | return crypto.timingSafeEqual(hash, Buffer.from(hashHex, 'hex')); |
| +добавлено | }; |
| +добавлено | |
| +добавлено | const json = (res, code, obj) => { |
| +добавлено | res.writeHead(code, { 'Content-Type': 'application/json' }); |
| +добавлено | res.end(JSON.stringify(obj)); |
| +добавлено | }; |
| +добавлено | const readBody = (req) => |
| +добавлено | new Promise((resolve, reject) => { |
| +добавлено | let data = ''; |
| +добавлено | req.on('data', (c) => { |
| +добавлено | data += c; |
| +добавлено | if (data.length > 16_384) reject(new Error('body too large')); |
| +добавлено | }); |
| +добавлено | req.on('end', () => { try { resolve(JSON.parse(data || '{}')); } catch { reject(new Error('bad json')); } }); |
| +добавлено | }); |
| +добавлено | |
| +добавлено | const isEmail = (v) => typeof v === 'string' && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v.trim()); |
| +добавлено | |
| +добавлено | function setSessionCookie(res, token, expiresAt) { |
| +добавлено | const maxAge = Math.floor((expiresAt.getTime() - Date.now()) / 1000); |
| +добавлено | res.setHeader('Set-Cookie', |
| +добавлено | `sid=${token}; HttpOnly; SameSite=Lax; Path=/; Max-Age=${maxAge}`); |
| +добавлено | } |
| +добавлено | |
| +добавлено | async function createSession(res, userId) { |
| +добавлено | const token = crypto.randomBytes(32).toString('base64url'); |
| +добавлено | const tokenHash = crypto.createHash('sha256').update(token).digest('hex'); |
| +добавлено | const expires = new Date(Date.now() + SESSION_DAYS * 86400_000); |
| +добавлено | await pool.query('insert into sessions(token_hash, user_id, expires_at) values ($1,$2,$3)', |
| +добавлено | [tokenHash, userId, expires]); |
| +добавлено | setSessionCookie(res, token, expires); |
| +добавлено | } |
| +добавлено | |
| +добавлено | async function userBySession(req) { |
| +добавлено | const cookie = req.headers.cookie || ''; |
| +добавлено | const sid = cookie.split(';').map((s) => s.trim()).find((s) => s.startsWith('sid=')); |
| +добавлено | if (!sid) return null; |
| +добавлено | const tokenHash = crypto.createHash('sha256').update(sid.slice(4)).digest('hex'); |
| +добавлено | const { rows } = await pool.query( |
| +добавлено | `select u.id, u.email, u.name from sessions s join users u on u.id = s.user_id |
| +добавлено | where s.token_hash = $1 and s.expires_at > now()`, [tokenHash]); |
| +добавлено | return rows[0] || null; |
| +добавлено | } |
| +добавлено | |
| +добавлено | // примитивный rate limit: 10 попыток / 5 минут с IP на login+register |
| +добавлено | const attempts = new Map(); |
| +добавлено | function rateLimited(ip) { |
| +добавлено | const now = Date.now(); |
| +добавлено | const rec = (attempts.get(ip) || []).filter((t) => now - t < 300_000); |
| +добавлено | rec.push(now); |
| +добавлено | attempts.set(ip, rec); |
| +добавлено | return rec.length > 10; |
| +добавлено | } |
| +добавлено | |
| +добавлено | const server = http.createServer(async (req, res) => { |
| +добавлено | try { |
| +добавлено | const url = new URL(req.url, 'http://x'); |
| +добавлено | |
| +добавлено | if (req.method === 'POST' && url.pathname === '/api/register') { |
| +добавлено | if (rateLimited(req.socket.remoteAddress)) return json(res, 429, { error: 'Слишком много попыток' }); |
| +добавлено | const { email, name, password } = await readBody(req); |
| +добавлено | if (!isEmail(email)) return json(res, 400, { error: 'Некорректный email' }); |
| +добавлено | if (typeof password !== 'string' || password.length < 8) |
| +добавлено | return json(res, 400, { error: 'Пароль — минимум 8 символов' }); |
| +добавлено | const mail = email.trim().toLowerCase(); |
| +добавлено | try { |
| +добавлено | const { rows } = await pool.query( |
| +добавлено | 'insert into users(email, name, pass_hash) values ($1,$2,$3) returning id', |
| +добавлено | [mail, (name || '').trim().slice(0, 80), hashPass(password)]); |
| +добавлено | await createSession(res, rows[0].id); |
| +добавлено | return json(res, 201, { ok: true }); |
| +добавлено | } catch (e) { |
| +добавлено | if (e.code === '23505') return json(res, 409, { error: 'Такой email уже зарегистрирован' }); |
| +добавлено | throw e; |
| +добавлено | } |
| +добавлено | } |
| +добавлено | |
| +добавлено | if (req.method === 'POST' && url.pathname === '/api/login') { |
| +добавлено | if (rateLimited(req.socket.remoteAddress)) return json(res, 429, { error: 'Слишком много попыток' }); |
| +добавлено | const { email, password } = await readBody(req); |
| +добавлено | const mail = (email || '').trim().toLowerCase(); |
| +добавлено | const { rows } = await pool.query('select id, pass_hash from users where email = $1', [mail]); |
| +добавлено | const fail = () => json(res, 401, { error: 'Неверная пара email/пароль' }); |
| +добавлено | if (!rows[0]) return fail(); |
| +добавлено | if (typeof password !== 'string' || !checkPass(password, rows[0].pass_hash)) return fail(); |
| +добавлено | await createSession(res, rows[0].id); |
| +добавлено | return json(res, 200, { ok: true }); |
| +добавлено | } |
| +добавлено | |
| +добавлено | if (req.method === 'POST' && url.pathname === '/api/logout') { |
| +добавлено | const cookie = req.headers.cookie || ''; |
| +добавлено | const sid = cookie.split(';').map((s) => s.trim()).find((s) => s.startsWith('sid=')); |
| +добавлено | if (sid) { |
| +добавлено | const tokenHash = crypto.createHash('sha256').update(sid.slice(4)).digest('hex'); |
| +добавлено | await pool.query('delete from sessions where token_hash = $1', [tokenHash]); |
| +добавлено | } |
| +добавлено | res.setHeader('Set-Cookie', 'sid=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0'); |
| +добавлено | return json(res, 200, { ok: true }); |
| +добавлено | } |
| +добавлено | |
| +добавлено | if (req.method === 'GET' && url.pathname === '/api/me') { |
| +добавлено | const user = await userBySession(req); |
| +добавлено | if (!user) return json(res, 401, { error: 'unauthorized' }); |
| +добавлено | return json(res, 200, { user }); |
| +добавлено | } |
| +добавлено | |
| +добавлено | json(res, 404, { error: 'not found' }); |
| +добавлено | } catch (e) { |
| +добавлено | console.error(e); |
| +добавлено | json(res, 500, { error: 'internal' }); |
| +добавлено | } |
| +добавлено | }); |
| +добавлено | |
| +добавлено | server.listen(PORT, () => console.log(`auth api on :${PORT}`)); |
| +добавлено | { |
| +добавлено | "url": "http://127.0.0.1:3000/", |
| +добавлено | "seed": 42, |
| +добавлено | "storageContract": { |
| +добавлено | "allowed": [] |
| +добавлено | }, |
| +добавлено | "selectors": {}, |
| +добавлено | "visual": { "maxDiffRatio": 0.01 }, |
| +добавлено | "perf": { |
| +добавлено | "sessionSec": 12, |
| +добавлено | "maxMutationsPerSec": 400, |
| +добавлено | "maxHeapGrowthMb": 30, |
| +добавлено | "maxResizeMs": 400 |
| +добавлено | } |
| +добавлено | } |
| +добавлено | // Lighthouse CI measures the production build. Add every important route to ROUTES. |
| +добавлено | // Budgets may be tightened per project; loosening them needs a human decision. |
| +добавлено | const PORT = Number(process.env.LHCI_PORT ?? 3000) |
| +добавлено | const ROUTES = ['/'] |
| +добавлено | |
| +добавлено | module.exports = { |
| +добавлено | ci: { |
| +добавлено | collect: { |
| +добавлено | startServerCommand: `__BUILD_CMD__PORT=${PORT} __SERVE_CMD__`, |
| +добавлено | startServerReadyPattern: 'ready|started|listening|Local:', |
| +добавлено | startServerReadyTimeout: 240000, |
| +добавлено | url: ROUTES.map((route) => `http://localhost:${PORT}${route}`), |
| +добавлено | numberOfRuns: 3, |
| +добавлено | ...(process.env.CHROME_PATH ? { chromePath: process.env.CHROME_PATH } : {}), |
| +добавлено | settings: { |
| +добавлено | preset: 'desktop', |
| +добавлено | chromeFlags: '--no-sandbox --headless=new', |
| +добавлено | }, |
| +добавлено | }, |
| +добавлено | assert: { |
| +добавлено | assertions: { |
| +добавлено | 'categories:performance': ['error', { minScore: 0.9 }], |
| +добавлено | 'categories:accessibility': ['error', { minScore: 0.95 }], |
| +добавлено | 'categories:best-practices': ['error', { minScore: 0.9 }], |
| +добавлено | 'categories:seo': ['warn', { minScore: 0.9 }], |
| +добавлено | 'largest-contentful-paint': ['error', { maxNumericValue: 2500 }], |
| +добавлено | 'cumulative-layout-shift': ['error', { maxNumericValue: 0.1 }], |
| +добавлено | 'total-blocking-time': ['error', { maxNumericValue: 200 }], |
| +добавлено | interactive: ['warn', { maxNumericValue: 3800 }], |
| +добавлено | 'total-byte-weight': ['warn', { maxNumericValue: 1600000 }], |
| +добавлено | }, |
| +добавлено | }, |
| +добавлено | upload: { |
| +добавлено | target: 'filesystem', |
| +добавлено | outputDir: './.agent-state/artifacts/lhci', |
| +добавлено | }, |
| +добавлено | }, |
| +добавлено | } |
| +добавлено | import { defineConfig } from '@playwright/test' |
| +добавлено | |
| +добавлено | const PORT = Number(process.env.E2E_PORT ?? 3000) |
| +добавлено | const baseURL = process.env.E2E_BASE_URL ?? `http://localhost:${PORT}` |
| +добавлено | |
| +добавлено | export default defineConfig({ |
| +добавлено | testDir: './e2e', |
| +добавлено | outputDir: './.agent-state/artifacts/playwright/results', |
| +добавлено | snapshotPathTemplate: '{testDir}/__screenshots__/{projectName}/{testFilePath}/{arg}{ext}', |
| +добавлено | fullyParallel: true, |
| +добавлено | forbidOnly: Boolean(process.env.CI), |
| +добавлено | retries: process.env.CI ? 1 : 0, |
| +добавлено | reporter: [ |
| +добавлено | ['list'], |
| +добавлено | ['json', { outputFile: './.agent-state/artifacts/playwright/report.json' }], |
| +добавлено | ['html', { outputFolder: './.agent-state/artifacts/playwright/html', open: 'never' }], |
| +добавлено | ], |
| +добавлено | expect: { |
| +добавлено | toHaveScreenshot: { maxDiffPixelRatio: 0.01, animations: 'disabled', caret: 'hide', scale: 'css' }, |
| +добавлено | }, |
| +добавлено | use: { |
| +добавлено | baseURL, |
| +добавлено | trace: 'retain-on-failure', |
| +добавлено | screenshot: 'only-on-failure', |
| +добавлено | locale: 'en-US', |
| +добавлено | timezoneId: 'UTC', |
| +добавлено | }, |
| +добавлено | projects: [ |
| +добавлено | { name: 'desktop', use: { browserName: 'chromium', viewport: { width: 1440, height: 900 } } }, |
| +добавлено | { name: 'mobile', use: { browserName: 'chromium', viewport: { width: 375, height: 812 }, isMobile: true, hasTouch: true, deviceScaleFactor: 2 } }, |
| +добавлено | ], |
| +добавлено | webServer: process.env.E2E_BASE_URL |
| +добавлено | ? undefined |
| +добавлено | : { |
| +добавлено | command: process.env.E2E_SERVER_CMD ?? '__DEV_CMD__', |
| +добавлено | url: baseURL, |
| +добавлено | reuseExistingServer: !process.env.CI, |
| +добавлено | timeout: 180_000, |
| +добавлено | env: { PORT: String(PORT) }, |
| +добавлено | }, |
| +добавлено | }) |
| +добавлено | import react from '@vitejs/plugin-react' |
| +добавлено | import { fileURLToPath } from 'node:url' |
| +добавлено | import { defineConfig } from 'vitest/config' |
| +добавлено | |
| +добавлено | export default defineConfig({ |
| +добавлено | plugins: [react()], |
| +добавлено | resolve: { |
| +добавлено | alias: { '@': fileURLToPath(new URL('./', import.meta.url)) }, |
| +добавлено | }, |
| +добавлено | test: { |
| +добавлено | environment: 'jsdom', |
| +добавлено | setupFiles: ['./vitest.setup.ts'], |
| +добавлено | include: ['**/*.test.{ts,tsx}'], |
| +добавлено | exclude: ['node_modules', 'e2e', '.next', '.agent-worktrees'], |
| +добавлено | css: true, |
| +добавлено | }, |
| +добавлено | }) |