@tokenoftrust/storefront-runner 7.3.2 → 7.5.1

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.
Files changed (420) hide show
  1. package/agency-kit/tools/lib/catalog-model/files.mjs +11 -4
  2. package/agency-kit/tools/lib/catalog-model/model.mjs +5 -1
  3. package/agency-kit/tools/lib/redirect-shadows.mjs +261 -0
  4. package/apps/storefront/astro.config.mjs +8 -2
  5. package/apps/storefront/package.json +1 -2
  6. package/apps/storefront/src/components/catalog/storefront/ProductCard.astro +20 -6
  7. package/apps/storefront/src/components/catalog/storefront/islands/ImageGallery.tsx +17 -6
  8. package/apps/storefront/src/components/compliance/storefront/islands/CheckoutComplianceGate.tsx +1 -32
  9. package/apps/storefront/src/config/compliance/rulesets.ts +1 -1
  10. package/apps/storefront/src/layouts/Layout.astro +17 -0
  11. package/apps/storefront/src/lib/access/auth/agentRoles.ts +20 -0
  12. package/apps/storefront/src/lib/access/auth/agentSessionGate.ts +32 -8
  13. package/apps/storefront/src/lib/access/auth/brokerAssertion.ts +16 -2
  14. package/apps/storefront/src/lib/access/auth/contactReaderAuthority.ts +39 -0
  15. package/apps/storefront/src/lib/access/auth/loginGate.ts +15 -17
  16. package/apps/storefront/src/lib/access/dashboard/staffAdmission.ts +5 -0
  17. package/apps/storefront/src/lib/access/dashboard/tenantSelection.ts +2 -0
  18. package/apps/storefront/src/lib/access/shared/capability.ts +14 -6
  19. package/apps/storefront/src/lib/access/shared/generated/capabilityCatalog.generated.ts +161 -0
  20. package/apps/storefront/src/lib/activity/activityScope.ts +36 -0
  21. package/apps/storefront/src/lib/activity/recordActivity.ts +23 -1
  22. package/apps/storefront/src/lib/activity/serverFanOut.ts +31 -0
  23. package/apps/storefront/src/lib/activity/store.ts +9 -3
  24. package/apps/storefront/src/lib/checkout/agent/checkoutProtocol.ts +196 -0
  25. package/apps/storefront/src/lib/checkout/agent/checkoutSession.ts +296 -0
  26. package/apps/storefront/src/lib/checkout/agent/webBotAuth.ts +347 -0
  27. package/apps/storefront/src/lib/checkout/commerce/cardCartForm.ts +2 -0
  28. package/apps/storefront/src/lib/checkout/commerce/cartSession.ts +109 -12
  29. package/apps/storefront/src/lib/checkout/commerce/checkoutHandoffRoute.ts +53 -25
  30. package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +48 -6
  31. package/apps/storefront/src/lib/checkout/proposal/cartProposal.ts +388 -0
  32. package/apps/storefront/src/lib/checkout/proposal/listMatcher.ts +149 -0
  33. package/apps/storefront/src/lib/checkout/proposal/proposalRoutes.ts +522 -0
  34. package/apps/storefront/src/lib/checkout/proposal/reviewHtml.ts +100 -0
  35. package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +26 -2
  36. package/apps/storefront/src/lib/content/shared/redirects.ts +21 -4
  37. package/apps/storefront/src/lib/publication/shared/edgeCache.ts +5 -2
  38. package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderDecorator.ts +15 -8
  39. package/apps/storefront/src/lib/publication/shared/runtimeEnv.ts +1 -1
  40. package/apps/storefront/src/middleware/controlPlane.ts +15 -1
  41. package/apps/storefront/src/middleware/index.ts +7 -3
  42. package/apps/storefront/src/middleware/renderChain.ts +46 -33
  43. package/apps/storefront/src/pages/api/cart-proposal/confirm.ts +12 -0
  44. package/apps/storefront/src/pages/api/cart-proposal/review.ts +26 -0
  45. package/apps/storefront/src/pages/api/commerce/checkout-sessions/[id].ts +9 -0
  46. package/apps/storefront/src/pages/api/commerce/checkout-sessions.ts +8 -0
  47. package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +29 -6
  48. package/apps/storefront/src/pages/api/compliance/preflight.ts +25 -1
  49. package/apps/storefront/src/pages/products/[handle].astro +2 -15
  50. package/apps/storefront/tsconfig.astro.json +11 -0
  51. package/package.json +1 -1
  52. package/packages/public-runtime/src/activity/README.md +12 -0
  53. package/packages/public-runtime/src/activity/catalog.ts +7 -0
  54. package/packages/public-runtime/src/activity/event.ts +19 -0
  55. package/packages/public-runtime/src/activity/redaction.ts +31 -2
  56. package/packages/public-runtime/src/catalog-files.ts +3 -2
  57. package/packages/public-runtime/src/checkout-orders.ts +18 -19
  58. package/packages/public-runtime/src/checkout.ts +70 -0
  59. package/packages/public-runtime/src/compliance/evaluate.ts +60 -1
  60. package/packages/public-runtime/src/compliance/index.ts +1 -1
  61. package/packages/public-runtime/src/compliance/pact-report.ts +184 -3
  62. package/packages/public-runtime/src/compliance/profile.ts +268 -20
  63. package/packages/public-runtime/src/compliance/ruleset.ts +42 -0
  64. package/packages/public-runtime/src/customization-runtime.ts +1 -1
  65. package/packages/public-runtime/src/product.ts +9 -1
  66. package/packages/public-runtime/src/publication-content-redirects.ts +16 -3
  67. package/packages/public-runtime/tests/fixtures/compliance-decisions.golden.json +252 -52
  68. package/pnpm-lock.runner.yaml +0 -15
  69. package/scripts/tenant/materialize-tenant-content.mjs +3 -0
  70. package/scripts/tenant/validate.mjs +128 -0
  71. package/apps/storefront/dev-plugins/dev-publish.mjs +0 -55
  72. package/apps/storefront/drizzle.config.apps.ts +0 -13
  73. package/apps/storefront/integrations/preview-annotations-client-bundle.mjs +0 -80
  74. package/apps/storefront/migrations-apps/0000_fast_millenium_guard.sql +0 -129
  75. package/apps/storefront/migrations-apps/0001_woozy_lyja.sql +0 -22
  76. package/apps/storefront/migrations-apps/0002_good_switch.sql +0 -26
  77. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +0 -12
  78. package/apps/storefront/migrations-apps/0004_deep_morph.sql +0 -36
  79. package/apps/storefront/migrations-apps/0005_common_mystique.sql +0 -23
  80. package/apps/storefront/migrations-apps/0006_broad_microchip.sql +0 -16
  81. package/apps/storefront/migrations-apps/0007_brave_outlaw_kid.sql +0 -15
  82. package/apps/storefront/migrations-apps/0008_blue_dazzler.sql +0 -11
  83. package/apps/storefront/migrations-apps/0009_bored_shinobi_shaw.sql +0 -15
  84. package/apps/storefront/migrations-apps/0010_ws4_verified_provider_measurement.sql +0 -35
  85. package/apps/storefront/migrations-apps/0011_dt_tracking_tenant_databases.sql +0 -23
  86. package/apps/storefront/migrations-apps/0012_test_destinations.sql +0 -29
  87. package/apps/storefront/migrations-apps/0013_publication_space_editorial.sql +0 -64
  88. package/apps/storefront/migrations-apps/0014_retire_candidate_ledger.sql +0 -12
  89. package/apps/storefront/migrations-apps/0015_merchant_calculation_settings.sql +0 -31
  90. package/apps/storefront/migrations-apps/0016_scrappy_commerce_contract.sql +0 -166
  91. package/apps/storefront/migrations-apps/0017_commerce_durable_projection.sql +0 -28
  92. package/apps/storefront/migrations-apps/0018_commerce_provider_cart_identity.sql +0 -13
  93. package/apps/storefront/migrations-apps/0019_commerce_source_authority.sql +0 -23
  94. package/apps/storefront/migrations-apps/0020_contact_messages.sql +0 -18
  95. package/apps/storefront/migrations-apps/0021_contact_vault.sql +0 -166
  96. package/apps/storefront/migrations-apps/0022_contact_vault_fields.sql +0 -342
  97. package/apps/storefront/migrations-apps/0023_principal_grant_contacts.sql +0 -15
  98. package/apps/storefront/migrations-apps/0024_order_contact_erasure_state.sql +0 -22
  99. package/apps/storefront/migrations-apps/0025_shipment_audit_order_lookup.sql +0 -2
  100. package/apps/storefront/migrations-apps/0026_fulfillment_assignment.sql +0 -44
  101. package/apps/storefront/migrations-apps/0027_app_contact_authority.sql +0 -70
  102. package/apps/storefront/migrations-apps/0028_app_jwk_and_candidates.sql +0 -133
  103. package/apps/storefront/migrations-apps/0029_inventory_locations_wms.sql +0 -38
  104. package/apps/storefront/migrations-apps/0030_assignment_split_shipments.sql +0 -149
  105. package/apps/storefront/migrations-apps/meta/0000_snapshot.json +0 -843
  106. package/apps/storefront/migrations-apps/meta/0001_snapshot.json +0 -990
  107. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +0 -1160
  108. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +0 -1235
  109. package/apps/storefront/migrations-apps/meta/0004_snapshot.json +0 -1474
  110. package/apps/storefront/migrations-apps/meta/0005_snapshot.json +0 -1617
  111. package/apps/storefront/migrations-apps/meta/0006_snapshot.json +0 -1716
  112. package/apps/storefront/migrations-apps/meta/0007_snapshot.json +0 -1812
  113. package/apps/storefront/migrations-apps/meta/0008_snapshot.json +0 -1881
  114. package/apps/storefront/migrations-apps/meta/0009_snapshot.json +0 -1979
  115. package/apps/storefront/migrations-apps/meta/_journal.json +0 -76
  116. package/apps/storefront/perf/README.md +0 -64
  117. package/apps/storefront/perf/assert-budgets.ts +0 -159
  118. package/apps/storefront/platform-reconcile-tenants.json +0 -3
  119. package/apps/storefront/playwright.config.ts +0 -23
  120. package/apps/storefront/public/js/dashboard-access-banner.js +0 -53
  121. package/apps/storefront/public/js/dashboard-apps.js +0 -183
  122. package/apps/storefront/public/js/dashboard-contact-capture.js +0 -52
  123. package/apps/storefront/public/js/dashboard-delegate.js +0 -167
  124. package/apps/storefront/public/js/dashboard-team.js +0 -356
  125. package/apps/storefront/public/js/dashboard-vendor-search.js +0 -115
  126. package/apps/storefront/src/components/content/storefront/AsyncStylesheet.astro +0 -26
  127. package/apps/storefront/src/components/integrations/storefront/WidgetFrame.astro +0 -34
  128. package/apps/storefront/src/config/adminTenantLookup.ts +0 -35
  129. package/apps/storefront/src/config/evidenceTenantRoster.ts +0 -25
  130. package/apps/storefront/src/config/staffProvisionProjection.ts +0 -24
  131. package/apps/storefront/src/config/storeName.ts +0 -34
  132. package/apps/storefront/src/lib/access/admin/README.md +0 -122
  133. package/apps/storefront/src/lib/access/admin/adminShell.ts +0 -281
  134. package/apps/storefront/src/lib/access/admin/envelope.ts +0 -9
  135. package/apps/storefront/src/lib/access/admin/viewmodels/settings.ts +0 -64
  136. package/apps/storefront/src/lib/access/auth/adminApiGuard.ts +0 -66
  137. package/apps/storefront/src/lib/access/auth/adminEntry.ts +0 -126
  138. package/apps/storefront/src/lib/access/auth/mcpClientAssertion.ts +0 -217
  139. package/apps/storefront/src/lib/access/auth/operatorSession.ts +0 -120
  140. package/apps/storefront/src/lib/access/dashboard/agentStoreEntry.ts +0 -253
  141. package/apps/storefront/src/lib/access/dashboard/delegateGate.ts +0 -130
  142. package/apps/storefront/src/lib/access/dashboard/staffStoreEntry.ts +0 -153
  143. package/apps/storefront/src/lib/access/dashboard/staffVendorAccess.ts +0 -474
  144. package/apps/storefront/src/lib/access/dashboard/vendorQuery.ts +0 -61
  145. package/apps/storefront/src/lib/access/fixtures/settings.ts +0 -67
  146. package/apps/storefront/src/lib/access/fixtures/tenants.ts +0 -29
  147. package/apps/storefront/src/lib/access/notifications/magicLinkInviteEmail.ts +0 -62
  148. package/apps/storefront/src/lib/access/shared/grantContactLookup.ts +0 -97
  149. package/apps/storefront/src/lib/access/shared/principalGrants.ts +0 -775
  150. package/apps/storefront/src/lib/activity/alerts.ts +0 -426
  151. package/apps/storefront/src/lib/activity/candidateSubmitLease.ts +0 -87
  152. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +0 -181
  153. package/apps/storefront/src/lib/activity/evidence/evidenceReference.ts +0 -32
  154. package/apps/storefront/src/lib/activity/fixtures/evidence.ts +0 -99
  155. package/apps/storefront/src/lib/activity/query.ts +0 -403
  156. package/apps/storefront/src/lib/activity/uiActor.ts +0 -152
  157. package/apps/storefront/src/lib/admin/services/mock/index.ts +0 -12
  158. package/apps/storefront/src/lib/assets/addons/catalog.ts +0 -60
  159. package/apps/storefront/src/lib/assets/addons/storeEntitlements.ts +0 -260
  160. package/apps/storefront/src/lib/assets/durableAssetsRoute.ts +0 -65
  161. package/apps/storefront/src/lib/assets/durableR2.ts +0 -473
  162. package/apps/storefront/src/lib/assets/durableR2Bindings.ts +0 -33
  163. package/apps/storefront/src/lib/automation/admin/viewmodels/aiWorkflows.ts +0 -65
  164. package/apps/storefront/src/lib/automation/ai/approvalMode.ts +0 -20
  165. package/apps/storefront/src/lib/automation/ai/askEnvelope.ts +0 -47
  166. package/apps/storefront/src/lib/automation/ai/audit.ts +0 -12
  167. package/apps/storefront/src/lib/automation/ai/operationalRuns.ts +0 -155
  168. package/apps/storefront/src/lib/automation/ai/recommendation.ts +0 -20
  169. package/apps/storefront/src/lib/automation/fixtures/aiWorkflows.ts +0 -59
  170. package/apps/storefront/src/lib/catalog/admin/catalogSettingsClient.ts +0 -250
  171. package/apps/storefront/src/lib/catalog/admin/catalogSettingsFields.ts +0 -134
  172. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPreview.ts +0 -37
  173. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPricingView.ts +0 -39
  174. package/apps/storefront/src/lib/catalog/admin/catalogSettingsRuleView.ts +0 -44
  175. package/apps/storefront/src/lib/catalog/admin/catalogSettingsSkuView.ts +0 -21
  176. package/apps/storefront/src/lib/catalog/admin/catalogSettingsState.ts +0 -132
  177. package/apps/storefront/src/lib/catalog/admin/productSetupPhoto.ts +0 -23
  178. package/apps/storefront/src/lib/catalog/admin/productsTabClient.ts +0 -193
  179. package/apps/storefront/src/lib/catalog/admin/services/catalogProducts.ts +0 -32
  180. package/apps/storefront/src/lib/catalog/admin/viewmodels/catalogProducts.ts +0 -164
  181. package/apps/storefront/src/lib/catalog/admin/viewmodels/products.ts +0 -267
  182. package/apps/storefront/src/lib/catalog/fixtures/products.ts +0 -105
  183. package/apps/storefront/src/lib/catalog/tot/syncState.ts +0 -111
  184. package/apps/storefront/src/lib/checkout/admin/checkoutStyleInput.ts +0 -172
  185. package/apps/storefront/src/lib/checkout/admin/checkoutStyleTarget.ts +0 -65
  186. package/apps/storefront/src/lib/checkout/browser/checkoutExciseForm.ts +0 -152
  187. package/apps/storefront/src/lib/checkout/browser/checkoutRequirementsForm.ts +0 -72
  188. package/apps/storefront/src/lib/checkout/browser/checkoutStyleForm.ts +0 -110
  189. package/apps/storefront/src/lib/checkout/browser/settingDraftActions.ts +0 -367
  190. package/apps/storefront/src/lib/checkout/commerce/checkoutSettings.ts +0 -246
  191. package/apps/storefront/src/lib/checkout/fixtures/checkoutSettings.ts +0 -77
  192. package/apps/storefront/src/lib/content/blog/markdown.ts +0 -174
  193. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome-assignments.example.json +0 -6
  194. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome.example.json +0 -79
  195. package/apps/storefront/src/lib/content/index.ts +0 -27
  196. package/apps/storefront/src/lib/content/the-build/readingTime.ts +0 -35
  197. package/apps/storefront/src/lib/content/the-build/toc.ts +0 -95
  198. package/apps/storefront/src/lib/customers/admin/viewmodels/customers.ts +0 -56
  199. package/apps/storefront/src/lib/customers/contactVault/blindIndex.ts +0 -28
  200. package/apps/storefront/src/lib/customers/contactVault/contactAudit.ts +0 -149
  201. package/apps/storefront/src/lib/customers/contactVault/dataKeys.ts +0 -283
  202. package/apps/storefront/src/lib/customers/contactVault/fieldEnvelope.ts +0 -88
  203. package/apps/storefront/src/lib/customers/contactVault/isolateMetrics.ts +0 -37
  204. package/apps/storefront/src/lib/customers/contactVault/kms.ts +0 -292
  205. package/apps/storefront/src/lib/customers/contactVault/retention.ts +0 -302
  206. package/apps/storefront/src/lib/customers/contactVault/retentionPolicy.ts +0 -290
  207. package/apps/storefront/src/lib/customers/contactVault/zip3.ts +0 -24
  208. package/apps/storefront/src/lib/customers/fixtures/customers.ts +0 -86
  209. package/apps/storefront/src/lib/developer-experience/admin/memoizeByEnvelope.ts +0 -27
  210. package/apps/storefront/src/lib/developer-experience/admin/seed.ts +0 -54
  211. package/apps/storefront/src/lib/developer-experience/dev/activityIngestToken.ts +0 -85
  212. package/apps/storefront/src/lib/developer-experience/dev/activityStore.ts +0 -82
  213. package/apps/storefront/src/lib/developer-experience/dev/agentGrantAttestation.ts +0 -74
  214. package/apps/storefront/src/lib/developer-experience/dev/ai-widget-client.js +0 -308
  215. package/apps/storefront/src/lib/developer-experience/dev/apiBase.ts +0 -17
  216. package/apps/storefront/src/lib/developer-experience/dev/cliSignInCode.ts +0 -124
  217. package/apps/storefront/src/lib/developer-experience/dev/cockpit/ask.ts +0 -49
  218. package/apps/storefront/src/lib/developer-experience/dev/cockpit/clickToSource.ts +0 -71
  219. package/apps/storefront/src/lib/developer-experience/dev/cockpit/copyCommand.ts +0 -227
  220. package/apps/storefront/src/lib/developer-experience/dev/cockpit/files.ts +0 -249
  221. package/apps/storefront/src/lib/developer-experience/dev/cockpit/hostedActivity.ts +0 -500
  222. package/apps/storefront/src/lib/developer-experience/dev/cockpit/infoPopover.ts +0 -12
  223. package/apps/storefront/src/lib/developer-experience/dev/cockpit/mcpCopy.ts +0 -34
  224. package/apps/storefront/src/lib/developer-experience/dev/cockpit/monitor.ts +0 -107
  225. package/apps/storefront/src/lib/developer-experience/dev/cockpit/stepper.ts +0 -116
  226. package/apps/storefront/src/lib/developer-experience/dev/cockpit/themeToggle.ts +0 -23
  227. package/apps/storefront/src/lib/developer-experience/dev/livePreview.ts +0 -77
  228. package/apps/storefront/src/lib/developer-experience/dev/obstacleStore.ts +0 -214
  229. package/apps/storefront/src/lib/developer-experience/dev/previewStatus.ts +0 -87
  230. package/apps/storefront/src/lib/developer-experience/dev/rendezvousBroker.ts +0 -226
  231. package/apps/storefront/src/lib/developer-experience/dev/runtimeStore.ts +0 -291
  232. package/apps/storefront/src/lib/developer-experience/dev/storeStatus.ts +0 -142
  233. package/apps/storefront/src/lib/developer-experience/dev/subjectReissue.ts +0 -67
  234. package/apps/storefront/src/lib/developer-experience/fixtures/regulated-commerce-truth/index.ts +0 -540
  235. package/apps/storefront/src/lib/developer-experience/fixtures/ws3-readonly-clone-preflight/index.ts +0 -495
  236. package/apps/storefront/src/lib/engagement/contact/contactMessages.ts +0 -671
  237. package/apps/storefront/src/lib/engagement/contact/messagesTabClient.ts +0 -175
  238. package/apps/storefront/src/lib/engagement/contact/submission.ts +0 -112
  239. package/apps/storefront/src/lib/engagement/messaging/messagesClient.ts +0 -149
  240. package/apps/storefront/src/lib/engagement/newsletter/digest.ts +0 -117
  241. package/apps/storefront/src/lib/engagement/newsletter/resendClient.ts +0 -79
  242. package/apps/storefront/src/lib/engagement/newsletter/send.ts +0 -265
  243. package/apps/storefront/src/lib/engagement/social/golive.ts +0 -212
  244. package/apps/storefront/src/lib/engagement/social/notify.ts +0 -32
  245. package/apps/storefront/src/lib/engagement/social/tokenStore.ts +0 -171
  246. package/apps/storefront/src/lib/fulfillment/admin/commerceDesk.ts +0 -180
  247. package/apps/storefront/src/lib/fulfillment/admin/commerceDeskRouting.ts +0 -45
  248. package/apps/storefront/src/lib/fulfillment/admin/viewmodels/fulfillment.ts +0 -1071
  249. package/apps/storefront/src/lib/fulfillment/appShipmentEvidence.ts +0 -271
  250. package/apps/storefront/src/lib/fulfillment/carrierEvidence.ts +0 -105
  251. package/apps/storefront/src/lib/fulfillment/commerceProjection.ts +0 -157
  252. package/apps/storefront/src/lib/fulfillment/commerceReadback.ts +0 -60
  253. package/apps/storefront/src/lib/fulfillment/commerceRecovery.ts +0 -84
  254. package/apps/storefront/src/lib/fulfillment/commerceRuntime.ts +0 -41
  255. package/apps/storefront/src/lib/fulfillment/fulfillmentService.ts +0 -2842
  256. package/apps/storefront/src/lib/fulfillment/readiness.ts +0 -217
  257. package/apps/storefront/src/lib/fulfillment/splitShipments.ts +0 -388
  258. package/apps/storefront/src/lib/fulfillment/syntheticPreviewOrders.ts +0 -292
  259. package/apps/storefront/src/lib/integrations/apps/appContactAuthority.ts +0 -27
  260. package/apps/storefront/src/lib/integrations/apps/appContactConsents.ts +0 -118
  261. package/apps/storefront/src/lib/integrations/apps/appInstallEnv.ts +0 -28
  262. package/apps/storefront/src/lib/integrations/apps/gtmMigrationDraft.ts +0 -103
  263. package/apps/storefront/src/lib/integrations/apps/inventoryWrite.ts +0 -906
  264. package/apps/storefront/src/lib/integrations/apps/orders/customerHash.ts +0 -28
  265. package/apps/storefront/src/lib/integrations/apps/orders/idempotency.ts +0 -100
  266. package/apps/storefront/src/lib/integrations/apps/reports/salesVelocityReport.ts +0 -96
  267. package/apps/storefront/src/lib/integrations/apps/routeParams.ts +0 -45
  268. package/apps/storefront/src/lib/integrations/webhooks/cloudflareQueueDispatcher.ts +0 -82
  269. package/apps/storefront/src/lib/integrations/webhooks/commercePayloads.ts +0 -159
  270. package/apps/storefront/src/lib/integrations/webhooks/deliveryEngine.ts +0 -379
  271. package/apps/storefront/src/lib/integrations/webhooks/deliveryMapper.ts +0 -34
  272. package/apps/storefront/src/lib/integrations/webhooks/deliveryStore.ts +0 -903
  273. package/apps/storefront/src/lib/integrations/webhooks/dispatcher.ts +0 -168
  274. package/apps/storefront/src/lib/integrations/webhooks/emit.ts +0 -245
  275. package/apps/storefront/src/lib/integrations/webhooks/events.ts +0 -105
  276. package/apps/storefront/src/lib/integrations/webhooks/getDispatcher.ts +0 -77
  277. package/apps/storefront/src/lib/integrations/webhooks/orderFulfilledClaim.ts +0 -75
  278. package/apps/storefront/src/lib/measurement/admin/analyticsRegionPolicy.ts +0 -151
  279. package/apps/storefront/src/lib/measurement/admin/analyticsRegionsClient.ts +0 -84
  280. package/apps/storefront/src/lib/measurement/admin/consentSettingsClient.ts +0 -113
  281. package/apps/storefront/src/lib/measurement/analytics/index.ts +0 -44
  282. package/apps/storefront/src/lib/measurement/attribution/attributionService.ts +0 -206
  283. package/apps/storefront/src/lib/measurement/attribution/orderConversionD1.ts +0 -150
  284. package/apps/storefront/src/lib/measurement/attribution/verifiedProviderMeasurement.ts +0 -118
  285. package/apps/storefront/src/lib/measurement/tracking/interactionCollector.ts +0 -205
  286. package/apps/storefront/src/lib/measurement/tracking/pruneRollup.ts +0 -260
  287. package/apps/storefront/src/lib/measurement/tracking/tenantReadAccess.ts +0 -138
  288. package/apps/storefront/src/lib/measurement/tracking-writeback/rewriteTrackingIds.ts +0 -175
  289. package/apps/storefront/src/lib/measurement/tracking-writeback/writebackCandidate.ts +0 -110
  290. package/apps/storefront/src/lib/observability/diag/capture.ts +0 -162
  291. package/apps/storefront/src/lib/observability/diag/consoleLine.ts +0 -76
  292. package/apps/storefront/src/lib/observability/diag/debugConsole.ts +0 -118
  293. package/apps/storefront/src/lib/observability/diag/debugMode.ts +0 -163
  294. package/apps/storefront/src/lib/observability/diag/debugWindow.ts +0 -111
  295. package/apps/storefront/src/lib/observability/diag/redact.ts +0 -17
  296. package/apps/storefront/src/lib/observability/diag/reference.ts +0 -148
  297. package/apps/storefront/src/lib/observability/diag/referenceStore.ts +0 -113
  298. package/apps/storefront/src/lib/observability/diag/report.ts +0 -110
  299. package/apps/storefront/src/lib/observability/diag/serverResponseTime.ts +0 -91
  300. package/apps/storefront/src/lib/observability/diag/session.ts +0 -93
  301. package/apps/storefront/src/lib/observability/monitoring/manifest.ts +0 -301
  302. package/apps/storefront/src/lib/observability/performance/lighthouseReport.ts +0 -109
  303. package/apps/storefront/src/lib/observability/performance/rumAlert.ts +0 -179
  304. package/apps/storefront/src/lib/orders/admin/orderActions.ts +0 -556
  305. package/apps/storefront/src/lib/orders/admin/orderClient.ts +0 -248
  306. package/apps/storefront/src/lib/orders/admin/orderSource.ts +0 -410
  307. package/apps/storefront/src/lib/orders/admin/services/orders.ts +0 -922
  308. package/apps/storefront/src/lib/orders/admin/viewmodels/orders.ts +0 -135
  309. package/apps/storefront/src/lib/orders/data/commerceCallerConfig.ts +0 -37
  310. package/apps/storefront/src/lib/orders/data/ledgerContractOrders.ts +0 -148
  311. package/apps/storefront/src/lib/orders/data/orderForwardReceiver.ts +0 -532
  312. package/apps/storefront/src/lib/orders/data/orderMapper.ts +0 -454
  313. package/apps/storefront/src/lib/orders/data/ordersStore.ts +0 -623
  314. package/apps/storefront/src/lib/orders/data/sourceAuthorityContract.ts +0 -380
  315. package/apps/storefront/src/lib/orders/data/sourceAuthorityStore.ts +0 -830
  316. package/apps/storefront/src/lib/orders/fixtures/orders.ts +0 -186
  317. package/apps/storefront/src/lib/orders/providers/foxyOrderClient.ts +0 -207
  318. package/apps/storefront/src/lib/orders/vault/appRecipientRead.ts +0 -222
  319. package/apps/storefront/src/lib/orders/vault/contactIntake.ts +0 -63
  320. package/apps/storefront/src/lib/orders/vault/contactRoutes.ts +0 -110
  321. package/apps/storefront/src/lib/orders/vault/kmsEnv.ts +0 -11
  322. package/apps/storefront/src/lib/orders/vault/orderContact.ts +0 -96
  323. package/apps/storefront/src/lib/orders/vault/orderContactVault.ts +0 -1427
  324. package/apps/storefront/src/lib/orders/vault/vault-test-support.ts +0 -258
  325. package/apps/storefront/src/lib/publication/d1/schema-apps.ts +0 -808
  326. package/apps/storefront/src/lib/publication/notifications/candidateConflictEmail.ts +0 -80
  327. package/apps/storefront/src/lib/publication/servingMode.ts +0 -52
  328. package/apps/storefront/src/lib/publication/shared/previewAnnotations/moduleAsset.ts +0 -65
  329. package/apps/storefront/src/lib/publication/shared/routedApiParam.ts +0 -38
  330. package/apps/storefront/src/lib/reporting/admin/viewmodels/reporting.ts +0 -34
  331. package/apps/storefront/src/lib/reporting/fixtures/reporting.ts +0 -51
  332. package/apps/storefront/src/lib/subscriptions/admin/viewmodels/subscriptions.ts +0 -106
  333. package/apps/storefront/src/lib/subscriptions/fixtures/subscriptions.ts +0 -398
  334. package/apps/storefront/src/pages/api/admin/activity-alerts.ts +0 -58
  335. package/apps/storefront/src/pages/api/admin/commerce-readiness.ts +0 -172
  336. package/apps/storefront/src/pages/api/admin/fulfillment/batches.ts +0 -59
  337. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id]/address.ts +0 -66
  338. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id].ts +0 -118
  339. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contact-search.ts +0 -26
  340. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contacts.ts +0 -22
  341. package/apps/storefront/src/pages/api/admin/interaction-insights.ts +0 -101
  342. package/apps/storefront/src/pages/api/admin/orders/[id].ts +0 -63
  343. package/apps/storefront/src/pages/api/admin/orders.ts +0 -65
  344. package/apps/storefront/src/pages/api/contact.ts +0 -144
  345. package/apps/storefront/src/scheduled/contactVaultSweep.ts +0 -113
  346. package/apps/storefront/src/styles/admin.css +0 -1161
  347. package/apps/storefront/test/pipeline/fake-preview-services.ts +0 -288
  348. package/apps/storefront/test/pipeline/harness.ts +0 -209
  349. package/apps/storefront/test/pipeline/intake-worker.mjs +0 -14
  350. package/apps/storefront/test/pipeline/matrix-faults.ts +0 -366
  351. package/apps/storefront/test/pipeline/pipeline-host.ts +0 -418
  352. package/apps/storefront/test/pipeline/pool-config.cjs +0 -85
  353. package/apps/storefront/test/pipeline/publish-kinds.ts +0 -279
  354. package/apps/storefront/test/pipeline/synthetic-job.ts +0 -303
  355. package/apps/storefront/test/pipeline-faults/matrix-lib.ts +0 -696
  356. package/apps/storefront/vitest.config.cts +0 -44
  357. package/apps/storefront/vitest.faults.config.cts +0 -13
  358. package/apps/storefront/vitest.workers.config.cts +0 -7
  359. package/packages/feedback/fixtures/v1/expected-findings.json +0 -16
  360. package/packages/feedback/fixtures/v1/feedback-action/invalid/carries-transport-credential.json +0 -14
  361. package/packages/feedback/fixtures/v1/feedback-action/invalid/control-char-in-description.json +0 -13
  362. package/packages/feedback/fixtures/v1/feedback-action/invalid/legacy-schema-version.json +0 -13
  363. package/packages/feedback/fixtures/v1/feedback-action/invalid/page-path-with-query.json +0 -14
  364. package/packages/feedback/fixtures/v1/feedback-action/invalid/title-too-short.json +0 -13
  365. package/packages/feedback/fixtures/v1/feedback-action/valid/element-problem.json +0 -33
  366. package/packages/feedback/fixtures/v1/feedback-action/valid/page-comment.json +0 -20
  367. package/packages/feedback/fixtures/v1/feedback-action/valid/region-improvement.json +0 -24
  368. package/packages/feedback/fixtures/v1/feedback-action/valid/text-selection-feature.json +0 -30
  369. package/packages/feedback/fixtures/v1/submission-receipt/invalid/accepted-at-not-utc.json +0 -9
  370. package/packages/feedback/fixtures/v1/submission-receipt/invalid/bad-feedback-id.json +0 -9
  371. package/packages/feedback/fixtures/v1/submission-receipt/invalid/legacy-contract-version.json +0 -9
  372. package/packages/feedback/fixtures/v1/submission-receipt/invalid/missing-replayed.json +0 -8
  373. package/packages/feedback/fixtures/v1/submission-receipt/valid/accepted.json +0 -9
  374. package/packages/feedback/fixtures/v1/submission-receipt/valid/fractional-seconds.json +0 -9
  375. package/packages/feedback/fixtures/v1/submission-receipt/valid/replayed.json +0 -9
  376. package/packages/feedback/fixtures/v1/target-evidence/invalid/page-kind-claims-structure.json +0 -6
  377. package/packages/feedback/fixtures/v1/target-evidence/invalid/path-too-deep.json +0 -17
  378. package/packages/feedback/fixtures/v1/target-evidence/invalid/relative-region-out-of-range.json +0 -11
  379. package/packages/feedback/fixtures/v1/target-evidence/invalid/selector-uses-class.json +0 -7
  380. package/packages/feedback/fixtures/v1/target-evidence/invalid/source-precision-without-anchor.json +0 -6
  381. package/packages/feedback/fixtures/v1/target-evidence/valid/element-structure.json +0 -21
  382. package/packages/feedback/fixtures/v1/target-evidence/valid/host-iframe.json +0 -14
  383. package/packages/feedback/fixtures/v1/target-evidence/valid/source-anchor.json +0 -12
  384. package/packages/feedback/fixtures/v1/target-evidence/valid/text-selection.json +0 -26
  385. package/packages/feedback/package.json +0 -35
  386. package/packages/feedback/scripts/build-player.mjs +0 -28
  387. package/packages/feedback/src/index.ts +0 -1
  388. package/packages/feedback/src/primitives/composer.ts +0 -639
  389. package/packages/feedback/src/primitives/dialog.ts +0 -263
  390. package/packages/feedback/src/primitives/hostAdapter.ts +0 -116
  391. package/packages/feedback/src/primitives/index.ts +0 -10
  392. package/packages/feedback/src/primitives/launcher.ts +0 -200
  393. package/packages/feedback/src/primitives/picker.ts +0 -663
  394. package/packages/feedback/src/primitives/redaction.ts +0 -204
  395. package/packages/feedback/src/primitives/selection.ts +0 -49
  396. package/packages/feedback/src/primitives/shiftAccelerator.ts +0 -160
  397. package/packages/feedback/src/primitives/styles.ts +0 -77
  398. package/packages/feedback/src/primitives/surface.ts +0 -124
  399. package/packages/feedback/src/primitives/target.ts +0 -293
  400. package/packages/feedback/src/tour/canonical.ts +0 -27
  401. package/packages/feedback/src/tour/index.ts +0 -3
  402. package/packages/feedback/src/tour/player/browser.ts +0 -5
  403. package/packages/feedback/src/tour/player/host.ts +0 -12
  404. package/packages/feedback/src/tour/player/index.ts +0 -205
  405. package/packages/feedback/src/tour/player/manifest.ts +0 -76
  406. package/packages/feedback/src/tour/player/player.css +0 -130
  407. package/packages/feedback/src/tour/player/resolver.ts +0 -12
  408. package/packages/feedback/src/tour/player/surface.ts +0 -295
  409. package/packages/feedback/src/tour/player/types.ts +0 -8
  410. package/packages/feedback/src/tour/resolve/core.ts +0 -267
  411. package/packages/feedback/src/tour/resolve/dom.ts +0 -115
  412. package/packages/feedback/src/tour/resolve/index.ts +0 -29
  413. package/packages/feedback/src/tour/sanitize.ts +0 -76
  414. package/packages/feedback/src/tour/schema.ts +0 -362
  415. package/packages/feedback/src/v1/guards.ts +0 -335
  416. package/packages/feedback/src/v1/index.ts +0 -3
  417. package/packages/feedback/src/v1/protectedSurfaces.ts +0 -32
  418. package/packages/feedback/src/v1/types.ts +0 -177
  419. package/packages/feedback/tsconfig.json +0 -9
  420. package/packages/feedback/vitest.config.cts +0 -21
@@ -1,696 +0,0 @@
1
- /**
2
- * The fault matrix's scenarios, driver and convergence assertions (the cells are in
3
- * `./fault-matrix.test.ts`; the kill points inside the object are `../pipeline/matrix-faults.ts`).
4
- *
5
- * A SCENARIO is one job kind on one provider, from a fresh tenant: what the world holds before the
6
- * job (`setup`, which may run prerequisite jobs unfaulted) and the intent that starts it. The preview
7
- * kinds take no provider — the shared preview is Worker-served for Cloudflare and CloudFront tenants
8
- * alike, so they run once; every live-lane kind runs on both.
9
- *
10
- * A CELL runs a scenario with one fault armed and drives the job to its end the way the world would:
11
- * a CI dispatch is completed and its callback delivered, a hotfix's static prebuild is staged and
12
- * reported. The cell's outcome is then held against the scenario's unfaulted run (`baselineOf`).
13
- */
14
- import type { JobView, TransitionView } from "../../src/lib/publication/pipeline/job-runner";
15
- import type { MatrixEffect, MatrixFault, MatrixKill } from "../pipeline/matrix-faults";
16
- import type { CiDispatch } from "../../src/lib/publication/pipeline/publish/publish-test-support";
17
- import { pipelineFor, uniqueTenant } from "../pipeline/harness";
18
-
19
- export type Provider = "worker-r2-pointer" | "s3-overwrite";
20
-
21
- export const PROVIDER_NAME: Record<Provider, string> = { "worker-r2-pointer": "cloudflare", "s3-overwrite": "cloudfront" };
22
-
23
- const TERMINAL = new Set(["succeeded", "needs-developer", "stuck"]);
24
- const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
25
-
26
- type Stub = ReturnType<typeof pipelineFor>;
27
-
28
- /** One tenant's object, called the way a real caller would: a fresh stub per call, retried while it restarts. */
29
- export class Tenant {
30
- /** The shas staged for the pointer plane so far (the world's staged table is replaced whole). */
31
- readonly staged: string[] = [];
32
-
33
- constructor(readonly id: string) {}
34
-
35
- async call<T>(fn: (stub: Stub) => Promise<T>): Promise<T> {
36
- for (let i = 0; ; i += 1) {
37
- try {
38
- return await fn(pipelineFor(this.id));
39
- } catch (err) {
40
- if (i > 400 || !/synthetic eviction|abort/i.test(String((err as Error).message))) throw err;
41
- await sleep(25);
42
- }
43
- }
44
- }
45
-
46
- harness<T = unknown>(op: string, args: Record<string, unknown> = {}): Promise<T> {
47
- return this.call((stub) => stub.publishHarness(op, { tenantId: this.id, ...args })) as Promise<T>;
48
- }
49
-
50
- matrix<T = unknown>(op: string, args: Record<string, unknown> = {}): Promise<T> {
51
- return this.call((stub) => stub.matrix(op, args)) as Promise<T>;
52
- }
53
-
54
- async submit(kind: string, input: unknown): Promise<string> {
55
- const result = await this.call((stub) =>
56
- stub.submit(this.id, { kind, input, actor: { type: "test", id: "fault-matrix" }, admissionDecisionId: "decision-matrix" }),
57
- );
58
- if (!result.ok) throw new Error(`${kind} refused at intake: ${result.reason}`);
59
- return result.jobId;
60
- }
61
-
62
- job(jobId: string): Promise<JobView | null> {
63
- return this.call((stub) => stub.job(jobId));
64
- }
65
-
66
- transitions(jobId?: string): Promise<TransitionView[]> {
67
- return this.call((stub) => stub.transitions(jobId, 2_000));
68
- }
69
-
70
- deliver(correlationId: string, payload: unknown) {
71
- return this.call((stub) => stub.deliverExternal(correlationId, payload));
72
- }
73
- }
74
-
75
- // ── Scenarios ─────────────────────────────────────────────────────────────────
76
-
77
- export interface Scenario {
78
- /** `<kind> × <provider>` (or `<kind>` for a provider-neutral preview kind). */
79
- id: string;
80
- kind: string;
81
- provider: Provider | null;
82
- lane: "live" | "preview";
83
- setup(t: Tenant): Promise<void>;
84
- intent(t: Tenant): { kind: string; input: unknown };
85
- /** How many times the intent is delivered (a duplicate delivery coalesces). Default 1. */
86
- deliveries?: number;
87
- }
88
-
89
- export const REPO = "shop.example";
90
-
91
- const AGGREGATE = { kind: "aggregate", expectedAggregateSha: null, expectedArtifactDigest: null };
92
-
93
- /** One go-live pins a draft so `apply-settings` starts. The version need not exist: a missing draft is refused and the step still runs. */
94
- function aggregateWithSettings(tenantId: string) {
95
- return {
96
- ...AGGREGATE,
97
- settings: [{
98
- path: `tenants/${tenantId}/checkout-requirements.json`,
99
- versionId: "settings-v1",
100
- expectedLiveVersionId: null,
101
- }],
102
- };
103
- }
104
-
105
- export function publishInput(provider: Provider, target: unknown) {
106
- return {
107
- aggregateId: "preview",
108
- repo: REPO,
109
- provider,
110
- staticPublishTarget: "www-test",
111
- publicManifestUrl: "https://shop.test/manifest.json",
112
- storefrontMode: "enabled",
113
- workerHost: "storefront.test",
114
- target,
115
- };
116
- }
117
-
118
- const HOTFIX_TARGET = {
119
- kind: "hotfix",
120
- changeId: "fix-9",
121
- prNumber: 9,
122
- headSha: "head-fix-9",
123
- expectedHeadSha: null,
124
- expectedArtifactDigest: null,
125
- message: null,
126
- };
127
-
128
- /** A green aggregate at `sha` (with an assets snapshot), staged for the pointer plane on Cloudflare. */
129
- async function seedRelease(t: Tenant, provider: Provider, sha: string, runId: string): Promise<void> {
130
- await t.harness("seedGreen", { sha, runId, prs: [{ changeId: `c-${sha}`, prNumber: 1, headSha: `h-${sha}` }], assets: true });
131
- if (provider === "worker-r2-pointer") {
132
- // The world's staged table is replaced whole: every sha staged so far stays staged.
133
- t.staged.push(sha);
134
- await t.harness("configure", { patch: { staged: Object.fromEntries(t.staged.map((s) => [s, { digest: `digest-${s}`, validated: true }])) } });
135
- }
136
- }
137
-
138
- /**
139
- * A CloudFront tenant's public host already serves an earlier release (a re-dispatch proves it is not
140
- * the new one), and GitHub lists a dispatched run within a second — well inside the CI window, as in
141
- * production (seconds against 45 minutes).
142
- */
143
- async function cloudFrontServesEarlier(t: Tenant, provider: Provider): Promise<void> {
144
- if (provider !== "s3-overwrite") return;
145
- await t.harness("serveOnCloudFront", { sha: "sha-0", treeDigest: "tree-0" });
146
- await t.harness("configure", { patch: { runListingDelayMs: 1_000 } });
147
- }
148
-
149
- /** Run a prerequisite job unfaulted to `succeeded`. */
150
- async function prerequisite(t: Tenant, kind: string, input: unknown): Promise<void> {
151
- const jobId = await t.submit(kind, input);
152
- const { job } = await drive(t, jobId);
153
- if (job.state !== "succeeded") throw new Error(`setup ${kind} ended ${job.state}: ${JSON.stringify(job.error)} outcome: ${outcomeOf(job)}`);
154
- }
155
-
156
- async function goLive(t: Tenant, provider: Provider, sha: string, runId: string): Promise<void> {
157
- await seedRelease(t, provider, sha, runId);
158
- await prerequisite(t, "publish", publishInput(provider, AGGREGATE));
159
- }
160
-
161
- const integrateInput = (changeId: string, pr: number) => ({ repo: REPO, changeId, prNumber: pr, headSha: `head-${changeId}` });
162
-
163
- async function integratedPr2(t: Tenant): Promise<void> {
164
- await t.call((stub) => stub.configureFake({ open: [{ changeId: "pr-2", headSha: "head-pr-2" }] }));
165
- await prerequisite(t, "integrate", integrateInput("pr-2", 2));
166
- }
167
-
168
- export const PREVIEW_SCENARIOS: Scenario[] = [
169
- {
170
- id: "integrate",
171
- kind: "integrate",
172
- provider: null,
173
- lane: "preview",
174
- // Two other open candidates: one rebases clean, one conflicts and emails its author.
175
- setup: (t) =>
176
- t.call((stub) =>
177
- stub.configureFake({
178
- open: [{ changeId: "pr-2", headSha: "head-pr-2" }],
179
- rebaseCandidates: [
180
- { changeId: "pr-5", pr: 5, conflicts: true },
181
- { changeId: "pr-6", pr: 6 },
182
- ],
183
- } as never),
184
- ),
185
- intent: () => ({ kind: "integrate", input: integrateInput("pr-2", 2) }),
186
- },
187
- { id: "rebuild", kind: "rebuild", provider: null, lane: "preview", setup: integratedPr2, intent: () => ({ kind: "rebuild", input: { repo: REPO } }) },
188
- {
189
- id: "revert",
190
- kind: "revert",
191
- provider: null,
192
- lane: "preview",
193
- setup: integratedPr2,
194
- intent: () => ({ kind: "revert", input: { repo: REPO, target: { prNumber: 2 } } }),
195
- },
196
- {
197
- id: "sync-preview",
198
- kind: "sync-preview",
199
- provider: null,
200
- lane: "preview",
201
- setup: async () => {},
202
- intent: () => ({ kind: "sync-preview", input: { repo: REPO, sha: "c-1", source: "push" } }),
203
- // The same push forwarded twice (two forwarders, or a redelivery): one job.
204
- deliveries: 2,
205
- },
206
- ];
207
-
208
- function liveScenarios(provider: Provider): Scenario[] {
209
- const name = PROVIDER_NAME[provider];
210
- return [
211
- {
212
- id: `publish × ${name}`,
213
- kind: "publish",
214
- provider,
215
- lane: "live",
216
- setup: async (t) => {
217
- await cloudFrontServesEarlier(t, provider);
218
- await seedRelease(t, provider, "sha-1", "run-1");
219
- },
220
- intent: (t) => ({
221
- kind: "publish",
222
- input: publishInput(provider, provider === "worker-r2-pointer" ? aggregateWithSettings(t.id) : AGGREGATE),
223
- }),
224
- },
225
- {
226
- id: `rollback × ${name}`,
227
- kind: "rollback",
228
- provider,
229
- lane: "live",
230
- setup: async (t) => {
231
- await cloudFrontServesEarlier(t, provider);
232
- await goLive(t, provider, "sha-1", "run-1");
233
- await goLive(t, provider, "sha-2", "run-2");
234
- },
235
- intent: (t) => ({ kind: "rollback", input: publishInput(provider, { kind: "release", receiptId: `rcpt:${t.id}:preview:run-1`, versionId: null }) }),
236
- },
237
- {
238
- id: `hotfix × ${name}`,
239
- kind: "hotfix",
240
- provider,
241
- lane: "live",
242
- setup: async (t) => {
243
- await cloudFrontServesEarlier(t, provider);
244
- await t.harness("configure", { patch: { hotfixMainSha: "main-9", hotfixAssets: true } });
245
- },
246
- intent: () => ({ kind: "hotfix", input: publishInput(provider, HOTFIX_TARGET) }),
247
- },
248
- ];
249
- }
250
-
251
- export const LIVE_SCENARIOS: Scenario[] = [...liveScenarios("worker-r2-pointer"), ...liveScenarios("s3-overwrite")];
252
-
253
- const SEED_PREVIEW = "a".repeat(40);
254
- const SEED_LIVE = "b".repeat(40);
255
-
256
- /**
257
- * `seed-from-legacy`: a store the legacy records left serving a preview tip and a live release,
258
- * with a run and a publication that never finished. The seed records the pipeline's first facts
259
- * for the provider the store serves on, and closes both records out.
260
- */
261
- function seedScenario(provider: Provider): Scenario {
262
- return {
263
- id: `seed-from-legacy × ${PROVIDER_NAME[provider]}`,
264
- kind: "seed-from-legacy",
265
- provider,
266
- lane: "live",
267
- setup: async (t) => {
268
- await t.harness("seedPointers", { preview: SEED_PREVIEW, live: SEED_LIVE });
269
- await t.harness("seedLegacy", { runId: "run-stale", sha: SEED_PREVIEW, opSubject: "op-stale" });
270
- },
271
- intent: (t) => ({
272
- kind: "seed-from-legacy",
273
- input: {
274
- tenantId: t.id,
275
- preview: {
276
- sha: SEED_PREVIEW,
277
- membership: [{ pr: 2, changeId: "pr-2", headSha: "head-pr-2" }],
278
- evidence: { digest: `digest-${SEED_PREVIEW}`, promotable: true },
279
- },
280
- live: { provider, sha: SEED_LIVE, receiptId: "rcpt-seeded", provedAt: null },
281
- abandon: { runs: ["run-stale"], ops: [{ operation: "publication", subjectId: "op-stale" }] },
282
- expect: { previewPointer: SEED_PREVIEW, livePointer: SEED_LIVE },
283
- },
284
- }),
285
- };
286
- }
287
-
288
- export const SEED_SCENARIOS: Scenario[] = [seedScenario("worker-r2-pointer"), seedScenario("s3-overwrite")];
289
-
290
- export const SCENARIOS: Scenario[] = [...PREVIEW_SCENARIOS, ...LIVE_SCENARIOS, ...SEED_SCENARIOS];
291
-
292
- // ── The driver ────────────────────────────────────────────────────────────────
293
-
294
- /** How the CI answers a publish/rollback dispatch (a hotfix's static prebuild is always staged and reported). */
295
- export type CallbackMode = "deliver" | "never" | "twice" | "superseded" | "cancel-first";
296
-
297
- export interface DriveNotes {
298
- /** Every answer to `deliverExternal`, in order, with the id it named. */
299
- deliveries: { correlationId: string; ok: boolean; duplicate: boolean | null; jobId: string | null }[];
300
- /** `superseded`: the job's state right after the stale callback was refused. */
301
- stateAfterStale: string | null;
302
- /** `cancel-first`: the cancelled dispatch, and the answer to its late callback. */
303
- cancelled: string | null;
304
- lateCallback: { ok: boolean } | null;
305
- }
306
-
307
- export const success = (sha: string, digest: string | null) => ({
308
- status: "succeeded",
309
- deliveredSourceSha: sha,
310
- deliveredTreeDigest: digest,
311
- runUrl: null,
312
- error: null,
313
- findings: [],
314
- });
315
-
316
- /**
317
- * Drive `jobId` to a terminal state, answering every external wait as the world would. Returns the
318
- * terminal job. `callbacks` shapes the answer to the FIRST publish/rollback CI dispatch only;
319
- * `handled` names waits the caller already answered.
320
- */
321
- export async function drive(
322
- t: Tenant,
323
- jobId: string,
324
- opts: { callbacks?: CallbackMode; timeoutMs?: number; handled?: string[] } = {},
325
- ): Promise<{ job: JobView; notes: DriveNotes }> {
326
- const mode = opts.callbacks ?? "deliver";
327
- const notes: DriveNotes = { deliveries: [], stateAfterStale: null, cancelled: null, lateCallback: null };
328
- /** Waits already answered (by the caller, or earlier in this drive). */
329
- const handled = new Set<string>(opts.handled ?? []);
330
- let shaped = false;
331
- const deadline = Date.now() + (opts.timeoutMs ?? 45_000);
332
- const deliver = async (id: string, payload: unknown) => {
333
- const r = await t.deliver(id, payload);
334
- notes.deliveries.push({ correlationId: id, ok: r.ok, duplicate: r.ok ? r.duplicate : null, jobId: r.ok ? r.jobId : null });
335
- return r;
336
- };
337
- for (;;) {
338
- const job = await t.job(jobId);
339
- if (!job) throw new Error(`job ${jobId} vanished`);
340
- if (TERMINAL.has(job.state)) return { job, notes };
341
- if (Date.now() > deadline) throw new Error(`job ${jobId} (${job.kind}) not terminal: ${JSON.stringify([job.step, job.state, job.attempt])}`);
342
- const waitingOn = job.state === "awaiting-external" ? job.awaiting : null;
343
- if (waitingOn && !handled.has(waitingOn)) {
344
- const dispatch = (await t.harness<CiDispatch[]>("dispatches")).find((d) => d.dispatchId === waitingOn);
345
- if (dispatch) {
346
- handled.add(waitingOn);
347
- if (dispatch.workflow === "www-candidate-prebuild") {
348
- const digest = `digest-${dispatch.versionId}`;
349
- await t.harness("completeStage", { dispatchId: waitingOn, conclusion: "success", digest });
350
- await deliver(waitingOn, success(dispatch.versionId, digest));
351
- } else {
352
- const tree = `tree-${dispatch.versionId}`;
353
- const shape = shaped ? "deliver" : mode;
354
- shaped = true;
355
- if (shape === "cancel-first") {
356
- notes.cancelled = waitingOn;
357
- await t.harness("completeRun", { dispatchId: waitingOn, conclusion: "cancelled" });
358
- } else {
359
- if (notes.cancelled) {
360
- // The cancelled run's callback arrives late, after the job re-dispatched: refused.
361
- const late = await t.deliver(notes.cancelled, success(dispatch.versionId, tree));
362
- notes.lateCallback = { ok: late.ok };
363
- }
364
- await t.harness("completeRun", { dispatchId: waitingOn, conclusion: "success", served: { treeDigest: tree } });
365
- if (shape === "superseded") {
366
- await deliver(`dsp:superseded:${waitingOn}`, success(dispatch.versionId, tree));
367
- notes.stateAfterStale = (await t.job(jobId))?.state ?? null;
368
- }
369
- if (shape !== "never") await deliver(waitingOn, success(dispatch.versionId, tree));
370
- if (shape === "twice") await deliver(waitingOn, success(dispatch.versionId, tree));
371
- }
372
- }
373
- }
374
- }
375
- await sleep(30);
376
- }
377
- }
378
-
379
- // ── A cell ────────────────────────────────────────────────────────────────────
380
-
381
- export interface EndState {
382
- live: { versionId: string | null; treeDigest: string | null };
383
- liveRecords: { provider: string; sha: string; receiptId: string }[];
384
- truth: {
385
- liveReceiptId: string | null;
386
- pendingReceiptId: string | null;
387
- deliveryState: string | null;
388
- unprovenLive: unknown;
389
- liveDisagrees: unknown;
390
- } | null;
391
- receipts: { receiptId: string; sha: string }[];
392
- promotion: { versionId: string; digest: string } | null;
393
- cloudfront: { sha: string; treeDigest: string | null } | null;
394
- assetsLive: string | null;
395
- /** The request-scoped records a seed closes out. */
396
- legacy: { runs: { runId: string; state: string }[]; op: string | null };
397
- preview: Record<string, unknown>;
398
- }
399
-
400
- export interface Health {
401
- alarm: number | null;
402
- active: { jobId: string; state: string }[];
403
- compensations: { jobId: string; exhausted: boolean; reported: boolean }[];
404
- }
405
-
406
- export interface CellRun {
407
- tenant: Tenant;
408
- jobId: string;
409
- jobIds: string[];
410
- job: JobView;
411
- notes: DriveNotes;
412
- log: TransitionView[];
413
- all: TransitionView[];
414
- kills: MatrixKill[];
415
- effects: MatrixEffect[];
416
- execs: { step: string; n: number }[];
417
- dispatches: CiDispatch[];
418
- end: EndState;
419
- health: Health;
420
- }
421
-
422
- export interface CellSpec {
423
- scenario: Scenario;
424
- fault?: MatrixFault;
425
- callbacks?: CallbackMode;
426
- /** Extra arrangement after the scenario's setup, before the intent (e.g. a lost dispatch response). */
427
- arrange?: (t: Tenant) => Promise<void>;
428
- }
429
-
430
- function slug(text: string): string {
431
- return text.replace(/[^a-z0-9]+/gi, "-").replace(/^-|-$/g, "").toLowerCase();
432
- }
433
-
434
- /** The tenant id never survives into a comparison: every cell has its own. */
435
- export function normalize<T>(value: T, tenantId: string): T {
436
- return JSON.parse(JSON.stringify(value).split(tenantId).join("<tenant>")) as T;
437
- }
438
-
439
- /** Wait until nothing is active and every compensation has settled (or the budget runs out). */
440
- export async function settle(t: Tenant, timeoutMs = 20_000): Promise<Health> {
441
- const deadline = Date.now() + timeoutMs;
442
- for (;;) {
443
- const health = await t.matrix<Health>("health");
444
- const unsettled = health.compensations.filter((c) => !(c.exhausted && c.reported));
445
- if ((health.active.length === 0 && unsettled.length === 0) || Date.now() > deadline) return health;
446
- await sleep(50);
447
- }
448
- }
449
-
450
- export async function collect(t: Tenant, jobId: string, jobIds: string[], job: JobView, notes: DriveNotes): Promise<CellRun> {
451
- const health = await settle(t);
452
- const [log, all, kills, effects, execs, dispatches, end, final] = await Promise.all([
453
- t.transitions(jobId),
454
- t.transitions(),
455
- t.matrix<MatrixKill[]>("kills"),
456
- t.matrix<MatrixEffect[]>("effects", { jobId }),
457
- t.matrix<{ step: string; n: number }[]>("execs", { jobId }),
458
- t.harness<CiDispatch[]>("dispatches"),
459
- t.matrix<EndState>("endState", { tenantId: t.id }),
460
- t.job(jobId),
461
- ]);
462
- return {
463
- tenant: t,
464
- jobId,
465
- jobIds,
466
- job: final ?? job,
467
- notes,
468
- log,
469
- all,
470
- kills,
471
- effects,
472
- execs,
473
- dispatches,
474
- end: normalize(end, t.id),
475
- health,
476
- };
477
- }
478
-
479
- export async function runCell(spec: CellSpec): Promise<CellRun> {
480
- const t = new Tenant(uniqueTenant(slug(spec.scenario.id)));
481
- await spec.scenario.setup(t);
482
- await spec.arrange?.(t);
483
- if (spec.fault) await t.matrix("arm", spec.fault as unknown as Record<string, unknown>);
484
- const intent = spec.scenario.intent(t);
485
- const jobIds: string[] = [];
486
- for (let i = 0; i < (spec.scenario.deliveries ?? 1); i += 1) jobIds.push(await t.submit(intent.kind, intent.input));
487
- const jobId = jobIds[0]!;
488
- const { job, notes } = await drive(t, jobId, spec.callbacks ? { callbacks: spec.callbacks } : {});
489
- return collect(t, jobId, jobIds, job, notes);
490
- }
491
-
492
- const baselines = new Map<string, Promise<CellRun>>();
493
-
494
- /** The scenario's unfaulted run, once per suite. */
495
- export function baselineOf(scenario: Scenario): Promise<CellRun> {
496
- let run = baselines.get(scenario.id);
497
- if (!run) {
498
- run = runCell({ scenario });
499
- baselines.set(scenario.id, run);
500
- }
501
- return run;
502
- }
503
-
504
- // ── Convergence ───────────────────────────────────────────────────────────────
505
-
506
- /**
507
- * External effects that must happen at most as often as in the unfaulted run (never twice for one
508
- * cause). The others are keyed or idempotent in production, so a resumed step repeating them is
509
- * correct: `forge:prepare-undo` opens the undo candidate under a fixed change id (`undoChangeId`),
510
- * `forge:forward-integrate` merges current main into preview ("already up to date" the second time),
511
- * `notice:went-live` is deduplicated per post (`socialPostedKey`), and pointer, assets, report,
512
- * designation and build writes put the same value again.
513
- */
514
- export const ONCE_EFFECTS: ReadonlySet<string> = new Set([
515
- "forge:merge",
516
- "forge:rebase",
517
- "email:conflict",
518
- "ci:stage-aggregate",
519
- "ci:www-publish",
520
- "ci:www-rollback",
521
- "ci:www-promote",
522
- "ci:www-candidate-prebuild",
523
- "forge:merge-to-main",
524
- ]);
525
-
526
- const OUTCOME_NOTES = new Set(["step-done", "checkpoint", "lease-expired", "yielded"]);
527
-
528
- export function stepStarts(log: TransitionView[]): string[] {
529
- return [...new Set(log.filter((t) => t.note?.startsWith("step-start")).map((t) => t.step))];
530
- }
531
-
532
- export function countBy<T>(items: T[], key: (item: T) => string): Record<string, number> {
533
- const out: Record<string, number> = {};
534
- for (const item of items) out[key(item)] = (out[key(item)] ?? 0) + 1;
535
- return out;
536
- }
537
-
538
- /** The job's log is one complete chain: created, started, each step start resolved, one terminal state at the end. */
539
- export function chainViolations(log: TransitionView[]): string[] {
540
- const v: string[] = [];
541
- if (log.length < 3) return [`transition log has ${log.length} entries`];
542
- if (log[0]!.from !== "none" || log[0]!.to !== "queued") v.push(`log starts ${log[0]!.from}→${log[0]!.to}`);
543
- for (let i = 1; i < log.length; i += 1) {
544
- if (log[i]!.from !== log[i - 1]!.to) v.push(`transition ${i} (${log[i]!.note}) does not continue the chain`);
545
- }
546
- const terminals = log.filter((t) => TERMINAL.has(t.to) && !TERMINAL.has(t.from));
547
- if (terminals.length !== 1) v.push(`${terminals.length} terminal transitions`);
548
- for (let i = 0; i < log.length; i += 1) {
549
- const t = log[i]!;
550
- if (!t.note?.startsWith("step-start")) continue;
551
- const next = log[i + 1];
552
- const resolved =
553
- next &&
554
- ((next.step === t.step && next.attempt === t.attempt && (OUTCOME_NOTES.has(next.note ?? "") || next.note?.startsWith("step-failed"))) ||
555
- next.note === "step-start; previous execution did not finish" ||
556
- next.to === "awaiting-external" ||
557
- TERMINAL.has(next.to));
558
- if (!resolved) v.push(`step-start ${t.step}#${t.attempt} has no recorded outcome`);
559
- }
560
- return v;
561
- }
562
-
563
- /** Across every job of the tenant: between a step's start and its outcome, no other step starts. */
564
- export function overlapViolations(all: TransitionView[], kills: readonly MatrixKill[] = [], effects: readonly MatrixEffect[] = []): string[] {
565
- let open: TransitionView | null = null;
566
- for (const t of all) {
567
- // A recorded abort ends only its exact execution; any later effect keeps the overlap visible.
568
- if (open && kills.some((kill) => ["before", "after", "resume", "effect"].includes(kill.mode) && !!kill.instanceId && kill.execution > 0 &&
569
- kill.jobId === open!.jobId && kill.step === open!.step && kill.stepStartSeq === open!.seq &&
570
- kill.transitionSeq >= open!.seq && kill.transitionSeq < t.seq &&
571
- !effects.some((effect) => effect.jobId === kill.jobId && effect.step === kill.step &&
572
- effect.instanceId === kill.instanceId && effect.execution === kill.execution && effect.seq > kill.effectSeq))) open = null;
573
- if (t.note?.startsWith("step-start")) {
574
- if (open && open.jobId !== t.jobId) return [`step ${t.step} of ${t.jobId} started while ${open.step} of ${open.jobId} was running`];
575
- open = t;
576
- } else if (
577
- open &&
578
- t.jobId === open.jobId &&
579
- (OUTCOME_NOTES.has(t.note ?? "") || t.note?.startsWith("step-failed") || t.to === "awaiting-external" || TERMINAL.has(t.to))
580
- ) {
581
- open = null;
582
- }
583
- }
584
- return [];
585
- }
586
-
587
- /**
588
- * What the job's own outcome says about why it ended (a `JobEnded` error's reason only points at
589
- * it): its reason code and message, or null when the job recorded none.
590
- */
591
- export function outcomeOf(job: JobView): string | null {
592
- const outcome = job.produces?.outcome as { reason?: unknown; message?: unknown } | undefined;
593
- if (!outcome || typeof outcome !== "object") return null;
594
- const parts = [outcome.reason, outcome.message].filter((p): p is string => typeof p === "string" && p.length > 0);
595
- return parts.length ? parts.join(": ") : JSON.stringify(outcome);
596
- }
597
-
598
- function diffKeys(a: Record<string, unknown>, b: Record<string, unknown>, keys: string[]): string[] {
599
- return keys.filter((k) => JSON.stringify(a[k]) !== JSON.stringify(b[k]));
600
- }
601
-
602
- export const LIVE_END_KEYS = ["live", "liveRecords", "truth", "receipts", "promotion", "cloudfront", "assetsLive"] as const;
603
- /** Every end-state key a cell is compared on. */
604
- const END_KEYS = [...LIVE_END_KEYS, "legacy", "preview"] as const;
605
-
606
- export interface ConvergenceOptions {
607
- /** The fault was armed and must have fired. */
608
- expectKill: boolean;
609
- /** End-state keys this cell legitimately changes (with why, in the caller). */
610
- ignoreEnd?: string[];
611
- /** Effect counts this cell legitimately adds (a cancelled run's re-dispatch). */
612
- extraEffects?: Record<string, number>;
613
- }
614
-
615
- /**
616
- * Everything the convergence guarantee says about one cell, as findings named
617
- * `<assertion>: <detail>` (empty when it holds):
618
- * verdict the job reaches the unfaulted run's terminal verdict
619
- * orphan nothing is left non-terminal (or a compensation unsettled) without an alarm — at the
620
- * kill instant and at the end
621
- * live==record `live` and the engine's live record agree (or the ledger surfaces unprovenLive /
622
- * liveDisagrees) at the end; at the kill instant they may differ only while the job's
623
- * compensation is armed to put `live` back
624
- * duplicate no once-only external effect (merge, dispatch, email, promote, notice) happens more
625
- * often than unfaulted
626
- * compensation a pending compensation settles
627
- * coalesced a duplicate delivery of one intent is the same job
628
- * log the job's transition log is one complete chain and finishes the unfaulted steps, in order
629
- * end-state what the job leaves behind equals the unfaulted run's
630
- */
631
- export function convergence(cell: CellRun, base: CellRun, opts: ConvergenceOptions): string[] {
632
- const v: string[] = [];
633
- const { job } = cell;
634
- if (job.state !== base.job.state || job.error?.code !== base.job.error?.code) {
635
- const outcome = outcomeOf(job);
636
- v.push(
637
- `verdict: ${job.state}${job.error ? ` (${job.error.code}: ${job.error.reason})` : ""}${outcome ? ` outcome: ${outcome}` : ""}, unfaulted ${base.job.state}`,
638
- );
639
- }
640
- if (opts.expectKill && cell.kills.length === 0) v.push("fired: the armed fault never fired");
641
-
642
- for (const kill of cell.kills) {
643
- const where = `${kill.step}/${kill.mode}${kill.effect ? `:${kill.effect}` : ""}`;
644
- if (kill.alarm === null && (kill.activeJobs > 0 || kill.pendingCompensations > 0)) {
645
- v.push(`orphan: killed at ${where} with ${kill.activeJobs} active job(s) and no alarm to resume them`);
646
- }
647
- // `live` may run ahead of the record only while something will reconcile them: the job's armed
648
- // compensation (a Cloudflare flip before its proof), or — CloudFront — `live` naming what the
649
- // public host is already proven to serve, which the resumed job records.
650
- if (kill.live !== kill.record && !kill.armed && !(kill.served !== null && kill.live === kill.served)) {
651
- v.push(`live==record: killed at ${where} with live=${kill.live} record=${kill.record} and no compensation armed`);
652
- }
653
- }
654
- for (const a of cell.health.active) v.push(`orphan: job ${a.jobId === cell.jobId ? "under test" : a.jobId} still ${a.state}`);
655
- for (const c of cell.health.compensations.filter((c) => !(c.exhausted && c.reported))) {
656
- v.push(`compensation: ${c.jobId === cell.jobId ? "the job's" : c.jobId} compensation never settled${cell.health.alarm === null ? " (and no alarm)" : ""}`);
657
- }
658
-
659
- if (new Set(cell.jobIds).size !== 1) v.push(`coalesced: ${cell.jobIds.length} deliveries made ${new Set(cell.jobIds).size} jobs`);
660
-
661
- const end = cell.end;
662
- const input = job.input as { provider?: string | null };
663
- if (job.lane === "live" && "provider" in input && job.state === "succeeded") {
664
- const provider = input.provider ?? "worker-r2-pointer";
665
- const record = end.liveRecords.find((r) => r.provider === provider)?.sha ?? null;
666
- const receiptSha = end.receipts.find((r) => r.receiptId === end.truth?.liveReceiptId)?.sha ?? null;
667
- const surfaced = end.truth?.unprovenLive != null || end.truth?.liveDisagrees != null;
668
- if (!surfaced && (end.live.versionId !== record || end.live.versionId !== receiptSha)) {
669
- v.push(`live==record: live=${end.live.versionId} record=${record} ledger=${receiptSha}, nothing surfaced`);
670
- }
671
- if (provider === "s3-overwrite" && !surfaced && end.cloudfront?.sha !== end.live.versionId) {
672
- v.push(`live==record: CloudFront serves ${end.cloudfront?.sha ?? "nothing"} while live names ${end.live.versionId}`);
673
- }
674
- }
675
-
676
- const cellOnce = countBy(cell.effects.filter((e) => ONCE_EFFECTS.has(e.effect)), (e) => e.effect);
677
- const baseOnce = countBy(base.effects.filter((e) => ONCE_EFFECTS.has(e.effect)), (e) => e.effect);
678
- for (const [effect, n] of Object.entries(cellOnce)) {
679
- const allowed = (baseOnce[effect] ?? 0) + (opts.extraEffects?.[effect] ?? 0);
680
- if (n > allowed) {
681
- const steps = [...new Set(cell.effects.filter((e) => e.effect === effect).map((e) => e.step))].join(",");
682
- v.push(`duplicate: ${effect} ${n}× (unfaulted ${baseOnce[effect] ?? 0}×) at ${steps}`);
683
- }
684
- }
685
-
686
- for (const finding of chainViolations(cell.log)) v.push(`log: ${finding}`);
687
- const done = cell.log.filter((t) => t.note === "step-done").map((t) => t.step);
688
- const baseDone = base.log.filter((t) => t.note === "step-done").map((t) => t.step);
689
- if (JSON.stringify(done) !== JSON.stringify(baseDone)) v.push(`log: finished [${done.join(",")}], unfaulted [${baseDone.join(",")}]`);
690
-
691
- const keys = END_KEYS.filter((k) => !opts.ignoreEnd?.includes(k));
692
- for (const key of diffKeys(end as unknown as Record<string, unknown>, base.end as unknown as Record<string, unknown>, keys)) {
693
- v.push(`end-state: ${key} = ${JSON.stringify((end as unknown as Record<string, unknown>)[key])}, unfaulted ${JSON.stringify((base.end as unknown as Record<string, unknown>)[key])}`);
694
- }
695
- return v;
696
- }