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

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 (491) hide show
  1. package/dist/.makaio-build.json +2 -2
  2. package/dist/{account-identity-B3vLwm9O.mjs → account-identity-DCBpVurJ.mjs} +1 -1
  3. package/dist/{adapter-Dz1fX5Wa.mjs → adapter-D6IpEDIo.mjs} +1 -1
  4. package/dist/adapters/config/index.d.mts +1 -1
  5. package/dist/adapters/config/index.mjs +1 -1
  6. package/dist/adapters/index.d.mts +2 -2
  7. package/dist/adapters/index.mjs +1 -1
  8. package/dist/adapters/node.d.mts +1 -1
  9. package/dist/adapters/node.mjs +1 -1
  10. package/dist/artifact-OnwP6uaD.mjs +1 -0
  11. package/dist/attempt-record-codec-CqKq0NIB.mjs +1 -0
  12. package/dist/{auth-C6tVtaOX.mjs → auth-CeH3w2fi.mjs} +1 -1
  13. package/dist/authority-state-bootstrap-rnsTk0u7.mjs +1 -0
  14. package/dist/{automation-trigger-ByjNlClm.mjs → automation-trigger-D_xKqEoV.mjs} +1 -1
  15. package/dist/bus/index.mjs +1 -1
  16. package/dist/{caller-owned-adapter-stub-C1M7FKrv.mjs → caller-owned-adapter-stub-egWCuKcE.mjs} +1 -1
  17. package/dist/{canonical-model-DXOvCaVg.mjs → canonical-model-DwuFQ02A.mjs} +1 -1
  18. package/dist/{capabilities-DEvmD9VJ.mjs → capabilities-DGqMG9M3.mjs} +1 -1
  19. package/dist/{client-BkznbdsO.mjs → client-CTqzLpVx.mjs} +1 -1
  20. package/dist/clients/index.d.mts +1 -1
  21. package/dist/clients/index.mjs +1 -1
  22. package/dist/clients/managed-install.d.mts +1 -1
  23. package/dist/clients/managed-install.mjs +1 -1
  24. package/dist/code-execution/worker-entry.d.mts +1 -1
  25. package/dist/code-execution/worker-entry.mjs +1 -1
  26. package/dist/{code-execution-Ckmn8OZu.mjs → code-execution-BMmUATcc.mjs} +1 -1
  27. package/dist/{code-execution-CweDSWco.mjs → code-execution-C2PgBdmE.mjs} +1 -1
  28. package/dist/{code-execution-DqkQjKa1.mjs → code-execution-Mo1jztUH.mjs} +1 -1
  29. package/dist/{compression-CtgeVLpP.mjs → compression-3DauETKU.mjs} +1 -1
  30. package/dist/{config-namespace-CjWvw8ij.mjs → config-namespace-MjFuIPyL.mjs} +1 -1
  31. package/dist/contracts/adapter/index.d.mts +2 -2
  32. package/dist/contracts/adapter/index.mjs +1 -1
  33. package/dist/contracts/adapter/schemas/session-lineage.d.mts +1 -1
  34. package/dist/contracts/artifact/index.d.mts +3 -3
  35. package/dist/contracts/artifact/index.mjs +1 -1
  36. package/dist/contracts/auth/index.d.mts +2 -2
  37. package/dist/contracts/auth/index.mjs +1 -1
  38. package/dist/contracts/automation-trigger/index.d.mts +3 -3
  39. package/dist/contracts/automation-trigger/index.mjs +1 -1
  40. package/dist/contracts/canonical-model/index.d.mts +1 -1
  41. package/dist/contracts/canonical-model/index.mjs +1 -1
  42. package/dist/contracts/capabilities/index.d.mts +1 -1
  43. package/dist/contracts/capabilities/index.mjs +1 -1
  44. package/dist/contracts/client/index.d.mts +2 -2
  45. package/dist/contracts/client/index.mjs +1 -1
  46. package/dist/contracts/code-execution/index.d.mts +1 -1
  47. package/dist/contracts/code-execution/index.mjs +1 -1
  48. package/dist/contracts/common/index.d.mts +1 -1
  49. package/dist/contracts/config/index.d.mts +1 -1
  50. package/dist/contracts/config/index.mjs +1 -1
  51. package/dist/contracts/extension/index.d.mts +5 -5
  52. package/dist/contracts/extension/index.mjs +1 -1
  53. package/dist/contracts/facet/index.d.mts +1 -1
  54. package/dist/contracts/facet/index.mjs +1 -1
  55. package/dist/contracts/harness/index.d.mts +1 -1
  56. package/dist/contracts/harness/index.mjs +1 -1
  57. package/dist/contracts/host/index.d.mts +1 -1
  58. package/dist/contracts/host/index.mjs +1 -1
  59. package/dist/contracts/index.d.mts +102 -102
  60. package/dist/contracts/index.mjs +1 -1
  61. package/dist/contracts/materialization/index.d.mts +2 -3
  62. package/dist/contracts/materialization/index.mjs +1 -1
  63. package/dist/contracts/model-registry/index.d.mts +1 -1
  64. package/dist/contracts/model-registry/index.mjs +1 -1
  65. package/dist/contracts/native-session-supervisor/index.d.mts +1 -1
  66. package/dist/contracts/native-session-supervisor/index.mjs +1 -1
  67. package/dist/contracts/platform/index.d.mts +1 -1
  68. package/dist/contracts/platform/index.mjs +1 -1
  69. package/dist/contracts/provider/index.d.mts +2 -2
  70. package/dist/contracts/provider/index.mjs +1 -1
  71. package/dist/contracts/reaction/index.d.mts +1 -1
  72. package/dist/contracts/reaction/index.mjs +1 -1
  73. package/dist/contracts/session/index.d.mts +2 -2
  74. package/dist/contracts/session/index.mjs +1 -1
  75. package/dist/contracts/shared/index.d.mts +2 -2
  76. package/dist/contracts/shared/index.mjs +1 -1
  77. package/dist/contracts/skill/index.d.mts +1 -1
  78. package/dist/contracts/skill/index.mjs +1 -1
  79. package/dist/contracts/telemetry/index.d.mts +1 -1
  80. package/dist/contracts/telemetry/index.mjs +1 -1
  81. package/dist/contracts/timeout/index.d.mts +1 -1
  82. package/dist/contracts/timeout/index.mjs +1 -1
  83. package/dist/contracts/toast/index.mjs +1 -1
  84. package/dist/contracts/variant/index.d.mts +1 -1
  85. package/dist/contracts/variant/index.mjs +1 -1
  86. package/dist/contracts/worker/index.d.mts +1 -1
  87. package/dist/contracts/worker/index.mjs +1 -1
  88. package/dist/contracts/workflow/index.d.mts +2 -2
  89. package/dist/contracts/workflow/index.mjs +1 -1
  90. package/dist/{contribution-Crm-mctl.d.mts → contribution-BoTMoHVB.d.mts} +2 -2
  91. package/dist/{definition-u_5rYQtc.d.mts → definition-BgY763Q4.d.mts} +1 -1
  92. package/dist/{definition-BH4QLGLI.mjs → definition-YGj42UeO.mjs} +1 -1
  93. package/dist/{detached-extension-handle-DAXKQT9c.mjs → detached-extension-handle-B9c_6Pcb.mjs} +1 -1
  94. package/dist/execution-attempt-owner-recovery-BNERIDH0.mjs +1 -0
  95. package/dist/{execution-attempt-repository-CgB7uiYD.d.mts → execution-attempt-repository-CtFZfBfp.d.mts} +111 -3
  96. package/dist/{execution-target-BcoF_oDB.mjs → execution-target-CqaBmnvX.mjs} +1 -1
  97. package/dist/{extension-Bfkr2DBs.mjs → extension-B51JzHJu.mjs} +1 -1
  98. package/dist/extension-C4lFc8-j.mjs +1 -0
  99. package/dist/{filesystem-service-CiUw0YN5.mjs → filesystem-service-DGqU-6x-.mjs} +1 -1
  100. package/dist/framework-packages-CZJDukan.mjs +1 -0
  101. package/dist/git/index.mjs +1 -1
  102. package/dist/{globby-QBDqstzq.mjs → globby-BT0rrriG.mjs} +1 -1
  103. package/dist/{handlers-BsHAFtye.mjs → handlers-CBbFzDHc.mjs} +1 -1
  104. package/dist/{harness-YQ2ewID9.mjs → harness-GNtHsoh4.mjs} +1 -1
  105. package/dist/{hook-responses-DcapjzLb.d.mts → hook-responses-BSCAdJ3i.d.mts} +1 -1
  106. package/dist/{index-QJW9g1mG.d.mts → index-BVRQOZbm.d.mts} +1 -1
  107. package/dist/{index-LryUXslm.d.mts → index-BZlmWCcW.d.mts} +3 -3
  108. package/dist/{index-rygpcDBV.d.mts → index-BZtasAZP.d.mts} +1 -1
  109. package/dist/{index-Bsr4rZl0.d.mts → index-BdbYIlDL.d.mts} +18 -18
  110. package/dist/{index-BxOFB25y.d.mts → index-BkY6zO7p.d.mts} +138 -115
  111. package/dist/{index-DZXpKlyB.d.mts → index-CDLHgV7v.d.mts} +14 -14
  112. package/dist/{index-CfJKwWJa.d.mts → index-CQtttPGm.d.mts} +1 -1
  113. package/dist/{index-BADuMxcP.d.mts → index-CYmQt2lF.d.mts} +100 -100
  114. package/dist/{index-J-kv32zv.d.mts → index-CYwbfa0_.d.mts} +2 -2
  115. package/dist/{index-DZnb56vt2.d.mts → index-C_OLvAr_.d.mts} +1 -1
  116. package/dist/{index-BvgLFm-U.d.mts → index-Cau0jTTM.d.mts} +1 -1
  117. package/dist/{index-BwccWakG.d.mts → index-D0DfEO45.d.mts} +1 -1
  118. package/dist/{index-COOM1j_L2.d.mts → index-DIYgFhTZ2.d.mts} +4 -4
  119. package/dist/{index-LOh6AEqx.d.mts → index-DJ0Muy2s.d.mts} +4 -4
  120. package/dist/{index-C1PfDEIV.d.mts → index-F6hV4tWI.d.mts} +35 -35
  121. package/dist/{index-CiKzWCW02.d.mts → index-LwOw7ZLk2.d.mts} +19 -19
  122. package/dist/{index-BakMNLkB.d.mts → index-PTp68NH1.d.mts} +92 -92
  123. package/dist/{index-vXmPEZ5O.d.mts → index-R2BZejEz.d.mts} +591 -726
  124. package/dist/{index-DIhkK4Y0.d.mts → index-RpG4EP3u.d.mts} +1 -1
  125. package/dist/{index-Bo3LRb2u.d.mts → index-dL0Oet1j.d.mts} +1 -1
  126. package/dist/{index-Cbv_3Xi12.d.mts → index-mylsCg6V2.d.mts} +1 -1
  127. package/dist/{index-BDzqNCXs.d.mts → index-nPpqnP7P.d.mts} +1 -1
  128. package/dist/kernel/cli/index.d.mts +2 -2
  129. package/dist/kernel/cli/index.mjs +1 -1
  130. package/dist/kernel/cli/register.d.mts +1 -1
  131. package/dist/kernel/cli/register.mjs +1 -1
  132. package/dist/kernel/cli/schemas.mjs +1 -1
  133. package/dist/kernel/extension/index.d.mts +1 -1
  134. package/dist/kernel/extension/index.mjs +1 -1
  135. package/dist/kernel/index.d.mts +5 -5
  136. package/dist/kernel/index.mjs +1 -1
  137. package/dist/kernel/namespace/index.d.mts +1 -1
  138. package/dist/kernel/namespace/index.mjs +1 -1
  139. package/dist/kernel/observability/index.d.mts +1 -1
  140. package/dist/kernel/observability/index.mjs +1 -1
  141. package/dist/kernel/providers/index.d.mts +1 -1
  142. package/dist/kernel/providers/index.mjs +1 -1
  143. package/dist/kernel/window/index.d.mts +1 -1
  144. package/dist/kernel/window/index.mjs +1 -1
  145. package/dist/kind-registration-BNhVCSaT.mjs +1 -0
  146. package/dist/{lib-271rPR7A.mjs → lib-B8Yv4IY-.mjs} +1 -1
  147. package/dist/{lib-RFpLjUda.mjs → lib-hwdGyO-m.mjs} +1 -1
  148. package/dist/{load-extensions-D9inWcDy.mjs → load-extensions-CNT2Nd9h.mjs} +1 -1
  149. package/dist/{load-extensions-CY8ELnCp.d.mts → load-extensions-D0yT_Kta.d.mts} +1 -1
  150. package/dist/materialization-Dx1z_MDj.mjs +1 -0
  151. package/dist/mcp-http-server/index.mjs +1 -1
  152. package/dist/model-B6t_-_sp.mjs +1 -0
  153. package/dist/{namespace-BymM0nl_.d.mts → namespace-C7wggVcn.d.mts} +9 -9
  154. package/dist/namespace-D4zmxaC4.mjs +1 -0
  155. package/dist/{namespace-DdqVQSyc.d.mts → namespace-Dh5fTXYt.d.mts} +2 -2
  156. package/dist/{namespace-DlrX8feY.d.mts → namespace-WeSQXdAL.d.mts} +45 -45
  157. package/dist/{namespace-BL7lHlmg.mjs → namespace-ZAIFBrIy.mjs} +1 -1
  158. package/dist/{native-session-supervisor-LKio8XZn.mjs → native-session-supervisor-BlGzmZrH.mjs} +1 -1
  159. package/dist/node/bus-server/index.d.mts +1 -1
  160. package/dist/node/bus-server/index.mjs +1 -1
  161. package/dist/node/bus-server/server-lifecycle.d.mts +1 -1
  162. package/dist/node/bus-server/server-lifecycle.mjs +1 -1
  163. package/dist/{orchestrator-shared-BGlN-m-V.mjs → orchestrator-shared-BKMtjTE9.mjs} +1 -1
  164. package/dist/{ownership-memory-handler-BpGdR_uG.mjs → ownership-memory-handler-BCu1EjFO.mjs} +1 -1
  165. package/dist/{package-DkpF17X_.d.mts → package-C9XYuN9J.d.mts} +20 -6
  166. package/dist/{package-CzKoZ1k0.mjs → package-D7c2HC-S.mjs} +2 -2
  167. package/dist/{package-JtjbO-Oi.mjs → package-buHQFmTH.mjs} +1 -1
  168. package/dist/package.json +1 -1
  169. package/dist/packages-BhhBcPgz.mjs +1 -0
  170. package/dist/{packages-Cx-BwSZr.d.mts → packages-DAqep89i.d.mts} +12 -39
  171. package/dist/{profile-N5qGUpF0.mjs → profile-DBDvy9uc.mjs} +1 -1
  172. package/dist/{provider-context-zTDSH2x9.mjs → provider-context-CSb0qX1c.mjs} +1 -1
  173. package/dist/{provider-context-CG42JlP9.mjs → provider-context-CTOrOW54.mjs} +1 -1
  174. package/dist/{reaction-D3TNwPK8.mjs → reaction-OQibmmDW.mjs} +1 -1
  175. package/dist/{resolved-sq8RXNDf.mjs → resolved-ONt3rOMh.mjs} +1 -1
  176. package/dist/rules/index.d.mts +1 -1
  177. package/dist/rules/index.mjs +1 -1
  178. package/dist/rules/schemas.d.mts +1 -1
  179. package/dist/runtime-bun/index.mjs +1 -1
  180. package/dist/runtime-node/code-execution/index.d.mts +2 -2
  181. package/dist/runtime-node/code-execution/index.mjs +1 -1
  182. package/dist/runtime-node/extension-discovery.d.mts +1 -1
  183. package/dist/runtime-node/extension-validation.d.mts +1 -1
  184. package/dist/runtime-node/extension-validation.mjs +1 -1
  185. package/dist/runtime-node/index.d.mts +6 -6
  186. package/dist/runtime-node/index.mjs +20 -20
  187. package/dist/runtime-node/makaio-config.d.mts +1 -1
  188. package/dist/runtime-node/makaio-config.mjs +1 -1
  189. package/dist/runtime-node/workflow-worker/index.d.mts +2 -2
  190. package/dist/runtime-node/workflow-worker/index.mjs +1 -1
  191. package/dist/runtime-node/workflow-worker/worker-entry.mjs +1 -1
  192. package/dist/{schema-Dq-7si8u.mjs → schema-B8jinlbH.mjs} +1 -1
  193. package/dist/{schema-C9PauHXt.d.mts → schema-wArHaxA9.d.mts} +2 -2
  194. package/dist/{schemas-QWDnauKX.mjs → schemas-BUK9I-Oz.mjs} +1 -1
  195. package/dist/{schemas-BDZFd3Wb.d.mts → schemas-BjNlwTDl.d.mts} +2 -2
  196. package/dist/{context-resolution-BrtoXnez.d.mts → schemas-C5FreSE0.d.mts} +133 -539
  197. package/dist/{schemas-_2Syo_01.mjs → schemas-CSDiTBsU.mjs} +1 -1
  198. package/dist/{schemas-BfO5jkrL.mjs → schemas-CbhvgFQs.mjs} +1 -1
  199. package/dist/schemas-hzbKeyyt.mjs +1 -0
  200. package/dist/{selection-DL3ric7K.mjs → selection-7SkHsmWs.mjs} +1 -1
  201. package/dist/services/adapter-runtime/index.d.mts +3 -3
  202. package/dist/services/adapter-runtime/index.mjs +1 -1
  203. package/dist/services/adapter-runtime/namespace.d.mts +1 -1
  204. package/dist/services/adapter-runtime/schemas.d.mts +1 -1
  205. package/dist/services/adapter-subsystem/index.d.mts +3 -3
  206. package/dist/services/adapter-subsystem/index.mjs +1 -1
  207. package/dist/services/adapter-subsystem/namespace.d.mts +1 -1
  208. package/dist/services/adapter-subsystem/namespace.mjs +1 -1
  209. package/dist/services/agent-runtime/index.d.mts +2 -2
  210. package/dist/services/agent-runtime/namespace.d.mts +1 -1
  211. package/dist/services/agent-runtime/schemas.d.mts +1 -1
  212. package/dist/services/automation-trigger/index.mjs +1 -1
  213. package/dist/services/capability/index.d.mts +2 -2
  214. package/dist/services/capability/index.mjs +1 -1
  215. package/dist/services/code-execution/index.d.mts +1 -1
  216. package/dist/services/code-execution/index.mjs +1 -1
  217. package/dist/services/codebase/index.d.mts +2 -2
  218. package/dist/services/codebase/namespace.d.mts +1 -1
  219. package/dist/services/codebase/schemas.d.mts +1 -1
  220. package/dist/services/compression/index.d.mts +2 -2
  221. package/dist/services/compression/namespace.d.mts +1 -1
  222. package/dist/services/compression/schemas.d.mts +1 -1
  223. package/dist/services/context-rules/index.d.mts +1 -1
  224. package/dist/services/context-rules/index.mjs +1 -1
  225. package/dist/services/execution-target/index.d.mts +3 -3
  226. package/dist/services/execution-target/index.mjs +1 -1
  227. package/dist/services/execution-target/namespace.d.mts +1 -1
  228. package/dist/services/execution-target/namespace.mjs +1 -1
  229. package/dist/services/execution-target/schemas.d.mts +1 -1
  230. package/dist/services/execution-target/schemas.mjs +1 -1
  231. package/dist/services/filesystem/index.d.mts +1 -1
  232. package/dist/services/filesystem/index.mjs +1 -1
  233. package/dist/services/git/namespace.mjs +1 -1
  234. package/dist/services/git/schemas.mjs +1 -1
  235. package/dist/services/harness/index.mjs +1 -1
  236. package/dist/services/index.d.mts +45 -66
  237. package/dist/services/index.mjs +1 -1
  238. package/dist/services/log-import/browser.d.mts +2 -2
  239. package/dist/services/log-import/index.d.mts +2 -2
  240. package/dist/services/log-import/log-import.d.mts +1 -1
  241. package/dist/services/log-import/log-import.mjs +1 -1
  242. package/dist/services/log-import/namespace.mjs +1 -1
  243. package/dist/services/log-import/schemas.mjs +1 -1
  244. package/dist/services/materialization/index.d.mts +13 -34
  245. package/dist/services/materialization/index.mjs +1 -1
  246. package/dist/services/model-registry/index.d.mts +1 -1
  247. package/dist/services/model-registry/index.mjs +1 -1
  248. package/dist/services/preferences/index.d.mts +2 -2
  249. package/dist/services/preferences/schemas.d.mts +1 -1
  250. package/dist/services/preferences/storage-namespace.d.mts +2 -2
  251. package/dist/services/provider-context/index.d.mts +1 -1
  252. package/dist/services/provider-context/index.mjs +1 -1
  253. package/dist/services/provider-runtime/index.mjs +1 -1
  254. package/dist/services/session/handlers/index.d.mts +1 -1
  255. package/dist/services/session/handlers/index.mjs +1 -1
  256. package/dist/services/session/index.d.mts +9 -9
  257. package/dist/services/session/index.mjs +1 -1
  258. package/dist/services/session/messages/namespace.d.mts +1 -1
  259. package/dist/services/session/messages/namespace.mjs +1 -1
  260. package/dist/services/session/orchestrator-testing/index.d.mts +1 -1
  261. package/dist/services/session/orchestrator-testing/index.mjs +1 -1
  262. package/dist/services/session/session-events/namespace.d.mts +1 -1
  263. package/dist/services/session/session-events/namespace.mjs +1 -1
  264. package/dist/services/session/storage/namespace.d.mts +1 -1
  265. package/dist/services/session/storage/schema.d.mts +1 -1
  266. package/dist/services/session/testing/index.mjs +1 -1
  267. package/dist/services/session/testing/orchestrator-shared.d.mts +1 -1
  268. package/dist/services/session/testing/orchestrator-shared.mjs +1 -1
  269. package/dist/services/session/turns/namespace.d.mts +1 -1
  270. package/dist/services/session/turns/namespace.mjs +1 -1
  271. package/dist/services/session-editor/index.d.mts +1 -1
  272. package/dist/services/session-editor/index.mjs +1 -1
  273. package/dist/services/settings/index.d.mts +3 -3
  274. package/dist/services/settings/index.mjs +1 -1
  275. package/dist/services/settings/namespace.mjs +1 -1
  276. package/dist/services/settings/storage/clients-namespace.d.mts +1 -1
  277. package/dist/services/settings/storage/clients-namespace.mjs +1 -1
  278. package/dist/services/settings/storage/index.d.mts +3 -3
  279. package/dist/services/settings/storage/index.mjs +1 -1
  280. package/dist/services/settings/storage/providers-namespace.d.mts +1 -1
  281. package/dist/services/settings/storage/providers-namespace.mjs +1 -1
  282. package/dist/services/subagent/index.d.mts +1 -1
  283. package/dist/services/subagent/index.mjs +1 -1
  284. package/dist/services/subagent-template/index.d.mts +2 -2
  285. package/dist/services/subagent-template/namespace.d.mts +1 -1
  286. package/dist/services/subagent-template/schemas.d.mts +1 -1
  287. package/dist/services/tool-approval/index.d.mts +1 -1
  288. package/dist/services/tool-approval/index.mjs +1 -1
  289. package/dist/services/tools/index.d.mts +1 -1
  290. package/dist/services/tools/index.mjs +1 -1
  291. package/dist/services/tray-menu/index.d.mts +3 -3
  292. package/dist/services/tray-menu/index.mjs +1 -1
  293. package/dist/services/tray-menu/namespace.d.mts +1 -1
  294. package/dist/services/tray-menu/schemas.d.mts +1 -1
  295. package/dist/services/turn/index.d.mts +1 -1
  296. package/dist/services/turn/namespace.d.mts +1 -1
  297. package/dist/services/workflow-transitions/index.d.mts +1 -1
  298. package/dist/services/workflow-transitions/index.mjs +1 -1
  299. package/dist/{session-CXOPk3yg.mjs → session-BDFNAcuY.mjs} +1 -1
  300. package/dist/{session-BOpTI79g.mjs → session-CQAuApxe.mjs} +1 -1
  301. package/dist/{shared-B9AWRm9A.mjs → shared-BYP7z9xy.mjs} +1 -1
  302. package/dist/{skill-DGNtc_ww.mjs → skill-1gU2q1KT.mjs} +1 -1
  303. package/dist/{src-DEgV239R.mjs → src-D4Gx0QHf.mjs} +1 -1
  304. package/dist/storage/drizzle/client.d.mts +1 -1
  305. package/dist/storage/drizzle/client.mjs +1 -1
  306. package/dist/storage/drizzle/index.d.mts +1 -1
  307. package/dist/storage/drizzle/index.mjs +1 -1
  308. package/dist/storage/handlers/drizzle/index.d.mts +1 -1
  309. package/dist/storage/handlers/drizzle/index.mjs +1 -1
  310. package/dist/storage/handlers/index.d.mts +1 -1
  311. package/dist/storage/handlers/index.mjs +1 -1
  312. package/dist/{tool-approval-service-BFDOFUGC.mjs → tool-approval-service-7mzJVMo_.mjs} +1 -1
  313. package/dist/{tools-DWKWX3eV.mjs → tools-Cyo6BuGM.mjs} +1 -1
  314. package/dist/{transition-DFA_ckdP.d.mts → transition-CwMPKBjz.d.mts} +2 -2
  315. package/dist/{types-p55qvq922.d.mts → types-BOF825V52.d.mts} +1 -1
  316. package/dist/{types-DkfDRSTr.d.mts → types-Dg_acP9p.d.mts} +36 -36
  317. package/dist/ui-kernel/index.d.mts +1 -1
  318. package/dist/ui-kernel/pages/schemas.d.mts +1 -1
  319. package/dist/{version-BYeVh1pI.mjs → version-3xWJDCeF.mjs} +1 -1
  320. package/dist/{view-builder-CYW_9n4A.d.mts → view-builder-D76L0Db8.d.mts} +209 -15
  321. package/dist/{visibility-DtDLRBdr.mjs → visibility-C5sLzqyS.mjs} +1 -1
  322. package/dist/{worker-B4nD_Erm.mjs → worker-9X0QNB1k.mjs} +1 -1
  323. package/dist/{worker-CLsRbzpk.mjs → worker-BwUhRg7i.mjs} +1 -1
  324. package/dist/workflow-B3MWrYhG.mjs +1 -0
  325. package/dist/workflow-engine/execution-attempt-repository.d.mts +2 -2
  326. package/dist/workflow-engine/execution-attempt-repository.mjs +1 -1
  327. package/dist/workflow-engine/index.d.mts +52 -52
  328. package/dist/workflow-engine/index.mjs +1 -1
  329. package/dist/workflow-engine/package.d.mts +1 -1
  330. package/dist/workflow-engine/package.mjs +1 -1
  331. package/dist/workflow-engine/provider-operation.d.mts +1 -1
  332. package/dist/workflow-engine/testing/conformance.d.mts +1 -1
  333. package/dist/workflow-engine/testing/conformance.mjs +3 -1
  334. package/dist/workflow-engine/testing/index.d.mts +9 -6
  335. package/dist/workflow-engine/testing/index.mjs +1 -1
  336. package/dist/workflow-engine/testing/sqlite.d.mts +1 -1
  337. package/dist/workflow-engine/testing/sqlite.mjs +63 -55
  338. package/dist/workflow-engine/workflow-orchestrator.mjs +1 -1
  339. package/dist/{workflow-transitions-c_VQbyV0.mjs → workflow-transitions-B7HtjuAn.mjs} +1 -1
  340. package/dist/workflow-worker-zYb2UguP.mjs +2 -0
  341. package/package.json +1 -1
  342. package/dist/artifact-ClvHqL3w.mjs +0 -1
  343. package/dist/attempt-record-codec-B32Whx75.mjs +0 -1
  344. package/dist/authority-state-bootstrap-7Cgb9TR2.mjs +0 -1
  345. package/dist/extension-Cz39YNXy.mjs +0 -1
  346. package/dist/framework-packages-BHgul8Kl.mjs +0 -1
  347. package/dist/materialization-B_LA9pfy.mjs +0 -1
  348. package/dist/model-DrzPt3ou.mjs +0 -1
  349. package/dist/namespace-sCPb79-7.mjs +0 -1
  350. package/dist/packages-Bp124-gx.mjs +0 -1
  351. package/dist/schemas-CNkUEbIr.mjs +0 -1
  352. package/dist/workflow-H8hsEikC.mjs +0 -1
  353. package/dist/workflow-worker-CmIkKnpF.mjs +0 -2
  354. /package/dist/{adapter-auth-runtime-DHHppU4f.mjs → adapter-auth-runtime-DGY1CDxj.mjs} +0 -0
  355. /package/dist/{adapter-binding-D68U_Hmh.d.mts → adapter-binding-fGIz-ss3.d.mts} +0 -0
  356. /package/dist/{ajv-krzJXh1X.mjs → ajv-DWgn_plp.mjs} +0 -0
  357. /package/dist/{attach-error-Cb3GbeKe.mjs → attach-error-B-vXQFLQ.mjs} +0 -0
  358. /package/dist/{attempt-fixtures-CnrnF5_4.mjs → attempt-fixtures-Dpfgqll0.mjs} +0 -0
  359. /package/dist/{base-orchestrator-DA95InJU.d.mts → base-orchestrator-BeLqYKJG.d.mts} +0 -0
  360. /package/dist/{bootstrap-start-client-DrvofWwi.mjs → bootstrap-start-client-BYoxrgMk.mjs} +0 -0
  361. /package/dist/{capability-j3NekkIu.mjs → capability-Bw4tsDQu.mjs} +0 -0
  362. /package/dist/{capability-service-s4ZYSEWc.d.mts → capability-service-BlYnun2M.d.mts} +0 -0
  363. /package/dist/{client-f5A-6La5.d.mts → client-CtOWHpFB.d.mts} +0 -0
  364. /package/dist/{client-binary-version-verifier-kd9LP9AQ.d.mts → client-binary-version-verifier-BwmToeS1.d.mts} +0 -0
  365. /package/dist/{client-binary-version-verifier-0lCKZOTg.mjs → client-binary-version-verifier-sv-Uv0lB.mjs} +0 -0
  366. /package/dist/{clients-namespace-q4PqU1cA.d.mts → clients-namespace-Bf73bcZh.d.mts} +0 -0
  367. /package/dist/{config-namespace-Cp71zTT0.d.mts → config-namespace-BbLLd4V0.d.mts} +0 -0
  368. /package/dist/{create-static-mount-CmQgA0jq.mjs → create-static-mount-BQnyEUH1.mjs} +0 -0
  369. /package/dist/{cross-spawn-CZygZJMH.mjs → cross-spawn-DPrJR9Nq.mjs} +0 -0
  370. /package/dist/{cursor-storage-bsc9lZKk.mjs → cursor-storage-iJ6vBOWd.mjs} +0 -0
  371. /package/dist/{definition-BHSzhrUf.d.mts → definition-aS9AM2ht.d.mts} +0 -0
  372. /package/dist/{definitions-CRpdnHYM.mjs → definitions-CYZTuMdL.mjs} +0 -0
  373. /package/dist/{descriptor-to-package-CcjdoWP4.mjs → descriptor-to-package-FBkLjHZo.mjs} +0 -0
  374. /package/dist/{drizzle-Bzc-OGVI.mjs → drizzle-CIf_jdYI.mjs} +0 -0
  375. /package/dist/{esm-i-S5TW72.mjs → esm-BH4Kmq3r.mjs} +0 -0
  376. /package/dist/{event-B8ELuk6k.mjs → event-m7_IdhOS.mjs} +0 -0
  377. /package/dist/{execution-attempt-repository-D0cCU7dI.mjs → execution-attempt-repository-D_qR7NyG.mjs} +0 -0
  378. /package/dist/{extension-context-BmU5XKjI.d.mts → extension-context-41A1ZUus.d.mts} +0 -0
  379. /package/dist/{extension-discovery-DnO7bINK.d.mts → extension-discovery-DNB1VVsV.d.mts} +0 -0
  380. /package/dist/{extension-namespace-QoTTwKPt.mjs → extension-namespace-twXNwE4R.mjs} +0 -0
  381. /package/dist/{extension-package-provenance-aYrZuS4W.mjs → extension-package-provenance-CTYdo0yF.mjs} +0 -0
  382. /package/dist/{facet-BnMh7Jyc.mjs → facet-Cly0VpTI.mjs} +0 -0
  383. /package/dist/{filesystem-service-BBArEDPL.d.mts → filesystem-service-DOrm4Llq.d.mts} +0 -0
  384. /package/dist/{handler-DF1fVDpf.mjs → handler-COkV00I9.mjs} +0 -0
  385. /package/dist/{host-B-_ntOMH.mjs → host-CiHn8Yog.mjs} +0 -0
  386. /package/dist/{identity-OjRlG6dZ.mjs → identity-BULrIHmo.mjs} +0 -0
  387. /package/dist/{index-xaBSwHxJ.d.mts → index-BB4EWIf3.d.mts} +0 -0
  388. /package/dist/{index-DYHxzwok2.d.mts → index-BBq5I7SB2.d.mts} +0 -0
  389. /package/dist/{index-NhW2h2wH2.d.mts → index-BJjdUzfw2.d.mts} +0 -0
  390. /package/dist/{index-CsFN2nv7.d.mts → index-BKvzOrbF.d.mts} +0 -0
  391. /package/dist/{index-D-JbTXIH.d.mts → index-BO8n7zAS.d.mts} +0 -0
  392. /package/dist/{index-Co1da7YK.d.mts → index-BbAqoQmv.d.mts} +0 -0
  393. /package/dist/{index-DSLTgc7h2.d.mts → index-BcTwLu9C2.d.mts} +0 -0
  394. /package/dist/{index-Dn_SGTgp.d.mts → index-Bg5iXHk5.d.mts} +0 -0
  395. /package/dist/{index-CPWBGotQ.d.mts → index-BiXqOfhl.d.mts} +0 -0
  396. /package/dist/{index-DSN2t48K.d.mts → index-BjaQsfAr.d.mts} +0 -0
  397. /package/dist/{index-mK-rgiit.d.mts → index-Bk865qJX.d.mts} +0 -0
  398. /package/dist/{index-CkpR5sIH.d.mts → index-Bq4PHWe9.d.mts} +0 -0
  399. /package/dist/{index-DW4SE_sH.d.mts → index-CUHWylh4.d.mts} +0 -0
  400. /package/dist/{index-CcrXttC02.d.mts → index-CavvxFdG2.d.mts} +0 -0
  401. /package/dist/{index-CDLf3Fka2.d.mts → index-Cb3NfGSV2.d.mts} +0 -0
  402. /package/dist/{index-Df1c_2PF.d.mts → index-Ce_l029J.d.mts} +0 -0
  403. /package/dist/{index-D94yE5Dr.d.mts → index-CgVdz5IV.d.mts} +0 -0
  404. /package/dist/{index-KAAnSRZt.d.mts → index-Ck5amD5_.d.mts} +0 -0
  405. /package/dist/{index-BB0HypzC.d.mts → index-ClJjlOox.d.mts} +0 -0
  406. /package/dist/{index-CGJgZGqN.d.mts → index-CoGo6HFE.d.mts} +0 -0
  407. /package/dist/{index-CrcfeFOo.d.mts → index-DR9-fFwc.d.mts} +0 -0
  408. /package/dist/{index-B-zl-O-Y.d.mts → index-Q29tcu5N.d.mts} +0 -0
  409. /package/dist/{index-DQD2-jcL.d.mts → index-VVJqONaI.d.mts} +0 -0
  410. /package/dist/{index-D6RMsZko.d.mts → index-gK54T8Am.d.mts} +0 -0
  411. /package/dist/{index-D_sMzTvv.d.mts → index-jW7MJ2_q.d.mts} +0 -0
  412. /package/dist/{index-CBixkF0n.d.mts → index-l5HeyxKn.d.mts} +0 -0
  413. /package/dist/{index-BDAfOYSw2.d.mts → index-oucWFlFP2.d.mts} +0 -0
  414. /package/dist/{index-Bf2MgOni.d.mts → index-z-YJG2cw.d.mts} +0 -0
  415. /package/dist/{index-C9xVZ-gt.d.mts → index-zvgQ8ErF.d.mts} +0 -0
  416. /package/dist/{json-value-pX6xnLGw.d.mts → json-value-C57MkQrB.d.mts} +0 -0
  417. /package/dist/{json-value-BBZ6uGwc.mjs → json-value-DM-EjTC1.mjs} +0 -0
  418. /package/dist/{jsonl-transport-DQIlRX_y.mjs → jsonl-transport-QQuABrN7.mjs} +0 -0
  419. /package/dist/{lib-6eNAiNK7.mjs → lib-Sx8gBJvV.mjs} +0 -0
  420. /package/dist/{model-registry-C9rFu3kV.mjs → model-registry-B7ThN_s3.mjs} +0 -0
  421. /package/dist/{model-registry-Cixxx2jv.mjs → model-registry-DNHDnyvs.mjs} +0 -0
  422. /package/dist/{modes-DwsJ3yVl.mjs → modes-CyG4sgs_.mjs} +0 -0
  423. /package/dist/{namespace-NXm_zvL1.mjs → namespace-BFlSY040.mjs} +0 -0
  424. /package/dist/{namespace-DiwqpB-c.mjs → namespace-BGgY903U.mjs} +0 -0
  425. /package/dist/{namespace-BMG3RCdr.d.mts → namespace-BY5-nA4j.d.mts} +0 -0
  426. /package/dist/{namespace-CVg_cpkh.d.mts → namespace-Bn-ryJn5.d.mts} +0 -0
  427. /package/dist/{namespace-Cs-cOyrn.d.mts → namespace-By3nEmBH.d.mts} +0 -0
  428. /package/dist/{namespace-Du0accdE.mjs → namespace-C9d0aoYT.mjs} +0 -0
  429. /package/dist/{namespace-Dw5H_KCF.d.mts → namespace-CPC1vbOu.d.mts} +0 -0
  430. /package/dist/{namespace-CPR2xem0.d.mts → namespace-Ca4sQ8X-.d.mts} +0 -0
  431. /package/dist/{namespace-BoyqQiW9.d.mts → namespace-D1qK-Ed3.d.mts} +0 -0
  432. /package/dist/{namespace-9ychTEk_.d.mts → namespace-DE3oGhaN.d.mts} +0 -0
  433. /package/dist/{namespace-DG0hjPcx.d.mts → namespace-DENdNdK0.d.mts} +0 -0
  434. /package/dist/{namespace-jVTsuZHX.mjs → namespace-DHrItZyM.mjs} +0 -0
  435. /package/dist/{namespace-DykqxEyX.d.mts → namespace-DInMixc8.d.mts} +0 -0
  436. /package/dist/{namespace-CQEYu8az.d.mts → namespace-DP0WWpTO.d.mts} +0 -0
  437. /package/dist/{namespace-BGDq7HmW.d.mts → namespace-DkAlBY9o.d.mts} +0 -0
  438. /package/dist/{namespace-BW3Bfu9h.mjs → namespace-QXCaZK3I.mjs} +0 -0
  439. /package/dist/{namespace-tjoxekmf.mjs → namespace-ZN49zpqw.mjs} +0 -0
  440. /package/dist/{orchestrator-shared-BzqqcY2z.d.mts → orchestrator-shared-2vuCvljs.d.mts} +0 -0
  441. /package/dist/{out-8bOYN6EF.mjs → out-Rz-t3WeC.mjs} +0 -0
  442. /package/dist/{ownership-recovery-guard-DyW5vGBr.mjs → ownership-recovery-guard-Ce9-C5Sa.mjs} +0 -0
  443. /package/dist/{package-DttKA9wN.mjs → package-DfjGt5oK.mjs} +0 -0
  444. /package/dist/{package-EGTn-Ng1.mjs → package-Tt2uoAFf.mjs} +0 -0
  445. /package/dist/{platform-CxyYPrkf.mjs → platform-C-fDsuEl.mjs} +0 -0
  446. /package/dist/{provider-operation-B2wQST6N.d.mts → provider-operation-BwrIrOeY.d.mts} +0 -0
  447. /package/dist/{providers-C-eekMxD.mjs → providers-DVlsnJaY.mjs} +0 -0
  448. /package/dist/{providers-namespace-DsKTnuO1.d.mts → providers-namespace-C56pGeTO.d.mts} +0 -0
  449. /package/dist/{quick-lru-CCEnf7y6.mjs → quick-lru-uXa2PNb5.mjs} +0 -0
  450. /package/dist/{registry-Dk12tAfv.mjs → registry-CZf8VGBh.mjs} +0 -0
  451. /package/dist/{schema-C0opCPww.mjs → schema-DIHGEQx3.mjs} +0 -0
  452. /package/dist/{schema-introspection-6-r_KEJQ.mjs → schema-introspection-CSnLZJpC.mjs} +0 -0
  453. /package/dist/{schemas-Dxvjq-Bi.d.mts → schemas-B0zhTfet.d.mts} +0 -0
  454. /package/dist/{schemas-ClGDFa44.d.mts → schemas-B2Q284-G.d.mts} +0 -0
  455. /package/dist/{schemas--LAbwXvw.d.mts → schemas-BJKx29Sp.d.mts} +0 -0
  456. /package/dist/{schemas-BivbWRkG.mjs → schemas-BKnJj2i-.mjs} +0 -0
  457. /package/dist/{schemas-DmULJ7Jk.d.mts → schemas-BMGJLkdK2.d.mts} +0 -0
  458. /package/dist/{schemas-B2UbGJpJ.d.mts → schemas-BSBb1KFq.d.mts} +0 -0
  459. /package/dist/{schemas-CeHU889f.mjs → schemas-BapfTRqp.mjs} +0 -0
  460. /package/dist/{schemas-Bk50UoMA.d.mts → schemas-BsZJHdvY.d.mts} +0 -0
  461. /package/dist/{schemas-CzGN0eqW.d.mts → schemas-CITR9cWN.d.mts} +0 -0
  462. /package/dist/{schemas-B8hKbBwI.mjs → schemas-CnFVygzI.mjs} +0 -0
  463. /package/dist/{schemas-scyC2tFF.mjs → schemas-DDCAGKRi.mjs} +0 -0
  464. /package/dist/{schemas-CBpjAhut.d.mts → schemas-DmE-a0kN.d.mts} +0 -0
  465. /package/dist/{schemas-Wqo3_F6-.d.mts → schemas-gfrOgGau.d.mts} +0 -0
  466. /package/dist/{schemas-CHRuwe18.d.mts → schemas-wPB7RnHB.d.mts} +0 -0
  467. /package/dist/{semver-BI7kTNsY.mjs → semver-D_D2mA48.mjs} +0 -0
  468. /package/dist/{server-lifecycle-B_OZnoe-.mjs → server-lifecycle-AvBVeCFR.mjs} +0 -0
  469. /package/dist/{server-lifecycle-WFZcCMwF.d.mts → server-lifecycle-CREtXADx.d.mts} +0 -0
  470. /package/dist/{session-lineage-C9kppcCa.d.mts → session-lineage-CRLvurB-.d.mts} +0 -0
  471. /package/dist/{shared-schemas-CQ6blrEW.mjs → shared-schemas-kUho6Kmw.mjs} +0 -0
  472. /package/dist/{src-DIyWekjW.mjs → src-DnLncoLg.mjs} +0 -0
  473. /package/dist/{storage-namespace-BZce8kkW.mjs → storage-namespace-CH4j0_Zs.mjs} +0 -0
  474. /package/dist/{storage-namespace-BWU-8rvj.d.mts → storage-namespace-JBh9nkKw.d.mts} +0 -0
  475. /package/dist/{storage-namespace-definition-Cca-zwXU.mjs → storage-namespace-definition-BJCbqVWz.mjs} +0 -0
  476. /package/dist/{storage-namespace-definition-B-8JKvzm.d.mts → storage-namespace-definition-C0mnpnC_.d.mts} +0 -0
  477. /package/dist/{supports-color-SV_FgSN2.mjs → supports-color-BBMFnbC4.mjs} +0 -0
  478. /package/dist/{telemetry-BqoC87F-.mjs → telemetry-CUkZrhW6.mjs} +0 -0
  479. /package/dist/{timeout-DVlN2Zhy.mjs → timeout-DeBYTGBR.mjs} +0 -0
  480. /package/dist/{tray-menu-service-eVVxgPLc.mjs → tray-menu-service-thAhpcPA.mjs} +0 -0
  481. /package/dist/{types-BnPJa-C_.d.mts → types-9ldZyQTb.d.mts} +0 -0
  482. /package/dist/{types-DQTCNM2i.d.mts → types-BMkn9jOe.d.mts} +0 -0
  483. /package/dist/{types-Cwza95hS.mjs → types-CjjNAiHa.mjs} +0 -0
  484. /package/dist/{types-DxHeL0pF.d.mts → types-DJuxNrac.d.mts} +0 -0
  485. /package/dist/{types-BFeWU3WM.d.mts → types-eCGV_g6P.d.mts} +0 -0
  486. /package/dist/{types-8rMNe3AS.d.mts → types-xXv0lUeU.d.mts} +0 -0
  487. /package/dist/{ui-config-B35GloSX.mjs → ui-config-9hlZAJOS.mjs} +0 -0
  488. /package/dist/{variant-Dwnge3J_.mjs → variant-73kFgYBK.mjs} +0 -0
  489. /package/dist/{window-registry-DQP5P2_0.d.mts → window-registry-CGaYVD7l.d.mts} +0 -0
  490. /package/dist/{window-registry-CKiMJjId.mjs → window-registry-CzAwaPKL.mjs} +0 -0
  491. /package/dist/{zod-json-schema-Dixc-B1T.mjs → zod-json-schema-B9TYYq3e.mjs} +0 -0
@@ -1 +1,3 @@
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
+ import{a as e,n as t}from"../../execution-attempt-repository-D_qR7NyG.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-Dpfgqll0.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){se(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 se(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 M(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 N(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 P(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})}),F(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 F(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 I(e){L(e),R(e),z(e),B(e),V(e)}function L(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 R(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 z(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 B(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 V(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 H(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 U(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 W={parse:e=>U(e),serialize:e=>JSON.stringify({counter:e})},G={parse:e=>U(e),serialize:e=>JSON.stringify({counter:Math.trunc(e)})};function K(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 q={parse:e=>K(e),serialize:e=>JSON.stringify({counter:e.counter,generation:e.generation+1})},ce={codec:o,makeOutcome:(e,t)=>c(e,t===0?`completed`:`failed`)},le={codec:W,makeOutcome:(e,t)=>t};function J(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 ue(e){J(e,`workflow run result`,ce),J(e,`counter`,le)}function de(e){m(`execution attempt outcome parity (${e.name}, normalizing codec)`,()=>{let t=_(e,G);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 fe(e){m(`execution attempt outcome parity (${e.name}, non-idempotent serialization)`,()=>{let t=_(e,q);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(q.serialize(r)).toBe(q.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 pe(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 me={parse:e=>pe(e),serialize:e=>JSON.stringify(e.href)};function he(e){m(`execution attempt outcome parity (${e.name}, non-cloneable outcome)`,()=>{let t=_(e,me);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 ge(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 _e={parse:e=>ge(e),serialize:e=>JSON.stringify(Array.from(e))};function ve(e){m(`execution attempt outcome parity (${e.name}, unfreezable outcome)`,()=>{let t=_(e,_e);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 ye(e){m(`execution attempt outcome parity (${e.name}, invalid stored outcome)`,()=>{let t=_(e,W);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 be(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 xe(e){Se(e),Ce(e),we(e)}function Se(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 Ce(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 we(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 Te(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 Ee=[`registration`,`readiness`,`admission`,`Preparation report`];async function De(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 Oe(e){let t=Ee.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 De(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 ke(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 Ae(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 ke(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 je(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 Me(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 Ne(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=Y(new Date(i.getTime()-1e3),120),o=Y(new Date(i.getTime()+1e3),-120),s=new Date(i.getTime()+6e4),c=Y(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 Y(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 Pe(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 Fe(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 Ie={parse:e=>{if(!Fe(e))throw Error(`MemberOrderOutcome requires numeric alpha and beta members`);return e},serialize:e=>JSON.stringify(e)};function Le(e){m(`execution attempt outcome parity (${e.name}, member-order codec)`,()=>{let t=_(e,Ie);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 Re(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 ze(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 X(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 Z(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 X(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 Z(t,n,o,`infrastructure-failure`)})}async function X(e,t,n){h(await e.repository.recovery.getAttemptWithAllocation(t)).toMatchObject({status:`allocated`,settlementKind:null,allocationRef:n})}async function Z(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 Be(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 Ve(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 Q(){return{...b(),requestKey:`initial-demand`,instruction:i(),bootstrapTimeoutMs:y}}function He(e){Ue(e),We(e),$(e),Ge(e)}function Ue(e){g(`creates one attempt for concurrent and sequential same-owner request replays`,async()=>{let{repository:t,peer:n}=e(),r=Q(),i={...r,executionAttemptId:`${r.executionAttemptId}-contender`},a=await Promise.all([t.ensureAttempt(r),n.ensureAttempt(i)]);h(a.map(e=>e.kind).sort()).toEqual([`created`,`replayed`]);let o=a.find(e=>e.kind===`created`);if(o?.kind!==`created`)throw Error(`Expected one created attempt`);for(let e of[t,n]){h(await e.ensureAttempt(r)).toEqual({kind:`replayed`,attempt:o.attempt}),h(await e.getActiveAttempt(r.executionId,o.attempt.executionAttemptId)).toEqual(o.attempt);let t=o.attempt.executionAttemptId===r.executionAttemptId?i.executionAttemptId:r.executionAttemptId;h(await e.readAttemptSettlement({...r,executionAttemptId:t})).toEqual({kind:`not-found`})}}),g(`commits one winner and one conflict for competing instructions under the same request`,async()=>{let{repository:t,peer:n}=e(),r=Q(),a={...r,executionAttemptId:`${r.executionAttemptId}-other`,instruction:i({revision:`2`})},o=await Promise.all([t.ensureAttempt(r),n.ensureAttempt(a)]);h(o.map(e=>e.kind).sort()).toEqual([`conflict`,`created`]);for(let[e,i]of[r,a].entries()){let r=o[e];if(!r)throw Error(`Expected both request decisions`);h(await n.ensureAttempt(i)).toEqual(r.kind===`created`?{kind:`replayed`,attempt:r.attempt}:{kind:`conflict`}),r.kind===`conflict`&&h(await t.readAttemptSettlement(i)).toEqual({kind:`not-found`})}}),g(`keeps opaque owner and request components independent without delimiter collisions`,async()=>{let{repository:t,peer:n}=e(),r=Q(),i=[{...r,executionId:`${r.executionId}:part`,requestKey:`key`},{...r,executionId:r.executionId,requestKey:`part:key`,executionAttemptId:`${r.executionAttemptId}-pair`},{...r,executionId:`${r.executionId}-other`,requestKey:`key`,executionAttemptId:`${r.executionAttemptId}-owner`}];for(let e of i)h(await t.ensureAttempt(e)).toMatchObject({kind:`created`,attempt:{executionId:e.executionId,executionAttemptId:e.executionAttemptId}});for(let e of i)h(await n.ensureAttempt(e)).toMatchObject({kind:`replayed`,attempt:{executionId:e.executionId,executionAttemptId:e.executionAttemptId}})})}function We(e){g.each([{executionId:``},{requestKey:``},{executionAttemptId:``},{bootstrapTimeoutMs:0},{bootstrapTimeoutMs:1/0},{instruction:i({revision:``})}])(`rejects invalid owner requests before consuming keys or fencing predecessors: %j`,async t=>{let{repository:n,peer:r}=e(),i=Q(),a=await n.createAttempt(i),o={...i,executionAttemptId:`${i.executionAttemptId}-next`};await h(r.ensureAttempt({...o,...t})).rejects.toThrow(),h(await n.getActiveAttempt(i.executionId,i.executionAttemptId)).toEqual(a),h(await r.readAttemptSettlement(o)).toEqual({kind:`not-found`}),h(await n.ensureAttempt(o)).toMatchObject({kind:`created`})}),g(`preserves a predecessor and leaves a colliding candidate request unbound`,async()=>{let{repository:n,peer:r}=e(),i=Q(),a=await n.createAttempt(i);await h(r.ensureAttempt(i)).rejects.toThrow(t),h(await n.getActiveAttempt(i.executionId,i.executionAttemptId)).toEqual(a);let o={...i,executionAttemptId:`${i.executionAttemptId}-fresh`};h(await r.ensureAttempt(o)).toMatchObject({kind:`created`,attempt:{executionAttemptId:o.executionAttemptId}}),h(await n.ensureAttempt(i)).toMatchObject({kind:`replayed`,attempt:{executionAttemptId:o.executionAttemptId}})})}function $(e){g.each([`completed`,`failed`])(`replays an old %s outcome without reopening its gate or replacing a successor`,async t=>{let{repository:n,peer:r}=e(),i=Q();await n.ensureAttempt(i),h(await n.commitOutcome({...i,result:n.canonicalizeOutcome(c(i.executionId,t))})).toMatchObject({kind:`accepted`});let a=await r.readAttemptSettlement(i);if(a.kind!==`outcome`)throw Error(`Expected durable outcome`);h(await r.ensureAttempt(i)).toEqual({kind:`replayed`,attempt:a.attempt});let o={...i,requestKey:`successor`,executionAttemptId:`${i.executionAttemptId}-successor`};await Promise.all([n.ensureAttempt(i),r.ensureAttempt(o)]);let s=await n.readAttemptSettlement(i);if(h(s).toMatchObject({kind:`outcome`,isCurrentAttempt:!1,attempt:{operationStartGate:`closed`},result:a.result}),s.kind!==`outcome`)throw Error(`Expected historical outcome`);h(await r.ensureAttempt(i)).toEqual({kind:`replayed`,attempt:s.attempt}),h(await n.getActiveAttempt(i.executionId,o.executionAttemptId)).toMatchObject({operationStartGate:`open`}),h(await n.getActiveAttempt(i.executionId,i.executionAttemptId)).toBeNull()}),g(`does not restore an unsettled predecessor when old replay races a fresh demand`,async()=>{let{repository:t,peer:n}=e(),r=Q();await t.ensureAttempt(r);let i={...r,requestKey:`replacement`,executionAttemptId:`${r.executionAttemptId}-replacement`};await Promise.all([t.ensureAttempt(r),n.ensureAttempt(i)]),h(await t.readAttemptSettlement(r)).toMatchObject({kind:`unsettled`,isCurrentAttempt:!1,attempt:{operationStartGate:`closed`}}),h(await t.ensureAttempt(r)).toMatchObject({kind:`replayed`,attempt:{operationStartGate:`closed`}}),h(await n.getActiveAttempt(r.executionId,i.executionAttemptId)).toMatchObject({operationStartGate:`open`})})}function Ge(e){g(`freezes input before awaiting storage and compares instructions independently of member order`,async()=>{let{repository:t,peer:n}=e(),r={alpha:1,beta:2,steps:[`first`,`second`]},a={...Q(),instruction:i({workload:{kind:`test`,version:`1`,input:r}})},o=t.ensureAttempt(a);r.alpha=999,r.steps.reverse();let s=await o;if(s.kind!==`created`)throw Error(`Expected new demand`);let c={...a,instruction:i({workload:{kind:`test`,version:`1`,input:{steps:[`first`,`second`],beta:2,alpha:1}}})};h(await n.ensureAttempt(c)).toEqual({kind:`replayed`,attempt:s.attempt}),h(await n.ensureAttempt(a)).toEqual({kind:`conflict`});let l={...c,instruction:i({workload:{kind:`test`,version:`1`,input:{alpha:1,beta:2,steps:[`second`,`first`]}}})};h(await t.ensureAttempt(l)).toEqual({kind:`conflict`}),s.attempt.instruction.workload.input={changed:!0};let u=await n.ensureAttempt(c);if(h(u).toMatchObject({kind:`replayed`,attempt:{instruction:c.instruction}}),u.kind===`conflict`)throw Error(`Expected replay`);u.attempt.instruction.workload.input={changedAgain:!0},h(await t.ensureAttempt(c)).toMatchObject({kind:`replayed`,attempt:{instruction:c.instruction}})}),g(`preserves original timing even when the new valid host budget would overflow an unused deadline`,async()=>{let{repository:t,peer:n}=e(),r=Q(),i=await t.ensureAttempt(r);if(i.kind!==`created`)throw Error(`Expected new demand`);for(let e of[1,2**53-1])h(await n.ensureAttempt({...r,bootstrapTimeoutMs:e})).toEqual({kind:`replayed`,attempt:i.attempt});await h(n.ensureAttempt({...r,bootstrapTimeoutMs:-1})).rejects.toThrow(),h(await t.readAttemptSettlement(r)).toMatchObject({attempt:i.attempt})})}const Ke={parse(e){if(typeof e!=`object`||!e||!(`values`in e)||!Array.isArray(e.values))throw Error(`Expected an outcome containing values`);let t=[];for(let n of e.values){if(typeof n!=`number`||!Number.isFinite(n))throw Error(`Expected finite outcome values`);t.push(n)}return{values:t}},serialize:e=>JSON.stringify(e)};function qe(e){m(`execution attempt owner settlement recovery (${e.name})`,()=>{let t=_(e,Ke);Je(t),Ye(t)})}function Je(e){g(`distinguishes absent, wrong-owner, pending, current settled, and historical settled attempts`,async()=>{let{repository:t,peer:n}=e(),r=b();h(await t.readAttemptSettlement(r)).toEqual({kind:`not-found`});let a={...r,requestKey:`initial`,instruction:i(),bootstrapTimeoutMs:y},o=await t.ensureAttempt(a);if(o.kind!==`created`)throw Error(`Expected new attempt`);h(await n.readAttemptSettlement({...r,executionId:`${r.executionId}-wrong`})).toEqual({kind:`not-found`}),h(await n.readAttemptSettlement(r)).toEqual({kind:`unsettled`,attempt:o.attempt,isCurrentAttempt:!0});let s=t.canonicalizeOutcome({values:[1,2]});h(await t.commitOutcome({...r,result:s})).toMatchObject({kind:`accepted`}),h(await n.readAttemptSettlement(r)).toMatchObject({kind:`outcome`,isCurrentAttempt:!0,result:s,attempt:{status:`settled`,settlementKind:`outcome`}}),await n.ensureAttempt({...a,requestKey:`successor`,executionAttemptId:`${r.executionAttemptId}-successor`}),h(await t.readAttemptSettlement(r)).toMatchObject({kind:`outcome`,isCurrentAttempt:!1,result:s}),h(await t.readAttemptSettlement({...r,executionId:`${r.executionId}-wrong`})).toEqual({kind:`not-found`})}),g(`recovers abandonment without inventing an owner outcome`,async()=>{let{repository:t,peer:n}=e(),r=b();await t.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y}),h(await t.abandonPendingAttempt(r.executionAttemptId,r.executionId)).toMatchObject({kind:`abandoned`});let a=await n.readAttemptSettlement(r);h(a).toMatchObject({kind:`settled-without-outcome`,isCurrentAttempt:!0,attempt:{status:`settled`,settlementKind:`abandoned`}}),h(a).not.toHaveProperty(`result`)}),g(`recovers confirmed infrastructure failure without inventing an owner outcome`,async()=>{let{repository:t,peer:o}=e(),s=b();await t.createAttempt({...s,instruction:i(),bootstrapTimeoutMs:y});let c=await t.beginProvisioning(n(s.executionAttemptId,s.executionId));if(c.kind!==`started`)throw Error(`Expected provisioning claim`);let l=c.claim;h(await t.recordAllocation({claim:l,allocationRef:r()})).toEqual({kind:`recorded`}),h(await o.recordAllocationTerminated({claim:l,evidence:a()})).toEqual({kind:`recorded`}),h(await t.recordInfrastructureFailure({claim:l,executionId:s.executionId})).toEqual({kind:`recorded`});let u=await o.readAttemptSettlement(s);h(u).toMatchObject({kind:`settled-without-outcome`,isCurrentAttempt:!0,attempt:{status:`settled`,settlementKind:`infrastructure-failure`}}),h(u).not.toHaveProperty(`result`)})}function Ye(e){g(`returns exact stored text and independent decoded outcomes and instruction snapshots on every read`,async()=>{let t=e(),n=b(),r=i({workload:{kind:`values`,version:`1`,input:{value:`original`}}});await t.repository.createAttempt({...n,instruction:r,bootstrapTimeoutMs:y}),h(await t.repository.commitOutcome({...n,result:t.repository.canonicalizeOutcome({values:[1,2]})})).toMatchObject({kind:`accepted`});let a=`
2
+ { "values" : [1, 2] }
3
+ `;await t.writeStoredOutcomeText(n.executionAttemptId,a);let o=await t.repository.readAttemptSettlement(n),s=await t.peer.readAttemptSettlement(n);if(o.kind!==`outcome`||s.kind!==`outcome`)throw Error(`Expected canonical outcomes`);h(o.result.text).toBe(a),h(s.result.text).toBe(a),h(o.result.outcome).toEqual({values:[1,2]}),h(o.result.outcome).not.toBe(s.result.outcome),h(o.result.outcome.values).not.toBe(s.result.outcome.values),o.result.outcome.values.push(999),o.attempt.instruction.workload.input={value:`changed`},h(s.result.outcome).toEqual({values:[1,2]}),h(await t.repository.readAttemptSettlement(n)).toMatchObject({kind:`outcome`,result:{text:a,outcome:{values:[1,2]}},attempt:{instruction:r}})}),g.each([`{`,`{"values":["invalid"]}`])(`rejects corrupt canonical outcome text instead of hiding it: %s`,async t=>{let n=e(),r=b();await n.repository.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y}),h(await n.repository.commitOutcome({...r,result:n.repository.canonicalizeOutcome({values:[1]})})).toMatchObject({kind:`accepted`}),await n.writeStoredOutcomeText(r.executionAttemptId,t),await h(n.repository.readAttemptSettlement(r)).rejects.toThrow(),await h(n.peer.readAttemptSettlement(r)).rejects.toThrow()}),g(`rejects outcome text on an unsettled attempt instead of treating it as pending`,async()=>{let t=e(),n=b();await t.repository.createAttempt({...n,instruction:i(),bootstrapTimeoutMs:y}),await t.writeStoredOutcomeText(n.executionAttemptId,`{"values":[1]}`),await h(t.repository.readAttemptSettlement(n)).rejects.toThrow(),await h(t.peer.readAttemptSettlement(n)).rejects.toThrow()})}function Xe(e){m(`execution attempt port parity (${e.name})`,()=>{let t=_(e,o);k(t),A(t),re(t),ie(t),ae(t),oe(t),M(t),N(t),P(t),I(t),H(t),be(t),xe(t),Te(t),Oe(t),Ae(t),je(t),Me(t),Ne(t),Pe(t),Re(t),ze(t),Be(t),Ve(t),He(t)}),ue(e),de(e),fe(e),he(e),ve(e),ye(e),Le(e),qe(e)}export{Xe as runExecutionAttemptRepositoryContract};
@@ -1,5 +1,5 @@
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";
1
+ 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-CtFZfBfp.mjs";
2
+ import { a as ProviderOperationClaim, i as ProcessBoundProvisionerLossProof, l as ProviderOperationOwnershipRecord } from "../../provider-operation-BwrIrOeY.mjs";
3
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
@@ -18,14 +18,15 @@ declare const INITIAL_ATTEMPT_CONTROL_STATE: AttemptControlState;
18
18
  /**
19
19
  * Durable state the in-memory realization keeps.
20
20
  *
21
- * The four maps mirror the four durable facts the port owns: canonical attempt
21
+ * The maps mirror the durable facts the port owns: canonical attempt
22
22
  * state, fenced provider-operation ownership, committed outcomes, and which
23
- * attempt is currently active for an owner. They are exposed so a test can
24
- * seed state before the first call and assert against it afterwards.
23
+ * attempt is currently active for an owner, plus replayable request bindings.
24
+ * They are exposed so a test can seed state before the first call and assert
25
+ * against it afterwards.
25
26
  *
26
27
  * Not generic over the outcome type: the committed outcomes are held as the
27
28
  * codec's durable text, the same representation a store's column holds, so
28
- * none of the four maps carries an outcome-typed value.
29
+ * none of the maps carries an outcome-typed value.
29
30
  */
30
31
  interface InMemoryAttemptRepositoryState {
31
32
  /** Attempt records keyed by `executionAttemptId`. */
@@ -45,6 +46,8 @@ interface InMemoryAttemptRepositoryState {
45
46
  readonly committedOutcomes: Map<string, string>;
46
47
  /** Active attempt per `executionId`, the fence every bootstrap path reads. */
47
48
  readonly activeAttempts: Map<string, string>;
49
+ /** Request-to-attempt bindings, nested by owner and then opaque request key. */
50
+ readonly requestBindings: Map<string, Map<string, string>>;
48
51
  }
49
52
  /**
50
53
  * The in-memory realization together with the state backing it.