import{jsx as e,jsxs as t}from"react/jsx-runtime";function a(){return t("div",{className:"space-y-8",children:[t("div",{className:"space-y-4",children:[e("h1",{className:"font-bold text-4xl",children:"Spec Experiments"}),e("p",{className:"text-lg text-muted-foreground",children:"Run controlled experiments on ContractSpec operations, gradually shift traffic, and roll back automatically when guardrails trip."})]}),t("div",{className:"space-y-3",children:[e("h2",{className:"font-bold text-2xl",children:"Define control + variants"}),e("pre",{className:"rounded-lg border bg-muted p-4 text-sm",children:`import { SpecExperimentRegistry } from '@contractspec/lib.growth/spec-experiments';

const registry = new SpecExperimentRegistry().register({
  target: { name: 'billing.createInvoice', version: 4 },
  experiment: {
    key: 'billing.createInvoice.evolution',
    version: '1.0.0',
    goal: 'Reduce PO validation failures',
    primaryMetric: 'latency_ms',
    variants: [
      { id: 'control' },
      { id: 'po-required', description: 'Force PO field', weight: 1 },
    ],
  },
  control: BillingCreateInvoiceV4,
  variants: [
    { id: 'po-required', spec: BillingCreateInvoiceForAcme },
  ],
  rolloutStages: [0.01, 0.1, 0.5, 1],
  guardrails: { errorRateThreshold: 0.02, latencyP99ThresholdMs: 500 },
});`})]}),t("div",{className:"space-y-3",children:[e("h2",{className:"font-bold text-2xl",children:"Attach to runtime"}),e("pre",{className:"rounded-lg border bg-muted p-4 text-sm",children:`import { createSpecVariantResolver } from '@contractspec/lib.growth/spec-experiments';

adapterContext.specVariantResolver = createSpecVariantResolver({
  adapter,
  resolveUserId: (ctx) => ctx.userId ?? ctx.organizationId ?? 'anon',
});`})]}),t("div",{className:"space-y-3",children:[e("h2",{className:"font-bold text-2xl",children:"Track outcomes + auto-rollback"}),e("pre",{className:"rounded-lg border bg-muted p-4 text-sm",children:`import {
  SpecExperimentAnalyzer,
  SpecExperimentController,
} from '@contractspec/lib.growth/spec-experiments';

const analyzer = new SpecExperimentAnalyzer(tracker);
const controller = new SpecExperimentController({
  registry,
  analyzer,
  onRollback: (target, evaluation) => notifyOps(target, evaluation.reasons),
});`})]}),e("div",{className:"grid gap-4 md:grid-cols-2",children:[{title:"Deterministic bucketing",description:"ExperimentRunner reuses the same hashing logic as growth experiments—every user sticks to a variant."},{title:"Multi-stage rollouts",description:"Use `rolloutStages` to shift 1% → 10% → 50% → 100%. Guardrails trigger rollbacks automatically."}].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))})]})}export{a as AdvancedSpecExperimentsPage};
