Skip to content
Merged
2 changes: 1 addition & 1 deletion dashboard/e2e/audit-alerts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ test("an alert's page shows its source, runs and text in words", async ({ page }
await expect(page.getByText("Waiting for checks")).toBeVisible();
await expect(page.getByText("awaiting_ci")).toHaveCount(0);
await expect(page.getByText("Started by this alert")).toBeVisible();
await expect(page.getByRole("link", { name: "Pull request" })).toHaveAttribute("href", "https://github.com/your-team/web/pull/12");
await expect(page.getByRole("link", { name: "Pull request", exact: true })).toHaveAttribute("href", "https://github.com/your-team/web/pull/12");
// The facts list is two columns: each label sits beside its value.
const label = await page.locator("dt", { hasText: "Source" }).boundingBox();
const value = await page.locator("dd", { hasText: "CloudWatch alarm" }).boundingBox();
Expand Down
217 changes: 217 additions & 0 deletions dashboard/e2e/prs-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
// Invented pull requests for the Pull requests page: the bookstore's repos
// (acme/web, acme/api, acme/checkout) and its people (octocat, mara, theo,
// jun). Every state the server sends appears at least once.

import type { PrDetail, PrRow, PrsPage } from "../src/lib/api";

const now = Date.now();
export const ago = (mins: number) => new Date(now - mins * 60_000).toISOString();

export const VIEWER = "octocat";

type Over = Partial<PrRow> & Pick<PrRow, "number" | "title" | "state" | "turn" | "next">;

export function pr(over: Over): PrRow {
const repo = over.repo ?? "acme/web";
return {
key: `${repo}#${over.number}`,
org: repo.split("/")[0],
repo,
url: `https://github.com/${repo}/pull/${over.number}`,
author: { login: "theo" },
draft: false,
base: "main",
head: `feature/${over.number}`,
created_at: ago(60 * 30),
updated_at: ago(20),
modifiers: [],
people: [{ login: "mara", roles: ["reviewer"] }],
checks: { total: 12, passed: 12, failed: 0, running: 0, required_failed: [], known: true },
reviews: { approvals: 0, required: 1, changes_requested_by: [], requested: ["mara"], coderhelm_verdict: null },
conflict: false,
open_threads: 0,
labels: [],
size: { additions: 120, deletions: 14 },
last_action: { actor: "theo", text: "pushed 1 commit", at: ago(40) },
coderhelm: null,
links: [],
waiting_since: ago(90),
...over,
};
}

export const ROWS: PrRow[] = [
pr({
number: 88,
repo: "acme/checkout",
title: "Add a gift-wrap option at checkout",
state: "needs_review",
turn: "you",
next: { code: "needs_review", text: "Needs your review: 1 approval (repo rule), asked 2 d ago.", from: ["person:octocat"], since: ago(60 * 48), rule: "repo_rule" },
reviews: { approvals: 0, required: 1, requested: ["octocat"], coderhelm_verdict: "APPROVE" },
waiting_since: ago(60 * 48),
}),
pr({
number: 418,
repo: "acme/api",
title: "Store stock counts as whole numbers",
author: { login: "coderhelm[bot]", coderhelm: true },
for: "octocat",
state: "needs_decision",
turn: "you",
next: { code: "product_decision", text: "CoderHelm stopped: needs you to pick how old stock counts move over.", from: ["person:octocat"], since: ago(25) },
coderhelm: { run_id: "run-418", round: 1, working: false, what: "Waiting on a decision" },
modifiers: ["agent_authored", "large"],
size: { additions: 880, deletions: 120 },
waiting_since: ago(25),
}),
pr({
number: 212,
title: "Round cart totals per currency",
author: { login: "coderhelm[bot]", coderhelm: true },
for: "theo",
state: "coderhelm_working",
turn: "coderhelm",
next: { code: "checks_failing", text: "Checks fail on lint: CoderHelm is fixing them, round 2.", from: ["coderhelm"], since: ago(4), rule: "required_check" },
checks: { total: 12, passed: 10, failed: 1, running: 1, required_failed: ["lint"], known: true },
reviews: { approvals: 1, required: 1, requested: [], coderhelm_verdict: null },
coderhelm: { run_id: "run-212", session_id: "session-212", round: 2, working: true, what: "Fixing CI" },
last_action: { actor: "coderhelm[bot]", text: "pushed a fix to lint", at: ago(4) },
links: [{ kind: "depends", repo: "acme/api", number: 418, url: "https://github.com/acme/api/pull/418", state: "needs_decision" }],
modifiers: ["agent_authored", "stacked"],
waiting_since: ago(4),
}),
pr({
number: 204,
title: "Share a wishlist by link",
author: { login: "sam" },
state: "changes_requested",
turn: "person",
next: { code: "changes_requested", text: "Changes requested by @mara: @sam to answer them.", from: ["person:sam"], since: ago(60 * 50) },
modifiers: ["stale"],
waiting_since: ago(60 * 50),
}),
pr({
number: 210,
title: "Show store hours in the header",
author: { login: "jun" },
state: "needs_review",
turn: "person",
next: { code: "needs_review", text: "Needs 1 approval (repo rule): @mara asked 1 d ago.", from: ["person:mara"], since: ago(60 * 24), rule: "repo_rule" },
}),
pr({
number: 215,
title: "Bump the image library",
author: { login: "jun" },
state: "checks_running",
turn: "machines",
next: { code: "checks_running", text: "Checks running: 9 of 12 done.", from: ["ci"], since: ago(6), rule: "required_check" },
checks: { total: 12, passed: 9, failed: 0, running: 3, known: true },
}),
pr({
number: 219,
title: "Cache book cover images",
author: { login: "mara" },
state: "ready_to_merge",
turn: "person",
next: { code: "ready_to_merge", text: "Ready to merge: every requirement is met; @mara merges.", from: ["person:mara"], since: ago(180) },
reviews: { approvals: 2, required: 2, requested: [], coderhelm_verdict: "APPROVE" },
}),
pr({
number: 199,
title: "Fix the author search page size",
state: "unknown",
turn: "machines",
next: { code: "unknown", text: "Unknown: GitHub hasn't said yet whether it merges cleanly.", from: [], since: ago(2) },
checks: { total: 0, passed: 0, failed: 0, running: 0, known: false },
}),
pr({
number: 190,
title: "Paginate the order history",
state: "merged",
turn: "done",
next: { code: "merged", text: "Merged by @mara.", from: [], since: ago(120) },
}),
];

export function page(rows: PrRow[] = ROWS, over: Partial<PrsPage> = {}): PrsPage {
const turn: Record<string, number> = {};
const state: Record<string, number> = {};
const repo: Record<string, number> = {};
for (const r of rows) {
turn[r.turn] = (turn[r.turn] ?? 0) + 1;
state[r.state] = (state[r.state] ?? 0) + 1;
repo[r.repo] = (repo[r.repo] ?? 0) + 1;
}
return {
prs: rows,
total: rows.length,
next: null,
counts: {
turn,
state,
repo,
org: { acme: rows.length },
views: {
my_turn: turn.you ?? 0,
coderhelm_working: state.coderhelm_working ?? 0,
needs_decision: state.needs_decision ?? 0,
ready: (state.ready_to_merge ?? 0) + (state.ready_auto_merge ?? 0),
stale: rows.filter((r) => r.modifiers?.includes("stale")).length,
},
},
viewer: VIEWER,
synced_at: ago(1),
sources: [{ name: "webhooks", read: "ok" }, { name: "reconcile", read: "ok", detail: "acme: 9 open pull requests read" }],
...over,
};
}

/** A long list, for the windowed list. */
export function many(n: number): PrRow[] {
return Array.from({ length: n }, (_, i) =>
pr({
number: 1000 + i,
title: `Bookstore change number ${i + 1}`,
state: "needs_review",
turn: "person",
next: { code: "needs_review", text: `Needs 1 approval (repo rule): @mara asked ${i + 1} h ago.`, from: ["person:mara"], since: ago(60 * (i + 1)) },
}),
);
}

export function detail(row: PrRow = ROWS[2]): PrDetail {
return {
pr: row,
checklist: [
{ key: "checks", mark: "blocked", text: "Required checks 10 of 12: lint failed, CoderHelm is on it", source: "required_check" },
{ key: "approvals", mark: "done", text: "Approvals 1 of 1: @mara", source: "repo_rule" },
{ key: "conflicts", mark: "done", text: "No conflicts with main" },
{ key: "threads", mark: "done", text: "Conversations resolved (3 of 3)" },
{ key: "queue", mark: "none", text: "Merge queue: not used in this repo" },
],
ledger: {
open_secs: 97_200,
spans: [],
totals: [
{ who: "person:mara", secs: 46_800 },
{ who: "coderhelm", secs: 3_600 },
{ who: "ci", secs: 14_400 },
{ who: "nobody", secs: 28_800 },
],
},
timeline: [
{ at: ago(4), actor: "coderhelm[bot]", coderhelm: true, kind: "pushed", text: "pushed a fix to lint", run_id: "run-212" },
{ at: ago(6), actor: "coderhelm[bot]", coderhelm: true, kind: "run", text: "read the lint log", run_id: "run-212" },
{ at: ago(10), actor: "ci", kind: "check", text: "lint failed on 4c2d1e0" },
{ at: ago(60 * 3), actor: "mara", kind: "review", text: "approved: looks right once CI is green" },
{ at: ago(60 * 26), actor: "coderhelm[bot]", coderhelm: true, kind: "pushed", text: "opened the pull request", run_id: "run-200" },
{ at: ago(60 * 27), actor: "theo", kind: "comment", text: "asked CoderHelm through WEB-42" },
],
runs: [
{ run_id: "run-212", title: "Fix CI (lint)", status: "running", started_at: ago(8), url: "/runs/detail?id=run-212" },
{ run_id: "run-200", title: "Write the pull request", status: "completed", started_at: ago(60 * 27), ended_at: ago(60 * 26), url: "/runs/detail?id=run-200" },
],
synced_at: ago(1),
};
}
Loading