@empire-builder-kit/nx 1.0.0-rc.47 → 1.0.0-rc.48

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 (764) hide show
  1. package/README.md +14 -169
  2. package/executors.json +24 -79
  3. package/generators.json +8 -18
  4. package/package.json +13 -71
  5. package/src/aws/identity.d.ts +1 -1
  6. package/src/aws-authority/boundary-transforms.d.ts +9 -0
  7. package/src/aws-authority/boundary-transforms.js +78 -0
  8. package/src/aws-authority/contracts.d.ts +116 -0
  9. package/src/aws-authority/contracts.js +40 -0
  10. package/src/aws-authority/deployment-guardrails.d.ts +4 -0
  11. package/src/aws-authority/deployment-guardrails.js +543 -0
  12. package/src/aws-authority/deployment-policy-groups.d.ts +3 -0
  13. package/src/aws-authority/deployment-policy-groups.js +299 -0
  14. package/src/aws-authority/deployment-resources.d.ts +64 -0
  15. package/src/aws-authority/deployment-resources.js +265 -0
  16. package/src/aws-authority/deployment-services.d.ts +3 -0
  17. package/src/aws-authority/deployment-services.js +717 -0
  18. package/src/aws-authority/development-authority.d.ts +11 -0
  19. package/src/aws-authority/development-authority.js +160 -0
  20. package/src/aws-authority/guardrail-actions.d.ts +87 -0
  21. package/src/aws-authority/guardrail-actions.js +463 -0
  22. package/src/aws-authority/policy-document.d.ts +15 -0
  23. package/src/aws-authority/policy-document.js +264 -0
  24. package/src/aws-authority/runtime-boundary.d.ts +7 -0
  25. package/src/aws-authority/runtime-boundary.js +211 -0
  26. package/src/aws-authority/service-actions.d.ts +96 -0
  27. package/src/aws-authority/service-actions.js +512 -0
  28. package/src/aws-authority/stage-authority.d.ts +6 -272
  29. package/src/aws-authority/stage-authority.js +109 -3609
  30. package/src/aws-authority/stage-identity.d.ts +6 -0
  31. package/src/aws-authority/stage-identity.js +134 -0
  32. package/src/cli/bootstrap.d.ts +0 -20
  33. package/src/cli/bootstrap.js +2 -153
  34. package/src/cli/dev-command.d.ts +2 -4
  35. package/src/cli/dev-command.js +1 -19
  36. package/src/cli/main.d.ts +0 -4
  37. package/src/cli/main.js +22 -80
  38. package/src/cli/output.d.ts +2 -4
  39. package/src/cli/output.js +2 -8
  40. package/src/executors/deployment-plan/deployment-plan.d.ts +0 -2
  41. package/src/executors/deployment-plan/deployment-plan.js +3 -68
  42. package/src/executors/dev-doctor/dev-doctor.js +2 -2
  43. package/src/executors/local-deploy/deployed-smoke.d.ts +12 -0
  44. package/src/executors/local-deploy/deployed-smoke.js +115 -0
  45. package/src/executors/local-deploy/deployment-authority.d.ts +24 -0
  46. package/src/executors/local-deploy/deployment-authority.js +81 -0
  47. package/src/executors/local-deploy/deployment-child.d.ts +18 -0
  48. package/src/executors/local-deploy/deployment-child.js +77 -0
  49. package/src/executors/local-deploy/deployment-contracts.d.ts +96 -0
  50. package/src/executors/local-deploy/deployment-contracts.js +3 -0
  51. package/src/executors/local-deploy/deployment-projects.d.ts +4 -0
  52. package/src/executors/local-deploy/deployment-projects.js +16 -0
  53. package/src/executors/local-deploy/deployment-receipt.d.ts +4 -0
  54. package/src/executors/local-deploy/deployment-receipt.js +55 -0
  55. package/src/executors/local-deploy/deployment-scope.d.ts +17 -0
  56. package/src/executors/local-deploy/deployment-scope.js +239 -0
  57. package/src/executors/local-deploy/deployment-source.d.ts +13 -0
  58. package/src/executors/local-deploy/deployment-source.js +86 -0
  59. package/src/executors/local-deploy/local-deploy.d.ts +5 -121
  60. package/src/executors/local-deploy/local-deploy.js +55 -936
  61. package/src/executors/sst-lifecycle/governed-child-process.d.ts +27 -0
  62. package/src/executors/sst-lifecycle/governed-child-process.js +277 -0
  63. package/src/executors/sst-lifecycle/governed-native-operation.js +4 -10
  64. package/src/executors/sst-lifecycle/run-sst-command.d.ts +4 -85
  65. package/src/executors/sst-lifecycle/run-sst-command.js +28 -834
  66. package/src/executors/sst-lifecycle/sst-contracts.d.ts +44 -0
  67. package/src/executors/sst-lifecycle/sst-contracts.js +3 -0
  68. package/src/executors/sst-lifecycle/sst-invocation.d.ts +17 -0
  69. package/src/executors/sst-lifecycle/sst-invocation.js +502 -0
  70. package/src/executors/sst-lifecycle/task-unlock.js +3 -3
  71. package/src/foundation/discovery.d.ts +1 -5
  72. package/src/foundation/discovery.js +0 -2
  73. package/src/foundation/index.d.ts +0 -2
  74. package/src/foundation/index.js +0 -9
  75. package/src/foundation/local-private-smoke-access.d.ts +6 -15
  76. package/src/foundation/local-private-smoke-access.js +8 -192
  77. package/src/foundation/observability.d.ts +16 -26
  78. package/src/foundation/observability.js +34 -135
  79. package/src/foundation/preflight.js +0 -14
  80. package/src/foundation/private-smoke-access.d.ts +7 -14
  81. package/src/foundation/private-smoke-access.js +4 -126
  82. package/src/foundation/root-site-workspace.d.ts +35 -0
  83. package/src/foundation/root-site-workspace.js +80 -0
  84. package/src/foundation/root-site.d.ts +8 -7
  85. package/src/foundation/root-site.js +17 -9
  86. package/src/generators/formatting.js +5 -4
  87. package/src/generators/function/function.d.ts +9 -5
  88. package/src/generators/function/function.js +106 -136
  89. package/src/generators/function/schema.json +2 -2
  90. package/src/generators/function-access/function-access.d.ts +0 -6
  91. package/src/generators/function-access/function-access.js +41 -109
  92. package/src/generators/observability-policy.js +1 -2
  93. package/src/{supply-chain → generators}/pnpm-toolchain-authority.d.ts +3 -3
  94. package/src/{supply-chain → generators}/pnpm-toolchain-authority.js +12 -12
  95. package/src/generators/post-generation-install.d.ts +1 -8
  96. package/src/generators/post-generation-install.js +11 -139
  97. package/src/generators/preset/dependency-overrides.d.ts +13 -19
  98. package/src/generators/preset/dependency-overrides.js +12 -56
  99. package/src/generators/preset/generator.js +0 -3
  100. package/src/generators/preset/workspace-files-foundation-infra.d.ts +6 -0
  101. package/src/generators/preset/workspace-files-foundation-infra.js +586 -0
  102. package/src/generators/preset/workspace-files-foundation-readme.d.ts +5 -0
  103. package/src/generators/preset/workspace-files-foundation-readme.js +90 -0
  104. package/src/generators/preset/workspace-files-foundation.d.ts +3 -0
  105. package/src/generators/preset/workspace-files-foundation.js +170 -0
  106. package/src/generators/preset/workspace-files-ownership.d.ts +9 -0
  107. package/src/generators/preset/workspace-files-ownership.js +124 -0
  108. package/src/generators/preset/workspace-files-root-config.d.ts +32 -0
  109. package/src/generators/preset/workspace-files-root-config.js +356 -0
  110. package/src/generators/preset/workspace-files-root-docs.d.ts +5 -0
  111. package/src/generators/preset/workspace-files-root-docs.js +109 -0
  112. package/src/generators/preset/workspace-files-shared.d.ts +18 -0
  113. package/src/generators/preset/workspace-files-shared.js +7 -0
  114. package/src/generators/preset/workspace-files-workflows.d.ts +39 -0
  115. package/src/generators/preset/workspace-files-workflows.js +306 -0
  116. package/src/generators/preset/workspace-files-workspace-health.d.ts +6 -0
  117. package/src/generators/preset/workspace-files-workspace-health.js +148 -0
  118. package/src/generators/preset/workspace-files.d.ts +10 -24
  119. package/src/generators/preset/workspace-files.js +48 -10705
  120. package/src/generators/site/built-in-site-documentation-files.d.ts +2 -1
  121. package/src/generators/site/built-in-site-documentation-files.js +15 -56
  122. package/src/generators/site/built-in-site-files.d.ts +4 -1
  123. package/src/generators/site/built-in-site-files.js +12 -11
  124. package/src/generators/site/built-in-site-infrastructure-files.d.ts +2 -1
  125. package/src/generators/site/built-in-site-infrastructure-files.js +46 -206
  126. package/src/generators/site/built-in-site-plan.d.ts +5 -1
  127. package/src/generators/site/built-in-site-plan.js +7 -5
  128. package/src/generators/site/built-in-site-project-files.d.ts +10 -2
  129. package/src/generators/site/built-in-site-project-files.js +131 -177
  130. package/src/generators/site/built-in-site-script-files.d.ts +2 -0
  131. package/src/generators/site/built-in-site-script-files.js +76 -280
  132. package/src/generators/site/built-in-site-shared.d.ts +64 -4
  133. package/src/generators/site/built-in-site-shared.js +307 -14
  134. package/src/generators/site/built-in-site-sst-config-files.d.ts +2 -1
  135. package/src/generators/site/built-in-site-sst-config-files.js +90 -22
  136. package/src/generators/site/built-in-site-web-files.d.ts +2 -1
  137. package/src/generators/site/built-in-site-web-files.js +19 -225
  138. package/src/generators/site/schema.d.ts +5 -0
  139. package/src/generators/site/schema.json +6 -0
  140. package/src/generators/site/site.d.ts +0 -8
  141. package/src/generators/site/site.js +17 -85
  142. package/src/generators/slice/built-in-plan-api-files.d.ts +1 -2
  143. package/src/generators/slice/built-in-plan-api-files.js +30 -890
  144. package/src/generators/slice/built-in-plan-database-lifecycle-files.js +57 -1851
  145. package/src/generators/slice/built-in-plan-infrastructure-files.d.ts +5 -2
  146. package/src/generators/slice/built-in-plan-infrastructure-files.js +80 -3272
  147. package/src/generators/slice/built-in-plan-key-value-files.d.ts +3 -2
  148. package/src/generators/slice/built-in-plan-key-value-files.js +3 -21
  149. package/src/generators/slice/built-in-plan-project-files.d.ts +5 -3
  150. package/src/generators/slice/built-in-plan-project-files.js +79 -897
  151. package/src/generators/slice/built-in-plan-shared.d.ts +3 -18
  152. package/src/generators/slice/built-in-plan-shared.js +4 -57
  153. package/src/generators/slice/built-in-plan-web-files.d.ts +1 -1
  154. package/src/generators/slice/built-in-plan-web-files.js +14 -540
  155. package/src/generators/slice/built-in-plan.d.ts +2 -3
  156. package/src/generators/slice/built-in-plan.js +79 -277
  157. package/src/{developer-agent/preview-changes.d.ts → generators/slice/generation-tree.d.ts} +1 -5
  158. package/src/generators/slice/generation-tree.js +161 -0
  159. package/src/generators/slice/schema.json +12 -4
  160. package/src/generators/slice/slice-config.d.ts +7 -0
  161. package/src/generators/slice/slice-config.js +125 -0
  162. package/src/generators/slice/slice.js +29 -261
  163. package/src/generators/slice/sql-bootstrap.d.ts +1 -0
  164. package/src/generators/slice/sql-bootstrap.js +505 -0
  165. package/src/generators/slice/sql-client.d.ts +1 -0
  166. package/src/generators/slice/sql-client.js +107 -0
  167. package/src/generators/slice/sql-infrastructure.d.ts +1 -0
  168. package/src/generators/slice/sql-infrastructure.js +225 -0
  169. package/src/generators/slice/sql-logging.d.ts +1 -0
  170. package/src/generators/slice/sql-logging.js +266 -0
  171. package/src/generators/slice/sql-migration.d.ts +2 -0
  172. package/src/generators/slice/sql-migration.js +202 -0
  173. package/src/generators/slice/standard-slice-contract.d.ts +25 -0
  174. package/src/generators/slice/standard-slice-contract.js +64 -0
  175. package/src/generators/sql/schema.json +1 -1
  176. package/src/generators/sql/sql.d.ts +1 -1
  177. package/src/generators/sql/sql.js +13 -7
  178. package/src/generators/upgrade/framework-package-upgrade.d.ts +4 -27
  179. package/src/generators/upgrade/framework-package-upgrade.js +16 -39
  180. package/src/generators/upgrade/framework-packages.d.ts +25 -0
  181. package/src/generators/upgrade/framework-packages.js +138 -0
  182. package/src/generators/upgrade/function-authentication-notice.d.ts +10 -18
  183. package/src/generators/upgrade/function-authentication-notice.js +24 -44
  184. package/src/generators/upgrade/schema.d.ts +0 -3
  185. package/src/generators/upgrade/schema.json +6 -16
  186. package/src/generators/upgrade/slice-compositions.d.ts +20 -0
  187. package/src/generators/upgrade/slice-compositions.js +100 -0
  188. package/src/generators/upgrade/slice-upgrade-guidance.d.ts +19 -0
  189. package/src/generators/upgrade/slice-upgrade-guidance.js +50 -0
  190. package/src/generators/upgrade/slice-upgrade.d.ts +4 -0
  191. package/src/generators/upgrade/slice-upgrade.js +231 -0
  192. package/src/generators/upgrade/upgrade-plan.d.ts +10 -13
  193. package/src/generators/upgrade/upgrade-plan.js +33 -197
  194. package/src/generators/upgrade/upgrade-preflight.d.ts +20 -0
  195. package/src/generators/upgrade/upgrade-preflight.js +64 -0
  196. package/src/generators/upgrade/upgrade.d.ts +8 -53
  197. package/src/generators/upgrade/upgrade.js +23 -1571
  198. package/src/generators/workload/schema.json +2 -2
  199. package/src/generators/workload/workload.d.ts +11 -11
  200. package/src/generators/workload/workload.js +166 -1255
  201. package/src/index.d.ts +0 -5
  202. package/src/index.js +0 -5
  203. package/src/local-dev/browser-verification.d.ts +0 -7
  204. package/src/local-dev/browser-verification.js +0 -136
  205. package/src/local-dev/contracts.d.ts +6 -0
  206. package/src/local-dev/contracts.js +17 -9
  207. package/src/local-dev/environment-checks.d.ts +126 -0
  208. package/src/local-dev/environment-checks.js +81 -0
  209. package/src/local-dev/environment-inspector.d.ts +3 -124
  210. package/src/local-dev/environment-inspector.js +9 -148
  211. package/src/local-dev/private-state.d.ts +1 -0
  212. package/src/local-dev/private-state.js +19 -23
  213. package/src/local-dev/process-identity.js +4 -2
  214. package/src/local-dev/slice-runner-child.d.ts +37 -0
  215. package/src/local-dev/slice-runner-child.js +127 -0
  216. package/src/local-dev/slice-runner-recovery.d.ts +32 -0
  217. package/src/local-dev/slice-runner-recovery.js +216 -0
  218. package/src/local-dev/slice-runner-state.d.ts +82 -0
  219. package/src/local-dev/slice-runner-state.js +265 -0
  220. package/src/local-dev/slice-runner.d.ts +4 -117
  221. package/src/local-dev/slice-runner.js +59 -594
  222. package/src/local-dev/tls.js +8 -97
  223. package/src/ownership/index.d.ts +1 -0
  224. package/src/ownership/index.js +6 -0
  225. package/src/ownership/pnpm-workspace.d.ts +77 -0
  226. package/src/ownership/pnpm-workspace.js +225 -0
  227. package/src/ownership/site-record.d.ts +8 -0
  228. package/src/ownership/site-record.js +17 -2
  229. package/src/repository-policy/capacity-migration.d.ts +1 -1
  230. package/src/repository-policy/capacity-migration.js +1 -1
  231. package/src/repository-policy/foundation-router.d.ts +17 -0
  232. package/src/repository-policy/foundation-router.js +44 -0
  233. package/src/repository-policy/index.d.ts +2 -0
  234. package/src/repository-policy/index.js +2 -0
  235. package/src/repository-policy/policy-accounts.d.ts +22 -0
  236. package/src/repository-policy/policy-accounts.js +134 -0
  237. package/src/repository-policy/policy-files.d.ts +8 -0
  238. package/src/repository-policy/policy-files.js +201 -0
  239. package/src/repository-policy/policy-internal.d.ts +2 -0
  240. package/src/repository-policy/policy-internal.js +11 -0
  241. package/src/repository-policy/policy-model.d.ts +95 -0
  242. package/src/repository-policy/policy-model.js +42 -0
  243. package/src/repository-policy/policy-validation.d.ts +4 -0
  244. package/src/repository-policy/policy-validation.js +308 -0
  245. package/src/repository-policy/policy.d.ts +5 -120
  246. package/src/repository-policy/policy.js +34 -662
  247. package/src/repository-policy/public-dns.d.ts +4 -0
  248. package/src/repository-policy/public-dns.js +102 -5
  249. package/src/{generators/repository-policy → repository-policy}/tree-policy.d.ts +1 -1
  250. package/src/{generators/repository-policy → repository-policy}/tree-policy.js +5 -5
  251. package/src/schemas/repository-policy-v1.json +40 -3
  252. package/src/secrets/index.d.ts +0 -5
  253. package/src/secrets/index.js +0 -5
  254. package/src/slice-infra/index.d.ts +57 -0
  255. package/src/slice-infra/index.js +117 -0
  256. package/src/slice-scripts/build.d.ts +27 -0
  257. package/src/slice-scripts/build.js +120 -0
  258. package/src/slice-scripts/database.d.ts +87 -0
  259. package/src/slice-scripts/database.js +328 -0
  260. package/src/slice-scripts/index.d.ts +11 -0
  261. package/src/slice-scripts/index.js +23 -0
  262. package/src/slice-scripts/root-site-routes.d.ts +11 -0
  263. package/src/slice-scripts/root-site-routes.js +83 -0
  264. package/src/slice-scripts/sql-migration-engine.mjs +180 -0
  265. package/src/workload-roles/effective-policy.d.ts +0 -37
  266. package/src/workload-roles/effective-policy.js +1 -174
  267. package/src/workload-roles/standard-slice.d.ts +2 -19
  268. package/src/workload-roles/standard-slice.js +3 -129
  269. package/src/api-contract/baseline-update.d.ts +0 -82
  270. package/src/api-contract/baseline-update.js +0 -225
  271. package/src/api-contract/compatibility.d.ts +0 -30
  272. package/src/api-contract/compatibility.js +0 -643
  273. package/src/api-contract/contract-graph.d.ts +0 -35
  274. package/src/api-contract/contract-graph.js +0 -141
  275. package/src/api-contract/evidence.d.ts +0 -23
  276. package/src/api-contract/evidence.js +0 -87
  277. package/src/api-contract/index.d.ts +0 -6
  278. package/src/api-contract/index.js +0 -10
  279. package/src/api-contract/model.d.ts +0 -144
  280. package/src/api-contract/model.js +0 -993
  281. package/src/api-contract/rollout.d.ts +0 -32
  282. package/src/api-contract/rollout.js +0 -88
  283. package/src/authorization/compatibility.d.ts +0 -62
  284. package/src/authorization/compatibility.js +0 -175
  285. package/src/authorization/index.d.ts +0 -1
  286. package/src/authorization/index.js +0 -5
  287. package/src/blueprints/execution.d.ts +0 -55
  288. package/src/blueprints/execution.js +0 -329
  289. package/src/blueprints/external-sandbox.d.ts +0 -53
  290. package/src/blueprints/external-sandbox.js +0 -1194
  291. package/src/blueprints/index.d.ts +0 -5
  292. package/src/blueprints/index.js +0 -9
  293. package/src/blueprints/inputs.d.ts +0 -43
  294. package/src/blueprints/inputs.js +0 -103
  295. package/src/blueprints/manifest.d.ts +0 -281
  296. package/src/blueprints/manifest.js +0 -424
  297. package/src/blueprints/resolver.d.ts +0 -37
  298. package/src/blueprints/resolver.js +0 -387
  299. package/src/blueprints/transitions.d.ts +0 -20
  300. package/src/blueprints/transitions.js +0 -61
  301. package/src/cli/agent-command.d.ts +0 -30
  302. package/src/cli/agent-command.js +0 -204
  303. package/src/cli/agent-runtime.d.ts +0 -25
  304. package/src/cli/agent-runtime.js +0 -498
  305. package/src/cli/blueprint-authority.d.ts +0 -9
  306. package/src/cli/blueprint-authority.js +0 -43
  307. package/src/cli/blueprint-command.d.ts +0 -24
  308. package/src/cli/blueprint-command.js +0 -63
  309. package/src/data-lifecycle/index.d.ts +0 -3
  310. package/src/data-lifecycle/index.js +0 -7
  311. package/src/data-lifecycle/model.d.ts +0 -172
  312. package/src/data-lifecycle/model.js +0 -95
  313. package/src/data-lifecycle/sensitive-artifacts.d.ts +0 -28
  314. package/src/data-lifecycle/sensitive-artifacts.js +0 -146
  315. package/src/data-lifecycle/validation.d.ts +0 -32
  316. package/src/data-lifecycle/validation.js +0 -837
  317. package/src/database-retirement/contract.d.ts +0 -68
  318. package/src/database-retirement/contract.js +0 -166
  319. package/src/database-retirement/index.d.ts +0 -1
  320. package/src/database-retirement/index.js +0 -5
  321. package/src/developer-agent/context.d.ts +0 -57
  322. package/src/developer-agent/context.js +0 -662
  323. package/src/developer-agent/generator-planning.d.ts +0 -34
  324. package/src/developer-agent/generator-planning.js +0 -759
  325. package/src/developer-agent/generator-preview.d.ts +0 -8
  326. package/src/developer-agent/generator-preview.js +0 -650
  327. package/src/developer-agent/git-inspection.d.ts +0 -112
  328. package/src/developer-agent/git-inspection.js +0 -887
  329. package/src/developer-agent/handoff.d.ts +0 -43
  330. package/src/developer-agent/handoff.js +0 -713
  331. package/src/developer-agent/index.d.ts +0 -10
  332. package/src/developer-agent/index.js +0 -14
  333. package/src/developer-agent/model.d.ts +0 -497
  334. package/src/developer-agent/model.js +0 -144
  335. package/src/developer-agent/operation-registry.d.ts +0 -61
  336. package/src/developer-agent/operation-registry.js +0 -1591
  337. package/src/developer-agent/ordering.d.ts +0 -9
  338. package/src/developer-agent/ordering.js +0 -15
  339. package/src/developer-agent/planning.d.ts +0 -25
  340. package/src/developer-agent/planning.js +0 -481
  341. package/src/developer-agent/preview-changes.js +0 -225
  342. package/src/developer-agent/preview-source.d.ts +0 -2
  343. package/src/developer-agent/preview-source.js +0 -19
  344. package/src/developer-agent/validation.d.ts +0 -30
  345. package/src/developer-agent/validation.js +0 -2729
  346. package/src/developer-agent/workspace-inspection.d.ts +0 -20
  347. package/src/developer-agent/workspace-inspection.js +0 -1236
  348. package/src/developer-agent/workspace-path.d.ts +0 -6
  349. package/src/developer-agent/workspace-path.js +0 -22
  350. package/src/executors/blueprint-trust/blueprint-trust.d.ts +0 -29
  351. package/src/executors/blueprint-trust/blueprint-trust.js +0 -121
  352. package/src/executors/blueprint-trust/schema.json +0 -27
  353. package/src/executors/blueprint-verification/blueprint-verification.d.ts +0 -13
  354. package/src/executors/blueprint-verification/blueprint-verification.js +0 -110
  355. package/src/executors/blueprint-verification/schema.json +0 -44
  356. package/src/executors/developer-context/developer-context.d.ts +0 -38
  357. package/src/executors/developer-context/developer-context.js +0 -78
  358. package/src/executors/developer-context/schema.json +0 -87
  359. package/src/executors/foundation-profile-preflight/foundation-profile-preflight.d.ts +0 -19
  360. package/src/executors/foundation-profile-preflight/foundation-profile-preflight.js +0 -105
  361. package/src/executors/foundation-profile-preflight/schema.json +0 -32
  362. package/src/executors/github-bootstrap/github-bootstrap.d.ts +0 -13
  363. package/src/executors/github-bootstrap/github-bootstrap.js +0 -62
  364. package/src/executors/github-bootstrap/schema.json +0 -50
  365. package/src/executors/infrastructure-plan/infrastructure-plan.d.ts +0 -37
  366. package/src/executors/infrastructure-plan/infrastructure-plan.js +0 -275
  367. package/src/executors/infrastructure-plan/schema.json +0 -38
  368. package/src/executors/router-waf-rehearsal/router-waf-rehearsal.d.ts +0 -42
  369. package/src/executors/router-waf-rehearsal/router-waf-rehearsal.js +0 -1229
  370. package/src/executors/router-waf-rehearsal/schema.json +0 -29
  371. package/src/executors/secret-guardrails/schema.json +0 -6
  372. package/src/executors/secret-guardrails/secret-guardrails.d.ts +0 -3
  373. package/src/executors/secret-guardrails/secret-guardrails.js +0 -44
  374. package/src/executors/secret-initialize/schema.json +0 -42
  375. package/src/executors/secret-initialize/secret-initialize.d.ts +0 -34
  376. package/src/executors/secret-initialize/secret-initialize.js +0 -297
  377. package/src/executors/secret-metadata/schema.json +0 -36
  378. package/src/executors/secret-metadata/secret-metadata.d.ts +0 -46
  379. package/src/executors/secret-metadata/secret-metadata.js +0 -230
  380. package/src/executors/sst-lifecycle/generated-secret-retirement.d.ts +0 -53
  381. package/src/executors/sst-lifecycle/generated-secret-retirement.js +0 -192
  382. package/src/executors/sst-lifecycle/logging-preflight.d.ts +0 -22
  383. package/src/executors/sst-lifecycle/logging-preflight.js +0 -217
  384. package/src/executors/sst-lifecycle/secret-preflight.d.ts +0 -27
  385. package/src/executors/sst-lifecycle/secret-preflight.js +0 -125
  386. package/src/executors/work-markers/schema.json +0 -14
  387. package/src/executors/work-markers/work-markers.d.ts +0 -6
  388. package/src/executors/work-markers/work-markers.js +0 -20
  389. package/src/foundation/cost-estimate.d.ts +0 -175
  390. package/src/foundation/cost-estimate.js +0 -706
  391. package/src/foundation/private-smoke-admission.d.ts +0 -45
  392. package/src/foundation/private-smoke-admission.js +0 -180
  393. package/src/foundation/private-smoke-control-plane.d.ts +0 -18
  394. package/src/foundation/private-smoke-control-plane.js +0 -184
  395. package/src/foundation/root-site-readiness.d.ts +0 -27
  396. package/src/foundation/root-site-readiness.js +0 -78
  397. package/src/foundation/router-waf-rate-rehearsal.d.ts +0 -97
  398. package/src/foundation/router-waf-rate-rehearsal.js +0 -210
  399. package/src/foundation/router-waf.d.ts +0 -149
  400. package/src/foundation/router-waf.js +0 -809
  401. package/src/frontend-security/index.d.ts +0 -1
  402. package/src/frontend-security/index.js +0 -5
  403. package/src/frontend-security/security-headers.d.ts +0 -50
  404. package/src/frontend-security/security-headers.js +0 -418
  405. package/src/generators/blueprint/blueprint.d.ts +0 -5
  406. package/src/generators/blueprint/blueprint.js +0 -102
  407. package/src/generators/blueprint/files.d.ts +0 -6
  408. package/src/generators/blueprint/files.js +0 -217
  409. package/src/generators/blueprint/schema.d.ts +0 -4
  410. package/src/generators/blueprint/schema.json +0 -18
  411. package/src/generators/feature-registry.d.ts +0 -13
  412. package/src/generators/feature-registry.js +0 -73
  413. package/src/generators/function/function-registration.d.ts +0 -24
  414. package/src/generators/function/function-registration.js +0 -66
  415. package/src/generators/observability-infrastructure.d.ts +0 -2
  416. package/src/generators/observability-infrastructure.js +0 -31
  417. package/src/generators/preset/workspace-files-adopter-skills.d.ts +0 -7
  418. package/src/generators/preset/workspace-files-adopter-skills.js +0 -359
  419. package/src/generators/preset/workspace-files-agent-development.d.ts +0 -9
  420. package/src/generators/preset/workspace-files-agent-development.js +0 -42
  421. package/src/generators/preset/workspace-files-ci-acceptance.d.ts +0 -1
  422. package/src/generators/preset/workspace-files-ci-acceptance.js +0 -791
  423. package/src/generators/preset/workspace-files-ci-install.d.ts +0 -2
  424. package/src/generators/preset/workspace-files-ci-install.js +0 -196
  425. package/src/generators/preset/workspace-files-developer-agent.d.ts +0 -16
  426. package/src/generators/preset/workspace-files-developer-agent.js +0 -644
  427. package/src/generators/preset/workspace-files-ecr-inspector.d.ts +0 -18
  428. package/src/generators/preset/workspace-files-ecr-inspector.js +0 -298
  429. package/src/generators/preset/workspace-files-foundation-workload-roles.d.ts +0 -6
  430. package/src/generators/preset/workspace-files-foundation-workload-roles.js +0 -409
  431. package/src/generators/preset/workspace-files-performance-cost.d.ts +0 -66
  432. package/src/generators/preset/workspace-files-performance-cost.js +0 -866
  433. package/src/generators/preset/workspace-files-performance-load.d.ts +0 -73
  434. package/src/generators/preset/workspace-files-performance-load.js +0 -815
  435. package/src/generators/preset/workspace-files-shared-operation-claims.d.ts +0 -10
  436. package/src/generators/preset/workspace-files-shared-operation-claims.js +0 -59
  437. package/src/generators/preset/workspace-files-stage-authority.d.ts +0 -6
  438. package/src/generators/preset/workspace-files-stage-authority.js +0 -586
  439. package/src/generators/preset/workspace-files-thin-deploy.d.ts +0 -76
  440. package/src/generators/preset/workspace-files-thin-deploy.js +0 -2563
  441. package/src/generators/preset/workspace-files-thin-docs.d.ts +0 -7
  442. package/src/generators/preset/workspace-files-thin-docs.js +0 -386
  443. package/src/generators/preset/workspace-files-thin-release.d.ts +0 -14
  444. package/src/generators/preset/workspace-files-thin-release.js +0 -26
  445. package/src/generators/preset/workspace-files-workload-role-baseline.d.ts +0 -9
  446. package/src/generators/preset/workspace-files-workload-role-baseline.js +0 -1314
  447. package/src/generators/repository-policy/repository-policy.d.ts +0 -4
  448. package/src/generators/repository-policy/repository-policy.js +0 -294
  449. package/src/generators/repository-policy/schema.d.ts +0 -30
  450. package/src/generators/repository-policy/schema.json +0 -127
  451. package/src/generators/site/built-in-site-smoke-files.d.ts +0 -2
  452. package/src/generators/site/built-in-site-smoke-files.js +0 -37
  453. package/src/generators/slice/built-in-plan-alarm-identity.d.ts +0 -182
  454. package/src/generators/slice/built-in-plan-alarm-identity.js +0 -209
  455. package/src/generators/slice/built-in-plan-api-contract-files.d.ts +0 -2
  456. package/src/generators/slice/built-in-plan-api-contract-files.js +0 -2848
  457. package/src/generators/slice/built-in-plan-async-work-files.d.ts +0 -2
  458. package/src/generators/slice/built-in-plan-async-work-files.js +0 -6118
  459. package/src/generators/slice/built-in-plan-authorization-files.d.ts +0 -2
  460. package/src/generators/slice/built-in-plan-authorization-files.js +0 -2082
  461. package/src/generators/slice/built-in-plan-authorization-infrastructure-files.d.ts +0 -2
  462. package/src/generators/slice/built-in-plan-authorization-infrastructure-files.js +0 -1301
  463. package/src/generators/slice/built-in-plan-authorization-storage.d.ts +0 -3
  464. package/src/generators/slice/built-in-plan-authorization-storage.js +0 -119
  465. package/src/generators/slice/built-in-plan-background-work-files.d.ts +0 -2
  466. package/src/generators/slice/built-in-plan-background-work-files.js +0 -99
  467. package/src/generators/slice/built-in-plan-data-deletion-files.d.ts +0 -2
  468. package/src/generators/slice/built-in-plan-data-deletion-files.js +0 -273
  469. package/src/generators/slice/built-in-plan-data-export-infrastructure-files.d.ts +0 -2
  470. package/src/generators/slice/built-in-plan-data-export-infrastructure-files.js +0 -223
  471. package/src/generators/slice/built-in-plan-data-files.d.ts +0 -2
  472. package/src/generators/slice/built-in-plan-data-files.js +0 -618
  473. package/src/generators/slice/built-in-plan-data-lifecycle-files.d.ts +0 -2
  474. package/src/generators/slice/built-in-plan-data-lifecycle-files.js +0 -775
  475. package/src/generators/slice/built-in-plan-data-lifecycle-runtime-files.d.ts +0 -2
  476. package/src/generators/slice/built-in-plan-data-lifecycle-runtime-files.js +0 -863
  477. package/src/generators/slice/built-in-plan-data-retention-job-files.d.ts +0 -2
  478. package/src/generators/slice/built-in-plan-data-retention-job-files.js +0 -169
  479. package/src/generators/slice/built-in-plan-data-retention-launcher-files.d.ts +0 -2
  480. package/src/generators/slice/built-in-plan-data-retention-launcher-files.js +0 -186
  481. package/src/generators/slice/built-in-plan-data-rights-files.d.ts +0 -2
  482. package/src/generators/slice/built-in-plan-data-rights-files.js +0 -152
  483. package/src/generators/slice/built-in-plan-database-retirement-rehearsal-files.d.ts +0 -2
  484. package/src/generators/slice/built-in-plan-database-retirement-rehearsal-files.js +0 -508
  485. package/src/generators/slice/built-in-plan-event-contract-literal.d.ts +0 -6
  486. package/src/generators/slice/built-in-plan-event-contract-literal.js +0 -52
  487. package/src/generators/slice/built-in-plan-foundation-files.d.ts +0 -15
  488. package/src/generators/slice/built-in-plan-foundation-files.js +0 -314
  489. package/src/generators/slice/built-in-plan-frontend-files.d.ts +0 -2
  490. package/src/generators/slice/built-in-plan-frontend-files.js +0 -1975
  491. package/src/generators/slice/built-in-plan-frontend-header-proof.d.ts +0 -6
  492. package/src/generators/slice/built-in-plan-frontend-header-proof.js +0 -282
  493. package/src/generators/slice/built-in-plan-infrastructure-safety-files.d.ts +0 -2
  494. package/src/generators/slice/built-in-plan-infrastructure-safety-files.js +0 -373
  495. package/src/generators/slice/built-in-plan-key-value-cleanup.d.ts +0 -4
  496. package/src/generators/slice/built-in-plan-key-value-cleanup.js +0 -101
  497. package/src/generators/slice/built-in-plan-key-value-consumer.d.ts +0 -4
  498. package/src/generators/slice/built-in-plan-key-value-consumer.js +0 -151
  499. package/src/generators/slice/built-in-plan-key-value-deletion.d.ts +0 -2
  500. package/src/generators/slice/built-in-plan-key-value-deletion.js +0 -377
  501. package/src/generators/slice/built-in-plan-key-value-delivery.d.ts +0 -2
  502. package/src/generators/slice/built-in-plan-key-value-delivery.js +0 -137
  503. package/src/generators/slice/built-in-plan-key-value-export.d.ts +0 -2
  504. package/src/generators/slice/built-in-plan-key-value-export.js +0 -595
  505. package/src/generators/slice/built-in-plan-key-value-holds.d.ts +0 -2
  506. package/src/generators/slice/built-in-plan-key-value-holds.js +0 -189
  507. package/src/generators/slice/built-in-plan-key-value-infrastructure.d.ts +0 -2
  508. package/src/generators/slice/built-in-plan-key-value-infrastructure.js +0 -102
  509. package/src/generators/slice/built-in-plan-key-value-performance.d.ts +0 -5
  510. package/src/generators/slice/built-in-plan-key-value-performance.js +0 -530
  511. package/src/generators/slice/built-in-plan-key-value-provider.d.ts +0 -4
  512. package/src/generators/slice/built-in-plan-key-value-provider.js +0 -366
  513. package/src/generators/slice/built-in-plan-key-value-records.d.ts +0 -3
  514. package/src/generators/slice/built-in-plan-key-value-records.js +0 -232
  515. package/src/generators/slice/built-in-plan-key-value-retention-infrastructure.d.ts +0 -2
  516. package/src/generators/slice/built-in-plan-key-value-retention-infrastructure.js +0 -103
  517. package/src/generators/slice/built-in-plan-key-value-retention-job-files.d.ts +0 -2
  518. package/src/generators/slice/built-in-plan-key-value-retention-job-files.js +0 -160
  519. package/src/generators/slice/built-in-plan-key-value-retention-maintenance.d.ts +0 -2
  520. package/src/generators/slice/built-in-plan-key-value-retention-maintenance.js +0 -329
  521. package/src/generators/slice/built-in-plan-key-value-retention-worker.d.ts +0 -2
  522. package/src/generators/slice/built-in-plan-key-value-retention-worker.js +0 -477
  523. package/src/generators/slice/built-in-plan-key-value-retention.d.ts +0 -2
  524. package/src/generators/slice/built-in-plan-key-value-retention.js +0 -184
  525. package/src/generators/slice/built-in-plan-log-group-helpers.d.ts +0 -29
  526. package/src/generators/slice/built-in-plan-log-group-helpers.js +0 -130
  527. package/src/generators/slice/built-in-plan-metadata-files.d.ts +0 -3
  528. package/src/generators/slice/built-in-plan-metadata-files.js +0 -401
  529. package/src/generators/slice/built-in-plan-native-runtime-authority-files.d.ts +0 -2
  530. package/src/generators/slice/built-in-plan-native-runtime-authority-files.js +0 -324
  531. package/src/generators/slice/built-in-plan-next-build-authority.d.ts +0 -5
  532. package/src/generators/slice/built-in-plan-next-build-authority.js +0 -124
  533. package/src/generators/slice/built-in-plan-operations-files.d.ts +0 -8
  534. package/src/generators/slice/built-in-plan-operations-files.js +0 -1106
  535. package/src/generators/slice/built-in-plan-performance-files.d.ts +0 -4
  536. package/src/generators/slice/built-in-plan-performance-files.js +0 -2444
  537. package/src/generators/slice/built-in-plan-release-files.d.ts +0 -2
  538. package/src/generators/slice/built-in-plan-release-files.js +0 -6585
  539. package/src/generators/slice/built-in-plan-reliability-files.d.ts +0 -2
  540. package/src/generators/slice/built-in-plan-reliability-files.js +0 -4728
  541. package/src/generators/slice/built-in-plan-secret-runtime-files.d.ts +0 -2
  542. package/src/generators/slice/built-in-plan-secret-runtime-files.js +0 -1015
  543. package/src/generators/slice/built-in-plan-sql-events.d.ts +0 -2
  544. package/src/generators/slice/built-in-plan-sql-events.js +0 -276
  545. package/src/generators/slice/built-in-plan-testing-files.d.ts +0 -2
  546. package/src/generators/slice/built-in-plan-testing-files.js +0 -2618
  547. package/src/generators/slice/built-in-plan-testing-persistence-event-files.d.ts +0 -7
  548. package/src/generators/slice/built-in-plan-testing-persistence-event-files.js +0 -487
  549. package/src/generators/slice/built-in-plan-testing-persistence-files.d.ts +0 -2
  550. package/src/generators/slice/built-in-plan-testing-persistence-files.js +0 -180
  551. package/src/generators/slice/built-in-plan-thin-release-files.d.ts +0 -11
  552. package/src/generators/slice/built-in-plan-thin-release-files.js +0 -162
  553. package/src/generators/slice/built-in-plan-verification-files.d.ts +0 -2
  554. package/src/generators/slice/built-in-plan-verification-files.js +0 -442
  555. package/src/generators/slice/built-in-plan-workload-role-files.d.ts +0 -2
  556. package/src/generators/slice/built-in-plan-workload-role-files.js +0 -2220
  557. package/src/generators/slice/data-policy-review-seed.d.ts +0 -2
  558. package/src/generators/slice/data-policy-review-seed.js +0 -22
  559. package/src/generators/slice/deployed-smoke-diagnostics.d.ts +0 -35
  560. package/src/generators/slice/deployed-smoke-diagnostics.js +0 -189
  561. package/src/generators/slice/deployed-smoke-readiness.d.ts +0 -9
  562. package/src/generators/slice/deployed-smoke-readiness.js +0 -309
  563. package/src/generators/slice/local-source-identity.d.ts +0 -2
  564. package/src/generators/slice/local-source-identity.js +0 -31
  565. package/src/generators/slice/pnpm-launch-script.d.ts +0 -13
  566. package/src/generators/slice/pnpm-launch-script.js +0 -28
  567. package/src/generators/upgrade/custom-domain-notice.d.ts +0 -19
  568. package/src/generators/upgrade/custom-domain-notice.js +0 -38
  569. package/src/generators/upgrade/external-blueprint-compositions.d.ts +0 -84
  570. package/src/generators/upgrade/external-blueprint-compositions.js +0 -478
  571. package/src/generators/upgrade/sql-seeded-reconciliation.d.ts +0 -2
  572. package/src/generators/upgrade/sql-seeded-reconciliation.js +0 -170
  573. package/src/generators/workload/performance-registration.d.ts +0 -33
  574. package/src/generators/workload/performance-registration.js +0 -224
  575. package/src/generators/workload/reliability-registration.d.ts +0 -16
  576. package/src/generators/workload/reliability-registration.js +0 -150
  577. package/src/generators/workload/service-performance-files.d.ts +0 -5
  578. package/src/generators/workload/service-performance-files.js +0 -1883
  579. package/src/git-policy/action-pins.d.ts +0 -43
  580. package/src/git-policy/action-pins.js +0 -50
  581. package/src/git-policy/github-bootstrap.d.ts +0 -95
  582. package/src/git-policy/github-bootstrap.js +0 -1250
  583. package/src/git-policy/index.d.ts +0 -3
  584. package/src/git-policy/index.js +0 -7
  585. package/src/git-policy/routing.d.ts +0 -21
  586. package/src/git-policy/routing.js +0 -138
  587. package/src/infrastructure-change/convergence.d.ts +0 -13
  588. package/src/infrastructure-change/convergence.js +0 -85
  589. package/src/infrastructure-change/drift.d.ts +0 -13
  590. package/src/infrastructure-change/drift.js +0 -112
  591. package/src/infrastructure-change/index.d.ts +0 -7
  592. package/src/infrastructure-change/index.js +0 -11
  593. package/src/infrastructure-change/local-capability.d.ts +0 -73
  594. package/src/infrastructure-change/local-capability.js +0 -114
  595. package/src/infrastructure-change/model.d.ts +0 -274
  596. package/src/infrastructure-change/model.js +0 -29
  597. package/src/infrastructure-change/normalize.d.ts +0 -16
  598. package/src/infrastructure-change/normalize.js +0 -285
  599. package/src/infrastructure-change/plan.d.ts +0 -67
  600. package/src/infrastructure-change/plan.js +0 -671
  601. package/src/infrastructure-change/risk.d.ts +0 -9
  602. package/src/infrastructure-change/risk.js +0 -349
  603. package/src/infrastructure-change/summary.d.ts +0 -20
  604. package/src/infrastructure-change/summary.js +0 -130
  605. package/src/performance/cost-collection.d.ts +0 -225
  606. package/src/performance/cost-collection.js +0 -827
  607. package/src/performance/cost-controls.d.ts +0 -135
  608. package/src/performance/cost-controls.js +0 -347
  609. package/src/performance/evidence.d.ts +0 -140
  610. package/src/performance/evidence.js +0 -601
  611. package/src/performance/index.d.ts +0 -10
  612. package/src/performance/index.js +0 -14
  613. package/src/performance/load-safety.d.ts +0 -84
  614. package/src/performance/load-safety.js +0 -348
  615. package/src/performance/model.d.ts +0 -129
  616. package/src/performance/model.js +0 -451
  617. package/src/performance/pr-artifact-budget.d.ts +0 -42
  618. package/src/performance/pr-artifact-budget.js +0 -151
  619. package/src/performance/runner.d.ts +0 -75
  620. package/src/performance/runner.js +0 -227
  621. package/src/performance/scenario-endpoint.d.ts +0 -1
  622. package/src/performance/scenario-endpoint.js +0 -5
  623. package/src/performance/scenario.d.ts +0 -215
  624. package/src/performance/scenario.js +0 -744
  625. package/src/performance/unit-cost.d.ts +0 -105
  626. package/src/performance/unit-cost.js +0 -364
  627. package/src/release/index.d.ts +0 -2
  628. package/src/release/index.js +0 -6
  629. package/src/release/lifecycle.d.ts +0 -132
  630. package/src/release/lifecycle.js +0 -411
  631. package/src/release/manifest.d.ts +0 -148
  632. package/src/release/manifest.js +0 -503
  633. package/src/release/rollout.d.ts +0 -170
  634. package/src/release/rollout.js +0 -578
  635. package/src/release/source-authority.d.ts +0 -19
  636. package/src/release/source-authority.js +0 -212
  637. package/src/schemas/aggregate-count-evidence-v1.json +0 -135
  638. package/src/schemas/api-contract-baseline-v1.json +0 -674
  639. package/src/schemas/api-contract-compatibility-report-v1.json +0 -126
  640. package/src/schemas/aws-billing-actual-evidence-v1.json +0 -407
  641. package/src/schemas/blueprint-input-schema-v1.json +0 -23
  642. package/src/schemas/blueprint-v1.json +0 -188
  643. package/src/schemas/data-lifecycle-policy-v1.json +0 -517
  644. package/src/schemas/performance-policy-v1.json +0 -335
  645. package/src/schemas/testing-evidence-quarantine-v1.json +0 -168
  646. package/src/schemas/testing-evidence-result-v1.json +0 -319
  647. package/src/secrets/aws-control-plane.d.ts +0 -29
  648. package/src/secrets/aws-control-plane.js +0 -322
  649. package/src/secrets/generated-aws-control-plane.d.ts +0 -33
  650. package/src/secrets/generated-aws-control-plane.js +0 -322
  651. package/src/secrets/guardrails.d.ts +0 -26
  652. package/src/secrets/guardrails.js +0 -328
  653. package/src/secrets/metadata.d.ts +0 -48
  654. package/src/secrets/metadata.js +0 -199
  655. package/src/secrets/operator.d.ts +0 -190
  656. package/src/secrets/operator.js +0 -701
  657. package/src/secrets/verification.d.ts +0 -18
  658. package/src/secrets/verification.js +0 -152
  659. package/src/supply-chain/action-pins.d.ts +0 -26
  660. package/src/supply-chain/action-pins.js +0 -262
  661. package/src/supply-chain/blueprint-trust-git.d.ts +0 -130
  662. package/src/supply-chain/blueprint-trust-git.js +0 -1666
  663. package/src/supply-chain/blueprint-trust-process.d.ts +0 -4
  664. package/src/supply-chain/blueprint-trust-process.js +0 -88
  665. package/src/supply-chain/blueprint-trust.d.ts +0 -354
  666. package/src/supply-chain/blueprint-trust.js +0 -1558
  667. package/src/supply-chain/blueprint-verification-authority.d.ts +0 -62
  668. package/src/supply-chain/blueprint-verification-authority.js +0 -679
  669. package/src/supply-chain/blueprint-verification-execution.d.ts +0 -68
  670. package/src/supply-chain/blueprint-verification-execution.js +0 -639
  671. package/src/supply-chain/build-output-bounds.d.ts +0 -2
  672. package/src/supply-chain/build-output-bounds.js +0 -12
  673. package/src/supply-chain/build-output.d.ts +0 -41
  674. package/src/supply-chain/build-output.js +0 -551
  675. package/src/supply-chain/common.d.ts +0 -21
  676. package/src/supply-chain/common.js +0 -107
  677. package/src/supply-chain/container-artifact-contract.d.ts +0 -23
  678. package/src/supply-chain/container-artifact-contract.js +0 -208
  679. package/src/supply-chain/container-release.d.ts +0 -119
  680. package/src/supply-chain/container-release.js +0 -496
  681. package/src/supply-chain/ecr-applicability.d.ts +0 -19
  682. package/src/supply-chain/ecr-applicability.js +0 -103
  683. package/src/supply-chain/ecr-scanning.d.ts +0 -85
  684. package/src/supply-chain/ecr-scanning.js +0 -325
  685. package/src/supply-chain/ecs-deployed-image.d.ts +0 -87
  686. package/src/supply-chain/ecs-deployed-image.js +0 -302
  687. package/src/supply-chain/errors.d.ts +0 -6
  688. package/src/supply-chain/errors.js +0 -15
  689. package/src/supply-chain/generated-blueprint-trust-command.d.ts +0 -4
  690. package/src/supply-chain/generated-blueprint-trust-command.js +0 -1394
  691. package/src/supply-chain/generated-command.d.ts +0 -1
  692. package/src/supply-chain/generated-command.js +0 -775
  693. package/src/supply-chain/generated-container-release-command.d.ts +0 -16
  694. package/src/supply-chain/generated-container-release-command.js +0 -3248
  695. package/src/supply-chain/generated-ecr-collector-command.d.ts +0 -20
  696. package/src/supply-chain/generated-ecr-collector-command.js +0 -1445
  697. package/src/supply-chain/generated-files.d.ts +0 -13
  698. package/src/supply-chain/generated-files.js +0 -421
  699. package/src/supply-chain/generated-scanner-command.d.ts +0 -1
  700. package/src/supply-chain/generated-scanner-command.js +0 -778
  701. package/src/supply-chain/index.d.ts +0 -28
  702. package/src/supply-chain/index.js +0 -36
  703. package/src/supply-chain/inventory.d.ts +0 -96
  704. package/src/supply-chain/inventory.js +0 -828
  705. package/src/supply-chain/license-expression.d.ts +0 -7
  706. package/src/supply-chain/license-expression.js +0 -128
  707. package/src/supply-chain/policy.d.ts +0 -105
  708. package/src/supply-chain/policy.js +0 -304
  709. package/src/supply-chain/publication.d.ts +0 -48
  710. package/src/supply-chain/publication.js +0 -85
  711. package/src/supply-chain/sbom.d.ts +0 -228
  712. package/src/supply-chain/sbom.js +0 -913
  713. package/src/supply-chain/scanner.d.ts +0 -77
  714. package/src/supply-chain/scanner.js +0 -514
  715. package/src/supply-chain/vendored-source.d.ts +0 -95
  716. package/src/supply-chain/vendored-source.js +0 -315
  717. package/src/testing-evidence/fixture-scope.d.ts +0 -53
  718. package/src/testing-evidence/fixture-scope.js +0 -142
  719. package/src/testing-evidence/index.d.ts +0 -5
  720. package/src/testing-evidence/index.js +0 -9
  721. package/src/testing-evidence/quarantine.d.ts +0 -48
  722. package/src/testing-evidence/quarantine.js +0 -253
  723. package/src/testing-evidence/result.d.ts +0 -109
  724. package/src/testing-evidence/result.js +0 -585
  725. package/src/testing-evidence/runner-adapter.d.ts +0 -51
  726. package/src/testing-evidence/runner-adapter.js +0 -288
  727. package/src/testing-evidence/sensitive-artifacts.d.ts +0 -13
  728. package/src/testing-evidence/sensitive-artifacts.js +0 -93
  729. package/src/work-markers/index.d.ts +0 -1
  730. package/src/work-markers/index.js +0 -5
  731. package/src/work-markers/work-markers.d.ts +0 -39
  732. package/src/work-markers/work-markers.js +0 -363
  733. package/src/workload-roles/account-baseline.d.ts +0 -143
  734. package/src/workload-roles/account-baseline.js +0 -980
  735. package/src/workload-roles/authority.d.ts +0 -40
  736. package/src/workload-roles/authority.js +0 -202
  737. package/src/workload-roles/aws-adapter.d.ts +0 -99
  738. package/src/workload-roles/aws-adapter.js +0 -416
  739. package/src/workload-roles/aws-internal-handler.d.ts +0 -27
  740. package/src/workload-roles/aws-internal-handler.js +0 -58
  741. package/src/workload-roles/aws-s3-state.d.ts +0 -52
  742. package/src/workload-roles/aws-s3-state.js +0 -191
  743. package/src/workload-roles/aws-sdk-control-plane.d.ts +0 -12
  744. package/src/workload-roles/aws-sdk-control-plane.js +0 -291
  745. package/src/workload-roles/boundary.d.ts +0 -34
  746. package/src/workload-roles/boundary.js +0 -137
  747. package/src/workload-roles/convergence.d.ts +0 -66
  748. package/src/workload-roles/convergence.js +0 -186
  749. package/src/workload-roles/handler.d.ts +0 -43
  750. package/src/workload-roles/handler.js +0 -158
  751. package/src/workload-roles/history.d.ts +0 -47
  752. package/src/workload-roles/history.js +0 -324
  753. package/src/workload-roles/injection.d.ts +0 -119
  754. package/src/workload-roles/injection.js +0 -495
  755. package/src/workload-roles/manifest.d.ts +0 -54
  756. package/src/workload-roles/manifest.js +0 -343
  757. package/src/workload-roles/provisioner.d.ts +0 -70
  758. package/src/workload-roles/provisioner.js +0 -239
  759. package/src/workload-roles/registration.d.ts +0 -102
  760. package/src/workload-roles/registration.js +0 -462
  761. package/src/workload-roles/stage-boundary.d.ts +0 -31
  762. package/src/workload-roles/stage-boundary.js +0 -208
  763. /package/src/executors/{foundation-profile-preflight → local-deploy}/production-database-safeguard.d.ts +0 -0
  764. /package/src/executors/{foundation-profile-preflight → local-deploy}/production-database-safeguard.js +0 -0
@@ -1,4728 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderProductReliabilityFiles = renderProductReliabilityFiles;
4
- const reliability_1 = require("@empire-builder-kit/runtime/reliability");
5
- const deterministic_order_js_1 = require("../../deterministic-order.js");
6
- const built_in_plan_alarm_identity_js_1 = require("./built-in-plan-alarm-identity.js");
7
- const built_in_plan_shared_js_1 = require("./built-in-plan-shared.js");
8
- function reliabilityContract(name, reviewedAt) {
9
- return {
10
- escalationRouteKey: `${name}-on-call`,
11
- objectives: [
12
- {
13
- allowedExclusionPolicyRef: 'docs:reliability/exclusions.md',
14
- burn: { fast: 14.4, slow: 6, warning: 0.5 },
15
- effectiveAt: reviewedAt,
16
- feature: 'operations',
17
- id: 'api-availability',
18
- indicator: {
19
- goodEventDefinition: 'Valid API requests complete without a server failure.',
20
- metricRef: 'operations:metrics/api-availability',
21
- type: 'availability',
22
- validEventDefinition: 'Requests reaching a declared API operation, including authorization denials.',
23
- },
24
- journey: 'api-critical-operation',
25
- lowTraffic: { mode: 'data-insufficient' },
26
- minimumValidEvents: {
27
- diagnosticSample: 100,
28
- fastBurnWindow: 1,
29
- objectiveWindow: 100,
30
- slowBurnWindow: 5,
31
- },
32
- owner: `${name}-product`,
33
- references: {
34
- alarmIds: ['api-fast-burn', 'api-slow-burn'],
35
- dashboardRef: 'dashboard:operations',
36
- runbookRef: 'runbook:api-recovery',
37
- },
38
- target: 0.99,
39
- tier: 'critical',
40
- window: { days: 28, kind: 'rolling' },
41
- },
42
- {
43
- allowedExclusionPolicyRef: 'docs:reliability/exclusions.md',
44
- burn: { fast: 14.4, slow: 6, warning: 0.5 },
45
- effectiveAt: reviewedAt,
46
- feature: 'web',
47
- id: 'web-latency',
48
- indicator: {
49
- goodEventDefinition: 'Valid server-rendered requests complete within 1000 milliseconds.',
50
- metricRef: 'operations:metrics/web-latency',
51
- threshold: 1000,
52
- type: 'latency',
53
- unit: 'Milliseconds',
54
- validEventDefinition: 'Requests reaching the generated web application.',
55
- },
56
- journey: 'web-critical-route',
57
- lowTraffic: { mode: 'data-insufficient' },
58
- minimumValidEvents: {
59
- diagnosticSample: 100,
60
- fastBurnWindow: 1,
61
- objectiveWindow: 100,
62
- slowBurnWindow: 5,
63
- },
64
- owner: `${name}-product`,
65
- references: {
66
- alarmIds: ['web-latency-fast-burn', 'web-latency-slow-burn'],
67
- dashboardRef: 'dashboard:operations',
68
- runbookRef: 'runbook:web-recovery',
69
- },
70
- target: 0.95,
71
- tier: 'important',
72
- window: { days: 28, kind: 'rolling' },
73
- },
74
- {
75
- allowedExclusionPolicyRef: 'docs:reliability/exclusions.md',
76
- burn: { fast: 14.4, slow: 6, warning: 0.5 },
77
- effectiveAt: reviewedAt,
78
- feature: 'async-work',
79
- id: 'async-delivery-deadline',
80
- indicator: {
81
- goodEventDefinition: 'Accepted provider deliveries leave the queue within 900 seconds.',
82
- metricRef: 'operations:metrics/async-delivery-deadline',
83
- threshold: 900,
84
- type: 'deadline',
85
- unit: 'Seconds',
86
- validEventDefinition: 'Provider deliveries durably accepted into the generated queue.',
87
- },
88
- journey: 'provider-delivery',
89
- lowTraffic: { mode: 'data-insufficient' },
90
- minimumValidEvents: {
91
- diagnosticSample: 10,
92
- fastBurnWindow: 1,
93
- objectiveWindow: 10,
94
- slowBurnWindow: 5,
95
- },
96
- owner: `${name}-product`,
97
- references: {
98
- alarmIds: ['provider-queue-age'],
99
- dashboardRef: 'dashboard:operations',
100
- runbookRef: 'runbook:async-recovery',
101
- },
102
- target: 0.99,
103
- tier: 'important',
104
- window: { days: 28, kind: 'rolling' },
105
- },
106
- ],
107
- owner: `${name}-product`,
108
- providerDecision: {
109
- applicationSignalsCoverage: ['lambda', 'next'],
110
- basis: 'Direct CloudWatch metric math covers the generated Lambda, Next.js, queue, Service, Job, and database surfaces without making Application Signals mandatory. Re-evaluate with retained exact-candidate coverage and cost evidence.',
111
- cost: {
112
- currency: 'USD',
113
- monthly: 0,
114
- provenance: 'estimate',
115
- },
116
- directMetricMathCoverage: [
117
- 'lambda',
118
- 'next',
119
- 'queue',
120
- 'service',
121
- 'job',
122
- 'database',
123
- 'alert-delivery',
124
- ],
125
- reviewedAt,
126
- selected: 'direct-cloudwatch-metric-math',
127
- },
128
- schemaVersion: 1,
129
- slice: name,
130
- };
131
- }
132
- function alarmRegistrations(name, sql) {
133
- const common = {
134
- expectedFalseNegativeRisk: 'Low traffic or delayed CloudWatch data can delay detection.',
135
- expectedFalsePositiveRisk: 'A dependency or synthetic client can fail while the application remains healthy.',
136
- missingData: 'missing',
137
- testRef: 'evidence:reliability/failure-recovery',
138
- };
139
- // Symptom, owner, route and runbook come from the shared alarm identity
140
- // table, as every managed emitter's description does.
141
- const registered = (id) => {
142
- const identity = (0, built_in_plan_alarm_identity_js_1.sliceAlarmIdentity)(name, id);
143
- return {
144
- ...common,
145
- businessSymptom: identity.businessSymptom,
146
- escalationRouteKey: identity.route,
147
- id,
148
- owner: identity.owner,
149
- runbookRef: identity.runbookRef,
150
- };
151
- };
152
- const registrations = [
153
- {
154
- ...registered('api-fast-burn'),
155
- condition: 'The API availability objective is consuming budget rapidly.',
156
- dependencyAlarmIds: ['database-capacity'],
157
- severity: 'critical',
158
- },
159
- {
160
- ...registered('api-slow-burn'),
161
- condition: 'The API availability objective is consuming budget slowly.',
162
- dependencyAlarmIds: ['database-capacity'],
163
- severity: 'high',
164
- },
165
- {
166
- ...registered('web-latency-fast-burn'),
167
- condition: 'Web p95 latency exceeds the reviewed threshold.',
168
- dependencyAlarmIds: ['database-capacity'],
169
- severity: 'high',
170
- },
171
- {
172
- ...registered('web-latency-slow-burn'),
173
- condition: 'Web p95 latency remains above the reviewed threshold for the slow window.',
174
- dependencyAlarmIds: ['database-capacity'],
175
- severity: 'high',
176
- },
177
- {
178
- ...registered('provider-queue-age'),
179
- condition: 'Oldest provider-queue work exceeds 900 seconds.',
180
- dependencyAlarmIds: [],
181
- severity: 'high',
182
- },
183
- {
184
- ...registered('database-capacity'),
185
- condition: 'The Slice DynamoDB table or PendingEvents index reports read or write throttling.',
186
- dependencyAlarmIds: [],
187
- severity: 'high',
188
- },
189
- {
190
- ...registered('performance-load-cleanup-backlog'),
191
- condition: 'Every cleanup run in three consecutive hours reported PerformanceLoadCleanupContinuationRequired: no run completed a full performance-load expiry inventory within its 5,000-record, four-minute bound (Minimum of a per-run flag).',
192
- dependencyAlarmIds: [],
193
- expectedFalseNegativeRisk: 'Paused or failing cleanup reports nothing; failures surface through inbox-cleanup-errors. When the configured inboxCleanup cadence is slower than one hour, some hourly periods have no data and the three-period condition may never be met.',
194
- expectedFalsePositiveRisk: 'A run resumed from a saved cursor must rescan from the start before it can converge, so one interrupted run can report continuation for several runs. Expiry shares the run budget with inbox cleanup. Records near or above the 5,000-record per-run bound report continuation on every run; that is a capacity signal, not a failed cleanup.',
195
- severity: 'high',
196
- },
197
- {
198
- ...registered('performance-load-cleanup-deadline'),
199
- condition: 'The bounded expiry worker reports residue at least 24 hours past eligible expiry.',
200
- dependencyAlarmIds: ['performance-load-cleanup-backlog'],
201
- severity: 'critical',
202
- },
203
- {
204
- ...registered('data-export-cleanup-failure'),
205
- condition: 'AWS/Lambda reports an error for the exact generated confidential-export cleanup Function.',
206
- dependencyAlarmIds: [],
207
- severity: 'high',
208
- },
209
- {
210
- ...registered('data-export-cleanup-invocation-missing'),
211
- condition: 'AWS/Lambda reports fewer than one invocation across two consecutive hourly periods.',
212
- dependencyAlarmIds: [],
213
- severity: 'critical',
214
- },
215
- {
216
- ...registered('data-export-cleanup-deadline'),
217
- condition: 'The cleanup worker reports an open export at or after its immutable 24-hour cleanup deadline.',
218
- dependencyAlarmIds: [
219
- 'data-export-cleanup-failure',
220
- 'data-export-cleanup-invocation-missing',
221
- ],
222
- severity: 'critical',
223
- },
224
- {
225
- ...registered('function-failure'),
226
- condition: 'AWS/Lambda reports one or more errors in one minute for the exact generated data-export cleanup Function. Event-delivery Functions have their own error alarms.',
227
- dependencyAlarmIds: [],
228
- severity: 'high',
229
- },
230
- {
231
- ...registered('retention-job-failure'),
232
- condition: 'AWS Step Functions reports a failed, timed-out, or aborted execution for the exact retention state machine.',
233
- dependencyAlarmIds: [],
234
- severity: 'high',
235
- },
236
- {
237
- ...registered('alert-delivery-degraded'),
238
- condition: 'SNS reports one or more failed notifications.',
239
- dependencyAlarmIds: [],
240
- severity: 'critical',
241
- },
242
- {
243
- ...registered('data-protection-findings'),
244
- condition: 'CloudWatch Logs reports one or more protected-data findings.',
245
- dependencyAlarmIds: [],
246
- severity: 'critical',
247
- },
248
- {
249
- ...registered('event-dlq-depth'),
250
- condition: 'The event dead-letter queue contains one or more messages.',
251
- dependencyAlarmIds: [],
252
- severity: 'high',
253
- },
254
- {
255
- ...registered('provider-dlq-depth'),
256
- condition: 'The provider-delivery dead-letter queue contains one or more messages.',
257
- dependencyAlarmIds: [],
258
- severity: 'high',
259
- },
260
- {
261
- ...registered('async-target-dlq-depth'),
262
- condition: 'The asynchronous-target dead-letter queue contains one or more messages.',
263
- dependencyAlarmIds: [],
264
- severity: 'high',
265
- },
266
- {
267
- ...registered('outbox-relay-errors'),
268
- condition: 'AWS/Lambda reports one or more errors in five minutes for the generated async/outbox-relay Function, which drains only the isolated performance sink. Domain-event delivery is the key-value stream and reconciliation.',
269
- dependencyAlarmIds: [],
270
- severity: 'high',
271
- },
272
- {
273
- ...registered('inbox-cleanup-errors'),
274
- condition: 'The generated inbox cleanup job reports one or more errors.',
275
- dependencyAlarmIds: [],
276
- severity: 'high',
277
- },
278
- {
279
- ...registered('key-value-stream-delivery-errors'),
280
- condition: 'AWS/Lambda reports one or more errors in five minutes for the exact key-value stream delivery Function: the stream identity or record shape was rejected, or the handler crashed. Per-record publish failures are partial batch failures, not Lambda errors; they surface through key-value-stream-iterator-age while retries hold the shard back, and through outbox-backlog and event-delivery-attempts after the mapping discards them.',
281
- dependencyAlarmIds: [],
282
- severity: 'high',
283
- },
284
- {
285
- ...registered('key-value-stream-iterator-age'),
286
- condition: 'AWS/Lambda reports a stream iterator age of at least ten minutes for the exact key-value stream delivery Function. The mapping discards records older than one hour; reconciliation then recovers their retained intents.',
287
- dependencyAlarmIds: ['key-value-stream-delivery-errors'],
288
- severity: 'high',
289
- },
290
- {
291
- ...registered('key-value-reconciliation-errors'),
292
- condition: 'AWS/Lambda reports one or more errors in five minutes for the exact key-value reconciliation Function. Partial runs do not error; the backlog, rejected-intent, and attempts alarms report them.',
293
- dependencyAlarmIds: [],
294
- severity: 'high',
295
- },
296
- {
297
- ...registered('outbox-backlog'),
298
- condition: 'In two consecutive hours, key-value reconciliation reported one or more due intents it could not deliver (retry-required plus rejected). Each run reads at most one 25-intent page per shard, so the value is a lower bound, not a global count, and excludes intents leased by another delivery owner.',
299
- dependencyAlarmIds: [
300
- 'key-value-reconciliation-errors',
301
- 'key-value-stream-delivery-errors',
302
- ],
303
- expectedFalseNegativeRisk: 'Intents beyond the sampled pages, or behind a paused outbox, are not counted until a later run reaches them. When the configured reconciliation cadence is slower than one hour, some hourly periods have no data and the two-period condition may never be met.',
304
- severity: 'high',
305
- },
306
- {
307
- ...registered('event-intent-rejected'),
308
- condition: 'Within an hour, key-value reconciliation reported one or more retained intents that fail validation. Rejected intents are never dispatched or deleted, so this recurs until an operator investigates.',
309
- dependencyAlarmIds: [],
310
- severity: 'high',
311
- },
312
- {
313
- ...registered('event-delivery-attempts'),
314
- condition: 'Within an hour, key-value reconciliation observed a due intent with at least ten delivery leases (attempts). Attempts are reported only; no intent is capped, dropped, or quarantined.',
315
- dependencyAlarmIds: ['key-value-reconciliation-errors'],
316
- severity: 'high',
317
- },
318
- {
319
- ...registered('inbox-cleanup-backlog'),
320
- condition: 'Every cleanup run in three consecutive hours reported InboxCleanupContinuationRequired: no run completed a full provider-inbox inventory within its 10,000-receipt, four-minute bound (Minimum of a per-run flag).',
321
- dependencyAlarmIds: ['inbox-cleanup-errors'],
322
- expectedFalseNegativeRisk: 'Paused or failing cleanup reports nothing; failures surface through inbox-cleanup-errors. When the configured inboxCleanup cadence is slower than one hour, some hourly periods have no data and the three-period condition may never be met.',
323
- expectedFalsePositiveRisk: 'A run resumed from a saved cursor must rescan from the start before it can converge, so one interrupted run can report continuation for several runs; three hours absorb this while the retained inbox stays at or below about 6,666 receipts. A retained inbox near or above the 10,000-receipt per-run bound reports continuation on every run; that is a capacity signal, not a failed cleanup.',
324
- severity: 'high',
325
- },
326
- ...(sql
327
- ? [
328
- {
329
- ...registered('sql-outbox-relay-errors'),
330
- condition: 'AWS/Lambda reports one or more errors in five minutes for the exact SQL outbox relay Function, which fails every run that retains a failed delivery.',
331
- dependencyAlarmIds: [],
332
- severity: 'high',
333
- },
334
- {
335
- ...registered('sql-outbox-backlog'),
336
- condition: 'Every SQL relay run in two consecutive hours ended with one or more unpublished intents (Minimum of a global count). A paused relay reports nothing.',
337
- dependencyAlarmIds: ['sql-outbox-relay-errors'],
338
- expectedFalseNegativeRisk: 'A paused relay reports nothing. When the configured sqlOutboxRecovery cadence is slower than one hour and no notification wakes the relay, some hourly periods have no data and the two-period condition may never be met.',
339
- severity: 'high',
340
- },
341
- {
342
- ...registered('sql-outbox-attempts'),
343
- condition: 'Within an hour, an unpublished SQL intent reached at least ten relay attempts. Attempts are reported only; no intent is capped or dropped.',
344
- dependencyAlarmIds: ['sql-outbox-relay-errors'],
345
- severity: 'high',
346
- },
347
- ]
348
- : []),
349
- ];
350
- return registrations.map((registration) => (0, reliability_1.validateAlarmRegistrationMetadata)(registration));
351
- }
352
- function reliabilityExercises(name) {
353
- const shared = {
354
- cleanupRequired: true,
355
- owner: `${name}-product`,
356
- protectedMutationRequiresApproval: true,
357
- };
358
- return [
359
- {
360
- ...shared,
361
- failure: 'Inject one bounded generated API handler failure.',
362
- id: 'lambda-api-failure',
363
- observation: {
364
- adapter: 'aws-cloudwatch-alarm-history-v1',
365
- alarmIds: ['api-fast-burn'],
366
- dynamicAlarmKind: 'none',
367
- workflowMetadata: 'none',
368
- },
369
- postconditions: [
370
- 'critical API journey succeeds',
371
- 'alarm returns to normal without being disabled',
372
- 'release and configuration identity remain attributable',
373
- ],
374
- recovery: ['retry', 'roll-forward', 'protected-revert'],
375
- workload: 'lambda-api',
376
- },
377
- {
378
- ...shared,
379
- failure: 'Inject a bounded health or dependency failure in an EBK Service.',
380
- id: 'service-failure',
381
- observation: {
382
- adapter: 'aws-cloudwatch-alarm-history-v1',
383
- alarmIds: [],
384
- dynamicAlarmKind: 'service',
385
- workflowMetadata: 'none',
386
- },
387
- postconditions: [
388
- 'service readiness recovers',
389
- 'critical dependency remains protected',
390
- ],
391
- recovery: ['retry', 'roll-forward', 'degraded-mode'],
392
- workload: 'service',
393
- },
394
- {
395
- ...shared,
396
- failure: 'Inject one bounded generated Job failure before completion.',
397
- id: 'job-failure',
398
- observation: {
399
- adapter: 'aws-cloudwatch-alarm-history-v1',
400
- alarmIds: [],
401
- dynamicAlarmKind: 'job',
402
- workflowMetadata: 'none',
403
- },
404
- postconditions: [
405
- 'checkpoint or idempotency state is retained',
406
- 'deadline outcome is verified',
407
- ],
408
- recovery: ['retry', 'roll-forward'],
409
- workload: 'job',
410
- },
411
- {
412
- ...shared,
413
- failure: 'Run the built-in retention state machine with a bounded failing fixture.',
414
- id: 'retention-job-failure',
415
- observation: {
416
- adapter: 'aws-cloudwatch-alarm-history-v1',
417
- alarmIds: ['retention-job-failure'],
418
- dynamicAlarmKind: 'none',
419
- workflowMetadata: 'required',
420
- },
421
- postconditions: [
422
- 'the exact state machine execution reaches a terminal failure',
423
- 'the AWS-native execution alarm fires',
424
- 'the later recovery execution succeeds without weakening retention policy',
425
- ],
426
- recovery: ['retry', 'roll-forward'],
427
- workload: 'built-in-retention-job',
428
- },
429
- {
430
- ...shared,
431
- failure: 'Route a deterministic poison fixture to the generated DLQ.',
432
- id: 'queue-dlq-failure',
433
- observation: {
434
- adapter: 'aws-cloudwatch-alarm-history-v1',
435
- alarmIds: [
436
- 'async-target-dlq-depth',
437
- 'event-dlq-depth',
438
- 'provider-dlq-depth',
439
- ],
440
- dynamicAlarmKind: 'none',
441
- workflowMetadata: 'optional',
442
- },
443
- postconditions: [
444
- 'DLQ alarm fires',
445
- 'bounded redrive converges',
446
- 'no duplicate provider effect occurs',
447
- ],
448
- recovery: ['redrive', 'replay'],
449
- workload: 'queue-dlq',
450
- },
451
- {
452
- ...shared,
453
- failure: 'Inject bounded dependency latency and an availability failure.',
454
- id: 'dependency-failure',
455
- observation: {
456
- adapter: 'aws-cloudwatch-alarm-history-v1',
457
- alarmIds: ['api-fast-burn'],
458
- dynamicAlarmKind: 'none',
459
- workflowMetadata: 'none',
460
- },
461
- postconditions: [
462
- 'retry amplification stays bounded',
463
- 'critical work degrades or queues as declared',
464
- ],
465
- recovery: ['retry', 'degraded-mode', 'roll-forward'],
466
- workload: 'dependency',
467
- },
468
- {
469
- ...shared,
470
- failure: 'Exercise database unavailability or cold-resume latency.',
471
- id: 'database-failure',
472
- observation: {
473
- adapter: 'aws-cloudwatch-alarm-history-v1',
474
- alarmIds: ['database-capacity'],
475
- dynamicAlarmKind: 'none',
476
- workflowMetadata: 'none',
477
- },
478
- postconditions: [
479
- 'data invariants pass',
480
- 'connection concurrency remains bounded',
481
- 'critical journey recovery is verified',
482
- ],
483
- recovery: ['retry', 'restore', 'roll-forward'],
484
- workload: 'database',
485
- },
486
- {
487
- ...shared,
488
- failure: 'Fail the primary alert destination during a bounded proof.',
489
- id: 'alert-delivery-failure',
490
- observation: {
491
- adapter: 'aws-cloudwatch-alarm-history-v1',
492
- alarmIds: ['alert-delivery-degraded'],
493
- dynamicAlarmKind: 'none',
494
- workflowMetadata: 'none',
495
- },
496
- postconditions: [
497
- 'diagnostic degradation is recorded without using the failed route',
498
- 'delivery is unsupported unless an independent provider receipt exists',
499
- ],
500
- recovery: ['roll-forward'],
501
- workload: 'alert-delivery',
502
- },
503
- {
504
- ...shared,
505
- failure: 'Retain one exact deployed-smoke failure artifact before the successful rerun.',
506
- id: 'runtime-smoke-failure',
507
- observation: {
508
- adapter: 'testing-evidence-aggregate-v1',
509
- alarmIds: [],
510
- dynamicAlarmKind: 'none',
511
- workflowMetadata: 'none',
512
- },
513
- postconditions: [
514
- 'the testing-evidence aggregate binds the exact deployment and candidate',
515
- 'the failure remains retained beside the successful rerun',
516
- 'cleanup evidence is complete',
517
- ],
518
- recovery: ['retry', 'roll-forward'],
519
- workload: 'deployed-smoke',
520
- },
521
- ];
522
- }
523
- const ROUTED_INVENTORY_LEADING_KEYS = [
524
- 'actions',
525
- 'comparisonOperator',
526
- 'owner',
527
- 'route',
528
- ];
529
- /**
530
- * One inventory entry with the shared identity's owner, route and runbook,
531
- * the fields the generated verifier compares with the deployed alarm's
532
- * description. Keys keep the seeded order: a routed alarm's actions,
533
- * comparison operator, owner and route first, then the rest sorted.
534
- */
535
- function inventoryAlarmResource(name, resource) {
536
- const identity = (0, built_in_plan_alarm_identity_js_1.sliceAlarmIdentity)(name, resource.id);
537
- const fields = {
538
- ...resource,
539
- owner: identity.owner,
540
- route: identity.route,
541
- runbook: identity.runbook,
542
- };
543
- const leading = resource.actions === 'primary-route' ? ROUTED_INVENTORY_LEADING_KEYS : [];
544
- return Object.fromEntries([
545
- ...leading,
546
- ...Object.keys(fields)
547
- .filter((key) => !leading.includes(key))
548
- .sort(deterministic_order_js_1.compareUtf16),
549
- ].map((key) => [key, fields[key]]));
550
- }
551
- function deployedAlarmResources(name, sql) {
552
- const primary = {
553
- actions: 'primary-route',
554
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
555
- };
556
- const resources = [
557
- {
558
- ...primary,
559
- dimensionNames: ['ApiId'],
560
- evaluationPeriods: 1,
561
- id: 'api-fast-burn',
562
- metricNames: ['5xx', 'Count'],
563
- name: `${name}-{stage}-api-fast-burn`,
564
- namespace: 'AWS/ApiGateway',
565
- objectiveId: 'api-availability',
566
- signal: 'metric-math',
567
- threshold: 14.4,
568
- treatMissingData: 'missing',
569
- },
570
- {
571
- ...primary,
572
- dimensionNames: ['ApiId'],
573
- evaluationPeriods: 1,
574
- id: 'api-slow-burn',
575
- metricNames: ['5xx', 'Count'],
576
- name: `${name}-{stage}-api-slow-burn`,
577
- namespace: 'AWS/ApiGateway',
578
- objectiveId: 'api-availability',
579
- signal: 'metric-math',
580
- threshold: 6,
581
- treatMissingData: 'missing',
582
- },
583
- {
584
- ...primary,
585
- dimensionNames: ['Component', 'Feature', 'Operation', 'Slice', 'Stage'],
586
- dimensionValues: {
587
- Component: 'next-server',
588
- Feature: 'web',
589
- Operation: 'request',
590
- Slice: name,
591
- Stage: '{stage}',
592
- },
593
- evaluationPeriods: 1,
594
- id: 'web-latency-fast-burn',
595
- metricNames: ['OperationGood', 'OperationValid'],
596
- name: `${name}-{stage}-web-latency-fast-burn`,
597
- namespace: `EBK/${name}`,
598
- objectiveId: 'web-latency',
599
- signal: 'metric-math',
600
- threshold: 14.4,
601
- treatMissingData: 'missing',
602
- },
603
- {
604
- ...primary,
605
- dimensionNames: ['Component', 'Feature', 'Operation', 'Slice', 'Stage'],
606
- dimensionValues: {
607
- Component: 'next-server',
608
- Feature: 'web',
609
- Operation: 'request',
610
- Slice: name,
611
- Stage: '{stage}',
612
- },
613
- evaluationPeriods: 1,
614
- id: 'web-latency-slow-burn',
615
- metricNames: ['OperationGood', 'OperationValid'],
616
- name: `${name}-{stage}-web-latency-slow-burn`,
617
- namespace: `EBK/${name}`,
618
- objectiveId: 'web-latency',
619
- signal: 'metric-math',
620
- threshold: 6,
621
- treatMissingData: 'missing',
622
- },
623
- {
624
- ...primary,
625
- dimensionNames: ['QueueName'],
626
- dimensionValues: {
627
- QueueName: `ebk-{stage}-${name}-provider-queue`,
628
- },
629
- evaluationPeriods: 2,
630
- id: 'provider-queue-age',
631
- metricName: 'ApproximateAgeOfOldestMessage',
632
- name: `${name}-{stage}-provider-deadline`,
633
- namespace: 'AWS/SQS',
634
- period: 300,
635
- signal: 'metric',
636
- statistic: 'Maximum',
637
- threshold: 900,
638
- treatMissingData: 'missing',
639
- },
640
- {
641
- ...primary,
642
- dimensionNames: ['GlobalSecondaryIndexName', 'TableName'],
643
- dimensionValues: { GlobalSecondaryIndexName: 'PendingEvents' },
644
- evaluationPeriods: 1,
645
- id: 'database-capacity',
646
- metricNames: ['ReadThrottleEvents', 'WriteThrottleEvents'],
647
- name: `${name}-{stage}-database-capacity`,
648
- namespace: 'AWS/DynamoDB',
649
- period: 60,
650
- signal: 'metric-math',
651
- statistic: 'Sum',
652
- threshold: 1,
653
- treatMissingData: 'notBreaching',
654
- },
655
- {
656
- ...primary,
657
- dimensionNames: ['Component', 'Feature', 'Operation', 'Slice', 'Stage'],
658
- dimensionValues: {
659
- Component: 'performance-load-cleanup',
660
- Feature: 'performance',
661
- Operation: 'expiry-cleanup',
662
- Slice: name,
663
- Stage: '{stage}',
664
- },
665
- evaluationPeriods: 3,
666
- id: 'performance-load-cleanup-backlog',
667
- metricName: 'PerformanceLoadCleanupContinuationRequired',
668
- name: `${name}-{stage}-performance-load-cleanup-backlog`,
669
- namespace: 'EBK/Performance',
670
- period: 3600,
671
- signal: 'metric',
672
- statistic: 'Minimum',
673
- threshold: 1,
674
- treatMissingData: 'notBreaching',
675
- },
676
- {
677
- ...primary,
678
- dimensionNames: ['Component', 'Feature', 'Operation', 'Slice', 'Stage'],
679
- dimensionValues: {
680
- Component: 'performance-load-cleanup',
681
- Feature: 'performance',
682
- Operation: 'expiry-cleanup',
683
- Slice: name,
684
- Stage: '{stage}',
685
- },
686
- evaluationPeriods: 1,
687
- id: 'performance-load-cleanup-deadline',
688
- metricName: 'PerformanceLoadCleanupDeadlineBreaches',
689
- name: `${name}-{stage}-performance-load-cleanup-deadline`,
690
- namespace: 'EBK/Performance',
691
- period: 3600,
692
- signal: 'metric',
693
- statistic: 'Maximum',
694
- threshold: 1,
695
- treatMissingData: 'notBreaching',
696
- },
697
- {
698
- ...primary,
699
- comparisonOperator: 'LessThanThreshold',
700
- dimensionNames: ['FunctionName'],
701
- evaluationPeriods: 2,
702
- id: 'data-export-cleanup-invocation-missing',
703
- metricName: 'Invocations',
704
- name: `${name}-{stage}-data-export-cleanup-invocation-missing`,
705
- namespace: 'AWS/Lambda',
706
- period: 3600,
707
- signal: 'metric',
708
- statistic: 'Sum',
709
- threshold: 1,
710
- treatMissingData: 'breaching',
711
- },
712
- {
713
- ...primary,
714
- dimensionNames: ['FunctionName'],
715
- evaluationPeriods: 1,
716
- id: 'data-export-cleanup-failure',
717
- metricName: 'Errors',
718
- name: `${name}-{stage}-data-export-cleanup-failure`,
719
- namespace: 'AWS/Lambda',
720
- period: 300,
721
- signal: 'metric',
722
- statistic: 'Sum',
723
- threshold: 1,
724
- treatMissingData: 'notBreaching',
725
- },
726
- {
727
- ...primary,
728
- dimensionNames: ['Component', 'Feature', 'Operation', 'Slice', 'Stage'],
729
- dimensionValues: {
730
- Component: 'data-export-cleanup',
731
- Feature: 'data-lifecycle',
732
- Operation: 'expiry-cleanup',
733
- Slice: name,
734
- Stage: '{stage}',
735
- },
736
- evaluationPeriods: 1,
737
- id: 'data-export-cleanup-deadline',
738
- metricName: 'DataExportCleanupDeadlineBreaches',
739
- name: `${name}-{stage}-data-export-cleanup-deadline`,
740
- namespace: 'EBK/DataLifecycle',
741
- period: 3600,
742
- signal: 'metric',
743
- statistic: 'Maximum',
744
- threshold: 1,
745
- treatMissingData: 'notBreaching',
746
- },
747
- {
748
- ...primary,
749
- dimensionNames: ['FunctionName'],
750
- evaluationPeriods: 1,
751
- id: 'function-failure',
752
- metricName: 'Errors',
753
- name: `${name}-{stage}-function-failure`,
754
- namespace: 'AWS/Lambda',
755
- period: 60,
756
- signal: 'metric',
757
- statistic: 'Sum',
758
- threshold: 1,
759
- treatMissingData: 'notBreaching',
760
- },
761
- {
762
- ...primary,
763
- dimensionNames: ['StateMachineArn'],
764
- evaluationPeriods: 1,
765
- id: 'retention-job-failure',
766
- metricNames: [
767
- 'ExecutionsAborted',
768
- 'ExecutionsFailed',
769
- 'ExecutionsTimedOut',
770
- ],
771
- name: `${name}-{stage}-retention-job-failure`,
772
- namespace: 'AWS/States',
773
- signal: 'metric-math',
774
- threshold: 1,
775
- treatMissingData: 'notBreaching',
776
- },
777
- {
778
- ...primary,
779
- dimensionNames: ['QueueName'],
780
- dimensionValues: {
781
- QueueName: `ebk-{stage}-${name}-event-dlq`,
782
- },
783
- evaluationPeriods: 1,
784
- id: 'event-dlq-depth',
785
- metricName: 'ApproximateNumberOfMessagesVisible',
786
- name: `${name}-{stage}-event-dlq-depth`,
787
- namespace: 'AWS/SQS',
788
- period: 300,
789
- signal: 'metric',
790
- statistic: 'Maximum',
791
- threshold: 1,
792
- treatMissingData: 'notBreaching',
793
- },
794
- {
795
- ...primary,
796
- dimensionNames: ['QueueName'],
797
- dimensionValues: {
798
- QueueName: `ebk-{stage}-${name}-provider-dlq`,
799
- },
800
- evaluationPeriods: 1,
801
- id: 'provider-dlq-depth',
802
- metricName: 'ApproximateNumberOfMessagesVisible',
803
- name: `${name}-{stage}-provider-dlq-depth`,
804
- namespace: 'AWS/SQS',
805
- period: 300,
806
- signal: 'metric',
807
- statistic: 'Maximum',
808
- threshold: 1,
809
- treatMissingData: 'notBreaching',
810
- },
811
- {
812
- ...primary,
813
- dimensionNames: ['QueueName'],
814
- dimensionValues: {
815
- QueueName: `ebk-{stage}-${name}-async-target-dlq`,
816
- },
817
- evaluationPeriods: 1,
818
- id: 'async-target-dlq-depth',
819
- metricName: 'ApproximateNumberOfMessagesVisible',
820
- name: `${name}-{stage}-async-target-dlq-depth`,
821
- namespace: 'AWS/SQS',
822
- period: 300,
823
- signal: 'metric',
824
- statistic: 'Maximum',
825
- threshold: 1,
826
- treatMissingData: 'notBreaching',
827
- },
828
- {
829
- ...primary,
830
- dimensionNames: ['FunctionName'],
831
- evaluationPeriods: 1,
832
- id: 'outbox-relay-errors',
833
- metricName: 'Errors',
834
- name: `${name}-{stage}-outbox-relay-errors`,
835
- namespace: 'AWS/Lambda',
836
- period: 300,
837
- signal: 'metric',
838
- statistic: 'Sum',
839
- threshold: 1,
840
- treatMissingData: 'notBreaching',
841
- },
842
- {
843
- ...primary,
844
- dimensionNames: ['FunctionName'],
845
- evaluationPeriods: 1,
846
- id: 'inbox-cleanup-errors',
847
- metricName: 'Errors',
848
- name: `${name}-{stage}-inbox-cleanup-errors`,
849
- namespace: 'AWS/Lambda',
850
- period: 300,
851
- signal: 'metric',
852
- statistic: 'Sum',
853
- threshold: 1,
854
- treatMissingData: 'notBreaching',
855
- },
856
- {
857
- ...primary,
858
- dimensionNames: ['FunctionName'],
859
- evaluationPeriods: 1,
860
- id: 'key-value-stream-delivery-errors',
861
- metricName: 'Errors',
862
- name: `${name}-{stage}-key-value-stream-delivery-errors`,
863
- namespace: 'AWS/Lambda',
864
- period: 300,
865
- signal: 'metric',
866
- statistic: 'Sum',
867
- threshold: 1,
868
- treatMissingData: 'notBreaching',
869
- },
870
- {
871
- ...primary,
872
- dimensionNames: ['FunctionName'],
873
- evaluationPeriods: 1,
874
- id: 'key-value-stream-iterator-age',
875
- metricName: 'IteratorAge',
876
- name: `${name}-{stage}-key-value-stream-iterator-age`,
877
- namespace: 'AWS/Lambda',
878
- period: 300,
879
- signal: 'metric',
880
- statistic: 'Maximum',
881
- threshold: 600_000,
882
- treatMissingData: 'notBreaching',
883
- },
884
- {
885
- ...primary,
886
- dimensionNames: ['FunctionName'],
887
- evaluationPeriods: 1,
888
- id: 'key-value-reconciliation-errors',
889
- metricName: 'Errors',
890
- name: `${name}-{stage}-key-value-reconciliation-errors`,
891
- namespace: 'AWS/Lambda',
892
- period: 300,
893
- signal: 'metric',
894
- statistic: 'Sum',
895
- threshold: 1,
896
- treatMissingData: 'notBreaching',
897
- },
898
- {
899
- ...primary,
900
- dimensionNames: ['Slice', 'Stage'],
901
- dimensionValues: { Slice: name, Stage: '{stage}' },
902
- evaluationPeriods: 2,
903
- id: 'outbox-backlog',
904
- metricName: 'OutboxBacklog',
905
- name: `${name}-{stage}-outbox-backlog`,
906
- namespace: 'EBK/Async',
907
- period: 3600,
908
- signal: 'metric',
909
- statistic: 'Maximum',
910
- threshold: 1,
911
- treatMissingData: 'notBreaching',
912
- },
913
- {
914
- ...primary,
915
- dimensionNames: ['Slice', 'Stage'],
916
- dimensionValues: { Slice: name, Stage: '{stage}' },
917
- evaluationPeriods: 1,
918
- id: 'event-intent-rejected',
919
- metricName: 'EventReconciliationRejected',
920
- name: `${name}-{stage}-event-intent-rejected`,
921
- namespace: 'EBK/Async',
922
- period: 3600,
923
- signal: 'metric',
924
- statistic: 'Maximum',
925
- threshold: 1,
926
- treatMissingData: 'notBreaching',
927
- },
928
- {
929
- ...primary,
930
- dimensionNames: ['Slice', 'Stage'],
931
- dimensionValues: { Slice: name, Stage: '{stage}' },
932
- evaluationPeriods: 1,
933
- id: 'event-delivery-attempts',
934
- metricName: 'EventDeliveryMaxAttempts',
935
- name: `${name}-{stage}-event-delivery-attempts`,
936
- namespace: 'EBK/Async',
937
- period: 3600,
938
- signal: 'metric',
939
- statistic: 'Maximum',
940
- threshold: 10,
941
- treatMissingData: 'notBreaching',
942
- },
943
- ...(sql
944
- ? [
945
- {
946
- ...primary,
947
- dimensionNames: ['FunctionName'],
948
- evaluationPeriods: 1,
949
- id: 'sql-outbox-relay-errors',
950
- metricName: 'Errors',
951
- name: `${name}-{stage}-sql-outbox-relay-errors`,
952
- namespace: 'AWS/Lambda',
953
- period: 300,
954
- signal: 'metric',
955
- statistic: 'Sum',
956
- threshold: 1,
957
- treatMissingData: 'notBreaching',
958
- },
959
- {
960
- ...primary,
961
- dimensionNames: ['Slice', 'Stage'],
962
- dimensionValues: { Slice: name, Stage: '{stage}' },
963
- evaluationPeriods: 2,
964
- id: 'sql-outbox-backlog',
965
- metricName: 'SqlOutboxBacklog',
966
- name: `${name}-{stage}-sql-outbox-backlog`,
967
- namespace: 'EBK/Async',
968
- period: 3600,
969
- signal: 'metric',
970
- statistic: 'Minimum',
971
- threshold: 1,
972
- treatMissingData: 'notBreaching',
973
- },
974
- {
975
- ...primary,
976
- dimensionNames: ['Slice', 'Stage'],
977
- dimensionValues: { Slice: name, Stage: '{stage}' },
978
- evaluationPeriods: 1,
979
- id: 'sql-outbox-attempts',
980
- metricName: 'SqlOutboxMaxAttempts',
981
- name: `${name}-{stage}-sql-outbox-attempts`,
982
- namespace: 'EBK/Async',
983
- period: 3600,
984
- signal: 'metric',
985
- statistic: 'Maximum',
986
- threshold: 10,
987
- treatMissingData: 'notBreaching',
988
- },
989
- ]
990
- : []),
991
- {
992
- ...primary,
993
- dimensionNames: ['Component', 'Feature', 'Operation', 'Slice', 'Stage'],
994
- dimensionValues: {
995
- Component: 'inbox-cleanup',
996
- Feature: 'async-work',
997
- Operation: 'inbox-cleanup',
998
- Slice: name,
999
- Stage: '{stage}',
1000
- },
1001
- evaluationPeriods: 3,
1002
- id: 'inbox-cleanup-backlog',
1003
- metricName: 'InboxCleanupContinuationRequired',
1004
- name: `${name}-{stage}-inbox-cleanup-backlog`,
1005
- namespace: 'EBK/Async',
1006
- period: 3600,
1007
- signal: 'metric',
1008
- statistic: 'Minimum',
1009
- threshold: 1,
1010
- treatMissingData: 'notBreaching',
1011
- },
1012
- {
1013
- actions: 'none',
1014
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
1015
- dimensionNames: ['TopicName'],
1016
- evaluationPeriods: 1,
1017
- id: 'alert-delivery-degraded',
1018
- metricName: 'NumberOfNotificationsFailed',
1019
- name: `${name}-{stage}-alert-delivery-degraded`,
1020
- namespace: 'AWS/SNS',
1021
- period: 300,
1022
- signal: 'metric',
1023
- statistic: 'Sum',
1024
- threshold: 1,
1025
- treatMissingData: 'notBreaching',
1026
- },
1027
- ];
1028
- return resources.map((resource) => inventoryAlarmResource(name, resource));
1029
- }
1030
- /** @internal */
1031
- function renderProductReliabilityFiles(name, pascalName, reviewedAt, sql = false) {
1032
- const contract = reliabilityContract(name, reviewedAt);
1033
- const alarms = alarmRegistrations(name, sql);
1034
- const exercises = reliabilityExercises(name);
1035
- const ownership = (0, built_in_plan_alarm_identity_js_1.sliceAlarmOwnership)(name);
1036
- return {
1037
- 'docs/reliability/slo.json': (0, built_in_plan_shared_js_1.json)(contract),
1038
- 'docs/reliability/exclusions.md': `# SLO exclusions
1039
-
1040
- This adopter-owned record starts empty. An exclusion must name one generated
1041
- SLO ID, owner, reason, bounded UTC start and end, and review reference. Define
1042
- planned maintenance exclusions before the window where possible. Never add a
1043
- retroactive exclusion merely to make attainment green.
1044
-
1045
- The generated verifier treats this document as the policy authority; managed
1046
- CloudWatch resources do not rewrite it.
1047
- `,
1048
- 'operations/reliability.json': (0, built_in_plan_shared_js_1.json)({
1049
- alarmRegistrations: alarms,
1050
- consoleIndependent: true,
1051
- deployedAlarmResources: deployedAlarmResources(name, sql),
1052
- diagnostic: {
1053
- metadataSources: [
1054
- 'alarm-state',
1055
- 'resource-metadata',
1056
- 'sanitized-signal',
1057
- ],
1058
- protectedSource: 'bounded-log-query',
1059
- runbookRef: 'runbook:reliability-diagnostic',
1060
- },
1061
- alertDelivery: {
1062
- confirmation: 'unsupported-until-independent-route-is-configured',
1063
- mode: 'diagnostic-only',
1064
- states: ['requested', 'confirmed', 'unsupported'],
1065
- },
1066
- dataLifecycleReferences: {
1067
- alarms: [
1068
- 'alarm:data-export-cleanup-deadline',
1069
- 'alarm:data-export-cleanup-failure',
1070
- 'alarm:data-export-cleanup-invocation-missing',
1071
- ],
1072
- status: 'requires-live-evidence',
1073
- },
1074
- incidentTemplateRef: 'operations:incident-template.json',
1075
- performanceReferences: {
1076
- alarms: [
1077
- 'alarm:cost-anomaly',
1078
- 'alarm:performance-load-cleanup-backlog',
1079
- 'alarm:performance-load-cleanup-deadline',
1080
- ],
1081
- capacityControls: [
1082
- 'control:api-lambda-concurrency',
1083
- 'control:async-worker-concurrency',
1084
- 'control:database-connections',
1085
- 'control:service-extension-concurrency',
1086
- ],
1087
- capacitySignals: [
1088
- 'adopter:service-saturation-percent',
1089
- 'database:connection-utilization-percent',
1090
- 'database:protected-async-backlog-utilization-percent',
1091
- 'runtime:nodejs-heap-utilization-percent',
1092
- ],
1093
- status: 'requires-adopter-values-and-live-evidence',
1094
- },
1095
- remediation: {
1096
- adapter: 'protected-async-recovery',
1097
- approvalRequired: true,
1098
- runbookRef: 'runbook:incident-remediation',
1099
- supportedApplyActions: ['redrive', 'replay'],
1100
- },
1101
- schemaVersion: 1,
1102
- slice: name,
1103
- sloRef: 'docs:reliability/slo.json',
1104
- runtimeSmoke: {
1105
- aggregateOwner: 'testing-evidence',
1106
- deployedResourceClass: 'testing-evidence-not-cloudwatch-alarm',
1107
- evidenceKind: 'testing-evidence-result',
1108
- metricOwner: 'not-provisioned-by-reliability',
1109
- reporter: 'testing-evidence-native-not-reliability-exercise-report',
1110
- target: 'smoke-deployed',
1111
- },
1112
- workloadCoverage: [
1113
- { kind: 'lambda-api', registration: 'api-fast-burn' },
1114
- { kind: 'function', registration: 'function-failure' },
1115
- { kind: 'next', registration: 'web-latency-fast-burn' },
1116
- {
1117
- kind: 'service',
1118
- registration: 'required-when-generated-by-ebk-workload-service-health',
1119
- },
1120
- {
1121
- kind: 'job',
1122
- registration: 'required-when-generated-by-ebk-workload-job-failure',
1123
- },
1124
- { kind: 'queue-dlq', registration: 'provider-queue-age' },
1125
- { kind: 'database', registration: 'database-capacity' },
1126
- {
1127
- kind: 'built-in-retention-job',
1128
- registration: 'retention-job-failure',
1129
- },
1130
- {
1131
- kind: 'built-in-data-export-cleanup',
1132
- registration: 'data-export-cleanup-failure',
1133
- },
1134
- {
1135
- kind: 'deployed-smoke',
1136
- registration: 'testing-evidence-aggregate',
1137
- },
1138
- {
1139
- kind: 'alert-delivery',
1140
- registration: 'alert-delivery-degraded',
1141
- },
1142
- ],
1143
- }),
1144
- 'testing/reliability-exercises.json': (0, built_in_plan_shared_js_1.json)({
1145
- exercises,
1146
- schemaVersion: 1,
1147
- slice: name,
1148
- }),
1149
- 'operations/incident-template.json': (0, built_in_plan_shared_js_1.json)({
1150
- affectedJourneyIds: ['api-critical-operation'],
1151
- declaredAt: reviewedAt,
1152
- followUpRefs: ['replace-with-owned-work-reference'],
1153
- id: `${name}-incident-template`,
1154
- impact: 'Replace with confirmed user or operator impact.',
1155
- roles: {
1156
- communicationsOwner: 'unassigned-human',
1157
- incidentCommander: 'unassigned-human',
1158
- scribe: 'unassigned',
1159
- technicalLead: 'unassigned-human',
1160
- },
1161
- severity: 'SEV-4',
1162
- slice: name,
1163
- state: 'declared',
1164
- timeline: [
1165
- {
1166
- actor: 'unassigned-human',
1167
- at: reviewedAt,
1168
- evidenceRefs: ['replace-with-sanitized-evidence-reference'],
1169
- message: 'Template only: confirm impact and explicitly declare the incident.',
1170
- type: 'decision',
1171
- },
1172
- ],
1173
- }),
1174
- 'reliability/contract.ts': `import {
1175
- validateReliabilityContract,
1176
- } from '@empire-builder-kit/runtime/reliability';
1177
- import declaration from '../docs/reliability/slo.json';
1178
-
1179
- export const Reliability = validateReliabilityContract(declaration);
1180
- `,
1181
- 'reliability/metrics.ts': `import {
1182
- createEmfMetricRecord,
1183
- createMetricEmitter,
1184
- createMetricRejectionReporter,
1185
- type BatchedMetricEmitter,
1186
- type EmfMetricObservation,
1187
- type MetricDimensions,
1188
- type MetricEmitter,
1189
- type MetricEmitterOptions,
1190
- type MetricOutcome,
1191
- } from '@empire-builder-kit/runtime/observability';
1192
- import {
1193
- reliabilityMetricDeclarations,
1194
- type ReliabilityMetricDeclaration,
1195
- } from './metric-declarations.js';
1196
-
1197
- export interface ReliabilityOperation {
1198
- component: string;
1199
- durationMilliseconds: number;
1200
- feature: string;
1201
- good?: boolean;
1202
- operation: string;
1203
- outcome: MetricOutcome;
1204
- }
1205
-
1206
- // Managed core declarations grow with generated callers on upgrade. Adopter
1207
- // declarations stay in the seeded extension file, never in request input.
1208
- const coreMetricDeclarations: readonly ReliabilityMetricDeclaration[] = [
1209
- { component: 'next-server', feature: 'web', operation: 'request' },
1210
- ];
1211
- const metricDeclarations: readonly ReliabilityMetricDeclaration[] = Object.freeze(
1212
- [...coreMetricDeclarations, ...reliabilityMetricDeclarations].map((entry) =>
1213
- Object.freeze({ ...entry }),
1214
- ),
1215
- );
1216
- // Deployment identity is fixed when the Lambda/Next module starts, not per request.
1217
- const reliabilityStage = process.env.EBK_STAGE ?? 'development';
1218
-
1219
- export function createReliabilityMetricEmitter(
1220
- options: Omit<MetricEmitterOptions, 'cardinalityPolicy'> = {},
1221
- ): BatchedMetricEmitter {
1222
- const values = (dimension: keyof ReliabilityMetricDeclaration) =>
1223
- [...new Set(metricDeclarations.map((entry) => entry[dimension]))];
1224
- const reportRejected = createMetricRejectionReporter(options.onRejected);
1225
- const emitter = createMetricEmitter({
1226
- ...options,
1227
- onRejected: reportRejected,
1228
- cardinalityPolicy: {
1229
- dimensions: {
1230
- component: values('component'),
1231
- feature: values('feature'),
1232
- operation: values('operation'),
1233
- slice: ['${name}'],
1234
- stage: [reliabilityStage],
1235
- },
1236
- metricNames: ['OperationValid', 'OperationGood', 'OperationDuration'],
1237
- },
1238
- });
1239
- // A declaration owns one tuple, not every Cartesian combination of its labels.
1240
- const tupleKey = (dimensions: MetricDimensions | undefined) => {
1241
- const labels = [dimensions?.component, dimensions?.feature, dimensions?.operation];
1242
- return labels.every((label) => typeof label === 'string')
1243
- ? JSON.stringify(labels.map((label) => label.trim()))
1244
- : undefined;
1245
- };
1246
- const declaredTuples = new Set(metricDeclarations.map((entry) =>
1247
- tupleKey({ ...entry, slice: '${name}', stage: reliabilityStage }),
1248
- ));
1249
- return {
1250
- reportRejected,
1251
- emit(input) {
1252
- if (!declaredTuples.has(tupleKey(input?.dimensions))) {
1253
- reportRejected('undeclared-tuple');
1254
- return undefined;
1255
- }
1256
- return emitter.emit(input);
1257
- },
1258
- emitBatch(input) {
1259
- if (!declaredTuples.has(tupleKey(input?.dimensions))) {
1260
- reportRejected('undeclared-tuple');
1261
- return undefined;
1262
- }
1263
- return emitter.emitBatch(input);
1264
- },
1265
- };
1266
- }
1267
-
1268
- // Invalid declarations fail closed during module initialization and prevent
1269
- // startup. After successful initialization, emission failures stay observational.
1270
- const defaultReliabilityMetricEmitter = createReliabilityMetricEmitter();
1271
-
1272
- export function recordReliabilityOperation(
1273
- input: ReliabilityOperation,
1274
- metrics: MetricEmitter = defaultReliabilityMetricEmitter,
1275
- ) {
1276
- const dimensions = {
1277
- component: input.component,
1278
- feature: input.feature,
1279
- operation: input.operation,
1280
- slice: '${name}',
1281
- stage: reliabilityStage,
1282
- };
1283
- const validObservation = {
1284
- metricName: 'OperationValid', unit: 'Count', value: 1,
1285
- } as const;
1286
- const goodObservation = {
1287
- metricName: 'OperationGood',
1288
- unit: 'Count',
1289
- value: (input.good ?? input.outcome === 'success') ? 1 : 0,
1290
- } as const;
1291
- const latencyObservation = Number.isFinite(input.durationMilliseconds)
1292
- ? {
1293
- metricName: 'OperationDuration',
1294
- unit: 'Milliseconds',
1295
- value: input.durationMilliseconds,
1296
- } as const
1297
- : undefined;
1298
- if (!latencyObservation) {
1299
- try {
1300
- const reportRejected = metrics.reportRejected ?? defaultReliabilityMetricEmitter.reportRejected;
1301
- reportRejected?.('invalid-observation');
1302
- } catch {
1303
- // Custom diagnostic adapters cannot turn completed work into a failed response.
1304
- }
1305
- }
1306
- const observations: readonly EmfMetricObservation[] = [
1307
- validObservation,
1308
- goodObservation,
1309
- ...(latencyObservation ? [latencyObservation] : []),
1310
- ];
1311
- if (metrics.emitBatch) {
1312
- const batch = metrics.emitBatch({ dimensions, metrics: observations });
1313
- // Keep the public per-metric result records while delivering one envelope.
1314
- const result = (observation: EmfMetricObservation | undefined) =>
1315
- batch && observation && createEmfMetricRecord({
1316
- ...observation,
1317
- dimensions,
1318
- now: () => new Date(batch._aws.Timestamp),
1319
- });
1320
- return {
1321
- good: result(goodObservation),
1322
- latency: result(latencyObservation),
1323
- valid: result(validObservation),
1324
- };
1325
- }
1326
- // Existing custom emit-only adapters retain one call per valid observation.
1327
- const valid = metrics.emit({ ...validObservation, dimensions });
1328
- const good = metrics.emit({ ...goodObservation, dimensions });
1329
- const latency = latencyObservation &&
1330
- metrics.emit({ ...latencyObservation, dimensions });
1331
- return { good, latency, valid };
1332
- }
1333
- `,
1334
- 'reliability/metric-declarations.ts': `import type {
1335
- MetricDimensions,
1336
- } from '@empire-builder-kit/runtime/observability';
1337
-
1338
- export type ReliabilityMetricDeclaration = Required<
1339
- Pick<MetricDimensions, 'component' | 'feature' | 'operation'>
1340
- >;
1341
-
1342
- // Seeded extension: declare finite deployment-owned labels for custom features.
1343
- // Never derive declarations from request, user, resource, or correlation IDs.
1344
- // Generated core declarations are added separately by the managed recorder.
1345
- export const reliabilityMetricDeclarations: readonly ReliabilityMetricDeclaration[] = [];
1346
- `,
1347
- 'infra/reliability.ts': `import {
1348
- createSloBurnAlarmPlan,
1349
- } from '@empire-builder-kit/runtime/reliability';
1350
- import { Reliability } from '../reliability/contract.js';
1351
-
1352
- export interface ReliabilityInfrastructureInput {
1353
- alertTopicArn: any;
1354
- alertTopicName: any;
1355
- apiId: any;
1356
- ${' databaseTableName: any;\n'}\
1357
- functionName: any;
1358
- providerQueueName: any;
1359
- }
1360
-
1361
- function alarmDescription(input: {
1362
- businessSymptom: string;
1363
- id: string;
1364
- runbook: string;
1365
- }) {
1366
- return JSON.stringify({
1367
- businessSymptom: input.businessSymptom,
1368
- id: input.id,
1369
- owner: '${ownership.owner}',
1370
- route: '${ownership.route}',
1371
- runbook: input.runbook,
1372
- schemaVersion: 1,
1373
- slice: '${name}',
1374
- });
1375
- }
1376
-
1377
- export function create${pascalName}Reliability(
1378
- input: ReliabilityInfrastructureInput,
1379
- ) {
1380
- const apiObjective = Reliability.objectives.find(
1381
- ({ id }) => id === 'api-availability',
1382
- );
1383
- const webObjective = Reliability.objectives.find(
1384
- ({ id }) => id === 'web-latency',
1385
- );
1386
- if (!apiObjective || !webObjective) {
1387
- throw new Error('Generated reliability objectives are incomplete.');
1388
- }
1389
- const apiBurn = createSloBurnAlarmPlan(apiObjective, {
1390
- bad: {
1391
- dimensions: { ApiId: input.apiId },
1392
- metricName: '5xx',
1393
- namespace: 'AWS/ApiGateway',
1394
- stat: 'Sum',
1395
- },
1396
- valid: {
1397
- dimensions: { ApiId: input.apiId },
1398
- metricName: 'Count',
1399
- namespace: 'AWS/ApiGateway',
1400
- stat: 'Sum',
1401
- },
1402
- });
1403
- const webDimensions = {
1404
- Component: 'next-server',
1405
- Feature: 'web',
1406
- Operation: 'request',
1407
- Slice: '${name}',
1408
- Stage: $app.stage,
1409
- };
1410
- const webBurn = createSloBurnAlarmPlan(webObjective, {
1411
- good: {
1412
- dimensions: webDimensions,
1413
- metricName: 'OperationGood',
1414
- namespace: 'EBK/${name}',
1415
- stat: 'Sum',
1416
- },
1417
- valid: {
1418
- dimensions: webDimensions,
1419
- metricName: 'OperationValid',
1420
- namespace: 'EBK/${name}',
1421
- stat: 'Sum',
1422
- },
1423
- });
1424
- const apiFastBurn = new aws.cloudwatch.MetricAlarm(
1425
- '${pascalName}ApiFastBurn',
1426
- {
1427
- alarmActions: [input.alertTopicArn],
1428
- alarmDescription: alarmDescription(${(0, built_in_plan_alarm_identity_js_1.renderSliceAlarmDescriptionInput)(name, 'api-fast-burn', ' ')}),
1429
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
1430
- datapointsToAlarm: 1,
1431
- evaluationPeriods: 1,
1432
- metricQueries: [...apiBurn.fast.metricQueries],
1433
- name: '${name}-' + $app.stage + '-api-fast-burn',
1434
- threshold: apiBurn.fast.burnThreshold,
1435
- treatMissingData: 'missing',
1436
- },
1437
- );
1438
- const apiSlowBurn = new aws.cloudwatch.MetricAlarm(
1439
- '${pascalName}ApiSlowBurn',
1440
- {
1441
- alarmActions: [input.alertTopicArn],
1442
- alarmDescription: alarmDescription(${(0, built_in_plan_alarm_identity_js_1.renderSliceAlarmDescriptionInput)(name, 'api-slow-burn', ' ')}),
1443
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
1444
- datapointsToAlarm: 1,
1445
- evaluationPeriods: 1,
1446
- metricQueries: [...apiBurn.slow.metricQueries],
1447
- name: '${name}-' + $app.stage + '-api-slow-burn',
1448
- threshold: apiBurn.slow.burnThreshold,
1449
- treatMissingData: 'missing',
1450
- },
1451
- );
1452
- const webLatency = new aws.cloudwatch.MetricAlarm(
1453
- '${pascalName}WebLatencyBurn',
1454
- {
1455
- alarmActions: [input.alertTopicArn],
1456
- alarmDescription: alarmDescription(${(0, built_in_plan_alarm_identity_js_1.renderSliceAlarmDescriptionInput)(name, 'web-latency-fast-burn', ' ')}),
1457
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
1458
- datapointsToAlarm: 1,
1459
- evaluationPeriods: 1,
1460
- metricQueries: [...webBurn.fast.metricQueries],
1461
- name: '${name}-' + $app.stage + '-web-latency-fast-burn',
1462
- threshold: webBurn.fast.burnThreshold,
1463
- treatMissingData: 'missing',
1464
- },
1465
- );
1466
- const webLatencySlow = new aws.cloudwatch.MetricAlarm(
1467
- '${pascalName}WebLatencySlowBurn',
1468
- {
1469
- alarmActions: [input.alertTopicArn],
1470
- alarmDescription: alarmDescription(${(0, built_in_plan_alarm_identity_js_1.renderSliceAlarmDescriptionInput)(name, 'web-latency-slow-burn', ' ')}),
1471
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
1472
- datapointsToAlarm: 1,
1473
- evaluationPeriods: 1,
1474
- metricQueries: [...webBurn.slow.metricQueries],
1475
- name: '${name}-' + $app.stage + '-web-latency-slow-burn',
1476
- threshold: webBurn.slow.burnThreshold,
1477
- treatMissingData: 'missing',
1478
- },
1479
- );
1480
- const providerDeadline = new aws.cloudwatch.MetricAlarm(
1481
- '${pascalName}ProviderDeadline',
1482
- {
1483
- alarmActions: [input.alertTopicArn],
1484
- alarmDescription: alarmDescription(${(0, built_in_plan_alarm_identity_js_1.renderSliceAlarmDescriptionInput)(name, 'provider-queue-age', ' ')}),
1485
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
1486
- dimensions: { QueueName: input.providerQueueName },
1487
- evaluationPeriods: 2,
1488
- metricName: 'ApproximateAgeOfOldestMessage',
1489
- name: '${name}-' + $app.stage + '-provider-deadline',
1490
- namespace: 'AWS/SQS',
1491
- period: 300,
1492
- statistic: 'Maximum',
1493
- threshold: 900,
1494
- treatMissingData: 'missing',
1495
- },
1496
- );
1497
- const databaseCapacity = new aws.cloudwatch.MetricAlarm(
1498
- '${pascalName}DatabaseCapacity',
1499
- {
1500
- alarmActions: [input.alertTopicArn],
1501
- alarmDescription: alarmDescription(${(0, built_in_plan_alarm_identity_js_1.renderSliceAlarmDescriptionInput)(name, 'database-capacity', ' ')}),
1502
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
1503
- ${` evaluationPeriods: 1,
1504
- name: '${name}-' + $app.stage + '-database-capacity',
1505
- threshold: 1,
1506
- treatMissingData: 'notBreaching',
1507
- // AWS publishes throttle-event metrics for the table and each index,
1508
- // unlike ThrottledRequests, which also requires an Operation dimension.
1509
- metricQueries: [
1510
- { id: 'total', expression: 'SUM(METRICS())', returnData: true },
1511
- ...['ReadThrottleEvents', 'WriteThrottleEvents'].flatMap((metricName, kind) =>
1512
- [undefined, 'PendingEvents'].map((index, scope) => ({
1513
- id: 'throttle' + kind + scope, returnData: false,
1514
- metric: { namespace: 'AWS/DynamoDB', metricName, period: 60, stat: 'Sum',
1515
- dimensions: { TableName: input.databaseTableName,
1516
- ...(index ? { GlobalSecondaryIndexName: index } : {}) },
1517
- },
1518
- })),
1519
- ),
1520
- ],
1521
- `}\
1522
- },
1523
- );
1524
- const functionFailure = new aws.cloudwatch.MetricAlarm(
1525
- '${pascalName}FunctionFailure',
1526
- {
1527
- alarmActions: [input.alertTopicArn],
1528
- alarmDescription: alarmDescription(${(0, built_in_plan_alarm_identity_js_1.renderSliceAlarmDescriptionInput)(name, 'function-failure', ' ')}),
1529
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
1530
- dimensions: { FunctionName: input.functionName },
1531
- evaluationPeriods: 1,
1532
- metricName: 'Errors',
1533
- name: '${name}-' + $app.stage + '-function-failure',
1534
- namespace: 'AWS/Lambda',
1535
- period: 60,
1536
- statistic: 'Sum',
1537
- threshold: 1,
1538
- treatMissingData: 'notBreaching',
1539
- },
1540
- );
1541
- const alertDelivery = new aws.cloudwatch.MetricAlarm(
1542
- '${pascalName}AlertDelivery',
1543
- {
1544
- alarmDescription: alarmDescription(${(0, built_in_plan_alarm_identity_js_1.renderSliceAlarmDescriptionInput)(name, 'alert-delivery-degraded', ' ')}),
1545
- comparisonOperator: 'GreaterThanOrEqualToThreshold',
1546
- dimensions: { TopicName: input.alertTopicName },
1547
- evaluationPeriods: 1,
1548
- metricName: 'NumberOfNotificationsFailed',
1549
- name: '${name}-' + $app.stage + '-alert-delivery-degraded',
1550
- namespace: 'AWS/SNS',
1551
- okActions: [],
1552
- period: 300,
1553
- statistic: 'Sum',
1554
- threshold: 1,
1555
- treatMissingData: 'notBreaching',
1556
- },
1557
- );
1558
- return {
1559
- alertDelivery,
1560
- apiFastBurn,
1561
- apiSlowBurn,
1562
- databaseCapacity,
1563
- functionFailure,
1564
- providerDeadline,
1565
- webLatency,
1566
- webLatencySlow,
1567
- };
1568
- }
1569
- `,
1570
- 'docs/runbooks/reliability-diagnostic.md': `# Reliability diagnostic
1571
-
1572
- The Standard Slice database-capacity alarm measures DynamoDB
1573
- ReadThrottleEvents and WriteThrottleEvents for its table and PendingEvents
1574
- index (60-second Sum, threshold 1, one evaluation, missing data notBreaching).
1575
- It does not measure Aurora ACUs, even when a user feature declares SQL.
1576
- During a seeded upgrade, reconcile only this database-capacity registration
1577
- against the generated infrastructure; preserve adopter-owned owners, routes
1578
- and other operational decisions. Then run the reliability verification target
1579
- with --deployed against the actual stage. A registry-only check cannot prove
1580
- that an AWS alarm was updated.
1581
-
1582
- The generated diagnostic adapter is defined for exactly three approval-free
1583
- sources: alarm state, sanitized SLO metric signals, and bounded ECS or Step
1584
- Functions resource metadata, but no supported producer currently exists for
1585
- its inputs. In a generated workspace \`reliability-diagnostic\` therefore fails
1586
- closed before any AWS read; do not cite it as an executed diagnostic. Its
1587
- definition follows. It executes read-only \`DescribeAlarms\`,
1588
- \`GetMetricData\`, \`DescribeServices\`, and \`DescribeExecution\` calls
1589
- against one exact target and immutable deployment binding. Dashboard, generic
1590
- health, cost, and runbook lookups are not claimed as executable diagnostic
1591
- sources. The adapter does not accept arbitrary metric expressions or resource
1592
- scans, read application log contents, or unmask data.
1593
-
1594
- Before an AWS read, the adapter requires a protected GitHub Actions context, a
1595
- \`.ebk/evidence/reliability/active-bindings.json\` index whose authority names
1596
- the \`Deployed smoke\` workflow, and matching
1597
- \`EBK_RELIABILITY_AUTHORIZED_*\` run values. Only the retired Deployed smoke and
1598
- Reliability read workflows produced these; the native Deploy workflow does not.
1599
- That index must name the current checked-out source commit and exact
1600
- repository. The adapter then recomputes the binding from the exact
1601
- deployed-smoke, active protected-release, and release-manifest artifact bytes.
1602
- The binding also carries the environment-reviewed alarm, API, ECS, and Step
1603
- Functions resource allowlist. A stale binding or substituted resource fails
1604
- before its service query.
1605
-
1606
- Sanitized metric capture is limited to six hours and produces
1607
- \`reliability-slo-diagnostic-sample\`. It reports the declared objective window
1608
- beside the sampled window but never claims that the sample proves the rolling
1609
- 28-day SLO. The report derives staging or production provenance from the active
1610
- binding; callers cannot label it.
1611
-
1612
- A bounded log query requires a human approval naming the approver, invoking
1613
- human, incident, reason, account, region, stage, Slice, exact log groups, query
1614
- class, time window, and expiry. The invoking human is the person whose session
1615
- runs the query; an agent may prepare the request and run the query inside that
1616
- human's session, and the approver must be a different human. Unmasking remains
1617
- a separate break-glass authority. The approved query window is at most one hour.
1618
- The script returns an authorization plan; the existing protected query runner
1619
- retains attributable evidence. Empty results never prove recovery.
1620
- `,
1621
- 'docs/runbooks/incident-remediation.md': `# Approval-gated incident remediation
1622
-
1623
- Use \`scripts/incident-remediation.mjs\` in report mode first. The report binds
1624
- one action, account, region, stage, Slice, preconditions, stop conditions,
1625
- verification, cleanup, adapter choice, and any adapter evidence through an
1626
- internally computed SHA-256 remediation-plan digest. That digest is distinct
1627
- from the async-recovery report digest consumed by redrive or replay.
1628
-
1629
- Apply requires an unexpired human approval bound to that exact report, action,
1630
- and target plus protected GitHub OIDC on the approved commit. The stable-v1
1631
- adapter supports bounded async redrive or replay through the generated
1632
- protected async-recovery path; its own resource, rate, idempotency, alarm,
1633
- cleanup, and evidence controls still apply. Other remediation paths remain
1634
- report-only until separately implemented. Stop when the active target or
1635
- approved report changes.
1636
- `,
1637
- 'docs/runbooks/api-recovery.md': `# API recovery
1638
-
1639
- Confirm customer impact, API validity classification, recent release and
1640
- configuration identity, database/dependency health, and correlated sanitized
1641
- signals. Prefer a verified roll-forward. A source revert must traverse the
1642
- normal develop-to-staging evidence path before protected production promotion.
1643
- Verify the critical API journey and data invariants before resolution.
1644
- `,
1645
- 'docs/runbooks/web-recovery.md': `# Web recovery
1646
-
1647
- Confirm the server-rendered route, deployed release, configuration digest,
1648
- origin, cache class, and dependency state. Compare cold and warm paths without
1649
- combining their populations. Verify headers, authentication, keyboard/focus,
1650
- responsive layout, reduced motion, and the user journey after recovery.
1651
- `,
1652
- 'docs/runbooks/alert-delivery.md': `# Alert delivery recovery
1653
-
1654
- The generated SNS delivery-failure alarm is diagnostic-only: it deliberately
1655
- has no action on the route whose failure it observes. Record delivery as
1656
- \`requested\` or \`unsupported\`; never promote it to \`confirmed\` without a
1657
- receipt captured from an independently configured provider or route. Do not
1658
- disable customer-impact alarms. Repair or select an approved independent route,
1659
- send one bounded proof, and retain its provider receipt before resolving.
1660
- `,
1661
- 'scripts/reliability-evidence-lib.mjs': `import { createHash } from 'node:crypto';
1662
- import { isBoundedSafeReference } from '@empire-builder-kit/runtime/safe-reference';
1663
- import {
1664
- lstatSync,
1665
- mkdirSync,
1666
- readFileSync,
1667
- writeFileSync,
1668
- } from 'node:fs';
1669
- import { relative, resolve, sep } from 'node:path';
1670
-
1671
- export const MAX_RELIABILITY_ARTIFACT_BYTES = 64 * 1024;
1672
- const DIGEST = /^[a-f0-9]{64}$/;
1673
-
1674
- export function sha256(bytes) {
1675
- return createHash('sha256').update(bytes).digest('hex');
1676
- }
1677
-
1678
- export function exactKeys(value, allowed, label) {
1679
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
1680
- throw new Error(label + ' must be an object.');
1681
- }
1682
- const unexpected = Object.keys(value).filter((key) => !allowed.includes(key));
1683
- if (unexpected.length > 0) {
1684
- throw new Error(label + ' contains unsupported fields: ' + unexpected.sort().join(', ') + '.');
1685
- }
1686
- return value;
1687
- }
1688
-
1689
- export function safeToken(value, label, maximum = 512) {
1690
- if (
1691
- typeof value !== 'string' ||
1692
- value.length < 1 ||
1693
- value.length > maximum ||
1694
- !isBoundedSafeReference(value, 'repository-evidence') ||
1695
- value.includes('..') ||
1696
- value.includes('\\\\')
1697
- ) {
1698
- throw new Error(label + ' is not a bounded sanitized token.');
1699
- }
1700
- return value;
1701
- }
1702
-
1703
- export function digest(value, label) {
1704
- if (typeof value !== 'string' || !DIGEST.test(value)) {
1705
- throw new Error(label + ' must be an exact SHA-256 digest.');
1706
- }
1707
- return value;
1708
- }
1709
-
1710
- export function utc(value, label) {
1711
- if (
1712
- typeof value !== 'string' ||
1713
- value.length > 32 ||
1714
- !value.endsWith('Z') ||
1715
- !Number.isFinite(Date.parse(value))
1716
- ) {
1717
- throw new Error(label + ' must be a bounded UTC timestamp.');
1718
- }
1719
- return value;
1720
- }
1721
-
1722
- export function readBoundedJson(path, label) {
1723
- const bytes = readFileSync(path);
1724
- if (bytes.length === 0 || bytes.length > MAX_RELIABILITY_ARTIFACT_BYTES) {
1725
- throw new Error(label + ' exceeds the reliability artifact size bound.');
1726
- }
1727
- let value;
1728
- try {
1729
- value = JSON.parse(bytes.toString('utf8'));
1730
- } catch {
1731
- throw new Error(label + ' is not valid JSON.');
1732
- }
1733
- return { bytes, value };
1734
- }
1735
-
1736
- export function binding(value, label) {
1737
- const record = exactKeys(
1738
- value,
1739
- [
1740
- 'candidateDigest',
1741
- 'configurationDigest',
1742
- 'deploymentDigest',
1743
- 'releaseDigest',
1744
- 'sourceCommit',
1745
- 'workload',
1746
- ],
1747
- label,
1748
- );
1749
- const sourceCommit = safeToken(
1750
- record.sourceCommit,
1751
- label + '.sourceCommit',
1752
- 40,
1753
- );
1754
- if (!/^[a-f0-9]{40}$/.test(sourceCommit)) {
1755
- throw new Error(label + '.sourceCommit must be an exact git commit.');
1756
- }
1757
- return {
1758
- candidateDigest: digest(record.candidateDigest, label + '.candidateDigest'),
1759
- configurationDigest: digest(
1760
- record.configurationDigest,
1761
- label + '.configurationDigest',
1762
- ),
1763
- deploymentDigest: digest(
1764
- record.deploymentDigest,
1765
- label + '.deploymentDigest',
1766
- ),
1767
- releaseDigest: digest(record.releaseDigest, label + '.releaseDigest'),
1768
- sourceCommit,
1769
- workload: safeToken(record.workload, label + '.workload', 128),
1770
- };
1771
- }
1772
-
1773
- export function sameBinding(left, right) {
1774
- return (
1775
- left.candidateDigest === right.candidateDigest &&
1776
- left.configurationDigest === right.configurationDigest &&
1777
- left.deploymentDigest === right.deploymentDigest &&
1778
- left.releaseDigest === right.releaseDigest &&
1779
- left.sourceCommit === right.sourceCommit &&
1780
- left.workload === right.workload
1781
- );
1782
- }
1783
-
1784
- function artifactReferencePath(value, label) {
1785
- const path = value;
1786
- if (
1787
- typeof path !== 'string' ||
1788
- path.length < 1 ||
1789
- path.length > 1024 ||
1790
- !/^(?:[A-Za-z0-9._-]+\\/)*[A-Za-z0-9._-]+$/.test(path) ||
1791
- path.startsWith('/') ||
1792
- path.split('/').includes('..')
1793
- ) {
1794
- throw new Error(label + ' must remain inside the Slice package.');
1795
- }
1796
- const root = resolve(process.cwd());
1797
- const absolute = resolve(root, path);
1798
- const within = relative(root, absolute);
1799
- if (within.startsWith('..' + sep) || within === '..') {
1800
- throw new Error(label + ' escapes the Slice package.');
1801
- }
1802
- return path;
1803
- }
1804
-
1805
- export function artifactReference(value, label) {
1806
- const record = exactKeys(value, ['digest', 'path'], label);
1807
- const expectedDigest = digest(record.digest, label + '.digest');
1808
- const path = artifactReferencePath(record.path, label + '.path');
1809
- const absolute = resolve(process.cwd(), path);
1810
- const artifact = readBoundedJson(absolute, label);
1811
- const metadata = lstatSync(absolute);
1812
- if (!metadata.isFile() || metadata.isSymbolicLink()) {
1813
- throw new Error(label + ' must be a regular non-symlink artifact.');
1814
- }
1815
- if (sha256(artifact.bytes) !== expectedDigest) {
1816
- throw new Error(label + ' digest does not match its exact artifact bytes.');
1817
- }
1818
- return { ...artifact, digest: expectedDigest, path };
1819
- }
1820
-
1821
- function reliabilityTarget(value, label) {
1822
- const target = exactKeys(
1823
- value,
1824
- ['account', 'region', 'slice', 'stage'],
1825
- label,
1826
- );
1827
- const account = safeToken(target.account, label + '.account', 12);
1828
- if (!/^\\d{12}$/.test(account)) {
1829
- throw new Error(label + '.account must be an exact AWS account ID.');
1830
- }
1831
- const stage = safeToken(target.stage, label + '.stage', 16);
1832
- if (!['staging', 'production'].includes(stage)) {
1833
- throw new Error(label + '.stage must be a protected stage.');
1834
- }
1835
- const slice = safeToken(target.slice, label + '.slice', 128);
1836
- if (slice !== '${name}') {
1837
- throw new Error(label + '.slice escaped the generated Slice.');
1838
- }
1839
- const region = safeToken(target.region, label + '.region', 64);
1840
- if (!/^[a-z]{2}(?:-[a-z]+)+-\\d$/.test(region)) {
1841
- throw new Error(label + '.region must be an exact AWS Region.');
1842
- }
1843
- return {
1844
- account,
1845
- region,
1846
- slice,
1847
- stage,
1848
- };
1849
- }
1850
-
1851
- export function awsPartition(region) {
1852
- if (region.startsWith('cn-')) return 'aws-cn';
1853
- if (region.startsWith('us-gov-')) return 'aws-us-gov';
1854
- if (region.startsWith('us-isob-')) return 'aws-iso-b';
1855
- if (region.startsWith('us-isoe-')) return 'aws-iso-e';
1856
- if (region.startsWith('us-isof-')) return 'aws-iso-f';
1857
- if (region.startsWith('us-iso-')) return 'aws-iso';
1858
- if (region.startsWith('eusc-')) return 'aws-eusc';
1859
- return 'aws';
1860
- }
1861
-
1862
- function reliabilityResources(value, target, label) {
1863
- const resources = exactKeys(
1864
- value,
1865
- ['alarmNames', 'apiId', 'ecsServices', 'stateMachineArns'],
1866
- label,
1867
- );
1868
- if (
1869
- !Array.isArray(resources.alarmNames) ||
1870
- resources.alarmNames.length < 1 ||
1871
- resources.alarmNames.length > 100 ||
1872
- new Set(resources.alarmNames).size !== resources.alarmNames.length
1873
- ) {
1874
- throw new Error(label + '.alarmNames must contain exact unique alarms.');
1875
- }
1876
- const alarmNames = resources.alarmNames
1877
- .map((value, index) =>
1878
- safeToken(value, label + '.alarmNames[' + index + ']', 255),
1879
- )
1880
- .sort();
1881
- if (
1882
- alarmNames.some(
1883
- (value) => !value.startsWith(target.slice + '-' + target.stage + '-'),
1884
- )
1885
- ) {
1886
- throw new Error(label + '.alarmNames escaped the exact Slice and stage.');
1887
- }
1888
- const apiId = safeToken(resources.apiId, label + '.apiId', 128);
1889
- if (!/^[a-z0-9]{1,128}$/.test(apiId)) {
1890
- throw new Error(label + '.apiId must be one exact API Gateway ID.');
1891
- }
1892
- if (
1893
- !Array.isArray(resources.ecsServices) ||
1894
- resources.ecsServices.length > 8
1895
- ) {
1896
- throw new Error(label + '.ecsServices exceeds its eight-cluster bound.');
1897
- }
1898
- const ecsServices = resources.ecsServices
1899
- .map((value, index) => {
1900
- const entry = exactKeys(
1901
- value,
1902
- ['cluster', 'services'],
1903
- label + '.ecsServices[' + index + ']',
1904
- );
1905
- const cluster = safeToken(
1906
- entry.cluster,
1907
- label + '.ecsServices[' + index + '].cluster',
1908
- 512,
1909
- );
1910
- if (
1911
- !Array.isArray(entry.services) ||
1912
- entry.services.length < 1 ||
1913
- entry.services.length > 10 ||
1914
- new Set(entry.services).size !== entry.services.length
1915
- ) {
1916
- throw new Error(
1917
- label + '.ecsServices[' + index + '] has invalid services.',
1918
- );
1919
- }
1920
- const services = entry.services
1921
- .map((service, serviceIndex) =>
1922
- safeToken(
1923
- service,
1924
- label +
1925
- '.ecsServices[' +
1926
- index +
1927
- '].services[' +
1928
- serviceIndex +
1929
- ']',
1930
- 255,
1931
- ),
1932
- )
1933
- .sort();
1934
- const clusterArnPrefix =
1935
- 'arn:' +
1936
- awsPartition(target.region) +
1937
- ':ecs:' +
1938
- target.region +
1939
- ':' +
1940
- target.account +
1941
- ':cluster/';
1942
- if (
1943
- cluster.startsWith('arn:') &&
1944
- !cluster.startsWith(clusterArnPrefix)
1945
- ) {
1946
- throw new Error(
1947
- label + '.ecsServices[' + index + '] escaped the exact target.',
1948
- );
1949
- }
1950
- return { cluster, services };
1951
- })
1952
- .sort((left, right) =>
1953
- left.cluster < right.cluster
1954
- ? -1
1955
- : left.cluster > right.cluster
1956
- ? 1
1957
- : 0,
1958
- );
1959
- if (
1960
- new Set(ecsServices.map(({ cluster }) => cluster)).size !==
1961
- ecsServices.length
1962
- ) {
1963
- throw new Error(label + '.ecsServices repeats an exact cluster.');
1964
- }
1965
- if (
1966
- !Array.isArray(resources.stateMachineArns) ||
1967
- resources.stateMachineArns.length > 8 ||
1968
- new Set(resources.stateMachineArns).size !==
1969
- resources.stateMachineArns.length
1970
- ) {
1971
- throw new Error(
1972
- label + '.stateMachineArns exceeds its exact unique bound.',
1973
- );
1974
- }
1975
- const stateMachinePrefix =
1976
- 'arn:' +
1977
- awsPartition(target.region) +
1978
- ':states:' +
1979
- target.region +
1980
- ':' +
1981
- target.account +
1982
- ':stateMachine:';
1983
- const stateMachineArns = resources.stateMachineArns
1984
- .map((value, index) =>
1985
- safeToken(value, label + '.stateMachineArns[' + index + ']', 512),
1986
- )
1987
- .sort();
1988
- if (
1989
- stateMachineArns.some(
1990
- (value) =>
1991
- !value.startsWith(stateMachinePrefix) ||
1992
- value.length === stateMachinePrefix.length,
1993
- )
1994
- ) {
1995
- throw new Error(label + '.stateMachineArns escaped the exact target.');
1996
- }
1997
- return {
1998
- alarmNames,
1999
- apiId,
2000
- ecsServices,
2001
- stateMachineArns,
2002
- };
2003
- }
2004
-
2005
- export function authorizedExecutionArn(resources, executionArn) {
2006
- return resources.stateMachineArns.some((stateMachineArn) => {
2007
- const separator = ':stateMachine:';
2008
- const position = stateMachineArn.indexOf(separator);
2009
- if (position < 0) return false;
2010
- const executionPrefix =
2011
- stateMachineArn.slice(0, position) +
2012
- ':execution:' +
2013
- stateMachineArn.slice(position + separator.length) +
2014
- ':';
2015
- return executionArn.startsWith(executionPrefix);
2016
- });
2017
- }
2018
-
2019
- function protectedDeploymentSource(reference, target, expectedSmoke) {
2020
- const deploymentReference = artifactReference(
2021
- reference,
2022
- 'sources.deployment',
2023
- );
2024
- const deployment = exactKeys(
2025
- deploymentReference.value,
2026
- [
2027
- 'deployment',
2028
- 'kind',
2029
- 'project',
2030
- 'resources',
2031
- 'schemaVersion',
2032
- 'smoke',
2033
- 'sourceCommit',
2034
- 'stage',
2035
- 'trigger',
2036
- ],
2037
- 'Protected deployment binding',
2038
- );
2039
- const identity = exactKeys(
2040
- deployment.deployment,
2041
- [
2042
- 'conclusion',
2043
- 'event',
2044
- 'headBranch',
2045
- 'headSha',
2046
- 'runAttempt',
2047
- 'runId',
2048
- 'workflow',
2049
- ],
2050
- 'Protected deployment identity',
2051
- );
2052
- const smoke = exactKeys(
2053
- deployment.smoke,
2054
- ['runAttempt', 'runId', 'workflow'],
2055
- 'Protected smoke identity',
2056
- );
2057
- const sourceCommit = safeToken(
2058
- deployment.sourceCommit,
2059
- 'Protected deployment sourceCommit',
2060
- 40,
2061
- );
2062
- const expectedBranch = target.stage === 'production' ? 'main' : 'develop';
2063
- if (
2064
- deployment.kind !== 'ebk-deployed-smoke-binding' ||
2065
- deployment.schemaVersion !== 1 ||
2066
- deployment.project !== '${name}' ||
2067
- deployment.stage !== target.stage ||
2068
- deployment.trigger !== 'deployment' ||
2069
- identity.conclusion !== 'success' ||
2070
- !['push', 'workflow_dispatch'].includes(identity.event) ||
2071
- identity.headBranch !== expectedBranch ||
2072
- identity.headSha !== sourceCommit ||
2073
- identity.workflow !== 'Deploy' ||
2074
- smoke.workflow !== 'Deployed smoke' ||
2075
- String(smoke.runId) !== expectedSmoke.runId ||
2076
- String(smoke.runAttempt) !== expectedSmoke.runAttempt ||
2077
- !/^\\d+$/.test(String(identity.runId ?? '')) ||
2078
- !/^\\d+$/.test(String(identity.runAttempt ?? '')) ||
2079
- !/^[a-f0-9]{40}$/.test(sourceCommit)
2080
- ) {
2081
- throw new Error(
2082
- 'Protected deployment source does not prove the active Slice deployment.',
2083
- );
2084
- }
2085
- return {
2086
- reference: deploymentReference,
2087
- resources: reliabilityResources(
2088
- deployment.resources,
2089
- target,
2090
- 'Protected deployment resources',
2091
- ),
2092
- runAttempt: String(identity.runAttempt),
2093
- runId: String(identity.runId),
2094
- sourceCommit,
2095
- };
2096
- }
2097
-
2098
- function protectedReleaseSource(reference, target, deployment) {
2099
- const releaseReference = artifactReference(
2100
- reference,
2101
- 'sources.release',
2102
- );
2103
- const release = exactKeys(
2104
- releaseReference.value,
2105
- [
2106
- 'candidateDigest',
2107
- 'deploymentCommit',
2108
- 'kind',
2109
- 'manifestDigest',
2110
- 'releaseId',
2111
- 'releaseMaterialDigest',
2112
- 'releaseSourceCommit',
2113
- 'runAttempt',
2114
- 'runId',
2115
- 'schemaVersion',
2116
- 'stage',
2117
- 'workflow',
2118
- ],
2119
- 'Active protected release',
2120
- );
2121
- const releaseSourceCommit = safeToken(
2122
- release.releaseSourceCommit,
2123
- 'Active protected release.releaseSourceCommit',
2124
- 40,
2125
- );
2126
- if (
2127
- release.kind !== 'ebk-active-protected-release-binding' ||
2128
- release.schemaVersion !== 1 ||
2129
- release.stage !== target.stage ||
2130
- release.deploymentCommit !== deployment.sourceCommit ||
2131
- String(release.runId) !== deployment.runId ||
2132
- String(release.runAttempt) !== deployment.runAttempt ||
2133
- release.workflow !== 'Deploy' ||
2134
- !/^[a-f0-9]{40}$/.test(releaseSourceCommit)
2135
- ) {
2136
- throw new Error(
2137
- 'Active release does not match the protected deployment identity.',
2138
- );
2139
- }
2140
- return {
2141
- candidateDigest: digest(
2142
- release.candidateDigest,
2143
- 'Active protected release.candidateDigest',
2144
- ),
2145
- manifestDigest: digest(
2146
- release.manifestDigest,
2147
- 'Active protected release.manifestDigest',
2148
- ),
2149
- reference: releaseReference,
2150
- releaseMaterialDigest: digest(
2151
- release.releaseMaterialDigest,
2152
- 'Active protected release.releaseMaterialDigest',
2153
- ),
2154
- releaseSourceCommit,
2155
- };
2156
- }
2157
-
2158
- function releaseManifestSource(reference, target, sourceCommit) {
2159
- const manifestReference = artifactReference(
2160
- reference,
2161
- 'sources.manifest',
2162
- );
2163
- const manifest = exactKeys(
2164
- manifestReference.value,
2165
- [
2166
- 'artifacts',
2167
- 'blueprints',
2168
- 'build',
2169
- 'builtAt',
2170
- 'configuration',
2171
- 'contracts',
2172
- 'controls',
2173
- 'frameworkCandidate',
2174
- 'infrastructure',
2175
- 'initialLifecycle',
2176
- 'kind',
2177
- 'materialDigest',
2178
- 'migrations',
2179
- 'packageLockDigest',
2180
- 'projects',
2181
- 'releaseId',
2182
- 'requiredTests',
2183
- 'schemaVersion',
2184
- 'secrets',
2185
- 'source',
2186
- 'supplyChain',
2187
- 'toolchain',
2188
- ],
2189
- 'Release manifest',
2190
- );
2191
- const source = exactKeys(
2192
- manifest.source,
2193
- ['commit', 'repository', 'treeDigest'],
2194
- 'Release manifest source',
2195
- );
2196
- const infrastructure = exactKeys(
2197
- manifest.infrastructure,
2198
- [
2199
- 'aggregateRisk',
2200
- 'configurationMetadataDigest',
2201
- 'materialDigest',
2202
- 'policyProfileDigest',
2203
- 'riskClasses',
2204
- 'stage',
2205
- 'tool',
2206
- ],
2207
- 'Release manifest infrastructure',
2208
- );
2209
- if (
2210
- manifest.kind !== 'ebk-release-manifest' ||
2211
- manifest.schemaVersion !== 1 ||
2212
- source.commit !== sourceCommit ||
2213
- infrastructure.stage !== target.stage ||
2214
- !Array.isArray(manifest.projects) ||
2215
- !manifest.projects.includes('${name}') ||
2216
- !Array.isArray(manifest.configuration)
2217
- ) {
2218
- throw new Error(
2219
- 'Release manifest does not match the protected deployment source.',
2220
- );
2221
- }
2222
- digest(manifest.materialDigest, 'Release manifest.materialDigest');
2223
- const configuration = manifest.configuration.filter(
2224
- (entry) => entry?.stage === target.stage,
2225
- );
2226
- if (configuration.length !== 1) {
2227
- throw new Error(
2228
- 'Release manifest must contain one exact protected-stage configuration.',
2229
- );
2230
- }
2231
- const configured = exactKeys(
2232
- configuration[0],
2233
- ['digest', 'stage'],
2234
- 'Release manifest configuration',
2235
- );
2236
- return {
2237
- configurationDigest: digest(
2238
- configured.digest,
2239
- 'Release manifest configuration.digest',
2240
- ),
2241
- reference: manifestReference,
2242
- };
2243
- }
2244
-
2245
- export function createReliabilityDeploymentBinding(
2246
- input,
2247
- expectedTarget,
2248
- expectedSmoke,
2249
- ) {
2250
- const request = exactKeys(
2251
- input,
2252
- ['schemaVersion', 'sources', 'workload'],
2253
- 'Reliability deployment binding input',
2254
- );
2255
- if (request.schemaVersion !== 1) {
2256
- throw new Error('Reliability deployment binding input is incompatible.');
2257
- }
2258
- const target = reliabilityTarget(expectedTarget, 'target');
2259
- const sources = exactKeys(
2260
- request.sources,
2261
- ['deployment', 'manifest', 'release'],
2262
- 'Reliability deployment sources',
2263
- );
2264
- const smoke = exactKeys(
2265
- expectedSmoke,
2266
- ['runAttempt', 'runId'],
2267
- 'expectedSmoke',
2268
- );
2269
- for (const [name, value] of Object.entries(smoke)) {
2270
- if (!/^\\d+$/.test(String(value ?? ''))) {
2271
- throw new Error('expectedSmoke.' + name + ' must be an exact run number.');
2272
- }
2273
- }
2274
- const deployment = protectedDeploymentSource(sources.deployment, target, {
2275
- runAttempt: String(smoke.runAttempt),
2276
- runId: String(smoke.runId),
2277
- });
2278
- const release = protectedReleaseSource(
2279
- sources.release,
2280
- target,
2281
- deployment,
2282
- );
2283
- const manifest = releaseManifestSource(
2284
- sources.manifest,
2285
- target,
2286
- release.releaseSourceCommit,
2287
- );
2288
- if (
2289
- release.manifestDigest !== manifest.reference.digest ||
2290
- release.releaseMaterialDigest !==
2291
- manifest.reference.value.materialDigest
2292
- ) {
2293
- throw new Error(
2294
- 'Active release does not bind the exact release manifest bytes.',
2295
- );
2296
- }
2297
- return {
2298
- binding: {
2299
- candidateDigest: release.candidateDigest,
2300
- configurationDigest: manifest.configurationDigest,
2301
- deploymentDigest: deployment.reference.digest,
2302
- releaseDigest: manifest.reference.digest,
2303
- sourceCommit: release.releaseSourceCommit,
2304
- workload: safeToken(request.workload, 'workload', 128),
2305
- },
2306
- kind: 'reliability-active-deployment-binding',
2307
- resources: deployment.resources,
2308
- schemaVersion: 1,
2309
- slice: '${name}',
2310
- smoke: {
2311
- runAttempt: String(smoke.runAttempt),
2312
- runId: String(smoke.runId),
2313
- },
2314
- sources: {
2315
- deployment: {
2316
- digest: deployment.reference.digest,
2317
- path: deployment.reference.path,
2318
- },
2319
- manifest: {
2320
- digest: manifest.reference.digest,
2321
- path: manifest.reference.path,
2322
- },
2323
- release: {
2324
- digest: release.reference.digest,
2325
- path: release.reference.path,
2326
- },
2327
- },
2328
- target,
2329
- };
2330
- }
2331
-
2332
- export function activeDeploymentBinding(reference, label) {
2333
- if (
2334
- process.env.GITHUB_ACTIONS !== 'true' ||
2335
- process.env.GITHUB_REF_PROTECTED !== 'true'
2336
- ) {
2337
- throw new Error(
2338
- 'AWS reliability access requires one protected GitHub Actions context.',
2339
- );
2340
- }
2341
- const requested = exactKeys(reference, ['digest', 'path'], label);
2342
- const indexPath = '.ebk/evidence/reliability/active-bindings.json';
2343
- const indexAbsolute = resolve(process.cwd(), indexPath);
2344
- const indexArtifact = readBoundedJson(
2345
- indexAbsolute,
2346
- 'Protected reliability binding index',
2347
- );
2348
- const indexMetadata = lstatSync(indexAbsolute);
2349
- if (!indexMetadata.isFile() || indexMetadata.isSymbolicLink()) {
2350
- throw new Error(
2351
- 'Protected reliability binding index must be a regular non-symlink artifact.',
2352
- );
2353
- }
2354
- const index = exactKeys(
2355
- indexArtifact.value,
2356
- [
2357
- 'authority',
2358
- 'bindings',
2359
- 'kind',
2360
- 'schemaVersion',
2361
- 'slice',
2362
- 'stage',
2363
- 'target',
2364
- ],
2365
- 'Protected reliability binding index',
2366
- );
2367
- const authority = exactKeys(
2368
- index.authority,
2369
- [
2370
- 'repository',
2371
- 'runAttempt',
2372
- 'runId',
2373
- 'sourceCommit',
2374
- 'workflow',
2375
- ],
2376
- 'Protected reliability binding authority',
2377
- );
2378
- const sourceCommit = safeToken(
2379
- authority.sourceCommit,
2380
- 'Protected reliability binding authority.sourceCommit',
2381
- 40,
2382
- );
2383
- const repository = safeToken(
2384
- authority.repository,
2385
- 'Protected reliability binding authority.repository',
2386
- 256,
2387
- );
2388
- if (
2389
- index.kind !== 'reliability-active-binding-index' ||
2390
- index.schemaVersion !== 1 ||
2391
- index.slice !== '${name}' ||
2392
- !['staging', 'production'].includes(index.stage) ||
2393
- authority.workflow !== 'Deployed smoke' ||
2394
- !/^\\d+$/.test(String(authority.runId ?? '')) ||
2395
- !/^\\d+$/.test(String(authority.runAttempt ?? '')) ||
2396
- !/^[a-f0-9]{40}$/.test(sourceCommit) ||
2397
- !/^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/.test(repository) ||
2398
- process.env.EBK_RELIABILITY_AUTHORIZED_SOURCE_COMMIT !== sourceCommit ||
2399
- process.env.EBK_RELIABILITY_AUTHORIZED_SMOKE_RUN_ID !==
2400
- String(authority.runId) ||
2401
- process.env.EBK_RELIABILITY_AUTHORIZED_SMOKE_RUN_ATTEMPT !==
2402
- String(authority.runAttempt) ||
2403
- process.env.GITHUB_REPOSITORY !== repository
2404
- ) {
2405
- throw new Error(
2406
- 'Protected reliability binding index is stale or lacks current workflow authority.',
2407
- );
2408
- }
2409
- const indexTarget = reliabilityTarget(
2410
- {
2411
- ...index.target,
2412
- slice: index.slice,
2413
- stage: index.stage,
2414
- },
2415
- 'Protected reliability binding index target',
2416
- );
2417
- if (
2418
- !Array.isArray(index.bindings) ||
2419
- index.bindings.length < 1 ||
2420
- index.bindings.length > 128
2421
- ) {
2422
- throw new Error(
2423
- 'Protected reliability binding index has invalid workload coverage.',
2424
- );
2425
- }
2426
- const indexedBindings = index.bindings.map((value, entryIndex) => {
2427
- const entry = exactKeys(
2428
- value,
2429
- ['digest', 'path', 'workload'],
2430
- 'Protected reliability binding index.bindings[' +
2431
- entryIndex +
2432
- ']',
2433
- );
2434
- return {
2435
- digest: digest(
2436
- entry.digest,
2437
- 'Protected reliability binding index.bindings.digest',
2438
- ),
2439
- path: artifactReferencePath(
2440
- entry.path,
2441
- 'Protected reliability binding index.bindings.path',
2442
- ),
2443
- workload: safeToken(
2444
- entry.workload,
2445
- 'Protected reliability binding index.bindings.workload',
2446
- 128,
2447
- ),
2448
- };
2449
- });
2450
- if (
2451
- new Set(
2452
- indexedBindings.map(
2453
- ({ digest: artifactDigest, path }) => artifactDigest + ':' + path,
2454
- ),
2455
- ).size !== indexedBindings.length ||
2456
- new Set(indexedBindings.map(({ workload }) => workload)).size !==
2457
- indexedBindings.length
2458
- ) {
2459
- throw new Error(
2460
- 'Protected reliability binding index contains ambiguous bindings.',
2461
- );
2462
- }
2463
- const indexed = indexedBindings.filter(
2464
- ({ digest: artifactDigest, path }) =>
2465
- artifactDigest === requested.digest && path === requested.path,
2466
- );
2467
- if (indexed.length !== 1) {
2468
- throw new Error(
2469
- 'Requested reliability binding is not selected by the protected current index.',
2470
- );
2471
- }
2472
- const active = artifactReference(requested, label);
2473
- const document = exactKeys(
2474
- active.value,
2475
- [
2476
- 'binding',
2477
- 'kind',
2478
- 'resources',
2479
- 'schemaVersion',
2480
- 'slice',
2481
- 'smoke',
2482
- 'sources',
2483
- 'target',
2484
- ],
2485
- 'Active reliability deployment binding',
2486
- );
2487
- const target = reliabilityTarget(
2488
- document.target,
2489
- 'Active reliability deployment binding target',
2490
- );
2491
- const capturedBinding = binding(
2492
- document.binding,
2493
- 'Active reliability deployment binding.binding',
2494
- );
2495
- const expected = createReliabilityDeploymentBinding(
2496
- {
2497
- schemaVersion: 1,
2498
- sources: document.sources,
2499
- workload: capturedBinding.workload,
2500
- },
2501
- target,
2502
- document.smoke,
2503
- );
2504
- if (
2505
- document.kind !== expected.kind ||
2506
- document.schemaVersion !== 1 ||
2507
- document.slice !== '${name}' ||
2508
- capturedBinding.sourceCommit !== sourceCommit ||
2509
- capturedBinding.workload !== indexed[0].workload ||
2510
- target.account !== indexTarget.account ||
2511
- target.region !== indexTarget.region ||
2512
- target.stage !== indexTarget.stage ||
2513
- JSON.stringify(document) !== JSON.stringify(expected)
2514
- ) {
2515
- throw new Error(
2516
- 'Active reliability deployment binding is stale or was substituted.',
2517
- );
2518
- }
2519
- return {
2520
- binding: capturedBinding,
2521
- authorityDigest: sha256(indexArtifact.bytes),
2522
- digest: active.digest,
2523
- document,
2524
- path: active.path,
2525
- resources: reliabilityResources(
2526
- document.resources,
2527
- target,
2528
- 'Active reliability deployment binding.resources',
2529
- ),
2530
- target,
2531
- };
2532
- }
2533
-
2534
- export function writeImmutableArtifact(directory, value) {
2535
- const bytes = Buffer.from(JSON.stringify(value, null, 2) + '\\n');
2536
- if (bytes.length > MAX_RELIABILITY_ARTIFACT_BYTES) {
2537
- throw new Error('Reliability artifact exceeds its output size bound.');
2538
- }
2539
- const artifactDigest = sha256(bytes);
2540
- const relativePath = directory + '/' + artifactDigest + '.json';
2541
- const absolute = resolve(process.cwd(), relativePath);
2542
- mkdirSync(resolve(process.cwd(), directory), {
2543
- mode: 0o700,
2544
- recursive: true,
2545
- });
2546
- try {
2547
- writeFileSync(absolute, bytes, { flag: 'wx', mode: 0o600 });
2548
- } catch (error) {
2549
- if (!readFileSync(absolute).equals(bytes)) throw error;
2550
- }
2551
- return { digest: artifactDigest, path: relativePath };
2552
- }
2553
- `,
2554
- 'scripts/create-reliability-deployment-binding.mjs': `import {
2555
- createReliabilityDeploymentBinding,
2556
- exactKeys,
2557
- readBoundedJson,
2558
- writeImmutableArtifact,
2559
- } from './reliability-evidence-lib.mjs';
2560
-
2561
- const inputPath =
2562
- process.env.EBK_RELIABILITY_BINDING_INPUT_PATH?.trim();
2563
- if (!inputPath) {
2564
- throw new Error('EBK_RELIABILITY_BINDING_INPUT_PATH is required.');
2565
- }
2566
- const required = (name, pattern) => {
2567
- const value = process.env[name]?.trim();
2568
- if (!value || !pattern.test(value)) {
2569
- throw new Error(name + ' is required and outside its exact bound.');
2570
- }
2571
- return value;
2572
- };
2573
- const input = exactKeys(
2574
- readBoundedJson(inputPath, 'Reliability deployment binding input').value,
2575
- ['schemaVersion', 'sources', 'workload'],
2576
- 'Reliability deployment binding input',
2577
- );
2578
- const document = createReliabilityDeploymentBinding(input, {
2579
- account: required('AWS_EXPECTED_ACCOUNT_ID', /^\\d{12}$/),
2580
- region: required('AWS_REGION', /^[a-z]{2}(?:-[a-z]+)+-\\d$/),
2581
- slice: '${name}',
2582
- stage: required('EBK_STAGE', /^(?:staging|production)$/),
2583
- }, {
2584
- runAttempt: required('EBK_SMOKE_RUN_ATTEMPT', /^\\d+$/),
2585
- runId: required('EBK_SMOKE_RUN_ID', /^\\d+$/),
2586
- });
2587
- const reference = writeImmutableArtifact(
2588
- '.ebk/evidence/reliability/bindings',
2589
- document,
2590
- );
2591
- process.stdout.write(
2592
- JSON.stringify({ ...reference, ...document }) + '\\n',
2593
- );
2594
- `,
2595
- 'scripts/verify-reliability.mjs': `import {
2596
- CloudWatchClient,
2597
- DescribeAlarmsCommand,
2598
- } from '@aws-sdk/client-cloudwatch';
2599
- import {
2600
- GetCallerIdentityCommand,
2601
- STSClient,
2602
- } from '@aws-sdk/client-sts';
2603
- import { readFileSync } from 'node:fs';
2604
- import { awsPartition } from './reliability-evidence-lib.mjs';
2605
- import {
2606
- validateAlarmRegistrationMetadata,
2607
- validateIncidentRecord,
2608
- validateReliabilityContract,
2609
- } from '@empire-builder-kit/runtime/reliability';
2610
-
2611
- const slo = JSON.parse(
2612
- readFileSync(new URL('../docs/reliability/slo.json', import.meta.url), 'utf8'),
2613
- );
2614
- const operations = JSON.parse(
2615
- readFileSync(new URL('../operations/reliability.json', import.meta.url), 'utf8'),
2616
- );
2617
- const incident = JSON.parse(
2618
- readFileSync(new URL('../operations/incident-template.json', import.meta.url), 'utf8'),
2619
- );
2620
- const contract = validateReliabilityContract(slo);
2621
- validateIncidentRecord(incident);
2622
- if (
2623
- operations?.schemaVersion !== 1 ||
2624
- operations?.slice !== '${name}' ||
2625
- operations?.sloRef !== 'docs:reliability/slo.json' ||
2626
- operations?.consoleIndependent !== true
2627
- ) {
2628
- throw new Error('Reliability operations registration is incompatible.');
2629
- }
2630
- if (!Array.isArray(operations.alarmRegistrations)) {
2631
- throw new Error('Reliability alarm registrations are absent.');
2632
- }
2633
- const alarmRegistrations = operations.alarmRegistrations.map(
2634
- validateAlarmRegistrationMetadata,
2635
- );
2636
- const registered = new Set(alarmRegistrations.map((alarm) => alarm.id));
2637
- if (registered.size !== alarmRegistrations.length) {
2638
- throw new Error('Reliability alarm registrations contain duplicate IDs.');
2639
- }
2640
- for (const objective of contract.objectives) {
2641
- for (const alarmId of objective.references.alarmIds) {
2642
- if (!registered.has(alarmId)) {
2643
- throw new Error(
2644
- 'SLO objective ' + objective.id + ' references an unregistered alarm.',
2645
- );
2646
- }
2647
- }
2648
- }
2649
- const requiredCoverage = [
2650
- 'alert-delivery',
2651
- 'built-in-retention-job',
2652
- 'deployed-smoke',
2653
- 'function',
2654
- 'job',
2655
- 'service',
2656
- ];
2657
- if (requiredCoverage.some(
2658
- (kind) => !operations.workloadCoverage?.some((entry) => entry.kind === kind),
2659
- )) {
2660
- throw new Error('Reliability workload coverage is incomplete.');
2661
- }
2662
- if (
2663
- operations.alertDelivery?.mode !== 'diagnostic-only' ||
2664
- operations.alertDelivery?.confirmation !==
2665
- 'unsupported-until-independent-route-is-configured' ||
2666
- operations.runtimeSmoke?.aggregateOwner !== 'testing-evidence' ||
2667
- operations.runtimeSmoke?.deployedResourceClass !==
2668
- 'testing-evidence-not-cloudwatch-alarm' ||
2669
- operations.runtimeSmoke?.reporter !==
2670
- 'testing-evidence-native-not-reliability-exercise-report' ||
2671
- operations.runtimeSmoke?.target !== 'smoke-deployed'
2672
- ) {
2673
- throw new Error(
2674
- 'Alert-delivery or deployed-smoke ownership is overstated.',
2675
- );
2676
- }
2677
-
2678
- let deployed = false;
2679
- if (process.argv.includes('--deployed')) {
2680
- const required = (key) => {
2681
- const value = process.env[key]?.trim();
2682
- if (!value || !/^[A-Za-z0-9._:/-]{1,128}$/.test(value)) {
2683
- throw new Error(key + ' is required for deployed verification.');
2684
- }
2685
- return value;
2686
- };
2687
- const account = required('AWS_EXPECTED_ACCOUNT_ID');
2688
- const region = required('AWS_REGION');
2689
- const stage = required('EBK_STAGE');
2690
- const partition = awsPartition(region);
2691
- const identity = await new STSClient({ region }).send(
2692
- new GetCallerIdentityCommand({}),
2693
- );
2694
- if (
2695
- identity.Account !== account ||
2696
- !identity.Arn?.startsWith('arn:' + partition + ':sts::' + account + ':')
2697
- ) {
2698
- throw new Error(
2699
- 'AWS caller identity does not match deployed reliability verification.',
2700
- );
2701
- }
2702
- const expected = operations.deployedAlarmResources?.map((resource) => ({
2703
- ...resource,
2704
- name: resource.name.replace('{stage}', stage),
2705
- }));
2706
- if (
2707
- !Array.isArray(expected) ||
2708
- expected.length < 1 ||
2709
- expected.length > 100 ||
2710
- new Set(expected.map(({ name }) => name)).size !== expected.length ||
2711
- new Set(expected.map(({ id }) => id)).size !== expected.length ||
2712
- expected.some(({ id }) => !registered.has(id))
2713
- ) {
2714
- throw new Error('Deployed alarm resource inventory is invalid.');
2715
- }
2716
- const response = await new CloudWatchClient({ region }).send(
2717
- new DescribeAlarmsCommand({
2718
- AlarmNames: expected.map(({ name }) => name),
2719
- MaxRecords: expected.length,
2720
- }),
2721
- );
2722
- if (response.NextToken) {
2723
- throw new Error('Deployed alarm verification exceeded its one-page bound.');
2724
- }
2725
- const alarms = response.MetricAlarms ?? [];
2726
- if (
2727
- alarms.length !== expected.length ||
2728
- new Set(alarms.map(({ AlarmName }) => AlarmName)).size !== alarms.length
2729
- ) {
2730
- throw new Error('Deployed alarm resource identity is absent or ambiguous.');
2731
- }
2732
- const primaryRouteArns = new Set();
2733
- for (const resource of expected) {
2734
- const alarm = alarms.find(({ AlarmName }) => AlarmName === resource.name);
2735
- const description = JSON.parse(alarm?.AlarmDescription ?? 'null');
2736
- if (
2737
- !alarm ||
2738
- alarm.AlarmArn !==
2739
- 'arn:' +
2740
- partition +
2741
- ':cloudwatch:' +
2742
- region +
2743
- ':' +
2744
- account +
2745
- ':alarm:' +
2746
- resource.name ||
2747
- description?.id !== resource.id ||
2748
- description?.slice !== '${name}' ||
2749
- description?.schemaVersion !== 1 ||
2750
- description?.owner !== resource.owner ||
2751
- description?.route !== resource.route ||
2752
- description?.runbook !== resource.runbook
2753
- ) {
2754
- throw new Error(
2755
- 'Deployed alarm does not match its exact AWS resource identity.',
2756
- );
2757
- }
2758
- if (
2759
- (resource.actions === 'none' && (alarm.AlarmActions?.length ?? 0) !== 0) ||
2760
- (resource.actions === 'primary-route' &&
2761
- (alarm.AlarmActions?.length ?? 0) !== 1)
2762
- ) {
2763
- throw new Error('Deployed alarm action route does not match policy.');
2764
- }
2765
- if (resource.actions === 'primary-route') {
2766
- const action = alarm.AlarmActions[0];
2767
- if (
2768
- typeof action !== 'string' ||
2769
- !action.startsWith(
2770
- 'arn:' + partition + ':sns:' + region + ':' + account + ':',
2771
- )
2772
- ) {
2773
- throw new Error('Deployed alarm action escaped the exact AWS target.');
2774
- }
2775
- primaryRouteArns.add(action);
2776
- }
2777
- const metricDefinitions = [
2778
- ...(alarm.MetricName
2779
- ? [{
2780
- dimensions: alarm.Dimensions ?? [],
2781
- metricName: alarm.MetricName,
2782
- namespace: alarm.Namespace,
2783
- period: alarm.Period,
2784
- statistic: alarm.Statistic,
2785
- }]
2786
- : []),
2787
- ...(alarm.Metrics ?? [])
2788
- .filter(({ MetricStat }) => MetricStat?.Metric)
2789
- .map(({ MetricStat }) => ({
2790
- dimensions: MetricStat.Metric.Dimensions ?? [],
2791
- metricName: MetricStat.Metric.MetricName,
2792
- namespace: MetricStat.Metric.Namespace,
2793
- period: MetricStat.Period,
2794
- statistic: MetricStat.Stat,
2795
- })),
2796
- ];
2797
- const actualDimensionNames = [
2798
- ...new Set(
2799
- metricDefinitions.flatMap(({ dimensions }) =>
2800
- dimensions.map(({ Name }) => Name),
2801
- ),
2802
- ),
2803
- ].sort();
2804
- const dimensionValues = new Map();
2805
- let incompatibleDimensionValue = false;
2806
- for (const { dimensions } of metricDefinitions) {
2807
- for (const { Name, Value } of dimensions) {
2808
- if (
2809
- typeof Name !== 'string' ||
2810
- typeof Value !== 'string' ||
2811
- Value.length < 1 ||
2812
- Value.length > 1024 ||
2813
- (dimensionValues.has(Name) &&
2814
- dimensionValues.get(Name) !== Value)
2815
- ) {
2816
- incompatibleDimensionValue = true;
2817
- }
2818
- dimensionValues.set(Name, Value);
2819
- }
2820
- }
2821
- const expectedDimensionValues = Object.fromEntries(
2822
- Object.entries(resource.dimensionValues ?? {}).map(([key, value]) => [
2823
- key,
2824
- value.replace('{stage}', stage),
2825
- ]),
2826
- );
2827
- const actualMetricNames = [
2828
- ...new Set(metricDefinitions.map(({ metricName }) => metricName)),
2829
- ].sort();
2830
- const actualNamespaces = [
2831
- ...new Set(metricDefinitions.map(({ namespace }) => namespace)),
2832
- ];
2833
- const expectedMetricNames = (
2834
- resource.metricNames ?? [resource.metricName]
2835
- ).slice().sort();
2836
- if (
2837
- JSON.stringify(actualDimensionNames) !==
2838
- JSON.stringify(resource.dimensionNames.slice().sort()) ||
2839
- incompatibleDimensionValue ||
2840
- Object.entries(expectedDimensionValues).some(
2841
- ([key, value]) => dimensionValues.get(key) !== value,
2842
- ) ||
2843
- JSON.stringify(actualMetricNames) !==
2844
- JSON.stringify(expectedMetricNames) ||
2845
- actualNamespaces.length !== 1 ||
2846
- actualNamespaces[0] !== resource.namespace ||
2847
- alarm.ComparisonOperator !== resource.comparisonOperator ||
2848
- alarm.EvaluationPeriods !== resource.evaluationPeriods ||
2849
- alarm.Threshold !== resource.threshold ||
2850
- alarm.TreatMissingData !== resource.treatMissingData ||
2851
- (resource.period !== undefined &&
2852
- metricDefinitions.some(({ period }) => period !== resource.period)) ||
2853
- (resource.statistic !== undefined &&
2854
- metricDefinitions.some(
2855
- ({ statistic }) => statistic !== resource.statistic,
2856
- ))
2857
- ) {
2858
- throw new Error(
2859
- 'Deployed alarm dimensions or AWS signal do not match inventory.',
2860
- );
2861
- }
2862
- if (
2863
- resource.signal === 'metric-math' &&
2864
- (
2865
- !Array.isArray(alarm.Metrics) ||
2866
- alarm.Metrics.filter(({ ReturnData }) => ReturnData).length !== 1 ||
2867
- (resource.objectiveId !== undefined &&
2868
- !alarm.Metrics.some(({ Expression }) => {
2869
- const objective = contract.objectives.find(
2870
- ({ id }) => id === resource.objectiveId,
2871
- );
2872
- const allowedBadFraction = objective
2873
- ? Number((1 - objective.target).toFixed(6)).toString()
2874
- : '';
2875
- return (
2876
- objective &&
2877
- Expression?.includes('IF(v>=') &&
2878
- Expression.includes('/' + allowedBadFraction)
2879
- );
2880
- }))
2881
- )
2882
- ) {
2883
- throw new Error('Deployed metric-math alarm is not executable.');
2884
- }
2885
- }
2886
- if (primaryRouteArns.size !== 1) {
2887
- throw new Error('Deployed alarms do not share one exact primary route.');
2888
- }
2889
- deployed = true;
2890
- }
2891
- process.stdout.write(JSON.stringify({
2892
- deployedAlarmResourcesVerified: deployed,
2893
- kind: 'reliability-contract-verification',
2894
- schemaVersion: 1,
2895
- slice: '${name}',
2896
- }) + '\\n');
2897
- `,
2898
- 'scripts/reliability-report.mjs': `import { readFileSync } from 'node:fs';
2899
- import {
2900
- evaluateSlo,
2901
- validateReliabilityContract,
2902
- } from '@empire-builder-kit/runtime/reliability';
2903
- import {
2904
- activeDeploymentBinding,
2905
- artifactReference,
2906
- binding,
2907
- digest,
2908
- exactKeys,
2909
- readBoundedJson,
2910
- safeToken,
2911
- sameBinding,
2912
- utc,
2913
- writeImmutableArtifact,
2914
- } from './reliability-evidence-lib.mjs';
2915
-
2916
- const inputPath = process.env.EBK_RELIABILITY_EVIDENCE_INPUT_PATH?.trim();
2917
- if (!inputPath) {
2918
- throw new Error('EBK_RELIABILITY_EVIDENCE_INPUT_PATH is required.');
2919
- }
2920
- const inputArtifact = readBoundedJson(inputPath, 'Reliability report input');
2921
- const input = exactKeys(
2922
- inputArtifact.value,
2923
- ['capture', 'objectiveId', 'schemaVersion'],
2924
- 'Reliability report input',
2925
- );
2926
- if (input.schemaVersion !== 1) {
2927
- throw new Error('Reliability report input is incompatible.');
2928
- }
2929
- const objectiveId = safeToken(input.objectiveId, 'objectiveId', 128);
2930
- const captured = artifactReference(input.capture, 'capture');
2931
- const capture = exactKeys(
2932
- captured.value,
2933
- [
2934
- 'binding',
2935
- 'bindingArtifact',
2936
- 'capturedAt',
2937
- 'kind',
2938
- 'metricResults',
2939
- 'objectiveId',
2940
- 'queryDigest',
2941
- 'sampleWindow',
2942
- 'schemaVersion',
2943
- 'slice',
2944
- 'target',
2945
- ],
2946
- 'Captured metric artifact',
2947
- );
2948
- if (
2949
- capture.kind !== 'reliability-metric-capture' ||
2950
- capture.schemaVersion !== 1 ||
2951
- capture.slice !== '${name}' ||
2952
- capture.objectiveId !== objectiveId ||
2953
- !Array.isArray(capture.metricResults)
2954
- ) {
2955
- throw new Error(
2956
- 'Reliability report requires the exact captured AWS metric artifact.',
2957
- );
2958
- }
2959
- const capturedBinding = binding(capture.binding, 'capture.binding');
2960
- const activeBinding = activeDeploymentBinding(
2961
- capture.bindingArtifact,
2962
- 'capture.bindingArtifact',
2963
- );
2964
- const captureTarget = exactKeys(
2965
- capture.target,
2966
- ['account', 'region', 'slice', 'stage'],
2967
- 'capture.target',
2968
- );
2969
- const sampleWindow = exactKeys(
2970
- capture.sampleWindow,
2971
- ['durationSeconds', 'end', 'start'],
2972
- 'capture.sampleWindow',
2973
- );
2974
- const sampleStart = utc(sampleWindow.start, 'capture.sampleWindow.start');
2975
- const sampleEnd = utc(sampleWindow.end, 'capture.sampleWindow.end');
2976
- const sampleDurationSeconds =
2977
- (Date.parse(sampleEnd) - Date.parse(sampleStart)) / 1_000;
2978
- digest(capture.queryDigest, 'capture.queryDigest');
2979
- if (
2980
- !sameBinding(capturedBinding, activeBinding.binding) ||
2981
- ['account', 'region', 'slice', 'stage'].some(
2982
- (key) => captureTarget[key] !== activeBinding.target[key],
2983
- ) ||
2984
- !Number.isSafeInteger(sampleWindow.durationSeconds) ||
2985
- sampleWindow.durationSeconds !== sampleDurationSeconds ||
2986
- sampleDurationSeconds <= 0 ||
2987
- sampleDurationSeconds > 6 * 60 * 60
2988
- ) {
2989
- throw new Error(
2990
- 'Captured metric sample is not bound to the exact active deployment and bounded window.',
2991
- );
2992
- }
2993
- const result = (id, optional = false) => {
2994
- const matches = capture.metricResults.filter((entry) => entry?.id === id);
2995
- if (matches.length === 0 && optional) return 0;
2996
- if (
2997
- matches.length !== 1 ||
2998
- !Array.isArray(matches[0].timestamps) ||
2999
- !Array.isArray(matches[0].values) ||
3000
- matches[0].timestamps.length !== matches[0].values.length ||
3001
- matches[0].values.length > 1008 ||
3002
- matches[0].timestamps.some(
3003
- (value) =>
3004
- typeof value !== 'string' ||
3005
- !Number.isFinite(Date.parse(value)) ||
3006
- Date.parse(value) < Date.parse(sampleStart) ||
3007
- Date.parse(value) > Date.parse(sampleEnd),
3008
- ) ||
3009
- matches[0].values.some(
3010
- (value) => typeof value !== 'number' || !Number.isFinite(value) || value < 0,
3011
- )
3012
- ) {
3013
- throw new Error('Captured metric series ' + id + ' is absent or ambiguous.');
3014
- }
3015
- return matches[0].values.reduce((total, value) => total + value, 0);
3016
- };
3017
- const contract = validateReliabilityContract(
3018
- JSON.parse(
3019
- readFileSync(
3020
- new URL('../docs/reliability/slo.json', import.meta.url),
3021
- 'utf8',
3022
- ),
3023
- ),
3024
- );
3025
- const objective = contract.objectives.find(
3026
- ({ id }) => id === objectiveId,
3027
- );
3028
- if (!objective) throw new Error('Reliability objective is not declared.');
3029
- if (capturedBinding.workload !== objective.journey) {
3030
- throw new Error(
3031
- 'Captured metric workload does not match the declared objective journey.',
3032
- );
3033
- }
3034
- const validEvents = result('valid');
3035
- const goodEvents = result('good');
3036
- const syntheticValid = result(
3037
- 'synthetic-valid',
3038
- objective.lowTraffic.mode === 'data-insufficient',
3039
- );
3040
- const syntheticGood = result(
3041
- 'synthetic-good',
3042
- objective.lowTraffic.mode === 'data-insufficient',
3043
- );
3044
- if (
3045
- !Number.isSafeInteger(validEvents) ||
3046
- !Number.isSafeInteger(goodEvents) ||
3047
- !Number.isSafeInteger(syntheticValid) ||
3048
- !Number.isSafeInteger(syntheticGood) ||
3049
- goodEvents > validEvents ||
3050
- syntheticGood > syntheticValid
3051
- ) {
3052
- throw new Error('Captured metric counts are incompatible.');
3053
- }
3054
- const evaluation = evaluateSlo({
3055
- goodEvents,
3056
- minimumValidEvents: objective.minimumValidEvents.diagnosticSample,
3057
- objective,
3058
- ...(validEvents >= objective.minimumValidEvents.diagnosticSample
3059
- ? {}
3060
- : {
3061
- syntheticSuccess:
3062
- syntheticValid > 0 ? syntheticGood === syntheticValid : undefined,
3063
- }),
3064
- validEvents,
3065
- });
3066
- const report = {
3067
- binding: capturedBinding,
3068
- capturedMetricDigest: captured.digest,
3069
- declaredObjectiveWindow: objective.window,
3070
- kind: 'reliability-slo-diagnostic-sample',
3071
- objectiveId: objective.id,
3072
- provenance: activeBinding.target.stage,
3073
- sampleEvaluation: evaluation,
3074
- sampleWindow: {
3075
- durationSeconds: sampleDurationSeconds,
3076
- end: sampleEnd,
3077
- start: sampleStart,
3078
- },
3079
- schemaVersion: 1,
3080
- scope: 'bounded-diagnostic-sample-not-slo-window-evidence',
3081
- slice: '${name}',
3082
- };
3083
- const reference = writeImmutableArtifact(
3084
- '.ebk/evidence/reliability/slo',
3085
- report,
3086
- );
3087
- process.stdout.write(JSON.stringify({ ...reference, ...report }) + '\\n');
3088
- `,
3089
- 'scripts/collect-reliability-exercise.mjs': `import {
3090
- CloudWatchClient,
3091
- DescribeAlarmHistoryCommand,
3092
- DescribeAlarmsCommand,
3093
- } from '@aws-sdk/client-cloudwatch';
3094
- import {
3095
- DescribeExecutionCommand,
3096
- SFNClient,
3097
- } from '@aws-sdk/client-sfn';
3098
- import {
3099
- GetCallerIdentityCommand,
3100
- STSClient,
3101
- } from '@aws-sdk/client-sts';
3102
- import { readFileSync } from 'node:fs';
3103
- import {
3104
- activeDeploymentBinding,
3105
- awsPartition,
3106
- authorizedExecutionArn,
3107
- exactKeys,
3108
- readBoundedJson,
3109
- safeToken,
3110
- utc,
3111
- writeImmutableArtifact,
3112
- } from './reliability-evidence-lib.mjs';
3113
-
3114
- const inputPath =
3115
- process.env.EBK_RELIABILITY_EXERCISE_COLLECTION_INPUT_PATH?.trim();
3116
- if (!inputPath) {
3117
- throw new Error(
3118
- 'EBK_RELIABILITY_EXERCISE_COLLECTION_INPUT_PATH is required.',
3119
- );
3120
- }
3121
- const input = exactKeys(
3122
- readBoundedJson(
3123
- inputPath,
3124
- 'Reliability exercise collection input',
3125
- ).value,
3126
- [
3127
- 'alarmResourceId',
3128
- 'bindingArtifact',
3129
- 'exerciseId',
3130
- 'schemaVersion',
3131
- 'target',
3132
- 'windowEnd',
3133
- 'windowStart',
3134
- 'workflowExecutions',
3135
- ],
3136
- 'Reliability exercise collection input',
3137
- );
3138
- if (input.schemaVersion !== 1) {
3139
- throw new Error('Reliability exercise collection input is incompatible.');
3140
- }
3141
- const exerciseId = safeToken(input.exerciseId, 'exerciseId', 128);
3142
- const declaration = JSON.parse(
3143
- readFileSync(
3144
- new URL('../testing/reliability-exercises.json', import.meta.url),
3145
- 'utf8',
3146
- ),
3147
- );
3148
- const operations = JSON.parse(
3149
- readFileSync(
3150
- new URL('../operations/reliability.json', import.meta.url),
3151
- 'utf8',
3152
- ),
3153
- );
3154
- const exercise = declaration.exercises?.find(({ id }) => id === exerciseId);
3155
- if (
3156
- !exercise ||
3157
- exercise.observation?.adapter !== 'aws-cloudwatch-alarm-history-v1'
3158
- ) {
3159
- throw new Error(
3160
- 'Reliability exercise has no stable-v1 AWS collection adapter.',
3161
- );
3162
- }
3163
- const alarmResourceId = safeToken(
3164
- input.alarmResourceId,
3165
- 'alarmResourceId',
3166
- 128,
3167
- );
3168
- const alarmResource = operations.deployedAlarmResources?.find(
3169
- ({ id }) => id === alarmResourceId,
3170
- );
3171
- const dynamicMatch =
3172
- (exercise.observation.dynamicAlarmKind === 'service' &&
3173
- /^service-[a-z][a-z0-9-]*-health$/.test(alarmResourceId)) ||
3174
- (exercise.observation.dynamicAlarmKind === 'job' &&
3175
- /^job-[a-z][a-z0-9-]*-failure$/.test(alarmResourceId));
3176
- if (
3177
- !alarmResource ||
3178
- (!exercise.observation.alarmIds.includes(alarmResourceId) && !dynamicMatch)
3179
- ) {
3180
- throw new Error(
3181
- 'Reliability exercise alarm is absent or outside its declared workload.',
3182
- );
3183
- }
3184
- const target = exactKeys(
3185
- input.target,
3186
- ['account', 'region', 'slice', 'stage'],
3187
- 'target',
3188
- );
3189
- for (const key of ['account', 'region', 'slice', 'stage']) {
3190
- safeToken(target[key], 'target.' + key, 128);
3191
- }
3192
- if (target.slice !== '${name}') {
3193
- throw new Error('Reliability collection target escaped the exact Slice.');
3194
- }
3195
- const activeBinding = activeDeploymentBinding(
3196
- input.bindingArtifact,
3197
- 'bindingArtifact',
3198
- );
3199
- const collectedBinding = activeBinding.binding;
3200
- const activeResources = activeBinding.resources;
3201
- const bindingTarget = activeBinding.target;
3202
- if (
3203
- collectedBinding.workload !== exercise.workload ||
3204
- ['account', 'region', 'slice', 'stage'].some(
3205
- (key) => bindingTarget[key] !== target[key],
3206
- )
3207
- ) {
3208
- throw new Error(
3209
- 'Reliability collection deployment binding does not match the exercise target.',
3210
- );
3211
- }
3212
- const identity = await new STSClient({ region: target.region }).send(
3213
- new GetCallerIdentityCommand({}),
3214
- );
3215
- const partition = awsPartition(target.region);
3216
- if (
3217
- identity.Account !== target.account ||
3218
- !identity.Arn?.startsWith(
3219
- 'arn:' + partition + ':sts::' + target.account + ':',
3220
- )
3221
- ) {
3222
- throw new Error(
3223
- 'AWS caller identity does not match the active reliability target.',
3224
- );
3225
- }
3226
- const windowStart = utc(input.windowStart, 'windowStart');
3227
- const windowEnd = utc(input.windowEnd, 'windowEnd');
3228
- const windowMilliseconds = Date.parse(windowEnd) - Date.parse(windowStart);
3229
- if (
3230
- windowMilliseconds <= 0 ||
3231
- windowMilliseconds > 6 * 60 * 60 * 1000
3232
- ) {
3233
- throw new Error(
3234
- 'Reliability collection window must be positive and at most six hours.',
3235
- );
3236
- }
3237
- const alarmName = alarmResource.name.replace('{stage}', target.stage);
3238
- if (
3239
- !alarmName.startsWith('${name}-' + target.stage + '-') ||
3240
- alarmName.includes('{stage}') ||
3241
- !activeResources.alarmNames.includes(alarmName)
3242
- ) {
3243
- throw new Error(
3244
- 'Reliability alarm is not authorized by the protected deployment.',
3245
- );
3246
- }
3247
- const historyRequest = {
3248
- AlarmName: alarmName,
3249
- EndDate: new Date(windowEnd),
3250
- HistoryItemType: 'StateUpdate',
3251
- MaxRecords: 32,
3252
- ScanBy: 'TimestampAscending',
3253
- StartDate: new Date(windowStart),
3254
- };
3255
- const stateRequest = {
3256
- AlarmNames: [alarmName],
3257
- MaxRecords: 1,
3258
- };
3259
- const cloudwatch = new CloudWatchClient({ region: target.region });
3260
- const historyResponse = await cloudwatch.send(
3261
- new DescribeAlarmHistoryCommand(historyRequest),
3262
- );
3263
- const stateResponse = await cloudwatch.send(
3264
- new DescribeAlarmsCommand(stateRequest),
3265
- );
3266
- if (historyResponse.NextToken || stateResponse.NextToken) {
3267
- throw new Error('Reliability alarm collection exceeded its page bound.');
3268
- }
3269
- const boundedText = (value, label, maximum = 2048) => {
3270
- if (
3271
- typeof value !== 'string' ||
3272
- value.length < 1 ||
3273
- value.length > maximum ||
3274
- [...value].some((character) => {
3275
- const code = character.charCodeAt(0);
3276
- return code < 9 || (code > 13 && code < 32) || code === 127;
3277
- })
3278
- ) {
3279
- throw new Error(label + ' is not bounded provider metadata.');
3280
- }
3281
- return value;
3282
- };
3283
- const requestId = safeToken(
3284
- historyResponse.$metadata?.requestId,
3285
- 'alarmHistory.requestId',
3286
- 128,
3287
- );
3288
- const stateRequestId = safeToken(
3289
- stateResponse.$metadata?.requestId,
3290
- 'alarmState.requestId',
3291
- 128,
3292
- );
3293
- const historyItems = (historyResponse.AlarmHistoryItems ?? []).map(
3294
- (item, index) => {
3295
- const historyData = boundedText(
3296
- item.HistoryData,
3297
- 'alarmHistory[' + index + '].historyData',
3298
- 4096,
3299
- );
3300
- let parsed;
3301
- try {
3302
- parsed = JSON.parse(historyData);
3303
- } catch {
3304
- throw new Error('Alarm history state data is not valid JSON.');
3305
- }
3306
- const state = parsed?.newState?.stateValue;
3307
- if (!['ALARM', 'INSUFFICIENT_DATA', 'OK'].includes(state)) {
3308
- throw new Error('Alarm history contains an unsupported state.');
3309
- }
3310
- const timestamp = utc(
3311
- item.Timestamp?.toISOString?.(),
3312
- 'alarmHistory[' + index + '].timestamp',
3313
- );
3314
- if (
3315
- Date.parse(timestamp) < Date.parse(windowStart) ||
3316
- Date.parse(timestamp) > Date.parse(windowEnd) ||
3317
- item.AlarmName !== alarmName ||
3318
- item.HistoryItemType !== 'StateUpdate'
3319
- ) {
3320
- throw new Error('Alarm history escaped the exact collection request.');
3321
- }
3322
- return {
3323
- alarmName,
3324
- historyData,
3325
- historyItemType: item.HistoryItemType,
3326
- historySummary: boundedText(
3327
- item.HistorySummary,
3328
- 'alarmHistory[' + index + '].historySummary',
3329
- ),
3330
- state,
3331
- timestamp,
3332
- };
3333
- },
3334
- );
3335
- const failureIndex = historyItems.findIndex(({ state }) => state === 'ALARM');
3336
- const recoveryIndex = historyItems.findIndex(
3337
- ({ state }, index) => index > failureIndex && state === 'OK',
3338
- );
3339
- if (failureIndex < 0 || recoveryIndex < 0) {
3340
- throw new Error(
3341
- 'Alarm history does not independently prove failure followed by recovery.',
3342
- );
3343
- }
3344
- const alarm = stateResponse.MetricAlarms?.[0];
3345
- const alarmArn =
3346
- 'arn:' +
3347
- partition +
3348
- ':cloudwatch:' +
3349
- target.region +
3350
- ':' +
3351
- target.account +
3352
- ':alarm:' +
3353
- alarmName;
3354
- let description;
3355
- try {
3356
- description = JSON.parse(alarm?.AlarmDescription ?? 'null');
3357
- } catch {
3358
- throw new Error('Reliability alarm description is not valid metadata.');
3359
- }
3360
- if (
3361
- stateResponse.MetricAlarms?.length !== 1 ||
3362
- alarm?.AlarmArn !== alarmArn ||
3363
- alarm?.AlarmName !== alarmName ||
3364
- alarm?.StateValue !== 'OK' ||
3365
- description?.id !== alarmResource.id ||
3366
- description?.slice !== '${name}' ||
3367
- description?.schemaVersion !== 1
3368
- ) {
3369
- throw new Error(
3370
- 'Reliability alarm response does not match the exact declared resource.',
3371
- );
3372
- }
3373
- const workflowInputs = input.workflowExecutions ?? [];
3374
- if (
3375
- !Array.isArray(workflowInputs) ||
3376
- workflowInputs.length > 2 ||
3377
- (exercise.observation.workflowMetadata === 'required' &&
3378
- workflowInputs.length !== 2) ||
3379
- (exercise.observation.workflowMetadata === 'none' &&
3380
- workflowInputs.length !== 0)
3381
- ) {
3382
- throw new Error(
3383
- 'Reliability workflow provenance is absent or outside its declared bound.',
3384
- );
3385
- }
3386
- const workflowExecutions = [];
3387
- for (const [index, workflowInput] of workflowInputs.entries()) {
3388
- const workflow = exactKeys(
3389
- workflowInput,
3390
- ['executionArn', 'role'],
3391
- 'workflowExecutions[' + index + ']',
3392
- );
3393
- if (
3394
- !['failure', 'recovery'].includes(workflow.role) ||
3395
- workflowInputs.filter(({ role }) => role === workflow.role).length !== 1
3396
- ) {
3397
- throw new Error('Reliability workflow roles must be exact and unique.');
3398
- }
3399
- const executionArn = safeToken(
3400
- workflow.executionArn,
3401
- 'workflowExecutions[' + index + '].executionArn',
3402
- 512,
3403
- );
3404
- if (!authorizedExecutionArn(activeResources, executionArn)) {
3405
- throw new Error(
3406
- 'Reliability workflow is not authorized by the protected deployment.',
3407
- );
3408
- }
3409
- const workflowRequest = {
3410
- executionArn,
3411
- includedData: 'METADATA_ONLY',
3412
- };
3413
- const response = await new SFNClient({ region: target.region }).send(
3414
- new DescribeExecutionCommand(workflowRequest),
3415
- );
3416
- const expectedStatuses =
3417
- workflow.role === 'failure'
3418
- ? ['ABORTED', 'FAILED', 'TIMED_OUT']
3419
- : ['SUCCEEDED'];
3420
- if (
3421
- response.executionArn !== executionArn ||
3422
- !activeResources.stateMachineArns.includes(response.stateMachineArn) ||
3423
- !expectedStatuses.includes(response.status)
3424
- ) {
3425
- throw new Error(
3426
- 'Reliability workflow response does not prove the declared outcome.',
3427
- );
3428
- }
3429
- workflowExecutions.push({
3430
- request: workflowRequest,
3431
- response: {
3432
- executionArn: response.executionArn,
3433
- requestId: safeToken(
3434
- response.$metadata?.requestId,
3435
- 'workflow.requestId',
3436
- 128,
3437
- ),
3438
- startDate: utc(
3439
- response.startDate?.toISOString?.(),
3440
- 'workflow.startDate',
3441
- ),
3442
- stateMachineArn: response.stateMachineArn,
3443
- status: response.status,
3444
- stopDate: utc(
3445
- response.stopDate?.toISOString?.(),
3446
- 'workflow.stopDate',
3447
- ),
3448
- },
3449
- role: workflow.role,
3450
- });
3451
- }
3452
- const failure = historyItems[failureIndex];
3453
- const recovery = historyItems[recoveryIndex];
3454
- const collection = {
3455
- alarm: {
3456
- alarmArn,
3457
- alarmName,
3458
- currentState: alarm.StateValue,
3459
- description,
3460
- },
3461
- binding: collectedBinding,
3462
- bindingArtifact: {
3463
- digest: activeBinding.digest,
3464
- path: activeBinding.path,
3465
- },
3466
- exerciseId,
3467
- kind: 'reliability-exercise-aws-collection',
3468
- requests: {
3469
- alarmHistory: {
3470
- ...historyRequest,
3471
- EndDate: windowEnd,
3472
- StartDate: windowStart,
3473
- },
3474
- alarmState: stateRequest,
3475
- },
3476
- responses: {
3477
- alarmHistory: {
3478
- items: historyItems,
3479
- requestId,
3480
- },
3481
- alarmState: {
3482
- requestId: stateRequestId,
3483
- state: alarm.StateValue,
3484
- },
3485
- workflowExecutions,
3486
- },
3487
- schemaVersion: 1,
3488
- slice: '${name}',
3489
- target,
3490
- transitions: {
3491
- failure: { state: failure.state, timestamp: failure.timestamp },
3492
- recovery: { state: recovery.state, timestamp: recovery.timestamp },
3493
- },
3494
- workload: exercise.workload,
3495
- };
3496
- const collectionArtifact = writeImmutableArtifact(
3497
- '.ebk/evidence/reliability/collections',
3498
- collection,
3499
- );
3500
- const observation = (role, transition, status) => ({
3501
- binding: collectedBinding,
3502
- capturedAt: transition.timestamp,
3503
- evidenceId:
3504
- exerciseId + '-' + role + '-' + collectionArtifact.digest.slice(0, 16),
3505
- exerciseId,
3506
- kind: 'reliability-exercise-' + role,
3507
- producer: {
3508
- adapter: 'aws-cloudwatch-alarm-history-v1',
3509
- collectionArtifact,
3510
- requestId,
3511
- resource: alarmArn,
3512
- },
3513
- schemaVersion: 1,
3514
- slice: '${name}',
3515
- status,
3516
- workload: exercise.workload,
3517
- });
3518
- const failureArtifact = writeImmutableArtifact(
3519
- '.ebk/evidence/reliability/exercise-inputs',
3520
- observation('failure', failure, 'observed'),
3521
- );
3522
- const recoveryArtifact = writeImmutableArtifact(
3523
- '.ebk/evidence/reliability/exercise-inputs',
3524
- observation(
3525
- 'recovery',
3526
- recovery,
3527
- exercise.workload === 'alert-delivery' ? 'unsupported' : 'verified',
3528
- ),
3529
- );
3530
- process.stdout.write(
3531
- JSON.stringify({
3532
- collection: collectionArtifact,
3533
- failure: failureArtifact,
3534
- kind: 'reliability-exercise-collection-result',
3535
- recovery: recoveryArtifact,
3536
- schemaVersion: 1,
3537
- }) + '\\n',
3538
- );
3539
- `,
3540
- 'scripts/reliability-exercise-report.mjs': `import { readFileSync } from 'node:fs';
3541
- import {
3542
- activeDeploymentBinding,
3543
- artifactReference,
3544
- binding,
3545
- exactKeys,
3546
- readBoundedJson,
3547
- safeToken,
3548
- sameBinding,
3549
- utc,
3550
- writeImmutableArtifact,
3551
- } from './reliability-evidence-lib.mjs';
3552
-
3553
- const inputPath = process.env.EBK_RELIABILITY_EXERCISE_INPUT_PATH?.trim();
3554
- if (!inputPath) {
3555
- throw new Error('EBK_RELIABILITY_EXERCISE_INPUT_PATH is required.');
3556
- }
3557
- const inputArtifact = readBoundedJson(
3558
- inputPath,
3559
- 'Reliability exercise report input',
3560
- );
3561
- const input = exactKeys(
3562
- inputArtifact.value,
3563
- ['artifacts', 'binding', 'exerciseId', 'schemaVersion'],
3564
- 'Reliability exercise report input',
3565
- );
3566
- const declaration = JSON.parse(
3567
- readFileSync(
3568
- new URL('../testing/reliability-exercises.json', import.meta.url),
3569
- 'utf8',
3570
- ),
3571
- );
3572
- if (input.schemaVersion !== 1) {
3573
- throw new Error('Reliability exercise report input is incompatible.');
3574
- }
3575
- const exerciseId = safeToken(input.exerciseId, 'exerciseId', 128);
3576
- const exercise = declaration.exercises?.find(
3577
- ({ id }) => id === exerciseId,
3578
- );
3579
- if (!exercise) {
3580
- throw new Error('Reliability exercise is undeclared or incomplete.');
3581
- }
3582
- const reportBinding = binding(input.binding, 'binding');
3583
- if (reportBinding.workload !== exercise.workload) {
3584
- throw new Error('Reliability exercise workload binding does not match.');
3585
- }
3586
- const references = exactKeys(
3587
- input.artifacts,
3588
- ['cleanup', 'failure', 'postconditions', 'recovery'],
3589
- 'artifacts',
3590
- );
3591
- const roles = ['failure', 'recovery', 'postconditions', 'cleanup'];
3592
- const statuses = {
3593
- cleanup: 'complete',
3594
- failure: 'observed',
3595
- postconditions: 'passed',
3596
- recovery:
3597
- exercise.workload === 'alert-delivery' ? 'unsupported' : 'verified',
3598
- };
3599
- const evidence = {};
3600
- const collectionDigests = [];
3601
- let protectedStage;
3602
- let previous = 0;
3603
- for (const role of roles) {
3604
- const reference = artifactReference(references[role], 'artifacts.' + role);
3605
- const artifact = exactKeys(
3606
- reference.value,
3607
- [
3608
- 'binding',
3609
- 'capturedAt',
3610
- 'checks',
3611
- 'evidenceId',
3612
- 'exerciseId',
3613
- 'kind',
3614
- 'producer',
3615
- 'schemaVersion',
3616
- 'slice',
3617
- 'status',
3618
- 'workload',
3619
- ],
3620
- role + ' artifact',
3621
- );
3622
- const artifactBinding = binding(artifact.binding, role + '.binding');
3623
- const producer = exactKeys(
3624
- artifact.producer,
3625
- role === 'failure' || role === 'recovery'
3626
- ? ['adapter', 'collectionArtifact', 'requestId', 'resource']
3627
- : ['kind', 'requestId', 'resource'],
3628
- role + '.producer',
3629
- );
3630
- const capturedAt = Date.parse(utc(artifact.capturedAt, role + '.capturedAt'));
3631
- if (
3632
- artifact.schemaVersion !== 1 ||
3633
- artifact.kind !== 'reliability-exercise-' + role ||
3634
- artifact.exerciseId !== exercise.id ||
3635
- artifact.slice !== '${name}' ||
3636
- artifact.workload !== exercise.workload ||
3637
- !sameBinding(reportBinding, artifactBinding) ||
3638
- capturedAt < previous ||
3639
- !safeToken(artifact.evidenceId, role + '.evidenceId', 128) ||
3640
- !safeToken(producer.requestId, role + '.producer.requestId', 128) ||
3641
- !safeToken(producer.resource, role + '.producer.resource', 512)
3642
- ) {
3643
- throw new Error(
3644
- 'Reliability exercise artifact is fabricated, cross-paired, or unsanitized.',
3645
- );
3646
- }
3647
- previous = capturedAt;
3648
- if (role === 'failure' || role === 'recovery') {
3649
- if (producer.adapter !== 'aws-cloudwatch-alarm-history-v1') {
3650
- throw new Error(
3651
- 'Failure and recovery require the generated AWS collection adapter.',
3652
- );
3653
- }
3654
- const collectionReference = artifactReference(
3655
- producer.collectionArtifact,
3656
- role + '.producer.collectionArtifact',
3657
- );
3658
- const collection = exactKeys(
3659
- collectionReference.value,
3660
- [
3661
- 'alarm',
3662
- 'binding',
3663
- 'bindingArtifact',
3664
- 'exerciseId',
3665
- 'kind',
3666
- 'requests',
3667
- 'responses',
3668
- 'schemaVersion',
3669
- 'slice',
3670
- 'target',
3671
- 'transitions',
3672
- 'workload',
3673
- ],
3674
- role + ' collection',
3675
- );
3676
- const collectionBinding = binding(
3677
- collection.binding,
3678
- role + '.collection.binding',
3679
- );
3680
- const collectionActiveBinding = activeDeploymentBinding(
3681
- collection.bindingArtifact,
3682
- role + '.collection.bindingArtifact',
3683
- );
3684
- const alarm = exactKeys(
3685
- collection.alarm,
3686
- ['alarmArn', 'alarmName', 'currentState', 'description'],
3687
- role + '.collection.alarm',
3688
- );
3689
- const requests = exactKeys(
3690
- collection.requests,
3691
- ['alarmHistory', 'alarmState'],
3692
- role + '.collection.requests',
3693
- );
3694
- const responses = exactKeys(
3695
- collection.responses,
3696
- ['alarmHistory', 'alarmState', 'workflowExecutions'],
3697
- role + '.collection.responses',
3698
- );
3699
- const alarmHistoryRequest = exactKeys(
3700
- requests.alarmHistory,
3701
- [
3702
- 'AlarmName',
3703
- 'EndDate',
3704
- 'HistoryItemType',
3705
- 'MaxRecords',
3706
- 'ScanBy',
3707
- 'StartDate',
3708
- ],
3709
- role + '.collection.requests.alarmHistory',
3710
- );
3711
- const alarmStateRequest = exactKeys(
3712
- requests.alarmState,
3713
- ['AlarmNames', 'MaxRecords'],
3714
- role + '.collection.requests.alarmState',
3715
- );
3716
- const alarmHistoryResponse = exactKeys(
3717
- responses.alarmHistory,
3718
- ['items', 'requestId'],
3719
- role + '.collection.responses.alarmHistory',
3720
- );
3721
- const alarmStateResponse = exactKeys(
3722
- responses.alarmState,
3723
- ['requestId', 'state'],
3724
- role + '.collection.responses.alarmState',
3725
- );
3726
- const collectionTarget = exactKeys(
3727
- collection.target,
3728
- ['account', 'region', 'slice', 'stage'],
3729
- role + '.collection.target',
3730
- );
3731
- const transitions = exactKeys(
3732
- collection.transitions,
3733
- ['failure', 'recovery'],
3734
- role + '.collection.transitions',
3735
- );
3736
- const transition = exactKeys(
3737
- transitions[role],
3738
- ['state', 'timestamp'],
3739
- role + '.collection.transitions.' + role,
3740
- );
3741
- if (
3742
- !Array.isArray(alarmHistoryResponse.items) ||
3743
- !Array.isArray(responses.workflowExecutions)
3744
- ) {
3745
- throw new Error(
3746
- 'Reliability collection responses are outside their bounded shape.',
3747
- );
3748
- }
3749
- const historyStates = alarmHistoryResponse.items.map((item, index) => {
3750
- const historyItem = exactKeys(
3751
- item,
3752
- [
3753
- 'alarmName',
3754
- 'historyData',
3755
- 'historyItemType',
3756
- 'historySummary',
3757
- 'state',
3758
- 'timestamp',
3759
- ],
3760
- role + '.collection.responses.alarmHistory.items[' + index + ']',
3761
- );
3762
- if (
3763
- historyItem.alarmName !== alarm.alarmName ||
3764
- historyItem.historyItemType !== 'StateUpdate' ||
3765
- !['ALARM', 'INSUFFICIENT_DATA', 'OK'].includes(historyItem.state) ||
3766
- !utc(
3767
- historyItem.timestamp,
3768
- role + '.collection.responses.alarmHistory.items.timestamp',
3769
- ) ||
3770
- typeof historyItem.historyData !== 'string' ||
3771
- historyItem.historyData.length > 4096 ||
3772
- typeof historyItem.historySummary !== 'string' ||
3773
- historyItem.historySummary.length > 2048
3774
- ) {
3775
- throw new Error(
3776
- 'Reliability collection contains incompatible alarm history.',
3777
- );
3778
- }
3779
- return {
3780
- state: historyItem.state,
3781
- timestamp: historyItem.timestamp,
3782
- };
3783
- });
3784
- const failureHistoryIndex = historyStates.findIndex(
3785
- ({ state }) => state === 'ALARM',
3786
- );
3787
- const recoveryHistoryIndex = historyStates.findIndex(
3788
- ({ state }, index) =>
3789
- index > failureHistoryIndex && state === 'OK',
3790
- );
3791
- for (const [index, workflowEntry] of
3792
- responses.workflowExecutions.entries()) {
3793
- const workflow = exactKeys(
3794
- workflowEntry,
3795
- ['request', 'response', 'role'],
3796
- role + '.collection.responses.workflowExecutions[' + index + ']',
3797
- );
3798
- const workflowRequest = exactKeys(
3799
- workflow.request,
3800
- ['executionArn', 'includedData'],
3801
- role + '.collection.responses.workflowExecutions.request',
3802
- );
3803
- const workflowResponse = exactKeys(
3804
- workflow.response,
3805
- [
3806
- 'executionArn',
3807
- 'requestId',
3808
- 'startDate',
3809
- 'stateMachineArn',
3810
- 'status',
3811
- 'stopDate',
3812
- ],
3813
- role + '.collection.responses.workflowExecutions.response',
3814
- );
3815
- if (
3816
- !['failure', 'recovery'].includes(workflow.role) ||
3817
- workflowRequest.includedData !== 'METADATA_ONLY' ||
3818
- workflowRequest.executionArn !== workflowResponse.executionArn ||
3819
- !safeToken(
3820
- workflowResponse.requestId,
3821
- role + '.collection.responses.workflow.requestId',
3822
- 128,
3823
- ) ||
3824
- (workflow.role === 'failure'
3825
- ? !['ABORTED', 'FAILED', 'TIMED_OUT'].includes(
3826
- workflowResponse.status,
3827
- )
3828
- : workflowResponse.status !== 'SUCCEEDED')
3829
- ) {
3830
- throw new Error(
3831
- 'Reliability collection workflow provenance is incompatible.',
3832
- );
3833
- }
3834
- }
3835
- if (
3836
- collection.kind !== 'reliability-exercise-aws-collection' ||
3837
- collection.schemaVersion !== 1 ||
3838
- collection.exerciseId !== exercise.id ||
3839
- collection.slice !== '${name}' ||
3840
- collection.workload !== exercise.workload ||
3841
- !sameBinding(reportBinding, collectionBinding) ||
3842
- !sameBinding(collectionBinding, collectionActiveBinding.binding) ||
3843
- alarm.currentState !== 'OK' ||
3844
- alarmStateResponse.state !== 'OK' ||
3845
- !safeToken(
3846
- alarmStateResponse.requestId,
3847
- role + '.collection.responses.alarmState.requestId',
3848
- 128,
3849
- ) ||
3850
- alarm.alarmArn !== producer.resource ||
3851
- collectionTarget.slice !== '${name}' ||
3852
- ['account', 'region', 'slice', 'stage'].some(
3853
- (key) =>
3854
- collectionTarget[key] !==
3855
- collectionActiveBinding.target[key],
3856
- ) ||
3857
- !safeToken(
3858
- collectionTarget.account,
3859
- role + '.collection.target.account',
3860
- 128,
3861
- ) ||
3862
- !safeToken(
3863
- collectionTarget.region,
3864
- role + '.collection.target.region',
3865
- 128,
3866
- ) ||
3867
- !safeToken(
3868
- collectionTarget.stage,
3869
- role + '.collection.target.stage',
3870
- 128,
3871
- ) ||
3872
- alarmHistoryRequest.AlarmName !== alarm.alarmName ||
3873
- alarmHistoryRequest.HistoryItemType !== 'StateUpdate' ||
3874
- alarmHistoryRequest.MaxRecords !== 32 ||
3875
- alarmHistoryRequest.ScanBy !== 'TimestampAscending' ||
3876
- !Array.isArray(alarmStateRequest.AlarmNames) ||
3877
- alarmStateRequest.AlarmNames.length !== 1 ||
3878
- alarmStateRequest.AlarmNames[0] !== alarm.alarmName ||
3879
- alarmStateRequest.MaxRecords !== 1 ||
3880
- alarmHistoryResponse.requestId !== producer.requestId ||
3881
- alarmHistoryResponse.items.length < 2 ||
3882
- failureHistoryIndex < 0 ||
3883
- recoveryHistoryIndex < 0 ||
3884
- transitions.failure.timestamp !==
3885
- historyStates[failureHistoryIndex].timestamp ||
3886
- transitions.recovery.timestamp !==
3887
- historyStates[recoveryHistoryIndex].timestamp ||
3888
- transition.timestamp !== artifact.capturedAt ||
3889
- transition.state !== (role === 'failure' ? 'ALARM' : 'OK')
3890
- ) {
3891
- throw new Error(
3892
- 'Reliability collection request, response, resource, or transition is cross-paired.',
3893
- );
3894
- }
3895
- if (
3896
- protectedStage !== undefined &&
3897
- protectedStage !== collectionActiveBinding.target.stage
3898
- ) {
3899
- throw new Error(
3900
- 'Reliability exercise collections crossed protected stages.',
3901
- );
3902
- }
3903
- protectedStage = collectionActiveBinding.target.stage;
3904
- collectionDigests.push(collectionReference.digest);
3905
- } else if (producer.kind !== 'testing-evidence') {
3906
- throw new Error(
3907
- 'Postconditions and cleanup require testing-evidence provenance.',
3908
- );
3909
- }
3910
- if (artifact.status !== statuses[role]) {
3911
- throw new Error('Reliability exercise artifact status is incompatible.');
3912
- }
3913
- if (role === 'postconditions') {
3914
- if (
3915
- !Array.isArray(artifact.checks) ||
3916
- artifact.checks.length !== exercise.postconditions.length ||
3917
- artifact.checks.some(
3918
- (check, index) =>
3919
- check !== 'postcondition-' + String(index + 1) + '-passed',
3920
- )
3921
- ) {
3922
- throw new Error(
3923
- 'Reliability exercise postcondition artifact is incomplete.',
3924
- );
3925
- }
3926
- } else if (artifact.checks !== undefined) {
3927
- throw new Error('Only the postcondition artifact may contain checks.');
3928
- }
3929
- evidence[role] = reference.digest;
3930
- }
3931
- if (
3932
- collectionDigests.length !== 2 ||
3933
- new Set(collectionDigests).size !== 1 ||
3934
- !['staging', 'production'].includes(protectedStage)
3935
- ) {
3936
- throw new Error(
3937
- 'Failure and recovery must come from one independently collected AWS transition chain.',
3938
- );
3939
- }
3940
- if (new Set(Object.values(evidence)).size !== roles.length) {
3941
- throw new Error('Reliability exercise artifacts must be independently captured.');
3942
- }
3943
- const report = {
3944
- artifacts: evidence,
3945
- binding: reportBinding,
3946
- ...(exercise.workload === 'alert-delivery'
3947
- ? { alertDelivery: { state: artifactReference(
3948
- references.recovery,
3949
- 'artifacts.recovery',
3950
- ).value.status } }
3951
- : {}),
3952
- exerciseId: exercise.id,
3953
- kind: 'reliability-failure-recovery-evidence',
3954
- provenance: protectedStage,
3955
- schemaVersion: 1,
3956
- slice: '${name}',
3957
- workload: exercise.workload,
3958
- };
3959
- const reference = writeImmutableArtifact(
3960
- '.ebk/evidence/reliability/exercises',
3961
- report,
3962
- );
3963
- process.stdout.write(JSON.stringify({ ...reference, ...report }) + '\\n');
3964
- `,
3965
- 'scripts/reliability-diagnostic.mjs': `import {
3966
- CloudWatchClient,
3967
- DescribeAlarmsCommand,
3968
- GetMetricDataCommand,
3969
- } from '@aws-sdk/client-cloudwatch';
3970
- import {
3971
- DescribeServicesCommand,
3972
- ECSClient,
3973
- } from '@aws-sdk/client-ecs';
3974
- import {
3975
- DescribeExecutionCommand,
3976
- SFNClient,
3977
- } from '@aws-sdk/client-sfn';
3978
- import {
3979
- GetCallerIdentityCommand,
3980
- STSClient,
3981
- } from '@aws-sdk/client-sts';
3982
- import { readFileSync } from 'node:fs';
3983
- import {
3984
- authorizeDiagnostic,
3985
- validateReliabilityContract,
3986
- } from '@empire-builder-kit/runtime/reliability';
3987
- import {
3988
- activeDeploymentBinding,
3989
- awsPartition,
3990
- authorizedExecutionArn,
3991
- exactKeys,
3992
- readBoundedJson,
3993
- safeToken,
3994
- sha256,
3995
- utc,
3996
- writeImmutableArtifact,
3997
- } from './reliability-evidence-lib.mjs';
3998
-
3999
- const inputPath = process.env.EBK_RELIABILITY_DIAGNOSTIC_INPUT_PATH?.trim();
4000
- if (!inputPath) {
4001
- throw new Error('EBK_RELIABILITY_DIAGNOSTIC_INPUT_PATH is required.');
4002
- }
4003
- const requestInput = readBoundedJson(inputPath, 'Reliability diagnostic input');
4004
- const request = exactKeys(
4005
- requestInput.value,
4006
- ['approval', 'bindingArtifact', 'query', 'source', 'target'],
4007
- 'Reliability diagnostic input',
4008
- );
4009
- const plan = authorizeDiagnostic({
4010
- ...(request.approval === undefined ? {} : { approval: request.approval }),
4011
- source: request.source,
4012
- target: request.target,
4013
- });
4014
- if (plan.approvalRequired) {
4015
- process.stdout.write(JSON.stringify({
4016
- approvalRequired: true,
4017
- expiresAt: plan.expiresAt,
4018
- queryClass: plan.queryClass,
4019
- source: plan.source,
4020
- target: plan.target,
4021
- }) + '\\n');
4022
- process.exit(0);
4023
- }
4024
- const activeBinding = activeDeploymentBinding(
4025
- request.bindingArtifact,
4026
- 'bindingArtifact',
4027
- );
4028
- const capturedBinding = activeBinding.binding;
4029
- const activeResources = activeBinding.resources;
4030
- const bindingTarget = activeBinding.target;
4031
- if (
4032
- bindingTarget.account !== plan.target.account ||
4033
- bindingTarget.region !== plan.target.region ||
4034
- bindingTarget.slice !== plan.target.slice ||
4035
- bindingTarget.stage !== plan.target.stage
4036
- ) {
4037
- throw new Error(
4038
- 'Reliability diagnostic deployment binding does not match the exact target.',
4039
- );
4040
- }
4041
- if (plan.source === 'alarm-state') {
4042
- const query = exactKeys(request.query, ['alarmNames'], 'alarm-state query');
4043
- if (
4044
- !Array.isArray(query.alarmNames) ||
4045
- query.alarmNames.some(
4046
- (value) =>
4047
- !activeResources.alarmNames.includes(
4048
- safeToken(value, 'alarm-state alarm', 255),
4049
- ),
4050
- )
4051
- ) {
4052
- throw new Error(
4053
- 'Alarm-state query is not authorized by the protected deployment.',
4054
- );
4055
- }
4056
- }
4057
- if (
4058
- plan.source === 'sanitized-signal' &&
4059
- request.query?.apiId !== undefined &&
4060
- safeToken(request.query.apiId, 'apiId', 128) !== activeResources.apiId
4061
- ) {
4062
- throw new Error(
4063
- 'Metric query API is not authorized by the protected deployment.',
4064
- );
4065
- }
4066
- if (plan.source === 'resource-metadata') {
4067
- const query = exactKeys(
4068
- request.query,
4069
- ['ecsServices', 'executions'],
4070
- 'resource-metadata query',
4071
- );
4072
- if (!Array.isArray(query.ecsServices) || !Array.isArray(query.executions)) {
4073
- throw new Error(
4074
- 'Resource query is not authorized by the protected deployment.',
4075
- );
4076
- }
4077
- for (const [index, value] of query.ecsServices.entries()) {
4078
- const requested = exactKeys(
4079
- value,
4080
- ['cluster', 'services'],
4081
- 'ecsServices[' + index + ']',
4082
- );
4083
- const cluster = safeToken(
4084
- requested.cluster,
4085
- 'ecsServices[' + index + '].cluster',
4086
- 512,
4087
- );
4088
- const authorized = activeResources.ecsServices.find(
4089
- (entry) => entry.cluster === cluster,
4090
- );
4091
- if (
4092
- !authorized ||
4093
- !Array.isArray(requested.services) ||
4094
- requested.services.some(
4095
- (service) =>
4096
- !authorized.services.includes(
4097
- safeToken(service, 'ecsServices.service', 255),
4098
- ),
4099
- )
4100
- ) {
4101
- throw new Error(
4102
- 'ECS query is not authorized by the protected deployment.',
4103
- );
4104
- }
4105
- }
4106
- for (const [index, value] of query.executions.entries()) {
4107
- const executionArn = safeToken(value, 'executions[' + index + ']', 512);
4108
- if (!authorizedExecutionArn(activeResources, executionArn)) {
4109
- throw new Error(
4110
- 'Step Functions query is not authorized by the protected deployment.',
4111
- );
4112
- }
4113
- }
4114
- }
4115
- const region = plan.target.region;
4116
- const partition = awsPartition(region);
4117
- const identity = await new STSClient({ region }).send(
4118
- new GetCallerIdentityCommand({}),
4119
- );
4120
- if (
4121
- identity.Account !== plan.target.account ||
4122
- !identity.Arn?.startsWith(
4123
- 'arn:' + partition + ':sts::' + plan.target.account + ':',
4124
- )
4125
- ) {
4126
- throw new Error(
4127
- 'AWS caller identity does not match the active reliability target.',
4128
- );
4129
- }
4130
- const capture = async (value, directory) => {
4131
- const reference = writeImmutableArtifact(directory, value);
4132
- process.stdout.write(JSON.stringify({ ...reference, ...value }) + '\\n');
4133
- };
4134
- if (plan.source === 'alarm-state') {
4135
- const query = exactKeys(request.query, ['alarmNames'], 'alarm-state query');
4136
- if (
4137
- !Array.isArray(query.alarmNames) ||
4138
- query.alarmNames.length < 1 ||
4139
- query.alarmNames.length > 32 ||
4140
- new Set(query.alarmNames).size !== query.alarmNames.length
4141
- ) {
4142
- throw new Error('Alarm-state query must name one to 32 exact alarms.');
4143
- }
4144
- const alarmNames = query.alarmNames.map((value, index) =>
4145
- safeToken(value, 'alarmNames[' + index + ']', 255),
4146
- );
4147
- if (
4148
- alarmNames.some(
4149
- (value) => !value.startsWith('${name}-' + plan.target.stage + '-'),
4150
- )
4151
- ) {
4152
- throw new Error('Alarm-state query escaped the exact Slice and stage.');
4153
- }
4154
- const response = await new CloudWatchClient({ region }).send(
4155
- new DescribeAlarmsCommand({
4156
- AlarmNames: alarmNames,
4157
- MaxRecords: alarmNames.length,
4158
- }),
4159
- );
4160
- if (response.NextToken) {
4161
- throw new Error('Alarm-state query exceeded its one-page bound.');
4162
- }
4163
- const alarms = (response.MetricAlarms ?? []).map((alarm) => ({
4164
- actionsEnabled: alarm.ActionsEnabled ?? null,
4165
- alarmArn: alarm.AlarmArn ?? null,
4166
- alarmName: alarm.AlarmName ?? null,
4167
- stateUpdatedTimestamp:
4168
- alarm.StateUpdatedTimestamp?.toISOString?.() ?? null,
4169
- stateValue: alarm.StateValue ?? null,
4170
- }));
4171
- if (
4172
- alarms.length !== alarmNames.length ||
4173
- new Set(alarms.map(({ alarmName }) => alarmName)).size !== alarms.length ||
4174
- alarms.some(
4175
- ({ alarmArn, alarmName }) =>
4176
- !alarmNames.includes(alarmName) ||
4177
- !alarmArn?.startsWith(
4178
- 'arn:' +
4179
- partition +
4180
- ':cloudwatch:' +
4181
- region +
4182
- ':' +
4183
- plan.target.account +
4184
- ':alarm:',
4185
- ),
4186
- )
4187
- ) {
4188
- throw new Error('AWS alarm response did not match the exact query target.');
4189
- }
4190
- await capture(
4191
- {
4192
- alarms,
4193
- binding: capturedBinding,
4194
- bindingDigest: activeBinding.digest,
4195
- capturedAt: new Date().toISOString(),
4196
- kind: 'reliability-alarm-capture',
4197
- schemaVersion: 1,
4198
- slice: '${name}',
4199
- target: plan.target,
4200
- },
4201
- '.ebk/evidence/reliability/diagnostics',
4202
- );
4203
- process.exit(0);
4204
- }
4205
- if (plan.source === 'sanitized-signal') {
4206
- const query = exactKeys(
4207
- request.query,
4208
- ['apiId', 'endTime', 'objectiveId', 'startTime'],
4209
- 'sanitized-signal query',
4210
- );
4211
- const objectiveId = safeToken(query.objectiveId, 'objectiveId', 128);
4212
- const contract = validateReliabilityContract(
4213
- JSON.parse(
4214
- readFileSync(
4215
- new URL('../docs/reliability/slo.json', import.meta.url),
4216
- 'utf8',
4217
- ),
4218
- ),
4219
- );
4220
- const objective = contract.objectives.find(({ id }) => id === objectiveId);
4221
- if (!objective || capturedBinding.workload !== objective.journey) {
4222
- throw new Error(
4223
- 'Metric query workload does not match the exact objective journey.',
4224
- );
4225
- }
4226
- const startTime = utc(query.startTime, 'startTime');
4227
- const endTime = utc(query.endTime, 'endTime');
4228
- const elapsed = Date.parse(endTime) - Date.parse(startTime);
4229
- if (elapsed <= 0 || elapsed > 6 * 60 * 60 * 1000) {
4230
- throw new Error('Metric query window must be positive and at most six hours.');
4231
- }
4232
- const dimensions = [
4233
- { Name: 'Component', Value: 'next-server' },
4234
- { Name: 'Feature', Value: objective.feature },
4235
- { Name: 'Operation', Value: 'request' },
4236
- { Name: 'Slice', Value: '${name}' },
4237
- { Name: 'Stage', Value: plan.target.stage },
4238
- ];
4239
- const metric = (id, metricName, metricDimensions = dimensions) => ({
4240
- Id: id,
4241
- MetricStat: {
4242
- Metric: {
4243
- Dimensions: metricDimensions,
4244
- MetricName: metricName,
4245
- Namespace:
4246
- objective.id === 'api-availability' &&
4247
- metricName !== 'SyntheticGood' &&
4248
- metricName !== 'SyntheticValid'
4249
- ? 'AWS/ApiGateway'
4250
- : 'EBK/${name}',
4251
- },
4252
- Period: 60,
4253
- Stat: 'Sum',
4254
- },
4255
- ReturnData: true,
4256
- });
4257
- const syntheticDimensions = [
4258
- { Name: 'Component', Value: 'synthetic' },
4259
- { Name: 'Feature', Value: 'operations' },
4260
- {
4261
- Name: 'Operation',
4262
- Value:
4263
- objective.id === 'api-availability'
4264
- ? 'api-health'
4265
- : 'web-critical-route',
4266
- },
4267
- { Name: 'Slice', Value: '${name}' },
4268
- { Name: 'Stage', Value: plan.target.stage },
4269
- ];
4270
- const syntheticQueries =
4271
- objective.lowTraffic.mode === 'synthetic'
4272
- ? [
4273
- metric('synthetic_valid', 'SyntheticValid', syntheticDimensions),
4274
- metric('synthetic_good', 'SyntheticGood', syntheticDimensions),
4275
- ]
4276
- : [];
4277
- let metricDataQueries;
4278
- if (objective.id === 'api-availability') {
4279
- const apiId = safeToken(query.apiId, 'apiId', 128);
4280
- if (apiId !== activeResources.apiId) {
4281
- throw new Error(
4282
- 'Metric query API is not authorized by the protected deployment.',
4283
- );
4284
- }
4285
- const apiDimensions = [{ Name: 'ApiId', Value: apiId }];
4286
- metricDataQueries = [
4287
- metric('valid', 'Count', apiDimensions),
4288
- { ...metric('bad', '5xx', apiDimensions), ReturnData: false },
4289
- {
4290
- Expression: 'valid-bad',
4291
- Id: 'good',
4292
- Label: 'Good API events',
4293
- ReturnData: true,
4294
- },
4295
- ...syntheticQueries,
4296
- ];
4297
- } else if (objective.id === 'web-latency') {
4298
- if (query.apiId !== undefined) {
4299
- throw new Error('Web metric capture must not accept an API identity.');
4300
- }
4301
- metricDataQueries = [
4302
- metric('valid', 'OperationValid'),
4303
- metric('good', 'OperationGood'),
4304
- ...syntheticQueries,
4305
- ];
4306
- } else {
4307
- throw new Error(
4308
- 'This objective has no stable-v1 AWS metric capture adapter.',
4309
- );
4310
- }
4311
- const response = await new CloudWatchClient({ region }).send(
4312
- new GetMetricDataCommand({
4313
- EndTime: new Date(endTime),
4314
- MaxDatapoints: 1008,
4315
- MetricDataQueries: metricDataQueries,
4316
- ScanBy: 'TimestampDescending',
4317
- StartTime: new Date(startTime),
4318
- }),
4319
- );
4320
- if (response.NextToken) {
4321
- throw new Error('Metric query exceeded its one-page data-point bound.');
4322
- }
4323
- const idMap = {
4324
- good: 'good',
4325
- synthetic_good: 'synthetic-good',
4326
- synthetic_valid: 'synthetic-valid',
4327
- valid: 'valid',
4328
- };
4329
- const metricResults = (response.MetricDataResults ?? [])
4330
- .filter(({ Id }) => idMap[Id])
4331
- .map((result) => ({
4332
- id: idMap[result.Id],
4333
- status: result.StatusCode ?? null,
4334
- timestamps: (result.Timestamps ?? []).map((value) => value.toISOString()),
4335
- values: result.Values ?? [],
4336
- }));
4337
- if (
4338
- metricResults.length !==
4339
- (objective.lowTraffic.mode === 'synthetic' ? 4 : 2) ||
4340
- new Set(metricResults.map(({ id }) => id)).size !== metricResults.length ||
4341
- !metricResults.some(({ id }) => id === 'valid') ||
4342
- !metricResults.some(({ id }) => id === 'good') ||
4343
- metricResults.some(
4344
- ({ status, timestamps, values }) =>
4345
- status !== 'Complete' ||
4346
- timestamps.length !== values.length ||
4347
- values.length > 1008 ||
4348
- timestamps.some(
4349
- (value) =>
4350
- !Number.isFinite(Date.parse(value)) ||
4351
- Date.parse(value) < Date.parse(startTime) ||
4352
- Date.parse(value) > Date.parse(endTime),
4353
- ) ||
4354
- values.some((value) => !Number.isFinite(value) || value < 0),
4355
- )
4356
- ) {
4357
- throw new Error('AWS metric response is incomplete or outside its bound.');
4358
- }
4359
- const queryDigest = sha256(
4360
- Buffer.from(JSON.stringify({
4361
- endTime,
4362
- metricDataQueries,
4363
- startTime,
4364
- target: plan.target,
4365
- })),
4366
- );
4367
- await capture(
4368
- {
4369
- binding: capturedBinding,
4370
- bindingArtifact: {
4371
- digest: activeBinding.digest,
4372
- path: activeBinding.path,
4373
- },
4374
- capturedAt: new Date().toISOString(),
4375
- kind: 'reliability-metric-capture',
4376
- metricResults,
4377
- objectiveId,
4378
- queryDigest,
4379
- sampleWindow: {
4380
- durationSeconds: elapsed / 1_000,
4381
- end: endTime,
4382
- start: startTime,
4383
- },
4384
- schemaVersion: 1,
4385
- slice: '${name}',
4386
- target: plan.target,
4387
- },
4388
- '.ebk/evidence/reliability/captures',
4389
- );
4390
- process.exit(0);
4391
- }
4392
- if (plan.source === 'resource-metadata') {
4393
- const query = exactKeys(
4394
- request.query,
4395
- ['ecsServices', 'executions'],
4396
- 'resource-metadata query',
4397
- );
4398
- const ecsServices = query.ecsServices ?? [];
4399
- const executions = query.executions ?? [];
4400
- if (
4401
- !Array.isArray(ecsServices) ||
4402
- !Array.isArray(executions) ||
4403
- ecsServices.length > 8 ||
4404
- executions.length > 8 ||
4405
- ecsServices.length + executions.length < 1
4406
- ) {
4407
- throw new Error('Resource query is empty or exceeds eight targets per kind.');
4408
- }
4409
- const resources = [];
4410
- for (const [index, input] of ecsServices.entries()) {
4411
- const target = exactKeys(input, ['cluster', 'services'], 'ecsServices[' + index + ']');
4412
- const cluster = safeToken(target.cluster, 'ecsServices.cluster', 512);
4413
- if (
4414
- !Array.isArray(target.services) ||
4415
- target.services.length < 1 ||
4416
- target.services.length > 10
4417
- ) {
4418
- throw new Error('ECS service query is outside its ten-service bound.');
4419
- }
4420
- const services = target.services.map((value) =>
4421
- safeToken(value, 'ecsServices.service', 255),
4422
- );
4423
- const response = await new ECSClient({ region }).send(
4424
- new DescribeServicesCommand({ cluster, services }),
4425
- );
4426
- if ((response.failures?.length ?? 0) > 0) {
4427
- throw new Error('ECS returned an unresolved reliability target.');
4428
- }
4429
- if (
4430
- response.services?.length !== services.length ||
4431
- new Set(
4432
- (response.services ?? []).map(({ serviceArn }) =>
4433
- serviceArn?.slice(serviceArn.lastIndexOf('/') + 1),
4434
- ),
4435
- ).size !== services.length ||
4436
- response.services.some(
4437
- ({ serviceArn }) =>
4438
- !services.includes(serviceArn?.slice(serviceArn.lastIndexOf('/') + 1)),
4439
- )
4440
- ) {
4441
- throw new Error('ECS response escaped the exact diagnostic target.');
4442
- }
4443
- resources.push(...response.services.map((service) => ({
4444
- desiredCount: service.desiredCount ?? null,
4445
- pendingCount: service.pendingCount ?? null,
4446
- runningCount: service.runningCount ?? null,
4447
- serviceArn: service.serviceArn ?? null,
4448
- status: service.status ?? null,
4449
- })));
4450
- }
4451
- for (const [index, value] of executions.entries()) {
4452
- const executionArn = safeToken(value, 'executions[' + index + ']', 512);
4453
- const response = await new SFNClient({ region }).send(
4454
- new DescribeExecutionCommand({
4455
- executionArn,
4456
- includedData: 'METADATA_ONLY',
4457
- }),
4458
- );
4459
- if (
4460
- response.executionArn !== executionArn ||
4461
- !activeResources.stateMachineArns.includes(response.stateMachineArn)
4462
- ) {
4463
- throw new Error(
4464
- 'Step Functions response escaped the exact diagnostic target.',
4465
- );
4466
- }
4467
- resources.push({
4468
- executionArn: response.executionArn ?? null,
4469
- stateMachineArn: response.stateMachineArn ?? null,
4470
- status: response.status ?? null,
4471
- stopDate: response.stopDate?.toISOString?.() ?? null,
4472
- });
4473
- }
4474
- await capture(
4475
- {
4476
- binding: capturedBinding,
4477
- bindingDigest: activeBinding.digest,
4478
- capturedAt: new Date().toISOString(),
4479
- kind: 'reliability-resource-capture',
4480
- resources,
4481
- schemaVersion: 1,
4482
- slice: '${name}',
4483
- target: plan.target,
4484
- },
4485
- '.ebk/evidence/reliability/diagnostics',
4486
- );
4487
- process.exit(0);
4488
- }
4489
- throw new Error(
4490
- 'This diagnostic source has no stable-v1 read-only AWS query adapter.',
4491
- );
4492
- `,
4493
- 'scripts/incident-remediation.mjs': `import { spawnSync } from 'node:child_process';
4494
- import {
4495
- planRemediation,
4496
- } from '@empire-builder-kit/runtime/reliability';
4497
- import {
4498
- readBoundedJson,
4499
- } from './reliability-evidence-lib.mjs';
4500
-
4501
- const inputPath = process.env.EBK_INCIDENT_REMEDIATION_INPUT_PATH?.trim();
4502
- if (!inputPath) {
4503
- throw new Error('EBK_INCIDENT_REMEDIATION_INPUT_PATH is required.');
4504
- }
4505
- const request = readBoundedJson(
4506
- inputPath,
4507
- 'Incident remediation input',
4508
- ).value;
4509
- const plan = planRemediation(request);
4510
- if (plan.mode === 'report') {
4511
- process.stdout.write(JSON.stringify({
4512
- action: plan.action,
4513
- approvalRequired: true,
4514
- authorized: false,
4515
- execution: plan.execution,
4516
- remediationPlanDigest: plan.remediationPlanDigest,
4517
- target: plan.target,
4518
- }) + '\\n');
4519
- process.exit(0);
4520
- }
4521
- const required = (name) => {
4522
- const value = process.env[name]?.trim();
4523
- if (!value) throw new Error(name + ' is required.');
4524
- return value;
4525
- };
4526
- if (
4527
- process.env.GITHUB_ACTIONS !== 'true' ||
4528
- process.env.GITHUB_REF_PROTECTED !== 'true' ||
4529
- process.env.GITHUB_SHA !== process.env.EBK_APPROVED_COMMIT ||
4530
- !process.env.ACTIONS_ID_TOKEN_REQUEST_URL
4531
- ) {
4532
- throw new Error(
4533
- 'Incident remediation apply requires protected GitHub OIDC on the approved commit.',
4534
- );
4535
- }
4536
- if (
4537
- plan.target.account !== required('AWS_EXPECTED_ACCOUNT_ID') ||
4538
- plan.target.region !== required('AWS_REGION') ||
4539
- plan.target.stage !== required('EBK_STAGE') ||
4540
- plan.target.slice !== '${name}'
4541
- ) {
4542
- throw new Error(
4543
- 'Incident remediation approval does not match the effective target.',
4544
- );
4545
- }
4546
- if (
4547
- !['redrive', 'replay'].includes(plan.action) ||
4548
- plan.execution.adapter !== 'protected-async-recovery'
4549
- ) {
4550
- throw new Error(
4551
- 'This remediation action has no stable-v1 executable adapter.',
4552
- );
4553
- }
4554
- if (
4555
- plan.execution.asyncRecoveryReportDigest !==
4556
- required('EBK_ASYNC_REPORT_DIGEST')
4557
- ) {
4558
- throw new Error(
4559
- 'Incident remediation does not match the distinct async-recovery report.',
4560
- );
4561
- }
4562
- const capability =
4563
- plan.action === 'redrive'
4564
- ? 'bounded-selective-redrive'
4565
- : 'event-replay';
4566
- const result = spawnSync(
4567
- process.execPath,
4568
- ['scripts/protected-async-recovery.mjs'],
4569
- {
4570
- env: {
4571
- ...process.env,
4572
- EBK_ASYNC_CAPABILITY: capability,
4573
- EBK_RECOVERY_ACTION: 'apply',
4574
- },
4575
- stdio: 'inherit',
4576
- },
4577
- );
4578
- if (result.error) throw result.error;
4579
- if (result.status !== 0) process.exit(result.status ?? 1);
4580
- `,
4581
- 'reliability/contract.spec.ts': `import { describe, expect, it } from 'vitest';
4582
- import { createAuthenticatedSession } from '@empire-builder-kit/runtime/auth';
4583
- import {
4584
- createApprovalRequest,
4585
- createDirectAuthorizationPrincipal,
4586
- decideApprovalRequest,
4587
- } from '@empire-builder-kit/runtime/authorization';
4588
- import {
4589
- authorizeDiagnostic,
4590
- candidateIncidentSeverity,
4591
- diagnosticApprovalDigestInput,
4592
- evaluateSlo,
4593
- planRemediation,
4594
- RELIABILITY_APPROVAL_POLICY_VERSION,
4595
- remediationApprovalDigestInput,
4596
- } from '@empire-builder-kit/runtime/reliability';
4597
- import { Reliability } from './contract.js';
4598
-
4599
- const human = (id: string) =>
4600
- createDirectAuthorizationPrincipal({
4601
- id,
4602
- kind: 'admin',
4603
- roles: [],
4604
- scopes: [],
4605
- session: createAuthenticatedSession({
4606
- subject: { id, type: 'user' },
4607
- }),
4608
- });
4609
- const approvedAuthorization = <Action extends string>(
4610
- input: {
4611
- action: Action;
4612
- command: unknown;
4613
- resource: { id?: string; type: string };
4614
- },
4615
- ) => {
4616
- const now = Date.now();
4617
- const pending = createApprovalRequest({
4618
- ...input,
4619
- author: human('human-operator'),
4620
- expiresAt: new Date(now + 30 * 60 * 1_000).toISOString(),
4621
- now: new Date(now - 60 * 1_000).toISOString(),
4622
- policyVersion: RELIABILITY_APPROVAL_POLICY_VERSION,
4623
- slice: '${name}',
4624
- });
4625
- return decideApprovalRequest(pending, {
4626
- approver: human('human-reviewer'),
4627
- expectedRequestDigest: pending.requestDigest,
4628
- now: new Date(now - 30 * 1_000).toISOString(),
4629
- outcome: 'approved',
4630
- reasonReference: 'incident-1-review',
4631
- requiredPolicyVersion: RELIABILITY_APPROVAL_POLICY_VERSION,
4632
- }).request;
4633
- };
4634
-
4635
- describe('${name} reliability contract', () => {
4636
- it('binds owned objectives and never auto-declares SEV-1', () => {
4637
- expect(Reliability.slice).toBe('${name}');
4638
- expect(Reliability.objectives.map(({ id }) => id)).toEqual([
4639
- 'api-availability',
4640
- 'web-latency',
4641
- 'async-delivery-deadline',
4642
- ]);
4643
- expect(candidateIncidentSeverity('critical')).toBe('SEV-2');
4644
- });
4645
-
4646
- it('makes low-traffic data sufficiency explicit', () => {
4647
- const objective = Reliability.objectives[0]!;
4648
- expect(
4649
- evaluateSlo({
4650
- goodEvents: 1,
4651
- objective,
4652
- validEvents: 1,
4653
- }).state,
4654
- ).toBe('data-insufficient');
4655
- });
4656
-
4657
- it('rejects cross-target diagnostic and remediation approvals', () => {
4658
- const target = {
4659
- account: '123456789012',
4660
- region: 'us-east-1',
4661
- slice: '${name}',
4662
- stage: 'production',
4663
- };
4664
- const approvalScope = {
4665
- allowedLogGroups: ['/ebk/production/${name}/api-health'],
4666
- incidentRef: 'incident-1',
4667
- queryClass: 'scoped-errors',
4668
- reason: 'Confirm the bounded failure signature.',
4669
- target: { ...target, slice: 'other-slice' },
4670
- windowEnd: '2026-07-29T12:00:00.000Z',
4671
- windowStart: '2026-07-29T11:30:00.000Z',
4672
- };
4673
- const approval = {
4674
- ...approvalScope,
4675
- authorization: approvedAuthorization(
4676
- diagnosticApprovalDigestInput(approvalScope),
4677
- ),
4678
- };
4679
- expect(() =>
4680
- authorizeDiagnostic({
4681
- approval,
4682
- source: 'bounded-log-query',
4683
- target,
4684
- }),
4685
- ).toThrow('does not match');
4686
- const report = planRemediation({
4687
- action: 'replay',
4688
- cleanup: ['Remove test resources.'],
4689
- execution: {
4690
- adapter: 'protected-async-recovery',
4691
- asyncRecoveryReportDigest: 'a'.repeat(64),
4692
- },
4693
- mode: 'report',
4694
- preconditions: ['The target is still active.'],
4695
- stopConditions: ['Stop on target change.'],
4696
- target,
4697
- verification: ['Verify the critical journey.'],
4698
- });
4699
- expect(() =>
4700
- planRemediation({
4701
- action: 'replay',
4702
- approval: {
4703
- authorization: approvedAuthorization(
4704
- remediationApprovalDigestInput({
4705
- incidentRef: 'incident-1',
4706
- plan: report,
4707
- }),
4708
- ),
4709
- incidentRef: 'incident-1',
4710
- },
4711
- cleanup: ['Remove test resources.'],
4712
- execution: {
4713
- adapter: 'protected-async-recovery',
4714
- asyncRecoveryReportDigest: 'a'.repeat(64),
4715
- },
4716
- mode: 'apply',
4717
- preconditions: ['The target is still active.'],
4718
- stopConditions: ['Stop on target change.'],
4719
- target,
4720
- verification: ['Verify a substituted journey.'],
4721
- }),
4722
- ).toThrow('does not match');
4723
- });
4724
- });
4725
- `,
4726
- };
4727
- }
4728
- //# sourceMappingURL=built-in-plan-reliability-files.js.map