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
375 changes: 285 additions & 90 deletions dashboard/e2e/audit-plans.spec.ts

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions dashboard/src/app/plans/detail/criteria.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use client";

import Link from "next/link";
import { useState } from "react";
import type { PlanCriterion, Task } from "@/lib/api";
import { StatusText, type StatusLook } from "@/components/list";
import { focusRing } from "@/components/ui";

// The plan's success criteria above its tasks: what done means, each with
// the tasks that cover it and what the work shows for it (the run's criteria
// trace). A long list folds to its count line once the plan runs.

const FOLD_OVER = 6;

const PROOF: Record<string, StatusLook> = {
proven: { label: "Proven", tone: "success" },
not_the_ticket: { label: "Passes without the change", tone: "waiting" },
failing: { label: "Fails", tone: "danger" },
missing: { label: "No test", tone: "waiting" },
unverified: { label: "Unverified", tone: "waiting" },
not_run: { label: "Not run yet", tone: "neutral" },
};

function look(c: PlanCriterion): StatusLook {
if (c.met) return PROOF.proven;
const worst = ["failing", "missing", "not_the_ticket", "unverified", "not_run"].find((s) => c.evidence.some((e) => e.state === s));
return worst ? PROOF[worst] : { label: "No evidence yet", tone: "muted" };
}

export function CriteriaList({ criteria, tasks, folded }: { criteria: PlanCriterion[]; tasks: Task[]; folded: boolean }) {
const [open, setOpen] = useState(!folded || criteria.length <= FOLD_OVER);
if (criteria.length === 0) {
return <p className="text-sm text-zinc-400">No criteria written. Add &quot;Done when&quot; lines to the tasks, and each one is checked against the work.</p>;
}
const met = criteria.filter((c) => c.met).length;
const number = (id: string) => tasks.findIndex((t) => t.task_id === id) + 1;
return (
<div className="space-y-2" data-testid="criteria">
<button
type="button"
onClick={() => setOpen(!open)}
aria-expanded={open}
className={`rounded text-sm text-zinc-300 hover:text-zinc-100 ${focusRing}`}
data-testid="criteria-count"
>
{criteria.length} criteri{criteria.length === 1 ? "on" : "a"}, {met} proven
<span className="ml-1 text-zinc-400">{open ? "(hide)" : "(show)"}</span>
</button>
{open && (
<ol className="divide-y divide-zinc-800 overflow-hidden rounded-lg border border-zinc-800 bg-zinc-900/30">
{criteria.map((c) => {
const ev = c.evidence[0];
return (
<li key={c.id} className="flex flex-col gap-1 px-4 py-2.5 sm:flex-row sm:items-start sm:justify-between sm:gap-4" data-testid="criterion">
<div className="min-w-0 text-sm">
<span className="mr-2 tabular-nums text-zinc-400">{c.id}</span>
<span className={c.met ? "text-zinc-300" : "text-zinc-100"}>{c.text}</span>
{c.tasks.length > 0 && (
<span className="ml-2 text-xs text-zinc-400">
task {c.tasks.map((t) => number(t)).filter((n) => n > 0).join(", ")}
</span>
)}
{ev?.by && <p className="text-xs text-zinc-400">{ev.by}{ev.tests && ev.tests.length > 0 ? `: ${ev.tests.join(", ")}` : ""}</p>}
</div>
<div className="flex shrink-0 items-center gap-2">
<StatusText look={look(c)} />
{ev?.run_id && (
<Link href={`/runs/detail?id=${encodeURIComponent(ev.run_id)}`} className={`rounded text-xs text-zinc-400 hover:text-zinc-200 hover:underline ${focusRing}`}>
Proof
</Link>
)}
</div>
</li>
);
})}
</ol>
)}
</div>
);
}
106 changes: 106 additions & 0 deletions dashboard/src/app/plans/detail/needs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"use client";

import Link from "next/link";
import type { NeedsItem, Task } from "@/lib/api";
import { ExternalLinkIcon } from "@/components/icons";
import { buttonClass } from "@/components/ui";

// What waits on a person, at the top of the plan, each row the exact ask:
// the run's question, the pull request to review or merge, the checks
// Coderhelm could not fix, the task that failed and why, the drafts left.
// A row goes away once it is handled: the list comes from the work itself.

const small = buttonClass("secondary", "sm");
const primarySmall = buttonClass("primary", "sm");

export interface NeedsActions {
busy: string | null;
retry: (task: Task) => void;
drop: (taskId: string) => void;
approveRest: () => void;
}

export function NeedsStrip({
items,
tasks,
actions,
}: {
items: NeedsItem[];
tasks: Task[];
actions: NeedsActions;
}) {
if (items.length === 0) return null;
const number = (id: string) => tasks.findIndex((t) => t.task_id === id) + 1;
return (
<section
id="needs"
aria-labelledby="needs-heading"
data-testid="needs-strip"
className="scroll-mt-8 rounded-lg border border-orange-500/30 bg-orange-500/5"
>
<h2 id="needs-heading" className="flex items-center gap-2 px-4 pt-3 text-sm font-semibold text-orange-200">
Needs you
<span className="font-normal tabular-nums text-orange-300">{items.length}</span>
</h2>
<ul className="divide-y divide-orange-500/10">
{items.map((n, i) => {
const task = tasks.find((t) => t.task_id === n.task_id);
const busy = (a: string) => actions.busy === `${n.task_id}:${a}`;
return (
<li key={`${n.task_id}:${n.kind}:${i}`} className="flex flex-col gap-2 px-4 py-3 sm:flex-row sm:items-start sm:justify-between" data-testid="needs-item" data-kind={n.kind}>
<div className="min-w-0">
<p className="text-sm font-medium text-zinc-100 [overflow-wrap:anywhere]">
{task && <span className="mr-1.5 tabular-nums text-zinc-400">{number(task.task_id)}.</span>}
{n.ask}
</p>
{n.detail && <p className="mt-0.5 line-clamp-3 text-xs text-zinc-300 [overflow-wrap:anywhere]">{n.detail}</p>}
</div>
<div className="flex shrink-0 flex-wrap gap-2">
{n.action === "approve" && (
<button type="button" onClick={actions.approveRest} disabled={!!actions.busy} className={primarySmall}>
Approve the rest
</button>
)}
{n.action === "answer" && n.run_id && (
<Link href={`/runs/detail?id=${encodeURIComponent(n.run_id)}`} className={primarySmall}>
Answer
</Link>
)}
{(n.action === "open_pr" || n.action === "open_link") && n.url && (
<a href={n.url} target="_blank" rel="noopener noreferrer" className={`${primarySmall} gap-1.5`}>
{prWord(n)}
<span aria-hidden="true" className="inline-flex">
<ExternalLinkIcon />
</span>
<span className="sr-only"> (opens in a new tab)</span>
</a>
)}
{n.action === "retry" && task && (
<>
<button type="button" onClick={() => actions.retry(task)} disabled={!!actions.busy} className={primarySmall}>
{busy("retry") ? "Retrying…" : "Retry"}
</button>
<button type="button" onClick={() => actions.drop(task.task_id)} disabled={!!actions.busy} className={small}>
Drop task
</button>
</>
)}
{n.run_id && n.action !== "answer" && (
<Link href={`/runs/detail?id=${encodeURIComponent(n.run_id)}`} className={buttonClass("ghost", "sm")}>
Open run
</Link>
)}
</div>
</li>
);
})}
</ul>
</section>
);
}

function prWord(n: NeedsItem): string {
const num = n.url?.match(/\/pull\/(\d+)/)?.[1];
const what = n.kind === "merge" ? "Merge" : n.kind === "approval" ? "Approve" : n.kind === "checks" ? "See checks on" : "Review";
return num ? `${what} #${num}` : `${what} the pull request`;
}
Loading
Loading