Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Require explicit approval confirmation

yxlyx2767984692ae
diff --git a/apps/native/app/visual-tests/approval/fixture.tsx b/apps/native/app/visual-tests/approval/fixture.tsx
new file mode 100644
index 00000000..70432b07
--- /dev/null
+++ b/apps/native/app/visual-tests/approval/fixture.tsx
@@ -0,0 +1,94 @@
+"use client";
+
+import { useState } from "react";
+import ApprovalCard from "@/components/primitives/ApprovalCard";
+import { AssistantBody } from "@/components/site/ChatBubbles";
+import { emptyTurn, type AssistantTurn } from "@/lib/acp";
+
+function askTurn(): AssistantTurn {
+ return {
+ ...emptyTurn(),
+ status: "ask",
+ ask: {
+ callId: "approval-fixture",
+ question: "Which flavor should we ship?",
+ options: ["Pistachio", "Mint", "Vanilla"],
+ },
+ };
+}
+
+const multiQuestions = [
+ { q: "Which market should launch first?", type: "radio" as const, options: ["Retail", "Online"] },
+ { q: "Which colors should be included?", type: "check" as const, options: ["Red", "Blue", "Green"] },
+];
+
+export default function ApprovalFixture() {
+ const [singleKey, setSingleKey] = useState(0);
+ const [singleSubmissions, setSingleSubmissions] = useState<string[]>([]);
+ const [singleCancellations, setSingleCancellations] = useState(0);
+ const [multiKey, setMultiKey] = useState(0);
+ const [multiSubmissions, setMultiSubmissions] = useState<string[][]>([]);
+
+ return (
+ <main className="min-h-screen bg-page p-8 text-ink">
+ <div className="mx-auto grid max-w-[900px] gap-10 md:grid-cols-2">
+ <section aria-label="Single-question approval" className="space-y-4">
+ <div className="flex items-center justify-between gap-3">
+ <h1 className="text-lg font-semibold">Single-question ask</h1>
+ <button
+ type="button"
+ onClick={() => {
+ setSingleKey((key) => key + 1);
+ setSingleSubmissions([]);
+ setSingleCancellations(0);
+ }}
+ className="rounded bg-field px-3 py-1.5 text-xs"
+ >
+ Reset single approval
+ </button>
+ </div>
+ <AssistantBody
+ key={singleKey}
+ turn={askTurn()}
+ following={false}
+ onAnswer={(text, cancelled) => {
+ if (cancelled) setSingleCancellations((count) => count + 1);
+ else setSingleSubmissions((answers) => [...answers, text]);
+ }}
+ />
+ <output aria-label="Single submissions" className="block font-mono text-xs">
+ {JSON.stringify(singleSubmissions)}
+ </output>
+ <output aria-label="Single cancellations" className="block font-mono text-xs">
+ {singleCancellations}
+ </output>
+ </section>
+
+ <section aria-label="Multi-question approval" className="space-y-4">
+ <div className="flex items-center justify-between gap-3">
+ <h1 className="text-lg font-semibold">Multi-question approval</h1>
+ <button
+ type="button"
+ onClick={() => {
+ setMultiKey((key) => key + 1);
+ setMultiSubmissions([]);
+ }}
+ className="rounded bg-field px-3 py-1.5 text-xs"
+ >
+ Reset multi approval
+ </button>
+ </div>
+ <ApprovalCard
+ key={multiKey}
+ questions={multiQuestions}
+ resettable={false}
+ onSubmitted={(answers) => setMultiSubmissions((all) => [...all, answers ?? []])}
+ />
+ <output aria-label="Multi submissions" className="block font-mono text-xs">
+ {JSON.stringify(multiSubmissions)}
+ </output>
+ </section>
+ </div>
+ </main>
+ );
+}
diff --git a/apps/native/app/visual-tests/approval/page.tsx b/apps/native/app/visual-tests/approval/page.tsx
new file mode 100644
index 00000000..d3cf6e70
--- /dev/null
+++ b/apps/native/app/visual-tests/approval/page.tsx
@@ -0,0 +1,9 @@
+import { notFound } from "next/navigation";
+import ApprovalFixture from "./fixture";
+
+export const dynamic = "force-dynamic";
+
+export default function ApprovalVisualTest() {
+ if (process.env.GRAFF_VISUAL_TESTS !== "1") notFound();
+ return <ApprovalFixture />;
+}
diff --git a/apps/native/components/primitives/ApprovalCard.tsx b/apps/native/components/primitives/ApprovalCard.tsx
index 70f9fe68..99231c5c 100644
--- a/apps/native/components/primitives/ApprovalCard.tsx
+++ b/apps/native/components/primitives/ApprovalCard.tsx
@@ -10,7 +10,7 @@ import GlideMenu from "@/components/primitives/GlideMenu";
* move between questions (the card's height animates to fit),
* the step counter rolls like an odometer, and the footer uses
* pill actions — a quiet Skip and a dark Continue with a ⏎.
- * Single-choice answers auto-advance; multi-select waits.
+ * Every answer waits for an explicit Continue, Send, or Enter confirmation.
* ───────────────────────────────────────────────────────── */
const DEFAULT_QUESTIONS = [
@@ -142,7 +142,7 @@ export default function ApprovalCard({
const [sent, setSent] = useState(false);
const [open, setOpen] = useState(true);
- const advanceTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const submittedRef = useRef(false);
const questionRefs = useRef<(HTMLDivElement | null)[]>([]);
const measured = useRef(false);
const [viewportH, setViewportH] = useState<number | undefined>(undefined);
@@ -175,15 +175,13 @@ export default function ApprovalCard({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [qi]);
- useEffect(() => () => { if (advanceTimer.current) clearTimeout(advanceTimer.current); }, []);
-
const goTo = (next: number) => {
- if (advanceTimer.current) clearTimeout(advanceTimer.current);
setQi(Math.min(Math.max(next, 0), QUESTIONS.length - 1));
};
const send = () => {
- if (advanceTimer.current) clearTimeout(advanceTimer.current);
+ if (submittedRef.current) return;
+ submittedRef.current = true;
setSent(true);
const collected = QUESTIONS.map((question, qIdx) => {
const customText = custom[qIdx]?.trim();
@@ -210,20 +208,14 @@ export default function ApprovalCard({
: [...picked, index];
return { ...current, [qi]: next };
});
- if (type === "radio") {
- setCustom((current) => ({ ...current, [qi]: "" }));
- if (advanceTimer.current) clearTimeout(advanceTimer.current);
- advanceTimer.current = setTimeout(() => {
- if (last) send();
- else setQi((current) => Math.min(QUESTIONS.length - 1, current + 1));
- }, 480);
- }
+ if (type === "radio") setCustom((current) => ({ ...current, [qi]: "" }));
};
const reset = () => {
setQi(0);
setAnswers({});
setCustom({});
+ submittedRef.current = false;
setSent(false);
setOpen(true);
measured.current = false;
@@ -310,6 +302,12 @@ export default function ApprovalCard({
aria-pressed={on}
tabIndex={active ? 0 : -1}
onClick={() => { if (active) toggle(i); }}
+ onKeyDown={(event) => {
+ if (event.key === "Enter" && question.type === "radio" && on) {
+ event.preventDefault();
+ advance();
+ }
+ }}
className="relative z-10 flex items-center gap-1.5 rounded-control pl-1 pr-2 py-1 text-left transition-colors duration-100"
>
<span
diff --git a/apps/native/e2e/approval-card.pw.ts b/apps/native/e2e/approval-card.pw.ts
new file mode 100644
index 00000000..c2b99f79
--- /dev/null
+++ b/apps/native/e2e/approval-card.pw.ts
@@ -0,0 +1,93 @@
+import { expect, test } from "@playwright/test";
+
+const oldAutoSubmitDelay = 480;
+
+test.beforeEach(async ({ page }) => {
+ await page.goto("/visual-tests/approval");
+});
+
+test("a radio click waits for Send, submits the latest selection once, and ignores repeated activation", async ({ page }) => {
+ const card = page.getByRole("region", { name: "Single-question approval" });
+ const submissions = card.getByLabel("Single submissions");
+ const pistachio = card.getByRole("button", { name: "Pistachio" });
+ const mint = card.getByRole("button", { name: "Mint" });
+
+ await pistachio.click();
+ await expect(pistachio).toHaveAttribute("aria-pressed", "true");
+ await page.waitForTimeout(oldAutoSubmitDelay + 150);
+ await expect(submissions).toHaveText("[]");
+ await expect(card.getByText("Which flavor should we ship?")).toBeVisible();
+
+ await mint.click();
+ await expect(pistachio).toHaveAttribute("aria-pressed", "false");
+ await expect(mint).toHaveAttribute("aria-pressed", "true");
+ await card.getByRole("button", { name: "Send" }).evaluate((button) => {
+ button.click();
+ button.click();
+ });
+
+ await expect(submissions).toHaveText(JSON.stringify(["Mint"]));
+ await expect(card.getByText("Answers sent")).toBeVisible();
+});
+
+test("Enter selects first, then explicitly submits the selected radio answer", async ({ page }) => {
+ const card = page.getByRole("region", { name: "Single-question approval" });
+ const mint = card.getByRole("button", { name: "Mint" });
+ const submissions = card.getByLabel("Single submissions");
+
+ await mint.focus();
+ await mint.press("Enter");
+ await expect(mint).toHaveAttribute("aria-pressed", "true");
+ await expect(submissions).toHaveText("[]");
+
+ await mint.press("Enter");
+ await expect(submissions).toHaveText(JSON.stringify(["Mint"]));
+ await expect(card.getByText("Answers sent")).toBeVisible();
+});
+
+test("custom answers submit on Enter and selecting an option clears the custom value", async ({ page }) => {
+ const card = page.getByRole("region", { name: "Single-question approval" });
+ const custom = card.getByRole("textbox", { name: "Custom answer" });
+ const submissions = card.getByLabel("Single submissions");
+
+ await custom.fill("Seasonal special");
+ await custom.press("Enter");
+ await expect(submissions).toHaveText(JSON.stringify(["Seasonal special"]));
+
+ await card.getByRole("button", { name: "Reset single approval" }).click();
+ const resetCustom = card.getByRole("textbox", { name: "Custom answer" });
+ await resetCustom.fill("Replace me");
+ await card.getByRole("button", { name: "Vanilla" }).click();
+ await expect(resetCustom).toHaveValue("");
+ await card.getByRole("button", { name: "Send" }).click();
+ await expect(card.getByLabel("Single submissions")).toHaveText(JSON.stringify(["Vanilla"]));
+});
+
+test("dismissing after selection cancels once and never submits later", async ({ page }) => {
+ const card = page.getByRole("region", { name: "Single-question approval" });
+
+ await card.getByRole("button", { name: "Pistachio" }).click();
+ await card.getByRole("button", { name: "Dismiss" }).click();
+ await expect(card.getByLabel("Single cancellations")).toHaveText("1");
+ await page.waitForTimeout(oldAutoSubmitDelay + 150);
+ await expect(card.getByLabel("Single submissions")).toHaveText("[]");
+});
+
+test("multi-question radio and checkbox answers require explicit progression", async ({ page }) => {
+ const card = page.getByRole("region", { name: "Multi-question approval" });
+ const submissions = card.getByLabel("Multi submissions");
+
+ await card.getByRole("button", { name: "Online" }).click();
+ await page.waitForTimeout(oldAutoSubmitDelay + 150);
+ await expect(card.getByText("Which market should launch first?")).toBeVisible();
+ await expect(submissions).toHaveText("[]");
+
+ await card.getByRole("button", { name: "Continue" }).click();
+ await expect(card.getByText("Which colors should be included?")).toBeVisible();
+ await card.getByRole("button", { name: "Red" }).click();
+ await card.getByRole("button", { name: "Blue" }).click();
+ await card.getByRole("button", { name: "Red" }).click();
+ await card.getByRole("button", { name: "Send" }).click();
+
+ await expect(submissions).toHaveText(JSON.stringify([["Online", "Blue"]]));
+});
diff --git a/apps/native/playwright.queue.config.ts b/apps/native/playwright.queue.config.ts
index be641e23..2101631b 100644
--- a/apps/native/playwright.queue.config.ts
+++ b/apps/native/playwright.queue.config.ts
@@ -1,6 +1,6 @@
import { defineConfig } from "@playwright/test";
export default defineConfig({
- testDir: "./e2e", testMatch: "queue.pw.ts", workers: 1,
+ testDir: "./e2e", testMatch: ["queue.pw.ts", "approval-card.pw.ts"], workers: 1,
use: { baseURL: "http://127.0.0.1:3021", headless: true },
webServer: {
command: "GRAFF_VISUAL_TESTS=1 GRAFF_DESKTOP_TOKEN= bunx next dev --port 3021 --hostname 127.0.0.1",