Astra: PO/GL actions, usage coverage, assisted sign-in, self-healing, recorder, new top navigation and theme (172a4e22a2bf)
fb62a97 verified Download web/src/pages/run/RunPage.tsx from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 18.1 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/pages/run/RunPage.tsx
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/src/pages/run/RunPage.tsx
-
curl -L -o RunPage.tsx https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/pages/run/RunPage.tsx
18.1 kB
| import { PREPARE_NODES } from './RunGuide'; | |
| import { useWaitsOnMe, waitingForWords } from '../../domain/waiting'; | |
| import { Anchor, Button, Group, Stack, Text, Textarea } from '@mantine/core'; | |
| import { IconExternalLink, IconFileTypePdf, IconHandStop, IconMessage, IconRobot, IconSend } from '@/components/icons'; | |
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | |
| import { useMemo, useState } from 'react'; | |
| import { Link } from 'react-router-dom'; | |
| import { AGENT_BY_NODE, stepName } from '../../domain/agents'; | |
| import { shortWhenSec } from '../../domain/runName'; | |
| import { api, unwrap } from '../../api/client'; | |
| import { useGraphSpec, useReport, useRun, useRunReadiness, useTemporal } from '../../api/hooks'; | |
| import { decisionWords, plainReason } from '../../domain/glossary'; | |
| import { ModuleCard, PatchChanges } from '../home/ReadinessPage'; | |
| import { Can, ErrorAlert, fmtTs, Pill } from '../../components/common'; | |
| import { GraphView } from '../../components/GraphView'; | |
| import { nodeStates, useRunStream, type RunEvent } from '../../hooks/useRunStream'; | |
| export const TERMINAL = ['completed', 'failed', 'killed', 'cancelled']; | |
| const HIDDEN_KEYS = new Set(['node', 'traceback', 'audit_seq', 'keys', 'module', 'message']); // an agent's message is shown in full | |
| const fmtKey = (k: string) => k.replace(/^n_/, '').replace(/_/g, ' '); | |
| const fmtVal = (k: string, v: unknown) => (k === 'ms' && typeof v === 'number' ? `${(v / 1000).toFixed(1)} s` : v); | |
| // The detail views of a test run (the former tabs). The run workspace (RunWorkspace.tsx) shows them in its center. | |
| /** Compact, human-readable rendering of a node's event summary (scalars as pills, lists as counts or short joins). */ | |
| function SummaryPills({ summary }: { summary: Record<string, unknown> }) { | |
| const entries = Object.entries(summary ?? {}).filter(([k, v]) => !HIDDEN_KEYS.has(k) && v !== null && v !== undefined && v !== '') | |
| .map(([k, v]) => [k === 'ms' ? 'took' : fmtKey(k), fmtVal(k, v)] as [string, unknown]) | |
| .sort(([a], [b]) => (a === 'took' ? 1 : b === 'took' ? -1 : 0)); | |
| if (!entries.length) return null; | |
| return ( | |
| <Group gap={6} mt={6} wrap="wrap"> | |
| {entries.slice(0, 12).map(([k, v]) => { | |
| let text: string; | |
| if (Array.isArray(v)) text = v.length <= 4 && v.every((x) => typeof x !== 'object') ? v.join(', ') || 'none' : `${v.length}`; | |
| else if (typeof v === 'object') text = Object.entries(v as Record<string, unknown>).slice(0, 4).map(([a, b]) => `${a} ${typeof b === 'object' ? '…' : String(b)}`).join(' · '); | |
| else text = String(v); | |
| return <Pill key={k} title={`${k}: ${text}`}><span style={{ opacity: 0.7 }}>{k}</span> {text.length > 60 ? `${text.slice(0, 60)}…` : text}</Pill>; | |
| })} | |
| </Group> | |
| ); | |
| } | |
| export function FeedCard({ e }: { e: RunEvent }) { | |
| const a = e.node ? AGENT_BY_NODE[e.node] : undefined; | |
| const tone = e.kind === 'error' || e.kind === 'killed' ? 'red' : e.kind === 'interrupted' ? 'amber' : a?.tone ?? 'neutral'; | |
| if (e.kind === 'note') { | |
| return ( | |
| <div className="fpt-card fpt-feed-item" style={{ background: 'var(--fpt-surface-2)' }}> | |
| <div className="fpt-feed-meta"><IconMessage size={12} /><b>{String(e.summary.by ?? 'someone')}</b><span title={fmtTs(e.ts)}>· note · {shortWhenSec(e.ts)}</span></div> | |
| <Text size="sm" mt={4} style={{ whiteSpace: 'pre-wrap' }}>{String(e.summary.text ?? '')}</Text> | |
| </div> | |
| ); | |
| } | |
| if (!e.node) { | |
| return ( | |
| <div className="fpt-feed-meta" style={{ padding: '2px 4px' }}> | |
| <span className="fpt-dot" style={{ background: 'var(--fpt-line)', width: 7, height: 7, flex: '0 0 7px' }} aria-hidden /> | |
| <span>Coordinator · {e.kind}{typeof e.summary?.status === 'string' ? `: ${String(e.summary.status).replace('_', ' ')}` : ''}{typeof e.summary?.message === 'string' ? ` · ${e.summary.message}` : ''} · {shortWhenSec(e.ts)}</span> | |
| </div> | |
| ); | |
| } | |
| const verb = e.kind === 'finished' ? 'finished' : e.kind === 'interrupted' ? 'paused for a human' : e.kind === 'error' ? 'failed' | |
| : e.kind === 'message' || e.kind === 'ai_scenarios' ? 'says' : e.kind; | |
| return ( | |
| <div className="fpt-card fpt-feed-item" data-kind={e.kind}> | |
| <div className="fpt-feed-meta"> | |
| <Pill tone={tone} title={`graph node: ${e.node}`}>{stepName(e.node)}{typeof e.summary?.module === 'string' ? ` · ${e.summary.module}` : ''}</Pill> | |
| <span title={fmtTs(e.ts)}>run by Coordinator · {verb} · {shortWhenSec(e.ts)}</span> | |
| </div> | |
| {typeof e.summary?.message === 'string' && <Text size="sm" mt={4}>{e.summary.message}</Text>} | |
| <SummaryPills summary={e.summary} /> | |
| </div> | |
| ); | |
| } | |
| function GateCard({ id, gate }: { id: string; gate: string }) { | |
| if (gate === 'sign_in') { | |
| return ( | |
| <div className="fpt-card fpt-feed-item" style={{ borderColor: 'transparent', background: 'var(--pill-amber-bg)', color: 'var(--pill-amber-fg)' }} role="status"> | |
| <Group justify="space-between" wrap="wrap"> | |
| <div className="fpt-feed-meta" style={{ color: 'inherit' }}><IconHandStop size={14} /><b>Sign-in needed</b><span>· a person signs in to the pod before the tests run</span></div> | |
| <Button size="xs" component={Link} to={`/runs/${id}`}>Open the sign-in</Button> | |
| </Group> | |
| </div> | |
| ); | |
| } | |
| const tab = gate === 'approve_cases' ? 'scenarios' : 'failures'; | |
| return ( | |
| <div className="fpt-card fpt-feed-item" style={{ borderColor: 'transparent', background: 'var(--pill-amber-bg)', color: 'var(--pill-amber-fg)' }} role="status"> | |
| <Group justify="space-between" wrap="wrap"> | |
| <div className="fpt-feed-meta" style={{ color: 'inherit' }}> | |
| <IconHandStop size={14} /><b>Waiting for your review</b> | |
| <span>· {gate === 'approve_cases' ? 'approve the scenarios for this patch' : 'judge the failures (real defect, not a defect, expected change)'}</span> | |
| </div> | |
| <Button size="xs" component={Link} to={`/runs/${id}/${tab}`}>{gate === 'approve_cases' ? 'Open scenario review' : 'Open failure review'}</Button> | |
| </Group> | |
| </div> | |
| ); | |
| } | |
| export function NoteBox({ id }: { id: string }) { | |
| const [text, setText] = useState(''); | |
| const qc = useQueryClient(); | |
| const send = useMutation({ | |
| mutationFn: () => unwrap(api.POST('/api/runs/{run_id}/notes', { params: { path: { run_id: id } }, body: { text } })), | |
| onSuccess: () => { setText(''); qc.invalidateQueries({ queryKey: ['run', id] }); }, | |
| }); | |
| return ( | |
| <Can perm="run.note"> | |
| <div className="fpt-card" style={{ padding: 10 }}> | |
| <Textarea aria-label="Add a note to this run" placeholder="Add a note for the team (saved to the audit log)…" autosize minRows={2} maxRows={6} | |
| value={text} onChange={(e) => setText(e.currentTarget.value)} variant="unstyled" /> | |
| <Group justify="space-between" mt={4}> | |
| <ErrorAlert error={send.error} /> | |
| <Button size="xs" ml="auto" disabled={!text.trim()} loading={send.isPending} onClick={() => send.mutate()} rightSection={<IconSend size={12} />}>Send</Button> | |
| </Group> | |
| </div> | |
| </Can> | |
| ); | |
| } | |
| export function Activity({ id }: { id: string }) { | |
| const run = useRun(id); | |
| const spec = useGraphSpec(); | |
| const report = useReport(id); | |
| const { events, mode } = useRunStream(id); | |
| const r = run.data!; | |
| const finished = TERMINAL.includes(r.status); | |
| const st = nodeStates(events, spec.data?.nodes ?? [], finished); | |
| const feed = useMemo(() => events.filter((e) => e.kind !== 'started'), [events]); | |
| const running = Object.entries(st).filter(([, s]) => s.state === 'running').map(([n]) => n); | |
| const pdfs = Object.entries(report.data?.files ?? {}).filter(([, f]) => f.pdf).map(([m]) => m); | |
| return ( | |
| <div className="fpt-cols"> | |
| <Stack gap={8} style={{ flex: '1 1 auto', minWidth: 0 }} aria-label="activity feed"> | |
| {feed.length === 0 && <Text size="sm" c="dimmed" p="sm">The coordinator is starting the agents…</Text>} | |
| {feed.map((e) => (r.pending_gate && e.kind === 'interrupted' && e === feed.filter((x) => x.kind === 'interrupted').at(-1) | |
| ? <GateCard key={e.seq} id={id} gate={r.pending_gate} /> : <FeedCard key={e.seq} e={e} />))} | |
| {r.pending_gate && !feed.some((e) => e.kind === 'interrupted') && <GateCard id={id} gate={r.pending_gate} />} | |
| {running.map((n) => ( | |
| <div key={n} className="fpt-card fpt-feed-item fpt-live"> | |
| <div className="fpt-feed-meta"><Pill tone="ink" title={`graph node: ${n}`}>{stepName(n)}</Pill><span>working…</span></div> | |
| </div> | |
| ))} | |
| <NoteBox id={id} /> | |
| </Stack> | |
| <aside className="fpt-side" aria-label="run side panel"> | |
| <div className="fpt-card" style={{ padding: 12 }}> | |
| <Group justify="space-between" mb={6}> | |
| <Text size="sm" fw={600}><IconRobot size={14} style={{ verticalAlign: -2 }} /> Agent team</Text> | |
| <span className="fpt-pill" data-tone={mode === 'sse' ? 'green' : 'amber'} data-testid="stream-mode">{mode === 'sse' ? 'live (server-sent events)' : mode}</span> | |
| </Group> | |
| <GraphView states={st} compact /> | |
| <Text size="xs" c="dimmed" mt={6}>retry count {r.retry_count ?? 0} of 1 (owned by the workflow)</Text> | |
| </div> | |
| {Object.keys(r.counts ?? {}).length > 0 && ( | |
| <div className="fpt-card" style={{ padding: 12 }}> | |
| <Text size="sm" fw={600} mb={6}>Counts</Text> | |
| <Group gap={6}>{Object.entries(r.counts ?? {}).slice(0, 10).map(([k, v]) => <Pill key={k}>{k} <b>{String(v)}</b></Pill>)}</Group> | |
| </div> | |
| )} | |
| <div className="fpt-card" style={{ padding: 12 }}> | |
| <Text size="sm" fw={600} mb={6}>Evidence & report</Text> | |
| <Stack gap={4}> | |
| <Anchor component={Link} to={`/runs/${id}/report`} size="sm">Report & sign-off</Anchor> | |
| {pdfs.map((m) => ( | |
| <Anchor key={m} href={`/api/runs/${encodeURIComponent(id)}/report/${m}/pdf`} target="_blank" rel="noopener noreferrer" size="sm"> | |
| <IconFileTypePdf size={13} style={{ verticalAlign: -2 }} /> {m} PDF | |
| </Anchor> | |
| ))} | |
| <Anchor component={Link} to={`/runs/${id}/changes`} size="sm">What this patch changes</Anchor> | |
| <Anchor component={Link} to={`/runs/${id}/failures`} size="sm">Failures</Anchor> | |
| </Stack> | |
| </div> | |
| </aside> | |
| </div> | |
| ); | |
| } | |
| export function TemporalLink({ id }: { id: string }) { | |
| const q = useTemporal(id); | |
| if (!q.data) return null; | |
| return ( | |
| <span data-testid="temporal-link" style={{ display: 'contents' }}> | |
| <Pill tone="lav" title={`workflow ${q.data.status ?? q.data.error}`}>Temporal {q.data.query ? `· ${q.data.query.status}${q.data.query.step ? ` · ${q.data.query.step}` : ''}` : `· ${q.data.status ?? q.data.error}`}</Pill> | |
| {q.data.ui && <a href={q.data.ui} target="_blank" rel="noopener noreferrer" className="fpt-iconbtn" aria-label="open in Temporal Web UI"><IconExternalLink size={14} /></a>} | |
| </span> | |
| ); | |
| } | |
| const DECISION_TEXT: Record<string, string> = { | |
| GO: 'Ready: every required check passed on the mock app. Review the report, sign it off and share it with the release owner.', | |
| 'NO-GO': 'Not ready: at least one required check failed or is not covered yet. The report explains which ones, in business terms.', | |
| HELD: 'On hold: these scenarios are on hold (for example until data masking is confirmed), so no decision was made.', | |
| }; | |
| /** One plain-language line: what is happening and what (if anything) the user must do now. */ | |
| export function NextStep({ r, here, compact = false }: { | |
| r: { run_id: string; status: string; pending_gate?: string | null; current_node?: string | null; decision?: string | null; decisions?: Record<string, string>; error?: string | null }; | |
| /** the detail view this banner sits on: its action is dropped when it points here */ | |
| here?: string; | |
| /** one line (phone, on the view that is itself the action) */ | |
| compact?: boolean; | |
| }) { | |
| let tone = 'ink', title = '', body = '', action: { to: string; label: string } | null = null; | |
| const mine = useWaitsOnMe()(r); | |
| if (r.status === 'waiting_sign_in' && !mine) { | |
| title = waitingForWords('sign_in'); | |
| body = 'The pod signs in through the company identity provider: a person with the consultant, QA approver or admin role signs in on this run page.'; | |
| } else if (r.status === 'waiting_sign_in') { | |
| tone = 'amber'; title = 'Sign-in needed'; | |
| body = 'This pod signs in through your company identity provider. Sign in once on the run page; the tests then start from that session.'; | |
| action = { to: `/runs/${r.run_id}`, label: 'Open the sign-in' }; | |
| } else if ((r.status === 'waiting_approval' || r.status === 'waiting_review') && !mine) { | |
| title = waitingForWords(r.pending_gate ?? (r.status === 'waiting_approval' ? 'approve_cases' : 'human_review')); | |
| body = r.status === 'waiting_approval' ? 'A consultant approves the scenarios before testing continues. You can read them meanwhile.' | |
| : 'A QA approver decides on the failed scenarios before the run finishes. You can read the failures meanwhile.'; | |
| } else if (r.status === 'waiting_approval') { | |
| tone = 'amber'; title = 'Your review: approve the scenarios'; | |
| body = 'The scenarios for this patch are ready. Read the new or changed ones and approve them (or skip them for this patch) so testing can continue.'; | |
| action = { to: `/runs/${r.run_id}/scenarios`, label: 'Open scenario review' }; | |
| } else if (r.status === 'waiting_review') { | |
| tone = 'amber'; title = 'Your review: judge the failures'; | |
| body = 'Some scenarios failed. The failure analysis suggests a cause for each; confirm real defects (they become tickets), mark expected changes from the patch, or mark them as not a defect.'; | |
| action = { to: `/runs/${r.run_id}/failures`, label: 'Open failure review' }; | |
| } else if ((r.status === 'queued' || r.status === 'running') && (r.status === 'queued' || !r.current_node || PREPARE_NODES.includes(r.current_node))) { | |
| // the same stage words as the guide: the agents are still choosing the scenarios | |
| title = 'Getting the test ready'; | |
| body = 'The agents are reading the test environment and the patch, then choosing the scenarios. You will be asked to approve them next.'; | |
| } else if (r.status === 'queued' || r.status === 'running') { | |
| title = 'Testing in progress'; | |
| body = 'Nothing to do yet: you will be asked when your review is needed.'; | |
| } else if (r.status === 'completed') { | |
| const d = r.decision ?? Object.values(r.decisions ?? {})[0]; | |
| tone = d === 'GO' ? 'green' : d === 'HELD' ? 'amber' : 'red'; | |
| title = d ? `Finished: ${decisionWords(d)}` : 'Finished'; body = (d && DECISION_TEXT[d]) || 'The test run finished. Open the report for the details.'; | |
| action = { to: `/runs/${r.run_id}/report`, label: 'Open report & sign-off' }; | |
| } else if (r.status === 'interrupted') { | |
| tone = 'amber'; title = 'Paused: you can carry on'; | |
| body = plainReason(r.error) ? `Reason: ${plainReason(r.error)}` : 'The run did not finish. Someone with run control can resume it from the last completed step.'; | |
| } else if (r.status === 'cancelled') { | |
| tone = 'neutral'; title = 'Cancelled'; | |
| body = plainReason(r.error) ? `Reason: ${plainReason(r.error)}` : 'This test run was cancelled before it finished.'; | |
| } else { | |
| tone = 'red'; title = 'Stopped'; | |
| body = plainReason(r.error) ? `Reason: ${plainReason(r.error)}` : 'The run did not finish. Someone with run control can resume it from the last completed step.'; | |
| } | |
| if (action && here && action.to.endsWith(`/${here}`)) action = null; // never a button to the page you are on | |
| if (compact && !action) { | |
| return ( | |
| <div className="fpt-nextstep" data-testid="next-step" data-compact="true" data-tone={tone} title={body}> | |
| <Text fw={600} size="sm" truncate>{title}</Text> | |
| </div> | |
| ); | |
| } | |
| return ( | |
| <div className="fpt-nextstep" data-testid="next-step" data-tone={tone}> | |
| <Group justify="space-between" wrap="wrap" gap="sm"> | |
| <div style={{ minWidth: 0, flex: '1 1 320px' }}> | |
| <Text fw={600} size="sm">{title}</Text> | |
| <Text size="sm">{body}</Text> | |
| </div> | |
| {action && <Button component={Link} to={action.to} size="xs">{action.label}</Button>} | |
| </Group> | |
| </div> | |
| ); | |
| } | |
| export const LEGACY_TAB: Record<string, string> = { progress: 'overview', cases: 'scenarios', triage: 'failures', team: 'workflow' }; | |
| function BusinessProgress({ id, status, gate }: { id: string; status: string; gate?: string | null }) { | |
| const rd = useRunReadiness(id); | |
| const c = (rd.data?.modules ?? []).reduce((acc, m) => ({ scen: acc.scen + m.counts.scenarios, done: acc.done + m.counts.passed + m.counts.passed_on_retry + m.counts.failing, | |
| fail: acc.fail + m.counts.failing, wait: acc.wait + m.counts.waiting_for_you }), { scen: 0, done: 0, fail: 0, wait: 0 }); | |
| const approved = gate === 'approve_cases' ? c.scen - c.wait : c.scen; | |
| return ( | |
| <Text size="sm" data-testid="business-progress" className="fpt-card" style={{ padding: '8px 14px' }}> | |
| Scenarios approved <b>{approved}</b> · Tested <b>{c.done}/{c.scen}</b> · Failing <b>{c.fail}</b> | |
| {status === 'completed' && rd.data?.signoff ? <> · Signed off by <b>{rd.data.signoff.by}</b></> : null} | |
| </Text> | |
| ); | |
| } | |
| export function Overview({ id, quick, status, gate }: { id: string; quick: boolean; status: string; gate?: string | null }) { | |
| const rd = useRunReadiness(id); | |
| return ( | |
| <Stack gap="md"> | |
| <BusinessProgress id={id} status={status} gate={gate} /> | |
| {quick && <Text size="sm" c="dimmed" data-testid="no-live-note">Quick simulation runs don't open a browser, so there is nothing to watch. Choose Full browser run when you start a test run to see it live.</Text>} | |
| {(rd.data?.modules ?? []).map((m) => <ModuleCard key={m.module} m={m} inRun />)} | |
| </Stack> | |
| ); | |
| } | |
| export function RunChanges({ id }: { id: string }) { | |
| const rd = useRunReadiness(id); | |
| return <PatchChanges modules={rd.data?.modules ?? []} />; | |
| } | |