@odla-ai/chapter 0.47.9 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/testing.ts","../src/testing-probe.ts","../src/testing-runner.ts"],"sourcesContent":["import type {\n ChapterAcceptanceManifest, ChapterAcceptanceScenario, ChapterAcceptanceSku, ChapterAcceptanceTarget, ChapterAcceptanceValidation,\n} from \"./testing-contract\";\nexport type * from \"./testing-contract\";\nexport { probeChapterJoinContracts } from \"./testing-probe\";\nexport { formatChapterAcceptanceRun, runChapterAcceptanceSuite } from \"./testing-runner\";\n\nconst SLUG = /^[a-z0-9][a-z0-9-]{1,62}$/;\nconst CURRENCY = /^[a-z]{3}$/;\nconst STRIPE_PRICE = /^price_[A-Za-z0-9]{8,}$/;\n\nfunction activeMemberships(site: ChapterAcceptanceTarget): ChapterAcceptanceSku[] {\n return site.skus.filter((sku) => sku.active && sku.kind === \"membership\");\n}\n\nfunction representativePaidMembership(site: ChapterAcceptanceTarget): ChapterAcceptanceSku | undefined {\n return activeMemberships(site).find((sku) => sku.priceCents > 0);\n}\n\nfunction record(value: unknown): Record<string, unknown> | null {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? value as Record<string, unknown>\n : null;\n}\n\n/** Validate the exact facts a multi-site acceptance run needs before it writes anywhere. */\nexport function validateChapterAcceptanceManifest(value: unknown): ChapterAcceptanceValidation {\n const errors: string[] = [];\n const input = record(value);\n if (!input) return { ok: false, errors: [\"manifest must be an object\"] };\n if (input.schemaVersion !== 1) errors.push(\"schemaVersion must be 1\");\n const inputTargets = Array.isArray(input.targets) ? input.targets : [];\n if (inputTargets.length < 2) errors.push(\"targets must contain at least two deployed Chapter targets\");\n\n const targetIds = new Set<string>();\n const siteIds = new Set<string>();\n const targets = new Set<string>();\n const priceOwners = new Map<string, string>();\n for (const [siteIndex, rawSite] of inputTargets.entries()) {\n const path = `targets[${siteIndex}]`;\n const site = record(rawSite);\n if (!site) {\n errors.push(`${path} must be an object`);\n continue;\n }\n const targetId = typeof site.targetId === \"string\" ? site.targetId : \"\";\n const siteId = typeof site.siteId === \"string\" ? site.siteId : \"\";\n if (!SLUG.test(targetId)) errors.push(`${path}.targetId must be a stable lowercase slug`);\n if (targetIds.has(targetId)) errors.push(`${path}.targetId duplicates ${JSON.stringify(targetId)}`);\n if (targetId) targetIds.add(targetId);\n if (!SLUG.test(siteId)) errors.push(`${path}.siteId must be a stable lowercase slug`);\n if (siteId) siteIds.add(siteId);\n try {\n if (typeof site.origin !== \"string\") throw new TypeError(\"origin\");\n const origin = new URL(site.origin);\n if (origin.protocol !== \"https:\" || origin.pathname !== \"/\" || origin.search || origin.hash) {\n errors.push(`${path}.origin must be an HTTPS origin without a path, query, or fragment`);\n }\n } catch {\n errors.push(`${path}.origin must be a valid HTTPS origin`);\n }\n const target = record(site.target);\n const targetValues = {} as Record<\"appId\" | \"environment\" | \"dataEnvironment\" | \"runtime\" | \"chapterId\", string>;\n for (const key of [\"appId\", \"environment\", \"dataEnvironment\", \"runtime\", \"chapterId\"] as const) {\n targetValues[key] = typeof target?.[key] === \"string\" ? String(target[key]) : \"\";\n if (!targetValues[key]) errors.push(`${path}.target.${key} is required`);\n }\n const partition = Object.values(targetValues).join(\"\\u0000\");\n if (targets.has(partition)) errors.push(`${path}.target duplicates another site partition`);\n if (Object.values(targetValues).every(Boolean)) targets.add(partition);\n if (site.stripeMode !== \"test\" && site.stripeMode !== \"live\") {\n errors.push(`${path}.stripeMode must be test or live`);\n }\n if (site.stripeMode === \"live\" && targetValues.environment !== \"prod\" && targetValues.environment !== \"production\") {\n errors.push(`${path}.stripeMode cannot be live outside a production environment`);\n }\n\n const skuIds = new Set<string>();\n const inputSkus = Array.isArray(site.skus) ? site.skus : [];\n if (!Array.isArray(site.skus) || inputSkus.length === 0) errors.push(`${path}.skus must be a non-empty array`);\n const skus: ChapterAcceptanceSku[] = [];\n for (const [skuIndex, rawSku] of inputSkus.entries()) {\n const skuPath = `${path}.skus[${skuIndex}]`;\n const sku = record(rawSku);\n if (!sku) {\n errors.push(`${skuPath} must be an object`);\n continue;\n }\n const id = typeof sku.id === \"string\" ? sku.id : \"\";\n if (!SLUG.test(id)) errors.push(`${skuPath}.id must be a stable lowercase slug`);\n if (skuIds.has(id)) errors.push(`${skuPath}.id duplicates ${JSON.stringify(id)}`);\n if (id) skuIds.add(id);\n if (sku.kind !== \"membership\" && sku.kind !== \"add_on\") errors.push(`${skuPath}.kind must be membership or add_on`);\n if (typeof sku.active !== \"boolean\") errors.push(`${skuPath}.active must be boolean`);\n const priceCents = typeof sku.priceCents === \"number\" ? sku.priceCents : Number.NaN;\n if (!Number.isSafeInteger(priceCents) || priceCents < 0) errors.push(`${skuPath}.priceCents must be a non-negative integer`);\n if (typeof sku.currency !== \"string\" || !CURRENCY.test(sku.currency)) errors.push(`${skuPath}.currency must be a lowercase ISO currency code`);\n if (sku.billing !== \"month\" && sku.billing !== \"year\" && sku.billing !== \"once\") {\n errors.push(`${skuPath}.billing must be month, year, or once`);\n }\n if (sku.kind === \"membership\" && sku.billing === \"once\") {\n errors.push(`${skuPath}.billing must be month or year for a membership SKU`);\n }\n if (sku.active === true && priceCents > 0 && (typeof sku.stripePriceId !== \"string\" || !STRIPE_PRICE.test(sku.stripePriceId))) {\n errors.push(`${skuPath}.stripePriceId is required for an active paid SKU`);\n }\n if (priceCents === 0 && sku.stripePriceId) errors.push(`${skuPath}.stripePriceId must be absent for a free SKU`);\n if (typeof sku.stripePriceId === \"string\" && sku.stripePriceId) {\n const owner = `${siteId}/${id}`;\n const previous = priceOwners.get(sku.stripePriceId);\n if (previous && previous !== owner) errors.push(`${skuPath}.stripePriceId is already owned by ${previous}`);\n else priceOwners.set(sku.stripePriceId, owner);\n }\n if (sku.compareAtPriceCents !== undefined) {\n if (!Number.isSafeInteger(sku.compareAtPriceCents) || Number(sku.compareAtPriceCents) <= priceCents) {\n errors.push(`${skuPath}.compareAtPriceCents must be an integer greater than priceCents`);\n }\n if (sku.discountDuration !== \"first_term\" && sku.discountDuration !== \"while_active\") {\n errors.push(`${skuPath}.discountDuration is required with compareAtPriceCents`);\n }\n } else if (sku.discountDuration) {\n errors.push(`${skuPath}.compareAtPriceCents is required with discountDuration`);\n }\n skus.push(sku as unknown as ChapterAcceptanceSku);\n }\n if (!skus.some((sku) => sku.active && sku.kind === \"membership\")) errors.push(`${path}.skus must contain an active membership SKU`);\n const options = record(site.options);\n if (!options) errors.push(`${path}.options must be an object`);\n if (options?.ordinaryInterview !== true) errors.push(`${path}.options.ordinaryInterview must be true`);\n if (typeof options?.invitationInterviewWaiver !== \"boolean\") errors.push(`${path}.options.invitationInterviewWaiver must be boolean`);\n if (options?.autoRenew !== true) errors.push(`${path}.options.autoRenew must be true`);\n const seat = record(options?.additionalSeat);\n if (options?.additionalSeat !== undefined && !seat) errors.push(`${path}.options.additionalSeat must be an object`);\n if (seat) {\n const seatSku = skus.find((sku) => sku.id === seat.skuId);\n if (!seatSku || !seatSku.active || seatSku.kind !== \"add_on\") {\n errors.push(`${path}.options.additionalSeat.skuId must name an active add_on SKU`);\n } else if (seatSku.billing === \"once\") {\n errors.push(`${path}.options.additionalSeat.skuId must name a recurring add_on SKU`);\n }\n if (typeof seat.purchaseWindowCalendarMonths !== \"number\" ||\n !Number.isInteger(seat.purchaseWindowCalendarMonths) || seat.purchaseWindowCalendarMonths < 1) {\n errors.push(`${path}.options.additionalSeat.purchaseWindowCalendarMonths must be a positive integer`);\n }\n if (seat.named !== true || seat.uniqueEmail !== true || seat.renewal !== \"membership_aligned\" || seat.chargeTiming !== \"start\") {\n errors.push(`${path}.options.additionalSeat must require a named unique-email seat, membership-aligned renewal, and payment at start`);\n }\n }\n }\n if (siteIds.size < 2) errors.push(\"targets must cover at least two distinct logical sites\");\n return errors.length ? { ok: false, errors } : { ok: true, value: value as ChapterAcceptanceManifest };\n}\n\nfunction scenario(input: Omit<ChapterAcceptanceScenario, \"id\">): ChapterAcceptanceScenario {\n return {\n ...input,\n id: [input.suite, input.targetId, input.skuId, input.siblingTargetId, input.kind].filter(Boolean).join(\":\"),\n };\n}\n\n/**\n * Build exhaustive pure cases plus a bounded provider-backed development matrix.\n * Throws before returning provider work when the manifest is invalid or names live Stripe.\n */\nexport function planChapterAcceptanceMatrix(manifest: ChapterAcceptanceManifest): ChapterAcceptanceScenario[] {\n const validation = validateChapterAcceptanceManifest(manifest);\n if (!validation.ok) throw new TypeError(`invalid Chapter acceptance manifest: ${validation.errors.join(\"; \")}`);\n if (manifest.targets.some((site) => site.stripeMode !== \"test\")) {\n throw new TypeError(\"provider acceptance runs are development-only and require Stripe test mode on every target\");\n }\n const scenarios: ChapterAcceptanceScenario[] = [];\n for (const site of manifest.targets) {\n for (const sku of site.skus.filter((candidate) => candidate.active)) {\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"catalog_contract\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n if (sku.priceCents > 0) {\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"amount_tamper\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"wrong_environment_event\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"post_stripe_compensation\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n for (const sibling of manifest.targets.filter((candidate) => candidate.targetId !== site.targetId)) {\n scenarios.push(scenario({\n suite: \"hermetic\", kind: \"sibling_event_isolation\", targetId: site.targetId, siteId: site.siteId,\n skuId: sku.id, siblingTargetId: sibling.targetId,\n }));\n }\n }\n }\n for (const sku of activeMemberships(site)) {\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"submit_replay\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n scenarios.push(scenario({\n suite: \"provider_dev\", kind: sku.priceCents > 0 ? \"paid_signup\" : \"free_signup\",\n targetId: site.targetId, siteId: site.siteId, skuId: sku.id,\n }));\n }\n const paid = representativePaidMembership(site);\n if (paid) {\n scenarios.push(scenario({ suite: \"provider_dev\", kind: \"ordinary_interview\", targetId: site.targetId, siteId: site.siteId, skuId: paid.id }));\n scenarios.push(scenario({ suite: \"provider_dev\", kind: \"renewal\", targetId: site.targetId, siteId: site.siteId, skuId: paid.id }));\n scenarios.push(scenario({ suite: \"provider_dev\", kind: \"refund_cancel\", targetId: site.targetId, siteId: site.siteId, skuId: paid.id }));\n if (site.options.invitationInterviewWaiver) {\n scenarios.push(scenario({ suite: \"provider_dev\", kind: \"invitation_interview_waiver\", targetId: site.targetId, siteId: site.siteId, skuId: paid.id }));\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"expired_interview_waiver\", targetId: site.targetId, siteId: site.siteId, skuId: paid.id }));\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"replayed_interview_waiver\", targetId: site.targetId, siteId: site.siteId, skuId: paid.id }));\n }\n if (site.options.additionalSeat) {\n scenarios.push(scenario({\n suite: \"provider_dev\", kind: \"named_seat\", targetId: site.targetId, siteId: site.siteId,\n skuId: site.options.additionalSeat.skuId,\n }));\n scenarios.push(scenario({\n suite: \"hermetic\", kind: \"duplicate_seat_email\", targetId: site.targetId, siteId: site.siteId,\n skuId: site.options.additionalSeat.skuId,\n }));\n scenarios.push(scenario({\n suite: \"hermetic\", kind: \"expired_seat_window\", targetId: site.targetId, siteId: site.siteId,\n skuId: site.options.additionalSeat.skuId,\n }));\n }\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"canceled_membership\", targetId: site.targetId, siteId: site.siteId, skuId: paid.id }));\n }\n }\n return scenarios;\n}\n","import type {\n ChapterAcceptanceManifest,\n ChapterAcceptanceTarget,\n ChapterJoinConfigProbe,\n ChapterJoinContractFinding,\n ChapterJoinContractProbeResult,\n} from \"./testing-contract\";\nimport { validateChapterAcceptanceManifest } from \"./testing\";\n\nfunction activeMemberships(site: ChapterAcceptanceTarget) {\n return site.skus.filter((sku) => sku.active && sku.kind === \"membership\");\n}\n\n/** Probe public deployed join contracts without creating applications or provider objects. */\nexport async function probeChapterJoinContracts(\n manifest: ChapterAcceptanceManifest,\n fetcher: typeof fetch = fetch,\n): Promise<ChapterJoinContractProbeResult> {\n const validation = validateChapterAcceptanceManifest(manifest);\n if (!validation.ok) throw new TypeError(`invalid Chapter acceptance manifest: ${validation.errors.join(\"; \")}`);\n const findings: ChapterJoinContractFinding[] = [];\n for (const site of manifest.targets) {\n let health: Response;\n let configResponse: Response;\n try {\n [health, configResponse] = await Promise.all([\n fetcher(`${site.origin}/api/health`, { headers: { \"cache-control\": \"no-cache\" } }),\n fetcher(`${site.origin}/api/join-config`, { headers: { \"cache-control\": \"no-cache\" } }),\n ]);\n } catch (error) {\n findings.push({ targetId: site.targetId, siteId: site.siteId, path: \"fetch\", expected: \"reachable\", actual: error instanceof Error ? error.message : String(error) });\n continue;\n }\n const targetNote = (path: string, expected: unknown, actual: unknown): void => {\n if (JSON.stringify(expected) !== JSON.stringify(actual)) findings.push({ targetId: site.targetId, siteId: site.siteId, path, expected, actual });\n };\n targetNote(\"/api/health status\", 200, health.status);\n targetNote(\"/api/join-config status\", 200, configResponse.status);\n if (!configResponse.ok) continue;\n let config: ChapterJoinConfigProbe;\n try {\n config = await configResponse.json() as ChapterJoinConfigProbe;\n } catch {\n targetNote(\"/api/join-config JSON\", \"object\", \"invalid JSON\");\n continue;\n }\n targetNote(\"id\", site.target.chapterId, config.id);\n const actualTiers = Array.isArray(config.tiers) ? config.tiers : [];\n const expectedTiers = activeMemberships(site).map((sku) => ({\n id: sku.id, priceCents: sku.priceCents, currency: sku.currency,\n interval: sku.billing, free: sku.priceCents === 0,\n }));\n const projected = actualTiers.map((tier) => {\n const value = tier as Record<string, unknown>;\n return {\n id: value.id, priceCents: value.priceCents, currency: value.currency,\n interval: value.interval, free: value.free,\n };\n });\n targetNote(\"tiers\", expectedTiers, projected);\n targetNote(\"paymentsReady\", expectedTiers.some((tier) => !tier.free), config.paymentsReady);\n }\n return { ok: findings.length === 0, findings };\n}\n","import type {\n ChapterAcceptanceCaseResult,\n ChapterAcceptanceCleanupEvidence,\n ChapterAcceptanceEvidence,\n ChapterAcceptanceExecutionContext,\n ChapterAcceptanceExecutor,\n ChapterAcceptanceManifest,\n ChapterAcceptanceProviderReference,\n ChapterAcceptanceRunResult,\n} from \"./testing-contract\";\nimport { planChapterAcceptanceMatrix } from \"./testing\";\n\nconst SAFE_LABEL = /^[a-z0-9][a-z0-9._:-]{0,159}$/;\nconst SAFE_REFERENCE = /^[A-Za-z0-9_:.=-]{3,240}$/;\n\nfunction safeErrorCode(error: unknown): string {\n if (error && typeof error === \"object\") {\n const code = (error as { code?: unknown }).code;\n if (typeof code === \"string\" && SAFE_LABEL.test(code)) return code;\n }\n return \"execution_failed\";\n}\n\nfunction validateLabels(values: readonly string[], path: string): void {\n if (!Array.isArray(values) || values.length === 0) throw Object.assign(new TypeError(`${path} must be non-empty`), { code: \"invalid_evidence\" });\n if (values.length > 64 || values.some((value) => typeof value !== \"string\" || !SAFE_LABEL.test(value))) {\n throw Object.assign(new TypeError(`${path} contains an unsafe or unbounded label`), { code: \"invalid_evidence\" });\n }\n}\n\nfunction validateReferences(values: readonly ChapterAcceptanceProviderReference[] | undefined): void {\n if (values === undefined) return;\n if (!Array.isArray(values) || values.length > 64) throw Object.assign(new TypeError(\"references must be bounded\"), { code: \"invalid_evidence\" });\n const kinds = new Set([\"stripe_event\", \"stripe_object\", \"clerk_user\", \"calendar_event\", \"email_message\", \"event_digest\"]);\n for (const reference of values) {\n if (!reference || !kinds.has(reference.kind) || typeof reference.value !== \"string\" ||\n !SAFE_REFERENCE.test(reference.value) || reference.value.includes(\"@\")) {\n throw Object.assign(new TypeError(\"references may contain only opaque provider ids or digests\"), { code: \"invalid_evidence\" });\n }\n }\n}\n\nfunction validateEvidence(evidence: ChapterAcceptanceEvidence, provider: boolean): void {\n if (!evidence || typeof evidence !== \"object\") throw Object.assign(new TypeError(\"executor returned no evidence\"), { code: \"invalid_evidence\" });\n validateLabels(evidence.checks, \"evidence.checks\");\n validateReferences(evidence.references);\n if (provider && (typeof evidence.deploymentVersion !== \"string\" || !SAFE_REFERENCE.test(evidence.deploymentVersion))) {\n throw Object.assign(new TypeError(\"provider evidence requires a safe deploymentVersion\"), { code: \"invalid_evidence\" });\n }\n}\n\nfunction validateCleanup(cleanup: ChapterAcceptanceCleanupEvidence): void {\n if (!cleanup || (cleanup.status !== \"complete\" && cleanup.status !== \"incomplete\")) {\n throw Object.assign(new TypeError(\"executor returned invalid cleanup evidence\"), { code: \"cleanup_failed\" });\n }\n validateLabels(cleanup.checks, \"cleanup.checks\");\n}\n\nfunction contextFor(manifest: ChapterAcceptanceManifest, id: string): ChapterAcceptanceExecutionContext {\n const scenario = planChapterAcceptanceMatrix(manifest).find((item) => item.id === id);\n if (!scenario) throw new TypeError(`unknown acceptance scenario ${id}`);\n const target = manifest.targets.find((item) => item.targetId === scenario.targetId)!;\n return {\n scenario,\n target,\n ...(scenario.skuId ? { sku: target.skus.find((item) => item.id === scenario.skuId) } : {}),\n ...(scenario.siblingTargetId ? {\n siblingTarget: manifest.targets.find((item) => item.targetId === scenario.siblingTargetId),\n } : {}),\n };\n}\n\n/**\n * Execute one suite serially. Provider runs fail before their first mutation\n * unless the app supplies cleanup, then invoke cleanup after every attempted\n * case even when execution throws. Raw provider error text is never retained.\n */\nexport async function runChapterAcceptanceSuite(\n manifest: ChapterAcceptanceManifest,\n suite: \"hermetic\" | \"provider_dev\",\n executor: ChapterAcceptanceExecutor,\n): Promise<ChapterAcceptanceRunResult> {\n const scenarios = planChapterAcceptanceMatrix(manifest).filter((item) => item.suite === suite);\n if (suite === \"provider_dev\" && typeof executor.cleanup !== \"function\") {\n throw new TypeError(\"provider_dev acceptance requires a cleanup executor before any case can run\");\n }\n const cases: ChapterAcceptanceCaseResult[] = [];\n for (const scenario of scenarios) {\n const context = contextFor(manifest, scenario.id);\n let evidence: ChapterAcceptanceEvidence | undefined;\n let errorCode: string | undefined;\n let cleanup: ChapterAcceptanceCleanupEvidence | undefined;\n try {\n evidence = await executor.execute(context);\n validateEvidence(evidence, suite === \"provider_dev\");\n } catch (error) {\n errorCode = safeErrorCode(error);\n } finally {\n if (suite === \"provider_dev\") {\n try {\n cleanup = await executor.cleanup!(context);\n validateCleanup(cleanup);\n if (cleanup.status !== \"complete\") errorCode = \"cleanup_incomplete\";\n } catch {\n errorCode = \"cleanup_failed\";\n }\n }\n }\n cases.push({\n id: scenario.id,\n suite,\n outcome: errorCode ? \"failed\" : \"passed\",\n ...(evidence ? { evidence } : {}),\n ...(cleanup ? { cleanup } : {}),\n ...(errorCode ? { errorCode } : {}),\n });\n }\n return { ok: cases.every((item) => item.outcome === \"passed\"), suite, cases };\n}\n\n/** PII-free line report suitable for CI logs and PM evidence. */\nexport function formatChapterAcceptanceRun(result: ChapterAcceptanceRunResult): string {\n const passed = result.cases.filter((item) => item.outcome === \"passed\").length;\n const lines = [`${result.ok ? \"ok\" : \"failed\"}: ${result.suite} ${passed}/${result.cases.length}`];\n for (const item of result.cases) {\n lines.push(`${item.outcome === \"passed\" ? \"PASS\" : \"FAIL\"} ${item.id}${item.errorCode ? ` ${item.errorCode}` : \"\"}`);\n }\n return lines.join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,SAAS,kBAAkB,MAA+B;AACxD,SAAO,KAAK,KAAK,OAAO,CAAC,QAAQ,IAAI,UAAU,IAAI,SAAS,YAAY;AAC1E;AAGA,eAAsB,0BACpB,UACA,UAAwB,OACiB;AACzC,QAAM,aAAa,kCAAkC,QAAQ;AAC7D,MAAI,CAAC,WAAW,GAAI,OAAM,IAAI,UAAU,wCAAwC,WAAW,OAAO,KAAK,IAAI,CAAC,EAAE;AAC9G,QAAM,WAAyC,CAAC;AAChD,aAAW,QAAQ,SAAS,SAAS;AACnC,QAAI;AACJ,QAAI;AACJ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src/testing-commercial.ts","../src/testing-probe.ts","../src/testing-runner.ts","../src/testing-release.ts"],"sourcesContent":["import type {\n ChapterAcceptanceManifest, ChapterAcceptanceScenario, ChapterAcceptanceSku, ChapterAcceptanceTarget, ChapterAcceptanceValidation,\n} from \"./testing-contract\";\nimport { validateCommercialCases } from \"./testing-commercial\";\nexport { assertCommercialQuote } from \"./testing-commercial\";\nexport type * from \"./testing-contract\";\nexport { probeChapterJoinContracts } from \"./testing-probe\";\nexport { formatChapterAcceptanceRun, runChapterAcceptanceSuite } from \"./testing-runner\";\nexport { assessChapterReleaseEvidence } from \"./testing-release\";\nexport type * from \"./testing-release\";\n\nconst SLUG = /^[a-z0-9][a-z0-9-]{1,62}$/;\nconst CURRENCY = /^[a-z]{3}$/;\nconst STRIPE_PRICE = /^price_[A-Za-z0-9]{8,}$/;\n\nfunction activeMemberships(site: ChapterAcceptanceTarget): ChapterAcceptanceSku[] {\n return site.skus.filter((sku) => sku.active && sku.kind === \"membership\");\n}\n\nfunction record(value: unknown): Record<string, unknown> | null {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? value as Record<string, unknown>\n : null;\n}\n\n/** Validate the exact facts a multi-site acceptance run needs before it writes anywhere. */\nexport function validateChapterAcceptanceManifest(value: unknown): ChapterAcceptanceValidation {\n const errors: string[] = [];\n const input = record(value);\n if (!input) return { ok: false, errors: [\"manifest must be an object\"] };\n if (input.schemaVersion !== 1) errors.push(\"schemaVersion must be 1\");\n const inputTargets = Array.isArray(input.targets) ? input.targets : [];\n if (inputTargets.length < 2) errors.push(\"targets must contain at least two deployed Chapter targets\");\n\n const targetIds = new Set<string>();\n const siteIds = new Set<string>();\n const targets = new Set<string>();\n const priceOwners = new Map<string, string>();\n for (const [siteIndex, rawSite] of inputTargets.entries()) {\n const path = `targets[${siteIndex}]`;\n const site = record(rawSite);\n if (!site) {\n errors.push(`${path} must be an object`);\n continue;\n }\n const targetId = typeof site.targetId === \"string\" ? site.targetId : \"\";\n const siteId = typeof site.siteId === \"string\" ? site.siteId : \"\";\n if (!SLUG.test(targetId)) errors.push(`${path}.targetId must be a stable lowercase slug`);\n if (targetIds.has(targetId)) errors.push(`${path}.targetId duplicates ${JSON.stringify(targetId)}`);\n if (targetId) targetIds.add(targetId);\n if (!SLUG.test(siteId)) errors.push(`${path}.siteId must be a stable lowercase slug`);\n if (siteId) siteIds.add(siteId);\n try {\n if (typeof site.origin !== \"string\") throw new TypeError(\"origin\");\n const origin = new URL(site.origin);\n if (origin.protocol !== \"https:\" || origin.pathname !== \"/\" || origin.search || origin.hash || origin.username || origin.password) {\n errors.push(`${path}.origin must be an HTTPS origin without a path, query, or fragment`);\n }\n } catch {\n errors.push(`${path}.origin must be a valid HTTPS origin`);\n }\n const target = record(site.target);\n const targetValues = {} as Record<\"appId\" | \"environment\" | \"dataEnvironment\" | \"runtime\" | \"chapterId\", string>;\n for (const key of [\"appId\", \"environment\", \"dataEnvironment\", \"runtime\", \"chapterId\"] as const) {\n targetValues[key] = typeof target?.[key] === \"string\" ? String(target[key]) : \"\";\n if (!targetValues[key]) errors.push(`${path}.target.${key} is required`);\n }\n const partition = Object.values(targetValues).join(\"\\u0000\");\n if (targets.has(partition)) errors.push(`${path}.target duplicates another site partition`);\n if (Object.values(targetValues).every(Boolean)) targets.add(partition);\n if (site.stripeMode !== \"test\" && site.stripeMode !== \"live\") {\n errors.push(`${path}.stripeMode must be test or live`);\n }\n if (site.stripeMode === \"live\" && targetValues.environment !== \"prod\" && targetValues.environment !== \"production\") {\n errors.push(`${path}.stripeMode cannot be live outside a production environment`);\n }\n\n const skuIds = new Set<string>();\n const inputSkus = Array.isArray(site.skus) ? site.skus : [];\n if (!Array.isArray(site.skus) || inputSkus.length === 0) errors.push(`${path}.skus must be a non-empty array`);\n const skus: ChapterAcceptanceSku[] = [];\n for (const [skuIndex, rawSku] of inputSkus.entries()) {\n const skuPath = `${path}.skus[${skuIndex}]`;\n const sku = record(rawSku);\n if (!sku) {\n errors.push(`${skuPath} must be an object`);\n continue;\n }\n const id = typeof sku.id === \"string\" ? sku.id : \"\";\n if (!SLUG.test(id)) errors.push(`${skuPath}.id must be a stable lowercase slug`);\n if (skuIds.has(id)) errors.push(`${skuPath}.id duplicates ${JSON.stringify(id)}`);\n if (id) skuIds.add(id);\n if (sku.kind !== \"membership\" && sku.kind !== \"add_on\") errors.push(`${skuPath}.kind must be membership or add_on`);\n if (typeof sku.active !== \"boolean\") errors.push(`${skuPath}.active must be boolean`);\n const priceCents = typeof sku.priceCents === \"number\" ? sku.priceCents : Number.NaN;\n if (!Number.isSafeInteger(priceCents) || priceCents < 0) errors.push(`${skuPath}.priceCents must be a non-negative integer`);\n if (typeof sku.currency !== \"string\" || !CURRENCY.test(sku.currency)) errors.push(`${skuPath}.currency must be a lowercase ISO currency code`);\n if (sku.billing !== \"month\" && sku.billing !== \"year\" && sku.billing !== \"once\") {\n errors.push(`${skuPath}.billing must be month, year, or once`);\n }\n if (sku.kind === \"membership\" && sku.billing === \"once\") {\n errors.push(`${skuPath}.billing must be month or year for a membership SKU`);\n }\n if (sku.active === true && priceCents > 0 && (typeof sku.stripePriceId !== \"string\" || !STRIPE_PRICE.test(sku.stripePriceId))) {\n errors.push(`${skuPath}.stripePriceId is required for an active paid SKU`);\n }\n if (priceCents === 0 && sku.stripePriceId) errors.push(`${skuPath}.stripePriceId must be absent for a free SKU`);\n if (typeof sku.stripePriceId === \"string\" && sku.stripePriceId) {\n const owner = `${siteId}/${id}`;\n const previous = priceOwners.get(sku.stripePriceId);\n if (previous && previous !== owner) errors.push(`${skuPath}.stripePriceId is already owned by ${previous}`);\n else priceOwners.set(sku.stripePriceId, owner);\n }\n if (sku.compareAtPriceCents !== undefined) {\n if (!Number.isSafeInteger(sku.compareAtPriceCents) || Number(sku.compareAtPriceCents) <= priceCents) {\n errors.push(`${skuPath}.compareAtPriceCents must be an integer greater than priceCents`);\n }\n if (sku.discountDuration !== \"first_term\" && sku.discountDuration !== \"while_active\") {\n errors.push(`${skuPath}.discountDuration is required with compareAtPriceCents`);\n }\n } else if (sku.discountDuration) {\n errors.push(`${skuPath}.compareAtPriceCents is required with discountDuration`);\n }\n skus.push(sku as unknown as ChapterAcceptanceSku);\n }\n if (!skus.some((sku) => sku.active && sku.kind === \"membership\")) errors.push(`${path}.skus must contain an active membership SKU`);\n errors.push(...validateCommercialCases(site.commercialCases, skus, `${path}.commercialCases`));\n const options = record(site.options);\n if (!options) errors.push(`${path}.options must be an object`);\n if (options?.ordinaryInterview !== true) errors.push(`${path}.options.ordinaryInterview must be true`);\n if (typeof options?.invitationInterviewWaiver !== \"boolean\") errors.push(`${path}.options.invitationInterviewWaiver must be boolean`);\n if (options?.autoRenew !== true) errors.push(`${path}.options.autoRenew must be true`);\n const seat = record(options?.additionalSeat);\n if (options?.additionalSeat !== undefined && !seat) errors.push(`${path}.options.additionalSeat must be an object`);\n if (seat) {\n const seatSku = skus.find((sku) => sku.id === seat.skuId);\n if (!seatSku || !seatSku.active || seatSku.kind !== \"add_on\") {\n errors.push(`${path}.options.additionalSeat.skuId must name an active add_on SKU`);\n } else if (seatSku.billing === \"once\") {\n errors.push(`${path}.options.additionalSeat.skuId must name a recurring add_on SKU`);\n }\n if (typeof seat.purchaseWindowCalendarMonths !== \"number\" ||\n !Number.isInteger(seat.purchaseWindowCalendarMonths) || seat.purchaseWindowCalendarMonths < 1) {\n errors.push(`${path}.options.additionalSeat.purchaseWindowCalendarMonths must be a positive integer`);\n }\n if (seat.named !== true || seat.uniqueEmail !== true || seat.renewal !== \"membership_aligned\" || seat.chargeTiming !== \"start\") {\n errors.push(`${path}.options.additionalSeat must require a named unique-email seat, membership-aligned renewal, and payment at start`);\n }\n }\n }\n if (siteIds.size < 2) errors.push(\"targets must cover at least two distinct logical sites\");\n return errors.length ? { ok: false, errors } : { ok: true, value: value as ChapterAcceptanceManifest };\n}\n\nfunction scenario(input: Omit<ChapterAcceptanceScenario, \"id\">): ChapterAcceptanceScenario {\n return {\n ...input,\n id: [input.suite, input.targetId, input.skuId, input.parentSkuId, input.commercialCaseId, input.siblingTargetId, input.kind].filter(Boolean).join(\":\"),\n };\n}\n\n/**\n * Build exhaustive pure cases plus a bounded provider-backed development matrix.\n * Throws before returning provider work when the manifest is invalid or names live Stripe.\n */\nexport function planChapterAcceptanceMatrix(manifest: ChapterAcceptanceManifest): ChapterAcceptanceScenario[] {\n const validation = validateChapterAcceptanceManifest(manifest);\n if (!validation.ok) throw new TypeError(`invalid Chapter acceptance manifest: ${validation.errors.join(\"; \")}`);\n if (manifest.targets.some((site) => site.stripeMode !== \"test\" || site.target.environment !== \"dev\" || site.target.dataEnvironment !== \"dev\")) {\n throw new TypeError(\"provider acceptance runs are development-only and require Stripe test mode and dev runtime/data environments on every target\");\n }\n const scenarios: ChapterAcceptanceScenario[] = [];\n for (const site of manifest.targets) {\n for (const vector of site.commercialCases ?? []) {\n const base = { targetId: site.targetId, siteId: site.siteId, skuId: vector.skuId, commercialCaseId: vector.id };\n scenarios.push(scenario({ ...base, suite: \"hermetic\", kind: \"commercial_policy_replay\" }));\n scenarios.push(scenario({ ...base, suite: \"provider_dev\", kind: \"commercial_quote\" }));\n scenarios.push(scenario({ ...base, suite: \"provider_dev\", kind: \"commercial_renewal\" }));\n }\n for (const sku of site.skus.filter((candidate) => candidate.active)) {\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"catalog_contract\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n if (sku.priceCents > 0) {\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"amount_tamper\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"wrong_environment_event\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"post_stripe_compensation\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n for (const sibling of manifest.targets.filter((candidate) => candidate.targetId !== site.targetId)) {\n scenarios.push(scenario({\n suite: \"hermetic\", kind: \"sibling_event_isolation\", targetId: site.targetId, siteId: site.siteId,\n skuId: sku.id, siblingTargetId: sibling.targetId,\n }));\n }\n }\n }\n for (const sku of activeMemberships(site)) {\n scenarios.push(scenario({ suite: \"hermetic\", kind: \"submit_replay\", targetId: site.targetId, siteId: site.siteId, skuId: sku.id }));\n scenarios.push(scenario({\n suite: \"provider_dev\", kind: sku.priceCents > 0 ? \"paid_signup\" : \"free_signup\",\n targetId: site.targetId, siteId: site.siteId, skuId: sku.id,\n }));\n }\n for (const membership of activeMemberships(site)) {\n const base = { targetId: site.targetId, siteId: site.siteId, skuId: membership.id };\n scenarios.push(scenario({ ...base, suite: \"provider_dev\", kind: \"ordinary_interview\" }));\n if (site.options.invitationInterviewWaiver) {\n scenarios.push(scenario({ ...base, suite: \"provider_dev\", kind: \"invitation_interview_waiver\" }));\n scenarios.push(scenario({ ...base, suite: \"hermetic\", kind: \"expired_interview_waiver\" }));\n scenarios.push(scenario({ ...base, suite: \"hermetic\", kind: \"replayed_interview_waiver\" }));\n }\n if (membership.priceCents === 0) continue;\n scenarios.push(scenario({ ...base, suite: \"provider_dev\", kind: \"renewal\" }));\n scenarios.push(scenario({ ...base, suite: \"provider_dev\", kind: \"refund_cancel\" }));\n if (site.options.additionalSeat) {\n const seat = { ...base, skuId: site.options.additionalSeat.skuId, parentSkuId: membership.id };\n for (const kind of [\"named_seat\", \"seat_declined_refund\", \"unaccepted_seat_refund\", \"seat_membership_alignment\"] as const) {\n scenarios.push(scenario({ ...seat, suite: \"provider_dev\", kind }));\n }\n for (const kind of [\"duplicate_seat_email\", \"expired_seat_window\"] as const) {\n scenarios.push(scenario({ ...seat, suite: \"hermetic\", kind }));\n }\n }\n scenarios.push(scenario({ ...base, suite: \"hermetic\", kind: \"canceled_membership\" }));\n }\n }\n return scenarios;\n}\n","import type { ChapterAcceptanceCommercialCase, ChapterAcceptanceSku } from \"./testing-contract\";\n\nconst object = (value: unknown): Record<string, unknown> | null =>\n value !== null && typeof value === \"object\" && !Array.isArray(value) ? value as Record<string, unknown> : null;\nconst id = (value: unknown): boolean => typeof value === \"string\" && /^[a-z0-9][a-z0-9_.:-]{1,159}$/.test(value);\nconst time = (value: unknown): value is number => Number.isSafeInteger(value) && Number(value) > 0;\n\n/** Keep commercial acceptance vectors separate from base SKUs and fail before provider writes. */\nexport function validateCommercialCases(value: unknown, skus: readonly ChapterAcceptanceSku[], path: string): string[] {\n if (value === undefined) return [];\n if (!Array.isArray(value) || !value.length || value.length > 32) return [`${path} must be a non-empty array of at most 32 cases`];\n const errors: string[] = [];\n const ids = new Set<string>();\n for (const [index, raw] of value.entries()) {\n const item = object(raw);\n const at = `${path}[${index}]`;\n if (!item) { errors.push(`${at} must be an object`); continue; }\n if (!id(item.id) || ids.has(String(item.id))) errors.push(`${at}.id must be a unique stable id`);\n ids.add(String(item.id));\n const sku = skus.find(candidate => candidate.id === item.skuId && candidate.active && candidate.kind === \"membership\" && candidate.priceCents > 0);\n if (!sku) errors.push(`${at}.skuId must name an active paid base membership SKU`);\n if (sku?.compareAtPriceCents !== undefined || sku?.discountDuration !== undefined) {\n errors.push(`${at} must not combine a discounted SKU with a separate commercial policy`);\n }\n if (!id(item.offeringVersionId)) errors.push(`${at}.offeringVersionId is required`);\n if (typeof item.founding !== \"boolean\" || (item.founding && !id(item.cohortPolicyVersionId)) ||\n (item.cohortPolicyVersionId !== undefined && !id(item.cohortPolicyVersionId))) errors.push(`${at}.founding requires a stable cohort policy identity`);\n if (!time(item.purchasedAt) || !time(item.initialTermEndsAt) || item.initialTermEndsAt <= item.purchasedAt) {\n errors.push(`${at} must specify a purchase instant and a later initial term end`);\n }\n const discount = object(item.discount);\n if (item.discount !== undefined && (!discount || !id(discount.policyVersionId) ||\n !Number.isInteger(discount.percentOffBps) || Number(discount.percentOffBps) <= 0 || Number(discount.percentOffBps) >= 10000 ||\n ![\"first_term\", \"while_active\", \"fixed_end\"].includes(String(discount.duration)) ||\n (discount.duration === \"fixed_end\" ? !time(discount.endsAt) || Number(discount.endsAt) <= Number(item.purchasedAt) : discount.endsAt !== undefined))) {\n errors.push(`${at}.discount must specify a version, percentage, and explicit expiry policy`);\n }\n if (sku) {\n const due = Math.round(sku.priceCents * (10000 - Number(discount?.percentOffBps ?? 0)) / 10000);\n const ongoing = discount?.duration === \"while_active\" || (discount?.duration === \"fixed_end\" && Number(discount.endsAt) > Number(item.initialTermEndsAt));\n if (item.dueTodayCents !== due || item.renewalCents !== (ongoing ? due : sku.priceCents)) {\n errors.push(`${at} expected initial and renewal amounts must match the separate policy on the base price`);\n }\n }\n }\n return errors;\n}\n\n/** Compare real observed checkout terms against a separately authored acceptance vector. */\nexport function assertCommercialQuote(expected: ChapterAcceptanceCommercialCase, sku: ChapterAcceptanceSku, actual: unknown): boolean {\n const quote = object(actual), lines = object(quote?.lineItems), terms = object(quote?.commercial);\n return Boolean(quote && terms && sku.id === expected.skuId && quote.tierId === expected.skuId &&\n quote.currency === sku.currency && quote.interval === sku.billing && lines?.standardCents === sku.priceCents &&\n lines.discountCents === sku.priceCents - expected.dueTodayCents && lines.dueTodayCents === expected.dueTodayCents &&\n terms.offeringVersionId === expected.offeringVersionId && terms.initialTermEndsAt === expected.initialTermEndsAt &&\n terms.renewalCents === expected.renewalCents && terms.autoRenew === true &&\n terms.discountPolicyVersionId === expected.discount?.policyVersionId &&\n terms.discountDuration === expected.discount?.duration);\n}\n","import type {\n ChapterAcceptanceManifest,\n ChapterAcceptanceTarget,\n ChapterJoinContractFinding,\n ChapterJoinContractProbeResult,\n} from \"./testing-contract\";\nimport { validateChapterAcceptanceManifest } from \"./testing\";\n\nconst MAX_BODY_BYTES = 64 * 1024;\nconst TIMEOUT_MS = 10_000;\n\nfunction record(value: unknown): Record<string, unknown> | null {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? value as Record<string, unknown> : null;\n}\n\nasync function readBoundedJson(response: Response, signal: AbortSignal): Promise<unknown> {\n const reader = response.body?.getReader();\n if (!reader) throw new Error(\"invalid_json\");\n const chunks: Uint8Array[] = [];\n let size = 0;\n const abort = () => { void reader.cancel().catch(() => {}); };\n signal.addEventListener(\"abort\", abort, { once: true });\n try {\n if (signal.aborted) throw new Error(\"response_failed\");\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n size += value.byteLength;\n if (size > MAX_BODY_BYTES) throw new Error(\"response_too_large\");\n chunks.push(value);\n }\n const bytes = new Uint8Array(size);\n let offset = 0;\n for (const chunk of chunks) { bytes.set(chunk, offset); offset += chunk.byteLength; }\n try { return JSON.parse(new TextDecoder().decode(bytes)); }\n catch { throw new Error(\"invalid_json\"); }\n } finally {\n signal.removeEventListener(\"abort\", abort);\n await reader.cancel().catch(() => {});\n reader.releaseLock();\n }\n}\n\ntype ProbeResponse = { status: number; json?: unknown; error?: string; identity?: Record<string, unknown> };\n\nasync function probe(url: string, fetcher: typeof fetch, json: boolean): Promise<ProbeResponse> {\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<ProbeResponse>((resolve) => {\n timer = setTimeout(() => {\n controller.abort();\n resolve({ status: 0, error: \"request_timeout\" });\n }, TIMEOUT_MS);\n });\n try {\n return await Promise.race([timeout, (async (): Promise<ProbeResponse> => {\n let response: Response;\n try {\n response = await fetcher(url, {\n headers: { \"cache-control\": \"no-cache\" }, redirect: \"manual\", signal: controller.signal,\n });\n } catch { return { status: 0, error: \"request_failed\" }; }\n if (!json || !response.ok) {\n await response.body?.cancel().catch(() => {});\n return { status: response.status };\n }\n try {\n return {\n status: response.status, json: await readBoundedJson(response, controller.signal),\n identity: Object.fromEntries([\"app-id\", \"chapter-id\", \"data-environment\", \"runtime\"].map((name) =>\n [name, slug(response.headers.get(`x-odla-${name}`) ?? undefined)])),\n };\n }\n catch (error) {\n const code = error instanceof Error && [\"invalid_json\", \"response_too_large\"].includes(error.message)\n ? error.message : \"response_failed\";\n return { status: response.status, error: code };\n }\n })()]);\n } finally { clearTimeout(timer); }\n}\n\n// Findings are durable CI/PM data, not a mirror of an untrusted HTTP body.\nfunction slug(value: unknown): unknown {\n return value === undefined ? undefined : typeof value === \"string\" && /^[a-z0-9][a-z0-9-]{1,62}$/.test(value) ? value : \"invalid_value\";\n}\nfunction amount(value: unknown): unknown {\n return value === undefined ? undefined : Number.isSafeInteger(value) && Number(value) >= 0 ? value : \"invalid_value\";\n}\nfunction boolean(value: unknown): unknown {\n return value === undefined ? undefined : typeof value === \"boolean\" ? value : \"invalid_value\";\n}\n\nfunction activeMemberships(site: ChapterAcceptanceTarget) {\n return site.skus.filter((sku) => sku.active && sku.kind === \"membership\");\n}\n\n/**\n * Probe public deployed join contracts without creating applications or provider objects.\n * Each request, including its body, is limited to ten seconds and 64 KiB. Redirects\n * are refused. Malformed responses become per-target findings, never raw bodies\n * or exception text; one failed target does not suppress the remaining targets.\n */\nexport async function probeChapterJoinContracts(\n manifest: ChapterAcceptanceManifest,\n fetcher: typeof fetch = fetch,\n): Promise<ChapterJoinContractProbeResult> {\n const validation = validateChapterAcceptanceManifest(manifest);\n if (!validation.ok) throw new TypeError(`invalid Chapter acceptance manifest: ${validation.errors.join(\"; \")}`);\n const findings: ChapterJoinContractFinding[] = [];\n for (const site of manifest.targets) {\n const [health, configResponse] = await Promise.all([\n probe(`${site.origin}/api/health`, fetcher, true),\n probe(`${site.origin}/api/join-config`, fetcher, true),\n ]);\n const targetNote = (path: string, expected: unknown, actual: unknown): void => {\n if (JSON.stringify(expected) !== JSON.stringify(actual)) findings.push({ targetId: site.targetId, siteId: site.siteId, path, expected, actual });\n };\n targetNote(\"/api/health status\", 200, health.error ?? health.status);\n if (health.status === 200 && !health.error) targetNote(\"/api/health ok\", true, boolean(record(health.json)?.ok));\n if (health.status === 200 && !health.error) {\n for (const [name, expected] of Object.entries({\n \"app-id\": site.target.appId, \"chapter-id\": site.target.chapterId,\n \"data-environment\": site.target.dataEnvironment, \"runtime\": site.target.runtime,\n })) targetNote(`/api/health x-odla-${name}`, expected, health.identity?.[name]);\n }\n targetNote(\"/api/join-config status\", 200, configResponse.status || configResponse.error);\n if (configResponse.status !== 200) continue;\n if (configResponse.error) {\n targetNote(\"/api/join-config JSON\", \"object\", configResponse.error === \"invalid_json\" ? \"invalid JSON\" : configResponse.error);\n continue;\n }\n const config = record(configResponse.json);\n if (!config) {\n targetNote(\"/api/join-config JSON\", \"object\", \"invalid shape\");\n continue;\n }\n targetNote(\"id\", site.target.chapterId, slug(config.id));\n const actualTiers = Array.isArray(config.tiers) ? config.tiers : [];\n const expectedTiers = activeMemberships(site).map((sku) => ({\n id: sku.id, priceCents: sku.priceCents, currency: sku.currency,\n interval: sku.billing, free: sku.priceCents === 0,\n }));\n const projected = actualTiers.map((tier) => {\n const value = record(tier);\n if (!value) return \"invalid_tier\";\n return {\n id: slug(value.id), priceCents: amount(value.priceCents),\n currency: value.currency === undefined ? undefined : typeof value.currency === \"string\" && /^[a-z]{3}$/.test(value.currency) ? value.currency : \"invalid_value\",\n interval: value.interval === undefined ? undefined : [\"month\", \"year\", \"once\"].includes(String(value.interval)) ? value.interval : \"invalid_value\",\n free: boolean(value.free),\n };\n });\n targetNote(\"tiers\", expectedTiers, projected);\n targetNote(\"paymentsReady\", expectedTiers.some((tier) => !tier.free), boolean(config.paymentsReady));\n }\n return { ok: findings.length === 0, findings };\n}\n","import type {\n ChapterAcceptanceCaseResult,\n ChapterAcceptanceCleanupEvidence,\n ChapterAcceptanceEvidence,\n ChapterAcceptanceExecutionContext,\n ChapterAcceptanceExecutor,\n ChapterAcceptanceManifest,\n ChapterAcceptanceProviderReference,\n ChapterAcceptanceRunResult,\n} from \"./testing-contract\";\nimport { planChapterAcceptanceMatrix } from \"./testing\";\n\nconst SAFE_LABEL = /^[a-z0-9][a-z0-9._:-]{0,159}$/;\nconst SAFE_REFERENCE = /^[A-Za-z0-9_:.=-]{3,240}$/;\nconst CREDENTIAL = /(?:^|[_.:-])(?:sk|rk|pk)_(?:test|live)_|whsec_|_secret_|eyJ[A-Za-z0-9_-]+\\./i;\nconst ERROR_CODES = new Set([\"invalid_evidence\", \"assertion_failed\", \"preflight_failed\", \"unsupported_scenario\", \"execution_failed\"]);\n\nfunction safeValue(value: string, pattern: RegExp): boolean {\n return pattern.test(value) && !CREDENTIAL.test(value);\n}\n\nfunction safeErrorCode(error: unknown): string {\n if (error && typeof error === \"object\") {\n const code = (error as { code?: unknown }).code;\n if (typeof code === \"string\" && ERROR_CODES.has(code)) return code;\n }\n return \"execution_failed\";\n}\n\nfunction validateLabels(values: readonly string[], path: string): void {\n if (!Array.isArray(values) || values.length === 0) throw Object.assign(new TypeError(`${path} must be non-empty`), { code: \"invalid_evidence\" });\n if (values.length > 64 || values.some((value) => typeof value !== \"string\" || !safeValue(value, SAFE_LABEL))) {\n throw Object.assign(new TypeError(`${path} contains an unsafe or unbounded label`), { code: \"invalid_evidence\" });\n }\n}\n\nfunction validateReferences(values: readonly ChapterAcceptanceProviderReference[] | undefined): void {\n if (values === undefined) return;\n if (!Array.isArray(values) || values.length > 64) throw Object.assign(new TypeError(\"references must be bounded\"), { code: \"invalid_evidence\" });\n const kinds = new Set([\"stripe_event\", \"stripe_object\", \"clerk_user\", \"calendar_event\", \"email_message\", \"event_digest\"]);\n for (const reference of values) {\n if (!reference || !kinds.has(reference.kind) || typeof reference.value !== \"string\" ||\n !safeValue(reference.value, SAFE_REFERENCE) || reference.value.includes(\"@\")) {\n throw Object.assign(new TypeError(\"references may contain only opaque provider ids or digests\"), { code: \"invalid_evidence\" });\n }\n }\n}\n\nfunction validateEvidence(evidence: ChapterAcceptanceEvidence, provider: boolean): ChapterAcceptanceEvidence {\n if (!evidence || typeof evidence !== \"object\") throw Object.assign(new TypeError(\"executor returned no evidence\"), { code: \"invalid_evidence\" });\n validateLabels(evidence.checks, \"evidence.checks\");\n validateReferences(evidence.references);\n if ((provider || evidence.deploymentVersion !== undefined) &&\n (typeof evidence.deploymentVersion !== \"string\" || !safeValue(evidence.deploymentVersion, SAFE_REFERENCE))) {\n throw Object.assign(new TypeError(\"provider evidence requires a safe deploymentVersion\"), { code: \"invalid_evidence\" });\n }\n // Copy only the validated wire contract. Never retain provider response objects,\n // extra fields, custom toJSON methods, or arrays that an adapter can later mutate.\n return {\n checks: [...evidence.checks],\n ...(evidence.deploymentVersion !== undefined ? { deploymentVersion: evidence.deploymentVersion } : {}),\n ...(evidence.references !== undefined ? {\n references: evidence.references.map(({ kind, value }) => ({ kind, value })),\n } : {}),\n };\n}\n\nfunction validateCleanup(cleanup: ChapterAcceptanceCleanupEvidence): ChapterAcceptanceCleanupEvidence {\n if (!cleanup || (cleanup.status !== \"complete\" && cleanup.status !== \"incomplete\")) {\n throw Object.assign(new TypeError(\"executor returned invalid cleanup evidence\"), { code: \"cleanup_failed\" });\n }\n validateLabels(cleanup.checks, \"cleanup.checks\");\n return { status: cleanup.status, checks: [...cleanup.checks] };\n}\n\nfunction contextFor(manifest: ChapterAcceptanceManifest, id: string): ChapterAcceptanceExecutionContext {\n const scenario = planChapterAcceptanceMatrix(manifest).find((item) => item.id === id);\n if (!scenario) throw new TypeError(`unknown acceptance scenario ${id}`);\n const target = manifest.targets.find((item) => item.targetId === scenario.targetId)!;\n return {\n scenario,\n target,\n ...(scenario.skuId ? { sku: target.skus.find((item) => item.id === scenario.skuId) } : {}),\n ...(scenario.parentSkuId ? { parentSku: target.skus.find((item) => item.id === scenario.parentSkuId) } : {}),\n ...(scenario.commercialCaseId ? { commercialCase: target.commercialCases?.find(item => item.id === scenario.commercialCaseId) } : {}),\n ...(scenario.siblingTargetId ? {\n siblingTarget: manifest.targets.find((item) => item.targetId === scenario.siblingTargetId),\n } : {}),\n };\n}\n\n/**\n * Execute one suite serially. Provider runs fail before their first mutation\n * unless the app supplies cleanup, then invoke cleanup after every attempted\n * case even when execution throws. Unconfirmed cleanup stops subsequent cases;\n * those cases fail with `not_run_cleanup_failed` and are never executed.\n * Evidence is copied only after validation; raw provider errors and extra fields\n * are never retained. Adapter check labels must not contain personal data.\n */\nexport async function runChapterAcceptanceSuite(\n manifest: ChapterAcceptanceManifest,\n suite: \"hermetic\" | \"provider_dev\",\n executor: ChapterAcceptanceExecutor,\n): Promise<ChapterAcceptanceRunResult> {\n if (suite !== \"hermetic\" && suite !== \"provider_dev\") throw new TypeError(\"unknown acceptance suite\");\n const scenarios = planChapterAcceptanceMatrix(manifest).filter((item) => item.suite === suite);\n if (suite === \"provider_dev\" && typeof executor.cleanup !== \"function\") {\n throw new TypeError(\"provider_dev acceptance requires a cleanup executor before any case can run\");\n }\n const cases: ChapterAcceptanceCaseResult[] = [];\n let cleanupFailed = false;\n for (const scenario of scenarios) {\n if (cleanupFailed) {\n cases.push({ id: scenario.id, suite, outcome: \"failed\", errorCode: \"not_run_cleanup_failed\" });\n continue;\n }\n const context = contextFor(manifest, scenario.id);\n let evidence: ChapterAcceptanceEvidence | undefined;\n let errorCode: string | undefined;\n let cleanup: ChapterAcceptanceCleanupEvidence | undefined;\n try {\n evidence = validateEvidence(await executor.execute(context), suite === \"provider_dev\");\n } catch (error) {\n errorCode = safeErrorCode(error);\n } finally {\n if (suite === \"provider_dev\") {\n try {\n cleanup = validateCleanup(await executor.cleanup!(context));\n if (cleanup.status !== \"complete\") {\n cleanupFailed = true;\n errorCode = \"cleanup_incomplete\";\n }\n } catch {\n cleanupFailed = true;\n errorCode = \"cleanup_failed\";\n }\n }\n }\n cases.push({\n id: scenario.id,\n suite,\n outcome: errorCode ? \"failed\" : \"passed\",\n ...(evidence ? { evidence } : {}),\n ...(cleanup ? { cleanup } : {}),\n ...(errorCode ? { errorCode } : {}),\n });\n }\n return { ok: cases.every((item) => item.outcome === \"passed\"), suite, cases };\n}\n\n/** PII-free line report suitable for CI logs and PM evidence. */\nexport function formatChapterAcceptanceRun(result: ChapterAcceptanceRunResult): string {\n const passed = result.cases.filter((item) => item.outcome === \"passed\").length;\n const lines = [`${result.ok ? \"ok\" : \"failed\"}: ${result.suite} ${passed}/${result.cases.length}`];\n for (const item of result.cases) {\n lines.push(`${item.outcome === \"passed\" ? \"PASS\" : \"FAIL\"} ${item.id}${item.errorCode ? ` ${item.errorCode}` : \"\"}`);\n }\n return lines.join(\"\\n\");\n}\n","/** A release proof is tied to a reviewed source commit and one exact dev deployment. */\nexport interface ChapterReleaseTarget {\n targetId: string;\n appId: string;\n chapterId: string;\n runtime: string;\n environment: \"dev\";\n dataEnvironment: \"dev\";\n stripeMode: \"test\";\n sourceCommit: string;\n deploymentVersion: string;\n}\n\n/** Required behavior is defined independently of currently enabled feature flags. */\nexport interface ChapterReleaseRequirement {\n id: string;\n targetId: string;\n phase: \"deterministic\" | \"deployed_contract\" | \"provider_dev\" | \"browser_dev\";\n assertions: readonly string[];\n /** Each provider kind needs at least one opaque id/digest from the real attempt. */\n providers: readonly (\"stripe\" | \"clerk\" | \"calendar\" | \"email\")[];\n cleanup: readonly string[];\n}\n\n/** An independent release contract, not a list inferred from whichever tests happened to run. */\nexport interface ChapterReleasePlan {\n schemaVersion: 1;\n targets: readonly ChapterReleaseTarget[];\n requirements: readonly ChapterReleaseRequirement[];\n}\n\n/** Structured result from an actual driver; this completeness check does not execute or authenticate a driver. */\nexport interface ChapterReleaseProof {\n requirementId: string;\n target: ChapterReleaseTarget;\n phase: ChapterReleaseRequirement[\"phase\"];\n outcome: \"passed\" | \"failed\" | \"blocked\";\n assertions: Readonly<Record<string, boolean>>;\n references: readonly { provider: ChapterReleaseRequirement[\"providers\"][number]; id: string }[];\n cleanup: Readonly<Record<string, boolean>>;\n}\n\n/** Bounded release blockers. Passing requests a human review, never permission to deploy. */\nexport interface ChapterReleaseAssessment {\n readyForReview: boolean;\n productionAuthorized: false;\n required: number;\n passed: number;\n blockers: readonly { requirementId: string; code: string }[];\n}\n\nconst ID = /^[a-z0-9][a-z0-9_.:-]{1,199}$/;\nconst validId = (value: unknown): value is string => typeof value === \"string\" && ID.test(value);\nconst opaque = (value: unknown): value is string => typeof value === \"string\" &&\n /^[A-Za-z0-9][A-Za-z0-9_:-]{2,159}$/.test(value) && !/(?:sk|rk|pk|whsec)_(?:test_|live_)?|_secret_|bearer|password|token/i.test(value);\nconst keys = [\"targetId\", \"appId\", \"chapterId\", \"runtime\", \"environment\", \"dataEnvironment\", \"stripeMode\", \"sourceCommit\", \"deploymentVersion\"] as const;\n\n/**\n * Require a complete, exact-candidate release evidence set. Missing, duplicate,\n * failed, stale, wrong-runtime, skipped, or incompletely cleaned attempts block\n * review. This is evidence validation, not provider execution: callers must use\n * real drivers and retain their independently inspectable run artifacts.\n */\nexport function assessChapterReleaseEvidence(plan: ChapterReleasePlan, proofs: readonly ChapterReleaseProof[]): ChapterReleaseAssessment {\n const blockers: { requirementId: string; code: string }[] = [];\n const block = (requirementId: string, code: string) => blockers.push({ requirementId, code });\n const targets = new Map<string, ChapterReleaseTarget>();\n if (!plan || plan.schemaVersion !== 1 || !Array.isArray(plan.targets) || !plan.targets.length ||\n plan.targets.length > 64 || !Array.isArray(plan.requirements) || !plan.requirements.length ||\n plan.requirements.length > 4096 || !Array.isArray(proofs) || proofs.length > 8192) {\n return { readyForReview: false, productionAuthorized: false, required: 0, passed: 0,\n blockers: [{ requirementId: \"plan\", code: \"invalid_release_plan\" }] };\n }\n for (const target of plan.targets) {\n if (!target || !validId(target.targetId) || targets.has(target.targetId) ||\n ![target.appId, target.chapterId, target.runtime].every(validId) ||\n target.environment !== \"dev\" || target.dataEnvironment !== \"dev\" || target.stripeMode !== \"test\" ||\n typeof target.sourceCommit !== \"string\" || !/^[0-9a-f]{40}$/.test(target.sourceCommit) || !opaque(target.deploymentVersion)) {\n block(\"plan\", \"invalid_or_undeployed_target\");\n continue;\n }\n targets.set(target.targetId, target);\n }\n const requirementIds = new Set<string>();\n let passed = 0;\n for (const requirement of plan.requirements) {\n if (!requirement || !validId(requirement.id) || requirementIds.has(requirement.id) ||\n ![\"deterministic\", \"deployed_contract\", \"provider_dev\", \"browser_dev\"].includes(requirement.phase) ||\n !Array.isArray(requirement.assertions) || !requirement.assertions.length ||\n !requirement.assertions.every(validId) || new Set(requirement.assertions).size !== requirement.assertions.length ||\n !Array.isArray(requirement.providers) || requirement.providers.some((kind: string) => ![\"stripe\", \"clerk\", \"calendar\", \"email\"].includes(kind)) ||\n !Array.isArray(requirement.cleanup) || !requirement.cleanup.every(validId) ||\n (requirement.phase === \"provider_dev\" && (!requirement.providers.length || !requirement.cleanup.length))) {\n block(\"plan\", \"invalid_requirement\");\n continue;\n }\n requirementIds.add(requirement.id);\n const target = targets.get(requirement.targetId);\n if (!target) { block(requirement.id, \"missing_candidate_target\"); continue; }\n const matching = proofs.filter((proof) => proof?.requirementId === requirement.id);\n if (matching.length !== 1) { block(requirement.id, matching.length ? \"duplicate_proof\" : \"missing_proof\"); continue; }\n const proof = matching[0]!;\n const before = blockers.length;\n if (!proof.target || keys.some((key) => proof.target[key] !== target[key])) block(requirement.id, \"candidate_mismatch\");\n if (proof.phase !== requirement.phase) block(requirement.id, \"wrong_execution_phase\");\n if (proof.outcome !== \"passed\") block(requirement.id, \"attempt_not_passed\");\n if (!proof.assertions || requirement.assertions.some((id: string) => proof.assertions[id] !== true)) block(requirement.id, \"assertions_incomplete\");\n if (!Array.isArray(proof.references) || proof.references.some((reference: ChapterReleaseProof[\"references\"][number]) => !reference || !opaque(reference.id) ||\n ![\"stripe\", \"clerk\", \"calendar\", \"email\"].includes(reference.provider)) ||\n requirement.providers.some((provider: string) => !proof.references.some((reference: ChapterReleaseProof[\"references\"][number]) => reference.provider === provider))) block(requirement.id, \"provider_evidence_incomplete\");\n if (!proof.cleanup || requirement.cleanup.some((id: string) => proof.cleanup[id] !== true)) block(requirement.id, \"cleanup_incomplete\");\n if (blockers.length === before) passed++;\n }\n if (proofs.some((proof) => !proof || !requirementIds.has(proof.requirementId))) block(\"plan\", \"unexpected_proof\");\n for (const target of targets.values()) {\n if (!plan.requirements.some((requirement) => requirement?.targetId === target.targetId)) block(\"plan\", \"uncovered_target\");\n }\n return { readyForReview: blockers.length === 0, productionAuthorized: false, required: plan.requirements.length, passed, blockers };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;A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AAY;AACzH,oBAAU,KAAK,SAAS,EAAE,GAAG,MAAM,OAAO,gBAAgB,KAAK,CAAC,CAAC;AAAA,QACnE;AACA,mBAAW,QAAQ,CAAC,wBAAwB,qBAAqB,GAAY;AAC3E,oBAAU,KAAK,SAAS,EAAE,GAAG,MAAM,OAAO,YAAY,KAAK,CAAC,CAAC;AAAA,QAC/D;AAAA,MACF;AACA,gBAAU,KAAK,SAAS,EAAE,GAAG,MAAM,OAAO,YAAY,MAAM,sBAAsB,CAAC,CAAC;AAAA,IACtF;AAAA,EACF;AACA,SAAO;AACT;","names":["id","scenario","proof","id","activeMemberships","record","id"]}
@@ -14,6 +14,27 @@ interface ChapterAcceptanceSku {
14
14
  /** How long the difference from compareAtPriceCents is retained. */
15
15
  discountDuration?: "first_term" | "while_active";
16
16
  }
17
+ /** Explicit expected terms at a test-clock instant, independent of the SKU price.
18
+ * These are acceptance assertions, never permission to issue an offer or change Stripe.
19
+ */
20
+ interface ChapterAcceptanceCommercialCase {
21
+ id: string;
22
+ skuId: string;
23
+ purchasedAt: number;
24
+ offeringVersionId: string;
25
+ founding: boolean;
26
+ /** Cohort policy may apply to a Steward without granting a price discount. */
27
+ cohortPolicyVersionId?: string;
28
+ dueTodayCents: number;
29
+ initialTermEndsAt: number;
30
+ renewalCents: number;
31
+ discount?: {
32
+ policyVersionId: string;
33
+ percentOffBps: number;
34
+ duration: "first_term" | "while_active" | "fixed_end";
35
+ endsAt?: number;
36
+ };
37
+ }
17
38
  /** Named-seat behavior that must be exercised as a membership add-on. */
18
39
  interface ChapterAcceptanceSeatOption {
19
40
  skuId: string;
@@ -45,6 +66,7 @@ interface ChapterAcceptanceTarget {
45
66
  stripeMode: "test" | "live";
46
67
  skus: readonly ChapterAcceptanceSku[];
47
68
  options: ChapterAcceptanceOptions;
69
+ commercialCases?: readonly ChapterAcceptanceCommercialCase[];
48
70
  }
49
71
  /** Complete multi-site contract consumed by hermetic and deployed-dev tests. */
50
72
  interface ChapterAcceptanceManifest {
@@ -60,7 +82,7 @@ type ChapterAcceptanceValidation = {
60
82
  errors: readonly string[];
61
83
  };
62
84
  /** Closed set of deterministic and provider-backed acceptance behaviors. */
63
- type ChapterAcceptanceScenarioKind = "catalog_contract" | "amount_tamper" | "wrong_environment_event" | "sibling_event_isolation" | "submit_replay" | "post_stripe_compensation" | "paid_signup" | "free_signup" | "ordinary_interview" | "invitation_interview_waiver" | "expired_interview_waiver" | "replayed_interview_waiver" | "named_seat" | "duplicate_seat_email" | "expired_seat_window" | "canceled_membership" | "renewal" | "refund_cancel";
85
+ type ChapterAcceptanceScenarioKind = "catalog_contract" | "commercial_quote" | "commercial_renewal" | "commercial_policy_replay" | "amount_tamper" | "wrong_environment_event" | "sibling_event_isolation" | "submit_replay" | "post_stripe_compensation" | "paid_signup" | "free_signup" | "ordinary_interview" | "invitation_interview_waiver" | "expired_interview_waiver" | "replayed_interview_waiver" | "named_seat" | "duplicate_seat_email" | "expired_seat_window" | "seat_declined_refund" | "unaccepted_seat_refund" | "seat_membership_alignment" | "canceled_membership" | "renewal" | "refund_cancel";
64
86
  /** One stable generated case. Provider cases are opt-in and test-mode only. */
65
87
  interface ChapterAcceptanceScenario {
66
88
  id: string;
@@ -69,6 +91,9 @@ interface ChapterAcceptanceScenario {
69
91
  targetId: string;
70
92
  siteId: string;
71
93
  skuId?: string;
94
+ /** Membership whose add-on path is exercised; never assume the first paid SKU. */
95
+ parentSkuId?: string;
96
+ commercialCaseId?: string;
72
97
  siblingTargetId?: string;
73
98
  }
74
99
  /** Public response shape needed by the non-mutating deployed contract probe. */
@@ -95,6 +120,8 @@ interface ChapterAcceptanceExecutionContext {
95
120
  scenario: ChapterAcceptanceScenario;
96
121
  target: ChapterAcceptanceTarget;
97
122
  sku?: ChapterAcceptanceSku;
123
+ parentSku?: ChapterAcceptanceSku;
124
+ commercialCase?: ChapterAcceptanceCommercialCase;
98
125
  siblingTarget?: ChapterAcceptanceTarget;
99
126
  }
100
127
  /** Provider references permitted in durable evidence. Values must be opaque ids or digests, never PII. */
@@ -137,18 +164,89 @@ interface ChapterAcceptanceRunResult {
137
164
  cases: ChapterAcceptanceCaseResult[];
138
165
  }
139
166
 
140
- /** Probe public deployed join contracts without creating applications or provider objects. */
167
+ /** Compare real observed checkout terms against a separately authored acceptance vector. */
168
+ declare function assertCommercialQuote(expected: ChapterAcceptanceCommercialCase, sku: ChapterAcceptanceSku, actual: unknown): boolean;
169
+
170
+ /**
171
+ * Probe public deployed join contracts without creating applications or provider objects.
172
+ * Each request, including its body, is limited to ten seconds and 64 KiB. Redirects
173
+ * are refused. Malformed responses become per-target findings, never raw bodies
174
+ * or exception text; one failed target does not suppress the remaining targets.
175
+ */
141
176
  declare function probeChapterJoinContracts(manifest: ChapterAcceptanceManifest, fetcher?: typeof fetch): Promise<ChapterJoinContractProbeResult>;
142
177
 
143
178
  /**
144
179
  * Execute one suite serially. Provider runs fail before their first mutation
145
180
  * unless the app supplies cleanup, then invoke cleanup after every attempted
146
- * case even when execution throws. Raw provider error text is never retained.
181
+ * case even when execution throws. Unconfirmed cleanup stops subsequent cases;
182
+ * those cases fail with `not_run_cleanup_failed` and are never executed.
183
+ * Evidence is copied only after validation; raw provider errors and extra fields
184
+ * are never retained. Adapter check labels must not contain personal data.
147
185
  */
148
186
  declare function runChapterAcceptanceSuite(manifest: ChapterAcceptanceManifest, suite: "hermetic" | "provider_dev", executor: ChapterAcceptanceExecutor): Promise<ChapterAcceptanceRunResult>;
149
187
  /** PII-free line report suitable for CI logs and PM evidence. */
150
188
  declare function formatChapterAcceptanceRun(result: ChapterAcceptanceRunResult): string;
151
189
 
190
+ /** A release proof is tied to a reviewed source commit and one exact dev deployment. */
191
+ interface ChapterReleaseTarget {
192
+ targetId: string;
193
+ appId: string;
194
+ chapterId: string;
195
+ runtime: string;
196
+ environment: "dev";
197
+ dataEnvironment: "dev";
198
+ stripeMode: "test";
199
+ sourceCommit: string;
200
+ deploymentVersion: string;
201
+ }
202
+ /** Required behavior is defined independently of currently enabled feature flags. */
203
+ interface ChapterReleaseRequirement {
204
+ id: string;
205
+ targetId: string;
206
+ phase: "deterministic" | "deployed_contract" | "provider_dev" | "browser_dev";
207
+ assertions: readonly string[];
208
+ /** Each provider kind needs at least one opaque id/digest from the real attempt. */
209
+ providers: readonly ("stripe" | "clerk" | "calendar" | "email")[];
210
+ cleanup: readonly string[];
211
+ }
212
+ /** An independent release contract, not a list inferred from whichever tests happened to run. */
213
+ interface ChapterReleasePlan {
214
+ schemaVersion: 1;
215
+ targets: readonly ChapterReleaseTarget[];
216
+ requirements: readonly ChapterReleaseRequirement[];
217
+ }
218
+ /** Structured result from an actual driver; this completeness check does not execute or authenticate a driver. */
219
+ interface ChapterReleaseProof {
220
+ requirementId: string;
221
+ target: ChapterReleaseTarget;
222
+ phase: ChapterReleaseRequirement["phase"];
223
+ outcome: "passed" | "failed" | "blocked";
224
+ assertions: Readonly<Record<string, boolean>>;
225
+ references: readonly {
226
+ provider: ChapterReleaseRequirement["providers"][number];
227
+ id: string;
228
+ }[];
229
+ cleanup: Readonly<Record<string, boolean>>;
230
+ }
231
+ /** Bounded release blockers. Passing requests a human review, never permission to deploy. */
232
+ interface ChapterReleaseAssessment {
233
+ readyForReview: boolean;
234
+ productionAuthorized: false;
235
+ required: number;
236
+ passed: number;
237
+ blockers: readonly {
238
+ requirementId: string;
239
+ code: string;
240
+ }[];
241
+ }
242
+ /**
243
+ * Require a complete, exact-candidate release evidence set. Missing, duplicate,
244
+ * failed, stale, wrong-runtime, skipped, or incompletely cleaned attempts block
245
+ * review. This is evidence validation, not provider execution: callers must use
246
+ * real drivers and retain their independently inspectable run artifacts.
247
+ */
248
+ declare function assessChapterReleaseEvidence(plan: ChapterReleasePlan, proofs: readonly ChapterReleaseProof[]): ChapterReleaseAssessment;
249
+
152
250
  /** Validate the exact facts a multi-site acceptance run needs before it writes anywhere. */
153
251
  declare function validateChapterAcceptanceManifest(value: unknown): ChapterAcceptanceValidation;
154
252
  /**
@@ -157,4 +255,4 @@ declare function validateChapterAcceptanceManifest(value: unknown): ChapterAccep
157
255
  */
158
256
  declare function planChapterAcceptanceMatrix(manifest: ChapterAcceptanceManifest): ChapterAcceptanceScenario[];
159
257
 
160
- export { type ChapterAcceptanceCaseResult, type ChapterAcceptanceCleanupEvidence, type ChapterAcceptanceEvidence, type ChapterAcceptanceExecutionContext, type ChapterAcceptanceExecutor, type ChapterAcceptanceManifest, type ChapterAcceptanceOptions, type ChapterAcceptanceProviderReference, type ChapterAcceptanceRunResult, type ChapterAcceptanceScenario, type ChapterAcceptanceScenarioKind, type ChapterAcceptanceSeatOption, type ChapterAcceptanceSku, type ChapterAcceptanceTarget, type ChapterAcceptanceValidation, type ChapterJoinConfigProbe, type ChapterJoinContractFinding, type ChapterJoinContractProbeResult, formatChapterAcceptanceRun, planChapterAcceptanceMatrix, probeChapterJoinContracts, runChapterAcceptanceSuite, validateChapterAcceptanceManifest };
258
+ export { type ChapterAcceptanceCaseResult, type ChapterAcceptanceCleanupEvidence, type ChapterAcceptanceCommercialCase, type ChapterAcceptanceEvidence, type ChapterAcceptanceExecutionContext, type ChapterAcceptanceExecutor, type ChapterAcceptanceManifest, type ChapterAcceptanceOptions, type ChapterAcceptanceProviderReference, type ChapterAcceptanceRunResult, type ChapterAcceptanceScenario, type ChapterAcceptanceScenarioKind, type ChapterAcceptanceSeatOption, type ChapterAcceptanceSku, type ChapterAcceptanceTarget, type ChapterAcceptanceValidation, type ChapterJoinConfigProbe, type ChapterJoinContractFinding, type ChapterJoinContractProbeResult, type ChapterReleaseAssessment, type ChapterReleasePlan, type ChapterReleaseProof, type ChapterReleaseRequirement, type ChapterReleaseTarget, assertCommercialQuote, assessChapterReleaseEvidence, formatChapterAcceptanceRun, planChapterAcceptanceMatrix, probeChapterJoinContracts, runChapterAcceptanceSuite, validateChapterAcceptanceManifest };
package/dist/testing.d.ts CHANGED
@@ -14,6 +14,27 @@ interface ChapterAcceptanceSku {
14
14
  /** How long the difference from compareAtPriceCents is retained. */
15
15
  discountDuration?: "first_term" | "while_active";
16
16
  }
17
+ /** Explicit expected terms at a test-clock instant, independent of the SKU price.
18
+ * These are acceptance assertions, never permission to issue an offer or change Stripe.
19
+ */
20
+ interface ChapterAcceptanceCommercialCase {
21
+ id: string;
22
+ skuId: string;
23
+ purchasedAt: number;
24
+ offeringVersionId: string;
25
+ founding: boolean;
26
+ /** Cohort policy may apply to a Steward without granting a price discount. */
27
+ cohortPolicyVersionId?: string;
28
+ dueTodayCents: number;
29
+ initialTermEndsAt: number;
30
+ renewalCents: number;
31
+ discount?: {
32
+ policyVersionId: string;
33
+ percentOffBps: number;
34
+ duration: "first_term" | "while_active" | "fixed_end";
35
+ endsAt?: number;
36
+ };
37
+ }
17
38
  /** Named-seat behavior that must be exercised as a membership add-on. */
18
39
  interface ChapterAcceptanceSeatOption {
19
40
  skuId: string;
@@ -45,6 +66,7 @@ interface ChapterAcceptanceTarget {
45
66
  stripeMode: "test" | "live";
46
67
  skus: readonly ChapterAcceptanceSku[];
47
68
  options: ChapterAcceptanceOptions;
69
+ commercialCases?: readonly ChapterAcceptanceCommercialCase[];
48
70
  }
49
71
  /** Complete multi-site contract consumed by hermetic and deployed-dev tests. */
50
72
  interface ChapterAcceptanceManifest {
@@ -60,7 +82,7 @@ type ChapterAcceptanceValidation = {
60
82
  errors: readonly string[];
61
83
  };
62
84
  /** Closed set of deterministic and provider-backed acceptance behaviors. */
63
- type ChapterAcceptanceScenarioKind = "catalog_contract" | "amount_tamper" | "wrong_environment_event" | "sibling_event_isolation" | "submit_replay" | "post_stripe_compensation" | "paid_signup" | "free_signup" | "ordinary_interview" | "invitation_interview_waiver" | "expired_interview_waiver" | "replayed_interview_waiver" | "named_seat" | "duplicate_seat_email" | "expired_seat_window" | "canceled_membership" | "renewal" | "refund_cancel";
85
+ type ChapterAcceptanceScenarioKind = "catalog_contract" | "commercial_quote" | "commercial_renewal" | "commercial_policy_replay" | "amount_tamper" | "wrong_environment_event" | "sibling_event_isolation" | "submit_replay" | "post_stripe_compensation" | "paid_signup" | "free_signup" | "ordinary_interview" | "invitation_interview_waiver" | "expired_interview_waiver" | "replayed_interview_waiver" | "named_seat" | "duplicate_seat_email" | "expired_seat_window" | "seat_declined_refund" | "unaccepted_seat_refund" | "seat_membership_alignment" | "canceled_membership" | "renewal" | "refund_cancel";
64
86
  /** One stable generated case. Provider cases are opt-in and test-mode only. */
65
87
  interface ChapterAcceptanceScenario {
66
88
  id: string;
@@ -69,6 +91,9 @@ interface ChapterAcceptanceScenario {
69
91
  targetId: string;
70
92
  siteId: string;
71
93
  skuId?: string;
94
+ /** Membership whose add-on path is exercised; never assume the first paid SKU. */
95
+ parentSkuId?: string;
96
+ commercialCaseId?: string;
72
97
  siblingTargetId?: string;
73
98
  }
74
99
  /** Public response shape needed by the non-mutating deployed contract probe. */
@@ -95,6 +120,8 @@ interface ChapterAcceptanceExecutionContext {
95
120
  scenario: ChapterAcceptanceScenario;
96
121
  target: ChapterAcceptanceTarget;
97
122
  sku?: ChapterAcceptanceSku;
123
+ parentSku?: ChapterAcceptanceSku;
124
+ commercialCase?: ChapterAcceptanceCommercialCase;
98
125
  siblingTarget?: ChapterAcceptanceTarget;
99
126
  }
100
127
  /** Provider references permitted in durable evidence. Values must be opaque ids or digests, never PII. */
@@ -137,18 +164,89 @@ interface ChapterAcceptanceRunResult {
137
164
  cases: ChapterAcceptanceCaseResult[];
138
165
  }
139
166
 
140
- /** Probe public deployed join contracts without creating applications or provider objects. */
167
+ /** Compare real observed checkout terms against a separately authored acceptance vector. */
168
+ declare function assertCommercialQuote(expected: ChapterAcceptanceCommercialCase, sku: ChapterAcceptanceSku, actual: unknown): boolean;
169
+
170
+ /**
171
+ * Probe public deployed join contracts without creating applications or provider objects.
172
+ * Each request, including its body, is limited to ten seconds and 64 KiB. Redirects
173
+ * are refused. Malformed responses become per-target findings, never raw bodies
174
+ * or exception text; one failed target does not suppress the remaining targets.
175
+ */
141
176
  declare function probeChapterJoinContracts(manifest: ChapterAcceptanceManifest, fetcher?: typeof fetch): Promise<ChapterJoinContractProbeResult>;
142
177
 
143
178
  /**
144
179
  * Execute one suite serially. Provider runs fail before their first mutation
145
180
  * unless the app supplies cleanup, then invoke cleanup after every attempted
146
- * case even when execution throws. Raw provider error text is never retained.
181
+ * case even when execution throws. Unconfirmed cleanup stops subsequent cases;
182
+ * those cases fail with `not_run_cleanup_failed` and are never executed.
183
+ * Evidence is copied only after validation; raw provider errors and extra fields
184
+ * are never retained. Adapter check labels must not contain personal data.
147
185
  */
148
186
  declare function runChapterAcceptanceSuite(manifest: ChapterAcceptanceManifest, suite: "hermetic" | "provider_dev", executor: ChapterAcceptanceExecutor): Promise<ChapterAcceptanceRunResult>;
149
187
  /** PII-free line report suitable for CI logs and PM evidence. */
150
188
  declare function formatChapterAcceptanceRun(result: ChapterAcceptanceRunResult): string;
151
189
 
190
+ /** A release proof is tied to a reviewed source commit and one exact dev deployment. */
191
+ interface ChapterReleaseTarget {
192
+ targetId: string;
193
+ appId: string;
194
+ chapterId: string;
195
+ runtime: string;
196
+ environment: "dev";
197
+ dataEnvironment: "dev";
198
+ stripeMode: "test";
199
+ sourceCommit: string;
200
+ deploymentVersion: string;
201
+ }
202
+ /** Required behavior is defined independently of currently enabled feature flags. */
203
+ interface ChapterReleaseRequirement {
204
+ id: string;
205
+ targetId: string;
206
+ phase: "deterministic" | "deployed_contract" | "provider_dev" | "browser_dev";
207
+ assertions: readonly string[];
208
+ /** Each provider kind needs at least one opaque id/digest from the real attempt. */
209
+ providers: readonly ("stripe" | "clerk" | "calendar" | "email")[];
210
+ cleanup: readonly string[];
211
+ }
212
+ /** An independent release contract, not a list inferred from whichever tests happened to run. */
213
+ interface ChapterReleasePlan {
214
+ schemaVersion: 1;
215
+ targets: readonly ChapterReleaseTarget[];
216
+ requirements: readonly ChapterReleaseRequirement[];
217
+ }
218
+ /** Structured result from an actual driver; this completeness check does not execute or authenticate a driver. */
219
+ interface ChapterReleaseProof {
220
+ requirementId: string;
221
+ target: ChapterReleaseTarget;
222
+ phase: ChapterReleaseRequirement["phase"];
223
+ outcome: "passed" | "failed" | "blocked";
224
+ assertions: Readonly<Record<string, boolean>>;
225
+ references: readonly {
226
+ provider: ChapterReleaseRequirement["providers"][number];
227
+ id: string;
228
+ }[];
229
+ cleanup: Readonly<Record<string, boolean>>;
230
+ }
231
+ /** Bounded release blockers. Passing requests a human review, never permission to deploy. */
232
+ interface ChapterReleaseAssessment {
233
+ readyForReview: boolean;
234
+ productionAuthorized: false;
235
+ required: number;
236
+ passed: number;
237
+ blockers: readonly {
238
+ requirementId: string;
239
+ code: string;
240
+ }[];
241
+ }
242
+ /**
243
+ * Require a complete, exact-candidate release evidence set. Missing, duplicate,
244
+ * failed, stale, wrong-runtime, skipped, or incompletely cleaned attempts block
245
+ * review. This is evidence validation, not provider execution: callers must use
246
+ * real drivers and retain their independently inspectable run artifacts.
247
+ */
248
+ declare function assessChapterReleaseEvidence(plan: ChapterReleasePlan, proofs: readonly ChapterReleaseProof[]): ChapterReleaseAssessment;
249
+
152
250
  /** Validate the exact facts a multi-site acceptance run needs before it writes anywhere. */
153
251
  declare function validateChapterAcceptanceManifest(value: unknown): ChapterAcceptanceValidation;
154
252
  /**
@@ -157,4 +255,4 @@ declare function validateChapterAcceptanceManifest(value: unknown): ChapterAccep
157
255
  */
158
256
  declare function planChapterAcceptanceMatrix(manifest: ChapterAcceptanceManifest): ChapterAcceptanceScenario[];
159
257
 
160
- export { type ChapterAcceptanceCaseResult, type ChapterAcceptanceCleanupEvidence, type ChapterAcceptanceEvidence, type ChapterAcceptanceExecutionContext, type ChapterAcceptanceExecutor, type ChapterAcceptanceManifest, type ChapterAcceptanceOptions, type ChapterAcceptanceProviderReference, type ChapterAcceptanceRunResult, type ChapterAcceptanceScenario, type ChapterAcceptanceScenarioKind, type ChapterAcceptanceSeatOption, type ChapterAcceptanceSku, type ChapterAcceptanceTarget, type ChapterAcceptanceValidation, type ChapterJoinConfigProbe, type ChapterJoinContractFinding, type ChapterJoinContractProbeResult, formatChapterAcceptanceRun, planChapterAcceptanceMatrix, probeChapterJoinContracts, runChapterAcceptanceSuite, validateChapterAcceptanceManifest };
258
+ export { type ChapterAcceptanceCaseResult, type ChapterAcceptanceCleanupEvidence, type ChapterAcceptanceCommercialCase, type ChapterAcceptanceEvidence, type ChapterAcceptanceExecutionContext, type ChapterAcceptanceExecutor, type ChapterAcceptanceManifest, type ChapterAcceptanceOptions, type ChapterAcceptanceProviderReference, type ChapterAcceptanceRunResult, type ChapterAcceptanceScenario, type ChapterAcceptanceScenarioKind, type ChapterAcceptanceSeatOption, type ChapterAcceptanceSku, type ChapterAcceptanceTarget, type ChapterAcceptanceValidation, type ChapterJoinConfigProbe, type ChapterJoinContractFinding, type ChapterJoinContractProbeResult, type ChapterReleaseAssessment, type ChapterReleasePlan, type ChapterReleaseProof, type ChapterReleaseRequirement, type ChapterReleaseTarget, assertCommercialQuote, assessChapterReleaseEvidence, formatChapterAcceptanceRun, planChapterAcceptanceMatrix, probeChapterJoinContracts, runChapterAcceptanceSuite, validateChapterAcceptanceManifest };