Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
626 changes: 626 additions & 0 deletions dashboard/e2e/prs-overview-data.ts

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions dashboard/e2e/prs-overview-mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Page, Route } from "@playwright/test";
import type { PrsOverview } from "../src/lib/api";
import { overview, type Scenario } from "./prs-overview-data";
import { detail, page as prsPage } from "./prs-data";

export interface OverviewBackend {
calls: string[];
/** The answer to /api/prs/overview for its query; a number is an error status. Tests swap it mid-way. */
answer: (url: URL) => PrsOverview | number;
}

/** Answers every API call the overview and the list make, from the invented data. */
export async function mockOverview(page: Page, scenario: Scenario | ((url: URL) => PrsOverview | number) = "normal"): Promise<OverviewBackend> {
const db: OverviewBackend = {
calls: [],
answer: typeof scenario === "function" ? scenario : (url) => overview(scenario, url.searchParams.get("repo") ?? undefined),
};
const json = (route: Route, body: unknown, status = 200) => route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
await page.route((url) => url.hostname !== "localhost", (route) => route.abort());
await page.route((url) => url.hostname === "localhost" && /^\/(api|auth)\//.test(url.pathname), async (route) => {
const url = new URL(route.request().url());
const p = url.pathname;
db.calls.push(`${route.request().method()} ${p}${url.search}`);
if (p === "/api/me") return json(route, { user_id: "u_1", team_id: "t_1", github_login: "octocat", email: "octocat@example.com", avatar_url: "", role: "member" });
if (p === "/api/usage") return json(route, { month: "2026-01", total_tokens: 0, tokens_in: 0, tokens_out: 0, total_runs: 0, max_tokens: 0 });
if (p === "/api/banners") return json(route, { banners: [] });
if (p === "/api/security/overview") return json(route, { enabled: false, dry_run: true, counts: { open: 0, p0: 0, p1: 0 } });
if (p === "/api/setup") return json(route, { repos: [], new_recommendations: [], auto_setup_new_repos: false });
if (p === "/api/support/badge") return json(route, { waiting: 0, queue_open: null });
if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_1", org: "acme", status: "active", current: true }] });
if (p === "/api/repos") return json(route, { repos: [{ name: "acme/web", enabled: true }, { name: "acme/checkout", enabled: true }] });
if (p === "/api/prs/overview") {
const a = db.answer(url);
if (typeof a === "number") return json(route, { error: "nope" }, a);
return json(route, a);
}
if (p === "/api/prs") return json(route, prsPage());
if (p === "/api/prs/detail") return json(route, detail());
return json(route, { error: "Not mocked" }, 404);
});
return db;
}
237 changes: 237 additions & 0 deletions dashboard/e2e/prs-overview.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
import { expect, test, type Page } from "@playwright/test";
import { overview, PEOPLE } from "./prs-overview-data";
import { mockOverview } from "./prs-overview-mock";

// The Pull requests overview (/prs/overview): the summary written from
// facts, the stage strip and its drill-down into the list, the aging chart,
// the repo table and one repo's page, the five panels, CoderHelm's slice,
// the "not enough history yet" and backfill states, the empty, error,
// loading and older-backend states, no person's name outside an item's
// owner, and the phone layout. Every API call is answered by the mock.

async function open(page: Page, scenario: Parameters<typeof mockOverview>[1] = "normal", url = "/prs/overview?org=acme") {
const db = await mockOverview(page, scenario);
await page.goto(url);
await expect(page.getByTestId("overview-summary")).toBeVisible();
return db;
}

test("the Pull requests menu lands on the Overview tab, and List is beside it", async ({ page }) => {
await mockOverview(page, "normal");
await page.goto("/prs/overview");
const tabs = page.getByTestId("section-tabs");
await expect(tabs.getByRole("link", { name: "Overview" })).toHaveAttribute("aria-current", "page");
await expect(tabs.getByRole("link", { name: "List" })).toHaveAttribute("href", /^\/prs\/?$/);
});

test("the summary: a verdict, three fixed tiles, ranked items with owners, and the stability and CoderHelm lines", async ({ page }) => {
await open(page, "bad");
const s = page.getByTestId("overview-summary");
await expect(s).toHaveAttribute("data-verdict", "slipping");
await expect(page.getByTestId("summary-verdict-word")).toHaveText(/Slipping/);
// The sentence starts with the reason, not the chip's word again.
await expect(page.getByTestId("summary-verdict")).not.toContainText("Slipping.");
const tiles = page.getByTestId("summary-tile");
await expect(tiles).toHaveCount(3);
await expect(tiles.nth(0)).toHaveAttribute("data-tile", "stale");
await expect(tiles.nth(1)).toHaveAttribute("data-tile", "failures");
await expect(tiles.nth(2)).toHaveAttribute("data-tile", "reviewed");
const items = page.getByTestId("summary-item");
expect(await items.count()).toBeLessThanOrEqual(5);
await expect(items.first()).toContainText("past SLA");
// A line with no owner says why.
await expect(page.getByTestId("summary-owner").filter({ hasText: "no reviewer was requested" })).toBeVisible();
await expect(page.getByTestId("summary-stability")).toBeVisible();
await expect(page.getByTestId("summary-coderhelm")).toContainText("blocked on the red main");
await expect(page.getByTestId("summary-window")).toContainText(/computed (Mon|Tue|Wed|Thu|Fri|Sat|Sun) [A-Z][a-z]{2} \d+, \d\d:\d\d/);
await page.getByTestId("summary-source-toggle").click();
await expect(page.getByTestId("summary-rule")).toContainText("Slipping: any obligation breached");
});

test("every number in the summary links to what produced it", async ({ page }) => {
await open(page, "normal");
const nums = page.getByTestId("summary-number");
expect(await nums.count()).toBeGreaterThan(4);
for (const n of await nums.all()) {
await expect(n).toHaveAttribute("data-fact", /.+/);
await expect(n).toHaveAttribute("href", /.+/);
}
// The text between them carries no bare count: digits sit inside a fact's link, a PR reference or a time.
const verdict = (await page.getByTestId("summary-verdict").innerText()).replace(/\s+/g, " ");
const linked = (await page.getByTestId("summary-verdict").getByTestId("summary-number").allInnerTexts()).join(" ");
for (const d of verdict.match(/\d+(\.\d+)?[hd%]?/g) ?? []) expect(`${linked} 11h`).toContain(d);
});

test("the five example weeks each read as their own verdict", async ({ page }) => {
for (const [kind, state, words] of [
["normal", "healthy", "38"],
["bad", "slipping", "critical security fixes"],
["quiet", "quiet", "6"],
["coderhelm_waiting", "at_risk", "Work is done but not landing"],
["unstable", "at_risk", "flaky"],
] as const) {
await page.unrouteAll({ behavior: "ignoreErrors" });
await open(page, kind);
await expect(page.getByTestId("overview-summary")).toHaveAttribute("data-verdict", state);
await expect(page.getByTestId("summary-verdict")).toContainText(words);
}
await expect(page.getByTestId("summary-coderhelm")).toContainText("rerun");
});

test("a quiet week says what was checked", async ({ page }) => {
await open(page, "quiet");
await expect(page.getByTestId("summary-quiet")).toContainText("Checked 14 repos and 9 open PRs");
await expect(page.getByTestId("summary-item")).toHaveCount(0);
});

test("a strip cell opens the list filtered to its stage, and the list shows the filter", async ({ page }) => {
const db = await open(page, "normal");
await page.locator('[data-testid="strip-cell"][data-stage="first_review"]').first().click();
await expect(page).toHaveURL(/\/prs\/?\?org=acme&stage=first_review/, { timeout: 60_000 });
await expect(page.getByTestId("prs-filter-chip")).toContainText("Stage: Waiting for first review");
await expect.poll(() => db.calls.some((c) => c.startsWith("GET /api/prs?") && c.includes("stage=first_review"))).toBe(true);
await page.getByTestId("prs-filter-chip").click();
await expect(page).not.toHaveURL(/stage=/);
});

test("past-usual counts open the list filtered to past p85", async ({ page }) => {
await open(page, "bad");
await page.getByTestId("panel-stale").getByTestId("stale-past-usual").click();
await expect(page).toHaveURL(/past=p85/, { timeout: 60_000 });
await expect(page.getByTestId("prs-filter-chip")).toContainText("Open past the p85");
});

test("the aging chart: one mark per PR, a shape per author, the percentile lines, and a click opens the PR", async ({ page }) => {
await open(page, "bad");
const o = overview("bad");
const dots = page.getByTestId("aging-dot");
await expect(dots).toHaveCount(o.aging.dots.length);
await expect(page.locator('[data-testid="aging-dot"][data-shape="hexagon"]').first()).toBeAttached();
await expect(page.locator('[data-testid="aging-dot"][data-shape="circle"]').first()).toBeAttached();
await expect(page.locator('[data-testid="aging-dot"][data-idle="true"]').first()).toBeAttached();
await expect(page.locator('[data-testid="aging-dot"][data-main-blocked="true"]').first()).toBeAttached();
for (const l of ["p50", "p85", "p95"]) await expect(page.getByTestId(`aging-line-${l}`)).toBeAttached();
// Every mark is named in words, never only by colour.
await expect(dots.first()).toHaveAttribute("aria-label", /open .*(person's|CoderHelm's|bot's) pull request/);
await page.getByTestId("aging-select-past").click();
await expect(page.getByTestId("aging-bubble")).not.toBeEmpty();
const key = o.aging.dots[0].key;
await page.locator(`[data-testid="aging-dot"][href*="${encodeURIComponent(key)}"]`).first().click();
await expect(page).toHaveURL(new RegExp(`/prs/?\\?.*pr=${encodeURIComponent(key).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`), { timeout: 60_000 });
});

test("the repo table: health words with their rule, new columns, and a row opens that repo's overview", async ({ page }) => {
const db = await open(page, "bad");
const rows = page.getByTestId("repo-row");
await expect(rows.first()).toHaveAttribute("data-health", "slipping");
await expect(page.getByTestId("rollup-rule")).toContainText("The org takes the worst state");
await expect(page.getByTestId("repo-flags").first()).not.toBeEmpty();
await page.getByTestId("repo-link").first().click();
await expect(page).toHaveURL(/\/prs\/overview\/?\?org=acme&repo=acme%2F/, { timeout: 60_000 });
await expect(page.getByTestId("overview-repo-views")).toBeVisible();
await expect.poll(() => db.calls.some((c) => c.includes("/api/prs/overview?") && c.includes("repo=acme"))).toBe(true);
});

test("the five panels render, and the Stale tile equals the Stale panel's headline", async ({ page }) => {
for (const kind of ["normal", "bad"] as const) {
await page.unrouteAll({ behavior: "ignoreErrors" });
await open(page, kind);
for (const p of ["stale", "failures", "review", "security", "events"]) await expect(page.getByTestId(`panel-${p}`)).toBeVisible();
const tile = (await page.locator('[data-testid="summary-tile"][data-tile="stale"] [data-fact="stale"]').innerText()).trim();
const panel = (await page.getByTestId("stale-headline").innerText()).trim();
expect(panel.startsWith(tile)).toBe(true);
expect(tile).toBe(String(overview(kind).stale.stale));
}
await expect(page.getByTestId("coverage-bar")).toBeVisible();
await expect(page.getByTestId("review-funnel")).toContainText("verified fixed");
await expect(page.getByTestId("security-past-sla")).toHaveText("2");
await expect(page.getByTestId("failure-suspects")).toContainText("suspect");
await expect(page.getByTestId("event-rows").locator("li")).toHaveCount(6);
});

test("CoderHelm's panel reports outcomes and runs in one end state each, with no line counts", async ({ page }) => {
await open(page, "unstable");
const ch = page.getByTestId("overview-coderhelm");
await expect(ch).toContainText("green only on a rerun (flaky, not fixed) 6");
await expect(ch).not.toContainText(/lines? (of code|written)/i);
});

test("an org with no CoderHelm pull requests still gets the whole overview", async ({ page }) => {
await open(page, "people_only");
await expect(page.getByTestId("aging-dot").first()).toBeAttached();
await expect(page.getByTestId("repo-row").first()).toBeVisible();
await expect(page.getByTestId("panel-review")).toBeVisible();
await expect(page.locator('[data-testid="aging-dot"][data-shape="hexagon"]')).toHaveCount(0);
await expect(page.getByTestId("summary-coderhelm")).toContainText("No PRs from CoderHelm in this window");
});

test("not enough history yet: young data says so instead of a zero", async ({ page }) => {
await open(page, "young");
await expect(page.getByTestId("history-note")).toContainText("1 week");
await expect(page.getByTestId("not-yet").first()).toBeVisible();
await expect(page.getByTestId("aging-external")).toBeVisible();
await expect(page.getByTestId("aging-band").first()).toBeAttached();
});

test("a backfill in progress shows how far it has read", async ({ page }) => {
await open(page, "backfilling");
await expect(page.getByTestId("history-backfill")).toContainText("12 of 40 repos read");
});

test("no person's name appears outside an item's owner", async ({ page }) => {
for (const kind of ["bad", "coderhelm_waiting", "people_only"] as const) {
await page.unrouteAll({ behavior: "ignoreErrors" });
await open(page, kind);
await expect(page.getByTestId("panel-events")).toBeVisible();
const text = await page.getByTestId("prs-overview").evaluate((root) => {
const clone = root.cloneNode(true) as HTMLElement;
clone.querySelectorAll('[data-testid="summary-owner"]').forEach((n) => n.remove());
return clone.innerText + " " + Array.from(clone.querySelectorAll("[aria-label],[title]")).map((n) => `${n.getAttribute("aria-label") ?? ""} ${n.getAttribute("title") ?? ""}`).join(" ");
});
for (const p of PEOPLE) expect(text.toLowerCase(), `${p} in ${kind}`).not.toMatch(new RegExp(`(^|[^a-z0-9-])@?${p}([^a-z0-9-]|$)`));
}
});

test("an older backend's 404 explains and points at the list", async ({ page }) => {
await mockOverview(page, () => 404);
await page.goto("/prs/overview");
await expect(page.getByTestId("overview-not-served")).toBeVisible();
await expect(page.getByTestId("overview-not-served").getByRole("link", { name: "list" })).toHaveAttribute("href", /^\/prs\/?$/);
});

test("a failed read shows the error with a retry that reads again", async ({ page }) => {
let fail = true;
await mockOverview(page, (url) => (fail ? 500 : overview("normal", url.searchParams.get("repo") ?? undefined)));
await page.goto("/prs/overview");
await expect(page.getByTestId("list-error")).toBeVisible({ timeout: 45_000 });
fail = false;
await page.getByTestId("list-error").getByRole("button").first().click();
await expect(page.getByTestId("overview-summary")).toBeVisible();
});

test("while it reads, the page shows its outline, and with nothing yet it says so", async ({ page }) => {
let release!: () => void;
const gate = new Promise<void>((r) => (release = r));
await mockOverview(page, "empty");
await page.route("**/api/prs/overview**", async (route) => {
await gate;
await route.fallback();
});
await page.goto("/prs/overview");
await expect(page.getByTestId("overview-loading")).toBeVisible();
release();
await expect(page.getByTestId("overview-empty")).toBeVisible();
});

for (const width of [320, 375]) {
test(`the phone layout at ${width}: priority order and no sideways scroll`, async ({ page }) => {
await page.setViewportSize({ width, height: 800 });
await open(page, "bad");
await expect(page.getByTestId("overview-phone")).toBeVisible();
await expect(page.getByTestId("overview-past-usual")).toBeVisible();
await page.getByTestId("phone-stale").click();
await expect(page.getByTestId("overview-phone").getByTestId("panel-stale")).toBeVisible();
const wide = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
expect(wide).toBeLessThanOrEqual(0);
});
}
3 changes: 2 additions & 1 deletion dashboard/e2e/wide-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { infraData } from "./infra";
import { setupData } from "./setup";
import { skillRunsData } from "./skill-runs";
import { prsData } from "./prs";
import { prsOverviewData } from "./prs-overview";
import { inboxData } from "./inbox";

// An invented backend whose records are full of long, unbroken strings
Expand Down Expand Up @@ -53,7 +54,7 @@ const base: Handler = ({ method, path }) => {
};

// Knowledge answers /api/knowledge before the chat's file does.
const HANDLERS: Handler[] = [base, runsData, reviewData, settingsData, logsData, learningData, knowledgeData, brainData, agentsData, pluginsData, securityData, infraData, setupData, skillRunsData, inboxData, prsData];
const HANDLERS: Handler[] = [base, runsData, reviewData, settingsData, logsData, learningData, knowledgeData, brainData, agentsData, pluginsData, securityData, infraData, setupData, skillRunsData, inboxData, prsData, prsOverviewData];

/** Mocks the whole API. Returns the list of GETs no handler answered. */
export async function mockWideApi(page: Page): Promise<{ unanswered: string[] }> {
Expand Down
31 changes: 31 additions & 0 deletions dashboard/e2e/wide-data/prs-overview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Handler } from "./index";
import { ORG, REPO, SENTENCE, TITLE, TOKEN } from "./long";
import { overview } from "../prs-overview-data";

// The Pull requests overview: the bad week, with every repo, title, owner,
// event and sentence stretched to the longest text the page will get.

const LOGIN = "dana-developer-with-a-long-login";

function wide(): unknown {
let s = JSON.stringify(overview("bad"));
// Each invented repo becomes a long one, still one per name.
s = s.replace(/acme\/([a-z-]+)/g, (_m, name: string) => `${REPO}-${name}`);
s = s.replace(/"org":"acme"/g, `"org":"${ORG}"`).replace(/"acme"/g, `"${ORG}"`);
for (const t of ["Round cart totals per currency", "Show stock per warehouse on the book page", "Cache the bestseller list for an hour"]) s = s.split(t).join(`${TITLE} ${TOKEN}`);
const o = JSON.parse(s);
for (const a of o.summary.attention) {
a.parts.push({ t: ` ${SENTENCE} ${TOKEN}` });
if (a.owner) a.owner = `${LOGIN}-${TOKEN}`;
}
for (const e of o.events) e.text = `${e.text}: ${SENTENCE} ${TOKEN}`;
o.summary.changed.parts.push({ t: ` ${SENTENCE} ${TOKEN}` });
o.failures.flaky = { count: 1, new: 1, top: [{ check: TOKEN, repo: REPO, retries: 12 }] };
return o;
}

export const prsOverviewData: Handler = ({ method, path }) => {
if (method !== "GET") return undefined;
if (path === "/api/prs/overview") return wide();
return undefined;
};
Loading
Loading