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.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
0.7 Dev desk wire: Iris's cards in the desk, Open review, N3, backup focus (Pixel) (#321)
Oleksandr Ivanchenkocbcda15a9d12
diff --git a/frontend/src/components/DevDesk.tsx b/frontend/src/components/DevDesk.tsxindex 3486fc5e..86e63e22 100644--- a/frontend/src/components/DevDesk.tsx+++ b/frontend/src/components/DevDesk.tsx@@ -1,6 +1,6 @@// The Dev desk: a row pinned at the top of the sidebar in a Dev space, and its page with two tabs,// What landed and Reviews. The page fetches plan §3.2's routes, updates live on the `dev_card`-// SSE (App re-sends it as DEV_CARD_EVENT) and mounts Iris's renderers through DevDeskSlots.+// SSE (App re-sends it as DEV_CARD_EVENT) and mounts Iris's cards (#314) through DevDeskSlots.import React, { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore } from 'react';import { ChevronLeft, Code, Loader2, RefreshCw } from 'lucide-react';@@ -153,7 +153,33 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, spaceName, onconst [actionError, setActionError] = useState<string | null>(null);const tabsId = useId();const tabRefs = useRef<Array<HTMLButtonElement | null>>([]);+ const panelRef = useRef<HTMLDivElement>(null);const notesId = notes?.id ?? null;+ // "Open review" on a landed card: the PR whose review card gets scrolled to and focused once the+ // Reviews tab has rendered.+ const [openPr, setOpenPr] = useState<number | null>(null);++ const openReview = useCallback((pr: number) => {+ setTab('reviews');+ setOpenPr(pr);+ }, []);++ useEffect(() => {+ if (openPr === null || tab !== 'reviews') return;+ const panel = panelRef.current;+ const card = panel?.querySelector<HTMLElement>(`[data-dev-card="review"][data-pr="${openPr}"]`);+ const heading = card?.querySelector<HTMLElement>('h3');+ setOpenPr(null);+ if (!card || !heading) {+ // Not on the desk (closed since, or not reviewed yet): focus the Reviews tab so the move is still visible.+ tabRefs.current[1]?.focus();+ return;+ }+ if (!heading.hasAttribute('tabindex')) heading.setAttribute('tabindex', '-1');+ const reduce = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;+ card.scrollIntoView?.({ block: 'start', behavior: reduce ? 'auto' : 'smooth' });+ heading.focus({ preventScroll: true });+ }, [openPr, tab, desk.reviews]);// The release-notes draft: 202 gives the pending card; its ready card comes after the SSE.useEffect(() => {@@ -312,7 +338,7 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, spaceName, on</div>)}- <div role="tabpanel" id={`${tabsId}-panel`} aria-labelledby={`${tabsId}-${tab}`} className="space-y-3">+ <div ref={panelRef} role="tabpanel" id={`${tabsId}-panel`} aria-labelledby={`${tabsId}-${tab}`} className="space-y-3">{first && desk.loading ? (<p className="flex items-center gap-2 py-8 justify-center text-meta text-zinc-400" data-dev-loading><Loader2 size={14} className="animate-spin motion-reduce:animate-none" aria-hidden="true" />@@ -325,13 +351,16 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, spaceName, onrollup={landed.rollup}last_tag={landed.last_tag}last_merge={lastMerge}+ cards={landedCards}+ branch={dev?.branch || 'main'}onMarkSeen={markSeen}onDraftNotes={draftNotes}drafting={!!notes && notes.status === 'pending'}+ marking={marking}/>)}{landedCards.length ? (- <LandedList cards={landedCards} reviews={reviews} now={now} />+ <LandedList cards={landedCards} reviews={reviews} now={now} onOpenReview={openReview} />) : (landed && (<Empty title="Nothing has landed yet" line="Each merge to main shows up here as a short card in plain words. kwant checks every 5 minutes." />diff --git a/frontend/src/components/DevDeskSlots.tsx b/frontend/src/components/DevDeskSlots.tsxindex 133ad5f7..3dea55f0 100644--- a/frontend/src/components/DevDeskSlots.tsx+++ b/frontend/src/components/DevDeskSlots.tsx@@ -1,26 +1,36 @@-// Where the Dev desk mounts Iris's renderers (components/dev/{Rollup,LandedList,ReviewCard,ReleaseNotesSheet}).-// Until hers land on main these are thin placeholders with the props in iris-dev-cards `dev/types.ts`-// (11c6d23), so the shell, its fetching and its live updates can be built and tested now. Swapping-// them is this one file: import hers and parse each card with her parse* first.+// Where the Dev desk mounts Iris's renderers (components/dev/, #314). The shell fetches and caches loose+// `ShellCard`s; this file parses each one with her parse* (dev/types.ts) and draws her card, or her plain+// `CardFallback` when a card has a shape her renderer can't draw honestly.-import React from 'react';-import { GitMerge, GitPullRequest, Loader2, X } from 'lucide-react';+import React, { useMemo } from 'react';import type { FindingAction, LandedRollup, ShellCard } from '../dev/shellTypes';-import { withDayLabels } from '../devMode';+import { parseLanded, parseReleaseNotes, parseReview } from '../dev/types';+import type { LandedCard as Landed, ReviewCard as Review } from '../dev/types';+import { needsYouAreas } from '../dev/logic';+import { CardFallback } from './dev/parts';+import { LandedList as IrisLandedList } from './dev/LandedCard';+import { ReviewCard as IrisReviewCard } from './dev/ReviewCard';+import { Rollup as IrisRollup } from './dev/Rollup';+import { ReleaseNotesSheet as IrisReleaseNotesSheet } from './dev/ReleaseNotesSheet';export interface RollupProps {rollup: LandedRollup;last_tag: string | null;last_merge: { pr: number; merged_at: string | null } | null;+ /** The landed cards on screen, for the tiles' warn border. */+ cards?: ShellCard[];+ branch?: string;onDraftNotes: () => void;onMarkSeen: () => void;drafting?: boolean;+ marking?: boolean;}export interface LandedListProps {cards: ShellCard[];reviews: ShellCard[];now?: number;+ onOpenReview?: (pr: number) => void;}export interface ReviewCardProps {@@ -37,85 +47,43 @@ export interface ReleaseNotesSheetProps {onClose: () => void;}-const cardBox = 'rounded-2xl border border-hairline bg-surface-raised px-4 py-3';-const ghost =- 'inline-flex items-center gap-1.5 rounded-xl border border-hairline-strong px-3 py-1.5 text-meta font-medium text-zinc-200 hover:bg-zinc-800 disabled:opacity-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400';+const isSome = <T,>(v: T | null): v is T => v !== null;+export const parseLandedCards = (cards: ShellCard[]): Landed[] => cards.map(parseLanded).filter(isSome);+export const parseReviewCards = (cards: ShellCard[]): Review[] => cards.map(parseReview).filter(isSome);-const text = (v: unknown): string | null => (typeof v === 'string' && v.trim() ? v : null);+export const Rollup: React.FC<RollupProps> = ({ cards = [], ...rest }) => {+ const needs = useMemo(() => needsYouAreas(parseLandedCards(cards)), [cards]);+ return <IrisRollup {...rest} needsYouAreas={needs} />;+};-export const Rollup: React.FC<RollupProps> = ({ rollup, last_tag, last_merge, onMarkSeen, onDraftNotes, drafting }) => (- <section className={cardBox} data-dev-slot="rollup" aria-label="Since you last looked">- <p className="text-body font-semibold text-zinc-50">- {rollup.count ? `${rollup.count} landed since you last looked` : 'Nothing new since you last looked'}- </p>- <p className="mt-0.5 text-meta text-zinc-400">- {rollup.areas.length ? rollup.areas.map((a) => `${a.area} ${a.count}`).join(' · ') : last_merge ? `Last merge: #${last_merge.pr}` : 'No merges yet.'}- </p>- <div className="mt-3 flex flex-wrap gap-2">- <button type="button" className={ghost} onClick={onMarkSeen} disabled={!rollup.count}>- Mark all seen- </button>- <button type="button" className={ghost} onClick={onDraftNotes} disabled={drafting}>- {drafting && <Loader2 size={12} className="animate-spin motion-reduce:animate-none" aria-hidden="true" />}- Draft release notes{last_tag ? ` since ${last_tag}` : ''}- </button>- </div>- </section>-);+export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now, onOpenReview }) => {+ const parsed = useMemo(() => parseLandedCards(cards), [cards]);+ const parsedReviews = useMemo(() => parseReviewCards(reviews), [reviews]);+ // Cards Iris's parser refuses (no PR number, wrong kind) still show, as the plain fallback row.+ const refused = useMemo(() => cards.filter((c) => parseLanded(c) === null), [cards]);+ return (+ <>+ {parsed.length > 0 && <IrisLandedList cards={parsed} reviews={parsedReviews} now={now} onOpenReview={onOpenReview} />}+ {refused.map((c) => (+ <CardFallback key={c.id} raw={c} />+ ))}+ </>+ );+};-export const LandedList: React.FC<LandedListProps> = ({ cards, now }) => (- <div className="flex flex-col gap-2" data-dev-slot="landed-list">- {withDayLabels(cards, now === undefined ? new Date() : new Date(now)).map(({ card, dayLabel }) => (- <React.Fragment key={card.id}>- {dayLabel && <h3 className="pt-2 text-2xs font-semibold uppercase tracking-wider text-zinc-500">{dayLabel}</h3>}- <article className={cardBox} data-dev-slot="landed" data-status={card.status}>- <p className="flex items-start gap-2 text-body font-medium text-zinc-100">- <GitMerge size={14} className="mt-0.5 shrink-0 text-sky-300" aria-hidden="true" />- <span className="min-w-0 break-words">{text(card.headline) ?? text(card.title) ?? `Merge ${card.id}`}</span>- </p>- <p className="mt-1 text-meta text-zinc-400">- {[card.pr ? `#${card.pr}` : null, text(card.area), card.status !== 'ready' ? card.status : null].filter(Boolean).join(' · ')}- </p>- </article>- </React.Fragment>- ))}- </div>-);+export const ReviewCard: React.FC<ReviewCardProps> = ({ card, onFinding, sample, now }) => {+ const parsed = useMemo(() => parseReview(card), [card]);+ if (!parsed) return <CardFallback raw={card} />;+ const send = async (cardId: string, findingId: string, action: FindingAction): Promise<Review> => {+ const next = parseReview(await onFinding(cardId, findingId, action));+ if (!next) throw new Error('The review came back in a shape this app doesn’t know.');+ return next;+ };+ return <IrisReviewCard card={parsed} onFinding={send} sample={sample} now={now} />;+};-export const ReviewCard: React.FC<ReviewCardProps> = ({ card }) => (- <article className={cardBox} data-dev-slot="review" data-status={card.status}>- <p className="flex items-start gap-2 text-body font-medium text-zinc-100">- <GitPullRequest size={14} className="mt-0.5 shrink-0 text-sky-300" aria-hidden="true" />- <span className="min-w-0 break-words">- {card.pr ? `#${card.pr} ` : ''}- {text(card.title) ?? 'Pull request'}- </span>- </p>- <p className="mt-1 text-meta text-zinc-400">{card.status === 'pending' ? 'Reviewing…' : card.status}</p>- </article>-);--export const ReleaseNotesSheet: React.FC<ReleaseNotesSheetProps> = ({ card, onClose, onDiscard }) => (- <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4" data-dev-slot="release-notes">- <div role="dialog" aria-modal="true" aria-label="Release notes draft" className="w-full max-w-[540px] rounded-3xl border border-hairline-strong bg-surface-raised p-6">- <div className="flex items-start justify-between gap-3">- <h2 className="text-lg font-semibold text-zinc-50">Release notes draft</h2>- <button type="button" onClick={onClose} aria-label="Close" className="p-1 rounded-lg text-zinc-400 hover:text-zinc-100">- <X size={16} aria-hidden="true" />- </button>- </div>- {card.status === 'pending' ? (- <p className="mt-3 flex items-center gap-2 text-meta text-zinc-400">- <Loader2 size={12} className="animate-spin motion-reduce:animate-none" aria-hidden="true" /> Writing the draft…- </p>- ) : (- <pre className="mt-3 max-h-[50vh] overflow-auto whitespace-pre-wrap text-meta text-zinc-300">{text(card.markdown) ?? ''}</pre>- )}- <div className="mt-4 flex justify-end gap-2">- <button type="button" className={ghost} onClick={onDiscard}>- Discard- </button>- </div>- </div>- </div>-);+export const ReleaseNotesSheet: React.FC<ReleaseNotesSheetProps> = ({ card, onSaveToNotion, onDiscard, onClose }) => {+ const parsed = useMemo(() => parseReleaseNotes(card), [card]);+ if (!parsed) return null;+ return <IrisReleaseNotesSheet card={parsed} onSaveToNotion={onSaveToNotion} onDiscard={onDiscard} onClose={onClose} />;+};diff --git a/frontend/src/components/DevModeSetup.tsx b/frontend/src/components/DevModeSetup.tsxindex 9991a600..55ee4e52 100644--- a/frontend/src/components/DevModeSetup.tsx+++ b/frontend/src/components/DevModeSetup.tsx@@ -116,7 +116,13 @@ export const DevModeSetup: React.FC<DevModeSetupProps> = ({ space, initial, onCa<label htmlFor="dv-repo" className="text-meta font-medium text-zinc-300">Repository</label>- <div className="mt-1.5 flex items-center gap-2 rounded-xl border border-hairline-strong bg-surface-main px-3 h-10 focus-within:border-sky-400/70">+ {/* N3: on phone the chip goes on its own line under the field, so the whole repo name stays readable.+ From sm up it sits inside the field, as before. */}+ <div+ className="mt-1.5 flex flex-col items-start gap-1.5 sm:flex-row sm:items-center sm:gap-2 sm:rounded-xl sm:border sm:border-hairline-strong sm:bg-surface-main sm:px-3 sm:h-10 sm:focus-within:border-sky-400/70"+ data-dv-repo-row+ >+ <div className="flex w-full min-w-0 items-center gap-2 rounded-xl border border-hairline-strong bg-surface-main px-3 h-10 focus-within:border-sky-400/70 sm:flex-1 sm:w-auto sm:rounded-none sm:border-0 sm:bg-transparent sm:px-0 sm:h-auto"><span className="font-mono text-[13px] text-zinc-500 shrink-0" aria-hidden="true">github.com/</span>@@ -137,6 +143,7 @@ export const DevModeSetup: React.FC<DevModeSetupProps> = ({ space, initial, onCaaria-invalid={field.state === 'invalid' || field.state === 'not_found' || undefined}className="min-w-0 flex-1 bg-transparent font-mono text-[13px] text-zinc-100 placeholder:text-zinc-600 outline-none"/>+ </div>{view.chip && (<span className={`kw-chip ${chipTone[view.chip.tone]} shrink-0`} data-dv-chip={field.state}>{view.chip.spinner && <Loader2 size={11} className="animate-spin motion-reduce:animate-none" aria-hidden="true" />}@@ -176,13 +183,13 @@ export const DevModeSetup: React.FC<DevModeSetupProps> = ({ space, initial, onCa<span className="text-zinc-500">None found</span>)}</Tile>- <Tile label="Production keys">+ <Tile label="Production keys" hint={!onOpenConnections && !productionCount ? 'Mark them in Connections' : undefined}><span className={productionCount ? '' : 'text-zinc-500'}>{productionCount ? `${productionCount} marked` : 'None marked'}</span>- {onOpenConnections && (+ {onOpenConnections ? (<button type="button" onClick={onOpenConnections} className="ml-1.5 text-meta font-medium text-sky-300 hover:text-sky-200">Mark</button>- )}+ ) : null}</Tile></div>)}@@ -243,9 +250,11 @@ export const DevModeSetup: React.FC<DevModeSetupProps> = ({ space, initial, onCa);};-const Tile: React.FC<{ label: string; children: React.ReactNode }> = ({ label, children }) => (+const Tile: React.FC<{ label: string; hint?: string; children: React.ReactNode }> = ({ label, hint, children }) => (<div className="rounded-xl border border-hairline bg-surface-main px-3 py-2"><p className="text-2xs font-semibold uppercase tracking-wider text-zinc-500">{label}</p><p className="mt-0.5 text-meta text-zinc-200 truncate">{children}</p>+ {/* Outside the truncated line, so it wraps in the narrow tile at 1440 instead of being cut. */}+ {hint && <p className="mt-0.5 text-meta leading-snug text-zinc-400">{hint}</p>}</div>);diff --git a/frontend/src/components/dev/ProdFloorCard.tsx b/frontend/src/components/dev/ProdFloorCard.tsxindex b7b8aa36..2ffb4478 100644--- a/frontend/src/components/dev/ProdFloorCard.tsx+++ b/frontend/src/components/dev/ProdFloorCard.tsx@@ -73,6 +73,7 @@ export const ProdFloorCard: React.FC<ProdFloorCardProps> = ({ id, floor, bot, coconst off = disabled || view.busy;const headingId = `floor-${id}-h`;const mainRef = useRef<HTMLButtonElement>(null);+ const cardRef = useRef<HTMLDivElement>(null);// `fromSecondary`: the secondary "Back up first" unmounts once the backup starts, so focus goes back to the// main button (which turns into Allow in place) when the backup is done.@@ -83,9 +84,18 @@ export const ProdFloorCard: React.FC<ProdFloorCardProps> = ({ id, floor, bot, coconst result = await onBackup(floor.space_id);send({ type: 'backup_done', result, now: Date.now() });setTick(Date.now());- if (fromSecondary) window.setTimeout(() => mainRef.current?.focus(), 0);} catch (e) {send({ type: 'backup_error', error: e instanceof Error ? e.message : 'no reason given' });+ } finally {+ // Done or failed, the secondary button is gone by now; the main button is Allow on success and+ // "Try the backup again" on failure. Bring focus there only if it was lost with the button (now on+ // <body>) or is still inside this card: never take it from the composer or anywhere else, because+ // after a good backup one Space on that button allows a production deploy.+ if (fromSecondary)+ window.setTimeout(() => {+ const a = document.activeElement;+ if (!a || a === document.body || cardRef.current?.contains(a)) mainRef.current?.focus();+ }, 0);}};@@ -106,6 +116,7 @@ export const ProdFloorCard: React.FC<ProdFloorCardProps> = ({ id, floor, bot, coreturn (<div+ ref={cardRef}data-approval-card={id}data-prod-floor={floor.kind}data-floor-case={view.case}@@ -193,7 +204,14 @@ export const ProdFloorCard: React.FC<ProdFloorCardProps> = ({ id, floor, bot, co</button>)}{view.secondaryBackup && (- <button type="button" disabled={off} onClick={() => void takeBackup(true)} className={PLAIN}>+ <button+ type="button"+ // aria-disabled, not disabled: a focused button that turns disabled drops focus to <body> for the+ // whole backup. takeBackup ignores presses while busy.+ aria-disabled={off || undefined}+ onClick={() => void takeBackup(true)}+ className={PLAIN}+ ><Database size={14} aria-hidden="true" />Back up first</button>diff --git a/frontend/src/components/dev/ReviewCard.tsx b/frontend/src/components/dev/ReviewCard.tsxindex 22f4cbf7..d1f12d55 100644--- a/frontend/src/components/dev/ReviewCard.tsx+++ b/frontend/src/components/dev/ReviewCard.tsx@@ -288,7 +288,7 @@ export const ReviewCard: React.FC<ReviewCardProps> = ({ card: given, onFinding,const sec = card.security as Review['security'] & { osv?: unknown; semgrep?: unknown };return (- <article data-dev-card="review" data-pr={card.pr} aria-labelledby={headingId} className="kw-card min-w-0 p-4">+ <article data-dev-card="review" data-pr={card.pr} aria-labelledby={headingId} className="kw-card min-w-0 scroll-mt-3 p-4">{/* 1. Header */}<header className="flex items-start gap-3"><span className={`flex h-8 w-8 shrink-0 items-center justify-center rounded-xl ${tile}`} aria-hidden="true">@@ -296,7 +296,7 @@ export const ReviewCard: React.FC<ReviewCardProps> = ({ card: given, onFinding,</span><div className="min-w-0 flex-1"><div className="flex flex-wrap items-center gap-1.5">- <h3 id={headingId} className="min-w-0 text-title font-semibold text-zinc-50 [overflow-wrap:anywhere]">+ <h3 id={headingId} className="min-w-0 rounded-sm text-title font-semibold text-zinc-50 [overflow-wrap:anywhere] focus:outline-none focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400">#{card.pr} {card.title}</h3>{card.draft && <span className="kw-chip">Draft</span>}diff --git a/frontend/tests/devDeskWire.test.mjs b/frontend/tests/devDeskWire.test.mjsnew file mode 100644index 00000000..2546ced2--- /dev/null+++ b/frontend/tests/devDeskWire.test.mjs@@ -0,0 +1,276 @@+// 0.7 Dev desk wiring (Pixel, after #314 and #315): the desk mounts Iris's real cards, "Open review" on a+// landed card switches to Reviews, scrolls to that PR's card and focuses its heading, the setup sheet's+// chip sits under the repo field on phone (Mira N3), and a failed backup from the secondary "Back up+// first" keeps keyboard focus.+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/s/spc_demo/dev', pretendToBeVisual: true });+const g = globalThis;+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'HTMLInputElement', 'Element', 'Node', 'Event', 'MouseEvent', 'KeyboardEvent', 'FocusEvent', '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;++const scrolled = [];+g.window.HTMLElement.prototype.scrollIntoView = function (opts) {+ scrolled.push([this.getAttribute('data-pr'), opts]);+};++const m = await loadBundled(`+ export { default as React } from 'react';+ export { createRoot } from 'react-dom/client';+ export { renderToStaticMarkup } from 'react-dom/server.browser';+ export * as fx from './src/dev/fixtures';+ export { DevDeskView, deskStore } from './src/components/DevDesk';+ export { DevModeSetup } from './src/components/DevModeSetup';+ export { ProdFloorCard } from './src/components/dev/ProdFloorCard';+ export { parseProdFloor } from './src/dev/types';+`);+const { React, createRoot, fx } = m;+const h = React.createElement;++// Demo data only. One open finding on #289's review, so its landed card offers "Open review".+const finding = fx.REVIEW_294.findings[0];+const reviewsRoute = { cards: [fx.REVIEW_290, { ...fx.REVIEW_289, findings: [finding] }, { id: 'dvr_bad', kind: 'review', status: 'ready', title: 'No PR number' }] };+const landedRoute = { ...fx.LANDED_ROUTE, cards: [...fx.LANDED_ROUTE.cards, { id: 'dvc_bad', kind: 'landed', status: 'ready', headline: 'A card without a PR' }] };+let routes = { landed: landedRoute, reviews: reviewsRoute };+g.fetch = g.window.fetch = async (url) => {+ const u = String(url);+ const json = (b) => new Response(JSON.stringify(b), { status: 200, headers: { 'Content-Type': 'application/json' } });+ if (u.includes('/dev/landed')) return json(routes.landed);+ if (u.includes('/dev/reviews')) return json(routes.reviews);+ if (u.includes('/dev_mode')) return json({ on: true, repo: 'demo-org/demo-app', branch: 'main' });+ return json({});+};++const settle = async (n = 20) => {+ for (let i = 0; i < n; i++) await new Promise((r) => setTimeout(r, 0));+};+const mounted = [];+afterEach(() => {+ while (mounted.length) mounted.pop()();+ document.body.replaceChildren();+ scrolled.length = 0;+});+const mount = async (el) => {+ const host = document.createElement('div');+ document.body.appendChild(host);+ const root = createRoot(host);+ root.render(el);+ await settle();+ mounted.push(() => root.unmount());+ return host;+};+const desk = async () => {+ m.deskStore._reset();+ const host = await mount(h(m.DevDeskView, { spaceId: 'spc_demo', spaceName: 'Demo', now: fx.FIXTURE_NOW }));+ await settle();+ return host;+};+const byText = (host, sel, text) => [...host.querySelectorAll(sel)].find((b) => b.textContent.trim() === text);+const click = async (el) => {+ el.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ await settle();+};++test('slot swap: What landed draws Iris’s rollup and landed cards; a card she can’t draw gets her fallback row', async () => {+ const host = await desk();+ assert.ok(host.querySelector('[data-dev-landed-list]'), 'Iris’s LandedList');+ assert.equal(host.querySelector('[data-dev-slot]'), null, 'no placeholder cards are left');+ assert.match(host.textContent, /changes? landed on main/, 'Iris’s rollup title, with the branch');+ const prs = [...host.querySelectorAll('[data-dev-card="landed"]')].map((c) => Number(c.getAttribute('data-pr')));+ assert.deepEqual(prs.sort(), [288, 289, 290, 301, 303]);+ const fallback = host.querySelectorAll('[data-dev-card="fallback"]');+ assert.equal(fallback.length, 1);+ assert.match(fallback[0].textContent, /A card without a PR · This card couldn’t be shown\./);+});++test('slot swap: Reviews draws Iris’s review cards, one per PR, and the fallback for a bad one', async () => {+ const host = await desk();+ await click(host.querySelector('[data-dev-tab="reviews"]'));+ const cards = [...host.querySelectorAll('[data-dev-card="review"]')];+ assert.deepEqual(cards.map((c) => c.getAttribute('data-pr')), ['290', '289']);+ assert.equal(cards[0].querySelector('h3').textContent.trim().startsWith('#290'), true);+ assert.equal(host.querySelectorAll('[data-dev-card="fallback"]').length, 1);+});++test('Open review: switches to Reviews, scrolls to that PR’s card and focuses its heading', async () => {+ const host = await desk();+ const open = byText(host, 'button', 'Open review');+ assert.ok(open, 'the landed card with an open finding offers Open review');+ assert.match(open.closest('article').textContent, /#289/);+ open.focus();+ await click(open);+ const reviewsTab = host.querySelector('[data-dev-tab="reviews"]');+ assert.equal(reviewsTab.getAttribute('aria-selected'), 'true');+ const card = host.querySelector('[data-dev-card="review"][data-pr="289"]');+ const heading = card.querySelector('h3');+ assert.equal(document.activeElement, heading, 'focus is on #289’s heading, not <body>');+ assert.equal(heading.getAttribute('tabindex'), '-1', 'focusable by script, not a tab stop');+ assert.deepEqual(scrolled, [['289', { block: 'start', behavior: 'smooth' }]]);+});++test('Open review: reduced motion scrolls without the smooth animation', async () => {+ const mm = g.window.matchMedia;+ g.window.matchMedia = (q) => ({ matches: /reduce/.test(q), addEventListener() {}, removeEventListener() {} });+ try {+ const host = await desk();+ await click(byText(host, 'button', 'Open review'));+ assert.deepEqual(scrolled, [['289', { block: 'start', behavior: 'auto' }]]);+ } finally {+ g.window.matchMedia = mm;+ }+});++test('Open review: when that PR’s card isn’t on the desk, focus goes to the Reviews tab', async () => {+ const host = await desk();+ const open = byText(host, 'button', 'Open review');+ // The review closes between the press and the render.+ m.deskStore._set('spc_demo', { reviews: [] });+ await click(open);+ const reviewsTab = host.querySelector('[data-dev-tab="reviews"]');+ assert.equal(reviewsTab.getAttribute('aria-selected'), 'true');+ assert.equal(document.activeElement, reviewsTab);+ assert.deepEqual(scrolled, []);+});++test('N3: on phone the chip goes on its own line under the repo field; from sm up it sits inside it', () => {+ const html = m.renderToStaticMarkup(h(m.DevModeSetup, { space: { id: 'spc_demo', name: 'Demo' }, initial: null, onCancel() {}, onDone() {} }));+ const row = html.match(/<div class="([^"]*)" data-dv-repo-row="true">/);+ assert.ok(row, 'the repo row');+ for (const c of ['flex-col', 'sm:flex-row', 'items-start', 'sm:border', 'sm:h-10']) assert.ok(row[1].split(' ').includes(c), c);+ // The bordered box on phone holds only the prefix and the input; the chip is its sibling.+ const field = html.slice(row.index + row[0].length).match(/^<div class="([^"]*)">/);+ assert.ok(field, 'the field box is the row’s first child');+ for (const c of ['w-full', 'border', 'h-10', 'sm:border-0', 'sm:h-auto']) assert.ok(field[1].split(' ').includes(c), c);+});++test('ProdFloorCard: a backup from the secondary Back up first that fails puts focus on Try the backup again', async () => {+ const floor = m.parseProdFloor(fx.FLOOR_DEPLOY_OLD.details);+ for (const failure of ['throws', 'not ok']) {+ const host = await mount(+ h(m.ProdFloorCard, {+ id: 'ap_4',+ floor,+ bot: 'Iris',+ command: './scripts/deploy_test.sh 9a2d5f3',+ cwd: '~/work/demo',+ onResolve() {},+ onBackup: async () => {+ if (failure === 'throws') throw new Error('disk full');+ return { id: null, ok: false, path: null, bytes: null, taken_at: null, error: 'disk full' };+ },+ }),+ );+ const secondary = [...host.querySelectorAll('button')].find((b) => b.textContent.trim() === 'Back up first' && !b.hasAttribute('data-floor-main'));+ assert.ok(secondary, 'the old-backup deploy offers the secondary button');+ secondary.focus();+ await click(secondary);+ const main = host.querySelector('[data-floor-main]');+ assert.equal(main.getAttribute('data-floor-main'), 'retry');+ assert.equal(main.textContent.trim(), 'Try the backup again');+ assert.equal(document.activeElement, main, `${failure}: focus is on Try again, not <body>`);+ mounted.pop()();+ host.remove();+ }+});++// Round 2 (Mira's #321 review). M1: after the backup, focus moves to the main button only when it was lost+// (on <body>) or is still in the card. After a good backup that button is "Allow this deploy", so taking focus+// from the composer let one Space allow a production deploy.+const floorCard = async (outcome) => {+ let release;+ const gate = new Promise((r) => (release = r));+ const resolved = [];+ const host = await mount(+ h(m.ProdFloorCard, {+ id: 'ap_m1',+ floor: m.parseProdFloor(fx.FLOOR_DEPLOY_OLD.details),+ bot: 'Iris',+ command: './scripts/deploy_test.sh 9a2d5f3',+ cwd: '~/work/demo',+ onResolve: (id, how) => resolved.push(`${id}:${how}`),+ onBackup: async () => {+ await gate;+ if (outcome === 'throws') throw new Error('disk full');+ if (outcome === 'not ok') return { id: null, ok: false, path: null, bytes: null, taken_at: null, error: 'disk full' };+ return { id: 'bk_1', ok: true, path: '/backups/demo.tar.gz', bytes: 2048, taken_at: new Date().toISOString(), error: null };+ },+ }),+ );+ const secondary = [...host.querySelectorAll('button')].find((b) => b.textContent.trim() === 'Back up first' && !b.hasAttribute('data-floor-main'));+ return { host, secondary, release, resolved };+};++for (const outcome of ['ok', 'throws', 'not ok']) {+ test(`M1: focus in an outside input stays there when the backup ends (${outcome}), and Space allows nothing`, async () => {+ const { host, secondary, release, resolved } = await floorCard(outcome);+ const composer = document.createElement('textarea');+ document.body.appendChild(composer);+ secondary.focus();+ await click(secondary);+ composer.focus();+ release();+ await settle();+ assert.equal(document.activeElement, composer, 'focus is not taken from the composer');+ composer.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }));+ composer.dispatchEvent(new KeyboardEvent('keyup', { key: ' ', bubbles: true }));+ await settle();+ assert.deepEqual(resolved, []);+ assert.equal(host.querySelector('[data-floor-main]').getAttribute('data-floor-main'), outcome === 'ok' ? 'allow' : 'retry');+ });+}++test('M1: with focus still in the card, a good backup lands focus on Allow this deploy', async () => {+ const { host, secondary, release } = await floorCard('ok');+ secondary.focus();+ await click(secondary);+ release();+ await settle();+ const main = host.querySelector('[data-floor-main]');+ assert.equal(main.textContent.trim(), 'Allow this deploy');+ assert.equal(document.activeElement, main);+});++test('S1: the secondary Back up first keeps focus during the backup and ignores presses while busy', async () => {+ const { host, secondary, release } = await floorCard('ok');+ secondary.focus();+ await click(secondary);+ assert.equal(secondary.hasAttribute('disabled'), false, 'not disabled, so focus does not drop to <body>');+ assert.equal(secondary.getAttribute('aria-disabled'), 'true');+ assert.equal(document.activeElement, secondary);+ assert.equal(host.querySelector('[data-floor-case]').getAttribute('data-floor-case'), 'taking');+ // A second press while busy does nothing: still one backup in flight, still taking.+ const before = host.innerHTML;+ await click(secondary);+ assert.equal(host.innerHTML, before);+ release();+ await settle();+});++test('S2: the Production keys hint sits outside the truncated line, so it wraps instead of being cut', async () => {+ const check = async () => ({ state: 'found', repo: 'demo-org/demo-app', branch: 'main', deploy_hint: 'docker' });+ const host = await mount(h(m.DevModeSetup, { space: { id: 'spc_demo', name: 'Demo' }, initial: { on: false, repo: 'demo-org/demo-app', branch: null }, check, onCancel() {}, onDone() {} }));+ await new Promise((r) => setTimeout(r, 450)); // the field's 400 ms check debounce+ await settle();+ const hint = [...host.querySelectorAll('[data-dv-tiles] p')].find((p) => p.textContent.trim() === 'Mark them in Connections');+ assert.ok(hint, 'the hint is its own line in the tile');+ assert.equal(hint.classList.contains('truncate'), false);+ assert.equal(hint.parentElement.querySelector('.truncate').textContent.includes('Mark them'), false, 'not inside the truncated value');+});++test('S3 + S4: the review heading has the violet focus ring and the card stops 12 px under the top', async () => {+ const host = await desk();+ await click(host.querySelector('[data-dev-tab="reviews"]'));+ const card = host.querySelector('[data-dev-card="review"]');+ assert.ok(card.className.split(' ').includes('scroll-mt-3'));+ const cls = card.querySelector('h3').className.split(' ');+ for (const c of ['focus:outline-none', 'focus-visible:outline-2', 'focus-visible:outline-sky-400', 'rounded-sm']) assert.ok(cls.includes(c), c);+});