@desplega.ai/agent-swarm 2.9.1 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/dist/acp-adapter-bht22g3k.js +16 -0
  2. package/dist/{acp-targets-ny75x1qy.js → acp-targets-arrwv4f0.js} +6 -6
  3. package/dist/{actions-b9qgrmeq.js → actions-y0d2n1c2.js} +49 -28
  4. package/dist/{agent-fs-provision-b5dhdsbd.js → agent-fs-provision-tpj7sktd.js} +4 -4
  5. package/dist/{amp-adapter-vtax2c9s.js → amp-adapter-vmmnmw8d.js} +1 -1
  6. package/dist/{anthropic-messages-r5xf5hqw.js → anthropic-messages-zdca3gv1.js} +13 -13
  7. package/dist/{app-g2z15hax.js → app-wb7w45dq.js} +3 -3
  8. package/dist/{approval-notifications-yt13wp8r.js → approval-notifications-7mqr6vbd.js} +5 -5
  9. package/dist/{assistant-2cgfxsgk.js → assistant-gf60454p.js} +19 -19
  10. package/dist/{boot-args-schema-3gwy0f60.js → boot-args-schema-qxmd59sr.js} +1 -1
  11. package/dist/{boot-reembed-mywmyp4s.js → boot-reembed-5tmeskj2.js} +1 -1
  12. package/dist/{boot-reembed-92g7s5zp.js → boot-reembed-wb44vc3s.js} +1 -1
  13. package/dist/boot-scrub-sweep-25bxhnw4.js +9 -0
  14. package/dist/{boot-seeds-ce7rvgq1.js → boot-seeds-nj9za0vk.js} +4 -4
  15. package/dist/{claude-adapter-3m4q7735.js → claude-adapter-d3krpdyb.js} +5 -5
  16. package/dist/{claude-managed-setup-c217draw.js → claude-managed-setup-7y4pwd81.js} +1 -1
  17. package/dist/{claude-sdk-session-7fbqm51z.js → claude-sdk-session-d138zy0e.js} +5 -5
  18. package/dist/{cli-tvc4jag9.js → cli-01k6wpr9.js} +3 -3
  19. package/dist/{cli-2xs8tsf7.js → cli-124ntmf0.js} +42 -36
  20. package/dist/{cli-jm0hvmz2.js → cli-2rnd5j3t.js} +1 -1
  21. package/dist/{cli-32djehja.js → cli-2spnz7ye.js} +8 -8
  22. package/dist/{cli-2dq9yv8p.js → cli-2v2zdm0a.js} +1 -1
  23. package/dist/{cli-fkef327x.js → cli-3caf7pmg.js} +2 -2
  24. package/dist/{cli-mw620q3n.js → cli-3et6fmfe.js} +1 -1
  25. package/dist/{cli-h9yqfzx9.js → cli-3f8zbtqa.js} +3 -3
  26. package/dist/{cli-mhapr559.js → cli-43evxwj4.js} +1 -1
  27. package/dist/{cli-pyjn0qhk.js → cli-539h29es.js} +138 -21
  28. package/dist/{cli-bnqncekd.js → cli-5qhfv9rw.js} +2 -2
  29. package/dist/{cli-p4kckx1z.js → cli-6037prsx.js} +6 -6
  30. package/dist/{cli-zr6qy15y.js → cli-6cwr32fe.js} +17 -17
  31. package/dist/{cli-1jykg0py.js → cli-7r162fxe.js} +22 -15
  32. package/dist/{cli-sn650d7x.js → cli-8st34zhr.js} +20 -10
  33. package/dist/{cli-rq5rpv6k.js → cli-91pkxres.js} +1 -1
  34. package/dist/{cli-m7zvgt57.js → cli-9fjr27ez.js} +10 -10
  35. package/dist/{cli-f8x9drqr.js → cli-aw83sr40.js} +19 -5
  36. package/dist/{cli-jkw6ptfw.js → cli-cc93xzes.js} +5 -5
  37. package/dist/{cli-gfy38pvt.js → cli-fcfbct2j.js} +5 -5
  38. package/dist/{cli-nafvvsp8.js → cli-fq2rr3jb.js} +5 -5
  39. package/dist/{boot-scrub-sweep-7dkdzqxx.js → cli-had1p04a.js} +8 -9
  40. package/dist/{cli-bg63qmsx.js → cli-j6te8keb.js} +4 -4
  41. package/dist/{cli-br0924pw.js → cli-jrbq4djp.js} +1 -1
  42. package/dist/{cli-kxx4k2jw.js → cli-k3q2va86.js} +2 -2
  43. package/dist/{cli-jaw5v1sy.js → cli-k5yewqgd.js} +3 -3
  44. package/dist/cli-kbtzfrxj.js +404 -0
  45. package/dist/{cli-td9tb872.js → cli-m9cvf7vs.js} +7 -7
  46. package/dist/{cli-f3jyzq4g.js → cli-md50mj0r.js} +2 -2
  47. package/dist/{cli-xag7btpe.js → cli-mk7c5ac4.js} +1 -1
  48. package/dist/cli-mys27d03.js +321 -0
  49. package/dist/{cli-nbt14he0.js → cli-nstkanmx.js} +5 -5
  50. package/dist/{cli-wn13hhdt.js → cli-nv4xsvmk.js} +4 -4
  51. package/dist/{cli-vyff45ve.js → cli-p0c3vtch.js} +2 -2
  52. package/dist/{cli-2czxfnvj.js → cli-p0n7b5rz.js} +662 -93
  53. package/dist/{cli-j7svy295.js → cli-q5srsxq2.js} +12 -12
  54. package/dist/{cli-vt89089n.js → cli-qrta34nb.js} +4 -4
  55. package/dist/{cli-ysvspf5e.js → cli-qx4f057j.js} +2 -2
  56. package/dist/{cli-zh0e5x7p.js → cli-s1khw52h.js} +11 -11
  57. package/dist/{cli-mkwkwq81.js → cli-s1zqk1aj.js} +18 -11
  58. package/dist/{cli-f9gz2vyj.js → cli-sb4426be.js} +7 -7
  59. package/dist/{cli-dgs10ttj.js → cli-th1dkc2v.js} +1 -1
  60. package/dist/{cli-3j873zxq.js → cli-tr27kwyg.js} +2 -2
  61. package/dist/{cli-6945ywhr.js → cli-tvgqesec.js} +6 -4
  62. package/dist/{cli-fjggej24.js → cli-v46zsvqk.js} +1 -1
  63. package/dist/{cli-67mwzr35.js → cli-v8z0yga9.js} +4 -4
  64. package/dist/{cli-pb2ay3sh.js → cli-vfqvrd82.js} +5 -5
  65. package/dist/{cli-fh97xn30.js → cli-vq2eg24x.js} +2 -2
  66. package/dist/{cli-v57d7fmm.js → cli-vsw91x06.js} +23 -22
  67. package/dist/{cli-2yjj3e31.js → cli-w1q68d8x.js} +9 -7
  68. package/dist/{cli-y2ewxhth.js → cli-wafmk3fn.js} +10 -10
  69. package/dist/{cli-ctx0b85j.js → cli-wwp1bd3n.js} +257 -101
  70. package/dist/{cli-bkjdknnp.js → cli-y4ccxtz5.js} +37 -5
  71. package/dist/{cli-w4n323t3.js → cli-y8p78ekx.js} +7 -7
  72. package/dist/{cli-8zh9nrew.js → cli-z0m452jr.js} +1 -1
  73. package/dist/{cli-mjw0yf82.js → cli-zeh2mhkg.js} +1 -1
  74. package/dist/{cli-jwampxxq.js → cli-zk7v5s89.js} +2 -2
  75. package/dist/cli.js +16 -16
  76. package/dist/{cloudflare-workers-ai-system-one-9y1zx3pt.js → cloudflare-workers-ai-system-one-4aysy6rh.js} +2 -2
  77. package/dist/{codex-adapter-n656pvb8.js → codex-adapter-exfdbj73.js} +4 -4
  78. package/dist/{codex-session-runner-p0fbv5y9.js → codex-session-runner-xhznc4g3.js} +4 -4
  79. package/dist/{commands-gwea8z5p.js → commands-d8g349v4.js} +3 -3
  80. package/dist/{controller-t67c3grh.js → controller-mwgdmb8y.js} +3 -3
  81. package/dist/{controllers-connect-ks155r0h.js → controllers-connect-5v7qx04j.js} +19 -19
  82. package/dist/core-sxy4epp2.js +38 -0
  83. package/dist/{cursor-adapter-ygwrtmkv.js → cursor-adapter-p2q5h35d.js} +1 -1
  84. package/dist/{db-rb2xqdb1.js → db-qpganbeb.js} +3 -3
  85. package/dist/{db-kpmx06s9.js → db-wcw0b2j8.js} +2 -2
  86. package/dist/{dispatcher-31sm0ej2.js → dispatcher-8d8s49yz.js} +17 -17
  87. package/dist/{dsh-adapter-qyxh0w31.js → dsh-adapter-me0twn13.js} +1 -1
  88. package/dist/{easter-egg-3d-00wjscn6.js → easter-egg-3d-wv7w5ty6.js} +1 -1
  89. package/dist/{embedding-space-qhw4g68n.js → embedding-space-e48xchqa.js} +6 -6
  90. package/dist/{embeddings-zdv9ke6x.js → embeddings-tgq2afbq.js} +1 -1
  91. package/dist/{execute-zna8wwr7.js → execute-8rhwrk7f.js} +1 -1
  92. package/dist/{external-channel-1ac6t56s.js → external-channel-8bt3j2pm.js} +2 -2
  93. package/dist/{fx-adapter-sk7n0fzc.js → fx-adapter-adtdb3jb.js} +8 -8
  94. package/dist/{grok-adapter-sjbcm5ew.js → grok-adapter-accnn9km.js} +8 -8
  95. package/dist/handlers-1x77561e.js +35 -0
  96. package/dist/{heartbeat-2f6z4kdx.js → heartbeat-x0056ra5.js} +20 -20
  97. package/dist/{hook-w1skzaqc.js → hook-a7vmn2st.js} +4 -4
  98. package/dist/{hook-8y0gvtp1.js → hook-mrd2ayxv.js} +5 -5
  99. package/dist/{http-wghxvpef.js → http-ym9c5svp.js} +676 -273
  100. package/dist/{index-s71ez27v.js → index-01ns1pkw.js} +1 -1
  101. package/dist/index-48qzcqzj.js +35 -0
  102. package/dist/{index-9zkchs9t.js → index-ny60jcat.js} +186 -14
  103. package/dist/{index-rv89fvzf.js → index-p46tvwtx.js} +21 -21
  104. package/dist/index-rkvaambe.js +36 -0
  105. package/dist/{index-8zn8nxn5.js → index-x6azjwm8.js} +1 -1
  106. package/dist/{index-25pvya7q.js → index-xj1mq27m.js} +17 -17
  107. package/dist/k8s-m56sw868.js +217 -0
  108. package/dist/{keepalive-sh02349h.js → keepalive-7yxg8z4c.js} +3 -3
  109. package/dist/lead-enzn86bz.js +74 -0
  110. package/dist/{maintenance-yj0dcjja.js → maintenance-6tefxmk1.js} +1 -1
  111. package/dist/{oauth-refresh-sweep-d9xedk66.js → oauth-refresh-sweep-70cavc3a.js} +2 -2
  112. package/dist/{onboard-dpgjn03r.js → onboard-fja65z08.js} +5 -5
  113. package/dist/{openai-decisions-q3hh60wr.js → openai-decisions-ytp6w6xh.js} +1 -1
  114. package/dist/{opencode-adapter-2d31cpjc.js → opencode-adapter-hakkm7yh.js} +5 -5
  115. package/dist/{otel-impl-1skarpfq.js → otel-impl-7zhnt6gj.js} +1 -1
  116. package/dist/{pending-bfmxtx0g.js → pending-h01yzpx4.js} +18 -18
  117. package/dist/{pi-mono-adapter-gvppnasy.js → pi-mono-adapter-f52hz743.js} +6 -6
  118. package/dist/{pricing-refresh-c6b325mk.js → pricing-refresh-fzxvk2zf.js} +2 -2
  119. package/dist/{rbac-roles-h80qbdbs.js → rbac-roles-9v6vhgbs.js} +3 -3
  120. package/dist/{rbac-roles-zfcx68tx.js → rbac-roles-hfgh8sba.js} +2 -2
  121. package/dist/{render-v2-nx20t3rb.js → render-v2-1rgspxzf.js} +3 -3
  122. package/dist/{resume-5ep8agan.js → resume-tqy61x24.js} +7 -7
  123. package/dist/{runtime-r3pj4mce.js → runtime-exkxyx5f.js} +1 -1
  124. package/dist/{session-access-n7p3m15b.js → session-access-3act7vt4.js} +4 -4
  125. package/dist/{session-source-backfill-v8mt0zwn.js → session-source-backfill-82qe7fqq.js} +2 -2
  126. package/dist/{setup-z1psaqhe.js → setup-ry1vfdef.js} +1 -1
  127. package/dist/thread-buffer-3x93yexa.js +38 -0
  128. package/dist/{typesafe-system-one-f2en2knd.js → typesafe-system-one-vcfj2ak8.js} +2 -2
  129. package/dist/user-merge-jobs-bx6bf7db.js +22 -0
  130. package/dist/{virtual-modules-rrbjdpxn.js → virtual-modules-s0rjzcqq.js} +3 -3
  131. package/dist/{work-objects-4aghh73z.js → work-objects-z2e5tv03.js} +20 -20
  132. package/dist/{worker-follow-up-166zmex1.js → worker-follow-up-y3xeg89w.js} +17 -17
  133. package/dist/worker-zfcv2wbf.js +74 -0
  134. package/openapi.json +1630 -388
  135. package/package.json +3 -3
  136. package/src/be/boot-seeds.ts +7 -1
  137. package/src/be/db/model-groups.ts +238 -0
  138. package/src/be/db/model-profiles.ts +26 -8
  139. package/src/be/db/session-costs.ts +8 -2
  140. package/src/be/db/tasks/read.ts +3 -2
  141. package/src/be/db/tasks/write.ts +2 -1
  142. package/src/be/db/user-references.ts +75 -0
  143. package/src/be/db/users/references.ts +185 -0
  144. package/src/be/db-client.ts +70 -19
  145. package/src/be/db.ts +32 -57
  146. package/src/be/key-window-usage.ts +1 -0
  147. package/src/be/memory/demotion-evidence.ts +34 -0
  148. package/src/be/memory/reranker.ts +34 -12
  149. package/src/be/memory/review-recall-filter.ts +83 -0
  150. package/src/be/memory/search-candidates.ts +19 -6
  151. package/src/be/memory/types.ts +11 -0
  152. package/src/be/migrations/312_task_ui_action_runs_repeatable.sql +6 -0
  153. package/src/be/migrations/314_model_groups.sql +85 -0
  154. package/src/be/migrations/318_superseded_workflow_cut_backfill.sql +22 -0
  155. package/src/be/migrations/319_user_fk_indexes.sql +153 -0
  156. package/src/be/migrations/320_session_costs_kind.sql +4 -0
  157. package/src/be/migrations/321_user_merge_jobs.sql +52 -0
  158. package/src/be/pricing-normalize.ts +2 -0
  159. package/src/be/rbac-roles.ts +6 -4
  160. package/src/be/runtime-pools/db.ts +20 -5
  161. package/src/be/runtime-pools/supervisor.ts +15 -1
  162. package/src/be/scripts/db.ts +11 -0
  163. package/src/be/scripts/typecheck.ts +2 -0
  164. package/src/be/seed-model-groups.ts +86 -0
  165. package/src/be/seed-model-profiles.ts +20 -13
  166. package/src/be/seed-scripts/catalog/dreaming-gather.ts +165 -1
  167. package/src/be/swarm-config-guard.ts +34 -0
  168. package/src/be/task-ui-spec.ts +102 -1
  169. package/src/be/user-merge-jobs.ts +564 -0
  170. package/src/be/users.ts +41 -23
  171. package/src/commands/onboard/agent-fs-version.ts +1 -1
  172. package/src/commands/onboard/compose-generator.ts +1 -1
  173. package/src/commands/onboard/env-generator.ts +1 -1
  174. package/src/commands/provider-credentials.ts +1 -1
  175. package/src/extensions/contract-types.generated.ts +1 -1
  176. package/src/extensions/contract.ts +15 -0
  177. package/src/extensions/dispatcher.ts +14 -4
  178. package/src/github/handlers.ts +57 -0
  179. package/src/github/types.ts +4 -0
  180. package/src/http/all-routes.ts +2 -0
  181. package/src/http/approval-requests.ts +5 -1
  182. package/src/http/auth.ts +3 -1
  183. package/src/http/config.ts +34 -1
  184. package/src/http/index.ts +13 -0
  185. package/src/http/memory.ts +19 -6
  186. package/src/http/model-groups.ts +277 -0
  187. package/src/http/model-profiles.ts +30 -13
  188. package/src/http/tasks.ts +41 -6
  189. package/src/http/tool-hooks.ts +140 -0
  190. package/src/http/users.ts +142 -19
  191. package/src/http/workflows.ts +19 -1
  192. package/src/integrations/chat-sdk/inbound.ts +8 -2
  193. package/src/integrations/chat-sdk/limits.ts +8 -3
  194. package/src/providers/acp-targets.ts +2 -2
  195. package/src/providers/amp-adapter.ts +1 -1
  196. package/src/providers/pricing-sources.md +9 -0
  197. package/src/rbac/legacy-policy.ts +1 -0
  198. package/src/rbac/permissions.ts +5 -0
  199. package/src/runtime-providers/index.ts +7 -5
  200. package/src/runtime-providers/k8s.ts +250 -0
  201. package/src/scripts-runtime/types/stdlib.d.ts +2 -0
  202. package/src/scripts-runtime/types/swarm-extension.d.ts +16 -1
  203. package/src/scripts-runtime/types/swarm-sdk.d.ts +2 -0
  204. package/src/slack/actions.ts +33 -10
  205. package/src/slack/blocks.ts +23 -2
  206. package/src/slack/render-v2.ts +47 -0
  207. package/src/tests/acp-adapter.test.ts +26 -0
  208. package/src/tests/chat-sdk-relay.test.ts +21 -1
  209. package/src/tests/check-pr-body.test.ts +43 -0
  210. package/src/tests/credential-check.test.ts +14 -6
  211. package/src/tests/db-client.test.ts +146 -0
  212. package/src/tests/deploy-guard.test.ts +7 -7
  213. package/src/tests/deploy-select.test.ts +83 -0
  214. package/src/tests/dreaming-gather-corrections.test.ts +467 -0
  215. package/src/tests/event-loop-lag.test.ts +9 -7
  216. package/src/tests/fixtures/extensions/native-tool-recorder/hooks.ts +26 -0
  217. package/src/tests/fixtures/extensions/native-tool-recorder/manifest.json +10 -0
  218. package/src/tests/fixtures/onboard/content.compose.yml.txt +1 -1
  219. package/src/tests/fixtures/onboard/content.env.txt +1 -1
  220. package/src/tests/fixtures/onboard/dev.compose.yml.txt +1 -1
  221. package/src/tests/fixtures/onboard/dev.env.txt +1 -1
  222. package/src/tests/fixtures/onboard/full-all.compose.yml.txt +1 -1
  223. package/src/tests/fixtures/onboard/full-all.env.txt +1 -1
  224. package/src/tests/fixtures/onboard/full.compose.yml.txt +1 -1
  225. package/src/tests/fixtures/onboard/full.env.txt +1 -1
  226. package/src/tests/fixtures/onboard/research.compose.yml.txt +1 -1
  227. package/src/tests/fixtures/onboard/research.env.txt +1 -1
  228. package/src/tests/fixtures/onboard/solo.compose.yml.txt +1 -1
  229. package/src/tests/fixtures/onboard/solo.env.txt +1 -1
  230. package/src/tests/github-event-filter.test.ts +8 -0
  231. package/src/tests/github-handlers-inline-comments.test.ts +2 -0
  232. package/src/tests/github-handlers-reactions.test.ts +4 -0
  233. package/src/tests/github-handlers.test.ts +3 -0
  234. package/src/tests/github-sender-trust.test.ts +223 -0
  235. package/src/tests/http-users.test.ts +142 -41
  236. package/src/tests/k8s-pool-smoke.test.ts +190 -0
  237. package/src/tests/key-window-usage.test.ts +15 -0
  238. package/src/tests/memory-rater-store.test.ts +35 -1
  239. package/src/tests/memory-reranker.test.ts +39 -4
  240. package/src/tests/memory-review-recall-filter.test.ts +205 -0
  241. package/src/tests/migration-318-superseded-workflow-cut-backfill.test.ts +74 -0
  242. package/src/tests/model-groups-api.test.ts +415 -0
  243. package/src/tests/model-profiles-api.test.ts +1 -0
  244. package/src/tests/operator-granted-credentials.test.ts +7 -2
  245. package/src/tests/operator-granted-role-wire.test.ts +2 -1
  246. package/src/tests/rbac-engine.test.ts +1 -0
  247. package/src/tests/runtime-k8s-pools.test.ts +142 -0
  248. package/src/tests/runtime-pools-db.test.ts +42 -2
  249. package/src/tests/runtime-pools-http.test.ts +47 -2
  250. package/src/tests/runtime-provider-registration.test.ts +5 -14
  251. package/src/tests/runtime-providers-k8s.test.ts +303 -0
  252. package/src/tests/script-connections.test.ts +13 -1
  253. package/src/tests/short-id.test.ts +23 -0
  254. package/src/tests/slack-blocks.test.ts +69 -0
  255. package/src/tests/slack-render-v2.test.ts +54 -0
  256. package/src/tests/spec-base-url.test.ts +13 -1
  257. package/src/tests/system-one-decide-session-cost.test.ts +196 -0
  258. package/src/tests/task-ui-action-route.test.ts +59 -1
  259. package/src/tests/task-ui-script-actions.test.ts +517 -0
  260. package/src/tests/tool-hooks-http.test.ts +187 -0
  261. package/src/tests/ui-spec-script-actions-config.test.ts +196 -0
  262. package/src/tests/user-delete-perf.test.ts +321 -0
  263. package/src/tests/user-merge-jobs.test.ts +680 -0
  264. package/src/tests/vcs-provider.test.ts +25 -5
  265. package/src/tests/vendored-openapi.test.ts +13 -1
  266. package/src/tests/workflow-agent-task-retry.test.ts +62 -0
  267. package/src/tests/workflow-foreach-supersede-retry.test.ts +10 -0
  268. package/src/tests/workflow-http-v2.test.ts +27 -0
  269. package/src/tests/workflow-replay.test.ts +10 -1
  270. package/src/tests/workflow-triggers-v2.test.ts +128 -0
  271. package/src/tests/workflow-wait-event.test.ts +109 -1
  272. package/src/tools/memory-search.ts +14 -3
  273. package/src/tools/store-progress.ts +26 -26
  274. package/src/tools/swarm-config/delete-config.ts +12 -1
  275. package/src/tools/swarm-config/set-config.ts +8 -0
  276. package/src/tools/system-one-decide.ts +113 -3
  277. package/src/tools/utils.ts +4 -1
  278. package/src/tools/workflows/create-workflow.ts +2 -0
  279. package/src/tools/workflows/update-workflow.ts +3 -1
  280. package/src/types.ts +86 -2
  281. package/src/ui-spec/actions.ts +30 -4
  282. package/src/ui-spec/schema.ts +38 -0
  283. package/src/ui-spec/script-actions.ts +340 -0
  284. package/src/ui-spec/script-allowlist.ts +48 -0
  285. package/src/utils/short-id.ts +20 -14
  286. package/src/utils/task-ui-spec.ts +16 -4
  287. package/src/vcs/index.ts +12 -2
  288. package/src/workflows/executors/system-one-decision.ts +2 -2
  289. package/src/workflows/resume.ts +3 -2
  290. package/src/workflows/task-step-routing.ts +30 -10
  291. package/src/workflows/triggers.ts +35 -3
  292. package/templates/extensions/manifest.schema.json +13 -0
  293. package/templates/skills/swarm-docs/content.md +2 -0
  294. package/templates/skills/ui-spec/content.md +7 -1
  295. package/templates/workflows/dreaming/content.md +1 -1
  296. package/dist/acp-adapter-g909b5hw.js +0 -16
  297. package/dist/cli-b91nz213.js +0 -93
  298. package/dist/handlers-yzy0c87x.js +0 -35
  299. package/dist/index-2t4859r5.js +0 -35
  300. package/dist/index-cxca2t8y.js +0 -36
  301. package/dist/lead-gk4h5eg7.js +0 -74
  302. package/dist/thread-buffer-a1re2r9r.js +0 -38
  303. package/dist/worker-3dyyb8ev.js +0 -74
  304. package/dist/{azure-openai-responses-590s1eea.js → azure-openai-responses-b3y7fz36.js} +8 -8
  305. package/dist/{cli-m7c2380k.js → cli-3aaeb78m.js} +4 -4
  306. package/dist/{cli-g0vv9dg4.js → cli-8y43jx2r.js} +8 -8
  307. package/dist/{cli-m0cy2vyf.js → cli-k6nejceb.js} +4 -4
  308. package/dist/{google-generative-ai-maq6c9bf.js → google-generative-ai-bh0djqjp.js} +4 -4
  309. package/dist/{google-vertex-2jgsw2nb.js → google-vertex-prjbw8dj.js} +8 -8
  310. package/dist/{mistral-conversations-0c30em7t.js → mistral-conversations-tm2vd4gc.js} +8 -8
  311. package/dist/{node-dqm4xgxw.js → node-2wfcey7d.js} +0 -0
  312. package/dist/{openai-codex-responses-bkcd8pjj.js → openai-codex-responses-sxjv60xx.js} +4 -4
  313. package/dist/{openai-completions-f3n69rep.js → openai-completions-0c7qnhsx.js} +20 -20
  314. package/dist/{openai-responses-gbh0wfqe.js → openai-responses-a7h29chp.js} +15 -15
  315. package/dist/{pi-messages-zebyt7gb.js → pi-messages-2j0fpqwq.js} +5 -5
@@ -12,7 +12,7 @@ INSTALL_PRESET=solo
12
12
  MEMORY_HYBRID_SEARCH=1
13
13
  MEMORY_GRAPH_EXPANSION=1
14
14
  MEMORY_RATERS=implicit-citation,explicit-self
15
- MEMORY_DEMOTION_FLOOR=1.0
15
+ MEMORY_DEMOTION_FLOOR=0.5
16
16
 
17
17
  # === Authentication ===
18
18
  HARNESS_PROVIDER=claude
@@ -56,6 +56,7 @@ const BASE_PR = {
56
56
  body: null as string | null,
57
57
  html_url: "https://github.com/test/repo/pull/1",
58
58
  user: { login: "testuser" },
59
+ author_association: "COLLABORATOR",
59
60
  head: { ref: "feature", sha: "abc1234567890" },
60
61
  base: { ref: "main" },
61
62
  merged: false,
@@ -81,6 +82,7 @@ function makeIssueEvent(overrides: Partial<IssueEvent> = {}): IssueEvent {
81
82
  body: null,
82
83
  html_url: "https://github.com/test/repo/issues/10",
83
84
  user: { login: "testuser" },
85
+ author_association: "COLLABORATOR",
84
86
  },
85
87
  repository: BASE_REPO,
86
88
  sender: BASE_SENDER,
@@ -110,6 +112,7 @@ describe("suppressed cascade events", () => {
110
112
  state: "approved",
111
113
  html_url: "https://github.com/test/repo/pull/1#pullrequestreview-1",
112
114
  user: { login: "reviewer" },
115
+ author_association: "COLLABORATOR",
113
116
  submitted_at: "2026-01-01T00:00:00Z",
114
117
  },
115
118
  pull_request: {
@@ -137,6 +140,7 @@ describe("suppressed cascade events", () => {
137
140
  state: "approved",
138
141
  html_url: "https://github.com/test/repo/pull/99#pullrequestreview-2",
139
142
  user: { login: "reviewer" },
143
+ author_association: "COLLABORATOR",
140
144
  submitted_at: "2026-01-01T00:00:00Z",
141
145
  },
142
146
  pull_request: {
@@ -165,6 +169,7 @@ describe("suppressed cascade events", () => {
165
169
  state: "approved",
166
170
  html_url: "https://github.com/test/repo/pull/99#pullrequestreview-3",
167
171
  user: { login: "reviewer" },
172
+ author_association: "COLLABORATOR",
168
173
  submitted_at: "2026-01-01T00:00:00Z",
169
174
  },
170
175
  pull_request: {
@@ -192,6 +197,7 @@ describe("suppressed cascade events", () => {
192
197
  state: "commented",
193
198
  html_url: "https://github.com/test/repo/pull/99#pullrequestreview-4",
194
199
  user: { login: "reviewer" },
200
+ author_association: "COLLABORATOR",
195
201
  submitted_at: "2026-01-01T00:00:00Z",
196
202
  },
197
203
  pull_request: {
@@ -286,6 +292,7 @@ describe("explicit actions create tasks", () => {
286
292
  body: `@${GITHUB_BOT_NAME} please review this`,
287
293
  html_url: "https://github.com/test/repo/issues/10#issuecomment-100",
288
294
  user: { login: "testuser" },
295
+ author_association: "COLLABORATOR",
289
296
  },
290
297
  issue: {
291
298
  number: 10,
@@ -361,6 +368,7 @@ describe("explicit actions create tasks", () => {
361
368
  body: null,
362
369
  html_url: "https://github.com/test/repo/issues/11",
363
370
  user: { login: "testuser" },
371
+ author_association: "COLLABORATOR",
364
372
  },
365
373
  label: { id: 2, name: "enhancement", color: "a2eeef" },
366
374
  });
@@ -111,6 +111,7 @@ function makeReviewEvent(opts: {
111
111
  state: opts.state,
112
112
  html_url: `https://github.com/test/repo/pull/99#pullrequestreview-${id}`,
113
113
  user: { login: "reviewer" },
114
+ author_association: "COLLABORATOR",
114
115
  submitted_at: "2026-01-01T00:00:00Z",
115
116
  commit_id: opts.commitId ?? HEAD_OID,
116
117
  },
@@ -386,6 +387,7 @@ describe("inline review comment surfacing", () => {
386
387
  body: SAMPLE_INLINE_COMMENTS[0].body, // no @agent-swarm mention
387
388
  html_url: SAMPLE_INLINE_COMMENTS[0].html_url,
388
389
  user: { login: "reviewer" },
390
+ author_association: "COLLABORATOR",
389
391
  },
390
392
  pull_request: {
391
393
  number: 99,
@@ -137,6 +137,7 @@ function makeIssueEvent(overrides: Partial<IssueEvent> & { number: number }): Is
137
137
  body: null,
138
138
  html_url: `https://github.com/test/repo/issues/${number}`,
139
139
  user: { login: "human-dev" },
140
+ author_association: "COLLABORATOR",
140
141
  },
141
142
  repository: { full_name: "test/repo", html_url: "https://github.com/test/repo" },
142
143
  sender: { login: "human-dev" },
@@ -154,6 +155,7 @@ function makePREvent(overrides: Partial<PullRequestEvent> & { number: number }):
154
155
  body: null,
155
156
  html_url: `https://github.com/test/repo/pull/${number}`,
156
157
  user: { login: "human-dev" },
158
+ author_association: "COLLABORATOR",
157
159
  head: { ref: "feature", sha: "abc1234567890" },
158
160
  base: { ref: "main" },
159
161
  merged: false,
@@ -179,6 +181,7 @@ function makeCommentEvent(opts: {
179
181
  body: MENTION,
180
182
  html_url: `https://github.com/test/repo/issues/${opts.number}#issuecomment-${opts.commentId}`,
181
183
  user: { login: "human-dev" },
184
+ author_association: "COLLABORATOR",
182
185
  },
183
186
  repository: { full_name: "test/repo", html_url: "https://github.com/test/repo" },
184
187
  sender: { login: "human-dev" },
@@ -219,6 +222,7 @@ function makeReviewEvent(opts: {
219
222
  state: "changes_requested",
220
223
  html_url: `https://github.com/test/repo/pull/${opts.prNumber}#pullrequestreview-${opts.reviewId}`,
221
224
  user: { login: "human-dev" },
225
+ author_association: "COLLABORATOR",
222
226
  submitted_at: "2026-10-01T00:00:00Z",
223
227
  },
224
228
  pull_request: {
@@ -111,6 +111,7 @@ function makeIssueEvent(senderLogin: string, issueNumber = 10): IssueEvent {
111
111
  body: null,
112
112
  html_url: `https://github.com/test/repo/issues/${issueNumber}`,
113
113
  user: { login: senderLogin },
114
+ author_association: "COLLABORATOR",
114
115
  },
115
116
  repository: BASE_REPO,
116
117
  sender: { login: senderLogin },
@@ -125,6 +126,7 @@ function makeCommentEvent(senderLogin: string, body: string): CommentEvent {
125
126
  body,
126
127
  html_url: "https://github.com/test/repo/issues/10#issuecomment-999",
127
128
  user: { login: senderLogin },
129
+ author_association: "COLLABORATOR",
128
130
  },
129
131
  issue: { number: 10, title: "Test Issue", html_url: "https://github.com/test/repo/issues/10" },
130
132
  repository: BASE_REPO,
@@ -149,6 +151,7 @@ function makeReviewEvent(
149
151
  state: options.state ?? "approved",
150
152
  html_url: "https://github.com/test/repo/pull/99#pullrequestreview-1",
151
153
  user: { login: senderLogin },
154
+ author_association: "COLLABORATOR",
152
155
  submitted_at: "2026-01-01T00:00:00Z",
153
156
  },
154
157
  pull_request: {
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Sender trust for GitHub content events (mentions, comments, reviews).
3
+ *
4
+ * A lead task is created only when the sender is a linked swarm user, a login
5
+ * in GITHUB_ALLOWED_SENDERS, or the content's author with an OWNER, MEMBER or
6
+ * COLLABORATOR author_association. Anyone else is still recorded on the
7
+ * unmapped tracker, but no task is created.
8
+ */
9
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, mock, test } from "bun:test";
10
+ import { unlink } from "node:fs/promises";
11
+ import { closeDb, createAgent, createUser, getDbClient, getKv, initDb } from "../be/db";
12
+ import { linkIdentity } from "../be/users";
13
+ import {
14
+ handleComment,
15
+ handleIssue,
16
+ handlePullRequest,
17
+ handlePullRequestReview,
18
+ } from "../github/handlers";
19
+ import { GITHUB_BOT_NAME } from "../github/mentions";
20
+ import type {
21
+ CommentEvent,
22
+ IssueEvent,
23
+ PullRequestEvent,
24
+ PullRequestReviewEvent,
25
+ } from "../github/types";
26
+
27
+ mock.module("../github/app", () => ({
28
+ getInstallationToken: async () => null,
29
+ isReactionsEnabled: () => false,
30
+ initGitHub: () => true,
31
+ resetGitHub: () => {},
32
+ getWebhookSecret: () => null,
33
+ isGitHubEnabled: () => true,
34
+ verifyWebhookSignature: async () => false,
35
+ }));
36
+
37
+ const TEST_DB_PATH = "./test-github-sender-trust.sqlite";
38
+ const UNMAPPED_NAMESPACE = "integration:unmapped:github";
39
+ const LEAD_ID = "lead-gh-sender-trust";
40
+ const EXTERNAL = "external-user";
41
+ const REPO = { full_name: "test/repo", html_url: "https://github.com/test/repo" };
42
+ const MENTION = `@${GITHUB_BOT_NAME} hello`;
43
+
44
+ beforeAll(async () => {
45
+ for (const s of ["", "-wal", "-shm"]) await unlink(`${TEST_DB_PATH}${s}`).catch(() => {});
46
+ initDb(TEST_DB_PATH);
47
+ await createAgent({ id: LEAD_ID, name: "SenderTrustLead", status: "idle", isLead: true });
48
+ });
49
+
50
+ afterAll(async () => {
51
+ closeDb();
52
+ for (const s of ["", "-wal", "-shm"]) await unlink(`${TEST_DB_PATH}${s}`).catch(() => {});
53
+ });
54
+
55
+ beforeEach(async () => {
56
+ const client = getDbClient();
57
+ await client.run("DELETE FROM kv_entries WHERE namespace = ?", [UNMAPPED_NAMESPACE]);
58
+ await client.run("DELETE FROM agent_tasks");
59
+ });
60
+
61
+ afterEach(() => {
62
+ delete process.env.GITHUB_ALLOWED_SENDERS;
63
+ });
64
+
65
+ type TaskRow = { agentId: string | null; requestedByUserId: string | null };
66
+
67
+ async function tasksBy(login: string): Promise<TaskRow[]> {
68
+ return getDbClient().query<TaskRow>(
69
+ "SELECT agentId, requestedByUserId FROM agent_tasks WHERE vcsAuthor = ?",
70
+ [login],
71
+ );
72
+ }
73
+
74
+ let nextId = 9000;
75
+
76
+ function commentEvent(login: string, association?: string, author = login): CommentEvent {
77
+ const id = nextId++;
78
+ return {
79
+ action: "created",
80
+ comment: {
81
+ id,
82
+ body: MENTION,
83
+ html_url: `https://github.com/test/repo/issues/10#issuecomment-${id}`,
84
+ user: { login: author },
85
+ author_association: association,
86
+ },
87
+ issue: { number: 10, title: "Issue", html_url: "https://github.com/test/repo/issues/10" },
88
+ repository: REPO,
89
+ sender: { login },
90
+ };
91
+ }
92
+
93
+ function issueEvent(login: string, association?: string, author = login): IssueEvent {
94
+ const number = nextId++;
95
+ return {
96
+ action: "opened",
97
+ issue: {
98
+ number,
99
+ title: "Issue",
100
+ body: MENTION,
101
+ html_url: `https://github.com/test/repo/issues/${number}`,
102
+ user: { login: author },
103
+ author_association: association,
104
+ },
105
+ repository: REPO,
106
+ sender: { login },
107
+ };
108
+ }
109
+
110
+ function prEvent(login: string, association?: string): PullRequestEvent {
111
+ const number = nextId++;
112
+ return {
113
+ action: "opened",
114
+ pull_request: {
115
+ number,
116
+ title: "PR",
117
+ body: MENTION,
118
+ html_url: `https://github.com/test/repo/pull/${number}`,
119
+ user: { login },
120
+ author_association: association,
121
+ head: { ref: "feature", sha: "0000000000000" },
122
+ base: { ref: "main" },
123
+ merged: false,
124
+ },
125
+ repository: REPO,
126
+ sender: { login },
127
+ };
128
+ }
129
+
130
+ function reviewEvent(login: string, association?: string): PullRequestReviewEvent {
131
+ const number = nextId++;
132
+ return {
133
+ action: "submitted",
134
+ review: {
135
+ id: nextId++,
136
+ body: "hello",
137
+ state: "approved",
138
+ html_url: `https://github.com/test/repo/pull/${number}#pullrequestreview-1`,
139
+ user: { login },
140
+ author_association: association,
141
+ submitted_at: "2026-01-01T00:00:00Z",
142
+ },
143
+ pull_request: {
144
+ number,
145
+ title: "Bot PR",
146
+ body: null,
147
+ html_url: `https://github.com/test/repo/pull/${number}`,
148
+ user: { login: GITHUB_BOT_NAME },
149
+ head: { ref: "feature" },
150
+ base: { ref: "main" },
151
+ },
152
+ repository: REPO,
153
+ sender: { login },
154
+ };
155
+ }
156
+
157
+ describe("unlinked sender without repo association creates no task", () => {
158
+ test("issue comment mention", async () => {
159
+ const res = await handleComment(commentEvent(EXTERNAL, "NONE"), "issue_comment");
160
+ expect(res.created).toBe(false);
161
+ expect(await tasksBy(EXTERNAL)).toHaveLength(0);
162
+ // The sender is still recorded for operator triage.
163
+ expect(await getKv(UNMAPPED_NAMESPACE, `${EXTERNAL}:meta`)).not.toBeNull();
164
+ });
165
+
166
+ test("issue opened with a mention", async () => {
167
+ const res = await handleIssue(issueEvent(EXTERNAL, "NONE"));
168
+ expect(res.created).toBe(false);
169
+ expect(await tasksBy(EXTERNAL)).toHaveLength(0);
170
+ });
171
+
172
+ test("pull request opened with a mention", async () => {
173
+ const res = await handlePullRequest(prEvent(EXTERNAL, "CONTRIBUTOR"));
174
+ expect(res.created).toBe(false);
175
+ expect(await tasksBy(EXTERNAL)).toHaveLength(0);
176
+ });
177
+
178
+ test("review on a bot-authored PR", async () => {
179
+ const res = await handlePullRequestReview(reviewEvent(EXTERNAL, "NONE"));
180
+ expect(res.created).toBe(false);
181
+ expect(await tasksBy(EXTERNAL)).toHaveLength(0);
182
+ });
183
+
184
+ test("missing association", async () => {
185
+ const res = await handleComment(commentEvent(EXTERNAL), "issue_comment");
186
+ expect(res.created).toBe(false);
187
+ });
188
+
189
+ test("an association on content someone else wrote does not vouch for the sender", async () => {
190
+ const res = await handleIssue(issueEvent(EXTERNAL, "OWNER", "repo-owner"));
191
+ expect(res.created).toBe(false);
192
+ });
193
+ });
194
+
195
+ describe("trusted senders still create a lead task", () => {
196
+ test("linked swarm user with no association", async () => {
197
+ const user = await createUser({ name: "Known Dev", email: "known@example.test" });
198
+ await linkIdentity(user.id, "github", "known-dev", { kind: "system", id: "test:setup" });
199
+ const res = await handleComment(commentEvent("known-dev", "NONE"), "issue_comment");
200
+ const rows = await tasksBy("known-dev");
201
+ expect(res.created).toBe(true);
202
+ expect(rows).toHaveLength(1);
203
+ expect(rows[0]?.agentId).toBe(LEAD_ID);
204
+ expect(rows[0]?.requestedByUserId).toBe(user.id);
205
+ });
206
+
207
+ test.each(["OWNER", "MEMBER", "COLLABORATOR"])("%s association", async (association) => {
208
+ const login = `assoc-${association.toLowerCase()}`;
209
+ expect((await handleComment(commentEvent(login, association), "issue_comment")).created).toBe(
210
+ true,
211
+ );
212
+ expect((await handleIssue(issueEvent(login, association))).created).toBe(true);
213
+ expect((await handlePullRequest(prEvent(login, association))).created).toBe(true);
214
+ expect((await handlePullRequestReview(reviewEvent(login, association))).created).toBe(true);
215
+ });
216
+
217
+ test("login listed in GITHUB_ALLOWED_SENDERS (case-insensitive)", async () => {
218
+ process.env.GITHUB_ALLOWED_SENDERS = " someone-else , External-User ";
219
+ const res = await handleComment(commentEvent(EXTERNAL, "NONE"), "issue_comment");
220
+ expect(res.created).toBe(true);
221
+ expect(await tasksBy(EXTERNAL)).toHaveLength(1);
222
+ });
223
+ });
@@ -35,6 +35,11 @@ import {
35
35
  upsertKv,
36
36
  } from "../be/db";
37
37
  import { ensureRbacSeedsSynced, setUserRoles } from "../be/rbac-roles";
38
+ import {
39
+ clearUserMergeRetryTimersForTests,
40
+ getUserMergeJob,
41
+ runUserMergeJobs,
42
+ } from "../be/user-merge-jobs";
38
43
  import { fingerprintApiKey, linkIdentity } from "../be/users";
39
44
  import { handleCore } from "../http/core";
40
45
  import { handleUsers } from "../http/users";
@@ -94,8 +99,12 @@ afterAll(async () => {
94
99
  });
95
100
 
96
101
  beforeEach(async () => {
102
+ // A merge test's background job must not outlive the test, nor its retry timer.
103
+ clearUserMergeRetryTimersForTests();
104
+ await runUserMergeJobs();
97
105
  // Clean slate between tests for deterministic event counts.
98
106
  const client = getDbClient();
107
+ await client.run("DELETE FROM user_merge_jobs");
99
108
  await client.run("DELETE FROM user_identity_events");
100
109
  await client.run("DELETE FROM user_external_ids");
101
110
  await client.run("DELETE FROM user_tokens");
@@ -807,7 +816,11 @@ describe("POST /api/users/unmapped/:kind/:externalId/resolve", () => {
807
816
  });
808
817
 
809
818
  describe("POST /api/users/:id/merge", () => {
810
- test("moves identities, removes source, leaves manual_merge event", async () => {
819
+ type MergeResponse = {
820
+ job: { id: string; status: string; sourceUserId: string; targetUserId: string };
821
+ };
822
+
823
+ test("202: moves identities, queues the job, the job removes the source", async () => {
811
824
  const target = await createUser({ name: "Target", email: "t@x.com" });
812
825
  const source = await createUser({
813
826
  name: "Source",
@@ -840,8 +853,27 @@ describe("POST /api/users/:id/merge", () => {
840
853
  method: "POST",
841
854
  body: JSON.stringify({ sourceUserId: source.id }),
842
855
  });
843
- expect(r.status).toBe(200);
844
- const { user } = (await r.json()) as {
856
+ expect(r.status).toBe(202);
857
+ const { job } = (await r.json()) as MergeResponse;
858
+ expect(job.sourceUserId).toBe(source.id);
859
+ expect(job.targetUserId).toBe(target.id);
860
+ expect(["pending", "running", "done"]).toContain(job.status);
861
+
862
+ // The route's own kick drains the queue; wait for it.
863
+ await runUserMergeJobs();
864
+ const finished = await getUserMergeJob(job.id);
865
+ expect(finished?.status).toBe("done");
866
+ expect(finished?.error).toBeNull();
867
+ expect(finished?.progress["workflow-context"]).toBe(1);
868
+ expect(finished?.progress["scheduled_tasks.created_by"]).toBe(1);
869
+ expect(finished?.progress["delete-user"]).toBe(1);
870
+
871
+ const jobR = await authedFetch(`/api/users/merge-jobs/${job.id}`);
872
+ expect(jobR.status).toBe(200);
873
+ expect(((await jobR.json()) as MergeResponse).job.status).toBe("done");
874
+
875
+ const targetR = await authedFetch(`/api/users/${target.id}`);
876
+ const { user } = (await targetR.json()) as {
845
877
  user: {
846
878
  id: string;
847
879
  identities: Array<{ kind: string; externalId: string }>;
@@ -879,8 +911,9 @@ describe("POST /api/users/:id/merge", () => {
879
911
  method: "POST",
880
912
  body: JSON.stringify({ sourceUserId: source.id }),
881
913
  });
882
- expect(r.status).toBe(200);
883
- const { user } = (await r.json()) as {
914
+ expect(r.status).toBe(202);
915
+ const targetR = await authedFetch(`/api/users/${target.id}`);
916
+ const { user } = (await targetR.json()) as {
884
917
  user: {
885
918
  recentEvents: Array<{
886
919
  eventType: string;
@@ -897,33 +930,16 @@ describe("POST /api/users/:id/merge", () => {
897
930
  expect(mergeEvent!.after?.source?.email).toBe("ms@x.com");
898
931
  });
899
932
 
900
- test("rolls back identity moves when deletion fails", async () => {
933
+ test("rolls back identity moves when the short phase fails", async () => {
901
934
  const target = await createUser({ name: "RollbackTarget", email: "rollback-target@x.com" });
902
935
  const source = await createUser({ name: "RollbackSource", email: "rollback-source@x.com" });
903
- const workflow = await createWorkflow({
904
- name: `rollback-attribution-${crypto.randomUUID()}`,
905
- definition: { nodes: [] },
906
- });
907
- const run = await createWorkflowRun({
908
- id: crypto.randomUUID(),
909
- workflowId: workflow.id,
910
- createdBy: source.id,
911
- });
912
- await updateWorkflowRun(run.id, {
913
- context: { swarm: { requestedByUserId: source.id }, retained: "rollback" },
914
- });
915
- const schedule = await createScheduledTask({
916
- name: `rollback-user-schedule-${crypto.randomUUID()}`,
917
- intervalMs: 60_000,
918
- taskTemplate: "Retain rollback schedule",
919
- createdBy: source.id,
920
- });
921
936
  await linkIdentity(source.id, "slack", "U_MERGE_ROLLBACK", {
922
937
  kind: "operator",
923
938
  id: OPERATOR_FP,
924
939
  });
925
- await getDbClient().run(`CREATE TEMP TRIGGER fail_merge_source_delete
926
- BEFORE DELETE ON users WHEN OLD.id = '${source.id}'
940
+ // The merge mark is the last write of the short phase.
941
+ await getDbClient().run(`CREATE TEMP TRIGGER fail_merge_mark
942
+ BEFORE UPDATE OF mergedIntoUserId ON users WHEN NEW.id = '${source.id}'
927
943
  BEGIN SELECT RAISE(ABORT, 'forced merge failure'); END`);
928
944
 
929
945
  try {
@@ -938,14 +954,6 @@ describe("POST /api/users/:id/merge", () => {
938
954
  ["slack", "U_MERGE_ROLLBACK"],
939
955
  );
940
956
  expect(identity?.userId).toBe(source.id);
941
- expect(
942
- (
943
- await getDbClient().get<{ count: number }>(
944
- "SELECT COUNT(*) AS count FROM users WHERE id = ?",
945
- [source.id],
946
- )
947
- )?.count,
948
- ).toBe(1);
949
957
  expect(
950
958
  (
951
959
  await getDbClient().get<{ emailAliases: string }>(
@@ -962,18 +970,111 @@ describe("POST /api/users/:id/merge", () => {
962
970
  )
963
971
  )?.count,
964
972
  ).toBe(0);
965
- expect((await getWorkflowRun(run.id))?.createdBy).toBe(source.id);
966
- expect((await getWorkflowRun(run.id))?.context).toEqual({
967
- swarm: { requestedByUserId: source.id },
968
- retained: "rollback",
973
+ expect(
974
+ (
975
+ await getDbClient().get<{ count: number }>(
976
+ "SELECT COUNT(*) AS count FROM user_merge_jobs",
977
+ )
978
+ )?.count,
979
+ ).toBe(0);
980
+ } finally {
981
+ await getDbClient().run("DROP TRIGGER fail_merge_mark");
982
+ }
983
+ });
984
+
985
+ test("a job that fails waits for a retry with the error and keeps the short phase", async () => {
986
+ const target = await createUser({ name: "FailTarget", email: "fail-target@x.com" });
987
+ const source = await createUser({ name: "FailSource", email: "fail-source@x.com" });
988
+ const workflow = await createWorkflow({
989
+ name: `failed-job-${crypto.randomUUID()}`,
990
+ definition: { nodes: [] },
991
+ });
992
+ const run = await createWorkflowRun({
993
+ id: crypto.randomUUID(),
994
+ workflowId: workflow.id,
995
+ createdBy: source.id,
996
+ });
997
+ await linkIdentity(source.id, "slack", "U_MERGE_FAIL", { kind: "operator", id: OPERATOR_FP });
998
+ await getDbClient().run(`CREATE TEMP TRIGGER fail_merge_source_delete
999
+ BEFORE DELETE ON users WHEN OLD.id = '${source.id}'
1000
+ BEGIN SELECT RAISE(ABORT, 'forced merge failure'); END`);
1001
+
1002
+ try {
1003
+ const response = await authedFetch(`/api/users/${target.id}/merge`, {
1004
+ method: "POST",
1005
+ body: JSON.stringify({ sourceUserId: source.id }),
969
1006
  });
970
- expect((await getScheduledTaskById(schedule.id))?.createdBy).toBe(source.id);
971
- expect((await getScheduledTaskById(schedule.id))?.updatedBy).toBe(source.id);
1007
+ expect(response.status).toBe(202);
1008
+ const { job } = (await response.json()) as MergeResponse;
1009
+ await runUserMergeJobs();
1010
+
1011
+ // A failed attempt goes back to pending with a backoff; the error is kept.
1012
+ const failed = await getUserMergeJob(job.id);
1013
+ expect(failed?.status).toBe("pending");
1014
+ expect(failed?.attempts).toBe(1);
1015
+ expect(failed?.nextAttemptAt).not.toBeNull();
1016
+ expect(failed?.error).toContain("forced merge failure");
1017
+ // The short phase stays committed: identity moved, source marked.
1018
+ const identity = await getDbClient().get<{ userId: string }>(
1019
+ "SELECT userId FROM user_external_ids WHERE kind = ? AND externalId = ?",
1020
+ ["slack", "U_MERGE_FAIL"],
1021
+ );
1022
+ expect(identity?.userId).toBe(target.id);
1023
+ const sourceR = await authedFetch(`/api/users/${source.id}`);
1024
+ expect(sourceR.status).toBe(200);
1025
+ expect(
1026
+ ((await sourceR.json()) as { user: { mergedIntoUserId?: string } }).user.mergedIntoUserId,
1027
+ ).toBe(target.id);
1028
+ // The batches before the failure are committed too.
1029
+ expect((await getWorkflowRun(run.id))?.createdBy).toBe(target.id);
1030
+ const listR = await authedFetch("/api/users/merge-jobs?status=pending");
1031
+ expect(listR.status).toBe(200);
1032
+ expect(
1033
+ ((await listR.json()) as { jobs: Array<{ id: string }> }).jobs.map((j) => j.id),
1034
+ ).toContain(job.id);
972
1035
  } finally {
1036
+ clearUserMergeRetryTimersForTests();
973
1037
  await getDbClient().run("DROP TRIGGER fail_merge_source_delete");
974
1038
  }
975
1039
  });
976
1040
 
1041
+ test("409 merge_in_progress while a job for the source or target is not done", async () => {
1042
+ const target = await createUser({ name: "BusyTarget", email: "busy-target@x.com" });
1043
+ const source = await createUser({ name: "BusySource", email: "busy-source@x.com" });
1044
+ const other = await createUser({ name: "BusyOther", email: "busy-other@x.com" });
1045
+ await getDbClient().run(`CREATE TEMP TRIGGER hold_merge_source_delete
1046
+ BEFORE DELETE ON users WHEN OLD.id = '${source.id}'
1047
+ BEGIN SELECT RAISE(ABORT, 'hold'); END`);
1048
+ try {
1049
+ const first = await authedFetch(`/api/users/${target.id}/merge`, {
1050
+ method: "POST",
1051
+ body: JSON.stringify({ sourceUserId: source.id }),
1052
+ });
1053
+ expect(first.status).toBe(202);
1054
+ await runUserMergeJobs();
1055
+ // The source carries the merge mark whatever the job's state.
1056
+ const again = await authedFetch(`/api/users/${other.id}/merge`, {
1057
+ method: "POST",
1058
+ body: JSON.stringify({ sourceUserId: source.id }),
1059
+ });
1060
+ expect(again.status).toBe(409);
1061
+ expect(((await again.json()) as { error: string }).error).toBe("merge_in_progress");
1062
+ const intoSource = await authedFetch(`/api/users/${source.id}/merge`, {
1063
+ method: "POST",
1064
+ body: JSON.stringify({ sourceUserId: other.id }),
1065
+ });
1066
+ expect(intoSource.status).toBe(409);
1067
+ } finally {
1068
+ clearUserMergeRetryTimersForTests();
1069
+ await getDbClient().run("DROP TRIGGER hold_merge_source_delete");
1070
+ }
1071
+ });
1072
+
1073
+ test("GET /api/users/merge-jobs/:jobId → 404 for an unknown job", async () => {
1074
+ const r = await authedFetch("/api/users/merge-jobs/no-such-job");
1075
+ expect(r.status).toBe(404);
1076
+ });
1077
+
977
1078
  test("409 last_admin when the source is the only admin, and nothing is merged", async () => {
978
1079
  ensureRbacSeedsSynced({ quiet: true });
979
1080
  const admin = await createUser({ name: "OnlyAdmin" });
@@ -1008,7 +1109,7 @@ describe("POST /api/users/:id/merge", () => {
1008
1109
  method: "POST",
1009
1110
  body: JSON.stringify({ sourceUserId: source.id }),
1010
1111
  });
1011
- expect(r.status).toBe(200);
1112
+ expect(r.status).toBe(202);
1012
1113
  });
1013
1114
 
1014
1115
  test("400 when target == source", async () => {