var s=Object.defineProperty;var c=(t)=>t;function l(t,a){this[t]=c.bind(null,a)}var m=(t,a)=>{for(var o in a)s(t,o,{get:a[o],enumerable:!0,configurable:!0,set:l.bind(a,o)})};var u=(t,a)=>()=>(t&&(a=t(t=0)),a);import{CodeBlock as n,InstallCommand as d}from"@contractspec/lib.design-system";import i from"@contractspec/lib.ui-link";import{ChevronRight as p}from"lucide-react";import{jsx as e,jsxs as r}from"react/jsx-runtime";function b(){return r("div",{className:"space-y-8",children:[r("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."})]}),r("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Installation"}),e(d,{package:"@contractspec/lib.testing"})]}),r("div",{className:"space-y-3",children:[e("h2",{className:"font-bold text-2xl",children:"Record traffic"}),e(n,{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,
});`})]}),r("div",{className:"space-y-3",children:[e("h2",{className:"font-bold text-2xl",children:"Generate suites"}),e(n,{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',
});`})]}),r("div",{className:"space-y-3",children:[e("h2",{className:"font-bold text-2xl",children:"CLI workflow"}),e(n,{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((t)=>r("div",{className:"card-subtle space-y-2 p-4",children:[e("h3",{className:"font-semibold text-lg",children:t.title}),e("p",{className:"text-muted-foreground text-sm",children:t.description})]},t.title))}),r("div",{className:"flex items-center gap-4 pt-4",children:[e(i,{href:"/docs/libraries",className:"btn-ghost",children:"Back to Libraries"}),r(i,{href:"/docs/libraries/resilience",className:"btn-primary",children:["Next: Resilience ",e(p,{size:16})]})]})]})}export{b as LibrariesTestingPage};
