// @bun
import{CodeBlock as a,InstallCommand as n}from"@contractspec/lib.design-system";import o from"@contractspec/lib.ui-link";import{ChevronRight as i}from"lucide-react";import{jsx as e,jsxs as t}from"react/jsx-runtime";function d(){return t("div",{className:"space-y-8",children:[t("div",{className:"space-y-4",children:[e("h1",{className:"font-bold text-4xl",children:"@contractspec/lib.testing"}),e("p",{className:"text-lg text-muted-foreground",children:"Golden tests ensure new rollouts behave exactly like the traffic that inspired them. Record requests in production, replay them locally, and ship with confidence."})]}),t("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Installation"}),e(n,{package:"@contractspec/lib.testing"})]}),t("div",{className:"space-y-3",children:[e("h2",{className:"font-bold text-2xl",children:"Record traffic"}),e(a,{language:"typescript",code:`import {
  TrafficRecorder,
  InMemoryTrafficStore,
} from '@contractspec/lib.testing/recorder';

const recorder = new TrafficRecorder({
  store: new InMemoryTrafficStore(),
  sampleRate: 0.02,
  sanitize: (snapshot) => ({
    ...snapshot,
    input: { ...snapshot.input, secret: undefined },
  }),
});

await recorder.record({
  operation: { name: 'orders.create', version: 6 },
  input: payload,
  output,
  success: true,
  tenantId: ctx.organizationId ?? undefined,
});`})]}),t("div",{className:"space-y-3",children:[e("h2",{className:"font-bold text-2xl",children:"Generate suites"}),e(a,{language:"typescript",code:`import { GoldenTestGenerator } from '@contractspec/lib.testing';

const generator = new GoldenTestGenerator();
const code = generator.generate(snapshots, {
  suiteName: 'orders.create golden path',
  runnerImport: './tests/run-operation',
  runnerFunction: 'runOrdersCommand',
  framework: 'vitest',
});`})]}),t("div",{className:"space-y-3",children:[e("h2",{className:"font-bold text-2xl",children:"CLI workflow"}),e(a,{language:"bash",code:"contractspec test generate \\\n  --operation orders.create \\\n  --output tests/orders.create.golden.test.ts \\\n  --runner-import ./tests/run-operation \\\n  --runner-fn runOrdersCommand \\\n  --from-production \\\n  --days 7 \\\n  --sample-rate 0.05"})]}),e("div",{className:"grid gap-4 md:grid-cols-2",children:[{title:"Framework agnostic",description:"Vitest by default, Jest via `generateJestSuite`, or call `runGoldenTests` manually inside CI."},{title:"Sanitize & sample",description:"Scrub payloads before persistence and control sample rates per operation to stay within compliance limits."}].map((r)=>t("div",{className:"card-subtle space-y-2 p-4",children:[e("h3",{className:"font-semibold text-lg",children:r.title}),e("p",{className:"text-muted-foreground text-sm",children:r.description})]},r.title))}),t("div",{className:"flex items-center gap-4 pt-4",children:[e(o,{href:"/docs/libraries",className:"btn-ghost",children:"Back to Libraries"}),t(o,{href:"/docs/libraries/resilience",className:"btn-primary",children:["Next: Resilience ",e(i,{size:16})]})]})]})}export{d as LibrariesTestingPage};
