{
  "schemaVersion": 1,
  "target": "react",
  "name": "test-results",
  "version": "0.1.0",
  "category": "ai-elements",
  "title": "Test Results",
  "description": "A test run with pass, fail, and skip counts over a proportional bar, collapsible suites, and failing tests that expand to their message and expected and received values.",
  "tags": [
    "ai",
    "agent",
    "tests",
    "ci",
    "results",
    "vitest",
    "jest"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "agent-state",
      "version": "0.1.0"
    },
    {
      "name": "step-list",
      "version": "0.3.0"
    }
  ],
  "docsPath": "/components/test-results",
  "props": [
    {
      "name": "suites",
      "type": "{ name, durationMs?, tests: { name, status, durationMs?, failure? }[] }[]",
      "description": "Suites and their tests. status is queued, running, passed, failed, or skipped; failure holds message, expected, actual, and location."
    },
    {
      "name": "title",
      "type": "ReactNode",
      "default": "\"Test results\"",
      "description": "Heading."
    },
    {
      "name": "command",
      "type": "string",
      "description": "The command that ran, shown under the title."
    },
    {
      "name": "durationMs",
      "type": "number",
      "description": "Total time, shown once the run ends."
    },
    {
      "name": "running",
      "type": "boolean",
      "description": "Marks the run in progress; derived from the tests when unset."
    }
  ],
  "accessibility": [
    "The summary bar is role img with a label such as 9 passed, 1 failed, 1 skipped, of 11 tests; the counts also appear as a labelled list below it.",
    "Each test pairs its status glyph with an sr-only status after its name; skipped tests are struck through.",
    "Suites and failing tests are Base UI Collapsible buttons operable with Enter and Space; suites with failures start open.",
    "The overall status is a live region (Running tests, Passed, or Failed). Disclosures animate in 220ms; instant with reduced motion."
  ],
  "states": [
    "running",
    "passed",
    "failed"
  ],
  "files": [
    {
      "path": "agent/test-results.tsx",
      "content": "\"use client\";\n\nimport { Collapsible } from \"@base-ui/react/collapsible\";\nimport type { ComponentProps, ReactNode } from \"react\";\nimport { AgentState } from \"./agent-state\";\nimport { StatusGlyph, type StatusGlyphKind } from \"./step-list\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nconst ease = \"ease-[cubic-bezier(0.23,1,0.32,1)]\";\n\nexport type TestStatus = \"queued\" | \"running\" | \"passed\" | \"failed\" | \"skipped\";\n\nexport interface TestFailure {\n  /** The assertion message. */\n  message: string;\n  /** Expected value, shown on its own line. */\n  expected?: string;\n  /** Received value, shown on its own line. */\n  actual?: string;\n  /** Where the assertion failed, for example `src/cart.test.ts:42:18`. */\n  location?: string;\n}\n\nexport interface TestCase {\n  name: string;\n  status: TestStatus;\n  durationMs?: number;\n  failure?: TestFailure;\n}\n\nexport interface TestSuite {\n  /** Usually the test file path. */\n  name: string;\n  tests: TestCase[];\n  durationMs?: number;\n}\n\nexport interface TestResultsProps extends Omit<ComponentProps<\"section\">, \"children\" | \"title\"> {\n  suites: TestSuite[];\n  /** Heading. Defaults to \"Test results\". */\n  title?: ReactNode;\n  /** The command that ran, shown under the title, e.g. `pnpm vitest run`. */\n  command?: string;\n  /** Total time, shown once the run ends. */\n  durationMs?: number;\n  /** Marks the run as in progress; derived from the tests when unset. */\n  running?: boolean;\n}\n\nconst glyphFor: Record<TestStatus, StatusGlyphKind> = {\n  queued: \"queued\",\n  running: \"running\",\n  passed: \"success\",\n  failed: \"failed\",\n  skipped: \"skipped\",\n};\n\nfunction count(tests: TestCase[]) {\n  const totals = { passed: 0, failed: 0, skipped: 0, pending: 0 };\n  for (const test of tests) {\n    if (test.status === \"passed\") totals.passed++;\n    else if (test.status === \"failed\") totals.failed++;\n    else if (test.status === \"skipped\") totals.skipped++;\n    else totals.pending++;\n  }\n  return totals;\n}\n\nfunction suiteStatus(tests: TestCase[]): TestStatus {\n  const totals = count(tests);\n  if (tests.some((test) => test.status === \"running\")) return \"running\";\n  if (totals.failed) return \"failed\";\n  if (totals.pending) return \"queued\";\n  if (totals.passed) return \"passed\";\n  return \"skipped\";\n}\n\n/**\n * A test run: pass, fail, and skip counts over a proportional bar, then one row per suite.\n * Suites with failures start open, and each failing test expands to its message and the\n * expected and received values.\n */\nexport function TestResults({ suites, title = \"Test results\", command, durationMs, running: runningProp, className, ...props }: TestResultsProps) {\n  const all = suites.flatMap((suite) => suite.tests);\n  const totals = count(all);\n  const running = runningProp ?? all.some((test) => test.status === \"running\" || test.status === \"queued\");\n  const total = all.length;\n  const summary = [\n    `${totals.passed} passed`,\n    totals.failed ? `${totals.failed} failed` : null,\n    totals.skipped ? `${totals.skipped} skipped` : null,\n    totals.pending ? `${totals.pending} remaining` : null,\n  ]\n    .filter(Boolean)\n    .join(\", \");\n\n  return (\n    <section\n      aria-label={typeof title === \"string\" ? title : \"Test results\"}\n      aria-busy={running || undefined}\n      className={cx(\n        \"@container overflow-hidden rounded-xl border bg-white text-left text-zinc-950 shadow-[0_1px_2px_rgb(0_0_0/0.04)]\",\n        \"transition-[border-color] duration-200 motion-reduce:transition-none\",\n        \"dark:bg-black dark:text-white dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]\",\n        !running && totals.failed ? \"border-red-500/35\" : \"border-zinc-950/10 dark:border-white/10\",\n        className,\n      )}\n      {...props}\n    >\n      <header className=\"p-4\">\n        <div className=\"flex items-start justify-between gap-3\">\n          <div className=\"min-w-0\">\n            <h3 className=\"text-sm leading-6 font-semibold\">{title}</h3>\n            {command ? <p className=\"truncate font-mono text-xs text-zinc-500\">{command}</p> : null}\n          </div>\n          <div className=\"flex shrink-0 items-center gap-2.5\">\n            {!running && durationMs != null ? (\n              <span className={`font-mono text-xs text-zinc-500 tabular-nums transition-opacity duration-300 ${ease} starting:opacity-0 motion-reduce:transition-none`}>\n                {formatDuration(durationMs)}\n              </span>\n            ) : null}\n            {running ? (\n              <AgentState status size=\"sm\" activity=\"working\" label=\"Running tests\" />\n            ) : (\n              <span role=\"status\" className=\"inline-flex h-6 items-center gap-1.5 text-xs\">\n                <StatusGlyph key={totals.failed ? \"failed\" : \"success\"} kind={totals.failed ? \"failed\" : \"success\"} />\n                <span className={totals.failed ? \"text-red-600 dark:text-red-400\" : \"text-zinc-600 dark:text-zinc-400\"}>{totals.failed ? \"Failed\" : \"Passed\"}</span>\n              </span>\n            )}\n          </div>\n        </div>\n\n        <div\n          role=\"img\"\n          aria-label={`${summary}, of ${total} tests`}\n          className=\"mt-3.5 flex h-1.5 gap-0.5 overflow-hidden rounded-full\"\n        >\n          {total === 0 ? <span className=\"flex-1 bg-zinc-950/[0.06] dark:bg-white/[0.08]\" /> : null}\n          <Segment value={totals.passed} className=\"bg-emerald-500\" />\n          <Segment value={totals.failed} className=\"bg-red-500\" />\n          <Segment value={totals.skipped} className=\"bg-zinc-950/20 dark:bg-white/25\" />\n          <Segment value={totals.pending} className=\"bg-zinc-950/[0.06] dark:bg-white/[0.08]\" />\n        </div>\n\n        <dl className=\"mt-2.5 flex flex-wrap gap-x-4 gap-y-1 text-xs\">\n          <Total label=\"Passed\" value={totals.passed} kind=\"success\" />\n          <Total label=\"Failed\" value={totals.failed} kind=\"failed\" />\n          <Total label=\"Skipped\" value={totals.skipped} kind=\"skipped\" />\n          {totals.pending ? <Total label=\"Remaining\" value={totals.pending} kind=\"queued\" /> : null}\n        </dl>\n      </header>\n\n      <ul className=\"border-t border-zinc-950/[0.07] dark:border-white/[0.08]\">\n        {suites.map((suite) => (\n          <SuiteRow key={suite.name} suite={suite} />\n        ))}\n      </ul>\n    </section>\n  );\n}\n\nfunction Segment({ value, className }: { value: number; className: string }) {\n  if (!value) return null;\n  return <span className={cx(\"h-full min-w-1.5 first:rounded-l-full last:rounded-r-full\", className)} style={{ flexGrow: value, flexBasis: 0 }} />;\n}\n\nfunction Total({ label, value, kind }: { label: string; value: number; kind: StatusGlyphKind }) {\n  return (\n    <div className=\"flex items-center gap-1.5\">\n      <StatusGlyph kind={kind} className={value ? \"\" : \"opacity-40\"} />\n      <dt className=\"text-zinc-600 dark:text-zinc-400\">{label}</dt>\n      <dd className={cx(\"font-mono tabular-nums\", value ? \"text-zinc-950 dark:text-white\" : \"text-zinc-500\")}>{value}</dd>\n    </div>\n  );\n}\n\nconst panel = cx(\n  \"h-(--collapsible-panel-height) overflow-hidden\",\n  `transition-[height,opacity] duration-220 ${ease} motion-reduce:transition-none`,\n  \"data-starting-style:h-0 data-starting-style:opacity-0\",\n  \"data-ending-style:h-0 data-ending-style:opacity-0 data-ending-style:duration-180\",\n);\n\nconst chevron = `size-4 shrink-0 text-zinc-500 transition-transform duration-200 ${ease} group-data-panel-open:rotate-90 motion-reduce:transition-none`;\n\nfunction SuiteRow({ suite }: { suite: TestSuite }) {\n  const totals = count(suite.tests);\n  const status = suiteStatus(suite.tests);\n  return (\n    <li className=\"border-b border-zinc-950/[0.07] last:border-b-0 dark:border-white/[0.08]\">\n      <Collapsible.Root defaultOpen={totals.failed > 0 || status === \"running\"}>\n        <Collapsible.Trigger\n          className={cx(\n            \"group flex w-full cursor-pointer items-center gap-2.5 py-2.5 pr-4 pl-3 text-left select-none\",\n            \"transition-colors duration-150 hover:bg-zinc-950/[0.03] motion-reduce:transition-none dark:hover:bg-white/[0.04]\",\n            \"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n          )}\n        >\n          <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" className={chevron}>\n            <path d=\"m6.25 4.5 3.5 3.5-3.5 3.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n          </svg>\n          <StatusGlyph key={status} kind={glyphFor[status]} />\n          <span className=\"min-w-0 flex-1 truncate font-mono text-[13px] text-zinc-950 dark:text-white\">{suite.name}</span>\n          <span className=\"shrink-0 font-mono text-xs text-zinc-500 tabular-nums\">\n            {/* In a narrow container the glyph carries the failure and the duration drops, so the file name keeps its room. */}\n            {totals.failed ? <span className=\"text-red-600 @max-md:hidden dark:text-red-400\">{totals.failed} failed, </span> : null}\n            {totals.passed}/{suite.tests.length}\n            {suite.durationMs != null ? <span className=\"ml-2.5 @max-md:hidden\">{formatDuration(suite.durationMs)}</span> : null}\n          </span>\n        </Collapsible.Trigger>\n        <Collapsible.Panel className={panel}>\n          <ul className=\"pb-2\">\n            {suite.tests.map((test) => (\n              <TestRow key={test.name} test={test} />\n            ))}\n          </ul>\n        </Collapsible.Panel>\n      </Collapsible.Root>\n    </li>\n  );\n}\n\nconst statusText: Record<TestStatus, string> = {\n  queued: \"queued\",\n  running: \"running\",\n  passed: \"passed\",\n  failed: \"failed\",\n  skipped: \"skipped\",\n};\n\nfunction TestRow({ test }: { test: TestCase }) {\n  const label = (\n    <>\n      <StatusGlyph key={test.status} kind={glyphFor[test.status]} />\n      <span\n        className={cx(\n          \"min-w-0 flex-1 text-[13px] leading-5\",\n          test.status === \"skipped\" ? \"text-zinc-500 line-through decoration-zinc-500/60\" : test.status === \"queued\" ? \"text-zinc-500\" : \"text-zinc-800 dark:text-zinc-200\",\n        )}\n      >\n        {test.name}\n        <span className=\"sr-only\">, {statusText[test.status]}</span>\n      </span>\n      {test.durationMs != null && test.status !== \"queued\" && test.status !== \"running\" ? (\n        <span className=\"shrink-0 font-mono text-[11px] text-zinc-500 tabular-nums\">{formatDuration(test.durationMs)}</span>\n      ) : null}\n    </>\n  );\n\n  if (test.status !== \"failed\" || !test.failure) {\n    return <li className=\"flex items-start gap-2.5 py-1 pr-4 pl-16 [&>svg]:mt-0.5\">{label}</li>;\n  }\n\n  const failure = test.failure;\n  return (\n    <li>\n      <Collapsible.Root defaultOpen>\n        <Collapsible.Trigger\n          className={cx(\n            \"group flex w-full cursor-pointer items-start gap-2.5 py-1 pr-4 pl-[38px] text-left [&>svg]:mt-0.5\",\n            \"transition-colors duration-150 hover:bg-zinc-950/[0.03] motion-reduce:transition-none dark:hover:bg-white/[0.04]\",\n            \"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n          )}\n        >\n          <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" className={chevron}>\n            <path d=\"m6.25 4.5 3.5 3.5-3.5 3.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n          </svg>\n          {label}\n        </Collapsible.Trigger>\n        <Collapsible.Panel className={panel}>\n          <div className=\"pt-1 pr-4 pb-2 pl-16\">\n            <div className=\"rounded-lg border border-red-500/35 bg-red-500/[0.08] px-3 py-2.5 font-mono text-xs leading-relaxed break-words\">\n              <p className=\"text-red-700 dark:text-red-300\">{failure.message}</p>\n              {failure.expected != null || failure.actual != null ? (\n                <dl className=\"mt-2 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-0.5\">\n                  {failure.expected != null ? (\n                    <>\n                      <dt className=\"text-zinc-500\">Expected</dt>\n                      <dd className=\"text-emerald-700 dark:text-emerald-400\">{failure.expected}</dd>\n                    </>\n                  ) : null}\n                  {failure.actual != null ? (\n                    <>\n                      <dt className=\"text-zinc-500\">Received</dt>\n                      <dd className=\"text-red-700 dark:text-red-300\">{failure.actual}</dd>\n                    </>\n                  ) : null}\n                </dl>\n              ) : null}\n              {failure.location ? <p className=\"mt-2 text-zinc-500\">{failure.location}</p> : null}\n            </div>\n          </div>\n        </Collapsible.Panel>\n      </Collapsible.Root>\n    </li>\n  );\n}\n\nfunction formatDuration(ms: number): string {\n  return ms < 1000 ? `${Math.round(ms)} ms` : `${(ms / 1000).toFixed(1)} s`;\n}\n"
    }
  ],
  "example": {
    "content": "import { TestResults, type TestSuite } from \"@/components/shaken/agent/test-results\";\n\nconst suites: TestSuite[] = [\n  {\n    name: \"src/billing/proration.test.ts\",\n    durationMs: 412,\n    tests: [\n      { name: \"charges the remaining days of the month on upgrade\", status: \"passed\", durationMs: 18 },\n      { name: \"credits unused days on downgrade\", status: \"passed\", durationMs: 11 },\n      {\n        name: \"rounds partial cents toward the customer\",\n        status: \"failed\",\n        durationMs: 9,\n        failure: {\n          message: \"expected 1233 to be 1234\",\n          expected: \"1234\",\n          actual: \"1233\",\n          location: \"src/billing/proration.test.ts:48:31\",\n        },\n      },\n      { name: \"handles leap years in annual plans\", status: \"skipped\" },\n    ],\n  },\n  {\n    name: \"src/billing/invoice.test.ts\",\n    durationMs: 266,\n    tests: [\n      { name: \"numbers invoices per workspace\", status: \"passed\", durationMs: 7 },\n      { name: \"adds tax lines for EU customers\", status: \"passed\", durationMs: 14 },\n      { name: \"voids a draft without sending email\", status: \"passed\", durationMs: 22 },\n    ],\n  },\n  {\n    name: \"src/components/PlanPicker.test.tsx\",\n    durationMs: 893,\n    tests: [\n      { name: \"shows the current plan as selected\", status: \"passed\", durationMs: 61 },\n      { name: \"disables plans below current usage\", status: \"passed\", durationMs: 48 },\n      { name: \"confirms before downgrading\", status: \"passed\", durationMs: 104 },\n    ],\n  },\n];\n\nexport default function TestResultsExample() {\n  return <TestResults suites={suites} command=\"pnpm vitest run src/billing src/components\" durationMs={1820} className=\"w-full max-w-xl\" />;\n}\n"
  }
}
