import { expect, type Page } from "@playwright/test"; import { readFileSync } from "node:fs"; import { HUB_HOME } from "../playwright.config.ts"; export const tokens = () => JSON.parse(readFileSync(`${HUB_HOME}/tokens.json`, "utf8")) as { agent: string; client: string }; const BASE = "http://127.0.0.1:8791"; export async function login(page: Page, path = "/app/board") { await page.goto(path); await page.getByLabel("Клиентский токен хаба").fill(tokens().client); await page.getByRole("button", { name: "Войти" }).click(); await expect(page.getByRole("link", { name: "Доска" })).toBeVisible(); } async function call(path: string, body: unknown) { const r = await fetch(BASE + path, { method: "POST", headers: { Authorization: "Bearer " + tokens().agent, "Content-Type": "application/json" }, body: JSON.stringify(body) }); expect(r.ok, `${path} → ${r.status}`).toBe(true); return r.json(); } // учебный агент: взять команду refresh, загрузить состояние зеркала как есть и отчитаться done export async function agentServeRefresh() { const { command } = await call("/agent/claim", { agent_version: 99, settings_version: null, last_jira_call_at: null }); expect(command?.type).toBe("refresh"); await call("/agent/state", { command_id: command.id, issues: [], links: [], neighbor_keys: [] }); await call(`/agent/commands/${command.id}/result`, { status: "done", result: { issues: 0 }, jira_calls: 1, rate_limited: 0 }); return command.id as number; }