@makaio/framework 1.0.0-dev-1789000242829 → 1.0.0-dev-1789056039016
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.
- package/dist/.makaio-build.json +2 -2
- package/dist/adapters/claude/index.d.mts +60 -60
- package/dist/adapters/config/index.d.mts +1 -1
- package/dist/adapters/index.d.mts +2 -2
- package/dist/adapters/node.d.mts +1 -1
- package/dist/artifact--nbPrvm5.mjs +1 -0
- package/dist/attempt-control-evidence-BKw1U3wL.mjs +1 -0
- package/dist/bootstrap-start-client-D7t7d9ty.mjs +1 -0
- package/dist/bus/index.mjs +1 -1
- package/dist/clients/index.d.mts +1 -1
- package/dist/clients/managed-install.d.mts +1 -1
- package/dist/code-execution/worker-entry.d.mts +1 -1
- package/dist/contracts/adapter/index.d.mts +2 -2
- package/dist/contracts/adapter/schemas/session-lineage.d.mts +1 -1
- package/dist/contracts/artifact/index.d.mts +3 -3
- package/dist/contracts/artifact/index.mjs +1 -1
- package/dist/contracts/auth/index.d.mts +2 -2
- package/dist/contracts/automation-trigger/index.d.mts +3 -3
- package/dist/contracts/canonical-model/index.d.mts +1 -1
- package/dist/contracts/capabilities/index.d.mts +1 -1
- package/dist/contracts/client/index.d.mts +2 -2
- package/dist/contracts/code-execution/index.d.mts +1 -1
- package/dist/contracts/common/index.d.mts +1 -1
- package/dist/contracts/config/index.d.mts +1 -1
- package/dist/contracts/extension/index.d.mts +5 -5
- package/dist/contracts/facet/index.d.mts +1 -1
- package/dist/contracts/harness/index.d.mts +1 -1
- package/dist/contracts/host/index.d.mts +1 -1
- package/dist/contracts/index.d.mts +287 -61
- package/dist/contracts/index.mjs +1 -1
- package/dist/contracts/materialization/index.d.mts +2 -2
- package/dist/contracts/model-registry/index.d.mts +1 -1
- package/dist/contracts/native-session-supervisor/index.d.mts +1 -1
- package/dist/contracts/platform/index.d.mts +1 -1
- package/dist/contracts/provider/index.d.mts +2 -2
- package/dist/contracts/reaction/index.d.mts +1 -1
- package/dist/contracts/session/index.d.mts +2 -2
- package/dist/contracts/shared/index.d.mts +2 -2
- package/dist/contracts/skill/index.d.mts +1 -1
- package/dist/contracts/telemetry/index.d.mts +1 -1
- package/dist/contracts/timeout/index.d.mts +1 -1
- package/dist/contracts/variant/index.d.mts +1 -1
- package/dist/contracts/worker/index.d.mts +3 -3
- package/dist/contracts/worker/index.mjs +1 -1
- package/dist/contracts/workflow/index.d.mts +2 -2
- package/dist/contracts/workflow/index.mjs +1 -1
- package/dist/{contribution-BfEEQ8YZ.d.mts → contribution-BWanQHUz.d.mts} +2 -2
- package/dist/{definition-6d5JBi55.d.mts → definition-DSOXLpQj.d.mts} +1 -1
- package/dist/{detached-extension-handle-BJnk3WEh.mjs → detached-extension-handle-BNvRSUVO.mjs} +1 -1
- package/dist/{execution-attempt-repository-DSpz2kyW.d.mts → execution-attempt-repository-BoNwNybg.d.mts} +85 -3
- package/dist/{hook-responses-CpEfxEmG.d.mts → hook-responses-DVjMuGh9.d.mts} +1 -1
- package/dist/{index-CCNCo440.d.mts → index-B4KCyY6J.d.mts} +16 -16
- package/dist/{index-Bj2JCo9V.d.mts → index-BXair-QK.d.mts} +1 -1
- package/dist/{index-BfzuauBt2.d.mts → index-BgKU1PuR2.d.mts} +1 -1
- package/dist/{index-DvoitgXV.d.mts → index-C0jn5nKJ.d.mts} +11 -11
- package/dist/{index-CRM23ToM2.d.mts → index-CAURP-Tl2.d.mts} +3 -3
- package/dist/{index-BTluq4-E.d.mts → index-CKvliyuY.d.mts} +4847 -1730
- package/dist/{index-BlHq_Ksb.d.mts → index-CLmjrH8K.d.mts} +2 -2
- package/dist/{index-GTCM4lXx.d.mts → index-CO6ADD43.d.mts} +25 -25
- package/dist/{index-BM-FPWjs2.d.mts → index-CTNGL-cq2.d.mts} +1 -1
- package/dist/{index-CDhbUjUH.d.mts → index-CU9xmTkP.d.mts} +1 -1
- package/dist/{index-hm8NV4CJ2.d.mts → index-CVP9K9-a2.d.mts} +8 -8
- package/dist/{index-BfwHYuRf.d.mts → index-Caai1zAG.d.mts} +1 -1
- package/dist/{index-D7IZQNhD.d.mts → index-CgYGg-Ne2.d.mts} +2 -2
- package/dist/{index-Bn6sN1op.d.mts → index-DUH2eTyC.d.mts} +1 -1
- package/dist/{index-C742b1FV.d.mts → index-DUdGqxHD.d.mts} +1 -1
- package/dist/{index-Dzozmb5u.d.mts → index-Ddk-kjif.d.mts} +3 -3
- package/dist/{index-DY_0TRvM.d.mts → index-DhW9WHFS.d.mts} +2 -2
- package/dist/{index-6kg8YFYt.d.mts → index-DnZksNTM.d.mts} +1 -1
- package/dist/{index-B3G-Hzwn.d.mts → index-Dp3UZQv_.d.mts} +1 -1
- package/dist/{index-BxJRljy-.d.mts → index-Dtc5UYJG.d.mts} +237 -102
- package/dist/{index-DR308wUB2.d.mts → index-H2NL2OwF2.d.mts} +119 -7
- package/dist/{index-CjMMvZch.d.mts → index-LRAmVQLj.d.mts} +278 -44
- package/dist/kernel/cli/index.d.mts +2 -2
- package/dist/kernel/cli/register.d.mts +1 -1
- package/dist/kernel/extension/index.d.mts +1 -1
- package/dist/kernel/index.d.mts +5 -5
- package/dist/kernel/namespace/index.d.mts +1 -1
- package/dist/kernel/observability/index.d.mts +1 -1
- package/dist/kernel/providers/index.d.mts +1 -1
- package/dist/kernel/window/index.d.mts +1 -1
- package/dist/{lib-BmXBuE-w.mjs → lib-B1Mvm4hQ.mjs} +1 -1
- package/dist/{lib-R-c_q77C.mjs → lib-D1-cvcTz.mjs} +1 -1
- package/dist/{load-extensions-Bu10B5B1.d.mts → load-extensions-D6SVKBPw.d.mts} +1 -1
- package/dist/{load-extensions-s4YmICgn.mjs → load-extensions-bwisKaW0.mjs} +1 -1
- package/dist/{namespace-btfJrUf6.d.mts → namespace-CYYFqmtJ.d.mts} +6 -6
- package/dist/{namespace-CfA0C0JR.d.mts → namespace-CfNNUjVv.d.mts} +2 -2
- package/dist/{namespace-BHb_9sh4.d.mts → namespace-DyWNxLt1.d.mts} +6 -6
- package/dist/{namespace-Dmbm2JzV.d.mts → namespace-l1Rcc4mp.d.mts} +2 -2
- package/dist/node/bus-server/index.d.mts +1 -1
- package/dist/node/bus-server/server-lifecycle.d.mts +1 -1
- package/dist/{package-BaTrCWZl.d.mts → package-CnR_tOsW.d.mts} +21 -3
- package/dist/package-tvzH3A0x.mjs +7 -0
- package/dist/package.json +1 -1
- package/dist/rules/index.d.mts +1 -1
- package/dist/rules/schemas.d.mts +1 -1
- package/dist/runtime-bun/index.mjs +1 -1
- package/dist/runtime-node/code-execution/index.d.mts +2 -2
- package/dist/runtime-node/extension-discovery.d.mts +1 -1
- package/dist/runtime-node/extension-validation.d.mts +1 -1
- package/dist/runtime-node/extension-validation.mjs +1 -1
- package/dist/runtime-node/index.d.mts +6 -6
- package/dist/runtime-node/index.mjs +21 -21
- package/dist/runtime-node/makaio-config.d.mts +1 -1
- package/dist/runtime-node/workflow-execution-bus-access.mjs +1 -1
- package/dist/runtime-node/workflow-worker/index.d.mts +2 -2
- package/dist/runtime-node/workflow-worker/index.mjs +1 -1
- package/dist/runtime-node/workflow-worker/worker-entry.mjs +1 -1
- package/dist/{schemas-DYIVJDlx.d.mts → schemas-BGcAiQE0.d.mts} +4 -4
- package/dist/{schemas-CQe4xCRn.d.mts → schemas-D6JvwH-h.d.mts} +2 -2
- package/dist/{schemas-Cz7H2f7S.d.mts → schemas-DChhgfU0.d.mts} +7 -7
- package/dist/{schemas-yXs929kr.d.mts → schemas-Dt1YwXLN.d.mts} +7 -7
- package/dist/{schemas-BkCqhK3X.d.mts → schemas-FkLOBJgq.d.mts} +4 -4
- package/dist/{schemas-GyKYcV-Z2.d.mts → schemas-Fn-eeay32.d.mts} +7 -7
- package/dist/{schemas-bcDK-fK3.d.mts → schemas-_NrySTmN.d.mts} +7 -7
- package/dist/services/adapter-runtime/index.d.mts +3 -3
- package/dist/services/adapter-runtime/namespace.d.mts +1 -1
- package/dist/services/adapter-runtime/schemas.d.mts +1 -1
- package/dist/services/adapter-subsystem/index.d.mts +3 -3
- package/dist/services/adapter-subsystem/namespace.d.mts +1 -1
- package/dist/services/agent-runtime/index.d.mts +2 -2
- package/dist/services/agent-runtime/namespace.d.mts +1 -1
- package/dist/services/agent-runtime/schemas.d.mts +1 -1
- package/dist/services/capability/index.d.mts +2 -2
- package/dist/services/code-execution/index.d.mts +1 -1
- package/dist/services/codebase/index.d.mts +2 -2
- package/dist/services/codebase/namespace.d.mts +1 -1
- package/dist/services/codebase/schemas.d.mts +1 -1
- package/dist/services/compression/index.d.mts +2 -2
- package/dist/services/compression/namespace.d.mts +1 -1
- package/dist/services/compression/schemas.d.mts +1 -1
- package/dist/services/context-rules/index.d.mts +1 -1
- package/dist/services/execution-target/index.d.mts +3 -3
- package/dist/services/execution-target/namespace.d.mts +1 -1
- package/dist/services/execution-target/schemas.d.mts +1 -1
- package/dist/services/filesystem/index.d.mts +1 -1
- package/dist/services/filesystem/namespace.d.mts +6 -6
- package/dist/services/filesystem/schemas.d.mts +3 -3
- package/dist/services/git/namespace.d.mts +2 -2
- package/dist/services/git/schemas.d.mts +1 -1
- package/dist/services/index.d.mts +57 -57
- package/dist/services/log-import/browser.d.mts +2 -2
- package/dist/services/log-import/index.d.mts +2 -2
- package/dist/services/log-import/log-import.d.mts +1 -1
- package/dist/services/materialization/index.d.mts +1 -1
- package/dist/services/model-registry/index.d.mts +1 -1
- package/dist/services/preferences/index.d.mts +2 -2
- package/dist/services/preferences/schemas.d.mts +1 -1
- package/dist/services/preferences/storage-namespace.d.mts +2 -2
- package/dist/services/provider-context/index.d.mts +1 -1
- package/dist/services/session/handlers/index.d.mts +1 -1
- package/dist/services/session/index.d.mts +9 -9
- package/dist/services/session/messages/namespace.d.mts +1 -1
- package/dist/services/session/orchestrator-testing/index.d.mts +1 -1
- package/dist/services/session/session-events/namespace.d.mts +1 -1
- package/dist/services/session/storage/namespace.d.mts +1 -1
- package/dist/services/session/storage/schema.d.mts +1 -1
- package/dist/services/session/testing/orchestrator-shared.d.mts +1 -1
- package/dist/services/session/turns/namespace.d.mts +1 -1
- package/dist/services/session-editor/index.d.mts +1 -1
- package/dist/services/settings/index.d.mts +3 -3
- package/dist/services/settings/namespace.d.mts +4 -4
- package/dist/services/settings/storage/clients-namespace.d.mts +1 -1
- package/dist/services/settings/storage/extension-configs/namespace.d.mts +3 -3
- package/dist/services/settings/storage/index.d.mts +3 -3
- package/dist/services/settings/storage/providers-namespace.d.mts +1 -1
- package/dist/services/subagent/index.d.mts +1 -1
- package/dist/services/subagent-template/index.d.mts +2 -2
- package/dist/services/subagent-template/namespace.d.mts +1 -1
- package/dist/services/subagent-template/schemas.d.mts +1 -1
- package/dist/services/tool-approval/index.d.mts +1 -1
- package/dist/services/tools/index.d.mts +1 -1
- package/dist/services/tray-menu/index.d.mts +3 -3
- package/dist/services/tray-menu/namespace.d.mts +1 -1
- package/dist/services/tray-menu/schemas.d.mts +1 -1
- package/dist/services/turn/index.d.mts +1 -1
- package/dist/services/turn/namespace.d.mts +1 -1
- package/dist/services/workflow-transitions/index.d.mts +1 -1
- package/dist/{src-CmLn6zYj.mjs → src-BZdlyUxT.mjs} +1 -1
- package/dist/storage/drizzle/client.d.mts +1 -1
- package/dist/storage/drizzle/index.d.mts +1 -1
- package/dist/storage/handlers/drizzle/index.d.mts +1 -1
- package/dist/storage/handlers/index.d.mts +1 -1
- package/dist/{storage-namespace-zRXWqAfO.d.mts → storage-namespace-BUSNKZLw.d.mts} +10 -10
- package/dist/{transition-bYkXnLY2.d.mts → transition-D2VKNtv6.d.mts} +2 -2
- package/dist/{types-Bnc-pdB12.d.mts → types-DafDuOcH2.d.mts} +1 -1
- package/dist/{types-BNKqcHfP.d.mts → types-DyXXIK4c.d.mts} +3 -3
- package/dist/ui-kernel/index.d.mts +4 -4
- package/dist/ui-kernel/pages/namespace.d.mts +4 -4
- package/dist/ui-kernel/pages/schemas.d.mts +1 -1
- package/dist/{view-builder-CA5qUx85.d.mts → view-builder-BFEvUe6n.d.mts} +1 -1
- package/dist/worker-L8vWpbYa.mjs +1 -0
- package/dist/{workflow-5yHn_Knq.mjs → workflow-DNks09Ip.mjs} +1 -1
- package/dist/workflow-engine/execution-attempt-repository.d.mts +1 -1
- package/dist/workflow-engine/index.d.mts +98 -60
- package/dist/workflow-engine/index.mjs +1 -1
- package/dist/workflow-engine/package.d.mts +1 -1
- package/dist/workflow-engine/package.mjs +1 -1
- package/dist/workflow-engine/provider-operation.d.mts +1 -1
- package/dist/workflow-engine/testing/conformance.d.mts +1 -1
- package/dist/workflow-engine/testing/conformance.mjs +2 -2
- package/dist/workflow-engine/testing/index.d.mts +3 -1
- package/dist/workflow-engine/testing/index.mjs +1 -1
- package/dist/workflow-engine/testing/sqlite.d.mts +1 -1
- package/dist/workflow-engine/testing/sqlite.mjs +50 -33
- package/dist/workflow-worker-BDA-E_pm.mjs +2 -0
- package/package.json +1 -1
- package/dist/artifact-Cxm5ZX7L.mjs +0 -1
- package/dist/bootstrap-start-client-rW55mDI-.mjs +0 -1
- package/dist/package-BT94BLu4.mjs +0 -7
- package/dist/worker-Cx1JDOB9.mjs +0 -1
- package/dist/workflow-worker-BAO7pQpx.mjs +0 -2
- /package/dist/{adapter-binding-DhANVB-O.d.mts → adapter-binding-CTssGlH_.d.mts} +0 -0
- /package/dist/{attempt-fixtures-CMx-2OlG.mjs → attempt-fixtures-B8FSy_vs.mjs} +0 -0
- /package/dist/{attempt-record-codec-D2Gb_epJ.mjs → attempt-record-codec-BrungudT.mjs} +0 -0
- /package/dist/{base-orchestrator-tAgnJAKu.d.mts → base-orchestrator-C5Z9Aowq.d.mts} +0 -0
- /package/dist/{capability-service-Cpkonrc0.d.mts → capability-service-DX3wLjdt.d.mts} +0 -0
- /package/dist/{client-At2zn3yg.d.mts → client-BsXMxeCN.d.mts} +0 -0
- /package/dist/{client-binary-version-verifier-EOj8xXqm.d.mts → client-binary-version-verifier-uMFQoKZj.d.mts} +0 -0
- /package/dist/{clients-namespace-CVRwXq8f.d.mts → clients-namespace-1hXA6qNd.d.mts} +0 -0
- /package/dist/{config-namespace-D7GbrasR.d.mts → config-namespace-Bpq9WOY4.d.mts} +0 -0
- /package/dist/{create-static-mount-BIH26VH8.mjs → create-static-mount-Cr24q94C.mjs} +0 -0
- /package/dist/{definition-VK1rERAp.d.mts → definition-Ckt_WmJw.d.mts} +0 -0
- /package/dist/{extension-context-Cpf_n5FH.d.mts → extension-context-BGNUn34r.d.mts} +0 -0
- /package/dist/{extension-discovery-B0ZL076T.d.mts → extension-discovery-Dx118u_N.d.mts} +0 -0
- /package/dist/{filesystem-service-BWoNtujU.d.mts → filesystem-service-DtApanQk.d.mts} +0 -0
- /package/dist/{index-Bk0Xjk-B.d.mts → index-1AKlC3kZ.d.mts} +0 -0
- /package/dist/{index-CDA33y5A.d.mts → index-5KVPGsig.d.mts} +0 -0
- /package/dist/{index-8a41yDOl.d.mts → index-B4lidHiL.d.mts} +0 -0
- /package/dist/{index-Bzxs2nVR.d.mts → index-BLhNHkiK.d.mts} +0 -0
- /package/dist/{index-DzHc6hsJ.d.mts → index-Bw7benCh.d.mts} +0 -0
- /package/dist/{index-DXSVC0bM.d.mts → index-C0zo4Id_.d.mts} +0 -0
- /package/dist/{index-BL1F1xYB.d.mts → index-C3n8beRR.d.mts} +0 -0
- /package/dist/{index-C8oBOTl_.d.mts → index-C86rKLPD.d.mts} +0 -0
- /package/dist/{index-BIlFSGnW.d.mts → index-CIl66QhT.d.mts} +0 -0
- /package/dist/{index-Dckvm0Ml2.d.mts → index-CK5GEXLB2.d.mts} +0 -0
- /package/dist/{index-D4XNkbM4.d.mts → index-CUcEfh31.d.mts} +0 -0
- /package/dist/{index-DwY1Mt9a.d.mts → index-CrDp6vHG.d.mts} +0 -0
- /package/dist/{index-CilWtThn.d.mts → index-CrvTRZqh.d.mts} +0 -0
- /package/dist/{index-DCfYa3cF.d.mts → index-CzKJC3Bt.d.mts} +0 -0
- /package/dist/{index-BBkJsViX2.d.mts → index-D4FE3jHM2.d.mts} +0 -0
- /package/dist/{index-Ccaqmi0J.d.mts → index-DK8lSIvY.d.mts} +0 -0
- /package/dist/{index-Du-eXjEN.d.mts → index-DLsopffG.d.mts} +0 -0
- /package/dist/{index-BcPO9w0j.d.mts → index-DNN9jOVO.d.mts} +0 -0
- /package/dist/{index-C75h1xHF2.d.mts → index-DO0QO0ux2.d.mts} +0 -0
- /package/dist/{index-krTCFThl2.d.mts → index-DSRxn5Zr2.d.mts} +0 -0
- /package/dist/{index-CSJOBx3H.d.mts → index-Dfv9hyZE.d.mts} +0 -0
- /package/dist/{index-BpsurXEW.d.mts → index-DqS8eCAT.d.mts} +0 -0
- /package/dist/{index-CjazerMN.d.mts → index-Dv5aNxoa.d.mts} +0 -0
- /package/dist/{index-CWeWBh-_.d.mts → index-DxxORQny.d.mts} +0 -0
- /package/dist/{index-BTHdi23O.d.mts → index-DyBuGOvY.d.mts} +0 -0
- /package/dist/{index-CVh7ZP2I.d.mts → index-fpGFhEmI.d.mts} +0 -0
- /package/dist/{index-DwKPj8jD.d.mts → index-lLuIAmRB.d.mts} +0 -0
- /package/dist/{index-Bn1JTbn_2.d.mts → index-qLkIGcgv2.d.mts} +0 -0
- /package/dist/{index-DCHdW5g-.d.mts → index-tCFckLG6.d.mts} +0 -0
- /package/dist/{json-value-BKUDMT7k.d.mts → json-value-Bjl8jzom.d.mts} +0 -0
- /package/dist/{jsonl-transport-3yp3clGp.mjs → jsonl-transport-D4ch0vsf.mjs} +0 -0
- /package/dist/{lib-DF6sgNx_.mjs → lib-BLdnqIFF.mjs} +0 -0
- /package/dist/{namespace-fEBskugJ.d.mts → namespace--mFdPlbu.d.mts} +0 -0
- /package/dist/{namespace-KTRWfIPy.d.mts → namespace-Bivbsfms.d.mts} +0 -0
- /package/dist/{namespace-BiEV44Mk.d.mts → namespace-C-4xI2rm.d.mts} +0 -0
- /package/dist/{namespace-B0_Sg-1m.d.mts → namespace-CQPcYS-Q.d.mts} +0 -0
- /package/dist/{namespace-BNNFD-ul.d.mts → namespace-CvCk6Y9i.d.mts} +0 -0
- /package/dist/{namespace-BgaVgd00.d.mts → namespace-DXrdGpbs.d.mts} +0 -0
- /package/dist/{namespace-B3MnuAqp.d.mts → namespace-Dwf7aOLt.d.mts} +0 -0
- /package/dist/{namespace-Czr38fiF.d.mts → namespace-E4ajXk0W.d.mts} +0 -0
- /package/dist/{namespace-CY-9Evdf.d.mts → namespace-TX9DlWiQ.d.mts} +0 -0
- /package/dist/{namespace-CjmNxtr1.d.mts → namespace-XUB3XnBK.d.mts} +0 -0
- /package/dist/{orchestrator-shared-Cwc6JKkV.d.mts → orchestrator-shared-D2I9gyOl.d.mts} +0 -0
- /package/dist/{packages-DTz_1dCa.d.mts → packages-Dj9Nul23.d.mts} +0 -0
- /package/dist/{providers-namespace-Bming6U8.d.mts → providers-namespace-BA0JT--_.d.mts} +0 -0
- /package/dist/{runtime-inputs-DeOea-ab.d.mts → runtime-inputs-CIYLDuBM.d.mts} +0 -0
- /package/dist/{schema-DFCBjTB7.d.mts → schema-B098Jz9p.d.mts} +0 -0
- /package/dist/{schemas-DqWwz4eR.d.mts → schemas-ADuQFkhH.d.mts} +0 -0
- /package/dist/{schemas-BLy33xay.d.mts → schemas-BZyi7v9g.d.mts} +0 -0
- /package/dist/{schemas-CSeLgroC.d.mts → schemas-D9WJH6We.d.mts} +0 -0
- /package/dist/{schemas-DwqibWUL.d.mts → schemas-DKy_XYjq.d.mts} +0 -0
- /package/dist/{schemas-DTBWnWjN.d.mts → schemas-DMxM4U1A.d.mts} +0 -0
- /package/dist/{server-lifecycle-_m_x1_TC.d.mts → server-lifecycle-B8UabaW3.d.mts} +0 -0
- /package/dist/{session-lineage-CEyJWg_J.d.mts → session-lineage-CoNs4WZy.d.mts} +0 -0
- /package/dist/{src-DdaPoQOD.mjs → src-D9PYcdDS.mjs} +0 -0
- /package/dist/{storage-namespace-definition-CsaZPU3n.d.mts → storage-namespace-definition-1uCuoHvM.d.mts} +0 -0
- /package/dist/{types-CccTiXH2.d.mts → types-BlaguWul.d.mts} +0 -0
- /package/dist/{types-nor1SQLZ.d.mts → types-CbXf822E.d.mts} +0 -0
- /package/dist/{types-DjxvRcX6.d.mts → types-KF8zuMhi.d.mts} +0 -0
- /package/dist/{types-Dswhi1L9.d.mts → types-RWRXplnM.d.mts} +0 -0
- /package/dist/{types-DXGVwrQn.d.mts → types-nY8yr3th.d.mts} +0 -0
- /package/dist/{window-registry-DQ7udUzI.d.mts → window-registry-Dq5uOWpH.d.mts} +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{n as e,p as t}from"../../execution-attempt-repository-CWbgCTwA.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-CMx-2OlG.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(e){g(`checks runtime generation at commit without rejecting historical canonical duplicates`,async()=>{let n=e(),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(t),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=e(),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 e of[null,`another-operation`])await h(n.repository.commitOutcome({...r,result:a,runtimeFence:{runtimeGeneration:i,operationId:e}})).rejects.toThrow(t);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 t=e(),n=b(),r=await O(t.repository,n);await t.peer.createAttempt({...n,executionAttemptId:`${n.executionAttemptId}-replacement`,instruction:i(),bootstrapTimeoutMs:y}),h(await t.repository.commitOutcome({...n,result:t.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 t=e(),n=b(),r=i({workload:{kind:`test`,version:`1`,input:{value:`original`}}});await t.repository.createAttempt({...n,instruction:r,bootstrapTimeoutMs:y}),r.workload.input={value:`changed`},h(await t.repository.getInstruction(n)).toMatchObject({workload:{input:{value:`original`}}});let a=await t.repository.getInstruction(n);h(Object.isFrozen(a?.workload.input)).toBe(!0),h(await t.repository.getInstruction({...n,executionId:`other-owner`})).toBeNull(),h(await t.repository.getInstruction({...n,executionAttemptId:`missing`})).toBeNull();let o={...r,revision:``};await h(t.repository.createAttempt({executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-invalid`,instruction:o,bootstrapTimeoutMs:y})).rejects.toThrow(),h(await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).not.toBeNull(),h(await t.peer.getActiveAttempt(`${n.executionId}-foreign`,n.executionAttemptId)).toBeNull(),h(await t.peer.commitOutcome({...n,result:t.peer.canonicalizeOutcome(c(n.executionId))})).toMatchObject({kind:`accepted`}),h(await t.repository.getInstruction(n)).toEqual(a);let s={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-replacement`},l=i({id:`replacement-assignment`});await t.peer.createAttempt({...s,instruction:l,bootstrapTimeoutMs:y}),h(await t.repository.getInstruction(n)).toEqual(a),h(await t.repository.getInstruction(s)).toEqual(l),h(await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).toBeNull(),h(await t.repository.getActiveAttempt(s.executionId,s.executionAttemptId)).toMatchObject({executionAttemptId:s.executionAttemptId})}),g(`admits a workspace-less invocation without inventing a preparation result`,async()=>{let t=e(),n=b(),r=await O(t.repository,n);h(await t.repository.admitOperation({...n,runtimeGeneration:r,operationKind:`workspace-preparation`,admissionKey:`unneeded`})).toEqual({kind:`preparation-not-required`}),h(await t.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 t=e().repository,n=await C(t);h(await t.completeOperation(n)).toEqual({kind:`result-required`}),h(await t.reportOperation(n)).toEqual({kind:`accepted`,binding:n.result.binding}),h(await t.getActiveAttempt(n.executionId,n.executionAttemptId)).toMatchObject({activeOperationId:null,lastCompletedOperationId:n.operationId,preparationReceipts:[{operationId:n.operationId,runtimeGeneration:n.runtimeGeneration,result:n.result}]}),h(await t.admitOperation({...n,operationKind:`workspace-preparation`,admissionKey:`prepare-again`})).toEqual({kind:`preparation-already-completed`});let r=await t.admitOperation({...n,operationKind:`workload-invocation`,admissionKey:`invoke`});if(h(r.kind).toBe(`admitted`),h(await t.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),r.kind!==`admitted`)throw Error(`Expected Invocation`);h(await t.completeOperation({...n,operationId:r.operationId})).toEqual({kind:`result-required`}),await t.commitOutcome({...n,result:t.canonicalizeOutcome(c(n.executionId,`completed`))}),h(await t.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),h((await t.getActiveAttempt(n.executionId,n.executionAttemptId))?.activeOperationId).toBe(r.operationId)}),g(`acknowledges historical receipts without preparing the replacement runtime`,async()=>{let t=e().repository,n=await C(t);await t.reportOperation(n);let r=await T(t,n,`replacement`);await E(t,n,r),h(await t.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),h(await t.reportOperation({...n,result:{...n.result,binding:{workspaceRoot:`/changed`,sourceRoots:[]}}})).toEqual({kind:`conflict`}),h(await t.reportOperation({...n,operationId:`unaccepted-old-operation`})).toEqual({kind:`stale-generation`}),h(await t.admitOperation({...n,runtimeGeneration:r,operationKind:`workload-invocation`,admissionKey:`invoke-replacement`})).toEqual({kind:`preparation-required`});let i=await D(t,n,r,`workspace-preparation`,`prepare-replacement`),a={...n,runtimeGeneration:r,operationId:i,result:{...n.result,binding:{workspaceRoot:`/scratch/replacement`,sourceRoots:[]}}};h(await t.reportOperation(a)).toEqual({kind:`accepted`,binding:a.result.binding}),h(await t.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),h((await t.getActiveAttempt(n.executionId,n.executionAttemptId))?.preparationReceipts).toHaveLength(2),h(await t.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})]);if(h(o.kind).toBe(`claimed`),o.kind!==`claimed`)throw Error(`Expected takeover, got '${o.kind}'`);h(s).toEqual({kind:`accepted`,outcome:a.outcome,text:a.text,controlObservation:{controlRevision:0,cancellation:null}}),h(await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).toMatchObject({settlementKind:`outcome`}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({ownerId:o.claim.ownerId,token:o.claim.token,leaseExpiresAt:o.claim.leaseExpiresAt,completionEvidence: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(t){se(t),g(`rejects a reused attempt identifier without touching the existing attempt`,async()=>{let n=t(),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(e),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 e=t(),n=b(),a=await x(e.repository,n);await e.repository.recordAllocation({claim:a,allocationRef:r()});let o=b(),s=await x(e.repository,o);await e.repository.recordAllocation({claim:s,allocationRef:r()});let c={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-next`};await e.repository.createAttempt({...c,instruction:i(),bootstrapTimeoutMs:y}),h(await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({status:`allocated`,claimable:!1}),h(await e.repository.recovery.getAttemptWithAllocation(o.executionAttemptId)).toMatchObject({status:`allocated`,claimable:!0})}),g(`compares allocation references by value, not by member order`,async()=>{let e=t(),n=b(),i=await x(e.repository,n);await e.repository.recordAllocation({claim:i,allocationRef:r(s,{machineId:`parity-order`,region:`ord`})});let a=r(s,{region:`ord`,machineId:`parity-order`});h(await e.repository.recordAllocation({claim:i,allocationRef:a})).toMatchObject({kind:`duplicate`}),h(await e.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 e.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 e=t(),n=`${b().executionId}-recovery-order`,i=[];for(let t of[`c`,`b`,`a`]){let a=`${n}-${t}`,o=await x(e.repository,{executionId:n,executionAttemptId:a});await e.repository.recordAllocation({claim:o,allocationRef:r(s,{machineId:t})}),i.push(a)}h((await e.repository.recovery.getRecoverableAttempts(n)).map(e=>e.executionAttemptId)).toEqual([i.at(-1)])}),g(`refuses an evolution whose references name different providers`,async()=>{let e=t(),n=b(),i=await x(e.repository,n),a=r(s,{machineId:`parity-1`});await e.repository.recordAllocation({claim:i,allocationRef:a}),await h(e.repository.recovery.evolveAllocationRef({claim:i,executionId:n.executionId,currentRef:a,nextRef:r(`a-different-provider`,{machineId:`parity-1`})})).rejects.toThrow(),h((await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef).toEqual(a)}),g(`retains unresolved provisioning when infrastructure failure has no allocation to settle`,async()=>{let e=t(),n=b(),r=await x(e.repository,n);h(await e.peer.recordInfrastructureFailure({claim:r,executionId:n.executionId})).toEqual({kind:`not-allocated`});let i=await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(i).toMatchObject({status:`provisioning`,allocationRef:null,operationStartGate:`open`}),h(i?.settlementKind??null).toBeNull(),h(await e.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({...r,obligation:`provisioning-resolution`,failureCount:0,lastFailure:null})}),g(`settles infrastructure only after termination is durably confirmed`,async()=>{let e=t(),n=b(),i=await x(e.repository,n),o=r();await e.repository.recordAllocation({claim:i,allocationRef:o});let s=await e.repository.recordInfrastructureFailure({claim:i,executionId:n.executionId}),c=await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),l=await e.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 e.repository.recordAllocationTerminated({claim:i,evidence:a({summary:`provider reported the allocation terminated`})}),d=await e.repository.recordInfrastructureFailure({claim:i,executionId:n.executionId});h(u).toEqual({kind:`recorded`}),h(d).toEqual({kind:`recorded`}),h((await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.settlementKind).toBe(`infrastructure-failure`);let f=await e.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 e=t(),n=b(),i=await x(e.repository,n),a=r(`a-different-provider`,{machineId:`foreign-1`});await h(e.repository.recordAllocation({claim:i,allocationRef:a})).rejects.toThrow(),await h(e.repository.recovery.recordDiscoveredAllocation({claim:i,allocationRef:a})).rejects.toThrow();let o=await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(o?.allocationRef).toBeNull(),h(o?.status).toBe(`provisioning`),h((await e.repository.getProviderOperation(n.executionAttemptId))?.obligation).toBe(`provisioning-resolution`),h(await e.repository.recordAllocation({claim:i,allocationRef:r()})).toEqual({kind:`recorded`})}),g(`refuses a foreign allocation reference even from a fenced claim`,async()=>{let e=t(),n=b(),i=await x(e.repository,n);h((await e.repository.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`parity-remediator`,observedAt:u(36e5),leaseExpiresAt:u(72e5)})).kind).toBe(`claimed`),await h(e.repository.recordAllocation({claim:i,allocationRef:r(`a-different-provider`,{machineId:`foreign-2`})})).rejects.toThrow(),h(await e.repository.recordAllocation({claim:i,allocationRef:r()})).toEqual({kind:`stale`})}),g(`refuses an allocation reference the contract forbids, before any mutation`,async()=>{let e=t(),n=b(),i=await x(e.repository,n);await h(e.repository.recordAllocation({claim:i,allocationRef:{...r(),providerId:``}})).rejects.toThrow();let a=await e.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 e=t(),n=b(),i=await x(e.repository,n),a={machineId:`parity-owned`};await e.repository.recordAllocation({claim:i,allocationRef:r(s,a)}),a.machineId=`mutated-after-the-fact`,h((await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef?.providerData).toEqual({machineId:`parity-owned`})})}function se(t){g(`preserves exactly one instruction when two controllers create the same attempt identifier`,async()=>{let n=t(),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(e),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(`completes 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=d(`provisioner-A`),s=await t.repository.recordProvisionerIncarnationLost({claim:r,executionId:n.executionId,proof:o}),c=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),l=await t.repository.getProviderOperation(n.executionAttemptId);h(i).toEqual({kind:`incarnation-mismatch`,provisionerIncarnationId:`provisioner-A`}),h(a?.settlementKind??null).toBeNull(),h(s).toEqual({kind:`recorded`}),h(c?.status).toBe(`settled`),h(c?.settlementKind).toBe(`abandoned`),h(c?.allocationRef).toBeNull(),h(c?.claimable??!1).toBe(!1),h(l?.ownerId).toBe(r.ownerId),h(l?.token).toBe(r.token),h(l?.leaseExpiresAt).toBe(r.leaseExpiresAt),h(l?.completionEvidence).toEqual(o.evidence),h(l?.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 completes its 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:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt,obligation:`provisioning-resolution`,completionEvidence: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,controlObservation:{controlRevision:0,cancellation:null}}),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:i.ownerId,token:i.token,leaseExpiresAt:i.leaseExpiresAt,obligation:`terminal-convergence`,lastFailure:s,completionEvidence:null})})}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:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt,obligation:`provisioning-resolution`,completionEvidence: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,c=await e.repository.commitOutcome({...r,result:e.repository.canonicalizeOutcome(a)}),l={controlRevision:0,cancellation:null};h(c).toEqual({kind:`accepted`,outcome:a,text:s,controlObservation:l}),h(await e.repository.commitOutcome({...r,result:e.repository.canonicalizeOutcome(n.makeOutcome(r.executionId,0))})).toEqual({kind:`duplicate`,outcome:a,text:s,controlObservation:l}),h(await e.repository.commitOutcome({...r,result:e.repository.canonicalizeOutcome(n.makeOutcome(r.executionId,1))})).toEqual({kind:`conflict`})}),g(`stores prior cancellation beside an opaque outcome without transforming its value`,async()=>{let{repository:e,peer:r}=t(),a=b();await e.createAttempt({...a,instruction:i(),bootstrapTimeoutMs:y}),await r.requestAttemptCancellation({...a,requestKey:`stop-opaque-owner`});let o=await e.readCancellation(a.executionAttemptId),s=e.canonicalizeOutcome(n.makeOutcome(a.executionId,0)),c={controlRevision:1,cancellation:o};h(await e.commitOutcome({...a,result:s})).toEqual({kind:`accepted`,...s,controlObservation:c}),h(await r.commitOutcome({...a,result:s})).toEqual({kind:`duplicate`,...s,controlObservation:c}),h(await r.readAttemptSettlement(a)).toMatchObject({kind:`outcome`,result:s,controlObservation:c})})})}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});let r=await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(1.2)}),a={controlRevision:0,cancellation:null};h(r).toEqual({kind:`accepted`,outcome:1,text:`{"counter":1}`,controlObservation:a}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(1.7)})).toEqual({kind:`duplicate`,outcome:1,text:`{"counter":1}`,controlObservation:a}),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}`,controlObservation:{controlRevision:0,cancellation:null}}),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}`,controlObservation:{controlRevision:0,cancellation:null}}),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,controlObservation:{controlRevision:0,cancellation:null}}),h(await t.peer.commitOutcome({...n,result:s})).toEqual({kind:`duplicate`,outcome:s.outcome,text:s.text,controlObservation:{controlRevision:0,cancellation:null}}),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,controlObservation:{controlRevision:0,cancellation:null}}),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,controlObservation:{controlRevision:0,cancellation:null}});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);let o=await e.repository.commitOutcome({...n,result:r}),s={controlRevision:0,cancellation:null};h(o).toEqual({kind:`accepted`,outcome:{alpha:1,beta:2},text:r.text,controlObservation:s}),h(await e.peer.commitOutcome({...n,result:a})).toEqual({kind:`duplicate`,outcome:{alpha:1,beta:2},text:r.text,controlObservation:s}),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,controlObservation:{controlRevision:0,cancellation:null}}),await Z(t,n,a,`outcome`,async()=>{h(await t.peer.commitOutcome({...n,result:o})).toEqual({kind:`duplicate`,outcome:s.outcome,text:s.text,controlObservation:{controlRevision:0,cancellation:null}})})}),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(t){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 e=>{let{repository:n,peer:r}=t(),i=Q(),a=await n.createAttempt(i),o={...i,executionAttemptId:`${i.executionAttemptId}-next`};await h(r.ensureAttempt({...o,...e})).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}=t(),i=Q(),a=await n.createAttempt(i);await h(r.ensureAttempt(i)).rejects.toThrow(e),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=`
|
|
1
|
+
import{n as e,p as t}from"../../execution-attempt-repository-CWbgCTwA.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-B8FSy_vs.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(e){g(`checks runtime generation at commit without rejecting historical canonical duplicates`,async()=>{let n=e(),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(t),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=e(),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 e of[null,`another-operation`])await h(n.repository.commitOutcome({...r,result:a,runtimeFence:{runtimeGeneration:i,operationId:e}})).rejects.toThrow(t);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 t=e(),n=b(),r=await O(t.repository,n);await t.peer.createAttempt({...n,executionAttemptId:`${n.executionAttemptId}-replacement`,instruction:i(),bootstrapTimeoutMs:y}),h(await t.repository.commitOutcome({...n,result:t.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 t=e(),n=b(),r=i({workload:{kind:`test`,version:`1`,input:{value:`original`}}});await t.repository.createAttempt({...n,instruction:r,bootstrapTimeoutMs:y}),r.workload.input={value:`changed`},h(await t.repository.getInstruction(n)).toMatchObject({workload:{input:{value:`original`}}});let a=await t.repository.getInstruction(n);h(Object.isFrozen(a?.workload.input)).toBe(!0),h(await t.repository.getInstruction({...n,executionId:`other-owner`})).toBeNull(),h(await t.repository.getInstruction({...n,executionAttemptId:`missing`})).toBeNull();let o={...r,revision:``};await h(t.repository.createAttempt({executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-invalid`,instruction:o,bootstrapTimeoutMs:y})).rejects.toThrow(),h(await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).not.toBeNull(),h(await t.peer.getActiveAttempt(`${n.executionId}-foreign`,n.executionAttemptId)).toBeNull(),h(await t.peer.commitOutcome({...n,result:t.peer.canonicalizeOutcome(c(n.executionId))})).toMatchObject({kind:`accepted`}),h(await t.repository.getInstruction(n)).toEqual(a);let s={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-replacement`},l=i({id:`replacement-assignment`});await t.peer.createAttempt({...s,instruction:l,bootstrapTimeoutMs:y}),h(await t.repository.getInstruction(n)).toEqual(a),h(await t.repository.getInstruction(s)).toEqual(l),h(await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).toBeNull(),h(await t.repository.getActiveAttempt(s.executionId,s.executionAttemptId)).toMatchObject({executionAttemptId:s.executionAttemptId})}),g(`admits a workspace-less invocation without inventing a preparation result`,async()=>{let t=e(),n=b(),r=await O(t.repository,n);h(await t.repository.admitOperation({...n,runtimeGeneration:r,operationKind:`workspace-preparation`,admissionKey:`unneeded`})).toEqual({kind:`preparation-not-required`}),h(await t.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 t=e().repository,n=await C(t);h(await t.completeOperation(n)).toEqual({kind:`result-required`}),h(await t.reportOperation(n)).toEqual({kind:`accepted`,binding:n.result.binding}),h(await t.getActiveAttempt(n.executionId,n.executionAttemptId)).toMatchObject({activeOperationId:null,lastCompletedOperationId:n.operationId,preparationReceipts:[{operationId:n.operationId,runtimeGeneration:n.runtimeGeneration,result:n.result}]}),h(await t.admitOperation({...n,operationKind:`workspace-preparation`,admissionKey:`prepare-again`})).toEqual({kind:`preparation-already-completed`});let r=await t.admitOperation({...n,operationKind:`workload-invocation`,admissionKey:`invoke`});if(h(r.kind).toBe(`admitted`),h(await t.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),r.kind!==`admitted`)throw Error(`Expected Invocation`);h(await t.completeOperation({...n,operationId:r.operationId})).toEqual({kind:`result-required`}),await t.commitOutcome({...n,result:t.canonicalizeOutcome(c(n.executionId,`completed`))}),h(await t.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),h((await t.getActiveAttempt(n.executionId,n.executionAttemptId))?.activeOperationId).toBe(r.operationId)}),g(`acknowledges historical receipts without preparing the replacement runtime`,async()=>{let t=e().repository,n=await C(t);await t.reportOperation(n);let r=await T(t,n,`replacement`);await E(t,n,r),h(await t.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),h(await t.reportOperation({...n,result:{...n.result,binding:{workspaceRoot:`/changed`,sourceRoots:[]}}})).toEqual({kind:`conflict`}),h(await t.reportOperation({...n,operationId:`unaccepted-old-operation`})).toEqual({kind:`stale-generation`}),h(await t.admitOperation({...n,runtimeGeneration:r,operationKind:`workload-invocation`,admissionKey:`invoke-replacement`})).toEqual({kind:`preparation-required`});let i=await D(t,n,r,`workspace-preparation`,`prepare-replacement`),a={...n,runtimeGeneration:r,operationId:i,result:{...n.result,binding:{workspaceRoot:`/scratch/replacement`,sourceRoots:[]}}};h(await t.reportOperation(a)).toEqual({kind:`accepted`,binding:a.result.binding}),h(await t.reportOperation(n)).toEqual({kind:`duplicate`,binding:n.result.binding}),h((await t.getActiveAttempt(n.executionId,n.executionAttemptId))?.preparationReceipts).toHaveLength(2),h(await t.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})]);if(h(o.kind).toBe(`claimed`),o.kind!==`claimed`)throw Error(`Expected takeover, got '${o.kind}'`);h(s).toEqual({kind:`accepted`,outcome:a.outcome,text:a.text,controlObservation:{controlRevision:0,cancellation:null}}),h(await t.repository.getActiveAttempt(n.executionId,n.executionAttemptId)).toMatchObject({settlementKind:`outcome`}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({ownerId:o.claim.ownerId,token:o.claim.token,leaseExpiresAt:o.claim.leaseExpiresAt,completionEvidence: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(t){se(t),g(`rejects a reused attempt identifier without touching the existing attempt`,async()=>{let n=t(),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(e),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 e=t(),n=b(),a=await x(e.repository,n);await e.repository.recordAllocation({claim:a,allocationRef:r()});let o=b(),s=await x(e.repository,o);await e.repository.recordAllocation({claim:s,allocationRef:r()});let c={executionId:n.executionId,executionAttemptId:`${n.executionAttemptId}-next`};await e.repository.createAttempt({...c,instruction:i(),bootstrapTimeoutMs:y}),h(await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId)).toMatchObject({status:`allocated`,claimable:!1}),h(await e.repository.recovery.getAttemptWithAllocation(o.executionAttemptId)).toMatchObject({status:`allocated`,claimable:!0})}),g(`compares allocation references by value, not by member order`,async()=>{let e=t(),n=b(),i=await x(e.repository,n);await e.repository.recordAllocation({claim:i,allocationRef:r(s,{machineId:`parity-order`,region:`ord`})});let a=r(s,{region:`ord`,machineId:`parity-order`});h(await e.repository.recordAllocation({claim:i,allocationRef:a})).toMatchObject({kind:`duplicate`}),h(await e.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 e.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 e=t(),n=`${b().executionId}-recovery-order`,i=[];for(let t of[`c`,`b`,`a`]){let a=`${n}-${t}`,o=await x(e.repository,{executionId:n,executionAttemptId:a});await e.repository.recordAllocation({claim:o,allocationRef:r(s,{machineId:t})}),i.push(a)}h((await e.repository.recovery.getRecoverableAttempts(n)).map(e=>e.executionAttemptId)).toEqual([i.at(-1)])}),g(`refuses an evolution whose references name different providers`,async()=>{let e=t(),n=b(),i=await x(e.repository,n),a=r(s,{machineId:`parity-1`});await e.repository.recordAllocation({claim:i,allocationRef:a}),await h(e.repository.recovery.evolveAllocationRef({claim:i,executionId:n.executionId,currentRef:a,nextRef:r(`a-different-provider`,{machineId:`parity-1`})})).rejects.toThrow(),h((await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef).toEqual(a)}),g(`retains unresolved provisioning when infrastructure failure has no allocation to settle`,async()=>{let e=t(),n=b(),r=await x(e.repository,n);h(await e.peer.recordInfrastructureFailure({claim:r,executionId:n.executionId})).toEqual({kind:`not-allocated`});let i=await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(i).toMatchObject({status:`provisioning`,allocationRef:null,operationStartGate:`open`}),h(i?.settlementKind??null).toBeNull(),h(await e.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({...r,obligation:`provisioning-resolution`,failureCount:0,lastFailure:null})}),g(`settles infrastructure only after termination is durably confirmed`,async()=>{let e=t(),n=b(),i=await x(e.repository,n),o=r();await e.repository.recordAllocation({claim:i,allocationRef:o});let s=await e.repository.recordInfrastructureFailure({claim:i,executionId:n.executionId}),c=await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),l=await e.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 e.repository.recordAllocationTerminated({claim:i,evidence:a({summary:`provider reported the allocation terminated`})}),d=await e.repository.recordInfrastructureFailure({claim:i,executionId:n.executionId});h(u).toEqual({kind:`recorded`}),h(d).toEqual({kind:`recorded`}),h((await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.settlementKind).toBe(`infrastructure-failure`);let f=await e.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 e=t(),n=b(),i=await x(e.repository,n),a=r(`a-different-provider`,{machineId:`foreign-1`});await h(e.repository.recordAllocation({claim:i,allocationRef:a})).rejects.toThrow(),await h(e.repository.recovery.recordDiscoveredAllocation({claim:i,allocationRef:a})).rejects.toThrow();let o=await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);h(o?.allocationRef).toBeNull(),h(o?.status).toBe(`provisioning`),h((await e.repository.getProviderOperation(n.executionAttemptId))?.obligation).toBe(`provisioning-resolution`),h(await e.repository.recordAllocation({claim:i,allocationRef:r()})).toEqual({kind:`recorded`})}),g(`refuses a foreign allocation reference even from a fenced claim`,async()=>{let e=t(),n=b(),i=await x(e.repository,n);h((await e.repository.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`parity-remediator`,observedAt:u(36e5),leaseExpiresAt:u(72e5)})).kind).toBe(`claimed`),await h(e.repository.recordAllocation({claim:i,allocationRef:r(`a-different-provider`,{machineId:`foreign-2`})})).rejects.toThrow(),h(await e.repository.recordAllocation({claim:i,allocationRef:r()})).toEqual({kind:`stale`})}),g(`refuses an allocation reference the contract forbids, before any mutation`,async()=>{let e=t(),n=b(),i=await x(e.repository,n);await h(e.repository.recordAllocation({claim:i,allocationRef:{...r(),providerId:``}})).rejects.toThrow();let a=await e.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 e=t(),n=b(),i=await x(e.repository,n),a={machineId:`parity-owned`};await e.repository.recordAllocation({claim:i,allocationRef:r(s,a)}),a.machineId=`mutated-after-the-fact`,h((await e.repository.recovery.getAttemptWithAllocation(n.executionAttemptId))?.allocationRef?.providerData).toEqual({machineId:`parity-owned`})})}function se(t){g(`preserves exactly one instruction when two controllers create the same attempt identifier`,async()=>{let n=t(),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(e),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 ce(e){g(`completes 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=d(`provisioner-A`),s=await t.repository.recordProvisionerIncarnationLost({claim:r,executionId:n.executionId,proof:o}),c=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId),l=await t.repository.getProviderOperation(n.executionAttemptId);h(i).toEqual({kind:`incarnation-mismatch`,provisionerIncarnationId:`provisioner-A`}),h(a?.settlementKind??null).toBeNull(),h(s).toEqual({kind:`recorded`}),h(c?.status).toBe(`settled`),h(c?.settlementKind).toBe(`abandoned`),h(c?.allocationRef).toBeNull(),h(c?.claimable??!1).toBe(!1),h(l?.ownerId).toBe(r.ownerId),h(l?.token).toBe(r.token),h(l?.leaseExpiresAt).toBe(r.leaseExpiresAt),h(l?.completionEvidence).toEqual(o.evidence),h(l?.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 M(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 completes its 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:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt,obligation:`provisioning-resolution`,completionEvidence: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 N(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,controlObservation:{controlRevision:0,cancellation:null}}),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})}),P(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 P(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 F(e){I(e),L(e),R(e),z(e),B(e)}function I(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 L(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 R(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:i.ownerId,token:i.token,leaseExpiresAt:i.leaseExpiresAt,obligation:`terminal-convergence`,lastFailure:s,completionEvidence:null})})}function z(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 B(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:r.ownerId,token:r.token,leaseExpiresAt:r.leaseExpiresAt,obligation:`provisioning-resolution`,completionEvidence:i.evidence})})}function V(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 H(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 U={parse:e=>H(e),serialize:e=>JSON.stringify({counter:e})},W={parse:e=>H(e),serialize:e=>JSON.stringify({counter:Math.trunc(e)})};function G(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 K={parse:e=>G(e),serialize:e=>JSON.stringify({counter:e.counter,generation:e.generation+1})},le={codec:o,makeOutcome:(e,t)=>c(e,t===0?`completed`:`failed`)},ue={codec:U,makeOutcome:(e,t)=>t};function q(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,c=await e.repository.commitOutcome({...r,result:e.repository.canonicalizeOutcome(a)}),l={controlRevision:0,cancellation:null};h(c).toEqual({kind:`accepted`,outcome:a,text:s,controlObservation:l}),h(await e.repository.commitOutcome({...r,result:e.repository.canonicalizeOutcome(n.makeOutcome(r.executionId,0))})).toEqual({kind:`duplicate`,outcome:a,text:s,controlObservation:l}),h(await e.repository.commitOutcome({...r,result:e.repository.canonicalizeOutcome(n.makeOutcome(r.executionId,1))})).toEqual({kind:`conflict`})}),g(`stores prior cancellation beside an opaque outcome without transforming its value`,async()=>{let{repository:e,peer:r}=t(),a=b();await e.createAttempt({...a,instruction:i(),bootstrapTimeoutMs:y}),await r.requestAttemptCancellation({...a,requestKey:`stop-opaque-owner`});let o=await e.readCancellation(a.executionAttemptId),s=e.canonicalizeOutcome(n.makeOutcome(a.executionId,0)),c={controlRevision:1,cancellation:o};h(await e.commitOutcome({...a,result:s})).toEqual({kind:`accepted`,...s,controlObservation:c}),h(await r.commitOutcome({...a,result:s})).toEqual({kind:`duplicate`,...s,controlObservation:c}),h(await r.readAttemptSettlement(a)).toMatchObject({kind:`outcome`,result:s,controlObservation:c})})})}function de(e){q(e,`workflow run result`,le),q(e,`counter`,ue)}function fe(e){m(`execution attempt outcome parity (${e.name}, normalizing codec)`,()=>{let t=_(e,W);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});let r=await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(1.2)}),a={controlRevision:0,cancellation:null};h(r).toEqual({kind:`accepted`,outcome:1,text:`{"counter":1}`,controlObservation:a}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(1.7)})).toEqual({kind:`duplicate`,outcome:1,text:`{"counter":1}`,controlObservation:a}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome(2.5)})).toEqual({kind:`conflict`})})})}function pe(e){m(`execution attempt outcome parity (${e.name}, non-idempotent serialization)`,()=>{let t=_(e,K);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(K.serialize(r)).toBe(K.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}`,controlObservation:{controlRevision:0,cancellation:null}}),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}`,controlObservation:{controlRevision:0,cancellation:null}}),h(await e.repository.commitOutcome({...n,result:e.repository.canonicalizeOutcome({counter:4,generation:0})})).toEqual({kind:`conflict`})})})}function me(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 he={parse:e=>me(e),serialize:e=>JSON.stringify(e.href)};function ge(e){m(`execution attempt outcome parity (${e.name}, non-cloneable outcome)`,()=>{let t=_(e,he);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 _e(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 ve={parse:e=>_e(e),serialize:e=>JSON.stringify(Array.from(e))};function ye(e){m(`execution attempt outcome parity (${e.name}, unfreezable outcome)`,()=>{let t=_(e,ve);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 be(e){m(`execution attempt outcome parity (${e.name}, invalid stored outcome)`,()=>{let t=_(e,U);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 xe(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,controlObservation:{controlRevision:0,cancellation:null}}),h(await t.peer.commitOutcome({...n,result:s})).toEqual({kind:`duplicate`,outcome:s.outcome,text:s.text,controlObservation:{controlRevision:0,cancellation:null}}),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,controlObservation:{controlRevision:0,cancellation:null}}),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,controlObservation:{controlRevision:0,cancellation:null}});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 Se(e){Ce(e),we(e),Te(e)}function Ce(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 we(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 Te(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 Ee(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 De=[`registration`,`readiness`,`admission`,`Preparation report`];async function Oe(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 ke(e){let t=De.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 Oe(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 Ae(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 je(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 Ae(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 Me(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 Ne(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 Pe(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=J(new Date(i.getTime()-1e3),120),o=J(new Date(i.getTime()+1e3),-120),s=new Date(i.getTime()+6e4),c=J(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 J(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 Fe(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 Ie(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 Le={parse:e=>{if(!Ie(e))throw Error(`MemberOrderOutcome requires numeric alpha and beta members`);return e},serialize:e=>JSON.stringify(e)};function Re(e){m(`execution attempt outcome parity (${e.name}, member-order codec)`,()=>{let t=_(e,Le);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);let o=await e.repository.commitOutcome({...n,result:r}),s={controlRevision:0,cancellation:null};h(o).toEqual({kind:`accepted`,outcome:{alpha:1,beta:2},text:r.text,controlObservation:s}),h(await e.peer.commitOutcome({...n,result:a})).toEqual({kind:`duplicate`,outcome:{alpha:1,beta:2},text:r.text,controlObservation:s}),h(await e.peer.commitOutcome({...n,result:e.peer.canonicalizeOutcome({beta:2,alpha:3})})).toEqual({kind:`conflict`})})})}function ze(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 Be(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 Y(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,controlObservation:{controlRevision:0,cancellation:null}}),await X(t,n,a,`outcome`,async()=>{h(await t.peer.commitOutcome({...n,result:o})).toEqual({kind:`duplicate`,outcome:s.outcome,text:s.text,controlObservation:{controlRevision:0,cancellation:null}})})}),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 Y(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 X(t,n,o,`infrastructure-failure`)})}async function Y(e,t,n){h(await e.repository.recovery.getAttemptWithAllocation(t)).toMatchObject({status:`allocated`,settlementKind:null,allocationRef:n})}async function X(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 Ve(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 He(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 Z(){return{...b(),requestKey:`initial-demand`,instruction:i(),bootstrapTimeoutMs:y}}function Ue(e){We(e),Ge(e),Q(e),Ke(e)}function We(e){g(`creates one attempt for concurrent and sequential same-owner request replays`,async()=>{let{repository:t,peer:n}=e(),r=Z(),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=Z(),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=Z(),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 Ge(t){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 e=>{let{repository:n,peer:r}=t(),i=Z(),a=await n.createAttempt(i),o={...i,executionAttemptId:`${i.executionAttemptId}-next`};await h(r.ensureAttempt({...o,...e})).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}=t(),i=Z(),a=await n.createAttempt(i);await h(r.ensureAttempt(i)).rejects.toThrow(e),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 Q(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=Z();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=Z();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 Ke(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={...Z(),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=Z(),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 qe={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 Je(e){m(`execution attempt owner settlement recovery (${e.name})`,()=>{let t=_(e,qe);Ye(t),Xe(t)})}function Ye(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 Xe(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
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){g(`retains early provider completion evidence through takeover until later settlement closes the operation`,async()=>{let t=e(),n=b(),r=await w(t.repository,n),i=a({summary:`provider confirmed allocation cleanup before owner settlement`});h(await t.repository.completeProviderOperation({claim:r,evidence:i})).toEqual({kind:`evidence-recorded`}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({...r,completionEvidence:i});let o=await t.peer.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`early-proof-remediator`,observedAt:new Date(Date.parse(r.leaseExpiresAt)+1).toISOString(),leaseExpiresAt:new Date(Date.parse(r.leaseExpiresAt)+6e4).toISOString()});if(o.kind!==`claimed`)throw Error(`Expected takeover, got '${o.kind}'`);h(await t.repository.completeProviderOperation({claim:r,evidence:a()})).toEqual({kind:`stale`}),h(await t.peer.completeProviderOperation({claim:o.claim,evidence:a()})).toEqual({kind:`evidence-recorded`}),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({...o.claim,completionEvidence:i}),h(await t.repository.recovery.listOpenProviderOperations({observedAt:new Date(Date.parse(o.claim.leaseExpiresAt)+1).toISOString(),limit:1e4})).toContainEqual({attempt:h.objectContaining({executionAttemptId:n.executionAttemptId,settlementKind:null}),operation:h.objectContaining({completionEvidence:i})});let s=t.repository.canonicalizeOutcome(c(n.executionId));h(await t.repository.commitOutcome({...n,result:s})).toEqual({kind:`accepted`,outcome:s.outcome,text:s.text,controlObservation:{controlRevision:0,cancellation:null}}),h(await t.peer.recovery.getRecoverableAttempts(n.executionId)).toEqual([]),h(await t.peer.completeProviderOperation({claim:o.claim,evidence:i})).toEqual({kind:`already-completed`}),h((await t.repository.recovery.listOpenProviderOperations({observedAt:new Date(Date.parse(o.claim.leaseExpiresAt)+1).toISOString(),limit:1e4})).some(({attempt:e})=>e.executionAttemptId===n.executionAttemptId)).toBe(!1),h(await t.repository.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`too-late-remediator`,observedAt:new Date(Date.parse(o.claim.leaseExpiresAt)+1).toISOString(),leaseExpiresAt:new Date(Date.parse(o.claim.leaseExpiresAt)+6e4).toISOString()})).toEqual({kind:`resolved`})}),g(`lists pre-allocation, settled, and superseded provider obligations independently of attempt activity`,async()=>{let t=e(),n=b(),r=b(),a=b(),o=await x(t.repository,n),s=await w(t.repository,r),l=await x(t.repository,a),u=t.repository.canonicalizeOutcome(c(r.executionId));h(await t.repository.commitOutcome({...r,result:u})).toMatchObject({kind:`accepted`}),await t.peer.createAttempt({executionId:a.executionId,executionAttemptId:`${a.executionAttemptId}-replacement`,instruction:i(),bootstrapTimeoutMs:y});let d=new Date(Math.max(Date.parse(o.leaseExpiresAt),Date.parse(s.leaseExpiresAt),Date.parse(l.leaseExpiresAt))+1).toISOString(),f=(await t.repository.recovery.listOpenProviderOperations({observedAt:d,limit:1e4})).filter(({attempt:e})=>[n.executionAttemptId,r.executionAttemptId,a.executionAttemptId].includes(e.executionAttemptId));h(f).toHaveLength(3),h(f.map(({attempt:e})=>e.executionAttemptId).sort()).toEqual([n.executionAttemptId,r.executionAttemptId,a.executionAttemptId].sort()),h(f.find(({attempt:e})=>e.executionAttemptId===n.executionAttemptId)?.attempt).toMatchObject({status:`provisioning`,settlementKind:null}),h(f.find(({attempt:e})=>e.executionAttemptId===r.executionAttemptId)?.attempt).toMatchObject({status:`settled`,settlementKind:`outcome`}),h(f.find(({attempt:e})=>e.executionAttemptId===a.executionAttemptId)?.attempt).toMatchObject({status:`provisioning`,operationStartGate:`closed`})}),g(`filters live leases before applying the bound and rejects invalid operation-query bounds`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=new Date(Date.parse(r.leaseExpiresAt)-1).toISOString(),a=await t.repository.recovery.listOpenProviderOperations({observedAt:i,limit:1e4});h(a.some(({attempt:e})=>e.executionAttemptId===n.executionAttemptId)).toBe(!1),h(await t.peer.recovery.listOpenProviderOperations({observedAt:i,limit:1})).toEqual(a.slice(0,1));for(let e of[0,-1,.5,NaN,1/0,2**53-1+1])await h(t.repository.recovery.listOpenProviderOperations({observedAt:i,limit:e})).rejects.toThrow(RangeError)}),g(`orders open provider operations by binary attempt identifier when creation instants tie`,async()=>{let t=e(),{executionId:n}=b(),r=`2026-01-02T00:00:00.000Z`,i=[`${n}-!`,`${n}-A`,`${n}-a`,`${n}_a`];await t.seedRecoverableAttempts({executionId:n,entries:[{executionAttemptId:i[3],createdAt:r},{executionAttemptId:i[2],createdAt:r},{executionAttemptId:i[0],createdAt:r},{executionAttemptId:i[1],createdAt:r}]});for(let e of[t.repository,t.peer])h((await e.recovery.listOpenProviderOperations({observedAt:`2099-01-01T00:00:00.000Z`,limit:1e4})).filter(({attempt:e})=>e.executionId===n).map(({attempt:e})=>e.executionAttemptId)).toEqual(i)}),g(`fences an expired settled-operation claim before allowing its new owner to complete it`,async()=>{let t=e(),n=b(),r=await w(t.repository,n),i=t.repository.canonicalizeOutcome(c(n.executionId));h(await t.repository.commitOutcome({...n,result:i})).toMatchObject({kind:`accepted`});let o=await t.peer.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`provider-completion-remediator`,observedAt:new Date(Date.parse(r.leaseExpiresAt)+1).toISOString(),leaseExpiresAt:new Date(Date.parse(r.leaseExpiresAt)+6e4).toISOString()});if(o.kind!==`claimed`)throw Error(`Expected takeover, got '${o.kind}'`);h(await t.repository.completeProviderOperation({claim:r,evidence:a()})).toEqual({kind:`stale`});let s=a({summary:`replacement controller completed provider cleanup`});h(await t.peer.completeProviderOperation({claim:o.claim,evidence:s})).toEqual({kind:`completed`}),h(await t.peer.completeProviderOperation({claim:o.claim,evidence:s})).toEqual({kind:`already-completed`}),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({generation:o.claim.generation,ownerId:o.claim.ownerId,token:o.claim.token,completionEvidence:s})}),g(`does not let terminal infrastructure evidence overwrite an outcome or complete provider work`,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=t.repository.canonicalizeOutcome(c(n.executionId)),[o,s]=await Promise.all([t.repository.commitOutcome({...n,result:i}),t.peer.recordInfrastructureFailure({claim:r,executionId:n.executionId})]),l=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);o.kind===`accepted`?(h(s).toEqual({kind:`resolved`}),h(l).toMatchObject({settlementKind:`outcome`}),h(await t.peer.commitOutcome({...n,result:i})).toEqual({kind:`duplicate`,outcome:i.outcome,text:i.text,controlObservation:{controlRevision:0,cancellation:null}})):(h(o).toEqual({kind:`conflict`}),h(s).toEqual({kind:`recorded`}),h(l).toMatchObject({settlementKind:`infrastructure-failure`})),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({completionEvidence:null})}),g(`keeps terminal evidence and handoff distinct from provider completion`,async()=>{let t=e(),n=b(),r=await w(t.repository,n);h(await t.repository.recordAllocationTerminated({claim:r,evidence:a()})).toEqual({kind:`recorded`}),h(await t.repository.handoffProviderOperation({claim:r,evidence:a()})).toEqual({kind:`recorded`}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({obligation:`terminal-convergence`,ownerId:null,token:null,leaseExpiresAt:null,completionEvidence:null}),h((await t.repository.recovery.listOpenProviderOperations({observedAt:new Date().toISOString(),limit:1e4})).some(({attempt:e})=>e.executionAttemptId===n.executionAttemptId)).toBe(!0)})}function Ze(e){g(`persists cancellation and closes admission without confirming any outcome`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=await w(t,r);await t.requestCancellation({executionId:r.executionId,reason:`operator cancelled`});let o=await n.readCancellation(r.executionAttemptId);h(o).toEqual({requestKey:h.any(String),controlRevision:1,requestedAt:h.any(String),reason:`operator cancelled`}),h(Number.isFinite(Date.parse(o.requestedAt))).toBe(!0),h(await n.recovery.getAttemptWithAllocation(r.executionAttemptId)).toMatchObject({status:`allocated`,settlementKind:null,operationStartGate:`closed`}),h(await n.getProviderOperation(r.executionAttemptId)).toMatchObject({completionEvidence:null}),await t.handoffProviderOperation({claim:i,evidence:a()}),h(await n.readCancellation(r.executionAttemptId)).toEqual(o)}),g(`preserves the first request across duplicates and returns independent read values`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r),await t.requestCancellation({executionId:r.executionId});let i=await n.readCancellation(r.executionAttemptId);await n.requestCancellation({executionId:r.executionId,reason:`later reason`}),h(await t.readCancellation(r.executionAttemptId)).toEqual(i),Object.assign(i,{reason:`reader mutation`}),h(await n.readCancellation(r.executionAttemptId)).not.toHaveProperty(`reason`)}),g(`includes historical residual allocations but never another owner`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=b();await w(t,r);let a=t.canonicalizeOutcome(c(r.executionId));await t.commitOutcome({...r,result:a});let o={...r,executionAttemptId:`${r.executionAttemptId}-next`};await w(t,o),await w(t,i),await n.requestCancellation({executionId:r.executionId}),h(await t.readCancellation(r.executionAttemptId)).not.toBeNull(),h(await t.readCancellation(o.executionAttemptId)).not.toBeNull(),h(await t.readCancellation(i.executionAttemptId)).toBeNull(),h(await t.getAttemptControlState(i.executionAttemptId)).toMatchObject({operationStartGate:`open`}),h(await t.readAttemptSettlement(r)).toMatchObject({kind:`outcome`,isCurrentAttempt:!1,result:a,controlObservation:{controlRevision:0,cancellation:null}})}),g(`does not install a permanent owner-wide creation fence`,async()=>{let{repository:t,peer:n}=e(),r=b();await t.requestCancellation({executionId:r.executionId}),await n.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y}),h(await t.readCancellation(r.executionAttemptId)).toBeNull(),h(await t.getAttemptControlState(r.executionAttemptId)).toMatchObject({operationStartGate:`open`}),h(await n.readCancellation(`missing-attempt`)).toBeNull()}),g(`serializes concurrent controller requests to one immutable intent`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r),await Promise.all([t.requestCancellation({executionId:r.executionId,reason:`first controller`}),n.requestCancellation({executionId:r.executionId,reason:`second controller`})]);let i=await t.readCancellation(r.executionAttemptId);h([`first controller`,`second controller`]).toContain(i?.reason),h(await n.readCancellation(r.executionAttemptId)).toEqual(i)}),g(`refuses provider provisioning after cancellation committed before dispatch`,async()=>{let{repository:t,peer:r}=e(),a=b();await t.createAttempt({...a,instruction:i(),bootstrapTimeoutMs:y}),await r.requestCancellation({executionId:a.executionId}),h(await t.beginProvisioning(n(a.executionAttemptId,a.executionId))).toEqual({kind:`fenced`}),h(await r.getProviderOperation(a.executionAttemptId)).toBeNull()})}function Qe(e){g(`accepts exact cancellation before a runtime exists and replays the winning receipt`,async()=>{let{repository:t,peer:n}=e(),r=b();await t.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y});let a={...r,requestKey:`cancel-before-bootstrap`,reason:`operator requested stop`},o=await t.requestAttemptCancellation(a);if(h(o).toEqual({kind:`accepted`,intent:{requestKey:a.requestKey,controlRevision:1,requestedAt:h.any(String),reason:a.reason}}),o.kind!==`accepted`)throw Error(`Expected a cancellation receipt`);h(Number.isFinite(Date.parse(o.intent.requestedAt))).toBe(!0),h(await n.requestAttemptCancellation(a)).toEqual({kind:`replayed`,intent:o.intent}),h(await n.getAttemptControlState(r.executionAttemptId)).toMatchObject({runtimeGeneration:0,operationStartGate:`closed`,activeOperationId:null}),h(await n.readAttemptSettlement(r)).toMatchObject({kind:`unsettled`})}),g(`rejects conflicting reuse of the winning key but replays other keys without a second revision`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r);let i={...r,requestKey:`winning-key`,reason:`first reason`};await t.requestAttemptCancellation(i);let a=await n.readCancellation(r.executionAttemptId);h(await n.requestAttemptCancellation({...i,reason:`changed reason`})).toEqual({kind:`conflict`}),h(await n.requestAttemptCancellation({...r,requestKey:i.requestKey})).toEqual({kind:`conflict`}),h(await n.requestAttemptCancellation({...i,requestKey:`losing-key`,reason:`other reason`})).toEqual({kind:`replayed`,intent:a}),await n.requestCancellation({executionId:r.executionId,reason:`owner-wide replay`}),h(await t.readCancellation(r.executionAttemptId)).toEqual(a)}),g(`never reopens cancelled admission when an allocated runtime registers afterwards`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r),await t.requestAttemptCancellation({...r,requestKey:`cancel-before-registration`});let i=await n.readCancellation(r.executionAttemptId);h(await n.registerRuntime({...r,runtimeIncarnationId:`late-runtime`})).toEqual({kind:`registered`,runtimeGeneration:1}),h(await t.admitOperation({...r,runtimeGeneration:1,operationKind:`runtime-probe`,admissionKey:`late-readiness`})).toEqual({kind:`gate-closed`}),h(await n.getAttemptControlState(r.executionAttemptId)).toMatchObject({operationStartGate:`closed`,activeOperationId:null,runtimeReadyAt:null}),h(await n.readCancellation(r.executionAttemptId)).toEqual(i)}),g(`recovers one winning decision after concurrent requests and a lost response`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r);let i=[`controller-a`,`controller-b`].map(e=>({...r,requestKey:e,reason:e})),a=await Promise.all([t.requestAttemptCancellation(i[0]),n.requestAttemptCancellation(i[1])]);h(a.map(({kind:e})=>e).sort()).toEqual([`accepted`,`replayed`]);let o=await n.readCancellation(r.executionAttemptId);h(o).toMatchObject({controlRevision:1});for(let e of i)h(await n.requestAttemptCancellation(e)).toEqual({kind:`replayed`,intent:o});h(a).toEqual(h.arrayContaining([{kind:`accepted`,intent:o},{kind:`replayed`,intent:o}]))}),g(`snapshots request scope before yielding and returns detached receipts`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=b();await w(t,r),await w(t,i);let a={...r,requestKey:`original-key`,reason:`original reason`},o={...a},s=t.requestAttemptCancellation(a);Object.assign(a,i,{requestKey:`mutated-key`,reason:`mutated reason`});let c=await s;if(h(c).toMatchObject({kind:`accepted`,intent:{requestKey:o.requestKey,reason:o.reason,controlRevision:1}}),c.kind!==`accepted`)throw Error(`Expected a cancellation receipt`);let l=structuredClone(c.intent);Object.assign(c.intent,{requestKey:`reader-key`,reason:`reader reason`,controlRevision:99});let u=await n.requestAttemptCancellation(o);if(h(u).toEqual({kind:`replayed`,intent:l}),u.kind!==`replayed`)throw Error(`Expected cancellation replay`);Object.assign(u.intent,{controlRevision:100}),h(await t.readCancellation(r.executionAttemptId)).toEqual(l),h(await n.readCancellation(i.executionAttemptId)).toBeNull(),h(await n.getAttemptControlState(i.executionAttemptId)).toMatchObject({operationStartGate:`open`})}),g(`requires the exact owning scope without making historical cleanup depend on the current pointer`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r);let i={...r,executionAttemptId:`${r.executionAttemptId}-successor`};await w(t,i);let a={...r,requestKey:`historical-cleanup`};h(await n.requestAttemptCancellation({...a,executionId:`another-owner`})).toEqual({kind:`not-found`}),h(await n.requestAttemptCancellation({...a,executionAttemptId:`missing-attempt`})).toEqual({kind:`not-found`}),h(await t.readCancellation(r.executionAttemptId)).toBeNull(),h(await n.requestAttemptCancellation(a)).toMatchObject({kind:`accepted`,intent:{controlRevision:1}}),h(await t.readCancellation(i.executionAttemptId)).toBeNull(),h(await n.getAttemptControlState(i.executionAttemptId)).toMatchObject({operationStartGate:`open`})}),g.each([`cancel-first`,`admission-first`])(`orders cancellation and admission: %s`,async t=>{let{repository:n,peer:r}=e(),i=b(),a=await O(n,i),o=t===`admission-first`?await D(n,i,a,`workflow-run`,`first-operation`):null;await r.requestAttemptCancellation({...i,requestKey:`stop`});let s=await n.readCancellation(i.executionAttemptId);h(await n.getAttemptControlState(i.executionAttemptId)).toMatchObject({operationStartGate:`closed`,activeOperationId:o}),h(await n.readAttemptSettlement(i)).toMatchObject({kind:`unsettled`}),o!==null&&h(await n.completeOperation({executionAttemptId:i.executionAttemptId,runtimeGeneration:a,operationId:o})).toEqual({kind:`completed`}),h(await n.admitOperation({...i,runtimeGeneration:a,operationKind:`workflow-run`,admissionKey:`after-cancel`})).toEqual({kind:`gate-closed`}),h(await r.readCancellation(i.executionAttemptId)).toEqual(s)})}function $e(e){g.each([`completed`,`failed`])(`preserves raw %s after prior cancellation and freezes its receipt`,async t=>{let{repository:n,peer:r}=e(),i=b();await w(n,i);let a={...i,requestKey:`stop-before-outcome`,reason:`owner requested stop`};await n.requestAttemptCancellation(a);let o=await r.readCancellation(i.executionAttemptId),s=n.canonicalizeOutcome(c(i.executionId,t)),l={controlRevision:1,cancellation:o};h(await n.commitOutcome({...i,result:s})).toEqual({kind:`accepted`,...s,controlObservation:l}),await r.requestCancellation({executionId:i.executionId,reason:`later cleanup reason`}),h(await r.commitOutcome({...i,result:s})).toEqual({kind:`duplicate`,...s,controlObservation:l}),h(await r.readAttemptSettlement(i)).toMatchObject({kind:`outcome`,result:s,controlObservation:l}),h(await r.requestAttemptCancellation(a)).toEqual({kind:`replayed`,intent:o})}),g.each([`completed`,`failed`])(`never retroactively adds a cancellation to an earlier %s outcome`,async t=>{let{repository:n,peer:r}=e(),i=b();await w(n,i);let a=n.canonicalizeOutcome(c(i.executionId,t)),o={controlRevision:0,cancellation:null};h(await n.commitOutcome({...i,result:a})).toEqual({kind:`accepted`,...a,controlObservation:o}),h(await r.requestAttemptCancellation({...i,requestKey:`cleanup-after-outcome`})).toMatchObject({kind:`accepted`,intent:{controlRevision:1}}),h(await n.readCancellation(i.executionAttemptId)).not.toBeNull(),h(await r.commitOutcome({...i,result:a})).toEqual({kind:`duplicate`,...a,controlObservation:o}),h(await r.readAttemptSettlement(i)).toMatchObject({kind:`outcome`,result:a,controlObservation:o})}),g(`serializes concurrent cancellation and outcome to one replayable control observation`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r);let i=t.canonicalizeOutcome(c(r.executionId)),[a]=await Promise.all([t.commitOutcome({...r,result:i}),n.requestAttemptCancellation({...r,requestKey:`concurrent-stop`})]);if(a.kind!==`accepted`)throw Error(`Expected a canonical outcome`);let o=await t.readCancellation(r.executionAttemptId);h(o).toMatchObject({controlRevision:1}),h([{controlRevision:0,cancellation:null},{controlRevision:1,cancellation:o}]).toContainEqual(a.controlObservation),h(await n.commitOutcome({...r,result:i})).toEqual({...a,kind:`duplicate`}),h(await t.readAttemptSettlement(r)).toMatchObject({kind:`outcome`,result:i,controlObservation:a.controlObservation})}),g(`isolates commit, duplicate and settlement observations from caller mutation`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r),await t.requestAttemptCancellation({...r,requestKey:`stop`,reason:`immutable reason`});let i=t.canonicalizeOutcome(c(r.executionId)),a=await t.commitOutcome({...r,result:i});if(a.kind!==`accepted`)throw Error(`Expected an accepted outcome`);let o=structuredClone(a.controlObservation);Object.assign(a.controlObservation.cancellation,{reason:`mutated commit receipt`}),Object.assign(a.controlObservation,{controlRevision:99});let s=await n.commitOutcome({...r,result:i});if(h(s).toEqual({kind:`duplicate`,...i,controlObservation:o}),s.kind!==`duplicate`)throw Error(`Expected duplicate outcome`);Object.assign(s.controlObservation.cancellation,{requestKey:`mutated duplicate receipt`});let l=await t.readAttemptSettlement(r);if(h(l).toMatchObject({kind:`outcome`,controlObservation:o}),l.kind!==`outcome`)throw Error(`Expected outcome settlement`);Object.assign(l.controlObservation.cancellation,{controlRevision:100}),h(await n.readAttemptSettlement(r)).toMatchObject({kind:`outcome`,controlObservation:o}),h(await n.readCancellation(r.executionAttemptId)).toEqual(o.cancellation)}),g(`keeps runtime and supersession fences independent of accepted control revisions`,async()=>{let{repository:n,peer:r}=e(),i=b(),a=await O(n,i),o=await T(n,i,`replacement-runtime`);await r.requestAttemptCancellation({...i,requestKey:`stop-current-runtime`});let s=n.canonicalizeOutcome(c(i.executionId));await h(n.commitOutcome({...i,result:s,runtimeFence:{runtimeGeneration:a,operationId:null}})).rejects.toThrow(t),h(await r.readAttemptSettlement(i)).toMatchObject({kind:`unsettled`});let l=await n.readCancellation(i.executionAttemptId);h(l).toMatchObject({controlRevision:1}),h(await n.commitOutcome({...i,result:s,runtimeFence:{runtimeGeneration:o,operationId:null}})).toMatchObject({kind:`accepted`,controlObservation:{controlRevision:1,cancellation:l}});let u=b();await w(n,u),await r.requestAttemptCancellation({...u,requestKey:`stop-predecessor`}),await w(n,{...u,executionAttemptId:`${u.executionAttemptId}-next`}),h(await r.commitOutcome({...u,result:r.canonicalizeOutcome(c(u.executionId))})).toEqual({kind:`fenced`}),h(await r.readCancellation(u.executionAttemptId)).toMatchObject({controlRevision:1}),h(await r.readAttemptSettlement(u)).toMatchObject({kind:`unsettled`,isCurrentAttempt:!1})})}function et(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),Xe(t),Ze(t),Qe(t),$e(t)}),ue(e),de(e),fe(e),he(e),ve(e),ye(e),Le(e),qe(e)}export{et as runExecutionAttemptRepositoryContract};
|
|
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 Ze(e){g(`retains early provider completion evidence through takeover until later settlement closes the operation`,async()=>{let t=e(),n=b(),r=await w(t.repository,n),i=a({summary:`provider confirmed allocation cleanup before owner settlement`});h(await t.repository.completeProviderOperation({claim:r,evidence:i})).toEqual({kind:`evidence-recorded`}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({...r,completionEvidence:i});let o=await t.peer.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`early-proof-remediator`,observedAt:new Date(Date.parse(r.leaseExpiresAt)+1).toISOString(),leaseExpiresAt:new Date(Date.parse(r.leaseExpiresAt)+6e4).toISOString()});if(o.kind!==`claimed`)throw Error(`Expected takeover, got '${o.kind}'`);h(await t.repository.completeProviderOperation({claim:r,evidence:a()})).toEqual({kind:`stale`}),h(await t.peer.completeProviderOperation({claim:o.claim,evidence:a()})).toEqual({kind:`evidence-recorded`}),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({...o.claim,completionEvidence:i}),h(await t.repository.recovery.listOpenProviderOperations({observedAt:new Date(Date.parse(o.claim.leaseExpiresAt)+1).toISOString(),limit:1e4})).toContainEqual({attempt:h.objectContaining({executionAttemptId:n.executionAttemptId,settlementKind:null}),operation:h.objectContaining({completionEvidence:i})});let s=t.repository.canonicalizeOutcome(c(n.executionId));h(await t.repository.commitOutcome({...n,result:s})).toEqual({kind:`accepted`,outcome:s.outcome,text:s.text,controlObservation:{controlRevision:0,cancellation:null}}),h(await t.peer.recovery.getRecoverableAttempts(n.executionId)).toEqual([]),h(await t.peer.completeProviderOperation({claim:o.claim,evidence:i})).toEqual({kind:`already-completed`}),h((await t.repository.recovery.listOpenProviderOperations({observedAt:new Date(Date.parse(o.claim.leaseExpiresAt)+1).toISOString(),limit:1e4})).some(({attempt:e})=>e.executionAttemptId===n.executionAttemptId)).toBe(!1),h(await t.repository.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`too-late-remediator`,observedAt:new Date(Date.parse(o.claim.leaseExpiresAt)+1).toISOString(),leaseExpiresAt:new Date(Date.parse(o.claim.leaseExpiresAt)+6e4).toISOString()})).toEqual({kind:`resolved`})}),g(`lists pre-allocation, settled, and superseded provider obligations independently of attempt activity`,async()=>{let t=e(),n=b(),r=b(),a=b(),o=await x(t.repository,n),s=await w(t.repository,r),l=await x(t.repository,a),u=t.repository.canonicalizeOutcome(c(r.executionId));h(await t.repository.commitOutcome({...r,result:u})).toMatchObject({kind:`accepted`}),await t.peer.createAttempt({executionId:a.executionId,executionAttemptId:`${a.executionAttemptId}-replacement`,instruction:i(),bootstrapTimeoutMs:y});let d=new Date(Math.max(Date.parse(o.leaseExpiresAt),Date.parse(s.leaseExpiresAt),Date.parse(l.leaseExpiresAt))+1).toISOString(),f=(await t.repository.recovery.listOpenProviderOperations({observedAt:d,limit:1e4})).filter(({attempt:e})=>[n.executionAttemptId,r.executionAttemptId,a.executionAttemptId].includes(e.executionAttemptId));h(f).toHaveLength(3),h(f.map(({attempt:e})=>e.executionAttemptId).sort()).toEqual([n.executionAttemptId,r.executionAttemptId,a.executionAttemptId].sort()),h(f.find(({attempt:e})=>e.executionAttemptId===n.executionAttemptId)?.attempt).toMatchObject({status:`provisioning`,settlementKind:null}),h(f.find(({attempt:e})=>e.executionAttemptId===r.executionAttemptId)?.attempt).toMatchObject({status:`settled`,settlementKind:`outcome`}),h(f.find(({attempt:e})=>e.executionAttemptId===a.executionAttemptId)?.attempt).toMatchObject({status:`provisioning`,operationStartGate:`closed`})}),g(`filters live leases before applying the bound and rejects invalid operation-query bounds`,async()=>{let t=e(),n=b(),r=await x(t.repository,n),i=new Date(Date.parse(r.leaseExpiresAt)-1).toISOString(),a=await t.repository.recovery.listOpenProviderOperations({observedAt:i,limit:1e4});h(a.some(({attempt:e})=>e.executionAttemptId===n.executionAttemptId)).toBe(!1),h(await t.peer.recovery.listOpenProviderOperations({observedAt:i,limit:1})).toEqual(a.slice(0,1));for(let e of[0,-1,.5,NaN,1/0,2**53-1+1])await h(t.repository.recovery.listOpenProviderOperations({observedAt:i,limit:e})).rejects.toThrow(RangeError)}),g(`orders open provider operations by binary attempt identifier when creation instants tie`,async()=>{let t=e(),{executionId:n}=b(),r=`2026-01-02T00:00:00.000Z`,i=[`${n}-!`,`${n}-A`,`${n}-a`,`${n}_a`];await t.seedRecoverableAttempts({executionId:n,entries:[{executionAttemptId:i[3],createdAt:r},{executionAttemptId:i[2],createdAt:r},{executionAttemptId:i[0],createdAt:r},{executionAttemptId:i[1],createdAt:r}]});for(let e of[t.repository,t.peer])h((await e.recovery.listOpenProviderOperations({observedAt:`2099-01-01T00:00:00.000Z`,limit:1e4})).filter(({attempt:e})=>e.executionId===n).map(({attempt:e})=>e.executionAttemptId)).toEqual(i)}),g(`fences an expired settled-operation claim before allowing its new owner to complete it`,async()=>{let t=e(),n=b(),r=await w(t.repository,n),i=t.repository.canonicalizeOutcome(c(n.executionId));h(await t.repository.commitOutcome({...n,result:i})).toMatchObject({kind:`accepted`});let o=await t.peer.takeOverProviderOperation({executionAttemptId:n.executionAttemptId,ownerId:`provider-completion-remediator`,observedAt:new Date(Date.parse(r.leaseExpiresAt)+1).toISOString(),leaseExpiresAt:new Date(Date.parse(r.leaseExpiresAt)+6e4).toISOString()});if(o.kind!==`claimed`)throw Error(`Expected takeover, got '${o.kind}'`);h(await t.repository.completeProviderOperation({claim:r,evidence:a()})).toEqual({kind:`stale`});let s=a({summary:`replacement controller completed provider cleanup`});h(await t.peer.completeProviderOperation({claim:o.claim,evidence:s})).toEqual({kind:`completed`}),h(await t.peer.completeProviderOperation({claim:o.claim,evidence:s})).toEqual({kind:`already-completed`}),h(await t.repository.getProviderOperation(n.executionAttemptId)).toMatchObject({generation:o.claim.generation,ownerId:o.claim.ownerId,token:o.claim.token,completionEvidence:s})}),g(`does not let terminal infrastructure evidence overwrite an outcome or complete provider work`,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=t.repository.canonicalizeOutcome(c(n.executionId)),[o,s]=await Promise.all([t.repository.commitOutcome({...n,result:i}),t.peer.recordInfrastructureFailure({claim:r,executionId:n.executionId})]),l=await t.repository.recovery.getAttemptWithAllocation(n.executionAttemptId);o.kind===`accepted`?(h(s).toEqual({kind:`resolved`}),h(l).toMatchObject({settlementKind:`outcome`}),h(await t.peer.commitOutcome({...n,result:i})).toEqual({kind:`duplicate`,outcome:i.outcome,text:i.text,controlObservation:{controlRevision:0,cancellation:null}})):(h(o).toEqual({kind:`conflict`}),h(s).toEqual({kind:`recorded`}),h(l).toMatchObject({settlementKind:`infrastructure-failure`})),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({completionEvidence:null})}),g(`keeps terminal evidence and handoff distinct from provider completion`,async()=>{let t=e(),n=b(),r=await w(t.repository,n);h(await t.repository.recordAllocationTerminated({claim:r,evidence:a()})).toEqual({kind:`recorded`}),h(await t.repository.handoffProviderOperation({claim:r,evidence:a()})).toEqual({kind:`recorded`}),h(await t.peer.getProviderOperation(n.executionAttemptId)).toMatchObject({obligation:`terminal-convergence`,ownerId:null,token:null,leaseExpiresAt:null,completionEvidence:null}),h((await t.repository.recovery.listOpenProviderOperations({observedAt:new Date().toISOString(),limit:1e4})).some(({attempt:e})=>e.executionAttemptId===n.executionAttemptId)).toBe(!0)})}function Qe(e){g(`persists cancellation and closes admission without confirming any outcome`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=await w(t,r);await t.requestCancellation({executionId:r.executionId,reason:`operator cancelled`});let o=await n.readCancellation(r.executionAttemptId);h(o).toEqual({requestKey:h.any(String),controlRevision:1,requestedAt:h.any(String),reason:`operator cancelled`}),h(Number.isFinite(Date.parse(o.requestedAt))).toBe(!0),h(await n.recovery.getAttemptWithAllocation(r.executionAttemptId)).toMatchObject({status:`allocated`,settlementKind:null,operationStartGate:`closed`}),h(await n.getProviderOperation(r.executionAttemptId)).toMatchObject({completionEvidence:null}),await t.handoffProviderOperation({claim:i,evidence:a()}),h(await n.readCancellation(r.executionAttemptId)).toEqual(o)}),g(`preserves the first request across duplicates and returns independent read values`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r),await t.requestCancellation({executionId:r.executionId});let i=await n.readCancellation(r.executionAttemptId);await n.requestCancellation({executionId:r.executionId,reason:`later reason`}),h(await t.readCancellation(r.executionAttemptId)).toEqual(i),Object.assign(i,{reason:`reader mutation`}),h(await n.readCancellation(r.executionAttemptId)).not.toHaveProperty(`reason`)}),g(`includes historical residual allocations but never another owner`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=b();await w(t,r);let a=t.canonicalizeOutcome(c(r.executionId));await t.commitOutcome({...r,result:a});let o={...r,executionAttemptId:`${r.executionAttemptId}-next`};await w(t,o),await w(t,i),await n.requestCancellation({executionId:r.executionId}),h(await t.readCancellation(r.executionAttemptId)).not.toBeNull(),h(await t.readCancellation(o.executionAttemptId)).not.toBeNull(),h(await t.readCancellation(i.executionAttemptId)).toBeNull(),h(await t.getAttemptControlState(i.executionAttemptId)).toMatchObject({operationStartGate:`open`}),h(await t.readAttemptSettlement(r)).toMatchObject({kind:`outcome`,isCurrentAttempt:!1,result:a,controlObservation:{controlRevision:0,cancellation:null}})}),g(`does not install a permanent owner-wide creation fence`,async()=>{let{repository:t,peer:n}=e(),r=b();await t.requestCancellation({executionId:r.executionId}),await n.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y}),h(await t.readCancellation(r.executionAttemptId)).toBeNull(),h(await t.getAttemptControlState(r.executionAttemptId)).toMatchObject({operationStartGate:`open`}),h(await n.readCancellation(`missing-attempt`)).toBeNull()}),g(`serializes concurrent controller requests to one immutable intent`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r),await Promise.all([t.requestCancellation({executionId:r.executionId,reason:`first controller`}),n.requestCancellation({executionId:r.executionId,reason:`second controller`})]);let i=await t.readCancellation(r.executionAttemptId);h([`first controller`,`second controller`]).toContain(i?.reason),h(await n.readCancellation(r.executionAttemptId)).toEqual(i)}),g(`refuses provider provisioning after cancellation committed before dispatch`,async()=>{let{repository:t,peer:r}=e(),a=b();await t.createAttempt({...a,instruction:i(),bootstrapTimeoutMs:y}),await r.requestCancellation({executionId:a.executionId}),h(await t.beginProvisioning(n(a.executionAttemptId,a.executionId))).toEqual({kind:`fenced`}),h(await r.getProviderOperation(a.executionAttemptId)).toBeNull()})}function $e(e){g(`accepts exact cancellation before a runtime exists and replays the winning receipt`,async()=>{let{repository:t,peer:n}=e(),r=b();await t.createAttempt({...r,instruction:i(),bootstrapTimeoutMs:y});let a={...r,requestKey:`cancel-before-bootstrap`,reason:`operator requested stop`},o=await t.requestAttemptCancellation(a);if(h(o).toEqual({kind:`accepted`,intent:{requestKey:a.requestKey,controlRevision:1,requestedAt:h.any(String),reason:a.reason}}),o.kind!==`accepted`)throw Error(`Expected a cancellation receipt`);h(Number.isFinite(Date.parse(o.intent.requestedAt))).toBe(!0),h(await n.requestAttemptCancellation(a)).toEqual({kind:`replayed`,intent:o.intent}),h(await n.getAttemptControlState(r.executionAttemptId)).toMatchObject({runtimeGeneration:0,operationStartGate:`closed`,activeOperationId:null}),h(await n.readAttemptSettlement(r)).toMatchObject({kind:`unsettled`})}),g(`rejects conflicting reuse of the winning key but replays other keys without a second revision`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r);let i={...r,requestKey:`winning-key`,reason:`first reason`};await t.requestAttemptCancellation(i);let a=await n.readCancellation(r.executionAttemptId);h(await n.requestAttemptCancellation({...i,reason:`changed reason`})).toEqual({kind:`conflict`}),h(await n.requestAttemptCancellation({...r,requestKey:i.requestKey})).toEqual({kind:`conflict`}),h(await n.requestAttemptCancellation({...i,requestKey:`losing-key`,reason:`other reason`})).toEqual({kind:`replayed`,intent:a}),await n.requestCancellation({executionId:r.executionId,reason:`owner-wide replay`}),h(await t.readCancellation(r.executionAttemptId)).toEqual(a)}),g(`never reopens cancelled admission when an allocated runtime registers afterwards`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r),await t.requestAttemptCancellation({...r,requestKey:`cancel-before-registration`});let i=await n.readCancellation(r.executionAttemptId);h(await n.registerRuntime({...r,runtimeIncarnationId:`late-runtime`})).toEqual({kind:`registered`,runtimeGeneration:1}),h(await t.admitOperation({...r,runtimeGeneration:1,operationKind:`runtime-probe`,admissionKey:`late-readiness`})).toEqual({kind:`gate-closed`}),h(await n.getAttemptControlState(r.executionAttemptId)).toMatchObject({operationStartGate:`closed`,activeOperationId:null,runtimeReadyAt:null}),h(await n.readCancellation(r.executionAttemptId)).toEqual(i)}),g(`recovers one winning decision after concurrent requests and a lost response`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r);let i=[`controller-a`,`controller-b`].map(e=>({...r,requestKey:e,reason:e})),a=await Promise.all([t.requestAttemptCancellation(i[0]),n.requestAttemptCancellation(i[1])]);h(a.map(({kind:e})=>e).sort()).toEqual([`accepted`,`replayed`]);let o=await n.readCancellation(r.executionAttemptId);h(o).toMatchObject({controlRevision:1});for(let e of i)h(await n.requestAttemptCancellation(e)).toEqual({kind:`replayed`,intent:o});h(a).toEqual(h.arrayContaining([{kind:`accepted`,intent:o},{kind:`replayed`,intent:o}]))}),g(`snapshots request scope before yielding and returns detached receipts`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=b();await w(t,r),await w(t,i);let a={...r,requestKey:`original-key`,reason:`original reason`},o={...a},s=t.requestAttemptCancellation(a);Object.assign(a,i,{requestKey:`mutated-key`,reason:`mutated reason`});let c=await s;if(h(c).toMatchObject({kind:`accepted`,intent:{requestKey:o.requestKey,reason:o.reason,controlRevision:1}}),c.kind!==`accepted`)throw Error(`Expected a cancellation receipt`);let l=structuredClone(c.intent);Object.assign(c.intent,{requestKey:`reader-key`,reason:`reader reason`,controlRevision:99});let u=await n.requestAttemptCancellation(o);if(h(u).toEqual({kind:`replayed`,intent:l}),u.kind!==`replayed`)throw Error(`Expected cancellation replay`);Object.assign(u.intent,{controlRevision:100}),h(await t.readCancellation(r.executionAttemptId)).toEqual(l),h(await n.readCancellation(i.executionAttemptId)).toBeNull(),h(await n.getAttemptControlState(i.executionAttemptId)).toMatchObject({operationStartGate:`open`})}),g(`requires the exact owning scope without making historical cleanup depend on the current pointer`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r);let i={...r,executionAttemptId:`${r.executionAttemptId}-successor`};await w(t,i);let a={...r,requestKey:`historical-cleanup`};h(await n.requestAttemptCancellation({...a,executionId:`another-owner`})).toEqual({kind:`not-found`}),h(await n.requestAttemptCancellation({...a,executionAttemptId:`missing-attempt`})).toEqual({kind:`not-found`}),h(await t.readCancellation(r.executionAttemptId)).toBeNull(),h(await n.requestAttemptCancellation(a)).toMatchObject({kind:`accepted`,intent:{controlRevision:1}}),h(await t.readCancellation(i.executionAttemptId)).toBeNull(),h(await n.getAttemptControlState(i.executionAttemptId)).toMatchObject({operationStartGate:`open`})}),g.each([`cancel-first`,`admission-first`])(`orders cancellation and admission: %s`,async t=>{let{repository:n,peer:r}=e(),i=b(),a=await O(n,i),o=t===`admission-first`?await D(n,i,a,`workflow-run`,`first-operation`):null;await r.requestAttemptCancellation({...i,requestKey:`stop`});let s=await n.readCancellation(i.executionAttemptId);h(await n.getAttemptControlState(i.executionAttemptId)).toMatchObject({operationStartGate:`closed`,activeOperationId:o}),h(await n.readAttemptSettlement(i)).toMatchObject({kind:`unsettled`}),o!==null&&h(await n.completeOperation({executionAttemptId:i.executionAttemptId,runtimeGeneration:a,operationId:o})).toEqual({kind:`completed`}),h(await n.admitOperation({...i,runtimeGeneration:a,operationKind:`workflow-run`,admissionKey:`after-cancel`})).toEqual({kind:`gate-closed`}),h(await r.readCancellation(i.executionAttemptId)).toEqual(s)})}function $(e,t,n=`achieved`){return{...e,runtimeGeneration:t,runtimeIncarnationId:S,controlRevision:1,requestKey:`stop`,conclusion:{status:n,boundary:`admission-closed`,evidence:{source:`runtime`,summary:`Observed only the declared runtime boundary`,observedAt:`2026-09-10T12:00:00.000Z`}}}}function et(e){g.each([`achieved`,`unsupported`,`unconfirmed`])(`accepts a final %s report before its delivery receipt without rewriting either fact`,async t=>{let{repository:n,peer:r}=e(),i=b(),a=await O(n,i);await n.requestAttemptCancellation({...i,requestKey:`stop`});let o=$(i,a,t);h(await n.reportAttemptControl(o)).toEqual({kind:`accepted`});let{executionId:s,conclusion:c,...l}=o,u={...l,receivedAt:`2026-09-10T11:59:59.000Z`};h(await r.readAttemptCancellationControl(i)).toMatchObject({evidence:[{controlRevision:1,runtimeGeneration:a,receipt:null,report:{...l,conclusion:o.conclusion}}]}),h(await r.recordAttemptControlReceipt({executionId:s,...u})).toEqual({kind:`accepted`}),h(await r.reportAttemptControl(o)).toEqual({kind:`duplicate`}),h(await r.recordAttemptControlReceipt({executionId:s,...u})).toEqual({kind:`duplicate`}),h(await r.reportAttemptControl({...o,conclusion:{...o.conclusion,status:t===`achieved`?`unconfirmed`:`achieved`}})).toEqual({kind:`conflict`}),h(await r.recordAttemptControlReceipt({executionId:s,...u,receivedAt:`2026-09-10T12:01:00.000Z`})).toEqual({kind:`conflict`}),h(await n.readAttemptCancellationControl(i)).toMatchObject({evidence:[{receipt:u,report:{...l,conclusion:o.conclusion}}]}),h(await n.readAttemptSettlement(i)).toMatchObject({kind:`unsettled`})}),g(`retains historical-generation replay without accepting its first late fact for the new runtime`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=await O(t,r);await t.requestAttemptCancellation({...r,requestKey:`stop`});let a=$(r,i);h(await t.reportAttemptControl(a)).toEqual({kind:`accepted`});let o=await T(t,r,`replacement-runtime`),{conclusion:s,...c}=a;h(await n.recordAttemptControlReceipt({...c,receivedAt:`2026-09-10T12:00:00.000Z`})).toEqual({kind:`stale-generation`}),h(await n.reportAttemptControl(a)).toEqual({kind:`duplicate`});let l={...a,runtimeGeneration:o,runtimeIncarnationId:`replacement-runtime`};h(await n.reportAttemptControl(l)).toEqual({kind:`accepted`}),h(await t.readAttemptCancellationControl(r)).toMatchObject({control:{runtimeGeneration:o},evidence:[{runtimeGeneration:i,receipt:null,report:{runtimeIncarnationId:S}},{runtimeGeneration:o,receipt:null,report:{runtimeIncarnationId:`replacement-runtime`}}]})}),g(`keeps one final conclusion when independent controllers race to report different observations`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=await O(t,r);await t.requestAttemptCancellation({...r,requestKey:`stop`});let a=[$(r,i,`achieved`),$(r,i,`unconfirmed`)],o=await Promise.all([t.reportAttemptControl(a[0]),n.reportAttemptControl(a[1])]);h(o.map(({kind:e})=>e).sort()).toEqual([`accepted`,`conflict`]);let s=a[o[0].kind===`accepted`?0:1];h(await n.reportAttemptControl(s)).toEqual({kind:`duplicate`}),h(await t.readAttemptCancellationControl(r)).toMatchObject({evidence:[{report:{conclusion:s.conclusion}}]})}),g(`snapshots report input and detaches returned evidence from durable storage`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=await O(t,r);await t.requestAttemptCancellation({...r,requestKey:`stop`});let a=$(r,i),o=structuredClone(a),s=t.reportAttemptControl(a);Object.assign(a.conclusion.evidence,{summary:`mutated before storage yields`}),h(await s).toEqual({kind:`accepted`}),h(await n.reportAttemptControl(o)).toEqual({kind:`duplicate`});let c=await n.readAttemptCancellationControl(r);if(c?.evidence[0]?.report===null||c?.evidence[0]?.report===void 0)throw Error(`Expected persisted report`);Object.assign(c.evidence[0].report.conclusion.evidence,{summary:`mutated by reader`}),h(await t.readAttemptCancellationControl(r)).toMatchObject({evidence:[{report:{conclusion:o.conclusion}}]})}),g(`refuses mismatched owner, Cancel, runtime and operation without manufacturing evidence`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=await O(t,r),a=await D(t,r,i,`workflow-run`,`work`),o=$(r,i);h(await n.reportAttemptControl(o)).toEqual({kind:`cancel-mismatch`}),await t.requestAttemptCancellation({...r,requestKey:`stop`});let s={...o,operationId:a,conclusion:{...o.conclusion,boundary:`workload`}},c=[{change:{executionId:`wrong-owner`},kind:`not-found`},{change:{executionAttemptId:`unknown`},kind:`not-found`},{change:{requestKey:`wrong-request`},kind:`cancel-mismatch`},{change:{controlRevision:2},kind:`cancel-mismatch`},{change:{runtimeGeneration:i+1},kind:`stale-generation`},{change:{runtimeIncarnationId:`wrong-runtime`},kind:`stale-generation`},{change:{operationId:`wrong-operation`},kind:`operation-mismatch`}];for(let{change:e,kind:t}of c)if(h(await n.reportAttemptControl({...s,...e})).toEqual({kind:t}),t!==`operation-mismatch`){let{conclusion:r,operationId:i,...a}={...s,...e};h(await n.recordAttemptControlReceipt({...a,receivedAt:`2026-09-10T12:00:00.000Z`})).toEqual({kind:t})}h(await n.reportAttemptControl(o)).toEqual({kind:`operation-mismatch`}),h(await n.reportAttemptControl({...o,operationId:a})).toEqual({kind:`operation-mismatch`}),h(await n.readAttemptCancellationControl({...r,executionId:`wrong-owner`})).toBeNull(),h(await n.readAttemptCancellationControl(r)).toMatchObject({evidence:[]}),h(await n.reportAttemptControl(s)).toEqual({kind:`accepted`}),h(await t.getAttemptControlState(r.executionAttemptId)).toMatchObject({activeOperationId:a})}),g(`accepts a Setup conclusion after Preparation completed without releasing or replacing its binding`,async()=>{let{repository:t,peer:n}=e(),r=await C(t);h(await t.reportOperation(r)).toMatchObject({kind:`accepted`});let i={executionId:r.executionId,executionAttemptId:r.executionAttemptId};await t.requestAttemptCancellation({...i,requestKey:`stop`});let a=$(i,r.runtimeGeneration),o=await t.recovery.getAttemptWithAllocation(i.executionAttemptId);h(await n.reportAttemptControl({...a,operationId:r.operationId,conclusion:{...a.conclusion,boundary:`setup-process-group`}})).toEqual({kind:`accepted`}),h(await t.recovery.getAttemptWithAllocation(i.executionAttemptId)).toEqual(o)}),g(`accepts the first late report after Completed without changing outcome or its frozen control observation`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=await O(t,r),a=await D(t,r,i,`workflow-run`,`work`),o=t.canonicalizeOutcome(c(r.executionId));await t.commitOutcome({...r,result:o});let s=await t.readAttemptSettlement(r);h(s).toMatchObject({kind:`outcome`,controlObservation:{controlRevision:0,cancellation:null}}),await t.requestAttemptCancellation({...r,requestKey:`stop`});let l=$(r,i);h(await n.reportAttemptControl({...l,operationId:a,conclusion:{...l.conclusion,boundary:`workload`}})).toEqual({kind:`accepted`}),h(await n.readAttemptSettlement(r)).toEqual(s),h(await n.commitOutcome({...r,result:o})).toMatchObject({kind:`duplicate`,controlObservation:{controlRevision:0,cancellation:null}})}),g(`stores a historical Attempt report without affecting its successor or reopening admission`,async()=>{let{repository:t,peer:n}=e(),r=b(),i=await O(t,r),a=await D(t,r,i,`workflow-run`,`work`);await t.requestAttemptCancellation({...r,requestKey:`stop`});let o={...r,executionAttemptId:`${r.executionAttemptId}-next`};await w(t,o);let s=await n.recovery.getAttemptWithAllocation(o.executionAttemptId),c=$(r,i);h(await n.reportAttemptControl({...c,operationId:a,conclusion:{...c.conclusion,boundary:`workload`}})).toEqual({kind:`accepted`}),h(await n.recovery.getAttemptWithAllocation(o.executionAttemptId)).toEqual(s),h(await n.readAttemptCancellationControl(o)).toMatchObject({cancellation:null,evidence:[]}),h(await t.getAttemptControlState(r.executionAttemptId)).toMatchObject({operationStartGate:`closed`})})}function tt(e){g.each([`completed`,`failed`])(`preserves raw %s after prior cancellation and freezes its receipt`,async t=>{let{repository:n,peer:r}=e(),i=b();await w(n,i);let a={...i,requestKey:`stop-before-outcome`,reason:`owner requested stop`};await n.requestAttemptCancellation(a);let o=await r.readCancellation(i.executionAttemptId),s=n.canonicalizeOutcome(c(i.executionId,t)),l={controlRevision:1,cancellation:o};h(await n.commitOutcome({...i,result:s})).toEqual({kind:`accepted`,...s,controlObservation:l}),await r.requestCancellation({executionId:i.executionId,reason:`later cleanup reason`}),h(await r.commitOutcome({...i,result:s})).toEqual({kind:`duplicate`,...s,controlObservation:l}),h(await r.readAttemptSettlement(i)).toMatchObject({kind:`outcome`,result:s,controlObservation:l}),h(await r.requestAttemptCancellation(a)).toEqual({kind:`replayed`,intent:o})}),g.each([`completed`,`failed`])(`never retroactively adds a cancellation to an earlier %s outcome`,async t=>{let{repository:n,peer:r}=e(),i=b();await w(n,i);let a=n.canonicalizeOutcome(c(i.executionId,t)),o={controlRevision:0,cancellation:null};h(await n.commitOutcome({...i,result:a})).toEqual({kind:`accepted`,...a,controlObservation:o}),h(await r.requestAttemptCancellation({...i,requestKey:`cleanup-after-outcome`})).toMatchObject({kind:`accepted`,intent:{controlRevision:1}}),h(await n.readCancellation(i.executionAttemptId)).not.toBeNull(),h(await r.commitOutcome({...i,result:a})).toEqual({kind:`duplicate`,...a,controlObservation:o}),h(await r.readAttemptSettlement(i)).toMatchObject({kind:`outcome`,result:a,controlObservation:o})}),g(`serializes concurrent cancellation and outcome to one replayable control observation`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r);let i=t.canonicalizeOutcome(c(r.executionId)),[a]=await Promise.all([t.commitOutcome({...r,result:i}),n.requestAttemptCancellation({...r,requestKey:`concurrent-stop`})]);if(a.kind!==`accepted`)throw Error(`Expected a canonical outcome`);let o=await t.readCancellation(r.executionAttemptId);h(o).toMatchObject({controlRevision:1}),h([{controlRevision:0,cancellation:null},{controlRevision:1,cancellation:o}]).toContainEqual(a.controlObservation),h(await n.commitOutcome({...r,result:i})).toEqual({...a,kind:`duplicate`}),h(await t.readAttemptSettlement(r)).toMatchObject({kind:`outcome`,result:i,controlObservation:a.controlObservation})}),g(`isolates commit, duplicate and settlement observations from caller mutation`,async()=>{let{repository:t,peer:n}=e(),r=b();await w(t,r),await t.requestAttemptCancellation({...r,requestKey:`stop`,reason:`immutable reason`});let i=t.canonicalizeOutcome(c(r.executionId)),a=await t.commitOutcome({...r,result:i});if(a.kind!==`accepted`)throw Error(`Expected an accepted outcome`);let o=structuredClone(a.controlObservation);Object.assign(a.controlObservation.cancellation,{reason:`mutated commit receipt`}),Object.assign(a.controlObservation,{controlRevision:99});let s=await n.commitOutcome({...r,result:i});if(h(s).toEqual({kind:`duplicate`,...i,controlObservation:o}),s.kind!==`duplicate`)throw Error(`Expected duplicate outcome`);Object.assign(s.controlObservation.cancellation,{requestKey:`mutated duplicate receipt`});let l=await t.readAttemptSettlement(r);if(h(l).toMatchObject({kind:`outcome`,controlObservation:o}),l.kind!==`outcome`)throw Error(`Expected outcome settlement`);Object.assign(l.controlObservation.cancellation,{controlRevision:100}),h(await n.readAttemptSettlement(r)).toMatchObject({kind:`outcome`,controlObservation:o}),h(await n.readCancellation(r.executionAttemptId)).toEqual(o.cancellation)}),g(`keeps runtime and supersession fences independent of accepted control revisions`,async()=>{let{repository:n,peer:r}=e(),i=b(),a=await O(n,i),o=await T(n,i,`replacement-runtime`);await r.requestAttemptCancellation({...i,requestKey:`stop-current-runtime`});let s=n.canonicalizeOutcome(c(i.executionId));await h(n.commitOutcome({...i,result:s,runtimeFence:{runtimeGeneration:a,operationId:null}})).rejects.toThrow(t),h(await r.readAttemptSettlement(i)).toMatchObject({kind:`unsettled`});let l=await n.readCancellation(i.executionAttemptId);h(l).toMatchObject({controlRevision:1}),h(await n.commitOutcome({...i,result:s,runtimeFence:{runtimeGeneration:o,operationId:null}})).toMatchObject({kind:`accepted`,controlObservation:{controlRevision:1,cancellation:l}});let u=b();await w(n,u),await r.requestAttemptCancellation({...u,requestKey:`stop-predecessor`}),await w(n,{...u,executionAttemptId:`${u.executionAttemptId}-next`}),h(await r.commitOutcome({...u,result:r.canonicalizeOutcome(c(u.executionId))})).toEqual({kind:`fenced`}),h(await r.readCancellation(u.executionAttemptId)).toMatchObject({controlRevision:1}),h(await r.readAttemptSettlement(u)).toMatchObject({kind:`unsettled`,isCurrentAttempt:!1})})}function nt(e){m(`execution attempt port parity (${e.name})`,()=>{let t=_(e,o);k(t),A(t),re(t),ie(t),ae(t),oe(t),ce(t),M(t),N(t),F(t),V(t),xe(t),Se(t),Ee(t),ke(t),je(t),Me(t),Ne(t),Pe(t),Fe(t),ze(t),Be(t),Ve(t),He(t),Ue(t),Ze(t),Qe(t),$e(t),et(t),tt(t)}),de(e),fe(e),pe(e),ge(e),ye(e),be(e),Re(e),Je(e)}export{nt as runExecutionAttemptRepositoryContract};
|