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
8 changes: 8 additions & 0 deletions dashboard/e2e/close-runs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ interface Backend {
const OVER = ["closed", "cancelled", "merged", "retried", "archived"];

async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend> {
// "/" stays on Runs: the visit has begun (a phone's first visit opens the Inbox).
await page.addInitScript(() => {
try {
sessionStorage.setItem("ch-landed", "1");
} catch {
/* ignore */
}
});
const db: Backend = {
role: "member",
calls: [],
Expand Down
276 changes: 276 additions & 0 deletions dashboard/e2e/inbox-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
import type { Page, Route } from "@playwright/test";

// An invented team for the phone's Inbox: the bookstore's repos (acme/web,
// acme/api, acme/docs), octocat on the team, one of every kind of decision.
// `mockInbox(page, opts)` answers the whole API; what isn't here answers 404,
// as an older backend would.

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

export const QUESTION_RUN = {
run_id: "run_q1",
status: "needs_input",
ticket_source: "github",
ticket_id: "acme/web#41",
title: "Add gift cards to the bookstore checkout",
repo: "acme/web",
pr_number: 818,
pr_url: "https://github.com/acme/web/pull/818",
created_at: ago(95),
updated_at: ago(40),
current_pass: "plan",
questions: [
{
id: "q1",
question: "Should a gift card pay for shipping too, or only for books?",
why: "The checkout total and the refund rules both change with the answer.",
suggestions: ["Books and shipping", "Books only"],
decision: "gift_card_scope",
},
],
waiting_on: { action: "Answer CoderHelm's question", detail: "", since: ago(40) },
progress_notes: [
{ message: "Read the checkout and the order totals in src/checkout/total.ts.", timestamp: ago(60) },
{ message: "Found two places that add shipping: the cart and the payment step.", timestamp: ago(45) },
],
};

export const HANDOFF_RUN = {
run_id: "run_h1",
status: "needs_input",
ticket_source: "github",
ticket_id: "acme/docs#12",
title: "Document the new returns policy",
repo: "acme/docs",
pr_number: 44,
pr_url: "https://github.com/acme/docs/pull/44",
created_at: ago(300),
updated_at: ago(200),
draft_hold: {
kind: "held",
summary: "#44 stays a draft until a person signs off the wording",
reasons: [{ what: "the returns policy text needs a person's sign-off", todo: "Read the new page and mark the pull request ready" }],
pr_number: 44,
since: ago(200),
needs_person: true,
},
};

export const MERGE_RUN = {
run_id: "run_m1",
status: "needs_input",
ticket_source: "jira",
ticket_id: "WEB-42",
title: "Fix the flaky retry in the order queue",
repo: "acme/web",
pr_number: 812,
pr_url: "https://github.com/acme/web/pull/812",
prs: [{ repo: "acme/web", pr_number: 812, branch: "coderhelm/shop-212-order-retry", url: "https://github.com/acme/web/pull/812" }],
created_at: ago(500),
updated_at: ago(30),
merge_standing: { code: "auto_merge_off", text: "Checks pass and CoderHelm approved #812; auto-merge is off for this repo", next: "A person merges it", needs_person: true, approvals: null },
checks: { sha: "a1b2c3d", counts: { passed: 6, failed: 0, running: 0, queued: 0, skipped: 0 }, items: [] },
pr_review: { verdict: "APPROVE", review_sk: "REVIEW#acme/web#812#1", session_id: null, reviewed_sha: "a1b2c3d", at: ago(35) },
};

export const PR_MERGE = {
key: "acme/web#812",
org: "acme",
repo: "acme/web",
number: 812,
title: "Fix the flaky retry in the order queue",
url: "https://github.com/acme/web/pull/812",
author: { login: "coderhelm[bot]", coderhelm: true },
for: "octocat",
base: "main",
state: "ready_to_merge",
turn: "you",
next: { code: "merge", text: "Ready to merge: checks pass and CoderHelm approved", from: ["person:octocat"], since: ago(30) },
checks: { total: 6, passed: 6, failed: 0, running: 0 },
reviews: { approvals: 1, required: 1, coderhelm_verdict: "APPROVE" },
size: { additions: 42, deletions: 17 },
coderhelm: { run_id: "run_m1", session_id: "sess_812", what: "Retries a failed order write once after 2 seconds instead of looping, and logs the order id when it gives up." },
waiting_since: ago(30),
};

export const PR_FAILING = {
key: "acme/api#815",
org: "acme",
repo: "acme/api",
number: 815,
title: "Speed up the book search index",
url: "https://github.com/acme/api/pull/815",
author: { login: "coderhelm[bot]", coderhelm: true },
base: "main",
state: "checks_failing",
turn: "you",
next: { code: "checks_failing", text: "lint fails; CoderHelm can't fix it without your call", from: ["person:octocat"], since: ago(120) },
checks: { total: 5, passed: 4, failed: 1, running: 0, required_failed: ["lint"] },
reviews: { approvals: 0, required: 1, coderhelm_verdict: "APPROVE" },
size: { additions: 230, deletions: 96 },
coderhelm: { run_id: "run_f1", session_id: "sess_815", what: "Builds the search index in batches of 500 books, so a full rebuild takes minutes instead of an hour." },
waiting_since: ago(120),
};

export const APPROVAL = {
id: "appr_1",
status: "pending",
agent: "coder",
kind: "command",
tool: "shell",
repo: "acme/web",
command: "npm publish --tag next",
run_id: "run_p1",
args: {},
args_hash: "h",
why: "Publish the bookstore's checkout widget for the docs site",
asked_because: "rule",
reason: "Publishing needs a person",
created_at: ago(70),
expires_at: ago(-600),
};

export const PLANS = [
{ plan_id: "plan_1", title: "Split the billing service", description: "", repo: "acme/api", status: "executing", state: "needs_you", summary: "2 of 6 merged, 1 needs you", needs_count: 1, task_count: 6, created_at: ago(2000), updated_at: ago(150), last_activity_at: ago(150) },
{ plan_id: "plan_2", title: "Move book search to its own service", description: "", repo: "acme/api", status: "draft", state: "drafting", task_count: 4, created_at: ago(400), updated_at: ago(400) },
{ plan_id: "plan_3", title: "Old cleanup", description: "", repo: "acme/web", status: "done", state: "done", task_count: 3, created_at: ago(9000), updated_at: ago(9000) },
];

export const FINDING = {
id: "sec_1",
repo: "acme/web",
manifest: "package-lock.json",
ecosystem: "npm",
package: "bookshelf-parser",
version: "2.1.0",
fixed_version: null,
next_build: null,
advisory: { ids: ["GHSA-xxxx-0000-1111"], primary: "GHSA-xxxx-0000-1111", title: "Prototype pollution in bookshelf-parser", summary: "", cvss: 7.5, cvss_vector: null, epss: null, epss_percentile: null, kev: false, kev_due: null, malware: false, cwe: [], published_at: ago(5000), urls: [], source: "osv" },
scope: "runtime",
relation: "direct",
path: ["bookshelf-parser"],
verdict: "reachable",
evidence: null,
tier: "P1",
due_at: ago(-5000),
status: "no_fix",
pr: null,
dependabot_alert: null,
dismissed: null,
first_seen_at: ago(3000),
updated_at: ago(100),
};

export interface InboxMock {
/** Leave out a source, answer it 404 (an older backend), or fail it. */
runs?: "ok" | "empty" | "old" | "fail";
approvals?: "ok" | "empty" | "old" | "fail";
plans?: "ok" | "empty" | "old" | "fail";
prs?: "ok" | "empty" | "old" | "fail";
security?: "ok" | "empty" | "old" | "fail";
/** Hold every inbox read this long, to see the loading state. */
delayMs?: number;
/** Requests the page sent, for the checks. */
sent?: { method: string; path: string; body: string }[];
/** The auto-merge gate on acme/web#812 was stopped. */
gateStopped?: boolean;
}

const json = (route: Route, body: unknown, status = 200) => route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });

export async function mockInbox(page: Page, opts: InboxMock = {}) {
const o = { runs: "ok", approvals: "ok", plans: "ok", prs: "ok", security: "ok", ...opts } as Required<Omit<InboxMock, "delayMs" | "sent" | "gateStopped">> & InboxMock;
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 req = route.request();
const url = new URL(req.url());
const p = url.pathname;
const m = req.method();
if (m !== "GET") opts.sent?.push({ method: m, path: p, body: req.postData() ?? "" });
const state = (s: string, body: () => unknown) => {
if (s === "old") return json(route, { error: "Not found" }, 404);
if (s === "fail") return json(route, { error: "boom" }, 500);
return json(route, body());
};
const slow = async () => {
if (opts.delayMs) await new Promise((r) => setTimeout(r, opts.delayMs));
};

if (p === "/api/me") return json(route, { user_id: "u_octocat", team_id: "t_acme", github_login: "octocat", email: "octocat@example.com", avatar_url: "", role: "owner", mfa_enabled: false, platform_admin: false, flags: {} });
if (p === "/api/usage") return json(route, { month: "2026-01", total_tokens: 0, tokens_in: 0, tokens_out: 0, new_tokens: 0, total_runs: 0, max_tokens: 0, limits_legacy: false, limits: [] });
if (p === "/api/banners") return json(route, { banners: [] });
if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_acme", org: "acme", status: "active", current: true }] });
if (p === "/api/support/badge") return json(route, { waiting: 0, queue_open: null });

if (p === "/api/runs" && m === "GET") {
await slow();
const status = url.searchParams.get("status") ?? "";
if (status.includes("running")) return json(route, { runs: [{ ...QUESTION_RUN, run_id: "run_w1", status: "running" }, { ...QUESTION_RUN, run_id: "run_w2", status: "running" }], next: null });
if (status === "needs_input") return state(o.runs, () => ({ runs: o.runs === "empty" ? [] : [QUESTION_RUN, HANDOFF_RUN, MERGE_RUN], next: null }));
// The Runs page.
return json(route, { runs: [{ ...MERGE_RUN, status: "running", current_pass: "implement" }, QUESTION_RUN, HANDOFF_RUN], next: null });
}
const run = p.match(/^\/api\/runs\/([^/]+)(\/.*)?$/);
if (run) {
const sub = run[2] ?? "";
if (m === "POST" && sub === "/answer") return json(route, { status: "queued", run_id: "run_q2", posted: true, comment_url: "https://github.com/acme/web/issues/41#issuecomment-1" });
if (m === "POST" && sub === "/retry") return json(route, { status: "queued" });
if (m === "GET" && sub === "") {
const r = [QUESTION_RUN, HANDOFF_RUN, MERGE_RUN].find((x) => x.run_id === run[1]) ?? { ...MERGE_RUN, run_id: run[1], status: "running", current_pass: "implement", merge_standing: null };
return json(route, r);
}
return json(route, { error: "Not mocked" }, 404);
}
if (p === "/api/agents/approvals") {
await slow();
// The Inbox asks for every pending one; a run's page asks for its own (none here).
const all = o.approvals !== "empty" && !url.searchParams.get("run_id") && !url.searchParams.get("thread_id");
return state(o.approvals, () => ({ approvals: all ? [APPROVAL] : [], can: { approve: true, always: true } }));
}
if (p === "/api/plans") {
await slow();
return state(o.plans, () => ({ plans: o.plans === "empty" ? [] : PLANS, next_cursor: null }));
}
if (p === "/api/prs") {
await slow();
return state(o.prs, () => ({ prs: o.prs === "empty" ? [] : [PR_MERGE, PR_FAILING], total: 2, next: null, counts: { turn: { you: 2 } } }));
}
if (p === "/api/prs/detail") {
const n = Number(url.searchParams.get("number"));
const pr = [PR_MERGE, PR_FAILING].find((x) => x.number === n);
if (o.prs === "old" || !pr) return json(route, { error: "Not found" }, 404);
return json(route, { pr, checklist: [], ledger: { open_secs: 0, spans: [], totals: [] }, timeline: [], runs: [] });
}
if (p === "/api/reviewer/gate") {
if (m === "POST") return json(route, { status: "rearmed", ok: true, message: "Auto-merge re-armed. CoderHelm checks everything again, then merges." });
return json(route, { repo: "acme/web", pr_number: 812, auto_merge: true, can_control: true, gate: opts.gateStopped ? { state: "stopped", stopped: { by: "octocat", at: ago(60), reason: "Wanted to read it first" } } : { state: "armed" } });
}
if (p === "/api/security/findings") {
await slow();
return state(o.security, () => ({ findings: o.security === "empty" ? [] : [FINDING], next_cursor: null }));
}
return json(route, { error: `Not mocked: ${m} ${p}` }, 404);
});
}

/** Mark this visit as begun, so "/" stays on Runs instead of opening the Inbox. */
export async function skipLanding(page: Page) {
await page.addInitScript(() => {
try {
sessionStorage.setItem("ch-landed", "1");
} catch {
/* ignore */
}
});
}

export async function hideDevOverlay(page: Page) {
await page.addInitScript(() => {
document.addEventListener("DOMContentLoaded", () => {
const s = document.createElement("style");
s.textContent = "nextjs-portal{display:none!important}";
document.head.appendChild(s);
});
});
}
8 changes: 8 additions & 0 deletions dashboard/e2e/list-and-palette.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ interface Backend {
}

async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend> {
// "/" stays on Runs: the visit has begun (a phone's first visit opens the Inbox).
await page.addInitScript(() => {
try {
sessionStorage.setItem("ch-landed", "1");
} catch {
/* ignore */
}
});
const db: Backend = { calls: [], role: "admin", searchStatus: 200, ...init };
const json = (route: Route, body: unknown, status = 200) =>
route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
Expand Down
63 changes: 63 additions & 0 deletions dashboard/e2e/phone-inbox-shots.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect, test, type Page } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
import { hideDevOverlay, mockInbox, skipLanding } from "./inbox-data";

// Screenshots of the phone's Inbox and the flows it opens, at 375 wide, with
// the invented bookstore team, for a pull request. Written only when
// E2E_SHOTS_DIR is set; the checks are in phone-inbox.spec.ts.

const DIR = process.env.E2E_SHOTS_DIR;
const PREFIX = process.env.E2E_SHOTS_PREFIX ?? "phone2-";

async function shot(page: Page, name: string) {
fs.mkdirSync(DIR!, { recursive: true });
await page.addStyleTag({ content: "nextjs-portal{display:none!important}" });
await page.waitForTimeout(400);
await page.screenshot({ path: path.join(DIR!, `${PREFIX}${name}.png`) });
}

test("phone screenshots: the Inbox, its states and its flows", async ({ page }) => {
test.skip(!DIR, "E2E_SHOTS_DIR is not set");
test.setTimeout(240_000);
await page.setViewportSize({ width: 375, height: 812 });
await mockInbox(page);
await hideDevOverlay(page);
await skipLanding(page);

await page.goto("/inbox");
await expect(page.getByTestId("inbox-row")).toHaveCount(8);
// The count on the Inbox tab is read a moment after the page.
await expect(page.getByTestId("phone-bar-inbox")).toHaveAccessibleName(/decisions wait on you/);
await shot(page, "inbox");

await page.goto("/inbox/answer?run=run_q1");
await expect(page.getByRole("button", { name: "Books only" })).toBeVisible();
await page.getByRole("button", { name: "Books only" }).click();
await page.evaluate(() => window.scrollTo(0, 0));
await shot(page, "answer");

await page.goto("/inbox/pr?repo=acme%2Fweb&number=812&run=run_m1");
await expect(page.getByTestId("pr-verdict")).toContainText("Approved");
await page.getByTestId("pr-actions").getByRole("button", { name: "Merge" }).click();
await expect(page.getByRole("dialog", { name: "Merge #812?" })).toBeVisible();
await shot(page, "merge-sheet");
await page.keyboard.press("Escape");

await page.goto("/runs/detail?id=run_w1");
await expect(page.getByRole("heading", { level: 1 })).toBeVisible();
await shot(page, "run-detail");

await page.goto("/inbox");
await page.getByTestId("phone-bar-menu").click();
await page.getByRole("searchbox", { name: "Search the menu" }).fill("sec");
await expect(page.getByTestId("menu-search-results")).toBeVisible();
await shot(page, "menu-search");
await page.keyboard.press("Escape");

await page.unrouteAll({ behavior: "ignoreErrors" });
await mockInbox(page, { runs: "empty", approvals: "empty", plans: "empty", prs: "empty", security: "empty" });
await page.goto("/inbox");
await expect(page.getByTestId("inbox-empty")).toBeVisible();
await shot(page, "inbox-empty");
});
Loading
Loading