import { Anchor, Button, Group, SegmentedControl, Stack, Table, Text, Title } from '@mantine/core'; import { useEffect, useState } from 'react'; import { useQueryClient } from '@tanstack/react-query'; import { IconFileReport } from '@/components/icons'; import { api, errorMessage, unwrap } from '../../api/client'; import { useEvidence, useReport } from '../../api/hooks'; import { Can, DecisionBadge, ErrorAlert } from '../../components/common'; import { EmptyState, LoadingState } from '../../components/states'; import { Heals } from './Heals'; import './report.css'; /** A file's media type in plain words ("Screenshot" rather than "image/png"). */ function fileKind(t?: string | null): string { if (!t) return 'File'; if (t.startsWith('image/')) return 'Screenshot'; if (t.startsWith('video/')) return 'Video'; if (t.includes('zip')) return 'Trace'; if (t.includes('json')) return 'Data (JSON)'; if (t.startsWith('text/')) return 'Text'; return t; } /** The technical report (admin view): the exact rule result per area, the counts, the criteria, the open gaps, the * generated report itself and the run's evidence files. */ export function RunReport({ id, done }: { id: string; done: boolean }) { const q = useReport(id); const ev = useEvidence(id); const qc = useQueryClient(); const [deleting, setDeleting] = useState(false); const [delMsg, setDelMsg] = useState(null); const deleteEvidence = async () => { if (!window.confirm('Delete every screenshot, video and trace of this test run? This cannot be undone.')) return; setDeleting(true); try { const r = await unwrap(api.DELETE('/api/runs/{run_id}/evidence', { params: { path: { run_id: id } } })) as { files: number }; setDelMsg(`Deleted ${r.files} evidence ${r.files === 1 ? 'file' : 'files'}.`); await qc.invalidateQueries({ queryKey: ['run', id] }); void ev.refetch(); } catch (x) { setDelMsg(errorMessage(x)); } finally { setDeleting(false); } }; const mods = Object.keys(q.data?.decisions ?? {}); const [mod, setMod] = useState(null); useEffect(() => { if (!mod && mods.length) setMod(mods[0]); }, [mods, mod]); const refetch = q.refetch; useEffect(() => { if (done) void refetch(); }, [done, refetch]); if (q.isLoading) return ; if (q.error) return void q.refetch()} />; const r = q.data!; if (!mods.length) { return } title="No report yet" body="The reporter writes the technical report at the end of the test run." />; } const m = mod ?? mods[0]; const base = `/api/runs/${encodeURIComponent(id)}/report/${m}`; return (
{r.target} Go/no-go decisions come only from the fixed QA rules (C1–C6), never from the AI. {r.run_mode === 'stub' ? 'Quick simulation: example results, no browser was opened.' : r.target?.startsWith('Oracle Fusion') ? `Live test run against the ${r.target}.` : 'Live test run against the practice app.'}
{mods.length > 1 && }
{m} Markdown HTML {r.files[m]?.pdf ? PDF : PDF not available} Summary (JSON) {r.executive_summary[m]} {Object.entries(r.counts[m] ?? {}).map(([k, v]) => {k}: {v})} CriterionMetDetail {Object.entries(r.criteria[m] ?? {}).map(([k, c]) => ( {k}{c.ok ? 'Met' : 'Not met'}{c.detail} ))}
Open gaps {(r.gaps[m] ?? []).length === 0 ? No open gaps. : (
    {(r.gaps[m] ?? []).map((g, i) =>
  • {g}
  • )}
)}