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
165 changes: 165 additions & 0 deletions dashboard/e2e/stop-rules.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { expect, test, type Page, type Route } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";

// How a run that stopped by the stop rules reads on the run page: a tooling
// failure names the exact command and error (never "needs your answer"), a
// run covered by someone's open pull request links it, and a question shows
// the evidence it cites. Every API call is answered here.

const SHOTS_DIR = process.env.E2E_SHOTS_DIR || path.join("test-results", "shots");

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

const BASE = {
ticket_source: "jira",
ticket_id: "ABC-12",
title: "Cards list spec fails on every run",
repo: "your-team/web",
cost_usd: 1.2,
tokens_in: 1000,
tokens_out: 1000,
duration_s: 600,
current_pass: "done",
created_at: iso(60),
updated_at: iso(5),
pass_history: [],
progress_notes: [],
};

const RUNS: Record<string, unknown> = {
"01TOOL": {
...BASE,
run_id: "01TOOL",
status: "failed",
error: "Tooling failure: `cd 'e2e' && pnpm exec tsc --noEmit -p tsconfig.json` failed: sh: 1: tsc: not found",
stop_kind: "tooling",
tooling_failure: {
command: "cd 'e2e' && pnpm exec tsc --noEmit -p tsconfig.json",
error: "sh: 1: tsc: not found",
tried: [
"`cd 'e2e' && (pnpm install --ignore-workspace --frozen-lockfile || pnpm install --ignore-workspace)` failed (exit 1)",
"`cd 'e2e' && pnpm exec tsc --noEmit -p tsconfig.json` failed (exit 127)",
],
},
},
"01COVR": {
...BASE,
run_id: "01COVR",
status: "covered_by_pr",
error: "Already being fixed in #41",
covered_by: {
repo: "your-team/web",
number: 41,
url: "https://github.com/your-team/web/pull/41",
title: "Fix the cards list spec: select the card by its name",
author: "dev-b",
reason: "It selects the card by its name, which is the ticket's fix.",
},
},
"01ASKD": {
...BASE,
run_id: "01ASKD",
status: "needs_input",
questions: [
{
id: "q1",
question: "The spec already selects the card by its name, so the ticket's cause doesn't hold here. Is there another cause?",
why: "The ticket says the spec reads the first card.",
suggestions: [],
decision: null,
evidence: ["e2e/tests/cards.spec.ts:42", "L2"],
},
],
},
};

async function mockApi(page: Page, role = "member") {
const calls: string[] = [];
const json = (route: Route, body: unknown, status = 200) =>
route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
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 p = new URL(req.url()).pathname;
calls.push(`${req.method()} ${p}`);
if (p === "/api/me") return json(route, { user_id: "u_1", team_id: "t_1", github_login: "sam", email: "sam@example.com", avatar_url: "", role });
if (p === "/api/usage") return json(route, { month: "2026-01", total_tokens: 0, tokens_in: 0, tokens_out: 0, total_runs: 0, max_tokens: 0 });
if (p === "/api/banners") return json(route, { banners: [] });
if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_1", org: "your-team", status: "active", current: true }] });
if (p === "/api/repos") return json(route, { repos: [{ name: "your-team/web", enabled: true, ticket_source: "jira" }] });
if (p === "/api/plugins/catalog") return json(route, { plugins: [] });
const m = p.match(/^\/api\/runs\/(\w+)(\/.*)?$/);
if (m && RUNS[m[1]]) {
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 === "/openspec") return json(route, {});
if (rest === "/traces") return json(route, { traces: [] });
if (rest === "/agent-log") return json(route, { passes: [], live_events: [] });
if (rest === "/asks") return json(route, { asks: [] });
}
return json(route, { error: `Not mocked: ${p}` }, 404);
});
return calls;
}

async function shot(page: Page, name: string) {
fs.mkdirSync(SHOTS_DIR, { recursive: true });
await page.screenshot({ path: path.join(SHOTS_DIR, `${name}.png`), fullPage: true });
}

async function noSidewaysScroll(page: Page) {
const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
expect(overflow).toBeLessThanOrEqual(0);
}

for (const [label, width, height] of [
["desktop", 1440, 900],
["phone", 390, 844],
] as const) {
test(`a tooling failure names the command and error, not a question (${label})`, async ({ page }) => {
await page.setViewportSize({ width, height });
await mockApi(page);
await page.goto("/runs/detail?id=01TOOL");
const outcome = page.getByTestId("run-outcome");
await expect(outcome).toContainText("Tooling failure: Coderhelm's own environment failed");
await expect(outcome).toContainText("This is not a question for the ticket.");
await expect(page.getByTestId("tooling-command").locator("pre")).toContainText("cd 'e2e' && pnpm exec tsc --noEmit -p tsconfig.json");
await expect(page.getByTestId("tooling-error").locator("pre")).toContainText("sh: 1: tsc: not found");
await expect(page.getByTestId("tooling-failure")).toContainText("failed (exit 127)");
await expect(outcome).not.toContainText(/needs your answer|more detail/i);
await noSidewaysScroll(page);
await shot(page, `stop-rules-tooling-${width}`);
});

test(`a run covered by an open pull request links it (${label})`, async ({ page }) => {
await page.setViewportSize({ width, height });
await mockApi(page);
await page.goto("/runs/detail?id=01COVR");
const outcome = page.getByTestId("run-outcome");
await expect(outcome).toContainText("Already being fixed in #41");
await expect(page.getByTestId("covered-by")).toContainText("Fix the cards list spec: select the card by its name by dev-b");
await expect(page.getByTestId("covered-by")).toContainText("It selects the card by its name, which is the ticket's fix.");
await expect(page.getByTestId("covered-by-link")).toHaveAttribute("href", "https://github.com/your-team/web/pull/41");
await expect(page.getByText("Covered by an open PR").first()).toBeVisible();
await noSidewaysScroll(page);
await shot(page, `stop-rules-covered-${width}`);
});
}

test("a question shows the evidence it cites", async ({ page }) => {
await mockApi(page);
await page.goto("/runs/detail?id=01ASKD");
const ev = page.getByTestId("run-question-evidence");
await expect(ev).toContainText("Evidence:");
await expect(ev.locator("code")).toHaveText(["e2e/tests/cards.spec.ts:42", "L2"]);
});

test("a covered run can be retried when the ticket needs its own change", async ({ page }) => {
const calls = await mockApi(page);
await page.goto("/runs/detail?id=01COVR");
await page.getByTestId("run-outcome").getByRole("button", { name: /Retry/ }).click();
await expect.poll(() => calls).toContain("POST /api/runs/01COVR/retry");
});
70 changes: 68 additions & 2 deletions dashboard/src/app/runs/detail/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import { Problem, TechnicalDetails } from "@/components/problem";
import { CopyButton } from "@/components/copy-button";
import { Code } from "@/components/settings/code";
import { CodeBlock } from "@/components/code-block";
import { ChevronRightIcon, ExternalLinkIcon } from "@/components/icons";
import { RunTriggerLine } from "@/components/run-trigger";

Expand Down Expand Up @@ -445,7 +446,7 @@
if (idx > max) max = idx;
});
return max;
}, [run?.current_pass, run?.pass_history]);

Check warning on line 449 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 @@ -508,11 +509,11 @@
const doneCount = taskItems.filter((t) => isTaskDone(t, filesModified, run.status, maxPassIdx)).length;

// What each action is allowed for, matching the gateway's own checks.
const canRetry = ["failed", "needs_input", "needs_outside_change", "cancelled", "closed"].includes(run.status) && run.current_pass !== "feedback";
const canRetry = ["failed", "needs_input", "needs_outside_change", "covered_by_pr", "cancelled", "closed"].includes(run.status) && run.current_pass !== "feedback";
// A closed run is reopened first; the gateway refuses a re-review of it.
const canReview = !!run.pr_url && !["running", "queued", "merged", "closed"].includes(run.status);
// Starting over closes the pull request: never offered once it is merged.
const canReset = ["completed", "failed", "needs_input", "needs_outside_change", "cancelled", "closed", "success"].includes(run.status);
const canReset = ["completed", "failed", "needs_input", "needs_outside_change", "covered_by_pr", "cancelled", "closed", "success"].includes(run.status);
// Close is a button while the run works or waits on an answer; otherwise it sits in More.
const closeAsButton = closable && runCloseIsLikely(run.status);
const closeInMenu = closable && !closeAsButton;
Expand Down Expand Up @@ -743,6 +744,71 @@
</div>
</OutcomeCard>
);
} else if (run.status === "failed" && run.stop_kind === "tooling" && run.tooling_failure) {
// The run's own environment failed (a missing dependency or tool): never
// a question for the ticket. Say exactly which command and what it printed.
const tf = run.tooling_failure;
outcome = (
<OutcomeCard
tone="attention"
title="Tooling failure: Coderhelm's own environment failed"
testId="run-outcome"
actions={
<>
{retryButton}
{helpLink}
</>
}
>
<div className="min-w-0 space-y-2" data-testid="tooling-failure">
<p>This is not a question for the ticket. A command Coderhelm ran failed for want of a dependency or a tool, and installing and trying again didn&apos;t fix it.</p>
<CodeBlock code={tf.command} lang="bash" title="Command" wrap testId="tooling-command" />
<CodeBlock code={tf.error} title="Error" wrap testId="tooling-error" />
{!!tf.tried?.length && (
<>
<p className="text-sm font-medium text-zinc-200">Tried first</p>
<ul className="list-disc space-y-1 pl-5 text-sm [overflow-wrap:anywhere]">
{tf.tried.map((t) => (
<li key={t}>
<InlineMarkdown>{t}</InlineMarkdown>
</li>
))}
</ul>
</>
)}
</div>
</OutcomeCard>
);
} 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>
)}
{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}
</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>
);
} else if (run.status === "failed") {
outcome = (
<Problem
Expand Down
11 changes: 11 additions & 0 deletions dashboard/src/app/runs/detail/run-questions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ export function RunQuestions({
{q.question}
</p>
{q.why && <p className="mt-1 text-zinc-400 [overflow-wrap:anywhere]" data-testid="run-question-why">{q.why}</p>}
{!!q.evidence?.length && (
<p className="mt-1 text-sm text-zinc-400 [overflow-wrap:anywhere]" data-testid="run-question-evidence">
Evidence:{" "}
{q.evidence.map((e, j) => (
<span key={e}>
{j > 0 && ", "}
<code className="rounded bg-zinc-800 px-1 py-0.5 text-xs text-zinc-200">{e}</code>
</span>
))}
</p>
)}
{canAnswer && (
<div className="mt-3">
<label htmlFor={boxId} className="mb-1 block text-sm font-medium text-zinc-200">
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/run-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const LOOKS: Record<string, RunLook> = {
needs_input: { label: "Needs your answer", tone: "waiting", group: "waiting" },
// The code works as designed; the fix is a change in another system's data or settings.
needs_outside_change: { label: "Needs a change outside the code", tone: "attention", group: "waiting" },
// An open pull request (anyone's) already does the work; the run linked it and built no second fix.
covered_by_pr: { label: "Covered by an open PR", tone: "muted", group: "done" },
completed: { label: "Done", tone: "success", group: "done" },
merged: { label: "Merged", tone: "merged", group: "done" },
failed: { label: "Failed", tone: "danger", group: "failed" },
Expand All @@ -32,7 +34,7 @@ const LOOKS: Record<string, RunLook> = {
export const RUN_GROUP_STATUSES: Record<"active" | "waiting" | "done" | "failed" | "closed", string> = {
active: "pending,queued,running",
waiting: "awaiting_ci,needs_input,needs_outside_change",
done: "completed,success,merged",
done: "completed,success,merged,covered_by_pr",
failed: "failed,cancelled",
closed: "closed",
};
Expand Down
25 changes: 25 additions & 0 deletions dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,12 @@ export interface RunDetail extends Run {
fix_location?: string | null;
/** Markdown report when the fix is (partly) a change outside the code. */
outside_change_report?: string | null;
/** `tooling` when the run stopped on its own environment (a command failed for want of a dependency or tool), not a question. */
stop_kind?: string | null;
/** For a tooling failure: the exact command, the error it printed and what the run tried first. */
tooling_failure?: RunToolingFailure | null;
/** For a `covered_by_pr` run: the open pull request that already does the work, and why. */
covered_by?: RunCoveredBy | null;
/** The lesson saved for the repository when people said the fix was elsewhere. */
lesson?: string | null;
/** Who closed the run on purpose (their name, login or email), when and why. */
Expand Down Expand Up @@ -1961,6 +1967,25 @@ export interface RunQuestion {
suggestions?: string[];
/** Set when the question is a choice Coderhelm records on the ticket (e.g. an open pull request: work on it, or open its own). */
decision?: string | null;
/** The evidence the question cites: a `path:line` in the code or a lookup the run made. */
evidence?: string[];
}

/** A command the run itself ran that failed for want of a dependency or tool. */
export interface RunToolingFailure {
command: string;
error: string;
tried?: string[];
}

/** The open pull request that already does a run's work. */
export interface RunCoveredBy {
repo: string;
number: number;
url?: string;
title?: string;
author?: string;
reason?: string;
}

/** An answer given in Coderhelm to a run's question. */
Expand Down
8 changes: 5 additions & 3 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 = "a24df100f84bb755cfe15a3dc7f1e1a62fdeb7fb";
export const OPENAPI_REF = "d4eb86838dabe04a3d9fa0096bf7a17dcb6e54de";

/** The fields each public API schema has. */
export interface OpenApiFields {
Expand Down Expand Up @@ -56,13 +56,15 @@ export interface OpenApiFields {
RotateBody: "overlap_hours";
RotatedSecret: "previous_secret_expires_at" | "secret";
RoundIncomplete: "at" | "can_resume" | "files" | "kind" | "number" | "pushed" | "reason" | "summary" | "wip_branch";
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" | "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" | "ticket_id" | "ticket_source" | "title" | "tokens_in" | "tokens_out" | "trigger" | "updated_at";
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";
RunNote: "message" | "timestamp";
RunPass: "pass" | "started_at";
RunQuestion: "decision" | "id" | "question" | "suggestions" | "why";
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";
RunToolingFailure: "command" | "error" | "tried";
RunTrigger: "by" | "kind" | "label" | "ref" | "ref_url";
RunsPage: "next" | "runs" | "scanned";
SecretView: "previous_secret_expires_at" | "secret";
Expand Down
Loading