Skip to content
Open
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
89 changes: 72 additions & 17 deletions dashboard/e2e/prs-overview-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ export function overview(kind: Scenario = "normal", repo?: string): PrsOverview
missing.push({ path: "review.flow", reason: "history", text: "Not enough history yet: the weekly flow needs 2 weeks of review logs." });
missing.push({ path: "review.depth.rubber_stamp", reason: "history", text: "Not enough history yet: the repo's p10 approval time needs 30 approvals." });
missing.push({ path: "review.rubber_stamp_by_size", reason: "history", text: "Not enough history yet: fewer than 10 qualifying PRs." });
missing.push({ path: "repo_view.flow", reason: "history", text: "Not enough history yet: the flow by stage needs 2 nightly snapshots." });
missing.push({ path: "failures.main_red", reason: "history", text: "Not enough history yet: main's checks are read from this week on." });
missing.push({ path: "failures.flaky", reason: "history", text: "Not enough history yet: a flaky check needs 10 runs." });
}
Expand Down Expand Up @@ -613,24 +612,80 @@ export function overview(kind: Scenario = "normal", repo?: string): PrsOverview
missing,
sources: [{ name: "records", read: "ok", detail: "" }],
};
if (repo) {
const days = young ? 1 : 84;
o.repo_view = {
flow: young
? null
: Array.from({ length: days }, (_, i) => ({
day: iso((days - i) * D).slice(0, 10),
stages: { draft: 1 + (i % 3 === 0 ? 1 : 0), first_review: 3 + Math.round(4 * Math.sin(i / 9) ** 2) + Math.floor(i / 20), in_review: 3 + (i % 5 === 0 ? 1 : 0), blocked: 1 + Math.floor(i / 30), coderhelm_working: i % 4 === 0 ? 1 : 0, approved: 2 },
})),
merged: Array.from({ length: 34 }, (_, i) => {
const r = rng(i + 5);
const ch = i % 4 === 0;
return { key: `${repo}#${200 + i}`, number: 200 + i, title: TITLES[i % TITLES.length], cycle_secs: Math.round((1 + r() * r() * 120) * H), merged_at: iso((90 - i * 2.5) * D), coderhelm: ch };
}),
};
}
o.trends = isEmpty ? null : trendsOf(kind, repo, young, all);
return o;
}

/** A normal draw (Box-Muller) from the seeded generator. */
function normal(r: () => number): number {
return Math.sqrt(-2 * Math.log(Math.max(1e-9, r()))) * Math.cos(2 * Math.PI * r());
}

const STAGE_KEYS: PrStage[] = ["draft", "first_review", "in_review", "blocked", "coderhelm_working", "approved"];

/**
* The trends as history would give them: merges on weekdays at working
* hours (a weekend merge now and then), cycle times long-tailed and longer
* for ones that sat over a weekend, and the open count walking with
* weekday arrivals and merges. A young org's stage split begins 9 days ago.
*/
function trendsOf(kind: Scenario, repo: string | undefined, young: boolean, open: OverviewDot[]): NonNullable<PrsOverview["trends"]> {
const r = rng(kind.length * 131 + (repo?.length ?? 0) * 17 + 3);
const scale = repo ? 0.18 : 1;
const rate = (kind === "bad" ? 3.2 : kind === "quiet" ? 0.8 : 4.6) * scale;
const today = new Date(NOW);
today.setUTCHours(0, 0, 0, 0);
const dayStart = (back: number) => today.getTime() - back * D * 1000;
const merged: NonNullable<PrsOverview["trends"]>["merged"] = [];
let n = 900;
for (let back = 89; back >= 0; back--) {
const t0 = dayStart(back);
const wd = new Date(t0).getUTCDay();
const weekend = wd === 0 || wd === 6;
const want = weekend ? (r() < 0.15 * scale + 0.05 ? 1 : 0) : Math.max(0, Math.round(rate + normal(r) * Math.sqrt(rate)));
for (let k = 0; k < want; k++) {
const at = t0 + (9 + r() * 10) * H * 1000;
if (at > NOW) continue;
let cycle = Math.exp(Math.log(19 * H) + normal(r) * 1.15);
// Waiting through a weekend adds it.
if (wd <= 2 && r() < 0.35) cycle += 2 * D;
cycle = Math.min(40 * D, Math.max(12 * 60, cycle));
const rp = repo ?? REPOS[Math.floor(r() * 9)];
const number = n++;
merged.push({ key: `${rp}#${number}`, repo: rp, number, title: TITLES[Math.floor(r() * TITLES.length)], merged_at: new Date(at).toISOString(), cycle_secs: Math.round(cycle), coderhelm: r() < 0.18 });
}
}
// Open per day: walk back from today's open, weekdays moving, weekends still.
const nowByStage: Record<string, number> = {};
for (const d of open) nowByStage[d.stage] = (nowByStage[d.stage] ?? 0) + 1;
let total = open.length;
const days: NonNullable<PrsOverview["trends"]>["flow"] = [];
const split = young ? 9 : 84;
for (let back = 0; back < 84; back++) {
const t0 = dayStart(back);
const wd = new Date(t0).getUTCDay();
const stages: Partial<Record<PrStage, number>> = {};
if (back < split) {
let left = total;
STAGE_KEYS.forEach((st, i) => {
const share = (nowByStage[st] ?? 0) / Math.max(1, open.length);
const v = i === STAGE_KEYS.length - 1 ? left : Math.max(0, Math.min(left, Math.round(total * share + normal(r) * 0.8)));
stages[st] = v;
left -= v;
});
}
days.unshift({ day: new Date(t0).toISOString().slice(0, 10), stages: back < split ? stages : {}, total, unknown: back < split ? 0 : total });
const weekend = wd === 0 || wd === 6;
if (!weekend) total = Math.max(0, total + Math.round(normal(r) * 2.2 * Math.sqrt(scale) + (kind === "bad" ? -0.6 : 0.1)));
}
return {
flow: days,
split_from: young ? days[days.length - split].day : days[0].day,
merged: merged.reverse(),
cycle_days: 90,
flow_days: 84,
};
}

/** Every login the fixtures use for people: none may appear outside a pull request's row or an item's owner. */
export const PEOPLE = ["octocat", "mara", "theo", "jun"];
127 changes: 127 additions & 0 deletions dashboard/e2e/prs-overview-sizes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import fs from "node:fs";
import path from "node:path";
import { expect, test, type Locator } from "@playwright/test";
import { mockOverview } from "./prs-overview-mock";
import { sized, type Size } from "./prs-overview-sizes";

// The overview at three sizes of org (one repo with three open pull requests
// and no history; 14 repos and about 40 open; about 300 open) and four widths.
// Each is captured, and the layout rules hold at every one: no tooltip is
// visible until something is hovered or focused, the age chart is never
// taller than its marks need, and a handful of pull requests is a list, not
// an empty plot.

/**
* The legend items with no drawn mark of their kind: a mark counts only on
* a drawn dot or band (never the chart's own element).
*/
async function undrawnLegendItems(aging: Locator): Promise<string[]> {
const out: string[] = [];
const legend = aging.getByTestId("aging-legend");
if ((await legend.count()) === 0) return out;
for (const item of await legend.locator("[data-mark]").all()) {
const mark = (await item.getAttribute("data-mark")) ?? "";
const drawn = await aging.locator(`[data-testid="aging-dot"][data-marks~="${mark}"], [data-testid="aging-band"][data-marks~="${mark}"]`).count();
if (drawn === 0) out.push(mark);
}
return out;
}

const SHOTS_DIR = process.env.E2E_SHOTS_DIR || path.join("test-results", "overview-sizes");
const PREFIX = process.env.E2E_SHOTS_PREFIX || `org-polish-${process.env.E2E_SHOTS_TAG || "after"}`;
const WIDTHS = [1440, 1280, 1024, 375];
const SIZES: Size[] = ["sparse", "medium", "big"];

for (const size of SIZES) {
for (const width of WIDTHS) {
test(`overview, ${size} org at ${width}px: captured, nothing floating at rest, the chart sized to its marks`, async ({ page }) => {
await page.setViewportSize({ width, height: 900 });
await mockOverview(page, () => sized(size));
await page.goto("/prs/overview?org=acme");
await expect(page.getByTestId("overview-summary")).toBeVisible();
await page.mouse.move(0, 0);
fs.mkdirSync(SHOTS_DIR, { recursive: true });
await page.screenshot({ path: path.join(SHOTS_DIR, `${PREFIX}-${size}-${width}.png`), fullPage: true });
if (width >= 640) await page.getByTestId("overview-aging").screenshot({ path: path.join(SHOTS_DIR, `${PREFIX}-${size}-${width}-aging.png`) });

// Nothing floats over the page until a mark is hovered or focused.
await expect(page.locator('[role="tooltip"]:visible')).toHaveCount(0);

if (width >= 640) {
const aging = page.getByTestId("overview-aging");
await expect(aging).toBeVisible();
const marks = sized(size).aging.dots.length;
if (marks < 10) {
// A few pull requests are a list with their ages, not a plot.
await expect(aging.getByTestId("aging-chart")).toHaveCount(0);
await expect(aging.getByTestId("aging-row")).toHaveCount(marks);
} else {
const chart = aging.getByTestId("aging-chart");
const box = await chart.boundingBox();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Blocking (required: tests): Legend check can never fail (tests)

charts.tsx:318 puts data-marks on the chart's root svg, built from the same present set the legend uses. aging.locator('[data-marks~="mark"]') always matches that root element, so every legend item passes even when no mark of that kind is drawn. 'Every legend item is drawn' is not actually tested. Count only elements below the root, for example aging-dot and aging-band, or the dot elements at charts.tsx:401 and 482.

This repository requires tests with behavior changes, so this blocks the merge until the test is in the PR.

expect(box && box.height, "the chart is never taller than 320px").toBeLessThanOrEqual(320);
// Axis words are body size or smaller.
const sizes = await chart.locator("text").evaluateAll((els) => els.map((e) => parseFloat(getComputedStyle(e).fontSize) * (e.getBoundingClientRect().height / Math.max(1, (e as SVGTextElement).getBBox().height))));
expect(Math.max(...sizes), "axis labels are at most 13px on screen").toBeLessThanOrEqual(13.5);
// A mark shows its tooltip on hover, and it goes away after.
await chart.getByTestId("aging-dot").first().hover();
await expect(page.locator('[role="tooltip"]:visible')).toHaveCount(1);
await page.mouse.move(0, 0);
await expect(page.locator('[role="tooltip"]:visible')).toHaveCount(0);
}
// The legend names only what is drawn.
expect(await undrawnLegendItems(aging)).toEqual([]);
}

// A new install: panels with nothing to say are one quiet line, never rows of 0.
if (size === "sparse" && width >= 640) {
const stale = page.getByTestId("panel-stale");
await expect(stale.getByTestId("panel-rest")).toContainText("Nothing idle");
await expect(stale).not.toContainText("Not enough history yet");
await expect(page.getByTestId("panel-security")).not.toContainText("Not enough history yet");
await expect(page.getByTestId("overview-coderhelm")).not.toContainText("Not enough history yet");
// Whose turn and the conditions leave out their zeros; the note is said once.
await expect(page.locator('[data-testid="turn-link"]:visible')).toHaveText(["people 2", "CoderHelm 1"]);
await expect(page.locator('[data-testid="conditions-none"]:visible')).toHaveText("nothing stale, abandoned or zombie");
await expect(page.getByTestId("history-note")).toContainText("review health");
await expect(page.getByText("Failures and review health")).toHaveCount(0);
}

// On a phone a new install lists its open PRs by age, and has no
// failures or review folds; on a desktop, no such panels either.
if (size === "sparse" && width < 640) {
const phoneAge = page.getByTestId("overview-aging-phone");
await expect(phoneAge).toBeVisible();
await expect(phoneAge.getByTestId("aging-row")).toHaveCount(3);
await expect(phoneAge.getByTestId("aging-row").first()).toContainText("2.1d");
await expect(page.getByTestId("phone-failures")).toHaveCount(0);
await expect(page.getByTestId("phone-review")).toHaveCount(0);
}
if (width >= 1024) {
const panels = page.getByTestId("overview-panels");
const merged = size !== "sparse";
await expect(panels.getByTestId("panel-failures")).toHaveCount(merged ? 1 : 0);
await expect(panels.getByTestId("panel-review")).toHaveCount(merged ? 1 : 0);
await expect(panels.getByTestId("panel-stale")).toHaveCount(1);
await expect(panels.getByTestId("panel-security")).toHaveCount(1);
}

// No sideways scroll at any width.
const sideways = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
expect(sideways).toBeLessThanOrEqual(1);

});
}
}

test("the legend check fails when a legend item has no drawn mark", async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
await mockOverview(page, () => sized("medium"));
await page.goto("/prs/overview?org=acme");
const aging = page.getByTestId("overview-aging");
await expect(aging.getByTestId("aging-dot").first()).toBeVisible();
expect(await undrawnLegendItems(aging)).toEqual([]);
// Take every person's mark off the chart: the legend still names it, and
// the check says so.
await aging.evaluate((el) => el.querySelectorAll('[data-testid="aging-dot"][data-marks~="person"]').forEach((d) => d.remove()));
expect(await undrawnLegendItems(aging)).toEqual(["person"]);
});
103 changes: 103 additions & 0 deletions dashboard/e2e/prs-overview-sizes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// The overview at three sizes of org, for the layout and screenshot checks:
// a new install with one repo, three open pull requests and no history; a
// medium org (14 repos, about 40 open); and a big one (14 repos, about 300
// open, more than the chart shows). Invented data, from the bookstore.

import type { OverviewDot, PrStage, PrsOverview } from "../src/lib/api";
import { overview } from "./prs-overview-data";

export type Size = "sparse" | "medium" | "big";

const H = 3600;
const D = 86_400;

/** One repo, three open pull requests, no history: the first day of an install. */
function sparse(): PrsOverview {
const o = overview("empty");
const repo = "acme/bookstore";
const mk = (n: number, stage: PrStage, state: string, state_label: string, age: number, who: "person" | "coderhelm" | "bot", title: string): OverviewDot => ({
key: `${repo}#${n}`,
repo,
number: n,
title,
stage,
state,
state_label,
age_secs: age,
coderhelm: who === "coderhelm",
author_type: who,
band: null,
idle: false,
main_blocked: false,
});
const dots = [
mk(12, "first_review", "needs_review", "Needs review", 40 * 60, "person", "Add the paperback filter to search"),
mk(11, "in_review", "changes_requested", "Changes requested", 5 * H, "coderhelm", "Round cart totals per currency"),
mk(9, "approved", "checks_running", "Checks running", 2 * D + 3 * H, "person", "Show stock per warehouse on the book page"),
];
const stages: Partial<Record<PrStage, number>> = { first_review: 1, in_review: 1, approved: 1 };
o.scope = { ...o.scope, repos: 1, repos_read: 1 };
o.open = 3;
o.drafts = 0;
o.aging = { ...o.aging, dots, shown: 3, total: 3 };
o.strip = o.strip.map((c) => ({ ...c, count: stages[c.stage as PrStage] ?? 0, delta: null, spark: null, past_p85: 0 }));
o.turns = { person: 2, coderhelm: 1, machines: 0, nobody: 0 };
o.thresholds = { ...o.thresholds, cycle: null, first_review: null, external: true };
o.history = { ...o.history, days: 0, weeks: 0, young: true, merged_90d: 0 };
o.summary = {
...o.summary,
verdict: { ...o.summary.verdict, state: "quiet", word: "Quiet", parts: [{ t: "3 open pull requests in bookstore, none waiting longer than a couple of days." }] },
attention: [],
quiet: { repos: 1, open: 3, parts: [{ t: "Nothing needs you: no pull request is idle or blocked." }] },
coderhelm: { ...o.summary.coderhelm, parts: [{ t: "One pull request of its own in review; nothing merged yet." }] },
};
o.coderhelm = {
author: { ...o.coderhelm.author, opened: 1, merged: 0, closed_unmerged: 0, open: 1, merge_rate: null, p50_merge_secs: null, waiting_on_people: null },
fixer: { fixed: 0, merged: 0, closed_unmerged: 0, open: 0 },
reviewer: { reviewed: 2, findings: null, verified_rate: null, p50_first_look_secs: 4 * 60 },
runs: null,
exceptions: { ...o.coderhelm.exceptions, needs_decision: 0, oldest_secs: null, reworked: null, merges: null, cost_per_merged: null },
};
o.security = { ...o.security, dependency: null };
// Opened in the last two days, nothing merged: the trends have nothing to say yet.
const today = new Date();
today.setUTCHours(0, 0, 0, 0);
o.trends = {
flow: Array.from({ length: 84 }, (_, i) => {
const back = 83 - i;
const total = back === 0 ? 3 : back <= 2 ? 1 : 0;
return { day: new Date(today.getTime() - back * D * 1000).toISOString().slice(0, 10), stages: back === 0 ? stages : back <= 2 ? { approved: 1 } : {}, total, unknown: 0 };
}),
split_from: new Date(today.getTime() - 83 * D * 1000).toISOString().slice(0, 10),
merged: [],
cycle_days: 90,
flow_days: 84,
};
o.stale = { ...o.stale, stale: 0, past_usual: 0, on_author: 0, on_reviewer: 0, abandoned: { count: 0, oldest_secs: null }, zombie: 0, drift: null, draft_p85_secs: null, archive_candidates: 0 };
o.repos = [{ ...o.repos[0], repo, open: 3, stages, past_p85: 0, health: "healthy", why: "3 open, none past usual.", link: { overview: `repo=${repo}` } }];
return o;
}

/** About 300 open across 14 repos: the chart shows the oldest it can. */
function big(): PrsOverview {
const o = overview("bad");
const base = o.aging.dots;
const dots: OverviewDot[] = [];
for (let k = 0; k < 5; k++) {
for (const d of base) {
const number = d.number + 1000 * (k + 1);
dots.push({ ...d, number, key: `${d.repo}#${number}`, age_secs: Math.round(d.age_secs * (0.6 + 0.2 * k)) });
}
}
o.aging = { ...o.aging, dots: dots.slice(0, 200), shown: 200, total: dots.length };
o.open = dots.length;
o.strip = o.strip.map((c) => ({ ...c, count: c.count * 5, past_p85: (c.past_p85 ?? 0) * 5 }));
o.repos = o.repos.map((r) => ({ ...r, open: r.open * 5, past_p85: r.past_p85 * 5 }));
return o;
}

export function sized(size: Size): PrsOverview {
if (size === "sparse") return sparse();
if (size === "big") return big();
return overview("normal");
}
Loading
Loading