peppa/openspec/changes/pep-257-sessions/evidence/scenario.mjs
2026-11-25 12:58:11 +00:00

64 lines
4.8 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.

import { chromium } from "/tmp/tools/node_modules/playwright-core/index.mjs";
const [login] = process.argv.slice(2);
const B = "http://localhost:18300";
const b = await chromium.launch({ executablePath: process.env.CHROME });
const ctx = await b.newContext({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 2 });
const p = await ctx.newPage();
const errors = [];
p.on("pageerror", (e) => errors.push(e.message));
await p.goto(login, { waitUntil: "networkidle" }).catch(() => {});
await p.waitForTimeout(1500);
const O = "/tmp/shots/check";
const state = (label) => p.evaluate((label) => {
const sc = document.querySelector("[data-terminal-scroller]");
const rows = [...document.querySelectorAll(".xterm-rows > div")];
const last = rows.at(-1);
const scR = sc?.getBoundingClientRect();
const lastR = last?.getBoundingClientRect();
return {
label, url: location.pathname + location.search,
pane: document.querySelector("[data-session-pane]")?.getAttribute("data-session-pane"),
current: document.querySelector("[aria-current=true][data-session-row]")?.getAttribute("data-session-row"),
status: document.querySelector("[data-terminal-status]")?.getAttribute("data-terminal-status"),
font: document.querySelector("[data-terminal-font]")?.getAttribute("data-terminal-font"),
iframes: document.querySelectorAll("iframe").length,
letter: rows[0] && getComputedStyle(rows[0].parentElement).letterSpacing,
rows: rows.length,
statusBar: last?.textContent.trim().slice(0, 60),
statusBarVisible: !!(scR && lastR && lastR.bottom <= scR.bottom + 1 && lastR.top >= scR.top - 1),
gridFits: !!(sc && sc.scrollWidth <= sc.clientWidth + 1),
russianLine: rows.some((r) => r.textContent.includes("Это длинная строка ответа агента") && r.textContent.includes("КОНЕЦ")),
englishLine: rows.some((r) => r.textContent.includes("This is a long English line") && r.textContent.includes("END")),
};
}, label);
const log = async (label, shot) => { await p.waitForTimeout(1200); const s = await state(label); console.log(JSON.stringify(s)); if (shot) await p.screenshot({ path: `${O}-${shot}.png` }); return s; };
await p.goto(B + "/sessions", { waitUntil: "networkidle" }); await p.waitForTimeout(3000);
await log("1 вход: первая сессия выбрана сама", "1-first");
await p.click("[data-session-row='1']"); await p.waitForURL(/id=1/);
await log("2 переключение на другую живую сессию", "2-switch");
await p.click("[data-session-row='2']"); await p.waitForURL(/id=2/);
await log("3 обратно на первую", null);
await p.reload({ waitUntil: "networkidle" }); await p.waitForTimeout(2500);
await log("4 повторное открытие (перезагрузка)", "4-reload");
await p.setViewportSize({ width: 1100, height: 800 }); await log("5 окно 1100×800", "5-narrow");
await p.setViewportSize({ width: 1920, height: 1080 }); await log("6 окно 1920×1080", "6-wide");
await p.setViewportSize({ width: 1440, height: 900 });
await p.click("[data-terminal-zoom='+']"); await log("7 кнопка + (ручной размер, прокрутка)", "7-plus");
await p.click("[data-terminal-zoom='-']"); await p.click("[data-terminal-zoom='-']"); await log("8 кнопка −", null);
await p.click("[data-terminal-fit]"); await log("9 снова «По ширине»", null);
await p.click("button[aria-label='Во весь экран']"); await log("10 полный экран", "10-full");
await p.keyboard.press("Escape"); await log("11 выход из полного экрана", null);
await p.goto(B + "/t/PAY-1", { waitUntil: "networkidle" }); await p.waitForTimeout(1500);
const story = await p.evaluate(() => ({ xterm: document.querySelectorAll(".xterm").length, link: document.querySelector("[data-open-session]")?.getAttribute("href") }));
console.log(JSON.stringify({ label: "12 страница стори", ...story }));
await p.screenshot({ path: `${O}-12-story.png` });
await p.click("[data-open-session]"); await p.waitForURL(/sessions\?id=/); await p.waitForTimeout(2500);
await log("13 переход со стори", "13-from-story");
await p.goto(B + "/sessions?id=7", { waitUntil: "networkidle" }); await p.waitForTimeout(1500);
console.log(JSON.stringify({ label: "14 завершённая #7", gone: await p.evaluate(() => document.querySelector("[data-session-gone]")?.textContent) }));
await p.goto(B + "/runners?id=2", { waitUntil: "networkidle" }); await p.waitForTimeout(1500);
console.log(JSON.stringify({ label: "15 работа агентов", xterm: await p.evaluate(() => document.querySelectorAll(".xterm").length), link: await p.evaluate(() => document.querySelector("[data-open-session]")?.getAttribute("href")) }));
console.log("page errors:", errors);
await b.close();