Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

29q deny-reason-inbox-guard: Inbox reason test, room at 320, Say why open state (#845)

Oleksandr Ivanchenkobdb845d87753
diff --git a/frontend/src/components/InboxNew.tsx b/frontend/src/components/InboxNew.tsx
index 44916d53..b9be394d 100644
--- a/frontend/src/components/InboxNew.tsx
+++ b/frontend/src/components/InboxNew.tsx
@@ -353,8 +353,8 @@ const QueueRow: React.FC<RowProps> = ({ item, selected, focusable, wide, busy, o
)}
{item.kind === 'approval' && (
- <div className="px-3 pb-1 pl-[54px] [&>div]:my-0 [&>div]:mb-2">
- <ModernApprovalCard approval={approvalFromAway(item as AwayItem)} disabled={disabled} onResolve={(_, d, opts) => onResolve(item, d as ApprovalDecision, opts?.withoutBackup, opts?.reason)} />
+ <div className="px-3 pb-1 sm:pl-[54px] [&>div]:my-0 [&>div]:mb-2">
+ <ModernApprovalCard approval={approvalFromAway(item as AwayItem)} disabled={disabled} stackWhy onResolve={(_, d, opts) => onResolve(item, d as ApprovalDecision, opts?.withoutBackup, opts?.reason)} />
</div>
)}
diff --git a/frontend/src/components/ModernApprovalCard.tsx b/frontend/src/components/ModernApprovalCard.tsx
index 6d30516f..80aad33e 100644
--- a/frontend/src/components/ModernApprovalCard.tsx
+++ b/frontend/src/components/ModernApprovalCard.tsx
@@ -36,6 +36,8 @@ interface ModernApprovalCardProps {
/** Floor card only (22f): saves the backup command / re-reads the backup state; tests and the rig fake them. */
onSetCommand?: (spaceId: string, command: string) => Promise<void>;
onLoadBackup?: (spaceId: string) => Promise<FloorBackup | null>;
+ /** 29q: the Say why field stacks (field, then a full-width button) at every width, for a narrow column like the Inbox list. */
+ stackWhy?: boolean;
}
/** Server/tool/arguments of an MCP approval, or null for other tools. */
@@ -273,7 +275,7 @@ const SECONDARY =
* <bot>". Its own component so the card itself keeps no state. Fragment children of the action row: the form
* takes a whole line of its own (basis-full) on a wide screen and comes last on a phone.
*/
-const SayWhy: React.FC<{ botName: string | null; disabled: boolean; onDeny: (reason: string) => void }> = ({ botName, disabled, onDeny }) => {
+const SayWhy: React.FC<{ botName: string | null; disabled: boolean; stack?: boolean; onDeny: (reason: string) => void }> = ({ botName, disabled, stack = false, onDeny }) => {
// null while closed, else the reason typed so far.
const [why, setWhy] = useState<string | null>(null);
const id = useId();
@@ -289,7 +291,7 @@ const SayWhy: React.FC<{ botName: string | null; disabled: boolean; onDeny: (rea
aria-controls={id}
onClick={() => setWhy((w) => (w === null ? '' : null))}
data-approval-say-why=""
- className="self-start sm:self-auto sm:mr-auto -ml-2 sm:ml-0 inline-flex items-center gap-1.5 min-h-[44px] sm:min-h-[32px] px-2 rounded-lg text-sm text-[#a39dcc] hover:text-zinc-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#b8adff] disabled:opacity-50 disabled:cursor-not-allowed"
+ className={`self-start sm:self-auto sm:mr-auto -ml-2 sm:ml-0 inline-flex items-center gap-1.5 min-h-[44px] sm:min-h-[32px] px-2 rounded-lg text-sm ${why === null ? 'text-[#a39dcc]' : 'text-zinc-100'} hover:text-zinc-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#b8adff] disabled:opacity-50 disabled:cursor-not-allowed`}
>
<MessageSquare size={14} aria-hidden="true" />
<span>Say why</span>
@@ -298,7 +300,7 @@ const SayWhy: React.FC<{ botName: string | null; disabled: boolean; onDeny: (rea
<form
id={id}
data-approval-why=""
- className="sm:basis-full flex flex-col gap-2 sm:flex-row sm:items-center"
+ className={`sm:basis-full flex flex-col gap-2 ${stack ? '' : 'sm:flex-row sm:items-center'}`}
onSubmit={(e) => {
e.preventDefault();
onDeny(why);
@@ -322,9 +324,9 @@ const SayWhy: React.FC<{ botName: string | null; disabled: boolean; onDeny: (rea
placeholder="What should it do instead?"
enterKeyHint="send"
autoComplete="off"
- className="min-w-0 w-full sm:flex-1 min-h-[44px] sm:min-h-[36px] px-3 rounded-lg border border-[#3f3868] bg-zinc-950/70 text-base sm:text-sm text-[#ecebfa] placeholder:text-[#a39dcc] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#b8adff] disabled:opacity-50"
+ className={`min-w-0 w-full ${stack ? '' : 'sm:flex-1'} min-h-[44px] sm:min-h-[36px] px-3 rounded-lg border border-[#3f3868] bg-zinc-950/70 text-base sm:text-sm text-[#ecebfa] placeholder:text-[#a39dcc] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#b8adff] disabled:opacity-50`}
/>
- <button type="submit" disabled={disabled} data-approval-deny-why="" className={`${SECONDARY} w-full sm:w-auto sm:max-w-[50%] min-w-0`}>
+ <button type="submit" disabled={disabled} data-approval-deny-why="" className={`${SECONDARY} w-full ${stack ? '' : 'sm:w-auto sm:max-w-[50%]'} min-w-0`}>
<X size={14} aria-hidden="true" className="shrink-0" />
<span className="min-w-0 break-words [overflow-wrap:anywhere] text-left">Deny and tell {tellWho}</span>
</button>
@@ -344,6 +346,7 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
onBackup,
onSetCommand,
onLoadBackup,
+ stackWhy = false,
}) => {
// Dev mode's production floor has its own card: blast radius, backup row, and never "always allow".
const floor = parseProdFloor(approval.details);
@@ -606,7 +609,7 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
)}
</div>
{/* 29p: quiet, next to Deny (left of it on a wide screen, under the buttons on a phone). Deny itself stays one tap. */}
- {offerWhy && <SayWhy botName={botName} disabled={disabled} onDeny={denyWithReason} />}
+ {offerWhy && <SayWhy botName={botName} disabled={disabled} stack={stackWhy} onDeny={denyWithReason} />}
</div>
</div>
);
diff --git a/frontend/tests/denyReasonInbox.test.mjs b/frontend/tests/denyReasonInbox.test.mjs
new file mode 100644
index 00000000..8e8affb9
--- /dev/null
+++ b/frontend/tests/denyReasonInbox.test.mjs
@@ -0,0 +1,147 @@
+// 29q deny-reason-inbox-guard (Iris): the Inbox's own approval card carries a Say why reason to the server.
+// Mounts the real InboxNew (no stubbed onResolve) and reads the POST body it sends. Guards InboxNew's QueueRow
+// passing `opts?.reason` on: without it, an Inbox Deny with words would reach the bot as a plain no.
+process.env.TZ = 'UTC';
+import assert from 'node:assert/strict';
+import test, { afterEach } from 'node:test';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/inbox', pretendToBeVisual: true });
+const g = globalThis;
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'HTMLButtonElement', 'HTMLTextAreaElement', 'HTMLInputElement', 'Element', 'Node', 'Event', 'CustomEvent', 'MouseEvent', 'KeyboardEvent', 'FocusEvent', 'DOMParser', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'localStorage', 'sessionStorage']) {
+ if (!(k in dom.window)) continue;
+ Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });
+}
+g.window.matchMedia ??= () => ({ matches: false, addEventListener() {}, removeEventListener() {} });
+g.IS_REACT_ACT_ENVIRONMENT = false;
+
+// Every request the Inbox makes: [method, url, parsed body or null].
+let sent = [];
+g.fetch = async (url, init = {}) => {
+ sent.push([init.method ?? 'GET', String(url), init.body ? JSON.parse(init.body) : null]);
+ return { ok: true, status: 200, json: async () => ({}) };
+};
+
+const m = await loadBundled(`
+ export { default as React } from 'react';
+ export { createRoot } from 'react-dom/client';
+ export * as fx from './src/doneAwayFixture';
+ export * as store from './src/inboxStore';
+ export { InboxNew } from './src/components/InboxNew';
+ export { ModernApprovalCard } from './src/components/ModernApprovalCard';
+`);
+const { React, createRoot, fx, store: s } = m;
+const h = React.createElement;
+const settle = async (n = 20) => {
+ for (let i = 0; i < n; i++) await new Promise((r) => setTimeout(r, 0));
+};
+const clone = (x) => JSON.parse(JSON.stringify(x));
+const click = async (b) => {
+ b.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ await settle();
+};
+// A controlled React input: set the DOM value past React's tracker, then fire `input`.
+const type = async (input, text) => {
+ Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set.call(input, text);
+ input.dispatchEvent(new window.Event('input', { bubbles: true }));
+ await settle();
+};
+// Enter in the field: the browser submits its form.
+const enter = async (input) => {
+ input.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }));
+ input.form.dispatchEvent(new window.Event('submit', { bubbles: true, cancelable: true }));
+ await settle();
+};
+
+let root = null;
+afterEach(() => {
+ root?.unmount();
+ root = null;
+ document.body.innerHTML = '';
+});
+
+async function mountInbox(wide) {
+ const data = clone(fx.AWAY_INBOX);
+ document.body.innerHTML = '';
+ sessionStorage.clear();
+ window.history.replaceState(null, '', '/inbox');
+ s.inboxStore.reset();
+ s.inboxSource.get = async () => data;
+ s.inboxStore.patch({ data });
+ const el = document.createElement('div');
+ document.body.appendChild(el);
+ root = createRoot(el);
+ root.render(h(m.InboxNew, { onOpen: () => {}, noLoad: true, wide, now: Date.parse(data.now), placeName: fx.awayPlaceName }));
+ await settle();
+ sent = [];
+ const row = el.querySelector('[data-row="ap-1"]');
+ assert.ok(row, 'the Inbox shows the approval row');
+ return row;
+}
+const resolves = () => sent.filter(([method, url]) => method === 'POST' && url === '/api/approvals/ap-1/resolve');
+const denyBtn = (row) => [...row.querySelectorAll('[data-approval-actions] button')].find((b) => b.textContent.trim() === 'Deny');
+
+for (const wide of [true, false]) {
+ const where = wide ? 'wide' : 'phone';
+
+ test(`29q (${where}): an Inbox Deny with words sends them as reason`, async () => {
+ const row = await mountInbox(wide);
+ await click(row.querySelector('[data-approval-say-why]'));
+ const input = row.querySelector('[data-approval-why] input');
+ assert.ok(input, 'Say why opens the field in the Inbox card');
+ await type(input, ' Use the staging list ');
+ await enter(input);
+ assert.deepEqual(resolves().map(([, , body]) => body), [{ decision: 'deny', reason: 'Use the staging list' }]);
+ });
+
+ test(`29q (${where}): a plain one-tap Inbox Deny sends no reason`, async () => {
+ const row = await mountInbox(wide);
+ await click(denyBtn(row));
+ const bodies = resolves().map(([, , body]) => body);
+ assert.deepEqual(bodies, [{ decision: 'deny' }]);
+ assert.equal('reason' in bodies[0], false);
+ });
+}
+
+test('29q: Say why looks open while its field is open, and quiet again once closed', async () => {
+ const row = await mountInbox(true);
+ const btn = row.querySelector('[data-approval-say-why]');
+ const look = () => ({ open: btn.classList.contains('text-zinc-100'), quiet: btn.classList.contains('text-[#a39dcc]'), expanded: btn.getAttribute('aria-expanded') });
+ assert.deepEqual(look(), { open: false, quiet: true, expanded: 'false' });
+ await click(btn);
+ assert.deepEqual(look(), { open: true, quiet: false, expanded: 'true' });
+ await click(btn);
+ assert.deepEqual(look(), { open: false, quiet: true, expanded: 'false' });
+});
+
+test('29q: the Inbox approval card keeps the 54 px indent from sm up only, so a phone field has room', async () => {
+ const row = await mountInbox(false);
+ const wrap = row.querySelector('[data-approval-actions]').closest('li > div');
+ const cls = wrap.className.split(/\s+/);
+ assert.ok(cls.includes('sm:pl-[54px]'));
+ assert.equal(cls.includes('pl-[54px]'), false, 'no 54 px indent below sm');
+});
+
+test('29q: in the Inbox list the Say why field stacks at every width; the chat card keeps its one-line row from sm up', async () => {
+ const row = await mountInbox(true);
+ await click(row.querySelector('[data-approval-say-why]'));
+ const form = row.querySelector('[data-approval-why]');
+ const has = (el, c) => el.className.split(/\s+/).includes(c);
+ assert.equal(has(form, 'sm:flex-row'), false, 'Inbox: no side-by-side field and button');
+ assert.equal(has(form.querySelector('input'), 'sm:flex-1'), false);
+ assert.equal(has(form.querySelector('[data-approval-deny-why]'), 'sm:w-auto'), false, 'Inbox: the button stays full width');
+ // The chat card (no stackWhy) is unchanged.
+ const { ModernApprovalCard } = m;
+ const el = document.createElement('div');
+ document.body.appendChild(el);
+ const r2 = createRoot(el);
+ r2.render(h(ModernApprovalCard, { approval: { id: 'ap9', tool_name: 'mcp__github__create_pull_request', details: { source: 'mcp', server: 'github', tool: 'create_pull_request', kwant_name: 'TechLead', arguments: { repo: 'acme/site' } } }, onResolve: () => {} }));
+ await settle();
+ await click(el.querySelector('[data-approval-say-why]'));
+ const f2 = el.querySelector('[data-approval-why]');
+ assert.ok(has(f2, 'sm:flex-row'));
+ assert.ok(has(f2.querySelector('input'), 'sm:flex-1'));
+ assert.ok(has(f2.querySelector('[data-approval-deny-why]'), 'sm:w-auto'));
+ r2.unmount();
+});