@intentius/chant 0.124.55 → 0.124.56

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 (370) hide show
  1. package/dist/ci-agent.d.ts.map +1 -1
  2. package/dist/ci-agent.js +1 -2
  3. package/dist/ci-audit/attribution.d.ts +111 -0
  4. package/dist/ci-audit/attribution.d.ts.map +1 -0
  5. package/dist/ci-audit/attribution.js +194 -0
  6. package/dist/ci-audit/audit-log.d.ts +144 -0
  7. package/dist/ci-audit/audit-log.d.ts.map +1 -0
  8. package/dist/ci-audit/audit-log.js +149 -0
  9. package/dist/ci-audit/index.d.ts +12 -0
  10. package/dist/ci-audit/index.d.ts.map +1 -0
  11. package/dist/ci-audit/index.js +12 -0
  12. package/dist/ci-audit/unrecorded.d.ts +74 -0
  13. package/dist/ci-audit/unrecorded.d.ts.map +1 -0
  14. package/dist/ci-audit/unrecorded.js +95 -0
  15. package/dist/ci-audit.d.ts +3 -0
  16. package/dist/ci-audit.d.ts.map +1 -0
  17. package/dist/ci-audit.js +2 -0
  18. package/dist/ci-control.d.ts.map +1 -1
  19. package/dist/ci-control.js +3 -4
  20. package/dist/ci-estate.d.ts +24 -0
  21. package/dist/ci-estate.d.ts.map +1 -1
  22. package/dist/ci-estate.js +1 -2
  23. package/dist/ci-identity.d.ts.map +1 -1
  24. package/dist/ci-identity.js +2 -3
  25. package/dist/ci-job-guard.d.ts +139 -0
  26. package/dist/ci-job-guard.d.ts.map +1 -0
  27. package/dist/ci-job-guard.js +287 -0
  28. package/dist/ci-jobs.d.ts +7 -0
  29. package/dist/ci-jobs.d.ts.map +1 -1
  30. package/dist/ci-jobs.js +7 -0
  31. package/dist/ci-product-words.d.ts +7 -1
  32. package/dist/ci-product-words.d.ts.map +1 -1
  33. package/dist/ci-product-words.js +38 -4
  34. package/dist/ci-product.d.ts +35 -0
  35. package/dist/ci-product.d.ts.map +1 -1
  36. package/dist/ci-product.js +38 -3
  37. package/dist/ci-respond-run.d.ts +73 -0
  38. package/dist/ci-respond-run.d.ts.map +1 -0
  39. package/dist/ci-respond-run.js +247 -0
  40. package/dist/ci-respond.d.ts +189 -0
  41. package/dist/ci-respond.d.ts.map +1 -0
  42. package/dist/ci-respond.js +285 -0
  43. package/dist/cli/handlers/audit-log.d.ts +12 -0
  44. package/dist/cli/handlers/audit-log.d.ts.map +1 -0
  45. package/dist/cli/handlers/audit-log.js +81 -0
  46. package/dist/cli/handlers/build.d.ts +7 -0
  47. package/dist/cli/handlers/build.d.ts.map +1 -1
  48. package/dist/cli/handlers/build.js +81 -0
  49. package/dist/cli/handlers/ci-check-job.d.ts +11 -0
  50. package/dist/cli/handlers/ci-check-job.d.ts.map +1 -0
  51. package/dist/cli/handlers/ci-check-job.js +27 -0
  52. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  53. package/dist/cli/handlers/ci-check.js +38 -9
  54. package/dist/cli/handlers/e2e-safe-run.d.ts +12 -0
  55. package/dist/cli/handlers/e2e-safe-run.d.ts.map +1 -0
  56. package/dist/cli/handlers/e2e-safe-run.js +23 -0
  57. package/dist/cli/handlers/pr.d.ts +5 -0
  58. package/dist/cli/handlers/pr.d.ts.map +1 -1
  59. package/dist/cli/handlers/pr.js +259 -4
  60. package/dist/cli/handlers/run-wave.js +89 -1
  61. package/dist/cli/main.d.ts.map +1 -1
  62. package/dist/cli/main.js +56 -2
  63. package/dist/cli/parse-args.d.ts.map +1 -1
  64. package/dist/cli/parse-args.js +107 -0
  65. package/dist/cli/registry.d.ts +38 -0
  66. package/dist/cli/registry.d.ts.map +1 -1
  67. package/dist/components/adoption.d.ts.map +1 -1
  68. package/dist/components/adoption.js +1 -2
  69. package/dist/components/capability.d.ts +37 -0
  70. package/dist/components/capability.d.ts.map +1 -1
  71. package/dist/components/capability.js +25 -0
  72. package/dist/components/check-hooks.d.ts +4 -1
  73. package/dist/components/check-hooks.d.ts.map +1 -1
  74. package/dist/components/check-steps.d.ts +74 -0
  75. package/dist/components/check-steps.d.ts.map +1 -0
  76. package/dist/components/check-steps.js +102 -0
  77. package/dist/components/ci-services.d.ts.map +1 -1
  78. package/dist/components/ci-services.js +1 -2
  79. package/dist/components/driver.d.ts +12 -0
  80. package/dist/components/driver.d.ts.map +1 -1
  81. package/dist/components/driver.js +35 -1
  82. package/dist/components/groups.d.ts.map +1 -1
  83. package/dist/components/groups.js +4 -3
  84. package/dist/components/pr-env-ledger.d.ts.map +1 -1
  85. package/dist/components/pr-env-ledger.js +1 -2
  86. package/dist/components/pr-environment.d.ts +1 -1
  87. package/dist/components/pr-environment.d.ts.map +1 -1
  88. package/dist/components/pr-environment.js +1 -1
  89. package/dist/components/pr-pipeline.d.ts +129 -3
  90. package/dist/components/pr-pipeline.d.ts.map +1 -1
  91. package/dist/components/pr-pipeline.js +153 -17
  92. package/dist/components/pr-run.d.ts +8 -0
  93. package/dist/components/pr-run.d.ts.map +1 -1
  94. package/dist/components/pr-run.js +9 -4
  95. package/dist/components/product-pipeline.d.ts +35 -2
  96. package/dist/components/product-pipeline.d.ts.map +1 -1
  97. package/dist/components/product-pipeline.js +24 -5
  98. package/dist/components/wave-plan.d.ts +8 -0
  99. package/dist/components/wave-plan.d.ts.map +1 -1
  100. package/dist/components/wave-plan.js +18 -2
  101. package/dist/e2e-harness/bucket.d.ts +21 -0
  102. package/dist/e2e-harness/bucket.d.ts.map +1 -0
  103. package/dist/e2e-harness/bucket.js +61 -0
  104. package/dist/e2e-harness/claim.d.ts +70 -0
  105. package/dist/e2e-harness/claim.d.ts.map +1 -0
  106. package/dist/e2e-harness/claim.js +98 -0
  107. package/dist/e2e-harness/driver.d.ts +64 -0
  108. package/dist/e2e-harness/driver.d.ts.map +1 -0
  109. package/dist/e2e-harness/driver.js +243 -0
  110. package/dist/e2e-harness/forgejo.d.ts +77 -0
  111. package/dist/e2e-harness/forgejo.d.ts.map +1 -0
  112. package/dist/e2e-harness/forgejo.js +205 -0
  113. package/dist/e2e-harness/git.d.ts +32 -0
  114. package/dist/e2e-harness/git.d.ts.map +1 -0
  115. package/dist/e2e-harness/git.js +67 -0
  116. package/dist/e2e-harness/index.d.ts +22 -0
  117. package/dist/e2e-harness/index.d.ts.map +1 -0
  118. package/dist/e2e-harness/index.js +48 -0
  119. package/dist/e2e-harness/jobs.d.ts +8 -0
  120. package/dist/e2e-harness/jobs.d.ts.map +1 -0
  121. package/dist/e2e-harness/jobs.js +34 -0
  122. package/dist/e2e-harness/pins.d.ts +45 -0
  123. package/dist/e2e-harness/pins.d.ts.map +1 -0
  124. package/dist/e2e-harness/pins.js +44 -0
  125. package/dist/e2e-harness/ports.d.ts +113 -0
  126. package/dist/e2e-harness/ports.d.ts.map +1 -0
  127. package/dist/e2e-harness/ports.js +4 -0
  128. package/dist/e2e-harness/reports.d.ts +45 -0
  129. package/dist/e2e-harness/reports.d.ts.map +1 -0
  130. package/dist/e2e-harness/reports.js +57 -0
  131. package/dist/e2e-harness/safe-run-cli.d.ts +17 -0
  132. package/dist/e2e-harness/safe-run-cli.d.ts.map +1 -0
  133. package/dist/e2e-harness/safe-run-cli.js +43 -0
  134. package/dist/e2e-harness/safe-run.d.ts +61 -0
  135. package/dist/e2e-harness/safe-run.d.ts.map +1 -0
  136. package/dist/e2e-harness/safe-run.js +172 -0
  137. package/dist/e2e-harness/scenario.d.ts +11 -0
  138. package/dist/e2e-harness/scenario.d.ts.map +1 -0
  139. package/dist/e2e-harness/scenario.js +89 -0
  140. package/dist/e2e-harness/schemas/demo-cycle.schema.json +282 -0
  141. package/dist/e2e-harness/schemas/demo-step.schema.json +245 -0
  142. package/dist/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
  143. package/dist/e2e-harness/schemas/e2e-claims.schema.json +18 -0
  144. package/dist/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
  145. package/dist/e2e-harness/schemas/index.d.ts +191 -0
  146. package/dist/e2e-harness/schemas/index.d.ts.map +1 -0
  147. package/dist/e2e-harness/schemas/index.js +62 -0
  148. package/dist/e2e-harness/stack.d.ts +124 -0
  149. package/dist/e2e-harness/stack.d.ts.map +1 -0
  150. package/dist/e2e-harness/stack.js +207 -0
  151. package/dist/e2e-harness/steps.d.ts +11 -0
  152. package/dist/e2e-harness/steps.d.ts.map +1 -0
  153. package/dist/e2e-harness/steps.js +22 -0
  154. package/dist/e2e-harness.d.ts +3 -0
  155. package/dist/e2e-harness.d.ts.map +1 -0
  156. package/dist/e2e-harness.js +2 -0
  157. package/dist/exit-codes.d.ts +7 -1
  158. package/dist/exit-codes.d.ts.map +1 -1
  159. package/dist/exit-codes.js +7 -1
  160. package/dist/lexicon.d.ts +46 -0
  161. package/dist/lexicon.d.ts.map +1 -1
  162. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  163. package/dist/lifecycle/gate-ledger.js +2 -3
  164. package/dist/lifecycle/gated-request.d.ts.map +1 -1
  165. package/dist/lifecycle/gated-request.js +1 -2
  166. package/dist/lifecycle/query.d.ts.map +1 -1
  167. package/dist/lifecycle/query.js +4 -5
  168. package/dist/lifecycle/release-catalog.d.ts.map +1 -1
  169. package/dist/lifecycle/release-catalog.js +1 -1
  170. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  171. package/dist/lifecycle/release-ledger.js +1 -2
  172. package/dist/lifecycle/release-status.d.ts +20 -0
  173. package/dist/lifecycle/release-status.d.ts.map +1 -1
  174. package/dist/lifecycle/release-status.js +1 -22
  175. package/dist/lifecycle/wave-plans.d.ts +23 -7
  176. package/dist/lifecycle/wave-plans.d.ts.map +1 -1
  177. package/dist/lifecycle/wave-plans.js +9 -2
  178. package/dist/op/approval-status.d.ts +103 -0
  179. package/dist/op/approval-status.d.ts.map +1 -0
  180. package/dist/op/approval-status.js +197 -0
  181. package/dist/op/index.d.ts +1 -1
  182. package/dist/op/index.d.ts.map +1 -1
  183. package/dist/op/index.js +1 -1
  184. package/dist/op/op-waves-capability-spec.d.ts +8 -0
  185. package/dist/op/op-waves-capability-spec.d.ts.map +1 -1
  186. package/dist/op/op-waves-capability-spec.js +21 -0
  187. package/dist/op/op-waves-release.d.ts.map +1 -1
  188. package/dist/op/op-waves-release.js +1 -2
  189. package/dist/op/op-waves-run.d.ts +7 -2
  190. package/dist/op/op-waves-run.d.ts.map +1 -1
  191. package/dist/op/op-waves-run.js +96 -4
  192. package/dist/op/op-waves-stand-down.d.ts.map +1 -1
  193. package/dist/op/op-waves-stand-down.js +1 -2
  194. package/dist/op/op-waves.d.ts +35 -0
  195. package/dist/op/op-waves.d.ts.map +1 -1
  196. package/dist/op/op-waves.js +46 -6
  197. package/dist/op/runtime.d.ts +4 -0
  198. package/dist/op/runtime.d.ts.map +1 -1
  199. package/dist/op/runtime.js +2 -3
  200. package/dist/otlp.d.ts.map +1 -1
  201. package/dist/otlp.js +1 -2
  202. package/dist/parallelism.d.ts +17 -0
  203. package/dist/parallelism.d.ts.map +1 -0
  204. package/dist/parallelism.js +33 -0
  205. package/dist/policy-source.d.ts.map +1 -1
  206. package/dist/policy-source.js +1 -2
  207. package/dist/pr-forge.d.ts.map +1 -1
  208. package/dist/pr-forge.js +56 -39
  209. package/dist/pr-loop.d.ts +9 -0
  210. package/dist/pr-loop.d.ts.map +1 -1
  211. package/dist/pr-loop.js +22 -3
  212. package/dist/pr-merge.d.ts +64 -0
  213. package/dist/pr-merge.d.ts.map +1 -0
  214. package/dist/pr-merge.js +78 -0
  215. package/dist/pr-post.d.ts +70 -1
  216. package/dist/pr-post.d.ts.map +1 -1
  217. package/dist/pr-post.js +116 -5
  218. package/dist/pr-report-url.d.ts.map +1 -1
  219. package/dist/pr-report-url.js +1 -2
  220. package/dist/release-floors.d.ts +1 -1
  221. package/dist/release-floors.js +1 -1
  222. package/dist/run-event.d.ts.map +1 -1
  223. package/dist/run-event.js +1 -2
  224. package/dist/scheduled-op-cloud.d.ts +32 -0
  225. package/dist/scheduled-op-cloud.d.ts.map +1 -0
  226. package/dist/scheduled-op-cloud.js +69 -0
  227. package/dist/wave-runtime.mjs +340 -327
  228. package/dist/workspace/ci-lock-grain.d.ts +5 -0
  229. package/dist/workspace/ci-lock-grain.d.ts.map +1 -1
  230. package/dist/workspace/ci-lock-grain.js +1 -7
  231. package/dist/workspace/ci-run.d.ts.map +1 -1
  232. package/dist/workspace/ci-run.js +5 -1
  233. package/dist/workspace/pr-report.schema.json +5 -0
  234. package/package.json +1 -1
  235. package/src/ci-agent.ts +1 -2
  236. package/src/ci-audit/__fixtures__/cloudtrail-lookup-bucket.json +37 -0
  237. package/src/ci-audit/__fixtures__/cloudtrail-writes-window.json +59 -0
  238. package/src/ci-audit/attribution.ts +260 -0
  239. package/src/ci-audit/audit-log.ts +220 -0
  240. package/src/ci-audit/ci-audit.test.ts +175 -0
  241. package/src/ci-audit/index.ts +15 -0
  242. package/src/ci-audit/unrecorded.ts +140 -0
  243. package/src/ci-audit.ts +2 -0
  244. package/src/ci-control.ts +3 -4
  245. package/src/ci-estate.ts +1 -2
  246. package/src/ci-identity-database.test.ts +2 -3
  247. package/src/ci-identity-targets.test.ts +1 -3
  248. package/src/ci-identity.ts +2 -3
  249. package/src/ci-job-guard.test.ts +154 -0
  250. package/src/ci-job-guard.ts +319 -0
  251. package/src/ci-jobs.ts +8 -0
  252. package/src/ci-product-comment-targets.test.ts +45 -0
  253. package/src/ci-product-words.ts +35 -6
  254. package/src/ci-product.ts +55 -3
  255. package/src/ci-respond-run.ts +291 -0
  256. package/src/ci-respond.test.ts +264 -0
  257. package/src/ci-respond.ts +412 -0
  258. package/src/cli/handlers/audit-log.ts +74 -0
  259. package/src/cli/handlers/build-pr-loop-flags.test.ts +98 -0
  260. package/src/cli/handlers/build.ts +69 -0
  261. package/src/cli/handlers/ci-check-job.test.ts +114 -0
  262. package/src/cli/handlers/ci-check-job.ts +33 -0
  263. package/src/cli/handlers/ci-check.ts +38 -8
  264. package/src/cli/handlers/e2e-safe-run.ts +27 -0
  265. package/src/cli/handlers/pr-plan-comment-targets.test.ts +166 -0
  266. package/src/cli/handlers/pr-plan-flags.test.ts +161 -0
  267. package/src/cli/handlers/pr.ts +228 -4
  268. package/src/cli/handlers/run-wave.ts +79 -1
  269. package/src/cli/main.test.ts +1 -1
  270. package/src/cli/main.ts +56 -2
  271. package/src/cli/parse-args.ts +77 -0
  272. package/src/cli/registry.ts +38 -0
  273. package/src/components/adoption.ts +1 -2
  274. package/src/components/capability.ts +50 -0
  275. package/src/components/check-hooks.ts +4 -1
  276. package/src/components/check-steps.test.ts +70 -0
  277. package/src/components/check-steps.ts +158 -0
  278. package/src/components/ci-services.ts +1 -2
  279. package/src/components/driver.ts +35 -1
  280. package/src/components/groups.ts +4 -2
  281. package/src/components/plan-flags.test.ts +46 -0
  282. package/src/components/pr-comment-preview-targets.test.ts +34 -0
  283. package/src/components/pr-env-ledger.ts +1 -2
  284. package/src/components/pr-env-run-bundle.test.ts +0 -20
  285. package/src/components/pr-environment.ts +1 -1
  286. package/src/components/pr-pipeline-runners.test.ts +80 -0
  287. package/src/components/pr-pipeline.ts +232 -17
  288. package/src/components/pr-run.ts +17 -6
  289. package/src/components/pr-stale-job.test.ts +34 -0
  290. package/src/components/product-pipeline.ts +50 -8
  291. package/src/components/wave-plan.ts +18 -2
  292. package/src/e2e-harness/__project__/chant.config.ts +4 -0
  293. package/src/e2e-harness/__project__/src/compose.ts +33 -0
  294. package/src/e2e-harness/bucket.ts +69 -0
  295. package/src/e2e-harness/claim.test.ts +150 -0
  296. package/src/e2e-harness/claim.ts +140 -0
  297. package/src/e2e-harness/driver.test.ts +304 -0
  298. package/src/e2e-harness/driver.ts +294 -0
  299. package/src/e2e-harness/forgejo.ts +267 -0
  300. package/src/e2e-harness/git.ts +96 -0
  301. package/src/e2e-harness/index.ts +50 -0
  302. package/src/e2e-harness/jobs.ts +35 -0
  303. package/src/e2e-harness/pins.ts +52 -0
  304. package/src/e2e-harness/ports.ts +130 -0
  305. package/src/e2e-harness/reports.ts +79 -0
  306. package/src/e2e-harness/safe-run-cli.test.ts +102 -0
  307. package/src/e2e-harness/safe-run-cli.ts +54 -0
  308. package/src/e2e-harness/safe-run.ts +198 -0
  309. package/src/e2e-harness/scenario.ts +89 -0
  310. package/src/e2e-harness/schemas/README.md +62 -0
  311. package/src/e2e-harness/schemas/demo-cycle.schema.json +282 -0
  312. package/src/e2e-harness/schemas/demo-step.schema.json +245 -0
  313. package/src/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
  314. package/src/e2e-harness/schemas/e2e-claims.schema.json +18 -0
  315. package/src/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
  316. package/src/e2e-harness/schemas/index.ts +220 -0
  317. package/src/e2e-harness/schemas.test.ts +145 -0
  318. package/src/e2e-harness/stack.test.ts +124 -0
  319. package/src/e2e-harness/stack.ts +306 -0
  320. package/src/e2e-harness/steps.ts +30 -0
  321. package/src/e2e-harness.ts +2 -0
  322. package/src/exit-codes.test.ts +3 -2
  323. package/src/exit-codes.ts +7 -1
  324. package/src/gate-decision-bundle.test.ts +0 -2
  325. package/src/lexicon.ts +48 -0
  326. package/src/lifecycle/control-entries-ledger.test.ts +2 -3
  327. package/src/lifecycle/gate-ledger.ts +2 -3
  328. package/src/lifecycle/gated-request.ts +1 -2
  329. package/src/lifecycle/query.ts +4 -5
  330. package/src/lifecycle/release-catalog.test.ts +3 -4
  331. package/src/lifecycle/release-catalog.ts +1 -1
  332. package/src/lifecycle/release-ledger.ts +1 -2
  333. package/src/lifecycle/release-status.test.ts +3 -4
  334. package/src/lifecycle/release-status.ts +1 -2
  335. package/src/lifecycle/wave-plans.ts +33 -5
  336. package/src/op/approval-status.test.ts +134 -0
  337. package/src/op/approval-status.ts +235 -0
  338. package/src/op/gate-review.test.ts +2 -1
  339. package/src/op/index.ts +2 -0
  340. package/src/op/op-waves-after-plan.test.ts +12 -0
  341. package/src/op/op-waves-capability-spec.ts +20 -0
  342. package/src/op/op-waves-parallelism.test.ts +89 -0
  343. package/src/op/op-waves-pull-request.test.ts +78 -1
  344. package/src/op/op-waves-release.ts +1 -2
  345. package/src/op/op-waves-run.ts +94 -4
  346. package/src/op/op-waves-stand-down.ts +1 -2
  347. package/src/op/op-waves.ts +63 -6
  348. package/src/op/runtime.ts +6 -3
  349. package/src/otlp.ts +1 -2
  350. package/src/parallelism.test.ts +38 -0
  351. package/src/parallelism.ts +33 -0
  352. package/src/policy-source.ts +1 -2
  353. package/src/pr-forge-bundle.test.ts +1 -1
  354. package/src/pr-forge.ts +54 -35
  355. package/src/pr-loop-bundle.test.ts +1 -1
  356. package/src/pr-loop-narrowed.test.ts +63 -0
  357. package/src/pr-loop.ts +30 -3
  358. package/src/pr-merge.test.ts +100 -0
  359. package/src/pr-merge.ts +105 -0
  360. package/src/pr-post-stale.test.ts +163 -0
  361. package/src/pr-post.ts +159 -5
  362. package/src/pr-report-url.ts +1 -2
  363. package/src/product-subpaths-plain-node.e2e.test.ts +1 -0
  364. package/src/release-floors.ts +1 -1
  365. package/src/run-event.ts +1 -2
  366. package/src/scheduled-op-cloud.ts +68 -0
  367. package/src/stage-hooks-bundle.test.ts +0 -2
  368. package/src/workspace/ci-lock-grain.ts +1 -2
  369. package/src/workspace/ci-run.ts +5 -1
  370. package/src/workspace/pr-report.schema.json +5 -0
@@ -0,0 +1,220 @@
1
+ /**
2
+ * A cloud's audit log, as CI core reads it (#4632, moved from terragucci's
3
+ * respond/attribute.ts and state-writers.ts): who last wrote an object, and
4
+ * every write in a window. CloudTrail is the first reader; the cloud is
5
+ * named per workspace member ({@link AuditLogSettings}), so a member on
6
+ * another cloud reads as `unavailable` with the reason, never as silence.
7
+ *
8
+ * The reader runs the `aws` CLI with the credentials the job already holds
9
+ * (a drift job's preview identity, #4631). Tests pass `run` and read
10
+ * recorded CloudTrail output; nothing here reaches a cloud by itself.
11
+ */
12
+
13
+ import { spawnSync } from "node:child_process";
14
+
15
+ /** The clouds an audit log is read for. */
16
+ export type AuditCloud = "aws";
17
+
18
+ /** The audit log a member's writes are read from: `{ cloud: "aws", region? }`. */
19
+ export interface AuditLogSetting {
20
+ cloud: AuditCloud;
21
+ /** The region the log is read in. Default: the CLI's. */
22
+ region?: string;
23
+ /** How far back a lookup reads. Default 14 days. */
24
+ days?: number;
25
+ }
26
+
27
+ /** Each member's audit log, by member name; `*` for every member not named. */
28
+ export type AuditLogSettings = Record<string, AuditLogSetting>;
29
+
30
+ /** `aws`, `aws:us-east-1`, as `--audit-log` takes it. */
31
+ export function parseAuditLogSetting(text: string): AuditLogSetting | { error: string } {
32
+ const [cloud, region, ...rest] = text.split(":");
33
+ if (cloud !== "aws") return { error: `--audit-log reads aws's CloudTrail, not ${JSON.stringify(cloud)}: --audit-log aws[:<region>]` };
34
+ if (rest.length > 0) return { error: `--audit-log takes aws[:<region>], not ${JSON.stringify(text)}` };
35
+ return { cloud, ...(region ? { region } : {}) };
36
+ }
37
+
38
+ /** The setting for `member`: its own, else `*`'s. */
39
+ export function auditLogFor(settings: AuditLogSettings | undefined, member: string): AuditLogSetting | undefined {
40
+ return settings?.[member] ?? settings?.["*"];
41
+ }
42
+
43
+ /** What a lookup asks: the object by its type and its real name or id. */
44
+ export interface AuditQuery {
45
+ type: string;
46
+ address: string;
47
+ ref: string;
48
+ }
49
+
50
+ /** Who last wrote an object outside the engine. */
51
+ export type AuditAnswer =
52
+ | { status: "found"; actor: "controller" | "human"; who: string; event: string; at: string }
53
+ /** The log was read and holds no write outside the engine that tells a person from a controller. */
54
+ | { status: "silent" }
55
+ | { status: "unavailable"; reason: string };
56
+
57
+ /** One write the log holds. */
58
+ export interface AuditWrite {
59
+ at: string;
60
+ event: string;
61
+ /** The principal, as the log names it. */
62
+ who: string;
63
+ /** A person or a controller, when the record says. */
64
+ actor?: "controller" | "human";
65
+ /** The objects it wrote, by name or ARN. */
66
+ resources: string[];
67
+ /** The engine wrote it (its user agent says Terraform, OpenTofu or Pulumi). */
68
+ engine?: boolean;
69
+ id?: string;
70
+ }
71
+
72
+ /** Every write in a window. */
73
+ export type AuditWrites = { status: "read"; writes: AuditWrite[] } | { status: "unavailable"; reason: string };
74
+
75
+ /** What attribution and the unrecorded writer audit need from a log. */
76
+ export interface AuditLog {
77
+ lookup(q: AuditQuery): Promise<AuditAnswer>;
78
+ writes(q: { since: string; until: string }): Promise<AuditWrites>;
79
+ }
80
+
81
+ /** A CloudTrail record, cut to what is read. */
82
+ export interface TrailEvent {
83
+ eventID?: string;
84
+ eventName?: string;
85
+ eventTime?: string;
86
+ readOnly?: boolean | string;
87
+ userAgent?: string;
88
+ invokedBy?: string;
89
+ userIdentity?: { type?: string; userName?: string; arn?: string; invokedBy?: string; sessionContext?: { sessionIssuer?: { userName?: string } } };
90
+ resources?: Array<{ ARN?: string; resourceName?: string; ResourceName?: string }>;
91
+ }
92
+
93
+ const ENGINE_AGENT = /terraform|opentofu|tofu|pulumi/i;
94
+
95
+ /**
96
+ * A CloudTrail record read as a person or a controller, or neither. A write
97
+ * by an AWS service principal is a controller; an IAM user, the root user,
98
+ * an Identity Center session and a role session named for an email address
99
+ * are people. A role session with a machine name could be a pipeline or a
100
+ * controller, so it answers nothing.
101
+ */
102
+ export function classifyEvent(e: TrailEvent): { actor: "controller" | "human"; who: string } | undefined {
103
+ const id = e.userIdentity ?? {};
104
+ const by = id.invokedBy ?? e.invokedBy;
105
+ if (id.type === "AWSService" || (by && /\.amazonaws\.com$/.test(by))) return { actor: "controller", who: by ?? "an AWS service" };
106
+ const arn = id.arn ?? "";
107
+ const session = arn.split("/").at(-1) ?? "";
108
+ if (id.type === "IAMUser") return { actor: "human", who: id.userName ?? session };
109
+ if (id.type === "Root") return { actor: "human", who: "the root user" };
110
+ if (id.type === "IdentityCenterUser" || id.type === "FederatedUser") return { actor: "human", who: id.userName ?? session };
111
+ if (id.type === "AssumedRole") {
112
+ const issuer = id.sessionContext?.sessionIssuer?.userName ?? "";
113
+ if (/^AWSReservedSSO_/.test(issuer) || session.includes("@")) return { actor: "human", who: session || issuer };
114
+ }
115
+ return undefined;
116
+ }
117
+
118
+ const isWrite = (e: TrailEvent): boolean => e.readOnly !== true && e.readOnly !== "true";
119
+
120
+ /** The newest write outside the engine that classifies. An older write by someone else is not who last changed it. */
121
+ export function newestActor(events: readonly TrailEvent[]): AuditAnswer {
122
+ const writes = events.filter((e) => isWrite(e) && !ENGINE_AGENT.test(e.userAgent ?? "")).sort((a, b) => String(b.eventTime ?? "").localeCompare(String(a.eventTime ?? "")));
123
+ const e = writes[0];
124
+ const c = e && classifyEvent(e);
125
+ return e && c ? { status: "found", ...c, event: e.eventName ?? "an event", at: e.eventTime ?? "" } : { status: "silent" };
126
+ }
127
+
128
+ /** A CloudTrail record as a write, or undefined for a read. */
129
+ export function trailWrite(e: TrailEvent): AuditWrite | undefined {
130
+ if (!isWrite(e)) return undefined;
131
+ const c = classifyEvent(e);
132
+ const who = c?.who ?? e.userIdentity?.arn ?? e.userIdentity?.userName ?? "an unnamed principal";
133
+ const resources = (e.resources ?? []).map((r) => r.ARN ?? r.resourceName ?? r.ResourceName).filter((r): r is string => typeof r === "string" && r !== "");
134
+ return {
135
+ at: e.eventTime ?? "",
136
+ event: e.eventName ?? "an event",
137
+ who,
138
+ ...(c ? { actor: c.actor } : {}),
139
+ resources,
140
+ ...(ENGINE_AGENT.test(e.userAgent ?? "") ? { engine: true } : {}),
141
+ ...(e.eventID ? { id: e.eventID } : {}),
142
+ };
143
+ }
144
+
145
+ /** Runs the `aws` CLI with its arguments. */
146
+ export type AwsRun = (args: string[]) => { status: number | null; stdout: string; stderr: string; error?: Error };
147
+
148
+ /** The `aws` CLI on the job's PATH, with the credentials it already has. */
149
+ export const spawnAws: AwsRun = (args) => {
150
+ const p = spawnSync("aws", args, { encoding: "utf-8", maxBuffer: 1 << 26 });
151
+ return { status: p.status, stdout: p.stdout ?? "", stderr: p.stderr ?? "", ...(p.error ? { error: p.error } : {}) };
152
+ };
153
+
154
+ /** CloudTrail's `lookup-events` output: each record's own JSON in `CloudTrailEvent`. */
155
+ export function parseLookupEvents(stdout: string): TrailEvent[] | undefined {
156
+ let doc: { Events?: Array<{ CloudTrailEvent?: string; EventName?: string; EventTime?: string; EventId?: string; Resources?: Array<{ ResourceName?: string }> }> };
157
+ try {
158
+ doc = JSON.parse(stdout) as typeof doc;
159
+ } catch {
160
+ return undefined;
161
+ }
162
+ const events: TrailEvent[] = [];
163
+ for (const e of doc.Events ?? []) {
164
+ try {
165
+ const inner = JSON.parse(e.CloudTrailEvent ?? "{}") as TrailEvent;
166
+ events.push({
167
+ ...(e.EventName ? { eventName: e.EventName } : {}),
168
+ ...(e.EventTime ? { eventTime: String(e.EventTime) } : {}),
169
+ ...(e.EventId ? { eventID: e.EventId } : {}),
170
+ ...(e.Resources ? { resources: e.Resources.map((r) => ({ ...(r.ResourceName ? { ResourceName: r.ResourceName } : {}) })) } : {}),
171
+ ...inner,
172
+ });
173
+ } catch {
174
+ // A record that does not parse says nothing.
175
+ }
176
+ }
177
+ return events;
178
+ }
179
+
180
+ const why = (p: ReturnType<AwsRun>): string => {
181
+ if ((p.error as NodeJS.ErrnoException | undefined)?.code === "ENOENT") return "the aws CLI is not installed";
182
+ return (p.error?.message ?? (p.stderr.trim() || `aws exited ${p.status}`)).split("\n")[0]!;
183
+ };
184
+
185
+ export interface AwsAuditOptions extends Omit<AuditLogSetting, "cloud"> {
186
+ run?: AwsRun;
187
+ now?: () => Date;
188
+ }
189
+
190
+ /**
191
+ * CloudTrail through the `aws` CLI: `lookup-events` by resource name for a
192
+ * lookup, by `ReadOnly=false` over the window for the writes. Only an
193
+ * `aws_` (Terraform) or `aws:` (Pulumi) resource is looked up.
194
+ */
195
+ export function awsAuditLog(o: AwsAuditOptions = {}): AuditLog {
196
+ const run = o.run ?? spawnAws;
197
+ const region = o.region ? ["--region", o.region] : [];
198
+ return {
199
+ async lookup(q) {
200
+ if (!q.type.startsWith("aws_") && !q.type.startsWith("aws:")) return { status: "unavailable", reason: `CloudTrail holds no writes of ${q.type}` };
201
+ const start = new Date((o.now?.() ?? new Date()).getTime() - (o.days ?? 14) * 86_400_000).toISOString();
202
+ const p = run(["cloudtrail", "lookup-events", "--output", "json", "--max-results", "50", "--start-time", start, "--lookup-attributes", `AttributeKey=ResourceName,AttributeValue=${q.ref}`, ...region]);
203
+ if (p.error || p.status !== 0) return { status: "unavailable", reason: why(p) };
204
+ const events = parseLookupEvents(p.stdout);
205
+ return events ? newestActor(events) : { status: "unavailable", reason: "aws printed no JSON" };
206
+ },
207
+ async writes(q) {
208
+ const p = run(["cloudtrail", "lookup-events", "--output", "json", "--start-time", q.since, "--end-time", q.until, "--lookup-attributes", "AttributeKey=ReadOnly,AttributeValue=false", ...region]);
209
+ if (p.error || p.status !== 0) return { status: "unavailable", reason: why(p) };
210
+ const events = parseLookupEvents(p.stdout);
211
+ if (!events) return { status: "unavailable", reason: "aws printed no JSON" };
212
+ return { status: "read", writes: events.map(trailWrite).filter((w): w is AuditWrite => w !== undefined) };
213
+ },
214
+ };
215
+ }
216
+
217
+ /** The reader for a setting. */
218
+ export function auditLogOf(setting: AuditLogSetting, o: Omit<AwsAuditOptions, keyof Omit<AuditLogSetting, "cloud">> = {}): AuditLog {
219
+ return awsAuditLog({ ...o, ...(setting.region ? { region: setting.region } : {}), ...(setting.days !== undefined ? { days: setting.days } : {}) });
220
+ }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * #4632: drift attribution and the unrecorded writer audit in CI core, over
3
+ * recorded CloudTrail output (`./__fixtures__`). No test reaches a cloud:
4
+ * the `aws` CLI is a function that prints the recorded file.
5
+ */
6
+
7
+ import { readFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { describe, expect, test } from "vitest";
10
+ import { driftDocument, driftRecord, type DriftRecord } from "../drift-record";
11
+ import type { OpRunRecord } from "../op/runtime";
12
+ import {
13
+ applyWindowsFromRuns,
14
+ attributeDrift,
15
+ awsAuditLog,
16
+ classifyEvent,
17
+ judgeWrites,
18
+ knownWrite,
19
+ parseAuditLogSetting,
20
+ renderUnrecorded,
21
+ routeAttributions,
22
+ unrecordedWrites,
23
+ type AuditLog,
24
+ type AwsRun,
25
+ } from "./index";
26
+
27
+ const fixture = (name: string): string => readFileSync(join(import.meta.dirname, "__fixtures__", name), "utf-8");
28
+
29
+ /** An `aws` that prints the recorded output and keeps the arguments it was run with. */
30
+ function recordedAws(file: string): { run: AwsRun; calls: string[][] } {
31
+ const calls: string[][] = [];
32
+ return { calls, run: (args) => (calls.push(args), { status: 0, stdout: fixture(file), stderr: "" }) };
33
+ }
34
+
35
+ function drifted(over: Partial<DriftRecord>): DriftRecord {
36
+ return driftRecord({
37
+ member: "app",
38
+ engine: "terraform",
39
+ address: "aws_s3_bucket.logs",
40
+ resourceType: "aws_s3_bucket",
41
+ node: null,
42
+ observedAt: "2026-10-28T00:00:00Z",
43
+ read: "refresh",
44
+ status: "drifted",
45
+ attributes: [{ path: "versioning", before: false, after: true }],
46
+ evidence: { tool: "terraform" },
47
+ ...over,
48
+ } as DriftRecord);
49
+ }
50
+
51
+ describe("the audit log reader (#4632)", () => {
52
+ test("--audit-log takes aws with an optional region", () => {
53
+ expect(parseAuditLogSetting("aws:us-east-1")).toEqual({ cloud: "aws", region: "us-east-1" });
54
+ expect(parseAuditLogSetting("gcp")).toEqual({ error: expect.stringContaining("CloudTrail") });
55
+ });
56
+
57
+ test("a person, a controller, and a machine role that says neither", () => {
58
+ expect(classifyEvent({ userIdentity: { type: "IAMUser", userName: "lee" } })).toEqual({ actor: "human", who: "lee" });
59
+ expect(classifyEvent({ userIdentity: { type: "AWSService", invokedBy: "autoscaling.amazonaws.com" } })).toEqual({ actor: "controller", who: "autoscaling.amazonaws.com" });
60
+ expect(classifyEvent({ userIdentity: { type: "AssumedRole", arn: "arn:aws:sts::1:assumed-role/ci/runner" } })).toBeUndefined();
61
+ });
62
+
63
+ test("a lookup names the newest write outside the engine, from recorded CloudTrail", async () => {
64
+ const aws = recordedAws("cloudtrail-lookup-bucket.json");
65
+ const log = awsAuditLog({ run: aws.run, region: "us-east-1", now: () => new Date("2026-10-28T00:00:00Z") });
66
+ expect(await log.lookup({ type: "aws_s3_bucket", address: "aws_s3_bucket.logs", ref: "acme-logs" })).toEqual({
67
+ status: "found",
68
+ actor: "human",
69
+ who: "lee@example.com",
70
+ event: "PutBucketVersioning",
71
+ at: "2026-10-21T14:30:00Z",
72
+ });
73
+ expect(aws.calls[0]).toEqual(expect.arrayContaining(["lookup-events", "AttributeKey=ResourceName,AttributeValue=acme-logs", "--region", "us-east-1", "--start-time", "2026-10-14T00:00:00.000Z"]));
74
+ expect(await log.lookup({ type: "google_storage_bucket", address: "x", ref: "x" })).toMatchObject({ status: "unavailable" });
75
+ });
76
+
77
+ test("a CLI that is missing or fails reads as unavailable, with why", async () => {
78
+ const missing: AwsRun = () => ({ status: null, stdout: "", stderr: "", error: Object.assign(new Error("spawn aws ENOENT"), { code: "ENOENT" }) });
79
+ expect(await awsAuditLog({ run: missing }).writes({ since: "a", until: "b" })).toEqual({ status: "unavailable", reason: "the aws CLI is not installed" });
80
+ const denied: AwsRun = () => ({ status: 254, stdout: "", stderr: "An error occurred (AccessDeniedException)\nmore" });
81
+ expect(await awsAuditLog({ run: denied }).lookup({ type: "aws_s3_bucket", address: "a", ref: "b" })).toEqual({ status: "unavailable", reason: "An error occurred (AccessDeniedException)" });
82
+ });
83
+ });
84
+
85
+ describe("drift attribution over chant's drift document (#4632)", () => {
86
+ test("the known-writes table answers first, for Terraform and Pulumi types alike", () => {
87
+ expect(knownWrite("aws_ecs_service", "desired_count", { before: 2, live: 5 })?.actor).toBe("controller");
88
+ expect(knownWrite("aws:ecs/service:Service", "desiredCount", { before: 2, live: 5 })?.actor).toBe("controller");
89
+ expect(knownWrite("aws_s3_bucket", "tags", { before: { a: "1" }, live: { a: "1", "aws:cloudformation:stack-name": "x" } })?.actor).toBe("controller");
90
+ expect(knownWrite("aws_s3_bucket", "tags", { before: { a: "1" }, live: { a: "2" } })).toBeUndefined();
91
+ });
92
+
93
+ test("the table, then the member's log, then unattributed; an unreadable log is noted once", async () => {
94
+ const doc = driftDocument([
95
+ drifted({}),
96
+ drifted({ member: "web", address: "aws_ecs_service.web", resourceType: "aws_ecs_service", attributes: [{ path: "desired_count", before: 2, after: 6 }] }),
97
+ drifted({ member: "edge", engine: "pulumi", address: "urn:pulumi:dev::edge::aws:s3/bucketV2:BucketV2::assets", resourceType: "aws:s3/bucketV2:BucketV2", attributes: [{ path: "forceDestroy", before: false, after: true }, { path: "acl", before: "private", after: "public-read" }] }),
98
+ ]);
99
+ const bucketLog = awsAuditLog({ run: recordedAws("cloudtrail-lookup-bucket.json").run, now: () => new Date("2026-10-28T00:00:00Z") });
100
+ const down: AuditLog = { lookup: async () => ({ status: "unavailable", reason: "AccessDenied" }), writes: async () => ({ status: "unavailable", reason: "AccessDenied" }) };
101
+ const { attributions, notes } = await attributeDrift(doc, {
102
+ logFor: (m) => (m === "app" ? bucketLog : m === "edge" ? down : undefined),
103
+ refOf: (r) => (r.member === "app" ? "acme-logs" : "assets"),
104
+ });
105
+ expect(attributions.map((a) => [a.member, a.path, a.source, a.actor])).toEqual([
106
+ ["app", "versioning", "audit", "human"],
107
+ ["edge", "acl", "unattributed", undefined],
108
+ ["edge", "forceDestroy", "unattributed", undefined],
109
+ ["web", "desired_count", "table", "controller"],
110
+ ]);
111
+ expect(notes).toEqual(["edge: the audit log is unavailable: AccessDenied"]);
112
+ });
113
+
114
+ test("a model answers only what the table and the log left, at or above its threshold", async () => {
115
+ const doc = driftDocument([drifted({ attributes: [{ path: "a", before: 1, after: 2 }, { path: "b", before: "x", after: "y" }] })]);
116
+ const asked: unknown[] = [];
117
+ const { attributions, notes } = await attributeDrift(doc, {
118
+ ask: async (state) => {
119
+ asked.push(state);
120
+ return state.attribute === "a" ? { actor: "provider-default", probability: 0.91, model: "m1" } : { actor: "human", probability: 0.4, model: "m1" };
121
+ },
122
+ });
123
+ expect(attributions.map((a) => a.source)).toEqual(["model", "unattributed"]);
124
+ expect(asked[1]).toEqual({ resource_type: "aws_s3_bucket", attribute: "b", value_in_code: "(a string of 1 characters)", live_value: "(a string of 1 characters)" });
125
+ expect(notes[0]).toContain("below the threshold");
126
+ });
127
+
128
+ test("the route speaks each engine's way of ignoring an attribute", () => {
129
+ const routed = routeAttributions([
130
+ { member: "web", engine: "terraform", address: "aws_ecs_service.web", path: "desired_count", actor: "controller", source: "table", detail: "d" },
131
+ { member: "edge", engine: "pulumi", address: "urn:x", path: "desiredCount", actor: "controller", source: "table", detail: "d" },
132
+ { member: "app", engine: "terraform", address: "aws_s3_bucket.logs", path: "versioning", actor: "human", source: "audit", detail: "PutBucketVersioning by lee" },
133
+ ]);
134
+ expect(routed.lines[0]).toContain("lifecycle { ignore_changes = [desired_count] }");
135
+ expect(routed.lines[1]).toContain('ignoreChanges: ["desiredCount"]');
136
+ expect(routed.lines[2]).toContain("human edit");
137
+ expect([...routed.leave.keys()]).toEqual(["aws_ecs_service.web", "urn:x"]);
138
+ });
139
+ });
140
+
141
+ describe("the unrecorded writer audit against the ledger's applies (#4632)", () => {
142
+ const runs = [
143
+ { version: 1, id: "plywood-up-1", op: "plywood-up", env: "prod", started: "2026-10-25T10:00:00Z", ended: "2026-10-25T10:02:00Z", status: "ok", labels: { Principal: "plywood-up" }, outcomes: {}, phases: [], wave: { spec: "plywood-up", number: 1, name: "prod", job: "wave", exitCode: 0, applied: ["app"], failed: [], moved: [] } },
144
+ { version: 1, id: "drift-1", op: "plywood-drift", env: "prod", started: "2026-10-25T12:59:00Z", ended: "2026-10-25T13:01:00Z", status: "ok", labels: {}, outcomes: {}, phases: [] },
145
+ ] as unknown as OpRunRecord[];
146
+
147
+ test("only applies make windows: a wave job that applied, not a drift read", () => {
148
+ expect(applyWindowsFromRuns(runs)).toEqual([{ run: "plywood-up-1", op: "plywood-up", started: "2026-10-25T10:00:00Z", ended: "2026-10-25T10:02:00Z", principals: ["plywood-up"] }]);
149
+ });
150
+
151
+ test("over recorded CloudTrail: the apply's own write is recorded, a person's is not, a controller's is apart, a recent one waits", async () => {
152
+ const aws = recordedAws("cloudtrail-writes-window.json");
153
+ const report = await unrecordedWrites(awsAuditLog({ run: aws.run }), applyWindowsFromRuns(runs), {
154
+ since: "2026-10-25T00:00:00Z",
155
+ until: "2026-10-28T12:00:00Z",
156
+ now: new Date("2026-10-28T12:00:00Z"),
157
+ });
158
+ expect(aws.calls[0]).toEqual(expect.arrayContaining(["AttributeKey=ReadOnly,AttributeValue=false", "--start-time", "2026-10-25T00:00:00Z"]));
159
+ expect(report.recorded).toBe(1);
160
+ expect(report.controller.map((w) => w.event)).toEqual(["SetDesiredCapacity"]);
161
+ expect(report.pending).toBe(1);
162
+ expect(report.unrecorded.map((w) => [w.event, w.who, w.why])).toEqual([
163
+ ["PutBucketAcl", "lee@example.com", "plywood-up-1 ran then as plywood-up, not lee@example.com"],
164
+ ["PutBucketVersioning", "lee@example.com", "no recorded apply ran then"],
165
+ ]);
166
+ expect(renderUnrecorded(report)).toContain("2 writes no recorded apply made, 1 recorded, 1 by a controller, 1 too recent to judge");
167
+ });
168
+
169
+ test("resources narrow the writes to what the member manages; an unreadable log judges nothing", async () => {
170
+ const writes = [{ at: "2026-10-25T13:00:00Z", event: "PutBucketVersioning", who: "lee", resources: ["arn:aws:s3:::other"] }];
171
+ expect(judgeWrites(writes, [], { since: "a", until: "b", now: new Date("2026-10-28T00:00:00Z"), resources: ["acme-logs"] }).unrecorded).toEqual([]);
172
+ const down: AuditLog = { lookup: async () => ({ status: "silent" }), writes: async () => ({ status: "unavailable", reason: "no trail" }) };
173
+ expect(await unrecordedWrites(down, [], { since: "a", until: "b" })).toMatchObject({ unavailable: "no trail", unrecorded: [] });
174
+ });
175
+ });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `@intentius/chant/ci-audit` (#4632): drift attribution from a cloud's
3
+ * audit log, and the unrecorded writer audit against the ledger's apply
4
+ * records, in CI core for terragucci and plywood. A product feature-detects
5
+ * on `CI_AUDIT_FLOOR`.
6
+ */
7
+
8
+ import { NEXT_RELEASE } from "../release-floors";
9
+
10
+ /** The first chant with drift attribution and the unrecorded writer audit in core. */
11
+ export const CI_AUDIT_FLOOR = NEXT_RELEASE;
12
+
13
+ export * from "./audit-log";
14
+ export * from "./attribution";
15
+ export * from "./unrecorded";
@@ -0,0 +1,140 @@
1
+ /**
2
+ * The unrecorded writer audit (#4632, moved from terragucci's
3
+ * report/unrecorded.ts and state-writers.ts): the audit log's writes
4
+ * compared against the ledger's apply records, and every write no
5
+ * recorded apply made reported with its writer.
6
+ *
7
+ * A write counts as recorded when it falls inside a recorded apply's run
8
+ * (its record's start to its end, a second early since a log keeps times to
9
+ * the second) and, when the apply names its principals, one of them made
10
+ * it. A write a controller made (an AWS service) is a write by design, which
11
+ * drift attribution covers, so it is reported apart and never as
12
+ * unrecorded. A write younger than the settle time is left for a later run,
13
+ * since a running apply has not ended its record yet.
14
+ *
15
+ * The apply records are the op run ledger's (`../lifecycle/run-ledger.ts`):
16
+ * every op wave job that applied or tried to, and any run a caller names.
17
+ * Only times and principals are read, never a state's contents.
18
+ */
19
+
20
+ import type { OpRunRecord } from "../op/runtime";
21
+ import type { AuditLog, AuditWrite } from "./audit-log";
22
+
23
+ /** How long a write waits before it is judged. Default one hour. */
24
+ export const UNRECORDED_SETTLE_SECONDS = 3600;
25
+
26
+ /** One recorded apply's run. */
27
+ export interface ApplyWindow {
28
+ run: string;
29
+ op: string;
30
+ started: string;
31
+ ended: string;
32
+ /** The principals the apply ran as, when the record names them. Absent: any writer inside the window counts. */
33
+ principals?: string[];
34
+ }
35
+
36
+ /**
37
+ * The applies among run records: an op wave job that applied or failed a
38
+ * run, or any record `isApply` accepts. A record whose times do not parse
39
+ * is left out.
40
+ */
41
+ export function applyWindowsFromRuns(records: readonly OpRunRecord[], isApply: (r: OpRunRecord) => boolean = defaultIsApply): ApplyWindow[] {
42
+ return records
43
+ .filter((r) => isApply(r) && Number.isFinite(Date.parse(r.started)) && Number.isFinite(Date.parse(r.ended)))
44
+ .map((r) => {
45
+ const principal = r.labels?.Principal;
46
+ return { run: r.id, op: r.op, started: r.started, ended: r.ended, ...(principal ? { principals: [principal] } : {}) };
47
+ });
48
+ }
49
+
50
+ function defaultIsApply(r: OpRunRecord): boolean {
51
+ const w = r.wave;
52
+ if (w) return w.applied.length + w.failed.length > 0 || (w.targets !== undefined && Object.keys(w.targets).length > 0);
53
+ return r.op.startsWith("pr-") || r.op.startsWith("green-");
54
+ }
55
+
56
+ export interface UnrecordedWrite extends AuditWrite {
57
+ /** Why no recorded apply covers it. */
58
+ why: string;
59
+ }
60
+
61
+ export interface UnrecordedReport {
62
+ since: string;
63
+ until: string;
64
+ /** Writes no recorded apply made, oldest first. */
65
+ unrecorded: UnrecordedWrite[];
66
+ /** Writes a recorded apply covers. */
67
+ recorded: number;
68
+ /** Writes a controller made by design. */
69
+ controller: AuditWrite[];
70
+ /** Writes younger than the settle time, left for a later run. */
71
+ pending: number;
72
+ /** Why the log could not be read, when it could not. */
73
+ unavailable?: string;
74
+ }
75
+
76
+ const t = (iso: string): number => Date.parse(iso);
77
+
78
+ /** Whether `who` is one of `principals`: the same string, or an assumed-role ARN whose session or role is it. */
79
+ function samePrincipal(who: string, principals: readonly string[]): boolean {
80
+ const low = who.toLowerCase();
81
+ return principals.some((p) => {
82
+ const q = p.toLowerCase();
83
+ return low === q || low.endsWith(`/${q}`) || low.includes(`:assumed-role/${q}/`);
84
+ });
85
+ }
86
+
87
+ /** Judge each write against the apply windows. Pure. */
88
+ export function judgeWrites(
89
+ writes: readonly AuditWrite[],
90
+ windows: readonly ApplyWindow[],
91
+ at: { since: string; until: string; now?: Date; settleSeconds?: number; resources?: readonly string[] },
92
+ ): UnrecordedReport {
93
+ const now = (at.now ?? new Date()).getTime();
94
+ const settle = (at.settleSeconds ?? UNRECORDED_SETTLE_SECONDS) * 1000;
95
+ const keep = at.resources?.length ? new Set(at.resources) : undefined;
96
+ const report: UnrecordedReport = { since: at.since, until: at.until, unrecorded: [], recorded: 0, controller: [], pending: 0 };
97
+ for (const w of [...writes].sort((a, b) => a.at.localeCompare(b.at))) {
98
+ if (keep && !w.resources.some((r) => keep.has(r) || [...keep].some((k) => r.endsWith(`/${k}`) || r.endsWith(`:${k}`)))) continue;
99
+ if (w.actor === "controller") {
100
+ report.controller.push(w);
101
+ continue;
102
+ }
103
+ const when = t(w.at);
104
+ if (!Number.isFinite(when) || now - when < settle) {
105
+ report.pending++;
106
+ continue;
107
+ }
108
+ const inside = windows.filter((x) => when >= t(x.started) - 1000 && when <= t(x.ended) + 1000);
109
+ const by = inside.filter((x) => !x.principals || samePrincipal(w.who, x.principals));
110
+ if (by.length > 0) {
111
+ report.recorded++;
112
+ continue;
113
+ }
114
+ const why =
115
+ inside.length > 0
116
+ ? `${inside.map((x) => x.run).join(", ")} ran then as ${[...new Set(inside.flatMap((x) => x.principals ?? []))].join(", ")}, not ${w.who}`
117
+ : "no recorded apply ran then";
118
+ report.unrecorded.push({ ...w, why });
119
+ }
120
+ return report;
121
+ }
122
+
123
+ /** Read the log's writes over the window and judge them. Never throws for the log. */
124
+ export async function unrecordedWrites(
125
+ log: AuditLog,
126
+ windows: readonly ApplyWindow[],
127
+ at: { since: string; until: string; now?: Date; settleSeconds?: number; resources?: readonly string[] },
128
+ ): Promise<UnrecordedReport> {
129
+ const read = await log.writes({ since: at.since, until: at.until });
130
+ if (read.status === "unavailable") return { since: at.since, until: at.until, unrecorded: [], recorded: 0, controller: [], pending: 0, unavailable: read.reason };
131
+ return judgeWrites(read.writes, windows, at);
132
+ }
133
+
134
+ /** The report as lines for an issue or a log. */
135
+ export function renderUnrecorded(report: UnrecordedReport): string {
136
+ if (report.unavailable) return `The audit log could not be read, so no write was judged: ${report.unavailable}.`;
137
+ const lines = [`Between ${report.since} and ${report.until}: ${report.unrecorded.length} write${report.unrecorded.length === 1 ? "" : "s"} no recorded apply made, ${report.recorded} recorded, ${report.controller.length} by a controller, ${report.pending} too recent to judge.`];
138
+ for (const w of report.unrecorded) lines.push(`- ${w.at} ${w.event} by ${w.who}${w.resources.length ? ` on ${w.resources.join(", ")}` : ""}: ${w.why}`);
139
+ return lines.join("\n");
140
+ }
@@ -0,0 +1,2 @@
1
+ /** `@intentius/chant/ci-audit` (#4632): the subpath entry for `./ci-audit/index.ts`. */
2
+ export * from "./ci-audit/index";
package/src/ci-control.ts CHANGED
@@ -28,16 +28,15 @@
28
28
  * present means the rest is too.
29
29
  */
30
30
 
31
- import { NEXT_RELEASE } from "./release-floors";
32
31
 
33
32
  /** The first chant with `@intentius/chant/ci-control` (#4568). */
34
- export const CI_CONTROL_FLOOR = NEXT_RELEASE;
33
+ export const CI_CONTROL_FLOOR = "0.124.55";
35
34
 
36
35
  /** The first chant that records the applies a dispatch carries and marks cross-stack edges (#4617). `recordControlAppliedFromEnv` present means the rest is too. */
37
- export const CONTROL_APPLIED_FLOOR = NEXT_RELEASE;
36
+ export const CONTROL_APPLIED_FLOOR = "0.124.55";
38
37
 
39
38
  /** The first chant whose note jobs read the control repo for the cross-stack edges (#4619). `controlNoteCheckout` present means the rest is too. */
40
- export const CONTROL_NOTE_CHECKOUT_FLOOR = NEXT_RELEASE;
39
+ export const CONTROL_NOTE_CHECKOUT_FLOOR = "0.124.55";
41
40
 
42
41
  export {
43
42
  CONTROL_APPLY_OUTCOMES,
package/src/ci-estate.ts CHANGED
@@ -22,7 +22,6 @@
22
22
  * {@link CI_ESTATE_FLOOR} is its floor: `buildLedgerEstate` present means the
23
23
  * rest is too. Before it, the product keeps its own estate code.
24
24
  */
25
- import { NEXT_RELEASE } from "./release-floors";
26
25
  import { CHANT_WORDS, type CiProductWords } from "./ci-product-words";
27
26
  import type { QueryLoad } from "./lifecycle/query";
28
27
  import type { ReportPut } from "./pr-report-url";
@@ -34,7 +33,7 @@ import { buildEstate, ESTATE_FILES, renderEstateHtml, type Estate, type EstateSe
34
33
  import { estateRows, type EstateRowOptions, type EstateRows, type EstateTables } from "./ci-estate/rows";
35
34
 
36
35
  /** The first chant with `@intentius/chant/ci-estate` (#4612). */
37
- export const CI_ESTATE_FLOOR = NEXT_RELEASE;
36
+ export const CI_ESTATE_FLOOR = "0.124.55";
38
37
 
39
38
  export { estateRows, type ApprovedApply, type DriftRun, type EstateRowOptions, type EstateRows, type EstateTables, type GateLine, type PrEnvLine, type WaveJob } from "./ci-estate/rows";
40
39
  export {
@@ -15,7 +15,6 @@ import {
15
15
  TRADED_VARS,
16
16
  type CloudIdentityDeclaration,
17
17
  } from "./ci-identity";
18
- import { NEXT_RELEASE } from "./release-floors";
19
18
 
20
19
  const azure = (database?: boolean): CloudIdentityDeclaration => ({
21
20
  azure: {
@@ -49,7 +48,7 @@ describe("azure database tokens", () => {
49
48
  expect(TRADED_VARS.azure).toContain(AZURE_DATABASE_TOKEN_ENV);
50
49
  });
51
50
 
52
- test("the floor is the next release", () => {
53
- expect(AZURE_DATABASE_TOKEN_FLOOR).toBe(NEXT_RELEASE);
51
+ test("the floor shipped in 0.124.55", () => {
52
+ expect(AZURE_DATABASE_TOKEN_FLOOR).toBe("0.124.55");
54
53
  });
55
54
  });
@@ -281,7 +281,7 @@ describe("the plan trade with targets, run against the emulator (#4332)", () =>
281
281
  });
282
282
 
283
283
  describe("the ci-identity bundle (#4332)", () => {
284
- test("holds ci-identity.ts and the floor constant alone, with no glob library, and stays small", async () => {
284
+ test("holds ci-identity.ts alone, with no glob library, and stays small", async () => {
285
285
  const result = await build({
286
286
  entryPoints: [join(REPO, "packages", "core", "src", "ci-identity.ts")],
287
287
  bundle: true,
@@ -293,8 +293,6 @@ describe("the ci-identity bundle (#4332)", () => {
293
293
  logLevel: "silent",
294
294
  });
295
295
  expect(Object.keys(result.metafile.inputs).map((i) => i.replace(/^.*?packages\//, "packages/"))).toEqual([
296
- // The next-release floor constant (#4480, the #4549 token floors): no imports.
297
- "packages/core/src/release-floors.ts",
298
296
  "packages/core/src/ci-identity.ts",
299
297
  ]);
300
298
  expect(result.outputFiles.reduce((n, f) => n + f.contents.byteLength, 0)).toBeLessThan(24 * 1024);
@@ -59,7 +59,6 @@
59
59
  */
60
60
 
61
61
  import { readFileSync } from "node:fs";
62
- import { NEXT_RELEASE } from "./release-floors";
63
62
 
64
63
  /** The cloud providers `ci.identity.cloud` names. */
65
64
  export const CLOUDS = ["aws", "gcp", "azure"] as const;
@@ -74,14 +73,14 @@ export const IDENTITY_CLOUDS = [...CLOUDS, "pulumi"] as const;
74
73
  export type IdentityCloud = (typeof IDENTITY_CLOUDS)[number];
75
74
 
76
75
  /** The first chant that reads `ci.identity.cloud.pulumi` (#4549): a declaration that sets it needs this `minReader`. */
77
- export const PULUMI_CLOUD_IDENTITY_FLOOR = NEXT_RELEASE;
76
+ export const PULUMI_CLOUD_IDENTITY_FLOOR = "0.124.55";
78
77
 
79
78
  /**
80
79
  * The first chant that reads `ci.identity.cloud.azure.database` (#4572): the
81
80
  * trade also asks Entra for a token Azure Database for PostgreSQL accepts.
82
81
  * A declaration that sets it needs this `minReader`.
83
82
  */
84
- export const AZURE_DATABASE_TOKEN_FLOOR = NEXT_RELEASE;
83
+ export const AZURE_DATABASE_TOKEN_FLOOR = "0.124.55";
85
84
 
86
85
  /** The Entra scope of Azure Database for PostgreSQL's sign-in tokens (#4572). */
87
86
  export const AZURE_DATABASE_SCOPE = "https://ossrdbms-aad.database.windows.net/.default";