@makaio/framework 1.0.0-dev-1788721567504 → 1.0.0-dev-1788832451167

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 (309) hide show
  1. package/dist/.makaio-build.json +2 -2
  2. package/dist/adapters/config/index.d.mts +1 -1
  3. package/dist/adapters/index.d.mts +2 -2
  4. package/dist/adapters/node.d.mts +1 -1
  5. package/dist/{artifact-Btbuib48.mjs → artifact-ClvHqL3w.mjs} +1 -1
  6. package/dist/attempt-fixtures-CnrnF5_4.mjs +1 -0
  7. package/dist/attempt-record-codec-B32Whx75.mjs +1 -0
  8. package/dist/authority-state-bootstrap-7Cgb9TR2.mjs +1 -0
  9. package/dist/bootstrap-start-client-DrvofWwi.mjs +1 -0
  10. package/dist/bus/index.d.mts +46 -28
  11. package/dist/bus/index.mjs +1 -1
  12. package/dist/bus-CobBUqjo.mjs +2 -0
  13. package/dist/bus-Uy9C3TBM.mjs +1 -0
  14. package/dist/clients/index.d.mts +1 -1
  15. package/dist/clients/managed-install.d.mts +1 -1
  16. package/dist/code-execution/worker-entry.d.mts +1 -1
  17. package/dist/{context-resolution-CoKFKIqz.d.mts → context-resolution-BrtoXnez.d.mts} +97 -18
  18. package/dist/contracts/adapter/index.d.mts +2 -2
  19. package/dist/contracts/adapter/schemas/session-lineage.d.mts +1 -1
  20. package/dist/contracts/artifact/index.d.mts +3 -3
  21. package/dist/contracts/artifact/index.mjs +1 -1
  22. package/dist/contracts/auth/index.d.mts +2 -2
  23. package/dist/contracts/automation-trigger/index.d.mts +3 -3
  24. package/dist/contracts/canonical-model/index.d.mts +1 -1
  25. package/dist/contracts/capabilities/index.d.mts +2 -2
  26. package/dist/contracts/client/index.d.mts +2 -2
  27. package/dist/contracts/code-execution/index.d.mts +1 -1
  28. package/dist/contracts/common/index.d.mts +1 -1
  29. package/dist/contracts/config/index.d.mts +1 -1
  30. package/dist/contracts/extension/index.d.mts +5 -5
  31. package/dist/contracts/facet/index.d.mts +1 -1
  32. package/dist/contracts/harness/index.d.mts +1 -1
  33. package/dist/contracts/host/index.d.mts +1 -1
  34. package/dist/contracts/index.d.mts +901 -183
  35. package/dist/contracts/index.mjs +1 -1
  36. package/dist/contracts/materialization/index.d.mts +3 -3
  37. package/dist/contracts/materialization/index.mjs +1 -1
  38. package/dist/contracts/model-registry/index.d.mts +1 -1
  39. package/dist/contracts/native-session-supervisor/index.d.mts +1 -1
  40. package/dist/contracts/platform/index.d.mts +1 -1
  41. package/dist/contracts/provider/index.d.mts +2 -2
  42. package/dist/contracts/reaction/index.d.mts +1 -1
  43. package/dist/contracts/session/index.d.mts +2 -2
  44. package/dist/contracts/shared/index.d.mts +2 -2
  45. package/dist/contracts/skill/index.d.mts +1 -1
  46. package/dist/contracts/telemetry/index.d.mts +1 -1
  47. package/dist/contracts/timeout/index.d.mts +1 -1
  48. package/dist/contracts/variant/index.d.mts +1 -1
  49. package/dist/contracts/worker/index.d.mts +2 -2
  50. package/dist/contracts/worker/index.mjs +1 -1
  51. package/dist/contracts/workflow/index.d.mts +2 -2
  52. package/dist/contracts/workflow/index.mjs +1 -1
  53. package/dist/{contribution-CUHLVLsT.d.mts → contribution-Crm-mctl.d.mts} +2 -2
  54. package/dist/{definition-DyGImhyi.d.mts → definition-u_5rYQtc.d.mts} +1 -1
  55. package/dist/{detached-extension-handle-D0aI0pJA.mjs → detached-extension-handle-DAXKQT9c.mjs} +1 -1
  56. package/dist/{execution-attempt-repository-CRdrgou3.d.mts → execution-attempt-repository-CgB7uiYD.d.mts} +242 -9
  57. package/dist/execution-attempt-repository-D0cCU7dI.mjs +1 -0
  58. package/dist/{execution-target-H0RWV7Py.mjs → execution-target-BcoF_oDB.mjs} +1 -1
  59. package/dist/{hook-responses-9Ywsqzzq.d.mts → hook-responses-DcapjzLb.d.mts} +1 -1
  60. package/dist/{index-D1wTWSLR.d.mts → index-BADuMxcP.d.mts} +458 -458
  61. package/dist/{index-8NdPPzUh2.d.mts → index-BDAfOYSw2.d.mts} +12 -12
  62. package/dist/{index-DHnSLGP4.d.mts → index-BDzqNCXs.d.mts} +1 -1
  63. package/dist/{index-CxwqnZpT.d.mts → index-BakMNLkB.d.mts} +175 -80
  64. package/dist/{index-B0VO0rAl.d.mts → index-Bo3LRb2u.d.mts} +1 -1
  65. package/dist/{index-CVcG4Q3X.d.mts → index-Bsr4rZl0.d.mts} +13 -13
  66. package/dist/{index-B_8bA2JW.d.mts → index-BvgLFm-U.d.mts} +1 -1
  67. package/dist/{index-Dg11JxKZ.d.mts → index-BwccWakG.d.mts} +1 -1
  68. package/dist/{index-BJdkVFX9.d.mts → index-BxOFB25y.d.mts} +335 -78
  69. package/dist/{index-37_b--BH.d.mts → index-C1PfDEIV.d.mts} +52 -47
  70. package/dist/{index-CPRQ4dWX.d.mts → index-CBixkF0n.d.mts} +12 -0
  71. package/dist/{index-CyWGSxrs.d.mts → index-CGJgZGqN.d.mts} +292 -292
  72. package/dist/{index--Ws52sWV2.d.mts → index-COOM1j_L2.d.mts} +4 -4
  73. package/dist/{index-BmevAPME2.d.mts → index-Cbv_3Xi12.d.mts} +1 -1
  74. package/dist/{index-DWBkiiXH.d.mts → index-CfJKwWJa.d.mts} +1 -1
  75. package/dist/{index-DV38-klA2.d.mts → index-CiKzWCW02.d.mts} +273 -26
  76. package/dist/{index-AdcDBUnc.d.mts → index-D6RMsZko.d.mts} +95 -95
  77. package/dist/{index-CIEycZrt.d.mts → index-DIhkK4Y0.d.mts} +1 -1
  78. package/dist/{index-BKIxdzIw.d.mts → index-DZXpKlyB.d.mts} +21 -21
  79. package/dist/{index-DBD_oFEt2.d.mts → index-DZnb56vt2.d.mts} +1 -1
  80. package/dist/{index-Cny5RvjO.d.mts → index-J-kv32zv.d.mts} +2 -2
  81. package/dist/{index-BNzUyVwV.d.mts → index-LOh6AEqx.d.mts} +10 -10
  82. package/dist/{index-CYjgoYeX.d.mts → index-LryUXslm.d.mts} +3 -3
  83. package/dist/{index-CFI6FxC7.d.mts → index-QJW9g1mG.d.mts} +2 -2
  84. package/dist/{index-B0yMCJW8.d.mts → index-rygpcDBV.d.mts} +1 -1
  85. package/dist/{index-I5a37JCm.d.mts → index-vXmPEZ5O.d.mts} +382 -82
  86. package/dist/kernel/cli/index.d.mts +2 -2
  87. package/dist/kernel/cli/register.d.mts +1 -1
  88. package/dist/kernel/extension/index.d.mts +1 -1
  89. package/dist/kernel/index.d.mts +5 -5
  90. package/dist/kernel/namespace/index.d.mts +1 -1
  91. package/dist/kernel/observability/index.d.mts +1 -1
  92. package/dist/kernel/providers/index.d.mts +1 -1
  93. package/dist/kernel/window/index.d.mts +1 -1
  94. package/dist/{lib-Cm-uEoC1.mjs → lib-271rPR7A.mjs} +1 -1
  95. package/dist/{lib-BpGvHZye.mjs → lib-RFpLjUda.mjs} +1 -1
  96. package/dist/{load-extensions-BQoXaHhR.d.mts → load-extensions-CY8ELnCp.d.mts} +1 -1
  97. package/dist/{load-extensions-DG5LvPyM.mjs → load-extensions-D9inWcDy.mjs} +1 -1
  98. package/dist/{materialization-lVd9_-jr.mjs → materialization-B_LA9pfy.mjs} +1 -1
  99. package/dist/{namespace-DOezqDti.d.mts → namespace-BymM0nl_.d.mts} +27 -27
  100. package/dist/{namespace-Bo94cenp.d.mts → namespace-Cs-cOyrn.d.mts} +136 -136
  101. package/dist/{namespace-BdAK0lD8.d.mts → namespace-DdqVQSyc.d.mts} +2 -2
  102. package/dist/{namespace-BRuHzhPo.d.mts → namespace-DlrX8feY.d.mts} +45 -45
  103. package/dist/{namespace-CsnrP8AD.d.mts → namespace-Dw5H_KCF.d.mts} +1 -1
  104. package/dist/{namespace-CstawJgN.d.mts → namespace-DykqxEyX.d.mts} +2 -2
  105. package/dist/node/bus-server/index.d.mts +1 -1
  106. package/dist/node/bus-server/server-lifecycle.d.mts +1 -1
  107. package/dist/node/transports/index.d.mts +56 -16
  108. package/dist/node/transports/index.mjs +2 -2
  109. package/dist/package-CzKoZ1k0.mjs +7 -0
  110. package/dist/{package-DkZmsdCd.d.mts → package-DkpF17X_.d.mts} +458 -17
  111. package/dist/package.json +1 -1
  112. package/dist/rules/index.d.mts +1 -1
  113. package/dist/rules/schemas.d.mts +1 -1
  114. package/dist/runtime-bun/index.mjs +1 -1
  115. package/dist/runtime-node/code-execution/index.d.mts +2 -2
  116. package/dist/runtime-node/extension-discovery.d.mts +1 -1
  117. package/dist/runtime-node/extension-validation.d.mts +1 -1
  118. package/dist/runtime-node/extension-validation.mjs +1 -1
  119. package/dist/runtime-node/index.d.mts +6 -6
  120. package/dist/runtime-node/index.mjs +24 -24
  121. package/dist/runtime-node/makaio-config.d.mts +1 -1
  122. package/dist/runtime-node/workflow-execution-bus-access.mjs +1 -1
  123. package/dist/runtime-node/workflow-worker/index.d.mts +2 -2
  124. package/dist/runtime-node/workflow-worker/index.mjs +1 -1
  125. package/dist/runtime-node/workflow-worker/worker-entry.d.mts +22 -2
  126. package/dist/runtime-node/workflow-worker/worker-entry.mjs +1 -1
  127. package/dist/{schema-B3Pf7JP7.d.mts → schema-C9PauHXt.d.mts} +2 -2
  128. package/dist/{schemas-CJKHYluy.d.mts → schemas-B2UbGJpJ.d.mts} +15 -15
  129. package/dist/{schemas-B50oWBuj.d.mts → schemas-BDZFd3Wb.d.mts} +2 -2
  130. package/dist/schemas-CNkUEbIr.mjs +1 -0
  131. package/dist/schemas-CeHU889f.mjs +1 -0
  132. package/dist/{schemas-DTJtS14K.d.mts → schemas-ClGDFa44.d.mts} +136 -136
  133. package/dist/scoped-bus-DwVrmi_1.mjs +1 -0
  134. package/dist/services/adapter-runtime/index.d.mts +3 -3
  135. package/dist/services/adapter-runtime/namespace.d.mts +1 -1
  136. package/dist/services/adapter-runtime/schemas.d.mts +1 -1
  137. package/dist/services/adapter-subsystem/index.d.mts +3 -3
  138. package/dist/services/adapter-subsystem/namespace.d.mts +1 -1
  139. package/dist/services/agent-runtime/index.d.mts +2 -2
  140. package/dist/services/agent-runtime/namespace.d.mts +1 -1
  141. package/dist/services/agent-runtime/schemas.d.mts +1 -1
  142. package/dist/services/capability/index.d.mts +2 -2
  143. package/dist/services/code-execution/index.d.mts +1 -1
  144. package/dist/services/codebase/index.d.mts +2 -2
  145. package/dist/services/codebase/namespace.d.mts +1 -1
  146. package/dist/services/codebase/schemas.d.mts +1 -1
  147. package/dist/services/compression/index.d.mts +2 -2
  148. package/dist/services/compression/namespace.d.mts +1 -1
  149. package/dist/services/compression/schemas.d.mts +1 -1
  150. package/dist/services/context-rules/index.d.mts +4 -4
  151. package/dist/services/execution-target/index.d.mts +3 -3
  152. package/dist/services/execution-target/index.mjs +1 -1
  153. package/dist/services/execution-target/namespace.d.mts +1 -1
  154. package/dist/services/execution-target/namespace.mjs +1 -1
  155. package/dist/services/execution-target/schemas.d.mts +1 -1
  156. package/dist/services/execution-target/schemas.mjs +1 -1
  157. package/dist/services/filesystem/index.d.mts +1 -1
  158. package/dist/services/filesystem/namespace.d.mts +6 -6
  159. package/dist/services/filesystem/schemas.d.mts +3 -3
  160. package/dist/services/index.d.mts +124 -122
  161. package/dist/services/index.mjs +1 -1
  162. package/dist/services/log-import/browser.d.mts +2 -2
  163. package/dist/services/log-import/index.d.mts +2 -2
  164. package/dist/services/log-import/log-import.d.mts +1 -1
  165. package/dist/services/materialization/index.d.mts +1 -1
  166. package/dist/services/model-registry/index.d.mts +1 -1
  167. package/dist/services/preferences/index.d.mts +2 -2
  168. package/dist/services/preferences/schemas.d.mts +1 -1
  169. package/dist/services/preferences/storage-namespace.d.mts +2 -2
  170. package/dist/services/provider-context/index.d.mts +1 -1
  171. package/dist/services/session/handlers/index.d.mts +1 -1
  172. package/dist/services/session/index.d.mts +9 -9
  173. package/dist/services/session/messages/namespace.d.mts +1 -1
  174. package/dist/services/session/orchestrator-testing/index.d.mts +1 -1
  175. package/dist/services/session/session-events/namespace.d.mts +1 -1
  176. package/dist/services/session/storage/namespace.d.mts +1 -1
  177. package/dist/services/session/storage/schema.d.mts +1 -1
  178. package/dist/services/session/testing/orchestrator-shared.d.mts +1 -1
  179. package/dist/services/session/turns/namespace.d.mts +1 -1
  180. package/dist/services/session-editor/index.d.mts +1 -1
  181. package/dist/services/settings/index.d.mts +3 -3
  182. package/dist/services/settings/namespace.d.mts +12 -12
  183. package/dist/services/settings/storage/clients-namespace.d.mts +1 -1
  184. package/dist/services/settings/storage/extension-configs/namespace.d.mts +3 -3
  185. package/dist/services/settings/storage/index.d.mts +3 -3
  186. package/dist/services/settings/storage/providers-namespace.d.mts +1 -1
  187. package/dist/services/subagent/index.d.mts +1 -1
  188. package/dist/services/subagent-template/index.d.mts +2 -2
  189. package/dist/services/subagent-template/namespace.d.mts +1 -1
  190. package/dist/services/subagent-template/schemas.d.mts +1 -1
  191. package/dist/services/tool-approval/index.d.mts +1 -1
  192. package/dist/services/tools/index.d.mts +1 -1
  193. package/dist/services/tray-menu/index.d.mts +3 -3
  194. package/dist/services/tray-menu/namespace.d.mts +1 -1
  195. package/dist/services/tray-menu/schemas.d.mts +1 -1
  196. package/dist/services/turn/index.d.mts +1 -1
  197. package/dist/services/turn/namespace.d.mts +1 -1
  198. package/dist/services/workflow-transitions/index.d.mts +1 -1
  199. package/dist/{src-BmSQ3rlz.mjs → src-DEgV239R.mjs} +1 -1
  200. package/dist/storage/drizzle/client.d.mts +1 -1
  201. package/dist/storage/drizzle/index.d.mts +1 -1
  202. package/dist/storage/handlers/drizzle/index.d.mts +1 -1
  203. package/dist/storage/handlers/index.d.mts +1 -1
  204. package/dist/{transition-DxsrTsn4.d.mts → transition-DFA_ckdP.d.mts} +2 -2
  205. package/dist/{types-Czdm5op1.d.mts → types-DkfDRSTr.d.mts} +356 -356
  206. package/dist/{types-CtDGkyLx2.d.mts → types-p55qvq922.d.mts} +1 -1
  207. package/dist/ui-kernel/index.d.mts +1 -1
  208. package/dist/ui-kernel/pages/schemas.d.mts +1 -1
  209. package/dist/{view-builder-D-Wz_l_B.d.mts → view-builder-CYW_9n4A.d.mts} +1 -1
  210. package/dist/worker-B4nD_Erm.mjs +1 -0
  211. package/dist/{workflow-BomH9DBB.mjs → workflow-H8hsEikC.mjs} +1 -1
  212. package/dist/workflow-engine/execution-attempt-repository.d.mts +2 -2
  213. package/dist/workflow-engine/execution-attempt-repository.mjs +1 -1
  214. package/dist/workflow-engine/index.d.mts +300 -216
  215. package/dist/workflow-engine/index.mjs +1 -1
  216. package/dist/workflow-engine/package.d.mts +1 -1
  217. package/dist/workflow-engine/package.mjs +1 -1
  218. package/dist/workflow-engine/provider-operation.d.mts +1 -1
  219. package/dist/workflow-engine/testing/conformance.d.mts +85 -0
  220. package/dist/workflow-engine/testing/conformance.mjs +1 -0
  221. package/dist/workflow-engine/testing/index.d.mts +12 -5
  222. package/dist/workflow-engine/testing/index.mjs +1 -1
  223. package/dist/workflow-engine/testing/sqlite.d.mts +1 -1
  224. package/dist/workflow-engine/testing/sqlite.mjs +75 -46
  225. package/dist/workflow-engine/workflow-orchestrator.mjs +1 -1
  226. package/dist/workflow-worker-CmIkKnpF.mjs +2 -0
  227. package/package.json +13 -1
  228. package/dist/attempt-record-codec-BORASgzn.mjs +0 -1
  229. package/dist/authority-state-bootstrap-eitx6Ukn.mjs +0 -1
  230. package/dist/bus-D6NoBhIV.mjs +0 -2
  231. package/dist/bus-UgFdHybD.mjs +0 -1
  232. package/dist/package-UemD2NWn.mjs +0 -7
  233. package/dist/runtime-registration-client-BTtFpt_k.mjs +0 -1
  234. package/dist/schemas-C3kyQWGf.mjs +0 -1
  235. package/dist/schemas-TK29KWx-.mjs +0 -1
  236. package/dist/scoped-bus-DoPmCJeM.mjs +0 -1
  237. package/dist/worker-DlRdLf2d.mjs +0 -1
  238. package/dist/workflow-worker-DjUfKshi.mjs +0 -1
  239. /package/dist/{adapter-binding-CATvmGuz.d.mts → adapter-binding-D68U_Hmh.d.mts} +0 -0
  240. /package/dist/{base-orchestrator-B4YW6z_Q.d.mts → base-orchestrator-DA95InJU.d.mts} +0 -0
  241. /package/dist/{capability-service-BW1-teFU.d.mts → capability-service-s4ZYSEWc.d.mts} +0 -0
  242. /package/dist/{client-binary-version-verifier-lcv83Hq3.d.mts → client-binary-version-verifier-kd9LP9AQ.d.mts} +0 -0
  243. /package/dist/{client-BG0WX5Vz.d.mts → client-f5A-6La5.d.mts} +0 -0
  244. /package/dist/{clients-namespace-DLAjOTTb.d.mts → clients-namespace-q4PqU1cA.d.mts} +0 -0
  245. /package/dist/{config-namespace-CH7sJZ4f.d.mts → config-namespace-Cp71zTT0.d.mts} +0 -0
  246. /package/dist/{create-static-mount-DxuixuLZ.mjs → create-static-mount-CmQgA0jq.mjs} +0 -0
  247. /package/dist/{definition-BrgzUuFk.d.mts → definition-BHSzhrUf.d.mts} +0 -0
  248. /package/dist/{extension-context-QmFuHdq5.d.mts → extension-context-BmU5XKjI.d.mts} +0 -0
  249. /package/dist/{extension-discovery-Dhu3WplO.d.mts → extension-discovery-DnO7bINK.d.mts} +0 -0
  250. /package/dist/{filesystem-service-ZJ43SbBi.d.mts → filesystem-service-BBArEDPL.d.mts} +0 -0
  251. /package/dist/{index-BC-6qNeo.d.mts → index-B-zl-O-Y.d.mts} +0 -0
  252. /package/dist/{index-BfV8U4XX.d.mts → index-BB0HypzC.d.mts} +0 -0
  253. /package/dist/{index-8y4hT9WL.d.mts → index-Bf2MgOni.d.mts} +0 -0
  254. /package/dist/{index-B4svZC6L.d.mts → index-C9xVZ-gt.d.mts} +0 -0
  255. /package/dist/{index-kzIjbrS02.d.mts → index-CDLf3Fka2.d.mts} +0 -0
  256. /package/dist/{index-BuMsrli0.d.mts → index-CPWBGotQ.d.mts} +0 -0
  257. /package/dist/{index-pvX-BIpr2.d.mts → index-CcrXttC02.d.mts} +0 -0
  258. /package/dist/{index-B5dP8rj6.d.mts → index-CkpR5sIH.d.mts} +0 -0
  259. /package/dist/{index-CmbkCxj-.d.mts → index-Co1da7YK.d.mts} +0 -0
  260. /package/dist/{index-VzLAV0Yt.d.mts → index-CrcfeFOo.d.mts} +0 -0
  261. /package/dist/{index-BM56936c.d.mts → index-CsFN2nv7.d.mts} +0 -0
  262. /package/dist/{index-CVpaGijY.d.mts → index-D-JbTXIH.d.mts} +0 -0
  263. /package/dist/{index-l01zsChf.d.mts → index-D94yE5Dr.d.mts} +0 -0
  264. /package/dist/{index-D037TVsm.d.mts → index-DQD2-jcL.d.mts} +0 -0
  265. /package/dist/{index-D8D-yibS2.d.mts → index-DSLTgc7h2.d.mts} +0 -0
  266. /package/dist/{index-CL0Jo1b92.d.mts → index-DSN2t48K.d.mts} +0 -0
  267. /package/dist/{index-DQ8o3JGi.d.mts → index-DW4SE_sH.d.mts} +0 -0
  268. /package/dist/{index-DgspOUa72.d.mts → index-DYHxzwok2.d.mts} +0 -0
  269. /package/dist/{index-BMRB9yhF.d.mts → index-D_sMzTvv.d.mts} +0 -0
  270. /package/dist/{index-BFWvT0NG.d.mts → index-Df1c_2PF.d.mts} +0 -0
  271. /package/dist/{index-B2Y1Wvbh.d.mts → index-Dn_SGTgp.d.mts} +0 -0
  272. /package/dist/{index-C4V8Pmi4.d.mts → index-KAAnSRZt.d.mts} +0 -0
  273. /package/dist/{index-Ek4y8M9J2.d.mts → index-NhW2h2wH2.d.mts} +0 -0
  274. /package/dist/{index-CqdMbYmR.d.mts → index-mK-rgiit.d.mts} +0 -0
  275. /package/dist/{index-BTEJfzjE.d.mts → index-xaBSwHxJ.d.mts} +0 -0
  276. /package/dist/{json-value-DPqb-SJ8.d.mts → json-value-pX6xnLGw.d.mts} +0 -0
  277. /package/dist/{jsonl-transport-Cyyh5Wje.mjs → jsonl-transport-DQIlRX_y.mjs} +0 -0
  278. /package/dist/{lib-BqV8hYtk.mjs → lib-6eNAiNK7.mjs} +0 -0
  279. /package/dist/{namespace-DBO1OzYB.d.mts → namespace-9ychTEk_.d.mts} +0 -0
  280. /package/dist/{namespace-CVFaZv8x.d.mts → namespace-BGDq7HmW.d.mts} +0 -0
  281. /package/dist/{namespace-K23m4b0n.d.mts → namespace-BMG3RCdr.d.mts} +0 -0
  282. /package/dist/{namespace-CPm9dhi2.d.mts → namespace-BoyqQiW9.d.mts} +0 -0
  283. /package/dist/{namespace-BUYDmd0r.d.mts → namespace-CPR2xem0.d.mts} +0 -0
  284. /package/dist/{namespace-CPG6u60N.d.mts → namespace-CQEYu8az.d.mts} +0 -0
  285. /package/dist/{namespace-DqZweTbX.d.mts → namespace-CVg_cpkh.d.mts} +0 -0
  286. /package/dist/{namespace-B0ftHlK3.d.mts → namespace-DG0hjPcx.d.mts} +0 -0
  287. /package/dist/{orchestrator-shared-CNHSImNY.d.mts → orchestrator-shared-BzqqcY2z.d.mts} +0 -0
  288. /package/dist/{packages-CxPMEg8D.d.mts → packages-Cx-BwSZr.d.mts} +0 -0
  289. /package/dist/{provider-operation-DbdyFwNm.d.mts → provider-operation-B2wQST6N.d.mts} +0 -0
  290. /package/dist/{providers-namespace-CfZKp-C0.d.mts → providers-namespace-DsKTnuO1.d.mts} +0 -0
  291. /package/dist/{schemas-ChmQldVH.d.mts → schemas--LAbwXvw.d.mts} +0 -0
  292. /package/dist/{schemas-CF8QwRqt.d.mts → schemas-Bk50UoMA.d.mts} +0 -0
  293. /package/dist/{schemas-BCXvEWyF.d.mts → schemas-CBpjAhut.d.mts} +0 -0
  294. /package/dist/{schemas-bfZNpl0B.d.mts → schemas-CHRuwe18.d.mts} +0 -0
  295. /package/dist/{schemas-BGvkTiCx.d.mts → schemas-CzGN0eqW.d.mts} +0 -0
  296. /package/dist/{schemas-Pe892GgN.d.mts → schemas-DmULJ7Jk.d.mts} +0 -0
  297. /package/dist/{schemas-B6Q-qdmn.d.mts → schemas-Dxvjq-Bi.d.mts} +0 -0
  298. /package/dist/{schemas-CenET9Cq.d.mts → schemas-Wqo3_F6-.d.mts} +0 -0
  299. /package/dist/{server-lifecycle-L8zja8t8.d.mts → server-lifecycle-WFZcCMwF.d.mts} +0 -0
  300. /package/dist/{session-lineage-bUkd3fqx.d.mts → session-lineage-C9kppcCa.d.mts} +0 -0
  301. /package/dist/{src-BacfeiI4.mjs → src-DIyWekjW.mjs} +0 -0
  302. /package/dist/{storage-namespace-YmE8XCCL.d.mts → storage-namespace-BWU-8rvj.d.mts} +0 -0
  303. /package/dist/{storage-namespace-definition-BsnYAPot.d.mts → storage-namespace-definition-B-8JKvzm.d.mts} +0 -0
  304. /package/dist/{types-DdpSEmTO.d.mts → types-8rMNe3AS.d.mts} +0 -0
  305. /package/dist/{types-DnK6Wa_Y.d.mts → types-BFeWU3WM.d.mts} +0 -0
  306. /package/dist/{types-tyv0B605.d.mts → types-BnPJa-C_.d.mts} +0 -0
  307. /package/dist/{types-OKJCOjme.d.mts → types-DQTCNM2i.d.mts} +0 -0
  308. /package/dist/{types-BlB23n4f.d.mts → types-DxHeL0pF.d.mts} +0 -0
  309. /package/dist/{window-registry-Pcf35cac.d.mts → window-registry-DQP5P2_0.d.mts} +0 -0
@@ -1 +1 @@
1
- import{B as e,H as t,M as n,P as r,T as i,W as a,X as o,et as s,g as c,it as l,j as u,ot as d}from"../authority-state-bootstrap-eitx6Ukn.mjs";import{a as f,c as p,d as m,f as h,h as g,i as _,l as v,m as y,n as b,o as x,p as S,r as C,s as w,t as T,u as E}from"../package-UemD2NWn.mjs";import{assertWorkflowTriggerPayload as D,compileWorkflowTriggerBindingFilter as O}from"./workflow-trigger-binding-consumer.mjs";import{ATTEMPT_OPERATION_START_GATES as k,DuplicateExecutionAttemptError as A,EXECUTION_ATTEMPT_SETTLEMENT_KINDS as j,EXECUTION_ATTEMPT_STATUSES as M,decodeDurableOutcome as N,durableOutcome as P,sameAllocationRef as F,sameDurableOutcome as I}from"./execution-attempt-repository.mjs";import{PROVIDER_OPERATION_OBLIGATIONS as L}from"./provider-operation.mjs";import{JsonValueSchema as R,WorkflowFrameStateSchema as z}from"@makaio/framework/contracts";const B=new Set([...z.shape.status.options]);function V(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function H(e){if(!V(e))return!1;for(let t of Object.values(e))if(!V(t)||typeof t.status!=`string`||!B.has(t.status)||`result`in t&&t.result!==void 0&&!R.safeParse(t.result).success)return!1;return!0}function U(e){let t={trigger:V(e.trigger)?e.trigger:{},steps:H(e.steps)?e.steps:{},inputs:R.safeParse(e.inputs).success?e.inputs:{}};return`item`in e&&(t.item=e.item),typeof e.index==`number`&&(t.index=e.index),t}export{k as ATTEMPT_OPERATION_START_GATES,A as DuplicateExecutionAttemptError,j as EXECUTION_ATTEMPT_SETTLEMENT_KINDS,M as EXECUTION_ATTEMPT_STATUSES,f as ExecutionAttemptAuthority,L as PROVIDER_OPERATION_OBLIGATIONS,v as RUNTIME_PROBE_DELIVERY_TIMEOUT_MS,_ as WorkflowEngineService,T as WorkflowEngineToken,w as WorkflowExecutor,u as WorkflowStorageNamespace,n as WorkflowStorageSubjects,x as WorkflowTriggerReconciler,D as assertWorkflowTriggerPayload,U as buildWorkflowExpressionContextFromResolvedInputs,O as compileWorkflowTriggerBindingFilter,b as createWorkflowEnginePackage,N as decodeDurableOutcome,P as durableOutcome,S as getWorkflowState,y as initializeWorkflowState,g as patchWorkflowState,h as registerDrizzleWorkflowStorage,p as registerOperationAdmissionHandler,E as registerRuntimeRegistrationHandler,c as runAuthorityDispatchedAttempt,i as runShellStep,F as sameAllocationRef,I as sameDurableOutcome,m as submitAttemptOutcome,r as workflowDefinitionsDual,C as workflowEnginePackage,e as workflowExecutionStateDual,t as workflowExecutionStateEventsDual,a as workflowExecutionsDual,d as workflowFinalizationsDual,o as workflowStepSpansDual,s as worklogFrameEntriesDual,l as worklogSummariesDual};
1
+ import{B as e,C as t,E as n,F as ee,H as te,Q as r,S as i,T as a,V as o,W as s,X as c,_ as l,b as u,et as d,gt as f,mt as p,ot as m,ut as h,v as g,w as _,x as v,y}from"../authority-state-bootstrap-7Cgb9TR2.mjs";import{_ as b,a as x,c as S,d as C,f as w,g as T,h as E,i as D,l as O,m as k,n as A,o as ne,p as j,r as M,s as N,t as P,u as F}from"../package-CzKoZ1k0.mjs";import{_ as I,a as L,c as R,d as z,f as B,g as V,h as H,i as U,l as W,n as G,o as K,p as q,r as J,s as Y,t as X,u as Z}from"../execution-attempt-repository-D0cCU7dI.mjs";import{assertWorkflowTriggerPayload as re,compileWorkflowTriggerBindingFilter as ie}from"./workflow-trigger-binding-consumer.mjs";import{PROVIDER_OPERATION_OBLIGATIONS as ae}from"./provider-operation.mjs";import{JsonValueSchema as Q,WorkflowFrameStateSchema as oe}from"@makaio/framework/contracts";const se=new Set([...oe.shape.status.options]);function $(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ce(e){if(!$(e))return!1;for(let t of Object.values(e))if(!$(t)||typeof t.status!=`string`||!se.has(t.status)||`result`in t&&t.result!==void 0&&!Q.safeParse(t.result).success)return!1;return!0}function le(e){let t={trigger:$(e.trigger)?e.trigger:{},steps:ce(e.steps)?e.steps:{},inputs:Q.safeParse(e.inputs).success?e.inputs:{}};return`item`in e&&(t.item=e.item),typeof e.index==`number`&&(t.index=e.index),t}export{X as ATTEMPT_OPERATION_START_GATES,G as DuplicateExecutionAttemptError,J as EXECUTION_ATTEMPT_SETTLEMENT_KINDS,U as EXECUTION_ATTEMPT_STATUSES,x as ExecutionAttemptAuthority,ae as PROVIDER_OPERATION_OBLIGATIONS,O as RUNTIME_PROBE_DELIVERY_TIMEOUT_MS,L as RuntimeOutcomeFenceMismatchError,v as WORKFLOW_WORKLOAD_KIND,i as WORKFLOW_WORKLOAD_VERSION,l as WorkflowAttemptOutcomeSchema,D as WorkflowEngineService,P as WorkflowEngineToken,N as WorkflowExecutor,t as WorkflowInvocationInputSchema,o as WorkflowStorageNamespace,te as WorkflowStorageSubjects,ne as WorkflowTriggerReconciler,K as assertRuntimeOutcomeFence,re as assertWorkflowTriggerPayload,_ as buildWorkflowAttemptInstruction,le as buildWorkflowExpressionContextFromResolvedInputs,ie as compileWorkflowTriggerBindingFilter,A as createWorkflowEnginePackage,Y as decodeDurableOutcome,g as decodeWorkflowAttemptOutcome,R as durableOutcome,z as evaluateAttemptReachability,B as evaluateOperationAdmission,q as evaluateOperationCompletion,H as evaluateProvisionerIncarnationLoss,V as evaluateRuntimeReadiness,I as evaluateRuntimeRegistration,E as getWorkflowState,T as initializeWorkflowState,a as parseWorkflowAttemptInstruction,b as patchWorkflowState,S as registerBootstrapStartHandler,k as registerDrizzleWorkflowStorage,w as registerExecutionAttemptHandlers,C as registerOperationAdmissionHandler,F as registerRuntimeRegistrationHandler,e as resolveExecutionAttemptPeer,n as runAuthorityDispatchedAttempt,ee as runShellStep,W as sameAllocationRef,Z as sameDurableOutcome,j as submitAttemptOutcome,y as toCommittedWorkflowRunnerResult,u as workflowAttemptOutcomeCodec,s as workflowDefinitionsDual,M as workflowEnginePackage,c as workflowExecutionStateDual,r as workflowExecutionStateEventsDual,d as workflowExecutionsDual,f as workflowFinalizationsDual,m as workflowStepSpansDual,h as worklogFrameEntriesDual,p as worklogSummariesDual};
@@ -1,2 +1,2 @@
1
- import { n as createWorkflowEnginePackage, r as workflowEnginePackage, t as WorkflowEngineToken } from "../package-DkZmsdCd.mjs";
1
+ import { n as createWorkflowEnginePackage, r as workflowEnginePackage, t as WorkflowEngineToken } from "../package-DkpF17X_.mjs";
2
2
  export { WorkflowEngineToken, createWorkflowEnginePackage, workflowEnginePackage };
@@ -1 +1 @@
1
- import{n as e,r as t,t as n}from"../package-UemD2NWn.mjs";export{n as WorkflowEngineToken,e as createWorkflowEnginePackage,t as workflowEnginePackage};
1
+ import{n as e,r as t,t as n}from"../package-CzKoZ1k0.mjs";export{n as WorkflowEngineToken,e as createWorkflowEnginePackage,t as workflowEnginePackage};
@@ -1,2 +1,2 @@
1
- import { a as ProviderOperationClaim, c as ProviderOperationObligation, i as ProcessBoundProvisionerLossProof, l as ProviderOperationOwnershipRecord, n as InitialProviderOperationClaimContextSource, o as ProviderOperationClaimDecision, r as PROVIDER_OPERATION_OBLIGATIONS, s as ProviderOperationMutationDecision, t as InitialProviderOperationClaimContext } from "../provider-operation-DbdyFwNm.mjs";
1
+ import { a as ProviderOperationClaim, c as ProviderOperationObligation, i as ProcessBoundProvisionerLossProof, l as ProviderOperationOwnershipRecord, n as InitialProviderOperationClaimContextSource, o as ProviderOperationClaimDecision, r as PROVIDER_OPERATION_OBLIGATIONS, s as ProviderOperationMutationDecision, t as InitialProviderOperationClaimContext } from "../provider-operation-B2wQST6N.mjs";
2
2
  export { InitialProviderOperationClaimContext, InitialProviderOperationClaimContextSource, PROVIDER_OPERATION_OBLIGATIONS, ProcessBoundProvisionerLossProof, ProviderOperationClaim, ProviderOperationClaimDecision, ProviderOperationMutationDecision, ProviderOperationObligation, ProviderOperationOwnershipRecord };
@@ -0,0 +1,85 @@
1
+ import { C as ExecutionAttemptRepository, P as OutcomeCodec } from "../../execution-attempt-repository-CgB7uiYD.mjs";
2
+
3
+ //#region subsystems/workflow-engine/src/testing/conformance/types.d.ts
4
+ /** Narrow fixture input for recovery's oldest-first, identifier-tiebreak ordering contract. */
5
+ interface RecoverableAttemptsSeed {
6
+ /** Owner shared by all candidates created by this fixture. */
7
+ readonly executionId: string;
8
+ /** Fresh candidate identifiers and creation instants, in the insertion order to seed. */
9
+ readonly entries: readonly {
10
+ readonly executionAttemptId: string; /** Canonical UTC ISO-8601 instant with millisecond precision. */
11
+ readonly createdAt: string;
12
+ }[];
13
+ }
14
+ /**
15
+ * One isolated, recovery-capable realization exercised by the conformance suite.
16
+ * @typeParam TOutcome - Owner-specific outcome reconstructed by the injected codec.
17
+ */
18
+ interface ExecutionAttemptRepositoryContractHarness<TOutcome> {
19
+ /** Primary controller exposing the complete repository port, including recovery. */
20
+ readonly repository: Required<ExecutionAttemptRepository<TOutcome>>;
21
+ /** Independent controller sharing the primary controller's durable state. */
22
+ readonly peer: Required<ExecutionAttemptRepository<TOutcome>>;
23
+ /**
24
+ * Replace stored outcome text directly, bypassing validation by the port.
25
+ * This test-only hook represents corrupt durable data or a changed codec;
26
+ * it must not create another attempt or change the active-attempt pointer.
27
+ * @param executionAttemptId - Existing attempt whose outcome text to replace.
28
+ * @param text - Durable outcome text to store verbatim.
29
+ */
30
+ readonly writeStoredOutcomeText: (executionAttemptId: string, text: string) => Promise<void>;
31
+ /**
32
+ * Replace the host-owned bootstrap-claim expiry directly, bypassing the
33
+ * repository port. This fixture hook models the host path that issues
34
+ * bootstrap claims; it must not change any other attempt field.
35
+ * @param executionAttemptId - Existing attempt whose claim expiry to replace.
36
+ * @param claimExpiresAt - Canonical expiry instant, or `null` for no expiry.
37
+ */
38
+ readonly setClaimExpiry: (executionAttemptId: string, claimExpiresAt: string | null) => Promise<void>;
39
+ /**
40
+ * Seed a legacy null bootstrap deadline without changing any other attempt fact.
41
+ * @param executionAttemptId - Existing attempt whose stored bootstrap deadline to clear.
42
+ */
43
+ readonly clearStoredBootstrapDeadline: (executionAttemptId: string) => Promise<void>;
44
+ /**
45
+ * Seed complete allocated, unsettled, claimable candidates with no claim expiry.
46
+ * Preserve the supplied insertion order and creation instants. Include valid
47
+ * provider binding and operation state required by the backend. Unlike ordinary
48
+ * replacement, this testing-only fixture keeps every supplied candidate eligible
49
+ * for recovery after all entries are created; it does not accept arbitrary rows.
50
+ * @param input - One owner and fresh candidate identifiers with canonical creation instants.
51
+ */
52
+ readonly seedRecoverableAttempts: (input: RecoverableAttemptsSeed) => Promise<void>;
53
+ /** Close both controllers and remove resources owned by this harness. */
54
+ readonly dispose: () => void | Promise<void>;
55
+ }
56
+ /** Configuration passed to the callable Vitest repository conformance suite. */
57
+ interface ExecutionAttemptRepositoryContractFactory {
58
+ /** Realization label included in test names, for example `postgres`. */
59
+ readonly name: string;
60
+ /**
61
+ * Create fresh, isolated storage with two independent controllers.
62
+ * Every call must honor the supplied codec, including non-workflow outcomes.
63
+ * If initialization fails, release partially opened resources before rejecting;
64
+ * the suite can dispose only a harness this factory successfully returns.
65
+ * @param codec - Codec both controllers use to validate and persist outcomes.
66
+ * @returns Initialized harness, owned by the suite until its teardown.
67
+ * @typeParam TOutcome - Owner-specific outcome type for this contract group.
68
+ */
69
+ create<TOutcome>(codec: OutcomeCodec<TOutcome>): Promise<ExecutionAttemptRepositoryContractHarness<TOutcome>>;
70
+ }
71
+ //#endregion
72
+ //#region subsystems/workflow-engine/src/testing/conformance.d.ts
73
+ /**
74
+ * Register repository conformance tests synchronously in a Vitest test file.
75
+ *
76
+ * The factory is invoked during setup, once per contract group, with fresh
77
+ * storage and the group's codec. The suite checks the recovery-capable port's
78
+ * persistence semantics, including immutable instructions, Preparation receipts, runtime fences,
79
+ * competing controllers, and owner-defined outcome representations. Driver or
80
+ * schema-specific assertions remain the adapter's own responsibility.
81
+ * @param factory - Named realization and its isolated-storage factory.
82
+ */
83
+ declare function runExecutionAttemptRepositoryContract(factory: ExecutionAttemptRepositoryContractFactory): void;
84
+ //#endregion
85
+ export { type ExecutionAttemptRepositoryContractFactory, type ExecutionAttemptRepositoryContractHarness, type RecoverableAttemptsSeed, runExecutionAttemptRepositoryContract };
@@ -0,0 +1 @@
1
+ import{a as e,n as t}from"../../execution-attempt-repository-D0cCU7dI.mjs";import{c as n,d as r,f as i,l as a,m as o,n as s,p as c,r as l,s as u,u as d}from"../../attempt-fixtures-CnrnF5_4.mjs";import{RECOVERY_EVIDENCE_LIMITS as f}from"@makaio/framework/contracts";import{afterAll as p,beforeAll as ee,describe as m,expect as h,it as g}from"vitest";function _(e,t){let n;return ee(async()=>{n=await e.create(t)}),p(async()=>{await n?.dispose()}),()=>{if(!n)throw Error(`Repository conformance harness has not been initialized`);return n}}let v=0;const y=6e4;function b(){return v+=1,{executionId:`parity-exec-${v}`,executionAttemptId:`parity-attempt-${v}`}}async function x(e,t,r={}){await e.createAttempt({...t,instruction:i(),bootstrapTimeoutMs:y});let a=await e.beginProvisioning(n(t.executionAttemptId,t.executionId,r));if(a.kind!==`started`)throw Error(`Expected provisioning to start, got '${a.kind}'`);return a.claim}const S=`runtime-incarnation-1`;async function C(e,t=[]){let a=b();await e.createAttempt({...a,instruction:i({workspace:{provisioning:`create`,custody:`disposable`,sourceRoots:t,setup:[]}}),bootstrapTimeoutMs:y});let o=await e.beginProvisioning(n(a.executionAttemptId,a.executionId));if(o.kind!==`started`)throw Error(`Expected provisioning`);await e.recordAllocation({claim:o.claim,allocationRef:r()});let s=await T(e,a);await E(e,a,s);let c=await D(e,a,s,`workspace-preparation`,`prepare`);return{...a,operationId:c,runtimeGeneration:s,result:{kind:`workspace-prepared`,binding:{workspaceRoot:`/scratch/first`,sourceRoots:t.map(e=>({id:e.id,path:`/scratch/first/${e.path}`}))}}}}async function w(e,t){let n=await x(e,t),i=await e.recordAllocation({claim:n,allocationRef:r()});if(i.kind!==`recorded`)throw Error(`Expected the allocation to be recorded, got '${i.kind}'`);return n}async function T(e,t,n=S){let r=await e.registerRuntime({...t,runtimeIncarnationId:n});if(r.kind!==`registered`)throw Error(`Expected the runtime to register, got '${r.kind}'`);return r.runtimeGeneration}async function E(e,t,n){let r=await e.markRuntimeReady({...t,runtimeGeneration:n,readyAt:new Date().toISOString()});if(r.kind!==`ready`)throw Error(`Expected readiness to be accepted, got '${r.kind}'`);return r.acceptedAt}async function D(e,t,n,r,i){let a=await e.admitOperation({...t,operationKind:r,admissionKey:i,runtimeGeneration:n});if(a.kind!==`admitted`)throw Error(`Expected the operation to be admitted, got '${a.kind}'`);return a.operationId}async function O(e,t){await w(e,t);let n=await T(e,t);return await E(e,t,n),n}function k(t){g(`checks runtime generation at commit without rejecting historical canonical duplicates`,async()=>{let n=t(),r=b(),i=await O(n.repository,r),a=n.repository.canonicalizeOutcome(c(r.executionId,`failed`)),o={...r,result:a,runtimeFence:{runtimeGeneration:i,operationId:null}},s=await T(n.peer,r,`replacement-before-commit`);await h(n.repository.commitOutcome(o)).rejects.toThrow(e),h(await n.peer.getActiveAttempt(r.executionId,r.executionAttemptId)).toMatchObject({settlementKind:null,runtimeGeneration:s}),h(await n.peer.commitOutcome({...r,result:a,runtimeFence:{runtimeGeneration:s,operationId:null}})).toMatchObject({kind:`accepted`}),h(await n.repository.commitOutcome(o)).toMatchObject({kind:`duplicate`}),h(await n.repository.commitOutcome({...o,result:n.repository.canonicalizeOutcome(c(r.executionId,`completed`))})).toEqual({kind:`conflict`})}),g(`checks the active operation atomically before a new runtime outcome is committed`,async()=>{let n=t(),r=b(),i=await O(n.repository,r),a=n.repository.canonicalizeOutcome(c(r.executionId,`completed`)),o=await D(n.peer,r,i,`workload-invocation`,`invoke`);for(let t of[null,`another-operation`])await h(n.repository.commitOutcome({...r,result:a,runtimeFence:{runtimeGeneration:i,operationId:t}})).rejects.toThrow(e);h(await n.peer.getActiveAttempt(r.executionId,r.executionAttemptId)).toMatchObject({settlementKind:null,activeOperationId:o}),h(await n.repository.commitOutcome({...r,result:a,runtimeFence:{runtimeGeneration:i,operationId:o}})).toMatchObject({kind:`accepted`})}),g(`preserves superseded-attempt precedence over a stale runtime fence`,async()=>{let e=t(),n=b(),r=await O(e.repository,n);await e.peer.createAttempt({...n,executionAttemptId:`${n.executionAttemptId}-replacement`,instruction:i(),bootstrapTimeoutMs:y}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(c(n.executionId)),runtimeFence:{runtimeGeneration:r+1,operationId:null}})).toEqual({kind:`fenced`})}),g(`snapshots its instruction without retaining or freezing owner input`,async()=>{let e=t(),n=b(),r=i({workload:{kind:`test`,version:`1`,input:{value:`original`}}});await e.repository.createAttempt({...n,instruction:r,bootstrapTimeoutMs:y}),r.workload.input={value:`changed`},h(await e.repository.getInstruction(n)).toMatchObject({workload:{input:{value:`original`}}});let a=await e.repository.getInstruction(n);h(Object.isFrozen(a?.workload.input)).toBe(!0),h(await e.repository.getInstruction({...n,executionId:`other-owner`})).toBeNull(),h(await e.repository.getInstruction({...n,executionAttemptId:`missing`})).toBeNull();let o={...r,revision:``};await h(e.repository.createAttempt({executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-invalid`,instruction:o,bootstrapTimeoutMs:y})).rejects.toThrow(),h(await e.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).not.toBeNull(),h(await e.peer.getActiveAttempt(`${n.executionId}-foreign`,n.executionAttemptId)).toBeNull(),h(await e.peer.commitOutcome({...n,result:e.peer.canonicalizeOutcome(c(n.executionId))})).toMatchObject({kind:`accepted`}),h(await e.repository.getInstruction(n)).toEqual(a);let s={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-replacement`},l=i({id:`replacement-assignment`});await e.peer.createAttempt({...s,instruction:l,bootstrapTimeoutMs:y}),h(await e.repository.getInstruction(n)).toEqual(a),h(await e.repository.getInstruction(s)).toEqual(l),h(await e.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).toBeNull(),h(await e.repository.getActiveAttempt(s.executionId,s.executionAttemptId)).toMatchObject({executionAttemptId:s.executionAttemptId})}),g(`admits a workspace-less invocation without inventing a preparation result`,async()=>{let e=t(),n=b(),r=await O(e.repository,n);h(await e.repository.admitOperation({...n,runtimeGeneration:r,operationKind:`workspace-preparation`,admissionKey:`unneeded`})).toEqual({kind:`preparation-not-required`}),h(await e.repository.admitOperation({...n,runtimeGeneration:r,operationKind:`workload-invocation`,admissionKey:`invoke`})).toMatchObject({kind:`admitted`})}),g(`requires a preparation result and replays its receipt after invocation and settlement`,async()=>{let e=t().repository,n=await C(e);h(await e.completeOperation(n)).toEqual({kind:`result-required`}),h(await e.reportOperation(n)).toEqual({kind:`accepted`,binding:n.result.binding}),h(await e.getActiveAttempt(n.executionId,n.executionAttemptId)).toMatchObject({activeOperationId:null,lastCompletedOperationId:n.operationId,preparationReceipts:[{operationId:n.operationId,runtimeGeneration:n.runtimeGeneration,result:n.result}]}),h(await e.admitOperation({...n,operationKind:`workspace-preparation`,admissionKey:`prepare-again`})).toEqual({kind:`preparation-already-completed`});let r=await e.admitOperation({...n,operationKind:`workload-invocation`,admissionKey:`invoke`});if(h(r.kind).toBe(`admitted`),h(await e.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),r.kind!==`admitted`)throw Error(`Expected Invocation`);h(await e.completeOperation({...n,operationId:r.operationId})).toEqual({kind:`result-required`}),await e.commitOutcome({...n,result:e.canonicalizeOutcome(c(n.executionId,`completed`))}),h(await e.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),h((await e.getActiveAttempt(n.executionId,n.executionAttemptId))?.activeOperationId).toBe(r.operationId)}),g(`acknowledges historical receipts without preparing the replacement runtime`,async()=>{let e=t().repository,n=await C(e);await e.reportOperation(n);let r=await T(e,n,`replacement`);await E(e,n,r),h(await e.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),h(await e.reportOperation({...n,result:{...n.result,binding:{workspaceRoot:`/changed`,sourceRoots:[]}}})).toEqual({kind:`conflict`}),h(await e.reportOperation({...n,operationId:`unaccepted-old-operation`})).toEqual({kind:`stale-generation`}),h(await e.admitOperation({...n,runtimeGeneration:r,operationKind:`workload-invocation`,admissionKey:`invoke-replacement`})).toEqual({kind:`preparation-required`});let i=await D(e,n,r,`workspace-preparation`,`prepare-replacement`),a={...n,runtimeGeneration:r,operationId:i,result:{...n.result,binding:{workspaceRoot:`/scratch/replacement`,sourceRoots:[]}}};h(await e.reportOperation(a)).toEqual({kind:`accepted`,binding:a.result.binding}),h(await e.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),h((await e.getActiveAttempt(n.executionId,n.executionAttemptId))?.preparationReceipts).toHaveLength(2),h(await e.admitOperation({...n,runtimeGeneration:r,operationKind:`workload-invocation`,admissionKey:`invoke-replacement`})).toMatchObject({kind:`admitted`})})}function A(e){g(`authorizes provisioning once across racing controllers and subsequent retries`,async()=>{let t=e(),r=b();await t.repository.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y});let a=n(r.executionAttemptId,r.executionId,{ownerId:`provisioning-controller-primary`}),o={...a,ownerId:`provisioning-controller-peer`},s=await Promise.all([t.repository.beginProvisioning(a),t.peer.beginProvisioning(o)]);h(s.map(e=>e.kind).sort()).toEqual([`already-provisioning`,`started`]);let c=s.find(e=>e.kind===`started`);if(!c)throw Error(`Expected exactly one provisioning claim`);let l=s[0]?.kind===`started`?a:o;h(c.claim).toMatchObject({executionAttemptId:r.executionAttemptId,generation:1,ownerId:l.ownerId,leaseExpiresAt:l.leaseExpiresAt}),h(c.claim.token).toEqual(h.any(String));let u={...c.claim,obligation:`provisioning-resolution`,failureCount:0,lastFailure:null};for(let e of[t.repository,t.peer])h(await e.getProviderOperation(r.executionAttemptId)).toMatchObject(u),h(await e.recovery.getAttemptWithAllocation(r.executionAttemptId)).toMatchObject({status:`provisioning`,allocationRef:null,providerId:l.providerId,allocationLifetime:l.allocationLifetime,provisionerIncarnationId:l.provisionerIncarnationId});h(await t.repository.beginProvisioning(a)).toEqual({kind:`already-provisioning`}),h(await t.peer.beginProvisioning(o)).toEqual({kind:`already-provisioning`}),h(await t.peer.beginProvisioning({...o,providerId:`different-provider`,allocationLifetime:`provisioner-process-bound`,provisionerIncarnationId:`different-provisioner-incarnation`})).toEqual({kind:`already-provisioning`});for(let e of[t.repository,t.peer])h(await e.getProviderOperation(r.executionAttemptId)).toMatchObject(u),h(await e.recovery.getAttemptWithAllocation(r.executionAttemptId)).toMatchObject({providerId:l.providerId,allocationLifetime:l.allocationLifetime,provisionerIncarnationId:l.provisionerIncarnationId})}),g(`refuses takeover before the held lease expires without fencing its owner`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=a({summary:`allocation lookup remains inconclusive`});h(await t.repository.recordProviderOperationUncertainty({claim:r,evidence:i})).toEqual({kind:`recorded`});let o={...r,obligation:`provisioning-resolution`,failureCount:1,lastFailure:i},s={executionAttemptId:n.executionAttemptId,ownerId:`lease-takeover-controller`,leaseExpiresAt:new Date(Date.parse(r.leaseExpiresAt)+6e4).toISOString()};h(await t.peer.takeOverProviderOperation({...s,observedAt:new Date(Date.parse(r.leaseExpiresAt)-1).toISOString()})).toEqual({kind:`stale`});for(let e of[t.repository,t.peer])h(await e.getProviderOperation(n.executionAttemptId)).toMatchObject(o);h(await t.repository.recordProviderOperationUncertainty({claim:r,evidence:i})).toEqual({kind:`recorded`});let c=await t.peer.takeOverProviderOperation({...s,observedAt:new Date(Date.parse(r.leaseExpiresAt)+1).toISOString()});if(h(c.kind).toBe(`claimed`),c.kind!==`claimed`)throw Error(`Expected takeover after lease expiry`);h(c.claim.generation).toBe(r.generation+1),h(c.claim.token).not.toBe(r.token),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({...c.claim,ownerId:s.ownerId,leaseExpiresAt:s.leaseExpiresAt,obligation:`provisioning-resolution`,failureCount:2,lastFailure:i}),h(await t.repository.recordProviderOperationUncertainty({claim:r,evidence:i})).toEqual({kind:`stale`})}),te(e),ne(e)}function te(e){g(`renews the lease without changing generation or fencing the original claim`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=new Date(Date.parse(r.leaseExpiresAt)+6e4).toISOString(),o=await t.peer.renewProviderOperationClaim({claim:r,leaseExpiresAt:i});if(h(o.kind).toBe(`claimed`),o.kind!==`claimed`)throw Error(`Expected lease renewal`);h(o.claim).toEqual({...r,leaseExpiresAt:i}),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({...r,leaseExpiresAt:i,obligation:`provisioning-resolution`});for(let e of[r,o.claim])h(await t.repository.recordProviderOperationUncertainty({claim:e,evidence:a()})).toEqual({kind:`recorded`})})}function ne(e){let t=[`recordProviderOperationUncertainty`,`recordAllocation`,`recordAllocationTerminated`,`handoffProviderOperation`,`recordProvisioningAbsent`,`recordProvisionerIncarnationLost`,`recordInfrastructureFailure`,`renewProviderOperationClaim`,`recordDiscoveredAllocation`,`evolveAllocationRef`];g.each(t)(`refuses %s from a superseded claim without changing durable state`,async t=>{let n=e(),i=b(),a=await x(n.repository,i),o=r(),s=t===`evolveAllocationRef`;s&&h(await n.repository.recordAllocation({claim:a,allocationRef:o})).toEqual({kind:`recorded`});let c=await n.peer.takeOverProviderOperation({executionAttemptId:i.executionAttemptId,ownerId:`current-remediation-controller`,observedAt:new Date(Date.parse(a.leaseExpiresAt)+1).toISOString(),leaseExpiresAt:new Date(Date.parse(a.leaseExpiresAt)+6e4).toISOString()});if(h(c.kind).toBe(`claimed`),c.kind!==`claimed`)throw Error(`Expected takeover to fence the old claim`);let{executionId:l}=i;h(await j(n.repository,a,l,o,new Date(Date.parse(c.claim.leaseExpiresAt)+6e4).toISOString())[t]()).toMatchObject({kind:`stale`});let u=await n.peer.recovery.getAttemptWithAllocation(i.executionAttemptId);h(u).toMatchObject({status:s?`allocated`:`provisioning`,allocationRef:s?o:null}),h(u?.settlementKind??null).toBeNull(),h(await n.peer.getProviderOperation(i.executionAttemptId)).toMatchObject({...c.claim,obligation:s?`allocation-control`:`provisioning-resolution`,failureCount:0,lastFailure:null})}),g.each(t)(`returns not-found from %s for a valid claim naming no attempt`,async t=>{let n=e(),i=b(),a={executionAttemptId:i.executionAttemptId,generation:1,ownerId:`missing-operation-owner`,token:`00000000-0000-4000-8000-000000000001`,leaseExpiresAt:new Date().toISOString()};h(await j(n.peer,a,i.executionId,r(),new Date(Date.parse(a.leaseExpiresAt)+6e4).toISOString())[t]()).toEqual({kind:`not-found`});for(let e of[n.repository,n.peer])h(await e.getProviderOperation(i.executionAttemptId)).toBeNull(),h(await e.recovery.getAttemptWithAllocation(i.executionAttemptId)).toBeNull()})}function j(e,t,n,i,o){let s=a();return{recordProviderOperationUncertainty:()=>e.recordProviderOperationUncertainty({claim:t,evidence:s}),recordAllocation:()=>e.recordAllocation({claim:t,allocationRef:i}),recordAllocationTerminated:()=>e.recordAllocationTerminated({claim:t,evidence:s}),handoffProviderOperation:()=>e.handoffProviderOperation({claim:t,evidence:s}),recordProvisioningAbsent:()=>e.recordProvisioningAbsent({claim:t,executionId:n,evidence:s}),recordProvisionerIncarnationLost:()=>e.recordProvisionerIncarnationLost({claim:t,executionId:n,proof:d()}),recordInfrastructureFailure:()=>e.recordInfrastructureFailure({claim:t,executionId:n}),renewProviderOperationClaim:()=>e.renewProviderOperationClaim({claim:t,leaseExpiresAt:o}),recordDiscoveredAllocation:()=>e.recovery.recordDiscoveredAllocation({claim:t,allocationRef:i}),evolveAllocationRef:()=>e.recovery.evolveAllocationRef({claim:t,executionId:n,currentRef:i,nextRef:r(i.providerId,{machineId:`refined-allocation`})})}}function re(e){g(`preserves host claim expiry across allocation and excludes an expired allocation from recovery`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a=new Date(Date.now()+3600*1e3).toISOString();await t.setClaimExpiry(n.executionAttemptId,a),h(await t.repository.recordAllocation({claim:i,allocationRef:r()})).toEqual({kind:`recorded`}),h(await t.peer.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({claimable:!0,claimExpiresAt:a}),h(await t.peer.recovery.getRecoverableAttempts(n.executionId)).toEqual([h.objectContaining({executionAttemptId:n.executionAttemptId,claimExpiresAt:a})]),await t.setClaimExpiry(n.executionAttemptId,`2000-01-01T00:00:00.000Z`),h(await t.repository.recovery.getRecoverableAttempts(n.executionId)).toEqual([]),h(await t.peer.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({claimExpiresAt:`2000-01-01T00:00:00.000Z`})}),g(`preserves host claim expiry when a newer attempt supersedes an allocated one`,async()=>{let t=e(),n=b(),a=await x(t.repository,n),o=new Date(Date.now()+3600*1e3).toISOString();await t.setClaimExpiry(n.executionAttemptId,o),h(await t.repository.recordAllocation({claim:a,allocationRef:r()})).toEqual({kind:`recorded`});let s={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-replacement`};await t.peer.createAttempt({...s,instruction:i(),bootstrapTimeoutMs:y});let c=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(c).toMatchObject({status:`allocated`,claimExpiresAt:o}),h(c?.claimable??!1).toBe(!1);let l=await t.peer.recovery.getAttemptWithAllocation(s.executionAttemptId);h(l).toMatchObject({status:`pending`}),h(l?.claimable??!1).toBe(!1),h(l?.claimExpiresAt??null).toBeNull()})}function ie(e){g.each([{description:`omits`,sourceRoots:[]},{description:`substitutes`,sourceRoots:[{id:`different-source`,path:`/scratch/first/source`}]},{description:`adds undeclared roots alongside`,sourceRoots:[{id:`source`,path:`/scratch/first/source`},{id:`extra-source`,path:`/scratch/first/extra`}]}])(`retains the Preparation slot when the first report $description a requested source root`,async({sourceRoots:t})=>{let n=e(),r=await C(n.repository,[{id:`source`,path:`source`}]),i={...r,result:{...r.result,binding:{...r.result.binding,sourceRoots:t}}};h(await n.repository.reportOperation(i)).toEqual({kind:`binding-mismatch`}),h(await n.repository.getActiveAttempt(r.executionId,r.executionAttemptId)).toMatchObject({preparationReceipts:[],activeOperationId:r.operationId,activeOperationKind:`workspace-preparation`}),h(await n.repository.reportOperation(r)).toEqual({kind:`accepted`,binding:r.result.binding})})}function ae(e){g(`accepts a worker outcome while a peer takes over the expired provider claim`,async()=>{let t=e(),n=b(),i=await x(t.repository,n);await t.repository.recordAllocation({claim:i,allocationRef:r()});let a=t.repository.canonicalizeOutcome(c(n.executionId)),[o,s]=await Promise.all([t.peer.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`atomicity-remediator`,observedAt:new Date(Date.parse(i.leaseExpiresAt)+1).toISOString(),leaseExpiresAt:u(12e4)}),t.repository.commitOutcome({...n,result:a})]);h([`claimed`,`resolved`]).toContain(o.kind),h(s).toEqual({kind:`accepted`,outcome:a.outcome,text:a.text}),h(await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).toMatchObject({settlementKind:`outcome`}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({ownerId:null,token:null,leaseExpiresAt:null})}),g(`returns the first evolved reference to a stale same-provider correlator without another mutation`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a=r(s,{machineId:`atomicity-stale`}),o=r(s,{machineId:`atomicity-stale`,jobId:`first`});await t.repository.recordAllocation({claim:i,allocationRef:a}),h(await t.repository.recovery.evolveAllocationRef({claim:i,executionId:n.executionId,currentRef:a,nextRef:o})).toEqual({kind:`evolved`}),h(await t.peer.recovery.evolveAllocationRef({claim:i,executionId:n.executionId,currentRef:a,nextRef:r(s,{machineId:`atomicity-stale`,jobId:`second`})})).toEqual({kind:`stale`,storedRef:o}),h((await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef).toEqual(o)}),g(`allows exactly one racing allocation-ref evolution and retains its actual winner`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a=r(s,{machineId:`atomicity-race`}),o=r(s,{machineId:`atomicity-race`,jobId:`first`}),c=r(s,{machineId:`atomicity-race`,jobId:`second`});await t.repository.recordAllocation({claim:i,allocationRef:a});let l=await Promise.all([t.repository.recovery.evolveAllocationRef({claim:i,executionId:n.executionId,currentRef:a,nextRef:o}),t.peer.recovery.evolveAllocationRef({claim:i,executionId:n.executionId,currentRef:a,nextRef:c})]);h(l.map(e=>e.kind).sort()).toEqual([`evolved`,`stale`]);let u=l[0]?.kind===`evolved`?o:c;h(l.find(e=>e.kind===`stale`)).toEqual({kind:`stale`,storedRef:u}),h((await t.peer.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef).toEqual(u)}),g(`records one receipt and releases the Preparation slot when matching reports race`,async()=>{let t=e(),n=await C(t.repository),r=await Promise.all([t.repository.reportOperation(n),t.peer.reportOperation(n)]);h(r.map(e=>e.kind).sort()).toEqual([`accepted`,`duplicate`]),h(r).toContainEqual({kind:`accepted`,binding:n.result.binding}),h(r).toContainEqual({kind:`duplicate`,binding:n.result.binding});let i=await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId);h(i?.preparationReceipts).toEqual([{operationId:n.operationId,runtimeGeneration:n.runtimeGeneration,result:n.result}]),h(i?.activeOperationId).toBeNull(),h(i?.lastCompletedOperationId).toBe(n.operationId)}),g(`preserves the actual Preparation winner and releases its slot when reports conflict`,async()=>{let t=e(),n=await C(t.repository),r={...n,result:{...n.result,binding:{workspaceRoot:`/scratch/atomicity-second`,sourceRoots:[]}}},i=await Promise.all([t.repository.reportOperation(n),t.peer.reportOperation(r)]);h(i.map(e=>e.kind).sort()).toEqual([`accepted`,`conflict`]);let a=i[0]?.kind===`accepted`?n:r;h(i.find(e=>e.kind===`accepted`)).toEqual({kind:`accepted`,binding:a.result.binding});let o=await t.peer.getActiveAttempt(n.executionId,n.executionAttemptId);h(o?.preparationReceipts).toEqual([{operationId:a.operationId,runtimeGeneration:a.runtimeGeneration,result:a.result}]),h(o?.activeOperationId).toBeNull(),h(o?.lastCompletedOperationId).toBe(a.operationId)})}function oe(e){M(e),g(`rejects a reused attempt identifier without touching the existing attempt`,async()=>{let n=e(),o=b(),c=await x(n.repository,o),l=r();await n.repository.recordAllocation({claim:c,allocationRef:l}),await n.repository.recordAllocationTerminated({claim:c,evidence:a()}),await n.repository.recordInfrastructureFailure({claim:c,executionId:o.executionId}),await h(n.repository.createAttempt({...o,instruction:i(),bootstrapTimeoutMs:y})).rejects.toThrow(t),await h(n.repository.createAttempt({...o,instruction:i(),bootstrapTimeoutMs:y})).rejects.toMatchObject({executionAttemptId:o.executionAttemptId});let u=await n.repository.recovery.getAttemptWithAllocation(o.executionAttemptId);h(u?.status).toBe(`settled`),h(u?.settlementKind).toBe(`infrastructure-failure`),h(u?.allocationRef).toEqual(l),h(u?.providerId).toBe(s)}),g(`fences only the allocated attempt superseded for its execution`,async()=>{let t=e(),n=b(),a=await x(t.repository,n);await t.repository.recordAllocation({claim:a,allocationRef:r()});let o=b(),s=await x(t.repository,o);await t.repository.recordAllocation({claim:s,allocationRef:r()});let c={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-next`};await t.repository.createAttempt({...c,instruction:i(),bootstrapTimeoutMs:y}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({status:`allocated`,claimable:!1}),h(await t.repository.recovery.getAttemptWithAllocation(o.executionAttemptId)).toMatchObject({status:`allocated`,claimable:!0})}),g(`compares allocation references by value, not by member order`,async()=>{let t=e(),n=b(),i=await x(t.repository,n);await t.repository.recordAllocation({claim:i,allocationRef:r(s,{machineId:`parity-order`,region:`ord`})});let a=r(s,{region:`ord`,machineId:`parity-order`});h(await t.repository.recordAllocation({claim:i,allocationRef:a})).toMatchObject({kind:`duplicate`}),h(await t.repository.recovery.evolveAllocationRef({claim:i,executionId:n.executionId,currentRef:a,nextRef:r(s,{machineId:`parity-order`,region:`ord`,jobId:7})})).toEqual({kind:`evolved`}),h(await t.repository.recordAllocation({claim:i,allocationRef:r(s,{machineId:`somewhere-else`})})).toMatchObject({kind:`conflict`})}),g(`keeps only the newest active allocation recoverable for an execution`,async()=>{let t=e(),n=`${b().executionId}-recovery-order`,i=[];for(let e of[`c`,`b`,`a`]){let a=`${n}-${e}`,o=await x(t.repository,{executionId:n,executionAttemptId:a});await t.repository.recordAllocation({claim:o,allocationRef:r(s,{machineId:e})}),i.push(a)}h((await t.repository.recovery.getRecoverableAttempts(n)).map(e=>e.executionAttemptId)).toEqual([i.at(-1)])}),g(`refuses an evolution whose references name different providers`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a=r(s,{machineId:`parity-1`});await t.repository.recordAllocation({claim:i,allocationRef:a}),await h(t.repository.recovery.evolveAllocationRef({claim:i,executionId:n.executionId,currentRef:a,nextRef:r(`a-different-provider`,{machineId:`parity-1`})})).rejects.toThrow(),h((await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef).toEqual(a)}),g(`retains unresolved provisioning when infrastructure failure has no allocation to settle`,async()=>{let t=e(),n=b(),r=await x(t.repository,n);h(await t.peer.recordInfrastructureFailure({claim:r,executionId:n.executionId})).toEqual({kind:`not-allocated`});let i=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(i).toMatchObject({status:`provisioning`,allocationRef:null,operationStartGate:`open`}),h(i?.settlementKind??null).toBeNull(),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({...r,obligation:`provisioning-resolution`,failureCount:0,lastFailure:null})}),g(`settles infrastructure only after termination is durably confirmed`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),o=r();await t.repository.recordAllocation({claim:i,allocationRef:o});let s=await t.repository.recordInfrastructureFailure({claim:i,executionId:n.executionId}),c=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),l=await t.repository.getProviderOperation(n.executionAttemptId);h(s).toEqual({kind:`not-terminated`}),h(c?.status).toBe(`allocated`),h(c?.settlementKind??null).toBeNull(),h(l?.obligation).toBe(`allocation-control`);let u=await t.repository.recordAllocationTerminated({claim:i,evidence:a({summary:`provider reported the allocation terminated`})}),d=await t.repository.recordInfrastructureFailure({claim:i,executionId:n.executionId});h(u).toEqual({kind:`recorded`}),h(d).toEqual({kind:`recorded`}),h((await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.settlementKind).toBe(`infrastructure-failure`);let f=await t.repository.getProviderOperation(n.executionAttemptId);h(f?.obligation).toBe(`terminal-convergence`),h(f?.lastFailure?.summary).toBe(`provider reported the allocation terminated`)}),g(`refuses an allocation reference that names a provider other than the attempt own`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a=r(`a-different-provider`,{machineId:`foreign-1`});await h(t.repository.recordAllocation({claim:i,allocationRef:a})).rejects.toThrow(),await h(t.repository.recovery.recordDiscoveredAllocation({claim:i,allocationRef:a})).rejects.toThrow();let o=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(o?.allocationRef).toBeNull(),h(o?.status).toBe(`provisioning`),h((await t.repository.getProviderOperation(n.executionAttemptId))?.obligation).toBe(`provisioning-resolution`),h(await t.repository.recordAllocation({claim:i,allocationRef:r()})).toEqual({kind:`recorded`})}),g(`refuses a foreign allocation reference even from a fenced claim`,async()=>{let t=e(),n=b(),i=await x(t.repository,n);h((await t.repository.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`parity-remediator`,observedAt:u(36e5),leaseExpiresAt:u(72e5)})).kind).toBe(`claimed`),await h(t.repository.recordAllocation({claim:i,allocationRef:r(`a-different-provider`,{machineId:`foreign-2`})})).rejects.toThrow(),h(await t.repository.recordAllocation({claim:i,allocationRef:r()})).toEqual({kind:`stale`})}),g(`refuses an allocation reference the contract forbids, before any mutation`,async()=>{let t=e(),n=b(),i=await x(t.repository,n);await h(t.repository.recordAllocation({claim:i,allocationRef:{...r(),providerId:``}})).rejects.toThrow();let a=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(a?.status).toBe(`provisioning`),h(a?.allocationRef).toBeNull()}),g(`never lets a caller mutate durable evidence after the call returned`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a={machineId:`parity-owned`};await t.repository.recordAllocation({claim:i,allocationRef:r(s,a)}),a.machineId=`mutated-after-the-fact`,h((await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef?.providerData).toEqual({machineId:`parity-owned`})})}function M(e){g(`preserves exactly one instruction when two controllers create the same attempt identifier`,async()=>{let n=e(),r=b(),a=i({id:`primary-assignment`}),o=i({id:`peer-assignment`}),s=await Promise.allSettled([n.repository.createAttempt({...r,instruction:a,bootstrapTimeoutMs:y}),n.peer.createAttempt({...r,instruction:o,bootstrapTimeoutMs:y})]);h(s.map(e=>e.status).sort()).toEqual([`fulfilled`,`rejected`]);let c=s.find(e=>e.status===`rejected`);if(!c)throw Error(`Expected the duplicate creation to reject`);h(c.reason).toBeInstanceOf(t),h(c.reason).toMatchObject({executionAttemptId:r.executionAttemptId});let l=s[0]?.status===`fulfilled`?a:o;for(let e of[n.repository,n.peer])h(await e.getInstruction(r)).toEqual(l),h(await e.getActiveAttempt(r.executionId,r.executionAttemptId)).toMatchObject({...r,status:`pending`,instruction:l,operationStartGate:`open`,runtimeGeneration:0}),h(await e.getProviderOperation(r.executionAttemptId)).toBeNull()})}function N(e){g(`closes pre-allocation debt only on proof naming the attempt own provisioner`,async()=>{let t=e(),n=b(),r=await x(t.repository,n,{allocationLifetime:`provisioner-process-bound`,provisionerIncarnationId:`provisioner-A`}),i=await t.repository.recordProvisionerIncarnationLost({claim:r,executionId:n.executionId,proof:d(`provisioner-B`)}),a=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),o=await t.repository.recordProvisionerIncarnationLost({claim:r,executionId:n.executionId,proof:d(`provisioner-A`)}),s=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),c=await t.repository.getProviderOperation(n.executionAttemptId);h(i).toEqual({kind:`incarnation-mismatch`,provisionerIncarnationId:`provisioner-A`}),h(a?.settlementKind??null).toBeNull(),h(o).toEqual({kind:`recorded`}),h(s?.status).toBe(`settled`),h(s?.settlementKind).toBe(`abandoned`),h(s?.allocationRef).toBeNull(),h(s?.claimable??!1).toBe(!1),h(c?.ownerId).toBeNull(),h(c?.token).toBeNull(),h(c?.lastFailure?.summary).toBe(`supervisor observed the provisioner process exit`),h(c?.obligation).toBe(`provisioning-resolution`)}),g(`refuses a loss proof for an attempt whose allocation outlives its provisioner`,async()=>{let t=e(),n=b(),r=await x(t.repository,n);h(await t.repository.recordProvisionerIncarnationLost({claim:r,executionId:n.executionId,proof:d(l)})).toEqual({kind:`not-process-bound`,allocationLifetime:`provider-managed`});let i=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(i?.settlementKind??null).toBeNull(),h(i?.status).toBe(`provisioning`)}),g(`refuses a loss proof once the attempt owns an allocation`,async()=>{let t=e(),n=b(),i=await x(t.repository,n,{allocationLifetime:`provisioner-process-bound`,provisionerIncarnationId:`provisioner-A`}),a=r();await t.repository.recordAllocation({claim:i,allocationRef:a}),h(await t.repository.recordProvisionerIncarnationLost({claim:i,executionId:n.executionId,proof:d(`provisioner-A`)})).toEqual({kind:`allocated`,allocationRef:a});let o=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(o?.settlementKind??null).toBeNull(),h(o?.allocationRef).toEqual(a)}),g.each([`overlong summary`,`forbidden credentials field`])(`rejects evidence with a %s before it consults ownership`,async t=>{let n=e(),r=b(),i=await x(n.repository,r),o=await n.repository.takeOverProviderOperation({executionAttemptId:r.executionAttemptId,ownerId:`parity-remediator`,observedAt:u(36e5),leaseExpiresAt:u(72e5)});if(h(o.kind).toBe(`claimed`),o.kind!==`claimed`)throw Error(`Expected takeover to fence the evidence writer`);let s=t===`overlong summary`?a({summary:`x`.repeat(f.summary+1)}):{...a(),credentials:`synthetic-conformance-sentinel`},{executionId:c}=r;await h(n.repository.recordProvisioningAbsent({claim:i,executionId:c,evidence:s})).rejects.toThrow(),await h(n.repository.recordProviderOperationUncertainty({claim:i,evidence:s})).rejects.toThrow(),await h(n.repository.recordAllocationTerminated({claim:i,evidence:s})).rejects.toThrow(),await h(n.repository.handoffProviderOperation({claim:i,evidence:s})).rejects.toThrow(),await h(n.repository.recordProvisionerIncarnationLost({claim:i,executionId:c,proof:d(l,s)})).rejects.toThrow(),h(await n.repository.recordProvisioningAbsent({claim:i,executionId:c,evidence:a()})).toEqual({kind:`stale`}),h(await n.peer.getProviderOperation(r.executionAttemptId)).toMatchObject({...o.claim,obligation:`provisioning-resolution`,failureCount:0,lastFailure:null});let p=await n.peer.recovery.getAttemptWithAllocation(r.executionAttemptId);h(p).toMatchObject({status:`provisioning`,allocationRef:null}),h(p?.settlementKind??null).toBeNull()}),g(`preserves an evidence timestamp verbatim while canonicalizing a future offset-form lease renewal`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=`2026-07-27T12:00:00.000+02:00`,o=new Date(Date.parse(r.leaseExpiresAt)+6e4),s=new Date(o.getTime()+7200*1e3).toISOString().replace(`Z`,`+02:00`),c=o.toISOString();await t.repository.recordProviderOperationUncertainty({claim:r,evidence:a({observedAt:i})});let l=await t.repository.renewProviderOperationClaim({claim:r,leaseExpiresAt:s}),u=await t.repository.getProviderOperation(n.executionAttemptId);h(u?.lastFailure?.observedAt).toBe(i),h(u?.leaseExpiresAt).toBe(c),h(l.kind===`claimed`?l.claim.leaseExpiresAt:null).toBe(c)})}function P(e){g(`remediates a superseded attempt to settlement without reviving it`,async()=>{let t=e(),n=b(),o=await x(t.repository,n),l={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-replacement`};await t.peer.createAttempt({...l,instruction:i(),bootstrapTimeoutMs:y});let u=r(s,{machineId:`superseded-remediation`});h(await t.peer.recovery.recordDiscoveredAllocation({claim:o,allocationRef:u})).toEqual({kind:`recorded`}),h(await t.peer.recordAllocationTerminated({claim:o,evidence:a()})).toEqual({kind:`recorded`}),h(await t.peer.recordInfrastructureFailure({claim:o,executionId:n.executionId})).toEqual({kind:`recorded`});let d=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(d).toMatchObject({status:`settled`,settlementKind:`infrastructure-failure`,allocationRef:u}),h(d?.claimable??!1).toBe(!1),h(await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).toBeNull(),h(await t.repository.getActiveAttempt(l.executionId,l.executionAttemptId)).toMatchObject({executionAttemptId:l.executionAttemptId}),h(await t.repository.commitOutcome({...n,result:t.repository.canonicalizeOutcome(c(n.executionId))})).toEqual({kind:`fenced`})}),g.each([`active`,`superseded`])(`records a discovered allocation without making the %s attempt bootstrap-claimable`,async t=>{let n=e(),a=b(),o=await x(n.repository,a),s={executionId:a.executionId,executionAttemptId:`${a.executionAttemptId}-retry`};t===`superseded`&&await n.peer.createAttempt({...s,instruction:i(),bootstrapTimeoutMs:y});let c=r();h(await n.peer.recovery.recordDiscoveredAllocation({claim:o,allocationRef:c})).toEqual({kind:`recorded`});let l=await n.repository.recovery.getAttemptWithAllocation(a.executionAttemptId);h(l).toMatchObject({status:`allocated`,allocationRef:c}),h(l?.claimable??!1).toBe(!1),h((await n.repository.getProviderOperation(a.executionAttemptId))?.obligation).toBe(`allocation-control`),h(await n.repository.recovery.recordDiscoveredAllocation({claim:o,allocationRef:c})).toEqual({kind:`duplicate`,allocationRef:c}),t===`superseded`?(h(await n.repository.getActiveAttempt(a.executionId,a.executionAttemptId)).toBeNull(),h(await n.repository.getActiveAttempt(a.executionId,s.executionAttemptId)).toMatchObject({executionAttemptId:s.executionAttemptId})):h(await n.repository.getActiveAttempt(a.executionId,a.executionAttemptId)).toMatchObject({executionAttemptId:a.executionAttemptId})}),g(`rejects a different same-provider discovered allocation reference without replacing the original`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a=r(s,{machineId:`discovered-original`}),o=r(s,{machineId:`discovered-conflict`});h(await t.repository.recovery.recordDiscoveredAllocation({claim:i,allocationRef:a})).toEqual({kind:`recorded`});let c=await t.repository.getProviderOperation(n.executionAttemptId);h(await t.peer.recovery.recordDiscoveredAllocation({claim:i,allocationRef:o})).toEqual({kind:`conflict`,allocationRef:a}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({allocationRef:a}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toEqual(c)}),g(`settles proven provisioning absence and closes ownership without allocation debt`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=a({summary:`provider proved no allocation exists`});h(await t.peer.recordProvisioningAbsent({claim:r,executionId:n.executionId,evidence:i})).toEqual({kind:`recorded`});let o=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(o).toMatchObject({status:`settled`,settlementKind:`abandoned`,allocationRef:null}),h(o?.claimable??!1).toBe(!1),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({ownerId:null,token:null,leaseExpiresAt:null,obligation:`provisioning-resolution`,lastFailure:i}),h(await t.peer.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`absence-remediator`,observedAt:r.leaseExpiresAt,leaseExpiresAt:new Date(Date.parse(r.leaseExpiresAt)+6e4).toISOString()})).toEqual({kind:`resolved`})}),g(`keeps allocation and proven absence mutually exclusive when they race across controllers`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),o=r(s,{machineId:`absence-race`}),[c,l]=await Promise.all([t.repository.recordAllocation({claim:i,allocationRef:o}),t.peer.recordProvisioningAbsent({claim:i,executionId:n.executionId,evidence:a()})]),u=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);if(u?.status===`allocated`){h(c).toEqual({kind:`recorded`}),h(l).toEqual({kind:`allocated`,allocationRef:o}),h(u).toMatchObject({settlementKind:null,allocationRef:o});return}h(u).toMatchObject({status:`settled`,settlementKind:`abandoned`,allocationRef:null}),h(l).toEqual({kind:`recorded`}),h(c).toEqual({kind:`resolved`,allocationRef:null}),h(await t.repository.recordAllocation({claim:i,allocationRef:o})).toEqual({kind:`resolved`,allocationRef:null}),h((await t.peer.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef).toBeNull()}),g(`keeps allocation and own process-loss proof mutually exclusive when they race across controllers`,async()=>{let t=e(),n=b(),i=`process-loss-race-provisioner`,a=await x(t.repository,n,{allocationLifetime:`provisioner-process-bound`,provisionerIncarnationId:i}),o=r(s,{machineId:`process-loss-race`}),[c,l]=await Promise.all([t.repository.recordAllocation({claim:a,allocationRef:o}),t.peer.recordProvisionerIncarnationLost({claim:a,executionId:n.executionId,proof:d(i)})]),u=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);if(u?.status===`allocated`){h(c).toEqual({kind:`recorded`}),h(l).toEqual({kind:`allocated`,allocationRef:o}),h(u).toMatchObject({settlementKind:null,allocationRef:o});return}h(u).toMatchObject({status:`settled`,settlementKind:`abandoned`,allocationRef:null}),h(l).toEqual({kind:`recorded`}),h(c).toEqual({kind:`resolved`,allocationRef:null}),h(await t.repository.recordAllocation({claim:a,allocationRef:o})).toEqual({kind:`resolved`,allocationRef:null}),h((await t.peer.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef).toBeNull()}),g(`hands off unresolved allocation ownership and immediately fences the released claim`,async()=>{let t=e(),n=b(),r=await w(t.repository,n),i=a({summary:`controller released allocation recovery`});h(await t.repository.handoffProviderOperation({claim:r,evidence:i})).toEqual({kind:`recorded`}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({generation:r.generation,obligation:`allocation-control`,ownerId:null,token:null,leaseExpiresAt:null,failureCount:0,lastFailure:i}),h(await t.repository.recordAllocationTerminated({claim:r,evidence:a()})).toEqual({kind:`stale`});let o=await t.peer.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`handoff-remediator`,observedAt:new Date(Date.parse(r.leaseExpiresAt)-1).toISOString(),leaseExpiresAt:new Date(Date.parse(r.leaseExpiresAt)+6e4).toISOString()});if(h(o.kind).toBe(`claimed`),o.kind!==`claimed`)throw Error(`Expected immediate takeover after handoff`);h(o.claim.generation).toBe(r.generation+1),h(o.claim.token).not.toBe(r.token),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({generation:o.claim.generation,ownerId:`handoff-remediator`,token:o.claim.token,leaseExpiresAt:o.claim.leaseExpiresAt,obligation:`allocation-control`,failureCount:0,lastFailure:i})}),g(`preserves prior uncertainty without counting evidence-free ownership handoff`,async()=>{let t=e(),n=b(),r=await w(t.repository,n),i=a({summary:`provider did not confirm allocation status`});h(await t.repository.recordProviderOperationUncertainty({claim:r,evidence:i})).toEqual({kind:`recorded`}),h(await t.repository.handoffProviderOperation({claim:r})).toEqual({kind:`recorded`}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({generation:r.generation,obligation:`allocation-control`,ownerId:null,token:null,leaseExpiresAt:null,failureCount:1,lastFailure:i})})}function F(e){g(`never refuses a worker outcome that races an admission`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=c(n.executionId),[a,o]=await Promise.all([t.repository.admitOperation({...n,operationKind:`workflow-run`,admissionKey:`run-against-outcome`,runtimeGeneration:r}),t.peer.commitOutcome({...n,result:t.peer.canonicalizeOutcome(i)})]);h(o).toEqual({kind:`accepted`,outcome:i,text:t.repository.canonicalizeOutcome(i).text}),h([`admitted`,`resolved`]).toContain(a.kind);for(let e of[t.repository,t.peer])h(await e.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({status:`settled`,settlementKind:`outcome`,operationStartGate:`closed`})}),g(`advances the runtime generation once for two concurrent reports of one incarnation`,async()=>{let t=e(),n=b();await w(t.repository,n);let r={...n,runtimeIncarnationId:S},i=await Promise.all([t.repository.registerRuntime(r),t.peer.registerRuntime(r)]);h(i.map(e=>e.kind).sort()).toEqual([`duplicate`,`registered`]),h(i).toContainEqual({kind:`duplicate`,runtimeGeneration:1,runtimeReadyAt:null}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:1,runtimeIncarnationId:S,runtimeReadyAt:null})}),g(`allocates one generation per incarnation when two race for the endpoint`,async()=>{let t=e(),n=b();await w(t.repository,n);let r=await Promise.all([t.repository.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-a`}),t.peer.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-b`})]);h(r.flatMap(e=>e.kind===`registered`?[e.runtimeGeneration]:[]).sort()).toEqual([1,2]);let i=r[0]?.kind===`registered`&&r[0].runtimeGeneration===2?`runtime-incarnation-a`:`runtime-incarnation-b`;h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:2,runtimeIncarnationId:i,runtimeReadyAt:null,activeOperationId:null})}),g(`refuses a completion fenced against a superseded generation`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await D(t.repository,n,r,`runtime-probe`,`probe-1`);h(await t.repository.completeOperation({executionAttemptId:n.executionAttemptId,operationId:i,runtimeGeneration:r})).toEqual({kind:`completed`});let a=await T(t.repository,n,`runtime-incarnation-2`);await E(t.repository,n,a);let o=await D(t.repository,n,a,`workflow-run`,`run-1`);h(await t.repository.completeOperation({executionAttemptId:n.executionAttemptId,operationId:o,runtimeGeneration:r})).toEqual({kind:`stale-generation`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:o,activeOperationGeneration:a,lastCompletedOperationId:i})}),g(`answers two concurrent admissions of one key with the operation it admitted once`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i={...n,operationKind:`workflow-run`,admissionKey:`run-key`,runtimeGeneration:r},a=await Promise.all([t.repository.admitOperation(i),t.peer.admitOperation(i)]);h(a.map(e=>e.kind).sort()).toEqual([`admitted`,`duplicate`]);let o=a.flatMap(e=>e.kind===`admitted`||e.kind===`duplicate`?[e.operationId]:[]);h(o).toHaveLength(2),h(new Set(o).size).toBe(1),h(await t.peer.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:o[0],activeOperationKey:i.admissionKey,activeOperationGeneration:r})}),I(e),g(`answers an admission on a settled attempt as resolved, over a closed gate`,async()=>{let t=e(),n=b(),r=await O(t.repository,n);await t.repository.commitOutcome({...n,result:t.repository.canonicalizeOutcome(c(n.executionId))}),h(await t.repository.admitOperation({...n,operationKind:`workflow-run`,admissionKey:`after-settlement`,runtimeGeneration:r})).toEqual({kind:`resolved`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({operationStartGate:`closed`})}),g(`refuses an admission while another operation occupies the attempt`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await D(t.repository,n,r,`workflow-run`,`run-1`);h(await t.repository.admitOperation({...n,operationKind:`workflow-run`,admissionKey:`run-2`,runtimeGeneration:r})).toEqual({kind:`operation-active`,operationId:i})}),g(`refuses a completion for another operation and replays the matching one as duplicate`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await D(t.repository,n,r,`workflow-run`,`run-1`),a=async e=>t.repository.completeOperation({executionAttemptId:n.executionAttemptId,operationId:e,runtimeGeneration:r});h(await a(`operation-nobody-admitted`)).toEqual({kind:`mismatch`,activeOperationId:i}),h(await a(i)).toEqual({kind:`completed`}),h(await a(i)).toEqual({kind:`duplicate`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,lastCompletedOperationId:i})}),g(`closes the superseded attempt gate in the transaction that moves the pointer`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),a={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-next`};await t.repository.createAttempt({...a,instruction:i(),bootstrapTimeoutMs:y}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({operationStartGate:`closed`}),h(await t.repository.getAttemptControlState(a.executionAttemptId)).toMatchObject({operationStartGate:`open`,runtimeGeneration:0}),h(await t.repository.admitOperation({...n,operationKind:`workflow-run`,admissionKey:`after-supersession`,runtimeGeneration:r})).toEqual({kind:`fenced`})}),g(`closes the start gate of the pending attempt it abandons`,async()=>{let t=e(),n=b();await t.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y}),h(await t.repository.abandonPendingAttempt(n.executionAttemptId,n.executionId)).toEqual({kind:`abandoned`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({operationStartGate:`closed`})}),g(`reports the control state a process that lost its own memory recovers from`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await D(t.repository,n,r,`workflow-run`,`run-key`),a=await t.repository.getAttemptControlState(n.executionAttemptId);h(a).toMatchObject({runtimeGeneration:r,runtimeIncarnationId:S,operationStartGate:`open`,activeOperationId:i,activeOperationKind:`workflow-run`,activeOperationKey:`run-key`,activeOperationGeneration:r,lastCompletedOperationId:null}),h(a?.runtimeReadyAt).not.toBeNull(),h(await t.repository.admitOperation({...n,operationKind:`workflow-run`,admissionKey:`run-key`,runtimeGeneration:r})).toEqual({kind:`duplicate`,operationId:i,runtimeGeneration:r,admittedAt:a?.activeOperationAdmittedAt}),h(a?.activeOperationAdmittedAt).toEqual(h.any(String))})}function I(e){g(`admits exactly one of two competing operation keys across controllers`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i={...n,operationKind:`workflow-run`,runtimeGeneration:r},a=await Promise.all([t.repository.admitOperation({...i,admissionKey:`competing-primary`}),t.peer.admitOperation({...i,admissionKey:`competing-peer`})]);h(a.map(e=>e.kind).sort()).toEqual([`admitted`,`operation-active`]);let o=a.find(e=>e.kind===`admitted`);if(!o)throw Error(`Expected exactly one admitted operation`);h(a).toContainEqual({kind:`operation-active`,operationId:o.operationId}),h(o.runtimeGeneration).toBe(r);let s=a[0]?.kind===`admitted`?`competing-primary`:`competing-peer`;for(let e of[t.repository,t.peer])h(await e.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:o.operationId,activeOperationKind:`workflow-run`,activeOperationKey:s,activeOperationGeneration:r,activeOperationAdmittedAt:o.admittedAt})})}function L(e){R(e),z(e),B(e),V(e),H(e)}function R(e){g(`refuses abandonment after provisioning began without discarding its provider operation`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),a=await t.repository.getProviderOperation(n.executionAttemptId);h(i).toMatchObject({status:`provisioning`,settlementKind:null,allocationRef:null}),h(a).toMatchObject({generation:r.generation,ownerId:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt,obligation:`provisioning-resolution`}),h(await t.repository.abandonPendingAttempt(n.executionAttemptId,n.executionId)).toEqual({kind:`provisioning`}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(i),h(await t.repository.getProviderOperation(n.executionAttemptId)).toEqual(a)}),g(`refuses abandonment after allocation without discarding its provider operation`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a=r();await t.repository.recordAllocation({claim:i,allocationRef:a});let o=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),s=await t.repository.getProviderOperation(n.executionAttemptId);h(o).toMatchObject({status:`allocated`,settlementKind:null,allocationRef:a}),h(s).toMatchObject({generation:i.generation,ownerId:i.ownerId,token:i.token,leaseExpiresAt:i.leaseExpiresAt,obligation:`allocation-control`}),h(await t.repository.abandonPendingAttempt(n.executionAttemptId,n.executionId)).toEqual({kind:`allocated`}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(o),h(await t.repository.getProviderOperation(n.executionAttemptId)).toEqual(s)}),g(`refuses pre-allocation absence after allocation without discarding the allocation`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),o=r();await t.repository.recordAllocation({claim:i,allocationRef:o});let s=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),c=await t.repository.getProviderOperation(n.executionAttemptId);h(await t.peer.recordProvisioningAbsent({claim:i,executionId:n.executionId,evidence:a()})).toEqual({kind:`allocated`,allocationRef:o}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(s),h(await t.repository.getProviderOperation(n.executionAttemptId)).toEqual(c)})}function z(e){g(`settles a pending abandonment race once and closes its start gate`,async()=>{let t=e(),n=b();await t.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y}),h(await t.peer.abandonPendingAttempt(n.executionAttemptId,`${n.executionId}-foreign`)).toEqual({kind:`fenced`});let r=await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId);h(r).toMatchObject({status:`pending`,operationStartGate:`open`}),h(r?.settlementKind??null).toBeNull(),h((await Promise.all([t.repository.abandonPendingAttempt(n.executionAttemptId,n.executionId),t.peer.abandonPendingAttempt(n.executionAttemptId,n.executionId)])).map(e=>e.kind).sort()).toEqual([`abandoned`,`already-abandoned`]),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({status:`settled`,settlementKind:`abandoned`,allocationRef:null}),h((await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.claimable??!1).toBe(!1),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({operationStartGate:`closed`})})}function B(e){g(`preserves an infrastructure settlement when a worker outcome arrives late`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),o=r(),s=a({summary:`provider confirmed termination before worker outcome`});await t.repository.recordAllocation({claim:i,allocationRef:o}),h(await t.repository.recordAllocationTerminated({claim:i,evidence:s})).toEqual({kind:`recorded`}),h(await t.peer.recordInfrastructureFailure({claim:i,executionId:n.executionId})).toEqual({kind:`recorded`}),h(await t.repository.commitOutcome({...n,result:t.repository.canonicalizeOutcome(c(n.executionId,`completed`))})).toEqual({kind:`conflict`}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({status:`settled`,settlementKind:`infrastructure-failure`,allocationRef:o}),h((await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.claimable??!1).toBe(!1),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({ownerId:null,token:null,leaseExpiresAt:null,obligation:`terminal-convergence`,lastFailure:s})})}function V(e){g(`keeps a confirmed termination monotonic and distinguishes it from a missing allocation`,async()=>{let t=e(),n=b(),i=await x(t.repository,n);await t.repository.recordAllocation({claim:i,allocationRef:r()}),h(await t.repository.recordAllocationTerminated({claim:i,evidence:a()})).toEqual({kind:`recorded`}),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({obligation:`terminal-convergence`,failureCount:0}),h(await t.peer.recordProviderOperationUncertainty({claim:i,evidence:a()})).toEqual({kind:`recorded`}),h(await t.repository.recordAllocationTerminated({claim:i,evidence:a()})).toEqual({kind:`recorded`}),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({obligation:`terminal-convergence`,failureCount:1});let o=b(),s=await x(t.repository,o);h(await t.repository.recordAllocationTerminated({claim:s,evidence:a()})).toEqual({kind:`not-allocated`}),h(await t.repository.getProviderOperation(o.executionAttemptId)).toMatchObject({obligation:`provisioning-resolution`});let c=await t.peer.takeOverProviderOperation({executionAttemptId:o.executionAttemptId,ownerId:`terminal-remediator`,observedAt:u(12e4),leaseExpiresAt:u(18e4)});if(c.kind!==`claimed`)throw Error(`Expected takeover, got '${c.kind}'`);h(await t.repository.recordAllocationTerminated({claim:s,evidence:a()})).toEqual({kind:`stale`}),h(await t.repository.getProviderOperation(o.executionAttemptId)).toMatchObject({ownerId:`terminal-remediator`,obligation:`provisioning-resolution`})})}function H(e){g(`settles exactly once when matching process-loss proofs race`,async()=>{let t=e(),n=b(),r=await x(t.repository,n,{allocationLifetime:`provisioner-process-bound`,provisionerIncarnationId:`provisioner-A`}),i=d(`provisioner-A`);h((await Promise.all([t.repository.recordProvisionerIncarnationLost({claim:r,executionId:n.executionId,proof:i}),t.peer.recordProvisionerIncarnationLost({claim:r,executionId:n.executionId,proof:i})])).map(e=>e.kind).sort()).toEqual([`recorded`,`resolved`]),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({status:`settled`,settlementKind:`abandoned`,allocationRef:null}),h((await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.claimable??!1).toBe(!1),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({ownerId:null,token:null,leaseExpiresAt:null,obligation:`provisioning-resolution`,lastFailure:i.evidence})})}function U(e){g(`refuses a registration while an operation occupies the attempt`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await D(t.repository,n,r,`workflow-run`,`run-1`);h(await t.repository.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-2`})).toEqual({kind:`operation-active`,operationId:i})}),g(`replays registration and readiness during a workload, but fences a stale readiness report first`,async()=>{let t=e(),n=b(),r=await O(t.repository,n);await D(t.repository,n,r,`workflow-run`,`replay-workload`);let i=await t.repository.getAttemptControlState(n.executionAttemptId);h(await t.repository.registerRuntime({...n,runtimeIncarnationId:S})).toEqual({kind:`duplicate`,runtimeGeneration:r,runtimeReadyAt:i?.runtimeReadyAt}),h(await t.repository.markRuntimeReady({...n,runtimeGeneration:r,readyAt:new Date().toISOString()})).toEqual({kind:`duplicate`,acceptedAt:i?.runtimeReadyAt}),h(await t.repository.markRuntimeReady({...n,runtimeGeneration:r+1,readyAt:new Date().toISOString()})).toEqual({kind:`stale-generation`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toEqual(i)}),g(`reports settlement before replaying the last completed operation`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await D(t.repository,n,r,`workflow-run`,`complete`),a={executionAttemptId:n.executionAttemptId,operationId:i,runtimeGeneration:r};h(await t.repository.completeOperation(a)).toEqual({kind:`completed`}),h(await t.repository.completeOperation(a)).toEqual({kind:`duplicate`}),h((await t.repository.commitOutcome({...n,result:t.repository.canonicalizeOutcome(c(n.executionId))})).kind).toBe(`accepted`),h(await t.repository.completeOperation(a)).toEqual({kind:`resolved`})}),g(`admits the bounded probe before readiness and refuses every other kind`,async()=>{let t=e(),n=b();await w(t.repository,n);let r=await T(t.repository,n);h(await t.repository.admitOperation({...n,operationKind:`workflow-run`,admissionKey:`run-before-readiness`,runtimeGeneration:r})).toEqual({kind:`not-ready`});let i=await D(t.repository,n,r,`runtime-probe`,`probe-1`);h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:i,activeOperationKind:`runtime-probe`,runtimeReadyAt:null})}),g(`refuses readiness while an operation occupies the attempt`,async()=>{let t=e(),n=b();await w(t.repository,n);let r=await T(t.repository,n),i=await D(t.repository,n,r,`runtime-probe`,`probe-1`);h(await t.repository.markRuntimeReady({...n,runtimeGeneration:r,readyAt:new Date().toISOString()})).toEqual({kind:`operation-active`,operationId:i})}),g(`refuses readiness for an attempt superseded after its probe completed`,async()=>{let t=e(),n=b();await w(t.repository,n);let r=await T(t.repository,n),i=await D(t.repository,n,r,`runtime-probe`,`probe-1`);h(await t.repository.completeOperation({executionAttemptId:n.executionAttemptId,operationId:i,runtimeGeneration:r})).toEqual({kind:`completed`}),await w(t.repository,{executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-successor`}),h(await t.peer.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-after-supersession`})).toEqual({kind:`fenced`}),h(await t.repository.markRuntimeReady({...n,runtimeGeneration:r,readyAt:new Date().toISOString()})).toEqual({kind:`fenced`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:r,runtimeReadyAt:null,activeOperationId:null,operationStartGate:`closed`})}),g(`releases an in-flight superseded probe without allowing the old runtime to become ready`,async()=>{let t=e(),n=b();await w(t.repository,n);let r=await T(t.repository,n),a=await D(t.repository,n,r,`runtime-probe`,`probe-1`);await t.peer.createAttempt({executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-successor`,instruction:i(),bootstrapTimeoutMs:y}),h(await t.peer.completeOperation({executionAttemptId:n.executionAttemptId,operationId:a,runtimeGeneration:r})).toEqual({kind:`completed`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null,lastCompletedOperationId:a}),h(await t.peer.markRuntimeReady({...n,runtimeGeneration:r,readyAt:new Date().toISOString()})).toEqual({kind:`fenced`})}),g(`clears readiness when a new incarnation takes the endpoint`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await T(t.repository,n,`runtime-incarnation-2`);h(i).toBe(r+1),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:i,runtimeIncarnationId:`runtime-incarnation-2`,runtimeReadyAt:null}),await E(t.repository,n,i);let a=await D(t.repository,n,i,`workflow-run`,`run-1`);h(await t.repository.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-3`})).toEqual({kind:`operation-active`,operationId:a})}),g(`answers resolved for a settled attempt that still carries a leftover operation`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await D(t.repository,n,r,`workflow-run`,`run-1`);h((await t.repository.commitOutcome({...n,result:t.repository.canonicalizeOutcome(c(n.executionId))})).kind).toBe(`accepted`),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:i,operationStartGate:`closed`}),h(await t.repository.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-2`})).toEqual({kind:`resolved`}),h(await t.peer.markRuntimeReady({...n,runtimeGeneration:r,readyAt:new Date().toISOString()})).toEqual({kind:`resolved`}),h(await t.repository.admitOperation({...n,operationKind:`workflow-run`,admissionKey:`after-settlement`,runtimeGeneration:r})).toEqual({kind:`resolved`}),h(await t.repository.completeOperation({executionAttemptId:n.executionAttemptId,operationId:i,runtimeGeneration:r})).toEqual({kind:`resolved`})}),g(`refuses registration and admission once the allocation is confirmed terminated, before settlement`,async()=>{let t=e(),n=b(),r=await w(t.repository,n),i=await T(t.repository,n);await E(t.repository,n,i),h(await t.repository.recordAllocationTerminated({claim:r,evidence:a({summary:`provider reported the allocation terminated`})})).toEqual({kind:`recorded`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:i,operationStartGate:`open`}),h(await t.repository.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-2`})).toEqual({kind:`not-allocated`}),h(await t.repository.admitOperation({...n,operationKind:`workflow-run`,admissionKey:`after-termination`,runtimeGeneration:i})).toEqual({kind:`not-allocated`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:i,runtimeIncarnationId:S,activeOperationId:null}),h(await t.repository.recordInfrastructureFailure({claim:r,executionId:n.executionId})).toEqual({kind:`recorded`}),h(await t.repository.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-2`})).toEqual({kind:`resolved`})}),g(`refuses readiness once the allocation is confirmed terminated, even after the probe completed`,async()=>{let t=e(),n=b(),r=await w(t.repository,n),i=await T(t.repository,n),o=await D(t.repository,n,i,`runtime-probe`,`probe-1`);h(await t.repository.recordAllocationTerminated({claim:r,evidence:a({summary:`provider reported the allocation terminated`})})).toEqual({kind:`recorded`}),h(await t.repository.completeOperation({executionAttemptId:n.executionAttemptId,operationId:o,runtimeGeneration:i})).toEqual({kind:`completed`}),h(await t.repository.markRuntimeReady({...n,runtimeGeneration:i,readyAt:new Date().toISOString()})).toEqual({kind:`not-allocated`}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:i,runtimeReadyAt:null,activeOperationId:null})}),g(`reclaims a probe orphaned by a dead handshake when a new incarnation registers`,async()=>{let t=e(),n=b();await w(t.repository,n);let r=await T(t.repository,n),i=await D(t.repository,n,r,`runtime-probe`,`probe-1`);h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:i,activeOperationKind:`runtime-probe`}),h(await t.repository.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-2`})).toEqual({kind:`registered`,runtimeGeneration:r+1}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:r+1,runtimeIncarnationId:`runtime-incarnation-2`,runtimeReadyAt:null,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null}),h(await t.repository.completeOperation({executionAttemptId:n.executionAttemptId,operationId:i,runtimeGeneration:r})).toEqual({kind:`not-active`})}),g(`does not reclaim a workload operation when a new incarnation registers`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await D(t.repository,n,r,`workflow-run`,`run-1`);h(await t.repository.registerRuntime({...n,runtimeIncarnationId:`runtime-incarnation-2`})).toEqual({kind:`operation-active`,operationId:i}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:r,activeOperationId:i,activeOperationKind:`workflow-run`})})}function W(e){if(typeof e==`number`)return e;if(typeof e==`object`&&e){let t=e.counter;if(typeof t==`number`)return t}throw Error(`CounterOutcome requires a numeric counter`)}const G={parse:e=>W(e),serialize:e=>JSON.stringify({counter:e})},K={parse:e=>W(e),serialize:e=>JSON.stringify({counter:Math.trunc(e)})};function q(e){if(typeof e==`object`&&e){let{counter:t,generation:n}=e;if(typeof t==`number`&&(n===void 0||typeof n==`number`))return{counter:t,generation:n??0}}throw Error(`GenerationCounterOutcome requires a numeric counter`)}const J={parse:e=>q(e),serialize:e=>JSON.stringify({counter:e.counter,generation:e.generation+1})},se={codec:o,makeOutcome:(e,t)=>c(e,t===0?`completed`:`failed`)},ce={codec:G,makeOutcome:(e,t)=>t};function Y(e,t,n){m(`execution attempt outcome parity (${e.name}, ${t})`,()=>{let t=_(e,n.codec);g(`commits an outcome, reports the stored one on replay, and conflicts on a different one`,async()=>{let e=t(),r=b();await e.repository.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y});let a=n.makeOutcome(r.executionId,0);h(await e.peer.commitOutcome({executionAttemptId:r.executionAttemptId,executionId:`${r.executionId}-foreign-owner`,result:e.peer.canonicalizeOutcome(a)})).toEqual({kind:`fenced`});let o=await e.repository.recovery.getAttemptWithAllocation(r.executionAttemptId);h(o).toMatchObject({executionId:r.executionId,status:`pending`,operationStartGate:`open`}),h(o?.settlementKind??null).toBeNull(),h(await e.repository.getActiveAttempt(r.executionId,r.executionAttemptId)).toMatchObject({executionAttemptId:r.executionAttemptId});let s=e.repository.canonicalizeOutcome(a).text;h(await e.repository.commitOutcome({...r,result:e.repository.canonicalizeOutcome(a)})).toEqual({kind:`accepted`,outcome:a,text:s}),h(await e.repository.commitOutcome({...r,result:e.repository.canonicalizeOutcome(n.makeOutcome(r.executionId,0))})).toEqual({kind:`duplicate`,outcome:a,text:s}),h(await e.repository.commitOutcome({...r,result:e.repository.canonicalizeOutcome(n.makeOutcome(r.executionId,1))})).toEqual({kind:`conflict`})})})}function le(e){Y(e,`workflow run result`,se),Y(e,`counter`,ce)}function ue(e){m(`execution attempt outcome parity (${e.name}, normalizing codec)`,()=>{let t=_(e,K);g(`commits, replays, and conflicts on the truncated counter the codec persists`,async()=>{let e=t(),n=b();await e.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(1.2)})).toEqual({kind:`accepted`,outcome:1,text:`{"counter":1}`}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(1.7)})).toEqual({kind:`duplicate`,outcome:1,text:`{"counter":1}`}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(2.5)})).toEqual({kind:`conflict`})})})}function de(e){m(`execution attempt outcome parity (${e.name}, non-idempotent serialization)`,()=>{let t=_(e,J);g(`replays an identical submission as duplicate against the text it stored`,async()=>{let e=t(),n=b();await e.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y});let r={counter:0,generation:0};h(J.serialize(r)).toBe(J.serialize(r));let a=e.repository.canonicalizeOutcome(r);h(a).toEqual({text:`{"counter":0,"generation":1}`,outcome:{counter:0,generation:1}}),h(await e.repository.commitOutcome({...n,result:a})).toEqual({kind:`accepted`,outcome:{counter:0,generation:1},text:`{"counter":0,"generation":1}`}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome({counter:0,generation:0})})).toEqual({kind:`duplicate`,outcome:{counter:0,generation:1},text:`{"counter":0,"generation":1}`}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome({counter:4,generation:0})})).toEqual({kind:`conflict`})})})}function fe(e){if(e instanceof URL)return new URL(e.href);if(typeof e==`string`)return new URL(e);throw Error(`UrlOutcome requires a URL or an absolute URL string`)}const pe={parse:e=>fe(e),serialize:e=>JSON.stringify(e.href)};function me(e){m(`execution attempt outcome parity (${e.name}, non-cloneable outcome)`,()=>{let t=_(e,pe);g(`commits and replays an outcome structuredClone would refuse`,async()=>{let e=t(),n=b();await e.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y}),h(()=>structuredClone(new URL(`https://outcome.test/a`))).toThrow();let r=new URL(`https://outcome.test/a`),a=await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(r)});h(a.kind).toBe(`accepted`);let o=a.kind===`accepted`?a.outcome:null;h(o?.href).toBe(`https://outcome.test/a`),h(o).not.toBe(r);let s=await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(new URL(`https://outcome.test/a`))});h(s.kind).toBe(`duplicate`),h(s.kind===`duplicate`?s.outcome.href:null).toBe(`https://outcome.test/a`),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(new URL(`https://outcome.test/b`))})).toEqual({kind:`conflict`})}),g(`reports a committed outcome no earlier reader can have mutated`,async()=>{let e=t(),n=b();await e.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y});let r=await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(new URL(`https://outcome.test/a`))}),a=r.kind===`accepted`?r.outcome:null;a!==null&&(a.pathname=`/mutated`),h(a?.href).toBe(`https://outcome.test/mutated`);let o=await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(new URL(`https://outcome.test/a`))});h(o.kind).toBe(`duplicate`);let s=o.kind===`duplicate`?o.outcome:null;h(s?.href).toBe(`https://outcome.test/a`),h(s).not.toBe(a)}),g(`reports an accepted outcome decoded from the stored text, not the rendering the caller held`,async()=>{let e=t(),n=b();await e.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y});let r=e.repository.canonicalizeOutcome(new URL(`https://outcome.test/a`));r.outcome.pathname=`/mutated`,h(r.outcome.href).toBe(`https://outcome.test/mutated`),h(r.text).toBe(`"https://outcome.test/a"`);let a=await e.repository.commitOutcome({...n,result:r});h(a.kind).toBe(`accepted`),h(a.kind===`accepted`?a.outcome.href:null).toBe(`https://outcome.test/a`);let o=await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(new URL(`https://outcome.test/a`))});h(o.kind).toBe(`duplicate`),h(o.kind===`duplicate`?o.outcome.href:null).toBe(`https://outcome.test/a`)}),g(`decodes a durable text into a fresh outcome on every call`,async()=>{let e=t(),n=e.repository.canonicalizeOutcome(new URL(`https://outcome.test/a`)).text,r=e.repository.decodeOutcome(n);h(r.href).toBe(`https://outcome.test/a`),h(r).not.toBe(e.repository.decodeOutcome(n)),h(()=>e.repository.decodeOutcome(`5`)).toThrow()})})}function he(e){if(e instanceof Uint8Array||Array.isArray(e)&&e.every(e=>typeof e==`number`))return Uint8Array.from(e);throw Error(`BytesOutcome requires a Uint8Array or an array of byte values`)}const ge={parse:e=>he(e),serialize:e=>JSON.stringify(Array.from(e))};function _e(e){m(`execution attempt outcome parity (${e.name}, unfreezable outcome)`,()=>{let t=_(e,ge);g(`commits and replays an outcome Object.freeze would refuse`,async()=>{let e=t(),n=b();await e.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y}),h(()=>Object.freeze(Uint8Array.from([1,2,3]))).toThrow();let r=Uint8Array.from([1,2,3]),a=e.repository.canonicalizeOutcome(r);h(a.text).toBe(`[1,2,3]`);let o=await e.repository.commitOutcome({...n,result:a});h(o.kind).toBe(`accepted`);let s=o.kind===`accepted`?o.outcome:null;h(s).toEqual(Uint8Array.from([1,2,3])),h(s).not.toBe(r);let c=await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(Uint8Array.from([1,2,3]))});h(c.kind).toBe(`duplicate`),h(c.kind===`duplicate`?c.outcome:null).toEqual(Uint8Array.from([1,2,3])),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(Uint8Array.from([4]))})).toEqual({kind:`conflict`})})})}function ve(e){m(`execution attempt outcome parity (${e.name}, invalid stored outcome)`,()=>{let t=_(e,G);g(`throws instead of reporting conflict when the stored outcome does not parse`,async()=>{let e=t(),n=b();await e.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y}),await e.writeStoredOutcomeText(n.executionAttemptId,`"not-a-number"`),await h(e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(5)})).rejects.toThrow()})})}function ye(e){g(`keeps one canonical winner when two distinct outcomes race across controllers`,async()=>{let t=e(),n=b();await t.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y});let r=t.repository.canonicalizeOutcome(c(n.executionId,`completed`)),a=t.peer.canonicalizeOutcome(c(n.executionId,`failed`)),o=await Promise.all([t.repository.commitOutcome({...n,result:r}),t.peer.commitOutcome({...n,result:a})]);h(o.map(e=>e.kind).sort()).toEqual([`accepted`,`conflict`]);let s=o[0]?.kind===`accepted`?r:a;h(o.find(e=>e.kind===`accepted`)).toEqual({kind:`accepted`,outcome:s.outcome,text:s.text}),h(await t.peer.commitOutcome({...n,result:s})).toEqual({kind:`duplicate`,outcome:s.outcome,text:s.text}),h(await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).toMatchObject({status:`settled`,settlementKind:`outcome`})}),g(`keeps the actual winner stable when an outcome races confirmed infrastructure failure`,async()=>{let t=e(),n=b(),i=await x(t.repository,n);await t.repository.recordAllocation({claim:i,allocationRef:r()}),h(await t.repository.recordAllocationTerminated({claim:i,evidence:a()})).toEqual({kind:`recorded`});let o=t.repository.canonicalizeOutcome(c(n.executionId)),[s,l]=await Promise.all([t.repository.commitOutcome({...n,result:o}),t.peer.recordInfrastructureFailure({claim:i,executionId:n.executionId})]),u=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);if(h(await t.peer.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(u),s.kind===`accepted`){h(s).toEqual({kind:`accepted`,outcome:o.outcome,text:o.text}),h(l).toEqual({kind:`resolved`}),h(u).toMatchObject({status:`settled`,settlementKind:`outcome`}),h(await t.peer.commitOutcome({...n,result:o})).toEqual({kind:`duplicate`,outcome:o.outcome,text:o.text});return}h(s).toEqual({kind:`conflict`}),h(l).toEqual({kind:`recorded`}),h(u).toMatchObject({status:`settled`,settlementKind:`infrastructure-failure`}),h(await t.repository.recordInfrastructureFailure({claim:i,executionId:n.executionId})).toEqual({kind:`resolved`})})}function be(e){xe(e),Se(e),Ce(e)}function xe(e){g(`refuses begin provisioning for an allocated attempt without changing its authorization`,async()=>{let t=e(),i=b(),a=await w(t.repository,i),o=await t.repository.recovery.getAttemptWithAllocation(i.executionAttemptId),s=await t.repository.getProviderOperation(i.executionAttemptId),c=r();h(await t.peer.beginProvisioning(n(i.executionAttemptId,i.executionId))).toEqual({kind:`allocated`,allocationRef:c}),h(await t.repository.recovery.getAttemptWithAllocation(i.executionAttemptId)).toEqual(o),h(await t.peer.getProviderOperation(i.executionAttemptId)).toEqual(s),h(await t.repository.recordAllocation({claim:a,allocationRef:c})).toEqual({kind:`duplicate`,allocationRef:c})}),g(`refuses begin provisioning for a resolved attempt without changing its closed authorization`,async()=>{let t=e(),r=b(),i=await x(t.repository,r);h(await t.repository.recordProvisioningAbsent({claim:i,executionId:r.executionId,evidence:a()})).toEqual({kind:`recorded`});let o=await t.repository.recovery.getAttemptWithAllocation(r.executionAttemptId),s=await t.repository.getProviderOperation(r.executionAttemptId);h(await t.peer.beginProvisioning(n(r.executionAttemptId,r.executionId))).toEqual({kind:`resolved`,allocationRef:null}),h(await t.repository.recovery.getAttemptWithAllocation(r.executionAttemptId)).toEqual(o),h(await t.peer.getProviderOperation(r.executionAttemptId)).toEqual(s)}),g(`refuses begin provisioning for a superseded attempt without changing its authorization`,async()=>{let t=e(),r=b();await x(t.repository,r),await t.peer.createAttempt({executionId:r.executionId,executionAttemptId:`${r.executionAttemptId}-replacement`,instruction:i(),bootstrapTimeoutMs:y});let a=await t.repository.recovery.getAttemptWithAllocation(r.executionAttemptId),o=await t.repository.getProviderOperation(r.executionAttemptId);h(await t.peer.beginProvisioning(n(r.executionAttemptId,r.executionId))).toEqual({kind:`fenced`}),h(await t.repository.recovery.getAttemptWithAllocation(r.executionAttemptId)).toEqual(a),h(await t.peer.getProviderOperation(r.executionAttemptId)).toEqual(o)}),g(`refuses begin provisioning for an unknown attempt without authorizing a provider operation`,async()=>{let t=e(),r=b();h(await t.repository.beginProvisioning(n(r.executionAttemptId,r.executionId))).toEqual({kind:`not-found`}),h(await t.peer.getProviderOperation(r.executionAttemptId)).toBeNull()})}function Se(e){g(`refuses provisioning absence for a different execution without changing durable state`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),o=await t.repository.getProviderOperation(n.executionAttemptId);h(await t.peer.recordProvisioningAbsent({claim:r,executionId:`${n.executionId}-foreign`,evidence:a()})).toEqual({kind:`not-found`}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(i),h(await t.peer.getProviderOperation(n.executionAttemptId)).toEqual(o)}),g(`refuses provisioner loss for a different execution without changing durable state`,async()=>{let t=e(),n=b(),r=`foreign-owner-process-loss`,i=await x(t.repository,n,{allocationLifetime:`provisioner-process-bound`,provisionerIncarnationId:r}),a=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),o=await t.repository.getProviderOperation(n.executionAttemptId);h(await t.peer.recordProvisionerIncarnationLost({claim:i,executionId:`${n.executionId}-foreign`,proof:d(r)})).toEqual({kind:`not-found`}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(a),h(await t.peer.getProviderOperation(n.executionAttemptId)).toEqual(o)}),g(`refuses infrastructure failure for a different execution without changing durable state`,async()=>{let t=e(),n=b(),r=await w(t.repository,n);h(await t.repository.recordAllocationTerminated({claim:r,evidence:a()})).toEqual({kind:`recorded`});let i=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),o=await t.repository.getProviderOperation(n.executionAttemptId);h(await t.peer.recordInfrastructureFailure({claim:r,executionId:`${n.executionId}-foreign`})).toEqual({kind:`not-found`}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(i),h(await t.peer.getProviderOperation(n.executionAttemptId)).toEqual(o)}),g(`refuses allocation reference evolution for a different execution without changing durable state`,async()=>{let t=e(),n=b(),i=await w(t.repository,n),a=r(),o=r(a.providerId,{runId:1,jobId:`foreign-owner-refinement`}),s=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),c=await t.repository.getProviderOperation(n.executionAttemptId);h(await t.peer.recovery.evolveAllocationRef({claim:i,executionId:`${n.executionId}-foreign`,currentRef:a,nextRef:o})).toEqual({kind:`not-found`}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(s),h(await t.peer.getProviderOperation(n.executionAttemptId)).toEqual(c)})}function Ce(e){g(`retains allocation control and claim ownership when uncertainty is recorded before termination`,async()=>{let t=e(),n=b(),r=await w(t.repository,n),i=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),o=a({summary:`provider cannot yet confirm allocation termination`});h(await t.peer.recordProviderOperationUncertainty({claim:r,evidence:o})).toEqual({kind:`recorded`}),h(await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(i),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({...r,obligation:`allocation-control`,failureCount:1,lastFailure:o})}),g(`refuses takeover of an unknown attempt without manufacturing an operation or attempt`,async()=>{let t=e(),n=b(),r={executionAttemptId:n.executionAttemptId,ownerId:`unknown-takeover-controller`,observedAt:u(0),leaseExpiresAt:u(6e4)};h(await t.peer.takeOverProviderOperation(r)).toEqual({kind:`not-found`});for(let e of[t.repository,t.peer])h(await e.getProviderOperation(n.executionAttemptId)).toBeNull(),h(await e.recovery.getAttemptWithAllocation(n.executionAttemptId)).toBeNull()})}function we(e){g(`returns one canonical readiness instant when peer readiness reports race`,async()=>{let t=e(),n=b();await w(t.repository,n);let r=await T(t.repository,n),i=`2026-09-07T10:00:00.000Z`,a=`2026-09-07T10:00:01.000Z`,o=await Promise.all([t.repository.markRuntimeReady({...n,runtimeGeneration:r,readyAt:i}),t.peer.markRuntimeReady({...n,runtimeGeneration:r,readyAt:a})]);h(o.map(e=>e.kind).sort()).toEqual([`duplicate`,`ready`]);let s=o.findIndex(e=>e.kind===`ready`);if(s===-1)throw Error(`Expected one ready decision`);let c=[i,a][s];if(c===void 0)throw Error(`Ready decision had no matching input`);h(o[s]).toEqual({kind:`ready`,acceptedAt:c}),h(o[(s+1)%o.length]).toEqual({kind:`duplicate`,acceptedAt:c}),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeReadyAt:c})}),g(`reports not-ready before stale generation and stale generation after readiness`,async()=>{let t=e(),n=b();await w(t.repository,n);let r=await T(t.repository,n),i={...n,operationKind:`workflow-run`,admissionKey:`stale-generation`,runtimeGeneration:r-1};h(await t.repository.admitOperation(i)).toEqual({kind:`not-ready`}),h(await t.repository.markRuntimeReady({...n,runtimeGeneration:r,readyAt:`2026-09-07T10:01:00.000Z`})).toMatchObject({kind:`ready`}),h(await t.peer.admitOperation(i)).toEqual({kind:`stale-generation`,runtimeGeneration:r});let a=await t.repository.admitOperation({...i,admissionKey:`current-generation`,runtimeGeneration:r});if(h(a.kind).toBe(`admitted`),a.kind!==`admitted`)throw Error(`Expected current-generation admission`);h(await t.peer.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:a.operationId,activeOperationKind:`workflow-run`,activeOperationKey:`current-generation`,activeOperationGeneration:r})}),g(`completes one peer race once and clears every active operation field`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i=await D(t.repository,n,r,`runtime-probe`,`complete-race`),a={executionAttemptId:n.executionAttemptId,operationId:i,runtimeGeneration:r};h((await Promise.all([t.repository.completeOperation(a),t.peer.completeOperation(a)])).map(e=>e.kind).sort()).toEqual([`completed`,`duplicate`]),h(await t.repository.getAttemptControlState(n.executionAttemptId)).toMatchObject({activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null,lastCompletedOperationId:i})})}const Te=[`registration`,`readiness`,`admission`,`Preparation report`];async function Ee(e,t,n){let r={executionId:n.executionId,executionAttemptId:n.executionAttemptId};switch(t){case`registration`:return e.registerRuntime({...r,runtimeIncarnationId:S});case`readiness`:return e.markRuntimeReady({...r,runtimeGeneration:n.runtimeGeneration,readyAt:new Date().toISOString()});case`admission`:return e.admitOperation({...r,runtimeGeneration:n.runtimeGeneration,operationKind:`workspace-preparation`,admissionKey:`prepare`});case`Preparation report`:return e.reportOperation(n)}}function De(e){let t=Te.flatMap(e=>[`unknown attempt`,`foreign owner`].map(t=>({endpoint:e,identity:t})));g.each(t)(`refuses $identity at $endpoint without changing either real attempt`,async({endpoint:t,identity:n})=>{let r=e(),a=await C(r.repository),o=b();await r.repository.createAttempt({...o,instruction:i(),bootstrapTimeoutMs:y});let s=await r.repository.recovery.getAttemptWithAllocation(a.executionAttemptId),c=await r.repository.recovery.getAttemptWithAllocation(o.executionAttemptId),l=n===`unknown attempt`?{...a,executionAttemptId:`${a.executionAttemptId}-unknown`}:{...a,executionId:o.executionId};h(await Ee(r.peer,t,l)).toEqual({kind:`not-found`}),h(await r.peer.recovery.getAttemptWithAllocation(a.executionAttemptId)).toEqual(s),h(await r.peer.recovery.getAttemptWithAllocation(o.executionAttemptId)).toEqual(c),h(await r.repository.reportOperation(a)).toEqual({kind:`accepted`,binding:a.result.binding})}),g(`refuses completion of an unknown attempt without releasing a real Preparation slot`,async()=>{let t=e(),n=await C(t.repository),r=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(await t.peer.completeOperation({executionAttemptId:`${n.executionAttemptId}-unknown`,operationId:n.operationId,runtimeGeneration:n.runtimeGeneration})).toEqual({kind:`not-found`}),h(await t.peer.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(r),h(await t.repository.reportOperation(n)).toEqual({kind:`accepted`,binding:n.result.binding})})}async function Oe(e,t,n){switch(n){case`resolved`:h(await e.repository.commitOutcome({executionId:t.executionId,executionAttemptId:t.executionAttemptId,result:e.repository.canonicalizeOutcome(c(t.executionId,`failed`))})).toMatchObject({kind:`accepted`});break;case`fenced`:await e.repository.createAttempt({executionId:t.executionId,executionAttemptId:`${t.executionAttemptId}-successor`,instruction:i(),bootstrapTimeoutMs:y});break;case`not-allocated`:{let n=await e.repository.takeOverProviderOperation({executionAttemptId:t.executionAttemptId,ownerId:`preparation-termination-observer`,observedAt:u(12e4),leaseExpiresAt:u(18e4)});if(n.kind!==`claimed`)throw Error(`Expected takeover, got '${n.kind}'`);h(await e.repository.recordAllocationTerminated({claim:n.claim,evidence:a()})).toEqual({kind:`recorded`});break}case`no-active-operation`:return h(await e.repository.reportOperation(t)).toEqual({kind:`accepted`,binding:t.result.binding}),{...t,operationId:`${t.operationId}-unadmitted`};case`operation-mismatch`:return{...t,operationId:`${t.operationId}-different`}}return t}function ke(e){g.each([`resolved`,`fenced`,`not-allocated`,`no-active-operation`,`operation-mismatch`])(`retains Preparation receipts and operation state after a %s report refusal`,async t=>{let n=e(),r=await C(n.repository),i=await Oe(n,r,t),a=await n.repository.recovery.getAttemptWithAllocation(i.executionAttemptId),o=t===`no-active-operation`;h(a).toMatchObject({activeOperationId:o?null:r.operationId,activeOperationKind:o?null:`workspace-preparation`,preparationReceipts:o?[{operationId:r.operationId,runtimeGeneration:r.runtimeGeneration,result:r.result}]:[]}),h(await n.peer.reportOperation(i)).toEqual({kind:t}),h(await n.peer.recovery.getAttemptWithAllocation(i.executionAttemptId)).toEqual(a)})}function Ae(e){g(`grants an expired provider operation to exactly one of two competing controllers`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=a({summary:`provider lookup is still inconclusive`});h(await t.repository.recordProviderOperationUncertainty({claim:r,evidence:i})).toEqual({kind:`recorded`});let o=new Date(Date.parse(r.leaseExpiresAt)+1).toISOString(),s=new Date(Date.parse(r.leaseExpiresAt)+6e4).toISOString(),c={executionAttemptId:n.executionAttemptId,ownerId:`provider-atomicity-primary`,observedAt:o,leaseExpiresAt:s},l={...c,ownerId:`provider-atomicity-peer`},u=await Promise.all([t.repository.takeOverProviderOperation(c),t.peer.takeOverProviderOperation(l)]);h(u.map(e=>e.kind).sort()).toEqual([`claimed`,`stale`]);let d=u.find(e=>e.kind===`claimed`);if(!d||d.kind!==`claimed`)throw Error(`Expected one takeover claim`);h(d.claim).toMatchObject({executionAttemptId:n.executionAttemptId,generation:r.generation+1,leaseExpiresAt:s}),h(d.claim.ownerId).toBe(u[0]?.kind===`claimed`?c.ownerId:l.ownerId),h(d.claim.token).not.toBe(r.token);for(let e of[t.repository,t.peer])h(await e.getProviderOperation(n.executionAttemptId)).toMatchObject({...d.claim,obligation:`provisioning-resolution`,failureCount:1,lastFailure:i})}),g(`retains one actual discovered allocation when distinct same-provider discoveries race`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a=r(s,{machineId:`discovery-race-primary`}),o=r(s,{machineId:`discovery-race-peer`}),c=await Promise.all([t.repository.recovery.recordDiscoveredAllocation({claim:i,allocationRef:a}),t.peer.recovery.recordDiscoveredAllocation({claim:i,allocationRef:o})]);h(c.map(e=>e.kind).sort()).toEqual([`conflict`,`recorded`]);let l=c[0]?.kind===`recorded`?a:o;h(c.find(e=>e.kind===`conflict`)).toEqual({kind:`conflict`,allocationRef:l});let u=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(await t.peer.recovery.getAttemptWithAllocation(n.executionAttemptId)).toEqual(u),h(u).toMatchObject({status:`allocated`,allocationRef:l}),h(u?.claimable??!1).toBe(!1);for(let e of[t.repository,t.peer])h(await e.getProviderOperation(n.executionAttemptId)).toMatchObject({obligation:`allocation-control`})})}function X(e){g(`leaves one active attempt and closes its predecessor gate after concurrent distinct creations`,async()=>{let t=e(),n=b(),r={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-peer`};await Promise.all([t.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y}),t.peer.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y})]);let a=(await Promise.all([t.repository.getActiveAttempt(n.executionId,n.executionAttemptId),t.repository.getActiveAttempt(r.executionId,r.executionAttemptId)])).filter(e=>e!==null);h(a).toHaveLength(1);let o=a[0];if(!o)throw Error(`Expected one active attempt after concurrent creation`);for(let e of[t.repository,t.peer])for(let t of[n,r]){let n=t.executionAttemptId===o.executionAttemptId,r=await e.getActiveAttempt(t.executionId,t.executionAttemptId);n?h(r).toMatchObject({...t,status:`pending`,operationStartGate:`open`}):h(r).toBeNull(),h(await e.recovery.getAttemptWithAllocation(t.executionAttemptId)).toMatchObject({...t,status:`pending`,operationStartGate:n?`open`:`closed`})}}),g(`rejects an invalid instruction without storing a row or consuming its attempt identifier`,async()=>{let t=e(),n=b(),r=i();await h(t.repository.createAttempt({...n,instruction:{...r,revision:``},bootstrapTimeoutMs:y})).rejects.toThrow();for(let e of[t.repository,t.peer])h(await e.recovery.getAttemptWithAllocation(n.executionAttemptId)).toBeNull(),h(await e.getInstruction(n)).toBeNull(),h(await e.getActiveAttempt(n.executionId,n.executionAttemptId)).toBeNull();h(await t.peer.createAttempt({...n,instruction:r,bootstrapTimeoutMs:y})).toMatchObject({...n,status:`pending`,instruction:r,operationStartGate:`open`});for(let e of[t.repository,t.peer])h(await e.getInstruction(n)).toEqual(r),h(await e.getActiveAttempt(n.executionId,n.executionAttemptId)).toMatchObject({...n,status:`pending`,operationStartGate:`open`})})}function je(e){g(`orders offset-form takeover observations as instants and stores the new lease in canonical UTC`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=new Date(Date.parse(r.leaseExpiresAt)),a=Z(new Date(i.getTime()-1e3),120),o=Z(new Date(i.getTime()+1e3),-120),s=new Date(i.getTime()+6e4),c=Z(s,120),l=s.toISOString();h(a>r.leaseExpiresAt).toBe(!0),h(Date.parse(a)).toBeLessThan(Date.parse(r.leaseExpiresAt)),h(await t.peer.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`offset-before-expiry-controller`,observedAt:a,leaseExpiresAt:c})).toEqual({kind:`stale`}),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject(r),h(o<r.leaseExpiresAt).toBe(!0),h(Date.parse(o)).toBeGreaterThan(Date.parse(r.leaseExpiresAt));let u=await t.peer.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`offset-after-expiry-controller`,observedAt:o,leaseExpiresAt:c});if(h(u.kind).toBe(`claimed`),u.kind!==`claimed`)throw Error(`Expected takeover after the lease expiry instant`);h(u.claim).toMatchObject({generation:r.generation+1,ownerId:`offset-after-expiry-controller`,leaseExpiresAt:l}),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({...u.claim,leaseExpiresAt:l})})}function Z(e,t){let n=new Date(e.getTime()+t*6e4),r=Math.abs(t),i=t>=0?`+`:`-`,a=e=>e.toString().padStart(2,`0`);return`${n.toISOString().slice(0,-1)}${i}${a(Math.floor(r/60))}:${a(r%60)}`}function Me(e){g(`retains an accepted Preparation receipt after caller aliases are mutated`,async()=>{let t=e(),n=await C(t.repository,[{id:`source`,path:`source`}]),r=structuredClone(n),i=structuredClone(n.result.binding);h(await t.repository.reportOperation(n)).toEqual({kind:`accepted`,binding:i});let a=n.result.binding.sourceRoots[0];if(a===void 0)throw Error(`Expected the Preparation fixture to bind one source root`);Reflect.set(n.result.binding,`workspaceRoot`,`/mutated-workspace`),Reflect.set(a,`path`,`/mutated-workspace/source`),Reflect.set(n.result.binding.sourceRoots,0,{id:`replacement-source`,path:`/replacement`}),h((await t.peer.getActiveAttempt(r.executionId,r.executionAttemptId))?.preparationReceipts).toEqual([{operationId:r.operationId,runtimeGeneration:r.runtimeGeneration,result:r.result}]),h(await t.peer.reportOperation(r)).toEqual({kind:`duplicate`,binding:i})})}function Ne(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&`alpha`in e&&`beta`in e&&typeof e.alpha==`number`&&Number.isFinite(e.alpha)&&typeof e.beta==`number`&&Number.isFinite(e.beta)}const Pe={parse:e=>{if(!Ne(e))throw Error(`MemberOrderOutcome requires numeric alpha and beta members`);return e},serialize:e=>JSON.stringify(e)};function Fe(e){m(`execution attempt outcome parity (${e.name}, member-order codec)`,()=>{let t=_(e,Pe);g(`replays equivalent reordered members with the first committed durable text`,async()=>{let e=t(),n=b();await e.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y});let r=e.repository.canonicalizeOutcome({alpha:1,beta:2}),a=e.peer.canonicalizeOutcome({beta:2,alpha:1});h(r.text).not.toBe(a.text),h(await e.repository.commitOutcome({...n,result:r})).toEqual({kind:`accepted`,outcome:{alpha:1,beta:2},text:r.text}),h(await e.peer.commitOutcome({...n,result:a})).toEqual({kind:`duplicate`,outcome:{alpha:1,beta:2},text:r.text}),h(await e.peer.commitOutcome({...n,result:e.peer.canonicalizeOutcome({beta:2,alpha:3})})).toEqual({kind:`conflict`})})})}function Ie(e){g(`orders every recoverable candidate by creation instant, then by attempt identifier`,async()=>{let t=e(),{executionId:n}=b(),r={executionAttemptId:`${n}-z`,createdAt:`2026-01-01T00:00:00.000Z`},i={executionAttemptId:`${n}-a`,createdAt:`2026-01-02T00:00:00.000Z`},a={executionAttemptId:`${n}-b`,createdAt:i.createdAt};await t.seedRecoverableAttempts({executionId:n,entries:[a,r,i]});for(let e of[t.repository,t.peer])h((await e.recovery.getRecoverableAttempts(n)).map(({executionAttemptId:e,createdAt:t})=>({executionAttemptId:e,createdAt:t}))).toEqual([r,i,a])})}function Le(e){g(`preserves an allocated outcome settlement through abandonment replays`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),a=r();h(await t.repository.recordAllocation({claim:i,allocationRef:a})).toEqual({kind:`recorded`}),await Q(t,n.executionAttemptId,a);let o=t.repository.canonicalizeOutcome(c(n.executionId)),s=await t.repository.commitOutcome({...n,result:o});if(s.kind!==`accepted`)throw Error(`Expected outcome acceptance, got '${s.kind}'`);h(s).toEqual({kind:`accepted`,outcome:o.outcome,text:o.text}),await $(t,n,a,`outcome`,async()=>{h(await t.peer.commitOutcome({...n,result:o})).toEqual({kind:`duplicate`,outcome:s.outcome,text:s.text})})}),g(`preserves an allocated infrastructure settlement through abandonment replays`,async()=>{let t=e(),n=b(),i=await x(t.repository,n),o=r();h(await t.repository.recordAllocation({claim:i,allocationRef:o})).toEqual({kind:`recorded`}),await Q(t,n.executionAttemptId,o),h(await t.repository.recordAllocationTerminated({claim:i,evidence:a()})).toEqual({kind:`recorded`}),h(await t.peer.recordInfrastructureFailure({claim:i,executionId:n.executionId})).toEqual({kind:`recorded`}),await $(t,n,o,`infrastructure-failure`)})}async function Q(e,t,n){h(await e.repository.recovery.getAttemptWithAllocation(t)).toMatchObject({status:`allocated`,settlementKind:null,allocationRef:n})}async function $(e,t,n,r,i){let a=await e.repository.recovery.getAttemptWithAllocation(t.executionAttemptId);if(a===null)throw Error(`Expected a settled attempt`);h(a).toMatchObject({status:`settled`,settlementKind:r,allocationRef:n});let o=await e.repository.getProviderOperation(t.executionAttemptId);if(o===null)throw Error(`Expected a settled provider operation`);let s=structuredClone(a),c=structuredClone(o);for(let n of[e.repository,e.peer])h(await n.recovery.getRecoverableAttempts(t.executionId)).toEqual([]);for(let n of[e.repository,e.peer])h(await n.abandonPendingAttempt(t.executionAttemptId,t.executionId)).toEqual({kind:`already-settled`}),h(await n.recovery.getRecoverableAttempts(t.executionId)).toEqual([]);await i?.();for(let n of[e.repository,e.peer])h(await n.recovery.getAttemptWithAllocation(t.executionAttemptId)).toEqual(s),h(await n.getProviderOperation(t.executionAttemptId)).toEqual(c)}function Re(e){g(`persists the bootstrap deadline at the declared budget after its creation instant`,async()=>{let t=e(),n=b(),r=await t.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:12345});h(Date.parse(r.bootstrapDeadlineAt??``)-Date.parse(r.createdAt)).toBe(12345),h(await t.peer.getActiveAttempt(n.executionId,n.executionAttemptId)).toEqual(r)}),g.each([0,-1,.5,NaN,1/0,-1/0,2**53-1,864e13])(`rejects invalid or overflowing bootstrap budget %s before moving the active pointer`,async t=>{let n=e(),r=b(),a=await n.repository.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y}),o={executionId:r.executionId,executionAttemptId:b().executionAttemptId};await h(n.peer.createAttempt({...o,instruction:i(),bootstrapTimeoutMs:t})).rejects.toThrow(),h(await n.repository.getActiveAttempt(r.executionId,r.executionAttemptId)).toEqual(a),h(await n.repository.readBootstrapStartState(o)).toBeNull(),h(await n.peer.readBootstrapStartState(r)).toMatchObject({active:!0,operationStartGate:`open`})}),g(`reads coherent bootstrap facts through provisioning, allocation, termination and settlement`,async()=>{let t=e(),n=b();h(await t.repository.readBootstrapStartState(n)).toBeNull();let i=await x(t.repository,n),o=await t.peer.readBootstrapStartState(n);h(o).toEqual({settled:!1,active:!0,allocated:!1,allocationTerminated:!1,operationStartGate:`open`,bootstrapDeadlineAt:h.any(String)}),h(await t.peer.readBootstrapStartState({...n,executionId:`wrong-owner`})).toBeNull(),await t.repository.recordAllocation({claim:i,allocationRef:r()}),h(await t.peer.readBootstrapStartState(n)).toEqual({...o,allocated:!0}),await t.repository.recordAllocationTerminated({claim:i,evidence:a()}),h(await t.peer.readBootstrapStartState(n)).toEqual({...o,allocated:!0,allocationTerminated:!0}),await t.repository.recordInfrastructureFailure({claim:i,executionId:n.executionId}),h(await t.peer.readBootstrapStartState(n)).toEqual({...o,allocated:!0,allocationTerminated:!0,settled:!0,operationStartGate:`closed`})}),g(`reports supersession without hiding the historical allocation or changing its deadline`,async()=>{let t=e(),n=b();await w(t.repository,n);let r=await t.peer.readBootstrapStartState(n),a={executionId:n.executionId,executionAttemptId:b().executionAttemptId};await t.repository.createAttempt({...a,instruction:i(),bootstrapTimeoutMs:1}),h(await t.peer.readBootstrapStartState(n)).toEqual({...r,active:!1,operationStartGate:`closed`}),h(await t.peer.readBootstrapStartState(a)).toMatchObject({active:!0,allocated:!1,operationStartGate:`open`})}),g.each([`pending`,`allocated`,`settled`])(`keeps legacy %s attempts readable without extending bootstrap`,async t=>{let n=e(),r=b();t===`pending`?await n.repository.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y}):await w(n.repository,r),t===`settled`&&await n.repository.commitOutcome({...r,result:n.repository.canonicalizeOutcome(c(r.executionId,`completed`))}),await n.clearStoredBootstrapDeadline(r.executionAttemptId),h(await n.peer.readBootstrapStartState(r)).toMatchObject({bootstrapDeadlineAt:null,settled:t===`settled`,allocated:t!==`pending`}),h(await n.peer.getActiveAttempt(r.executionId,r.executionAttemptId)).toMatchObject({bootstrapDeadlineAt:null,status:t}),h(await n.peer.getInstruction(r)).toEqual(i()),t===`allocated`&&h((await n.peer.recovery.getRecoverableAttempts(r.executionId)).find(e=>e.executionAttemptId===r.executionAttemptId)).toMatchObject({bootstrapDeadlineAt:null})})}function ze(e){g(`keeps pending abandonment and provisioning mutually exclusive across controllers`,async()=>{let t=e(),r=b();await t.repository.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y});let[a,o]=await Promise.all([t.repository.abandonPendingAttempt(r.executionAttemptId,r.executionId),t.peer.beginProvisioning(n(r.executionAttemptId,r.executionId))]);if(a.kind===`abandoned`){h(o).toEqual({kind:`resolved`,allocationRef:null});for(let e of[t.repository,t.peer])h(await e.recovery.getAttemptWithAllocation(r.executionAttemptId)).toMatchObject({status:`settled`,settlementKind:`abandoned`,allocationRef:null}),h(await e.getAttemptControlState(r.executionAttemptId)).toMatchObject({operationStartGate:`closed`,activeOperationId:null}),h(await e.getProviderOperation(r.executionAttemptId)).toBeNull();return}if(h(a).toEqual({kind:`provisioning`}),o.kind!==`started`)throw Error(`Expected provisioning to start, got '${o.kind}'`);for(let e of[t.repository,t.peer])h(await e.recovery.getAttemptWithAllocation(r.executionAttemptId)).toMatchObject({status:`provisioning`,settlementKind:null,allocationRef:null}),h(await e.getAttemptControlState(r.executionAttemptId)).toMatchObject({operationStartGate:`open`,activeOperationId:null}),h(await e.getProviderOperation(r.executionAttemptId)).toMatchObject({...o.claim,obligation:`provisioning-resolution`})}),g(`keeps either the admitted generation-one run or the replacement runtime endpoint`,async()=>{let t=e(),n=b(),r=await O(t.repository,n),i={...n,operationKind:`workflow-run`,admissionKey:`mixed-authority-workflow-run`,runtimeGeneration:r},[a,o]=await Promise.all([t.repository.admitOperation(i),t.peer.registerRuntime({...n,runtimeIncarnationId:`mixed-authority-replacement`})]);if(a.kind===`admitted`){h(o).toEqual({kind:`operation-active`,operationId:a.operationId});for(let e of[t.repository,t.peer])h(await e.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:r,runtimeIncarnationId:S,runtimeReadyAt:h.any(String),activeOperationId:a.operationId,activeOperationKind:`workflow-run`,activeOperationGeneration:r});return}h(o).toEqual({kind:`registered`,runtimeGeneration:r+1}),h(a).toEqual({kind:`not-ready`});for(let e of[t.repository,t.peer])h(await e.getAttemptControlState(n.executionAttemptId)).toMatchObject({runtimeGeneration:r+1,runtimeIncarnationId:`mixed-authority-replacement`,runtimeReadyAt:null,activeOperationId:null})})}function Be(e){m(`execution attempt port parity (${e.name})`,()=>{let t=_(e,o);k(t),A(t),re(t),ie(t),ae(t),oe(t),N(t),P(t),F(t),L(t),U(t),ye(t),be(t),we(t),De(t),ke(t),Ae(t),X(t),je(t),Me(t),Ie(t),Le(t),Re(t),ze(t)}),le(e),ue(e),de(e),me(e),_e(e),ve(e),Fe(e)}export{Be as runExecutionAttemptRepositoryContract};
@@ -1,6 +1,6 @@
1
- import { a as ProviderOperationClaim, i as ProcessBoundProvisionerLossProof, l as ProviderOperationOwnershipRecord } from "../../provider-operation-DbdyFwNm.mjs";
2
- import { A as OutcomeCodec, F as RecordAllocationInput, P as ProvisioningClaimDecision, l as BeginProvisioningInput, r as AllocationRecordingDecision, s as AttemptControlState, w as ExecutionOwnerId, x as ExecutionAttemptRepository, y as ExecutionAttemptRecord } from "../../execution-attempt-repository-CRdrgou3.mjs";
3
- import { BoundedRecoveryEvidence, ProviderAllocationRef, WorkerAllocationLifetime, WorkflowRunResult } from "@makaio/framework/contracts";
1
+ import { a as ProviderOperationClaim, i as ProcessBoundProvisionerLossProof, l as ProviderOperationOwnershipRecord } from "../../provider-operation-B2wQST6N.mjs";
2
+ import { C as ExecutionAttemptRepository, E as ExecutionOwnerId, P as OutcomeCodec, V as RecordAllocationInput, r as AllocationRecordingDecision, s as AttemptControlState, u as BeginProvisioningInput, x as ExecutionAttemptRecord, z as ProvisioningClaimDecision } from "../../execution-attempt-repository-CgB7uiYD.mjs";
3
+ import { BoundedRecoveryEvidence, ExecutionAttemptInstruction, ExecutionAttemptPreparationResult, ProviderAllocationRef, WorkerAllocationLifetime, WorkflowRunResult } from "@makaio/framework/contracts";
4
4
 
5
5
  //#region subsystems/workflow-engine/src/testing/attempt-record-codec.d.ts
6
6
  /**
@@ -95,6 +95,12 @@ declare const TEST_OWNER_ID = "controller-incarnation-1";
95
95
  declare const TEST_PROVISIONER_INCARNATION_ID = "provisioner-incarnation-1";
96
96
  /** Provider identifier bound by the default begin-provisioning fixture. */
97
97
  declare const TEST_PROVIDER_ID = "test-provider";
98
+ /**
99
+ * Build an explicit test assignment without workspace or preservation obligations.
100
+ * @param overrides - Instruction fields specific to the scenario under test.
101
+ * @returns A complete owner-supplied test instruction.
102
+ */
103
+ declare function makeTestInstruction(overrides?: Partial<ExecutionAttemptInstruction>): ExecutionAttemptInstruction;
98
104
  /**
99
105
  * The single operation every provisioning-claim holder needs.
100
106
  *
@@ -185,9 +191,10 @@ interface AttemptAllocationDriver extends ProvisioningClaimGrantor {
185
191
  /**
186
192
  * Persist a new attempt for its owner.
187
193
  * @param executionId - Owner identifier the attempt belongs to.
194
+ * @param instruction - Frozen assignment supplied explicitly by the test owner.
188
195
  * @returns The persisted attempt record.
189
196
  */
190
- createAttempt(executionId: ExecutionOwnerId): Promise<ExecutionAttemptRecord>;
197
+ createAttempt(executionId: ExecutionOwnerId, instruction: ExecutionAttemptInstruction): Promise<ExecutionAttemptRecord>;
191
198
  /**
192
199
  * Record the allocation the provider returned for the claimed attempt.
193
200
  * @param input - The claim and the allocation reference to record.
@@ -216,4 +223,4 @@ declare function driveTestAttemptToAllocated(driver: Pick<AttemptAllocationDrive
216
223
  */
217
224
  declare function allocateTestAttempt(driver: AttemptAllocationDriver, executionId: ExecutionOwnerId): Promise<string>;
218
225
  //#endregion
219
- export { type AttemptAllocationDriver, INITIAL_ATTEMPT_CONTROL_STATE, type InMemoryAttemptRepository, type InMemoryAttemptRepositoryState, type ProvisioningClaimGrantor, TEST_OWNER_ID, TEST_PROVIDER_ID, TEST_PROVISIONER_INCARNATION_ID, allocateTestAttempt, beginTestProvisioning, createInMemoryAttemptRepository, driveTestAttemptToAllocated, leaseAt, makeBeginProvisioningInput, makeEvidence, makeProcessLossProof, makeTestAllocationRef, makeTestWorkflowResult, workflowRunResultOutcomeCodec };
226
+ export { type AttemptAllocationDriver, INITIAL_ATTEMPT_CONTROL_STATE, type InMemoryAttemptRepository, type InMemoryAttemptRepositoryState, type ProvisioningClaimGrantor, TEST_OWNER_ID, TEST_PROVIDER_ID, TEST_PROVISIONER_INCARNATION_ID, allocateTestAttempt, beginTestProvisioning, createInMemoryAttemptRepository, driveTestAttemptToAllocated, leaseAt, makeBeginProvisioningInput, makeEvidence, makeProcessLossProof, makeTestAllocationRef, makeTestInstruction, makeTestWorkflowResult, workflowRunResultOutcomeCodec };
@@ -1 +1 @@
1
- import{DuplicateExecutionAttemptError as e,decodeDurableOutcome as t,durableOutcome as n,sameAllocationRef as r,sameDurableOutcome as i}from"../execution-attempt-repository.mjs";import{a,c as o,i as s,l as c,n as l,o as u,r as d,s as f,t as p,u as m}from"../../attempt-record-codec-BORASgzn.mjs";import{BoundedRecoveryEvidenceSchema as h,PROVIDER_ALLOCATION_REF_VERSION as g,WorkflowRunResultSchema as _}from"@makaio/framework/contracts";function v(e,t){return{...e,status:`settled`,settlementKind:t,claimable:!1,operationStartGate:`closed`}}function y(g,_={}){let y=_.attempts??new Map,b=_.operations??new Map,x=e=>b.get(e)?.obligation===`terminal-convergence`,S=_.committedOutcomes??new Map,C=_.activeAttempts??new Map,w=e=>{let t=y.get(e.executionAttemptId),n=b.get(e.executionAttemptId);return!t||!n?{kind:`not-found`}:t.settlementKind==null?n.token===null||n.token!==e.token||n.generation!==e.generation||n.ownerId!==e.ownerId?{kind:`stale`,attempt:t}:{kind:`authorized`,attempt:t,operation:n}:{kind:`resolved`,attempt:t}},T=(e,t)=>{b.set(e.executionAttemptId,{...e,ownerId:null,token:null,leaseExpiresAt:null,lastFailure:t})},E=(e,t)=>{let n=u(e.allocationRef),i=w(e.claim);if(i.kind!==`not-found`&&o(i.attempt,n),i.kind===`resolved`)return{kind:`resolved`,allocationRef:i.attempt.allocationRef};if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a,operation:s}=i;if(a.allocationRef!==null)return r(a.allocationRef,n)?{kind:`duplicate`,allocationRef:a.allocationRef}:{kind:`conflict`,allocationRef:a.allocationRef};let c=C.get(a.executionId)===a.executionAttemptId;return y.set(a.executionAttemptId,{...a,status:`allocated`,allocationRef:n,claimable:t&&c}),b.set(s.executionAttemptId,{...s,obligation:`allocation-control`}),{kind:`recorded`}};return{async createAttempt(t){if(y.has(t.executionAttemptId))throw new e(t.executionAttemptId);let n={executionAttemptId:t.executionAttemptId,executionId:t.executionId,status:`pending`,allocationRef:null,createdAt:new Date().toISOString(),providerId:null,allocationLifetime:null,provisionerIncarnationId:null,settlementKind:null,claimable:!1,claimExpiresAt:null,...p},r=C.get(t.executionId),i=r===void 0?void 0:y.get(r);return i!==void 0&&y.set(i.executionAttemptId,{...i,claimable:i.status===`allocated`?!1:i.claimable,operationStartGate:`closed`}),y.set(t.executionAttemptId,n),C.set(t.executionId,t.executionAttemptId),n},async beginProvisioning(e){let t=a(e.allocationLifetime),n=y.get(e.executionAttemptId);if(!n||n.executionId!==e.executionId)return{kind:`not-found`};if(C.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};if(n.settlementKind!=null)return{kind:`resolved`,allocationRef:n.allocationRef};if(n.allocationRef!==null)return{kind:`allocated`,allocationRef:n.allocationRef};if(n.status!==`pending`)return{kind:`already-provisioning`};y.set(e.executionAttemptId,{...n,status:`provisioning`,providerId:e.providerId,allocationLifetime:t,provisionerIncarnationId:e.provisionerIncarnationId});let r={executionAttemptId:e.executionAttemptId,generation:1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:s(e.leaseExpiresAt)};return b.set(e.executionAttemptId,{executionAttemptId:e.executionAttemptId,generation:r.generation,ownerId:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt,obligation:`provisioning-resolution`,failureCount:0,lastFailure:null}),{kind:`started`,claim:r}},async getProviderOperation(e){return b.get(e)??null},async renewProviderOperationClaim(e){let t=w(e.claim);if(t.kind!==`authorized`)return{kind:t.kind};let n=s(e.leaseExpiresAt);return b.set(e.claim.executionAttemptId,{...t.operation,leaseExpiresAt:n}),{kind:`claimed`,claim:{...e.claim,leaseExpiresAt:n}}},async takeOverProviderOperation(e){let t=y.get(e.executionAttemptId),n=b.get(e.executionAttemptId);if(!t||!n)return{kind:`not-found`};if(t.settlementKind!=null)return{kind:`resolved`};if(n.ownerId!==null&&n.leaseExpiresAt!==null&&d(n.leaseExpiresAt)>d(e.observedAt))return{kind:`stale`};let r={executionAttemptId:e.executionAttemptId,generation:n.generation+1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:s(e.leaseExpiresAt)};return b.set(e.executionAttemptId,{...n,generation:r.generation,ownerId:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt}),{kind:`claimed`,claim:r}},async handoffProviderOperation(e){let t=e.evidence===void 0?void 0:h.parse(e.evidence),n=w(e.claim);return n.kind===`authorized`?(b.set(e.claim.executionAttemptId,{...n.operation,ownerId:null,token:null,leaseExpiresAt:null,lastFailure:t??n.operation.lastFailure}),{kind:`recorded`}):{kind:n.kind}},async recordProviderOperationUncertainty(e){let t=h.parse(e.evidence),n=w(e.claim);return n.kind===`authorized`?(b.set(e.claim.executionAttemptId,{...n.operation,failureCount:n.operation.failureCount+1,lastFailure:t}),{kind:`recorded`}):{kind:n.kind}},async recordAllocation(e){return E(e,!0)},async recordProvisioningAbsent(e){let t=h.parse(e.evidence),n=w(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.executionId===e.executionId?r.allocationRef===null?(y.set(r.executionAttemptId,v(r,`abandoned`)),T(i,t),{kind:`recorded`}):{kind:`allocated`,allocationRef:r.allocationRef}:{kind:`not-found`}},async recordProvisionerIncarnationLost(e){let t=h.parse(e.proof.evidence),n=w(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.executionId===e.executionId?r.allocationLifetime===`provisioner-process-bound`?r.provisionerIncarnationId===null||r.provisionerIncarnationId!==e.proof.provisionerIncarnationId?{kind:`incarnation-mismatch`,provisionerIncarnationId:r.provisionerIncarnationId}:r.allocationRef===null?(y.set(r.executionAttemptId,v(r,`abandoned`)),T(i,t),{kind:`recorded`}):{kind:`allocated`,allocationRef:r.allocationRef}:{kind:`not-process-bound`,allocationLifetime:r.allocationLifetime}:{kind:`not-found`}},async recordAllocationTerminated(e){let t=h.parse(e.evidence),n=w(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.allocationRef===null?{kind:`not-allocated`}:(b.set(i.executionAttemptId,{...i,obligation:`terminal-convergence`,lastFailure:t}),{kind:`recorded`})},async recordInfrastructureFailure(e){let t=w(e.claim);if(t.kind!==`authorized`)return{kind:t.kind};let{attempt:n,operation:r}=t;return n.executionId===e.executionId?n.allocationRef===null?{kind:`not-allocated`}:r.obligation===`terminal-convergence`?(y.set(n.executionAttemptId,v(n,`infrastructure-failure`)),T(r,r.lastFailure),{kind:`recorded`}):{kind:`not-terminated`}:{kind:`not-found`}},async registerRuntime(e){let t=y.get(e.executionAttemptId);if(t===void 0||t.executionId!==e.executionId)return{kind:`not-found`};if(t.settlementKind!=null)return{kind:`resolved`};if(C.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};if(t.allocationRef===null||x(t.executionAttemptId))return{kind:`not-allocated`};if(t.runtimeIncarnationId===e.runtimeIncarnationId)return{kind:`duplicate`,runtimeGeneration:t.runtimeGeneration,runtimeReadyAt:t.runtimeReadyAt};if(t.activeOperationId!==null&&t.activeOperationKind!==`runtime-probe`)return{kind:`operation-active`,operationId:t.activeOperationId};let n=t.runtimeGeneration+1;return y.set(t.executionAttemptId,{...t,runtimeGeneration:n,runtimeIncarnationId:e.runtimeIncarnationId,runtimeReadyAt:null,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null}),{kind:`registered`,runtimeGeneration:n}},async admitOperation(e){let t=y.get(e.executionAttemptId);if(t===void 0||t.executionId!==e.executionId)return{kind:`not-found`};if(t.settlementKind!=null)return{kind:`resolved`};if(C.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};if(t.allocationRef===null||x(t.executionAttemptId))return{kind:`not-allocated`};if(t.activeOperationId!==null)return t.activeOperationKey===e.admissionKey?{kind:`duplicate`,operationId:t.activeOperationId,runtimeGeneration:t.activeOperationGeneration??t.runtimeGeneration,admittedAt:t.activeOperationAdmittedAt??s(new Date().toISOString())}:{kind:`operation-active`,operationId:t.activeOperationId};if(t.operationStartGate===`closed`)return{kind:`gate-closed`};if(e.operationKind!==`runtime-probe`&&t.runtimeReadyAt===null)return{kind:`not-ready`};if(t.runtimeGeneration!==e.runtimeGeneration)return{kind:`stale-generation`,runtimeGeneration:t.runtimeGeneration};let n=crypto.randomUUID(),r=s(new Date().toISOString());return y.set(t.executionAttemptId,{...t,activeOperationId:n,activeOperationKind:e.operationKind,activeOperationKey:e.admissionKey,activeOperationGeneration:t.runtimeGeneration,activeOperationAdmittedAt:r}),{kind:`admitted`,operationId:n,runtimeGeneration:t.runtimeGeneration,admittedAt:r}},async completeOperation(e){let t=y.get(e.executionAttemptId);return t===void 0?{kind:`not-found`}:t.settlementKind==null?t.lastCompletedOperationId===e.operationId?{kind:`duplicate`}:t.activeOperationId===null?{kind:`not-active`}:t.activeOperationId===e.operationId?t.activeOperationGeneration===e.runtimeGeneration?(y.set(t.executionAttemptId,{...t,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null,lastCompletedOperationId:e.operationId}),{kind:`completed`}):{kind:`stale-generation`}:{kind:`mismatch`,activeOperationId:t.activeOperationId}:{kind:`resolved`}},async markRuntimeReady(e){let t=s(e.readyAt),n=y.get(e.executionAttemptId);return n===void 0||n.executionId!==e.executionId?{kind:`not-found`}:n.settlementKind==null?C.get(e.executionId)===e.executionAttemptId?n.allocationRef===null||x(n.executionAttemptId)?{kind:`not-allocated`}:n.runtimeGeneration===e.runtimeGeneration?n.runtimeReadyAt===null?n.activeOperationId===null?(y.set(n.executionAttemptId,{...n,runtimeReadyAt:t}),{kind:`ready`,acceptedAt:t}):{kind:`operation-active`,operationId:n.activeOperationId}:{kind:`duplicate`,acceptedAt:n.runtimeReadyAt}:{kind:`stale-generation`}:{kind:`fenced`}:{kind:`resolved`}},async getAttemptControlState(e){let t=y.get(e);return t===void 0?null:c(t)},async getActiveAttempt(e,t){return C.get(e)===t?y.get(t)??null:null},canonicalizeOutcome(e){return n(g,e)},decodeOutcome(e){return t(g,e)},async commitOutcome(e){let n=e.result;if(C.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};let r=y.get(e.executionAttemptId);if(r===void 0)return{kind:`fenced`};let a=S.get(e.executionAttemptId);if(a!==void 0){let e=t(g,a);return i(a,n.text)?{kind:`duplicate`,outcome:e,text:a}:{kind:`conflict`}}if(r.settlementKind!=null)return{kind:`conflict`};S.set(e.executionAttemptId,n.text),y.set(e.executionAttemptId,v(r,`outcome`));let o=b.get(e.executionAttemptId);return o&&T(o,o.lastFailure),{kind:`accepted`,outcome:t(g,n.text),text:n.text}},async abandonPendingAttempt(e,t){if(C.get(t)!==e)return{kind:`fenced`};let n=y.get(e);return n?n.status===`allocated`?{kind:`allocated`}:n.status===`provisioning`?{kind:`provisioning`}:n.status===`settled`?{kind:n.settlementKind===`abandoned`?`already-abandoned`:`already-settled`}:(y.set(e,v(n,`abandoned`)),{kind:`abandoned`}):{kind:`fenced`}},recovery:{async getAttemptWithAllocation(e){return y.get(e)??null},async recordDiscoveredAllocation(e){return E(e,!1)},async evolveAllocationRef(e){let{currentRef:t,nextRef:n}=f(e),i=w(e.claim);if(i.kind===`stale`)return{kind:`stale`,storedRef:i.attempt.allocationRef};if(i.kind!==`authorized`)return{kind:i.kind};let{attempt:a}=i;return a.executionId===e.executionId?a.allocationRef===null?{kind:`not-allocated`}:r(a.allocationRef,t)?(y.set(a.executionAttemptId,{...a,allocationRef:n}),{kind:`evolved`}):{kind:`stale`,storedRef:a.allocationRef}:{kind:`not-found`}},async getRecoverableAttempts(e){let t=d(new Date().toISOString()),n=[];for(let r of y.values())r.executionId===e&&r.status===`allocated`&&r.allocationRef!==null&&r.claimable===!0&&r.settlementKind==null&&(r.claimExpiresAt!=null&&d(r.claimExpiresAt)<t||n.push(m(r)));return n.sort(l)}},attempts:y,operations:b,committedOutcomes:S,activeAttempts:C}}const b=`controller-incarnation-1`,x=`provisioner-incarnation-1`,S=`test-provider`;function C(e){return new Date(Date.now()+e).toISOString()}function w(e,t,n={}){return{executionAttemptId:e,executionId:t,providerId:S,allocationLifetime:`provider-managed`,provisionerIncarnationId:x,ownerId:b,leaseExpiresAt:C(6e4),...n}}async function T(e,t,n,r={}){let i=await e.beginProvisioning(w(t,n,r));if(i.kind!==`started`)throw Error(`Expected provisioning to start, got '${i.kind}'`);return i.claim}function E(e={}){return{source:S,summary:`provider rejected the request before creating anything`,observedAt:new Date().toISOString(),...e}}function D(e=x,t=E({summary:`supervisor observed the provisioner process exit`})){return{kind:`provisioner-incarnation-lost`,provisionerIncarnationId:e,evidence:t}}function O(e=S,t={runId:1}){return{version:g,providerId:e,providerData:t}}const k={parse:e=>_.parse(e),serialize:e=>JSON.stringify(e)};function A(e,t=`completed`){let n={executionId:e,workflowId:`contract-workflow`};return t===`completed`?{...n,status:`completed`}:{...n,status:`failed`,error:`contract failure`}}async function j(e,t,n){let r=await e.beginProvisioning(w(t,n));if(r.kind!==`started`)throw Error(`Expected provisioning to start, got '${r.kind}'`);let i=await e.recordAllocation({claim:r.claim,allocationRef:O()});if(i.kind!==`recorded`)throw Error(`Expected the allocation to be recorded, got '${i.kind}'`)}async function M(e,t){let{executionAttemptId:n}=await e.createAttempt(t);return await j(e,n,t),n}export{p as INITIAL_ATTEMPT_CONTROL_STATE,b as TEST_OWNER_ID,S as TEST_PROVIDER_ID,x as TEST_PROVISIONER_INCARNATION_ID,M as allocateTestAttempt,T as beginTestProvisioning,y as createInMemoryAttemptRepository,j as driveTestAttemptToAllocated,C as leaseAt,w as makeBeginProvisioningInput,E as makeEvidence,D as makeProcessLossProof,O as makeTestAllocationRef,A as makeTestWorkflowResult,k as workflowRunResultOutcomeCodec};
1
+ import{_ as e,c as t,d as n,f as r,g as i,h as a,l as o,m as s,n as c,o as l,p as u,s as d,u as f}from"../../execution-attempt-repository-D0cCU7dI.mjs";import{a as p,c as m,d as h,f as g,i as _,l as v,m as y,n as b,o as x,p as S,r as C,s as w,t as T,u as E}from"../../attempt-record-codec-B32Whx75.mjs";import{a as D,c as O,d as k,f as A,i as j,l as M,m as N,n as P,o as F,p as I,r as L,s as R,t as z,u as B}from"../../attempt-fixtures-CnrnF5_4.mjs";import{BoundedRecoveryEvidenceSchema as V}from"@makaio/framework/contracts";function H(e,t){return{...e,status:`settled`,settlementKind:t,claimable:!1,operationStartGate:`closed`}}function U(D,O={}){let k=O.attempts??new Map,A=O.operations??new Map,j=e=>A.get(e)?.obligation===`terminal-convergence`,M=O.committedOutcomes??new Map,N=O.activeAttempts??new Map,P=e=>{let t=e.settlementKind!=null,r=!t&&N.get(e.executionId)===e.executionAttemptId;return n({matchesExecution:!0,settled:t,active:r,allocated:r&&e.allocationRef!==null&&!j(e.executionAttemptId)})},F=e=>{let t=k.get(e.executionAttemptId),n=A.get(e.executionAttemptId);return!t||!n?{kind:`not-found`}:t.settlementKind==null?n.token===null||n.token!==e.token||n.generation!==e.generation||n.ownerId!==e.ownerId?{kind:`stale`,attempt:t}:{kind:`authorized`,attempt:t,operation:n}:{kind:`resolved`,attempt:t}},I=(e,t)=>{A.set(e.executionAttemptId,{...e,ownerId:null,token:null,leaseExpiresAt:null,lastFailure:t})},L=(e,t)=>{let n=w(e.allocationRef),r=F(e.claim);if(r.kind!==`not-found`&&g(r.attempt,n),r.kind===`resolved`)return{kind:`resolved`,allocationRef:r.attempt.allocationRef};if(r.kind!==`authorized`)return{kind:r.kind};let{attempt:i,operation:a}=r;if(i.allocationRef!==null)return o(i.allocationRef,n)?{kind:`duplicate`,allocationRef:i.allocationRef}:{kind:`conflict`,allocationRef:i.allocationRef};let s=N.get(i.executionId)===i.executionAttemptId;return k.set(i.executionAttemptId,{...i,status:`allocated`,allocationRef:n,claimable:t&&s}),A.set(a.executionAttemptId,{...a,obligation:`allocation-control`}),{kind:`recorded`}};return{async createAttempt(e){let t=v(e.instruction),n=C(e.bootstrapTimeoutMs);if(k.has(e.executionAttemptId))throw new c(e.executionAttemptId);let r={executionAttemptId:e.executionAttemptId,executionId:e.executionId,instruction:t,preparationReceipts:Object.freeze([]),status:`pending`,allocationRef:null,...n,providerId:null,allocationLifetime:null,provisionerIncarnationId:null,settlementKind:null,claimable:!1,claimExpiresAt:null,...T},i=N.get(e.executionId),a=i===void 0?void 0:k.get(i);return a!==void 0&&k.set(a.executionAttemptId,{...a,claimable:a.status===`allocated`?!1:a.claimable,operationStartGate:`closed`}),k.set(e.executionAttemptId,r),N.set(e.executionId,e.executionAttemptId),r},async readBootstrapStartState(e){let t=k.get(e.executionAttemptId);return!t||t.executionId!==e.executionId?null:{settled:t.settlementKind!=null,active:N.get(e.executionId)===e.executionAttemptId,allocated:t.allocationRef!==null,allocationTerminated:j(e.executionAttemptId),operationStartGate:t.operationStartGate,bootstrapDeadlineAt:t.bootstrapDeadlineAt??null}},async beginProvisioning(e){let t=x(e.allocationLifetime),n=k.get(e.executionAttemptId);if(!n||n.executionId!==e.executionId)return{kind:`not-found`};if(N.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};if(n.settlementKind!=null)return{kind:`resolved`,allocationRef:n.allocationRef};if(n.allocationRef!==null)return{kind:`allocated`,allocationRef:n.allocationRef};if(n.status!==`pending`)return{kind:`already-provisioning`};k.set(e.executionAttemptId,{...n,status:`provisioning`,providerId:e.providerId,allocationLifetime:t,provisionerIncarnationId:e.provisionerIncarnationId});let r={executionAttemptId:e.executionAttemptId,generation:1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:p(e.leaseExpiresAt)};return A.set(e.executionAttemptId,{executionAttemptId:e.executionAttemptId,generation:r.generation,ownerId:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt,obligation:`provisioning-resolution`,failureCount:0,lastFailure:null}),{kind:`started`,claim:r}},async getProviderOperation(e){return A.get(e)??null},async renewProviderOperationClaim(e){let t=F(e.claim);if(t.kind!==`authorized`)return{kind:t.kind};let n=p(e.leaseExpiresAt);return A.set(e.claim.executionAttemptId,{...t.operation,leaseExpiresAt:n}),{kind:`claimed`,claim:{...e.claim,leaseExpiresAt:n}}},async takeOverProviderOperation(e){let t=k.get(e.executionAttemptId),n=A.get(e.executionAttemptId);if(!t||!n)return{kind:`not-found`};if(t.settlementKind!=null)return{kind:`resolved`};if(n.ownerId!==null&&n.leaseExpiresAt!==null&&_(n.leaseExpiresAt)>_(e.observedAt))return{kind:`stale`};let r={executionAttemptId:e.executionAttemptId,generation:n.generation+1,ownerId:e.ownerId,token:crypto.randomUUID(),leaseExpiresAt:p(e.leaseExpiresAt)};return A.set(e.executionAttemptId,{...n,generation:r.generation,ownerId:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt}),{kind:`claimed`,claim:r}},async handoffProviderOperation(e){let t=e.evidence===void 0?void 0:V.parse(e.evidence),n=F(e.claim);return n.kind===`authorized`?(A.set(e.claim.executionAttemptId,{...n.operation,ownerId:null,token:null,leaseExpiresAt:null,lastFailure:t??n.operation.lastFailure}),{kind:`recorded`}):{kind:n.kind}},async recordProviderOperationUncertainty(e){let t=V.parse(e.evidence),n=F(e.claim);return n.kind===`authorized`?(A.set(e.claim.executionAttemptId,{...n.operation,failureCount:n.operation.failureCount+1,lastFailure:t}),{kind:`recorded`}):{kind:n.kind}},async recordAllocation(e){return L(e,!0)},async recordProvisioningAbsent(e){let t=V.parse(e.evidence),n=F(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.executionId===e.executionId?r.allocationRef===null?(k.set(r.executionAttemptId,H(r,`abandoned`)),I(i,t),{kind:`recorded`}):{kind:`allocated`,allocationRef:r.allocationRef}:{kind:`not-found`}},async recordProvisionerIncarnationLost(e){let t=V.parse(e.proof.evidence),n=F(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n,o=a(r,e);return o===null?(k.set(r.executionAttemptId,H(r,`abandoned`)),I(i,t),{kind:`recorded`}):o},async recordAllocationTerminated(e){let t=V.parse(e.evidence),n=F(e.claim);if(n.kind!==`authorized`)return{kind:n.kind};let{attempt:r,operation:i}=n;return r.allocationRef===null?{kind:`not-allocated`}:(A.set(i.executionAttemptId,{...i,obligation:`terminal-convergence`,lastFailure:t}),{kind:`recorded`})},async recordInfrastructureFailure(e){let t=F(e.claim);if(t.kind!==`authorized`)return{kind:t.kind};let{attempt:n,operation:r}=t;return n.executionId===e.executionId?n.allocationRef===null?{kind:`not-allocated`}:r.obligation===`terminal-convergence`?(k.set(n.executionAttemptId,H(n,`infrastructure-failure`)),I(r,r.lastFailure),{kind:`recorded`}):{kind:`not-terminated`}:{kind:`not-found`}},async registerRuntime(t){let n=k.get(t.executionAttemptId);if(n===void 0||n.executionId!==t.executionId)return{kind:`not-found`};let r=P(n)??e(n,t);if(r!==null)return r;let i=n.runtimeGeneration+1;return k.set(n.executionAttemptId,{...n,runtimeGeneration:i,runtimeIncarnationId:t.runtimeIncarnationId,runtimeReadyAt:null,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null}),{kind:`registered`,runtimeGeneration:i}},async admitOperation(e){let t=k.get(e.executionAttemptId);if(t===void 0||t.executionId!==e.executionId)return{kind:`not-found`};let n=P(t);if(n!==null)return n;let i=r(t,e,t.activeOperationId!==null&&t.activeOperationKey===e.admissionKey&&t.activeOperationAdmittedAt===null?p(new Date().toISOString()):``,t);if(i!==null)return i;let a=crypto.randomUUID(),o=p(new Date().toISOString());return k.set(t.executionAttemptId,{...t,activeOperationId:a,activeOperationKind:e.operationKind,activeOperationKey:e.admissionKey,activeOperationGeneration:t.runtimeGeneration,activeOperationAdmittedAt:o}),{kind:`admitted`,operationId:a,runtimeGeneration:t.runtimeGeneration,admittedAt:o}},async getInstruction(e){let t=k.get(e.executionAttemptId);return t?.executionId===e.executionId?t.instruction:null},async reportOperation(e){let t=h(e.result),n=k.get(e.executionAttemptId);if(n===void 0||n.executionId!==e.executionId)return{kind:`not-found`};let r=s({matchesExecution:!0,settled:n.settlementKind!=null,active:N.get(e.executionId)===e.executionAttemptId,allocated:n.allocationRef!==null&&!j(e.executionAttemptId)},n,n,{...e,result:t});if(r!==null)return r;let i=E([...n.preparationReceipts,{operationId:e.operationId,runtimeGeneration:e.runtimeGeneration,result:t}]);return k.set(e.executionAttemptId,{...n,preparationReceipts:i,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null,lastCompletedOperationId:e.operationId}),{kind:`accepted`,binding:t.binding}},async completeOperation(e){let t=k.get(e.executionAttemptId);if(t===void 0)return{kind:`not-found`};if(t.settlementKind!=null)return{kind:`resolved`};let n=u(t,e);return n===null?(k.set(t.executionAttemptId,{...t,activeOperationId:null,activeOperationKind:null,activeOperationKey:null,activeOperationGeneration:null,activeOperationAdmittedAt:null,lastCompletedOperationId:e.operationId}),{kind:`completed`}):n},async markRuntimeReady(e){let t=p(e.readyAt),n=k.get(e.executionAttemptId);if(n===void 0||n.executionId!==e.executionId)return{kind:`not-found`};let r=P(n)??i(n,e);return r===null?(k.set(n.executionAttemptId,{...n,runtimeReadyAt:t}),{kind:`ready`,acceptedAt:t}):r},async getAttemptControlState(e){let t=k.get(e);return t===void 0?null:S(t)},async getActiveAttempt(e,t){return N.get(e)===t?k.get(t)??null:null},canonicalizeOutcome(e){return t(D,e)},decodeOutcome(e){return d(D,e)},async commitOutcome(e){let t=e.result;if(N.get(e.executionId)!==e.executionAttemptId)return{kind:`fenced`};let n=k.get(e.executionAttemptId);if(n===void 0)return{kind:`fenced`};let r=M.get(e.executionAttemptId);if(r!==void 0){let e=d(D,r);return f(r,t.text)?{kind:`duplicate`,outcome:e,text:r}:{kind:`conflict`}}if(n.settlementKind!=null)return{kind:`conflict`};l(n,e.runtimeFence),M.set(e.executionAttemptId,t.text),k.set(e.executionAttemptId,H(n,`outcome`));let i=A.get(e.executionAttemptId);return i&&I(i,i.lastFailure),{kind:`accepted`,outcome:d(D,t.text),text:t.text}},async abandonPendingAttempt(e,t){if(N.get(t)!==e)return{kind:`fenced`};let n=k.get(e);return n?n.status===`allocated`?{kind:`allocated`}:n.status===`provisioning`?{kind:`provisioning`}:n.status===`settled`?{kind:n.settlementKind===`abandoned`?`already-abandoned`:`already-settled`}:(k.set(e,H(n,`abandoned`)),{kind:`abandoned`}):{kind:`fenced`}},recovery:{async getAttemptWithAllocation(e){return k.get(e)??null},async recordDiscoveredAllocation(e){return L(e,!1)},async evolveAllocationRef(e){let{currentRef:t,nextRef:n}=m(e),r=F(e.claim);if(r.kind===`stale`)return{kind:`stale`,storedRef:r.attempt.allocationRef};if(r.kind!==`authorized`)return{kind:r.kind};let{attempt:i}=r;return i.executionId===e.executionId?i.allocationRef===null?{kind:`not-allocated`}:o(i.allocationRef,t)?(k.set(i.executionAttemptId,{...i,allocationRef:n}),{kind:`evolved`}):{kind:`stale`,storedRef:i.allocationRef}:{kind:`not-found`}},async getRecoverableAttempts(e){let t=_(new Date().toISOString()),n=[];for(let r of k.values())r.executionId===e&&r.status===`allocated`&&r.allocationRef!==null&&r.claimable===!0&&r.settlementKind==null&&(r.claimExpiresAt!=null&&_(r.claimExpiresAt)<t||n.push(y(r)));return n.sort(b)}},attempts:k,operations:A,committedOutcomes:M,activeAttempts:N}}export{T as INITIAL_ATTEMPT_CONTROL_STATE,z as TEST_OWNER_ID,P as TEST_PROVIDER_ID,L as TEST_PROVISIONER_INCARNATION_ID,j as allocateTestAttempt,D as beginTestProvisioning,U as createInMemoryAttemptRepository,F as driveTestAttemptToAllocated,R as leaseAt,O as makeBeginProvisioningInput,M as makeEvidence,B as makeProcessLossProof,k as makeTestAllocationRef,A as makeTestInstruction,I as makeTestWorkflowResult,N as workflowRunResultOutcomeCodec};
@@ -1,4 +1,4 @@
1
- import { A as OutcomeCodec, x as ExecutionAttemptRepository } from "../../execution-attempt-repository-CRdrgou3.mjs";
1
+ import { C as ExecutionAttemptRepository, P as OutcomeCodec } from "../../execution-attempt-repository-CgB7uiYD.mjs";
2
2
  import { MakaioDatabase } from "@makaio/framework/storage/drizzle";
3
3
 
4
4
  //#region subsystems/workflow-engine/src/testing/sqlite-attempt-repository.d.ts