import { Anchor, Button, CopyButton, Group, Skeleton, Stack, Text, Title } from '@mantine/core'; import { IconCheck, IconFileReport, IconFileSpreadsheet, IconFileTypePdf, IconLink, IconListNumbers } from '@/components/icons'; import { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { MODULE_NAMES } from '../../domain/agents'; import { useGate, useReport, useRun, useRunReadiness, useRunScenarios, useScenario } from '../../api/hooks'; import type { ApproveGate } from '../../api/types'; import { scriptUrl } from '../../pages/run/RunGuide'; import { RunScripts } from '../../pages/run/RunData'; import { OUTCOME, ScenarioBody } from '../../pages/run/ScenarioReview'; import { decisionSentence } from '../../pages/run/SignOffReport'; import { AiText, Can, DecisionBadge, ErrorAlert, Prio } from '../common'; import { CoworkerAvatar } from '../CoworkerAvatar'; import { coworkerForNode } from '../../domain/coworkers'; import { EmptyState } from './EmptyState'; import '../../pages/run/report.css'; const ORIGIN: Record = { library: { label: 'Library', tone: 'neutral' }, generated: { label: 'New', tone: 'lav' }, ai: { label: 'Written by the AI model', tone: 'lav' }, }; /** Panel Report tab: the verdict per business area, the counts, the downloads and the way to the full report. */ export function ReportSummary({ runId, hideVerdict = false }: { runId: string; hideVerdict?: boolean }) { const run = useRun(runId); const done = run.data?.status === 'completed'; const rep = useReport(runId); const rd = useRunReadiness(runId); const stopped = ['failed', 'killed', 'cancelled', 'interrupted'].includes(run.data?.status ?? ''); if (stopped) { // no coworker is on it any more: say so, never "Scout is on the run now" return } title="This test run stopped before it finished, so it has no report." body="The run guide says why it stopped and lets you carry on from where it stopped." action={} />; } if (!done) { const who = coworkerForNode(run.data?.pending_gate === 'approve_cases' ? 'approval_gate' : run.data?.pending_gate === 'human_review' ? 'human_review' : run.data?.current_node); return } title="The report appears when the test run has finished." body={who ? `${who.name} is on the run now. The guide shows each step.` : 'The run guide shows each step meanwhile.'} action={} />; } const mods = rd.data?.modules ?? []; const tested = mods.reduce((n, m) => n + m.counts.passed + m.counts.passed_on_retry + m.counts.failing, 0); const failing = mods.reduce((n, m) => n + m.counts.failing, 0); const notRun = mods.reduce((n, m) => n + m.counts.not_run, 0); const defects = mods.reduce((n, m) => n + m.confirmed_defects.length, 0); const gaps = mods.reduce((n, m) => n + m.steps.filter((s) => s.state === 'gap').length, 0); const link = typeof window !== 'undefined' ? `${window.location.origin}/runs/${runId}/report` : ''; const decisions = rep.data?.decisions ?? run.data?.decisions ?? {}; const writer = coworkerForNode('reporter'); return ( {Object.entries(decisions).map(([m, d]) => (
{!hideVerdict && ( {MODULE_NAMES[m] ?? m} )} {!hideVerdict && {decisionSentence(d, rep.data?.criteria?.[m] ?? {}, rep.data?.target)}} {rep.data?.files?.[m]?.pdf && ( )}
))}
Tested
{tested}
Failing
{failing}
Not run
{notRun}
Defects
{defects ? {defects} : 0}
Not covered yet
{gaps}
{writer &&

{writer.name} wrote this report.

} {({ copied, copy }) => }
); } /** Panel Excel tab: the test script (and, once finished, the results) as Excel; scripts for admins. */ export function ExcelPanel({ runId, finished }: { runId: string; finished: boolean }) { return (
Test script (Excel) Every step and the result we expect, with columns for your verdict and comments.
{finished && (
Results (Excel) The same workbook, with the outcome of every scenario in this test run.
)} Automation scripts (admin) Open the Scripts view
); } /** Panel Steps tab: one scenario, in the words of the review rows, for the selected `?scenario=`. */ export function ScenarioSteps({ runId, scenarioId }: { runId?: string; scenarioId: string | null }) { // The run's full scenario list is large (~250 KB) and slow on a busy machine; the Steps tab must not wait for it. // Use it when it is already loaded, and otherwise fetch the one selected scenario directly (a few KB). const sc = useRunScenarios(runId ?? ''); const gate = useGate(runId ?? '', !!runId); const inRun = (sc.data?.scenarios ?? []).find((x) => x.id === scenarioId); const lib = useScenario(scenarioId && !inRun ? scenarioId : null, runId); const found = inRun ?? lib.data; const loading = !!scenarioId && !found && !lib.isError; // a scenario that has not loaded in 10 s gets an error line with Try again (never an endless spinner) const [slow, setSlow] = useState(false); useEffect(() => { setSlow(false); if (!loading) return; const t = window.setTimeout(() => setSlow(true), 10_000); return () => window.clearTimeout(t); }, [loading, scenarioId]); const retry = () => { setSlow(false); if (scenarioId && !inRun) void lib.refetch(); }; if (!scenarioId) return } title="Pick a scenario to see its steps here" body="Use “Show steps” on a scenario or a screen." />; const s = found; if ((loading && slow) || (!loading && !s && lib.isError)) { return ( {slow ? 'The scenario is taking too long to load.' : 'The scenario could not be loaded.'} ); } if (loading) { return ( ); } if (!s) return ; const g = gate.data?.gate === 'approve_cases' ? (gate.data as ApproveGate) : null; const p = g?.pending.find((x) => x.id === s.id); const origin = ORIGIN[p?.origin ?? s.origin ?? 'library'] ?? ORIGIN.library; const out = s.outcome ? OUTCOME[s.outcome] : undefined; return ( Steps of {s.id} {s.title} {origin.tone === 'lav' && origin.label !== 'New' ? {origin.label} : {origin.label}} {out && In this run: {out.label}} ); }