Agent Harness
Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
// 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();
})();