import { Accordion, Anchor, Button, CopyButton, Group, Menu, Modal, Skeleton, Stack, Table, Text, Textarea, Title } from '@mantine/core'; import { IconAlertTriangle, IconBug, IconCheck, IconChecklist, IconChevronDown, IconDownload, IconFileSpreadsheet, IconFileTypePdf, IconLink, IconPlayerPause, IconSignature } from '@/components/icons'; import { useEffect, useRef, useState, type ReactNode } from 'react'; import { Link } from 'react-router-dom'; import { MODULE_NAMES, STEP_WORDS } from '../../domain/agents'; import { useReport, useRun, useRunReadiness, useSignOff, useTickets } from '../../api/hooks'; import { Can, DecisionBadge, ErrorAlert, fmtTs, RuleResult } from '../../components/common'; import { CoworkerAvatar } from '../../components/CoworkerAvatar'; import { DataTable } from '../../components/states'; import { coworkerForNode } from '../../domain/coworkers'; import './report.css'; import { shortWhen } from '../../domain/runName'; import { scriptUrl } from './RunGuide'; import { DECISION_WORDS, plainReason, RUN_STATUS_WORDS } from '../../domain/glossary'; import type { Criterion } from '../../api/types'; const CHECK_NAMES: Record = { C1: 'Coverage', C2: 'Critical and High scenarios', C3: 'Stability', C4: 'False failures', C5: 'Independent recount', C6: 'Honest labelling' }; const CRITERIA_WORDS: Record = { C1: 'Every scenario in scope has a test and was run', C2: 'Every Critical scenario passed; High-priority failures are explained and no High defect is open without a waiver', C3: 'Unstable scenarios stay under 5% and each has an owner', C4: 'False-failure rate is reported', C5: 'The counts in this report match the independent QA recount', C6: 'The report states it is from the mock app and lists open gaps', }; /** One sentence that explains a business area's decision from the QA rule's checks. */ export function decisionSentence(d: string, crit: Record, target?: string | null): string { const failed = Object.entries(crit).filter(([, c]) => !c.ok); return d === 'GO' ? `${DECISION_WORDS[d]}: every required check passed${target?.startsWith('Oracle Fusion') ? ' on the Oracle Fusion pod' : ' on the mock app'}.` : d === 'HELD' ? `${DECISION_WORDS[d]}: the scenarios of this area are on hold, so no decision is made.` : `${DECISION_WORDS[d] ?? d}: ${failed.length} required ${failed.length === 1 ? 'check' : 'checks'} not met: ${failed.map(([k]) => CRITERIA_WORDS[k] ?? k).join('; ')}.`; } const STOPPED = ['failed', 'killed', 'cancelled', 'interrupted']; function ReportSkeleton() { return ( ); } export function SignOffReport({ id }: { id: string }) { const run = useRun(id); const rd = useRunReadiness(id); const rep = useReport(id); const tickets = useTickets(id); const sign = useSignOff(id); const [comment, setComment] = useState(''); const [confirmNotReady, setConfirmNotReady] = useState(false); const signRef = useRef(null); const commentRef = useRef(null); // "Go to sign-off": scroll to the sign-off form and put the cursor in its comment (one accent action in the header) const goToSignOff = () => { signRef.current?.scrollIntoView({ behavior: 'smooth', block: 'center' }); window.setTimeout(() => commentRef.current?.focus({ preventScroll: true }), 300); }; const r = run.data; const mods = rd.data?.modules ?? []; const decisions = rep.data?.decisions ?? {}; const done = r?.status === 'completed'; const refetchReport = rep.refetch; const refetchTickets = tickets.refetch; useEffect(() => { if (done) { void refetchReport(); void refetchTickets(); } }, [done, refetchReport, refetchTickets]); const signed = rd.data?.signoff; const rows = mods.flatMap((m) => m.steps.filter((s) => s.scenarios > 0 || s.state === 'gap')); const patchCol = new Set(rows.map((s) => s.touched)).size > 1; // only worth a column when the steps differ const gapSteps = mods.flatMap((m) => m.steps.filter((s) => s.state === 'gap').map((s) => (mods.length > 1 ? `${MODULE_NAMES[m.module] ?? m.module}: ${s.name}` : s.name))); const gapChanges = mods.flatMap((m) => m.changes.filter((c) => c.gap).map((c) => c.area)); const allGaps = Object.values(rep.data?.gaps ?? {}).reduce((n, g) => n + g.length, 0); const link = typeof window !== 'undefined' ? `${window.location.origin}/runs/${id}/report` : ''; if (run.isLoading) return ; if (run.error) return ; if (r && STOPPED.includes(r.status)) { return (
This run did not finish, so there is no report {r.status === 'cancelled' ? 'It was cancelled' : r.status === 'killed' ? 'It was stopped by the emergency stop' : r.status === 'interrupted' ? 'It was paused before the end' : 'It stopped with an error'} {plainReason(r.error) ? `: ${plainReason(r.error).replace(/[.!?]$/, '')}.` : '.'} Start a new test run to get a report{r.status === 'interrupted' || r.status === 'failed' ? ', or carry on from where it stopped on the test run page' : ''}. Back to the test run
); } if (!done) return ; if (rep.isLoading || rd.isLoading) return ; const fusionTarget = !!rep.data?.target?.startsWith('Oracle Fusion'); const notReady = Object.values(decisions).some((d) => d !== 'GO'); const base = (m: string) => `/api/runs/${encodeURIComponent(id)}/report/${m}`; const label = (m: string) => MODULE_NAMES[m] ?? m; const pdfs = Object.keys(decisions).filter((m) => rep.data?.files?.[m]?.pdf); const passed = mods.reduce((n, m) => n + m.counts.passed + m.counts.passed_on_retry, 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 openDefects = (tickets.data?.items ?? []).filter((t) => t.status === 'open').length; const writer = coworkerForNode('reporter'); const doSign = () => sign.mutate(comment.trim(), { onSuccess: () => setConfirmNotReady(false) }); const trySign = () => { if (notReady) setConfirmNotReady(true); else doSign(); }; return (
{!signed && } {signed && Signed off by {signed.by}} {pdfs.length === 1 && ( )} {pdfs.length > 1 && ( {pdfs.map((m, i) => {label(m)})} )} {({ copied, copy }) => } {Object.keys(decisions).map((m) => (
{Object.keys(decisions).length > 1 && {label(m)}} {rep.data?.files?.[m]?.pdf && }>PDF report} Web page report (HTML) Open the report in a new tab Text report (Markdown)
))} }>Results (Excel)
{/* the verdict first: one header card per business area, the decision as a large word with its reason */} {Object.entries(decisions).map(([m, d]) => { const crit = rep.data?.criteria?.[m] ?? {}; return (
{MODULE_NAMES[m] ?? m}
{decisionSentence(d, crit, rep.data?.target)} {rep.data?.target?.startsWith('Oracle Fusion') ? `Results are from the ${rep.data.target}.` : 'Results are from the local mock app, not Oracle Fusion.'} {writer && (

{writer.name} wrote this report{r?.created_at ? `, from the test run started ${shortWhen(r.created_at)}` : ''}.

)}
); })}
} k="Scenarios tested" v={passed + failing} foot={`${passed} passed`} /> } k="Failing" v={failing} foot={failing ? 'See the failures' : 'Nothing failed'} to={failing ? `/runs/${id}/failures` : undefined} /> } k="Not run" v={notRun} foot={notRun ? 'Blocked or skipped' : 'Every scenario ran'} /> } k="Open defects" v={openDefects} foot={openDefects ? 'See the defects' : 'None open'} to={openDefects ? '/tickets' : undefined} />
Results by business process
{mods.flatMap((m) => m.steps.filter((s) => s.scenarios > 0 || s.state === 'gap').map((s) => ( {mods.length > 1 ? `${MODULE_NAMES[m.module] ?? m.module}: ` : ''}{s.name} {s.state === 'gap' && s.scenarios === 0 ? No scenario : s.scenarios} {s.passed + s.flaky}{s.failed}{s.not_run} {patchCol && {s.touched ? 'Yes' : 'No'}} )))}
Open defects {tickets.isLoading ? : tickets.error ? : (tickets.data?.items ?? []).length === 0 ? No defects raised in this test run. : ( {tickets.data!.items.map((t) => {t.ticket_id}, scenario {t.case_id}: {t.status === 'open' ? 'open' : t.status.replace(/_/g, ' ')})} )}
Not covered yet {gapSteps.length > 0 && Process steps with no scenario: {gapSteps.join(', ')}.} {gapChanges.length > 0 && Changes in this patch that no scenario tests yet ({gapChanges.length}): {gapChanges.slice(0, 8).join(', ')}{gapChanges.length > 8 ? ', …' : ''}. See what this patch changes} {gapSteps.length === 0 && gapChanges.length === 0 && No open coverage gaps for the steps in this test run.} {allGaps > 0 && The full list of {allGaps} open {allGaps === 1 ? 'point' : 'points'} is under Audit details below.}
<IconSignature size={16} aria-hidden /> Sign-off {signed ? ( Signed off by {signed.by} on {shortWhen(signed.at)}{signed.comment ? `, with the comment “${signed.comment}”` : ''}. Decision at sign-off: {Object.entries(signed.decisions).map(([m, d]) => `${MODULE_NAMES[m] ?? m} ${DECISION_WORDS[d] ?? d}`).join(', ')}. ) : ( Not signed off yet. A QA approver signs off finished test runs.}> Signing off records who reviewed this report and when (audit log). It does not change the decision. {notReady ? ' This result is Not ready: say why you sign it off anyway.' : ''}