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
93 changes: 93 additions & 0 deletions dashboard/e2e/stop-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,61 @@ const RUNS: Record<string, unknown> = {
reason: "It selects the card by its name, which is the ticket's fix.",
},
},
// Coderhelm's own pull request covered the ticket and lacked part of it:
// the run carried its work there; the ticket's earlier pull request is
// superseded.
"01CONT": {
...BASE,
run_id: "01CONT",
status: "covered_by_pr",
covered_by: {
repo: "your-team/web",
number: 52,
url: "https://github.com/your-team/web/pull/52",
title: "Merge and deploy the cards change",
author: "coderhelm[bot]",
reason: "It implements the scope.",
own: true,
outcome: "continued",
carried: { branch: "coderhelm/abc-13", head: "9f2c1e0", commits: 3, files: ["src/register.ts", "src/helpers/a.ts"], rebuilt: false },
open_items: ["Register the two extra helper files"],
superseded: { repo: "your-team/web", number: 41, url: "https://github.com/your-team/web/pull/41", title: "Cards list fix", closed: false },
note: "Continued in #52, Coderhelm's own open pull request that already covered this ticket.",
},
},
"01DONE": {
...BASE,
run_id: "01DONE",
status: "covered_by_pr",
covered_by: {
repo: "your-team/web",
number: 52,
url: "https://github.com/your-team/web/pull/52",
title: "Merge and deploy the cards change",
author: "coderhelm[bot]",
reason: "It implements the scope.",
own: true,
outcome: "complete",
superseded: { repo: "your-team/web", number: 41, url: "https://github.com/your-team/web/pull/41", closed: true, closed_by: "Sam" },
note: "#52 already has everything this ticket asks for.",
},
},
"01PERS": {
...BASE,
run_id: "01PERS",
status: "covered_by_pr",
covered_by: {
repo: "your-team/web",
number: 60,
url: "https://github.com/your-team/web/pull/60",
title: "Cards fix",
author: "dev-b",
reason: "It fixes the spec.",
own: false,
outcome: "person",
note: "dev-b's pull request #60 covers this ticket.",
},
},
"01ASKD": {
...BASE,
run_id: "01ASKD",
Expand Down Expand Up @@ -106,6 +161,7 @@ async function mockApi(page: Page, role = "member") {
const rest = m[2] ?? "";
if (rest === "") return json(route, RUNS[m[1]]);
if (rest === "/retry" && req.method() === "POST") return json(route, { status: "queued" });
if (rest === "/close-superseded" && req.method() === "POST") return json(route, { closed: true, message: "Closed #41." });
if (rest === "/openspec") return json(route, {});
if (rest === "/traces") return json(route, { traces: [] });
if (rest === "/agent-log") return json(route, { passes: [], live_events: [] });
Expand Down Expand Up @@ -187,3 +243,40 @@ test("a covered run can be retried when the ticket needs its own change", async
await page.getByTestId("run-outcome").getByRole("button", { name: /Retry/ }).click();
await expect.poll(() => calls).toContain("POST /api/runs/01COVR/retry");
});

test("a covered run that continued in Coderhelm's own pull request shows what was carried and offers to close the earlier one", async ({ page }) => {
const calls = await mockApi(page);
await page.goto("/runs/detail?id=01CONT");
const outcome = page.getByTestId("run-outcome");
await expect(outcome).toContainText("Continued in #52");
await expect(page.getByTestId("covered-carried")).toContainText("3 commits onto coderhelm/abc-13");
await expect(page.getByTestId("covered-open-items")).toContainText("Register the two extra helper files");
await expect(page.getByTestId("covered-superseded")).toContainText("#41 is superseded by #52");
await expect(page.getByTestId("covered-by-link")).toHaveAttribute("href", "https://github.com/your-team/web/pull/52");
// Retry isn't the way on: the work is in #52.
await expect(outcome.getByRole("button", { name: /Retry/ })).toHaveCount(0);
// Closing #41 happens only on a click, after a confirm.
expect(calls).not.toContain("POST /api/runs/01CONT/close-superseded");
await page.getByTestId("close-superseded").click();
await page.getByTestId("confirm-dialog").getByRole("button", { name: "Close #41" }).click();
await expect.poll(() => calls).toContain("POST /api/runs/01CONT/close-superseded");
});

test("a covering pull request that has everything says so, with the earlier one closed", async ({ page }) => {
await mockApi(page);
await page.goto("/runs/detail?id=01DONE");
await expect(page.getByTestId("run-outcome")).toContainText("#52 already has everything this ticket asks for");
await expect(page.getByTestId("covered-superseded")).toContainText("#41 is closed by Sam");
await expect(page.getByTestId("close-superseded")).toHaveCount(0);
});

test("a person's covering pull request is linked, never offered to continue in or close", async ({ page }) => {
await mockApi(page);
await page.goto("/runs/detail?id=01PERS");
const outcome = page.getByTestId("run-outcome");
await expect(outcome).toContainText("Covered by dev-b's pull request #60");
await expect(page.getByTestId("covered-by")).toContainText("dev-b's pull request #60 covers this ticket.");
await expect(page.getByTestId("close-superseded")).toHaveCount(0);
await expect(outcome.getByRole("button", { name: /Continue/ })).toHaveCount(0);
await expect(outcome.getByRole("button", { name: /Retry/ })).toBeVisible();
});
129 changes: 102 additions & 27 deletions dashboard/src/app/runs/detail/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
const [loading, setLoading] = useState(true);
// "missing" when the gateway says there is no such run, "failed" for anything else.
const [loadError, setLoadError] = useState<"missing" | "failed" | null>(null);
const [busy, setBusy] = useState<"retry" | "review" | "reset" | "cancel" | "close" | "reopen" | null>(null);
const [busy, setBusy] = useState<"retry" | "review" | "reset" | "cancel" | "close" | "reopen" | "close-superseded" | null>(null);
const [closeOpen, setCloseOpen] = useState(false);
const [specTab, setSpecTab] = useState<keyof Openspec>("proposal");
const [usage, setUsage] = useState<UsageInfo | null>(null);
Expand Down Expand Up @@ -434,7 +434,7 @@
if (idx > max) max = idx;
});
return max;
}, [run?.current_pass, run?.pass_history]);

Check warning on line 437 in dashboard/src/app/runs/detail/page.tsx

View workflow job for this annotation

GitHub Actions / Lint & Build

React Hook useMemo has a missing dependency: 'run'. Either include it or remove the dependency array

if (!runId) {
return (
Expand Down Expand Up @@ -601,6 +601,30 @@
setBusy(null);
}
};
// Close the ticket's earlier pull request a covered run superseded: only on
// a person's click (the gateway closes only Coderhelm's own pull request).
const closeSuperseded = async (n: number) => {
const ok = await confirm({
title: `Close #${n}?`,
message: `#${n} is superseded: this ticket's change is in the pull request the run continued in. Closing it is visible to everyone on the repository; its branch is kept.`,
confirmLabel: `Close #${n}`,
});
if (ok !== "primary") return;
setBusy("close-superseded");
try {
const r = await api.closeSupersededPr(runId);
if (!r.ok) {
toast(r.message || actionError(new Error(r.error), `close #${n}`), "error");
} else {
toast(r.message || `Closed #${n}.`);
}
fetchRun();
} catch (e) {
toast(actionError(e, `close #${n}`), "error");
} finally {
setBusy(null);
}
};
const cancel = async () => {
setBusy("cancel");
try {
Expand Down Expand Up @@ -781,34 +805,85 @@
);
} else if (run.status === "covered_by_pr") {
const cb = run.covered_by;
outcome = (
<OutcomeCard
tone="neutral"
title={cb ? `Already being fixed in #${cb.number}` : "Already being fixed in an open pull request"}
testId="run-outcome"
actions={
<>
{cb?.url && (
<a href={cb.url} target="_blank" rel="noopener noreferrer" className={secondaryButton} data-testid="covered-by-link">
Open #{cb.number}
</a>
const kind = cb?.outcome ?? "";
const carried = cb?.carried;
const sup = cb?.superseded;
// The work is in the covering pull request: Retry isn't what's next.
const done = kind === "continued" || kind === "complete";
const title = !cb
? "Already being fixed in an open pull request"
: kind === "continued"
? `Continued in #${cb.number}`
: kind === "complete"
? `#${cb.number} already has everything this ticket asks for`
: kind === "person"
? `Covered by ${cb.author || "a person"}'s pull request #${cb.number}`
: `Already being fixed in #${cb.number}`;
{
outcome = (
<OutcomeCard
tone="neutral"
title={title}
testId="run-outcome"
actions={
<>
{cb?.url && (
<a href={cb.url} target="_blank" rel="noopener noreferrer" className={done ? primaryButton : secondaryButton} data-testid="covered-by-link">
Open #{cb.number}
</a>
)}
{canAct && sup && !sup.closed && done && (
<button type="button" onClick={() => closeSuperseded(sup.number)} disabled={busy !== null} className={secondaryButton} data-testid="close-superseded">
Close #{sup.number}
</button>
)}
{!done && retryButton}
</>
}
>
<div className="min-w-0 space-y-2 [overflow-wrap:anywhere]" data-testid="covered-by">
{cb && (
<p>
<span className="font-medium text-zinc-100">{cb.title || `${cb.repo}#${cb.number}`}</span>
{cb.author ? <> by {cb.author}</> : null}
</p>
)}
{retryButton}
</>
}
>
<div className="min-w-0 space-y-1 [overflow-wrap:anywhere]" data-testid="covered-by">
{cb && (
<p>
<span className="font-medium text-zinc-100">{cb.title || `${cb.repo}#${cb.number}`}</span>
{cb.author ? <> by {cb.author}</> : null}
{cb?.reason && <p className="text-zinc-300">{cb.reason}</p>}
{carried && (carried.commits ?? 0) > 0 && (
<p data-testid="covered-carried">
Carried over: {carried.commits} commit{carried.commits === 1 ? "" : "s"} onto <Code>{carried.branch}</Code>
{carried.rebuilt ? " (rebuilt on it)" : ""}
{carried.files?.length ? <>, changing {carried.files.slice(0, 6).map((f, i) => <span key={f}>{i > 0 ? ", " : ""}<Code>{f}</Code></span>)}{carried.files.length > 6 ? ` and ${carried.files.length - 6} more` : ""}</> : null}
.
</p>
)}
{!!cb?.open_items?.length && (
<div data-testid="covered-open-items">
<p className="text-sm font-medium text-zinc-200">Still open for this ticket in #{cb.number}</p>
<ul className="list-disc space-y-1 pl-5 text-sm">
{cb.open_items.map((i) => (
<li key={i}>{i}</li>
))}
</ul>
</div>
)}
{sup && (
<p data-testid="covered-superseded">
{sup.url ? <a href={sup.url} target="_blank" rel="noopener noreferrer" className="underline underline-offset-2">#{sup.number}</a> : <>#{sup.number}</>}
{sup.closed
? <> is closed{sup.closed_by ? <> by {sup.closed_by}</> : null}: superseded by #{cb?.number}.</>
: <> is superseded by #{cb?.number}, which carries this ticket&apos;s change. It stays open until someone closes it: Coderhelm doesn&apos;t close a pull request by itself.</>}
</p>
)}
<p className="text-zinc-400">
{cb?.note
? cb.note
: "Coderhelm built no second fix and linked this pull request on the ticket. If the ticket needs a separate change, say so on the ticket, then retry."}
</p>
)}
{cb?.reason && <p className="text-zinc-300">{cb.reason}</p>}
<p className="text-zinc-400">Coderhelm built no second fix and linked this pull request on the ticket. If the ticket needs a separate change, say so on the ticket, then retry.</p>
</div>
</OutcomeCard>
);
</div>
</OutcomeCard>
);
}
} else if (run.status === "failed") {
outcome = (
<Problem
Expand Down
41 changes: 41 additions & 0 deletions dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ export const api = {
closeRuns: (ids: string[], body: CloseRunRequest) =>
request<BulkCloseAnswer>("/api/runs/close", { method: "POST", body: JSON.stringify({ run_ids: ids, ...body }) }),
/** Undo a close: the run shows as before (or waiting on a person); nothing restarts. */
/**
* Close the ticket's earlier pull request a covered run superseded. Only
* Coderhelm's own pull request is closed (the gateway reads it from GitHub
* first); anything else comes back `ok: false` with the reason.
*/
closeSupersededPr: (id: string) =>
requestWithBody<{ closed?: boolean; message?: string }, { message?: string }>(
`/api/runs/${encodeURIComponent(id)}/close-superseded`,
{ method: "POST" },
),
reopenRun: (id: string) =>
requestWithBody<{ status: string; message?: string }, { status?: string; message?: string }>(
`/api/runs/${encodeURIComponent(id)}/reopen`,
Expand Down Expand Up @@ -2109,6 +2119,37 @@ export interface RunCoveredBy {
title?: string;
author?: string;
reason?: string;
/** It is Coderhelm's own pull request: only then does a run continue in it or offer to close the earlier one. */
own?: boolean;
/** `continued`, `complete`, `person`, `busy` or `not_carried`; empty on older runs. */
outcome?: string;
/** What the run put on its branch, when it continued in it. */
carried?: RunCoveredCarried | null;
/** What is still open for this ticket in it. */
open_items?: string[];
/** The ticket's earlier pull request Coderhelm opened, now redundant. */
superseded?: RunSupersededPr | null;
/** What the run page says, in one paragraph. */
note?: string;
}

/** What a covered run carried over to Coderhelm's own covering pull request. */
export interface RunCoveredCarried {
branch: string;
head?: string;
commits?: number;
files?: string[];
rebuilt?: boolean;
}

/** The ticket's earlier pull request, superseded by the covering one. */
export interface RunSupersededPr {
repo: string;
number: number;
url?: string;
title?: string;
closed?: boolean;
closed_by?: string;
}

/** An answer given in Coderhelm to a run's question. */
Expand Down
6 changes: 4 additions & 2 deletions dashboard/src/lib/openapi-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// docs/api/openapi.json. Do not edit; run `npm run openapi:fields` instead.

/** The platform commit this was generated from. */
export const OPENAPI_REF = "4af300bd05abf7db9f07f0cfe4e7046098aa0bea";
export const OPENAPI_REF = "1c295b2fccaa0bc86b3ce72cf2598d1154948ff3";

/** The fields each public API schema has. */
export interface OpenApiFields {
Expand Down Expand Up @@ -64,11 +64,13 @@ export interface OpenApiFields {
Run: "answers" | "answers_url" | "applied_standards" | "branch" | "branches" | "cache_read_tokens" | "cache_write_tokens" | "close_reason" | "closed_at" | "closed_by" | "closed_from" | "codegen_env_missing" | "continued_run_id" | "cost_usd" | "covered_by" | "created_at" | "current_pass" | "duration_s" | "error" | "files_modified" | "fix_location" | "lesson" | "mcp_servers" | "outside_change_report" | "pass_history" | "policy_approval" | "policy_note" | "pr_number" | "pr_numbers" | "pr_url" | "pr_urls" | "progress_notes" | "prs" | "questions" | "questions_url" | "repo" | "round_incomplete" | "run_id" | "sign_in_prompts" | "status" | "stop_kind" | "ticket_id" | "ticket_source" | "title" | "tokens_in" | "tokens_out" | "tooling_failure" | "trigger" | "updated_at";
RunActionResult: "status";
RunAnswer: "answer" | "answered_at" | "author" | "question" | "question_id";
RunCoveredBy: "author" | "number" | "reason" | "repo" | "title" | "url";
RunCoveredBy: "author" | "carried" | "note" | "number" | "open_items" | "outcome" | "own" | "reason" | "repo" | "superseded" | "title" | "url";
RunCoveredCarried: "branch" | "commits" | "files" | "head" | "rebuilt";
RunNote: "message" | "timestamp";
RunPass: "pass" | "started_at";
RunQuestion: "decision" | "evidence" | "id" | "question" | "suggestions" | "why";
RunSummary: "cost_usd" | "created_at" | "current_pass" | "duration_s" | "pr_number" | "pr_url" | "repo" | "run_id" | "status" | "ticket_id" | "ticket_source" | "title" | "tokens_in" | "tokens_out" | "trigger";
RunSupersededPr: "closed" | "closed_by" | "number" | "repo" | "title" | "url";
RunToolingFailure: "command" | "error" | "tried";
RunTrigger: "by" | "kind" | "label" | "ref" | "ref_url";
RunsPage: "next" | "runs" | "scanned";
Expand Down
Loading