@desplega.ai/agent-swarm 2.13.3 → 2.13.4

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 (289) hide show
  1. package/dist/acp-adapter-mr4temec.js +17 -0
  2. package/dist/{acp-targets-k8xs4tj8.js → acp-targets-zrk9k0n7.js} +10 -10
  3. package/dist/{actions-pg5fxjer.js → actions-acqqj9jn.js} +236 -26
  4. package/dist/{agent-fs-provision-vbk3fppw.js → agent-fs-provision-zmaykqnd.js} +4 -4
  5. package/dist/{amp-adapter-adbhxsz9.js → amp-adapter-a7ts8tmw.js} +3 -3
  6. package/dist/{app-b267ggx1.js → app-tmwa442h.js} +7 -7
  7. package/dist/{approval-notifications-evc1a9z5.js → approval-notifications-6psaaaye.js} +8 -8
  8. package/dist/{assistant-wgz2ab84.js → assistant-564v6emv.js} +24 -24
  9. package/dist/{boot-args-schema-6tpk28j4.js → boot-args-schema-n099e0f2.js} +1 -1
  10. package/dist/{boot-reembed-ankp369c.js → boot-reembed-chx66qfk.js} +1 -1
  11. package/dist/{boot-reembed-r1zyvefv.js → boot-reembed-epvg4fp9.js} +1 -1
  12. package/dist/{boot-scrub-sweep-cgb6r5bd.js → boot-scrub-sweep-dhkfp0a7.js} +2 -2
  13. package/dist/{boot-seeds-bjceqg7b.js → boot-seeds-m74fc07r.js} +4 -4
  14. package/dist/{boxd-hr8rsxzq.js → boxd-451q55ys.js} +1 -1
  15. package/dist/{claude-adapter-knztdnff.js → claude-adapter-hw63yj3j.js} +9 -9
  16. package/dist/{claude-managed-adapter-qwejzqkk.js → claude-managed-adapter-z5s7fx6p.js} +3 -3
  17. package/dist/{claude-managed-setup-0vgz4d1j.js → claude-managed-setup-wee1762m.js} +3 -3
  18. package/dist/{claude-sdk-session-c3g6dv0g.js → claude-sdk-session-cktyqkpk.js} +11 -11
  19. package/dist/{cli-7fa6yv98.js → cli-0fgvnb0x.js} +6 -6
  20. package/dist/{cli-2v4xxnx2.js → cli-0h8skzss.js} +1 -1
  21. package/dist/{cli-hhb8kbwd.js → cli-0p76my9q.js} +29 -14
  22. package/dist/{cli-fp65jdp2.js → cli-1kvcsd2f.js} +219 -155
  23. package/dist/{cli-wtffytm8.js → cli-1vmhnncj.js} +3 -3
  24. package/dist/{cli-268b3dgn.js → cli-29h5239w.js} +5 -5
  25. package/dist/{cli-8fj8yfmk.js → cli-2vp0z049.js} +1 -1
  26. package/dist/{cli-bh53ppqm.js → cli-3bxrrh53.js} +4 -4
  27. package/dist/{cli-61fzwtjk.js → cli-3tzmh38q.js} +9 -9
  28. package/dist/{cli-88np9va3.js → cli-3xqad83h.js} +1 -1
  29. package/dist/{cli-gc715jrc.js → cli-3zrwrnz7.js} +1 -1
  30. package/dist/{cli-dw43pnzp.js → cli-404am6f3.js} +7 -7
  31. package/dist/{cli-8pnawt98.js → cli-49aq3cyn.js} +4 -4
  32. package/dist/{cli-fbmgpt72.js → cli-4fpa0zns.js} +3 -3
  33. package/dist/{cli-kwm1bek7.js → cli-4pbwg7sn.js} +2 -2
  34. package/dist/{cli-djwt4mtn.js → cli-4q2c8rxw.js} +9 -9
  35. package/dist/{cli-3mf04tkh.js → cli-4vynxtrb.js} +1 -1
  36. package/dist/{cli-80d5g0fa.js → cli-5ashycw3.js} +3 -3
  37. package/dist/{cli-61p7ty8d.js → cli-5rgm8p39.js} +3 -3
  38. package/dist/{cli-r6xnchva.js → cli-5rxsb3wq.js} +6 -6
  39. package/dist/{cli-a21cwm89.js → cli-60dwk8tx.js} +3 -3
  40. package/dist/{cli-v1v49t36.js → cli-7by7vp6m.js} +2 -2
  41. package/dist/{cli-vgh5adn9.js → cli-7g3fg4gf.js} +7 -7
  42. package/dist/{cli-hxj888w3.js → cli-7gbff32z.js} +2 -2
  43. package/dist/{cli-q8aq48v1.js → cli-8b4rpnwj.js} +1 -1
  44. package/dist/{cli-xc8m5cjn.js → cli-8cas2xvp.js} +3 -3
  45. package/dist/{cli-1606qw3n.js → cli-904wk98s.js} +797 -369
  46. package/dist/{cli-h3drhntp.js → cli-93n305hm.js} +2 -2
  47. package/dist/{cli-1wew39p0.js → cli-944w9wb4.js} +20 -16
  48. package/dist/{cli-je587f74.js → cli-94gx6ze9.js} +1 -1
  49. package/dist/{cli-hpxcfvdm.js → cli-9ah37a8a.js} +6 -6
  50. package/dist/{cli-rfejbpe1.js → cli-akm6y2a8.js} +1 -1
  51. package/dist/{cli-f8rcvf2x.js → cli-azj9t1f9.js} +37 -2
  52. package/dist/{cli-ef590376.js → cli-bv4vvnmg.js} +3 -3
  53. package/dist/{cli-ppf9ap9n.js → cli-bzcwwebm.js} +1 -1
  54. package/dist/{cli-sy2ge2ye.js → cli-cq4am6vg.js} +2 -2
  55. package/dist/{cli-gxqwm3k3.js → cli-d5pc8ep0.js} +102 -8
  56. package/dist/{cli-hd2a204w.js → cli-ea7nz50q.js} +12 -12
  57. package/dist/{cli-zkbz8m2q.js → cli-fkpnx3vf.js} +1 -1
  58. package/dist/{cli-ya1cj689.js → cli-fw67mnyc.js} +1 -1
  59. package/dist/{cli-5basv0e7.js → cli-gkv0r2hq.js} +1 -1
  60. package/dist/{cli-ka4tqjzd.js → cli-gse7bp3z.js} +12 -10
  61. package/dist/{cli-v8rpjrnx.js → cli-gtj12v95.js} +1 -1
  62. package/dist/{cli-g4dhd3pr.js → cli-hdhpdrka.js} +6 -23
  63. package/dist/{cli-dq30fq3q.js → cli-hhtbandk.js} +2 -2
  64. package/dist/cli-hyqksecw.js +1907 -0
  65. package/dist/{cli-t25rq8mg.js → cli-ja450998.js} +40 -11
  66. package/dist/{cli-43dsqhcp.js → cli-jbrc98qb.js} +4 -4
  67. package/dist/{cli-8sayvj48.js → cli-jyhbvdga.js} +3 -3
  68. package/dist/{cli-55fqpd9q.js → cli-jzerrzgc.js} +8 -8
  69. package/dist/{cli-hv3820ez.js → cli-k0nebh10.js} +1 -1
  70. package/dist/{cli-aytna2fm.js → cli-ka48vpev.js} +5 -5
  71. package/dist/{cli-d2epqm0y.js → cli-kezzteka.js} +1 -1
  72. package/dist/{cli-grk77aen.js → cli-kj84fqxz.js} +2 -2
  73. package/dist/{cli-h0ewec3d.js → cli-kr0jpw9c.js} +1 -1
  74. package/dist/{cli-wsnradtk.js → cli-m1sns1da.js} +2 -2
  75. package/dist/{cli-7kv5d674.js → cli-n1kjs58m.js} +4 -4
  76. package/dist/{cli-syqcny89.js → cli-nc4pbwmp.js} +9 -9
  77. package/dist/{cli-9gmkw6xn.js → cli-p3knvk62.js} +48 -42
  78. package/dist/{cli-50whymxq.js → cli-p436yrzp.js} +2 -2
  79. package/dist/{cli-0j4qmc80.js → cli-phdzn699.js} +7 -7
  80. package/dist/{cli-1gnf5c7x.js → cli-pz1dp12c.js} +1 -1
  81. package/dist/{cli-nbawx3s0.js → cli-pz1nq5xm.js} +6 -6
  82. package/dist/{cli-4dyhzhpx.js → cli-qzz6tz8s.js} +1 -1
  83. package/dist/{cli-ea367bdn.js → cli-rmgvwcmy.js} +22 -22
  84. package/dist/{cli-mgr3gatr.js → cli-rv3y60bt.js} +4 -4
  85. package/dist/cli-s33bzmk0.js +27 -0
  86. package/dist/{cli-at67kvnp.js → cli-srktrbby.js} +1 -1
  87. package/dist/{cli-pzsedyb0.js → cli-t0jmkcah.js} +14 -14
  88. package/dist/{cli-eetzmsy5.js → cli-t9pzz2eq.js} +2 -2
  89. package/dist/{cli-w24741sm.js → cli-tr19nyn9.js} +4 -4
  90. package/dist/{cli-e4gx499y.js → cli-ts5yv7dn.js} +163 -86
  91. package/dist/{cli-czeh7x13.js → cli-tsc3pdfd.js} +4 -4
  92. package/dist/{cli-y0q92v4r.js → cli-tzw1jr2t.js} +2 -2
  93. package/dist/{cli-tjf1bh1v.js → cli-x2cem5vy.js} +6 -4
  94. package/dist/{cli-vx9acp12.js → cli-ybte1fqc.js} +1 -1
  95. package/dist/{cli-gkjw33x5.js → cli-ysv0k1we.js} +2 -2
  96. package/dist/{cli-vdfngx2g.js → cli-ywy8yz6t.js} +2 -2
  97. package/dist/{cli-cpkxh68d.js → cli-z1vam71h.js} +2 -2
  98. package/dist/{cli-8m6gqnf1.js → cli-zexwhj3f.js} +3 -3
  99. package/dist/{cli-snwz16eg.js → cli-zhwjdhjr.js} +2 -2
  100. package/dist/{cli-y754psdt.js → cli-zjdhrzm0.js} +4 -4
  101. package/dist/cli.js +19 -19
  102. package/dist/{codex-adapter-493vb8cv.js → codex-adapter-2fs2c0n6.js} +8 -8
  103. package/dist/{codex-hook-ej8hn6z5.js → codex-hook-jxjv6dy5.js} +1 -1
  104. package/dist/{codex-login-ven5cz5j.js → codex-login-ktfg1cxk.js} +1 -1
  105. package/dist/{codex-session-runner-ps5m4z1g.js → codex-session-runner-r55tmx4c.js} +9 -9
  106. package/dist/{commands-shktk0b8.js → commands-0mxdy9x8.js} +3 -3
  107. package/dist/{controller-wn3vd217.js → controller-g3vkfhr4.js} +4 -4
  108. package/dist/{controllers-connect-yft057ws.js → controllers-connect-4wdmncqt.js} +25 -25
  109. package/dist/core-gsvj5f3z.js +42 -0
  110. package/dist/{cursor-adapter-8fpm4dng.js → cursor-adapter-t9qb96q2.js} +2 -2
  111. package/dist/{db-0ezhdhz5.js → db-487vvyv9.js} +3 -3
  112. package/dist/{db-84pz2w5c.js → db-76p7w3gr.js} +2 -2
  113. package/dist/{devin-adapter-fs90ab4v.js → devin-adapter-3bp6rape.js} +1 -1
  114. package/dist/{dispatcher-h2rz69f6.js → dispatcher-64rp6w67.js} +22 -22
  115. package/dist/{docker-1h33jvh9.js → docker-a59g3ebm.js} +2 -2
  116. package/dist/{dsh-adapter-g9yqv09y.js → dsh-adapter-8abzqk5c.js} +2 -2
  117. package/dist/{e2b-y7e5kmzf.js → e2b-3ykbe805.js} +2 -2
  118. package/dist/{e2b-jnk0yeva.js → e2b-dc8f6ctq.js} +2 -2
  119. package/dist/{easter-egg-3d-m41ad78v.js → easter-egg-3d-jrrwyf55.js} +1 -1
  120. package/dist/{embedding-space-yam9zwzj.js → embedding-space-001hhhpk.js} +6 -6
  121. package/dist/{embeddings-g2be0y8q.js → embeddings-esj19cnw.js} +1 -1
  122. package/dist/{event-bus-08t2b4y2.js → event-bus-7gbsr0g4.js} +1 -1
  123. package/dist/{execute-hhdejgzf.js → execute-301hkxqg.js} +1 -1
  124. package/dist/{external-channel-kjt2yzfj.js → external-channel-w10e2j05.js} +2 -2
  125. package/dist/fx-adapter-4sjrbdne.js +20 -0
  126. package/dist/grok-adapter-3a0ezfee.js +20 -0
  127. package/dist/handlers-ef3k11hb.js +41 -0
  128. package/dist/{heartbeat-2e5jdexj.js → heartbeat-tbrj7vhq.js} +25 -25
  129. package/dist/{hook-acg9saz7.js → hook-3am1sq68.js} +6 -6
  130. package/dist/{hook-34s8cmgn.js → hook-tx917rqw.js} +8 -8
  131. package/dist/{http-ra2zr2f8.js → http-3rmemtqy.js} +335 -1829
  132. package/dist/{index-mbpxhc4w.js → index-126v2d0t.js} +1 -4
  133. package/dist/{index-2z1z7qx6.js → index-2jw11t8s.js} +26 -26
  134. package/dist/{index-9q42cr54.js → index-aetfyx6p.js} +1 -1
  135. package/dist/index-e6bq0exk.js +42 -0
  136. package/dist/{index-9r4j0a60.js → index-gfnq66t1.js} +223 -25
  137. package/dist/index-hf2k1vge.js +39 -0
  138. package/dist/{index-93bw5wds.js → index-s7xtvc0f.js} +1 -1
  139. package/dist/index-taxmejj3.js +44 -0
  140. package/dist/{k8s-8326q0rq.js → k8s-36gfn847.js} +2 -2
  141. package/dist/{keepalive-vjnnqbkm.js → keepalive-9px3t7qj.js} +5 -5
  142. package/dist/lead-5vt6f174.js +83 -0
  143. package/dist/{maintenance-px2g599e.js → maintenance-vwqjwst6.js} +1 -1
  144. package/dist/{oauth-refresh-sweep-nkykf09m.js → oauth-refresh-sweep-yqry3wn4.js} +4 -4
  145. package/dist/{object-webhooks-gt9xnq21.js → object-webhooks-8s1wtths.js} +7 -7
  146. package/dist/{onboard-1f134p65.js → onboard-hb8czx0p.js} +7 -7
  147. package/dist/{opencode-adapter-94976yab.js → opencode-adapter-djd6m6dk.js} +8 -8
  148. package/dist/{otel-impl-5d4p2fqs.js → otel-impl-2ymwyczz.js} +2 -2
  149. package/dist/{pending-vkk0vx6n.js → pending-nxavtvx7.js} +23 -23
  150. package/dist/{pi-mono-adapter-cyzdv5er.js → pi-mono-adapter-d2cpmcy4.js} +12 -12
  151. package/dist/{pricing-refresh-jtmjwss9.js → pricing-refresh-1yz8jkqv.js} +2 -2
  152. package/dist/{rbac-roles-1fvmdyeb.js → rbac-roles-7s6m31xw.js} +6 -4
  153. package/dist/{rbac-roles-yd1fgpsn.js → rbac-roles-dbpx0x9v.js} +3 -3
  154. package/dist/{render-v2-kb5s3vx4.js → render-v2-7y20rjrn.js} +7 -7
  155. package/dist/{resume-z1vs44n5.js → resume-wz546x47.js} +10 -10
  156. package/dist/{runtime-gk6ct7r7.js → runtime-cb5bd9tz.js} +1 -1
  157. package/dist/{session-access-nz6nre4d.js → session-access-4vcft8kq.js} +5 -5
  158. package/dist/{session-source-backfill-wb60zjkd.js → session-source-backfill-57b50tpw.js} +3 -3
  159. package/dist/{setup-2x8g8j4s.js → setup-e1tevjyj.js} +1 -1
  160. package/dist/thread-buffer-686pa1p1.js +42 -0
  161. package/dist/{tree-visibility-ts3z30kw.js → tree-visibility-07wf1nct.js} +2 -2
  162. package/dist/{user-merge-jobs-zetg26e0.js → user-merge-jobs-n20qpv6s.js} +3 -3
  163. package/dist/{virtual-modules-674fka8x.js → virtual-modules-6fxmn1yv.js} +3 -3
  164. package/dist/{work-objects-w52yyjxm.js → work-objects-eg7y48pe.js} +25 -25
  165. package/dist/worker-4vp616ms.js +83 -0
  166. package/dist/{worker-follow-up-dyfxyjbj.js → worker-follow-up-jnvnnf2b.js} +22 -22
  167. package/dist/{x-asbrnafg.js → x-d27jj7z7.js} +2 -2
  168. package/openapi.json +475 -28
  169. package/package.json +2 -2
  170. package/src/be/db/approvals.ts +2 -0
  171. package/src/be/db/runtime.ts +5 -0
  172. package/src/be/db/script-run-sources.ts +17 -0
  173. package/src/be/db-retention.ts +1 -1
  174. package/src/be/db.ts +71 -62
  175. package/src/be/design-system.ts +63 -0
  176. package/src/be/migrations/342_script_run_sources.sql +20 -0
  177. package/src/be/migrations/runner.ts +8 -0
  178. package/src/be/migrations/script-run-sources.ts +51 -0
  179. package/src/be/rbac-roles.ts +2 -0
  180. package/src/be/scripts/typecheck.ts +4 -2
  181. package/src/be/seed-scripts/catalog/design-system-seed.ts +158 -0
  182. package/src/be/seed-scripts/index.ts +9 -0
  183. package/src/be/swarm-config-guard.ts +21 -1
  184. package/src/commands/onboard/agent-fs-version.ts +1 -1
  185. package/src/heartbeat/heartbeat.ts +18 -4
  186. package/src/http/all-routes.ts +1 -0
  187. package/src/http/approval-chat-answer.ts +99 -0
  188. package/src/http/approval-requests.ts +280 -225
  189. package/src/http/design-system.ts +103 -0
  190. package/src/http/index.ts +10 -6
  191. package/src/http/pages-public.ts +25 -10
  192. package/src/http/pages.ts +17 -0
  193. package/src/http/person-responder.ts +28 -0
  194. package/src/integrations/chat-sdk/adapters.ts +33 -3
  195. package/src/integrations/chat-sdk/inbound.ts +6 -18
  196. package/src/integrations/chat-sdk/mentions.ts +188 -0
  197. package/src/integrations/chat-sdk/outbound.ts +20 -3
  198. package/src/integrations/chat-sdk/router.ts +8 -0
  199. package/src/integrations/chat-sdk/telegram-thread.ts +12 -0
  200. package/src/jira/adf.ts +35 -9
  201. package/src/kv-reserved-namespaces.ts +5 -0
  202. package/src/pages/page-head.ts +11 -1
  203. package/src/providers/amp-adapter.ts +1 -1
  204. package/src/providers/dsh-adapter.ts +48 -13
  205. package/src/rbac/legacy-policy.ts +4 -0
  206. package/src/rbac/permissions.ts +8 -0
  207. package/src/scheduler/index.ts +1 -0
  208. package/src/scheduler/scheduler.test.ts +32 -1
  209. package/src/scheduler/scheduler.ts +24 -1
  210. package/src/script-workflows/executor.ts +6 -0
  211. package/src/script-workflows/supervisor.ts +2 -1
  212. package/src/scripts-runtime/sdk-allowlist.ts +2 -0
  213. package/src/scripts-runtime/swarm-sdk.ts +12 -23
  214. package/src/scripts-runtime/types/stdlib.d.ts +4 -1
  215. package/src/scripts-runtime/types/swarm-sdk.d.ts +4 -1
  216. package/src/server.ts +2 -0
  217. package/src/slack/actions.ts +3 -0
  218. package/src/slack/approval-actions.ts +148 -0
  219. package/src/slack/approval-buttons.ts +28 -0
  220. package/src/tests/chat-sdk-mentions.test.ts +183 -0
  221. package/src/tests/create-page-tool.test.ts +5 -0
  222. package/src/tests/dsh-adapter.test.ts +53 -1
  223. package/src/tests/fixtures/compiled-source-schema-boot.ts +24 -0
  224. package/src/tests/fixtures/secret-corpus.ts +43 -1
  225. package/src/tests/heartbeat-stall-thresholds.test.ts +174 -0
  226. package/src/tests/jira-adf.test.ts +42 -2
  227. package/src/tests/merge-gate-detect-changes.test.ts +208 -16
  228. package/src/tests/migration-342-script-run-sources.test.ts +196 -0
  229. package/src/tests/migration-bunfs-compat.test.ts +129 -9
  230. package/src/tests/rbac-e2e-helpers.test.ts +10 -4
  231. package/src/tests/rbac-e2e-helpers.ts +13 -4
  232. package/src/tests/rbac-roles.test.ts +2 -0
  233. package/src/tests/runtime-e2b-pools.test.ts +7 -1
  234. package/src/tests/schedule-target-type.test.ts +4 -1
  235. package/src/tests/script-connections.test.ts +2 -0
  236. package/src/tests/script-runs-retention.test.ts +43 -16
  237. package/src/tests/script-workflows-runtime-e2e.test.ts +56 -22
  238. package/src/tests/scripts-http.test.ts +9 -3
  239. package/src/tests/sdk-allowlist.test.ts +26 -13
  240. package/src/tests/sdk-store-progress-skipped.test.ts +12 -5
  241. package/src/tests/secret-rules.test.ts +34 -0
  242. package/src/tests/secret-scrub-gate.test.ts +7 -0
  243. package/src/tests/secret-scrubber.test.ts +62 -2
  244. package/src/tests/seed-scripts.test.ts +2 -2
  245. package/src/tests/system-one-hosts-ui-mirror.test.ts +1 -0
  246. package/src/tests/vcs-azure-devops.test.ts +10 -0
  247. package/src/tests/vcs-provider.test.ts +8 -0
  248. package/src/themes/design-system.ts +163 -0
  249. package/src/themes/page-theme.ts +28 -19
  250. package/src/tools/chat-post.ts +7 -3
  251. package/src/tools/create-page.ts +3 -0
  252. package/src/tools/design-system.ts +102 -0
  253. package/src/tools/mcp-servers/mcp-server-get.ts +1 -1
  254. package/src/tools/mcp-servers/mcp-server-list.ts +1 -1
  255. package/src/tools/register-chat-channel.ts +11 -2
  256. package/src/tools/skills/skill-get-file.ts +1 -1
  257. package/src/tools/skills/skill-get.ts +1 -1
  258. package/src/tools/skills/skill-list.ts +1 -1
  259. package/src/tools/skills/skill-search.ts +1 -1
  260. package/src/tools/utils.ts +49 -4
  261. package/src/tools/workflows/get-workflow-run.ts +1 -1
  262. package/src/tools/workflows/get-workflow.ts +1 -1
  263. package/src/tools/workflows/list-workflow-runs.ts +1 -1
  264. package/src/tools/workflows/list-workflows.ts +1 -1
  265. package/src/types.ts +65 -0
  266. package/src/utils/secret-rules.generated.ts +149 -149
  267. package/src/utils/secret-scrubber.ts +111 -5
  268. package/src/vcs/azure-devops.ts +22 -1
  269. package/src/vcs/index.ts +3 -1
  270. package/src/workflows/approval-inline.ts +122 -0
  271. package/src/workflows/approval-notifications.ts +7 -2
  272. package/src/workflows/engine.ts +6 -5
  273. package/src/workflows/executors/agent-task.ts +14 -0
  274. package/src/workflows/executors/system-one-providers.ts +23 -0
  275. package/templates/skills/pages/content.md +34 -8
  276. package/templates/skills/swarm-docs/content.md +5 -0
  277. package/templates/skills/workflow-iterate/content.md +1 -1
  278. package/dist/acp-adapter-t2q6nsqv.js +0 -17
  279. package/dist/cli-kh973792.js +0 -98
  280. package/dist/core-nheayfgm.js +0 -42
  281. package/dist/fx-adapter-8g7xsp8q.js +0 -20
  282. package/dist/grok-adapter-ztk2zkz1.js +0 -20
  283. package/dist/handlers-9ywssz71.js +0 -41
  284. package/dist/index-6mgbdtv1.js +0 -44
  285. package/dist/index-hqdsn2t2.js +0 -39
  286. package/dist/index-st231bqv.js +0 -40
  287. package/dist/lead-mk0xkth2.js +0 -82
  288. package/dist/thread-buffer-d50rqpev.js +0 -42
  289. package/dist/worker-662x1vse.js +0 -82
@@ -9,7 +9,7 @@
9
9
  import { afterAll, describe, expect, test } from "bun:test";
10
10
  import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
11
11
  import { tmpdir } from "node:os";
12
- import { dirname, join } from "node:path";
12
+ import { dirname, join, relative, resolve } from "node:path";
13
13
  import { CHILD_PROCESS_TEST_BUDGET_MS, expectChildOk, runChild } from "./test-proc";
14
14
 
15
15
  type Workflow = {
@@ -18,7 +18,42 @@ type Workflow = {
18
18
 
19
19
  // The GitHub expression the step uses for the diff base; the test substitutes a local branch.
20
20
  const BASE_REF_EXPR = ["$", "{{ steps.base.outputs.ref }}"].join("");
21
- const WORKFLOW_PATH = join(import.meta.dir, "../../.github/workflows/merge-gate.yml");
21
+ const REPO_ROOT = resolve(import.meta.dir, "../..");
22
+ const WORKFLOW_PATH = join(REPO_ROOT, ".github/workflows/merge-gate.yml");
23
+ const PRE_PUSH_PATH = join(REPO_ROOT, "scripts/pre-push-tests.sh");
24
+ const PRELOAD_PATH = join(REPO_ROOT, "src/tests/preload.ts");
25
+
26
+ /**
27
+ * Repo-relative files the test preload loads: relative imports plus `new URL("./x", import.meta.url)`
28
+ * worker entries, followed transitively inside src/tests/. `local` = src/tests/ files (reached
29
+ * only through the preload); `external` = the preload's direct imports elsewhere in src/.
30
+ */
31
+ async function preloadClosure(): Promise<{ local: string[]; external: string[] }> {
32
+ const transpiler = new Bun.Transpiler({ loader: "ts" });
33
+ const testsDir = join(REPO_ROOT, "src/tests");
34
+ const local = new Set<string>();
35
+ const external = new Set<string>();
36
+ const queue = [PRELOAD_PATH];
37
+ while (queue.length > 0) {
38
+ const file = queue.shift() as string;
39
+ const rel = relative(REPO_ROOT, file);
40
+ if (local.has(rel)) continue;
41
+ local.add(rel);
42
+ const src = await Bun.file(file).text();
43
+ const specs = transpiler.scanImports(src).map((i) => i.path);
44
+ for (const m of src.matchAll(/new URL\(\s*["'](\.[^"']+)["']\s*,\s*import\.meta\.url/g)) {
45
+ if (m[1]) specs.push(m[1]);
46
+ }
47
+ for (const spec of specs) {
48
+ if (!spec.startsWith(".")) continue;
49
+ let target = resolve(dirname(file), spec);
50
+ if (!target.endsWith(".ts")) target += ".ts";
51
+ if (target.startsWith(`${testsDir}/`)) queue.push(target);
52
+ else external.add(relative(REPO_ROOT, target));
53
+ }
54
+ }
55
+ return { local: [...local].sort(), external: [...external].sort() };
56
+ }
22
57
 
23
58
  async function loadFlagStep(): Promise<string> {
24
59
  const wf = Bun.YAML.parse(await Bun.file(WORKFLOW_PATH).text()) as Workflow;
@@ -27,6 +62,13 @@ async function loadFlagStep(): Promise<string> {
27
62
  return step.run.replaceAll(BASE_REF_EXPR, "base");
28
63
  }
29
64
 
65
+ async function loadScopeStep(): Promise<string> {
66
+ const wf = Bun.YAML.parse(await Bun.file(WORKFLOW_PATH).text()) as Workflow;
67
+ const step = wf.jobs["detect-changes"]?.steps.find((s) => s.id === "test-scope");
68
+ if (!step?.run) throw new Error("detect-changes step `test-scope` not found in merge-gate.yml");
69
+ return step.run;
70
+ }
71
+
30
72
  // Isolate from the host's git config (a global diff.renames=false would make
31
73
  // the positive control pass for the wrong reason).
32
74
  const GIT_ENV = {
@@ -52,18 +94,18 @@ async function git(cwd: string, ...args: string[]) {
52
94
  // Large enough that git's default rename detection pairs the two sides.
53
95
  const BODY = Array.from({ length: 40 }, (_, i) => `export const v${i} = ${i};`).join("\n");
54
96
 
55
- /** Builds a repo whose `base` branch holds `files`, applies `change` on HEAD, and returns the step's flags. */
56
- async function flagsFor(
57
- files: string[],
97
+ /** Builds a repo whose `base` branch holds `files`, then commits `change` on top as HEAD. */
98
+ async function repoWith(
99
+ files: Array<string | [path: string, body: string]>,
58
100
  change: (repo: string) => Promise<void>,
59
- script?: string,
60
- ): Promise<Record<string, string>> {
101
+ ): Promise<string> {
61
102
  const repo = await mkdtemp(join(tmpdir(), "merge-gate-flags-"));
62
103
  dirs.push(repo);
63
104
  await git(repo, "init", "-q", "-b", "base");
64
- for (const f of files) {
105
+ for (const entry of files) {
106
+ const [f, body] = typeof entry === "string" ? [entry, `${BODY}\n// ${entry}\n`] : entry;
65
107
  await mkdir(dirname(join(repo, f)), { recursive: true });
66
- await writeFile(join(repo, f), `${BODY}\n// ${f}\n`);
108
+ await writeFile(join(repo, f), body);
67
109
  }
68
110
  await git(repo, "add", "-A");
69
111
  await git(repo, "commit", "-qm", "base");
@@ -71,24 +113,60 @@ async function flagsFor(
71
113
  await change(repo);
72
114
  await git(repo, "add", "-A");
73
115
  await git(repo, "commit", "-qm", "pr");
116
+ return repo;
117
+ }
74
118
 
119
+ /** Runs `script` in `repo` and returns what it wrote to GITHUB_OUTPUT. */
120
+ async function runStep(
121
+ repo: string,
122
+ script: string,
123
+ env: Record<string, string> = {},
124
+ ): Promise<{ stdout: string; outputs: Record<string, string> }> {
75
125
  const out = join(repo, ".gh-output");
76
126
  const res = expectChildOk(
77
- await runChild(["bash", "-c", script ?? (await loadFlagStep())], {
127
+ await runChild(["bash", "-c", script], {
78
128
  cwd: repo,
79
- env: { ...GIT_ENV, GITHUB_OUTPUT: out },
129
+ env: { ...GIT_ENV, ...env, GITHUB_OUTPUT: out },
80
130
  }),
81
- "flag step",
131
+ "workflow step",
82
132
  );
83
- expect(res.stdout).toContain("Changed files:");
84
- const flags: Record<string, string> = {};
133
+ const outputs: Record<string, string> = {};
85
134
  for (const line of (await Bun.file(out).text()).split("\n")) {
86
135
  const [k, v] = line.split("=");
87
- if (k && v) flags[k] = v;
136
+ if (k && v) outputs[k] = v;
88
137
  }
89
- return flags;
138
+ return { stdout: res.stdout, outputs };
90
139
  }
91
140
 
141
+ /** Builds the repo and returns the change-flag step's flags. */
142
+ async function flagsFor(
143
+ files: string[],
144
+ change: (repo: string) => Promise<void>,
145
+ script?: string,
146
+ ): Promise<Record<string, string>> {
147
+ const repo = await repoWith(files, change);
148
+ const { stdout, outputs } = await runStep(repo, script ?? (await loadFlagStep()));
149
+ expect(stdout).toContain("Changed files:");
150
+ return outputs;
151
+ }
152
+
153
+ /** Builds the repo and returns the unit-test scope step's outputs for `event`. */
154
+ async function scopeFor(
155
+ files: Array<string | [path: string, body: string]>,
156
+ change: (repo: string) => Promise<void>,
157
+ event = "pull_request",
158
+ ): Promise<Record<string, string>> {
159
+ const repo = await repoWith(files, change);
160
+ return (await runStep(repo, await loadScopeStep(), { EVENT_NAME: event })).outputs;
161
+ }
162
+
163
+ const edit =
164
+ (path: string, body = "edited\n") =>
165
+ async (repo: string) => {
166
+ await mkdir(dirname(join(repo, path)), { recursive: true });
167
+ await writeFile(join(repo, path), body);
168
+ };
169
+
92
170
  const mv = (from: string, to: string) => async (repo: string) => {
93
171
  await mkdir(dirname(join(repo, to)), { recursive: true });
94
172
  await git(repo, "mv", from, to);
@@ -165,3 +243,117 @@ describe("merge-gate detect-changes flags", () => {
165
243
  CHILD_PROCESS_TEST_BUDGET_MS,
166
244
  );
167
245
  });
246
+
247
+ describe("merge-gate unit-test scope", () => {
248
+ test(
249
+ "a leaf source change on a pull request runs only the affected tests",
250
+ async () => {
251
+ const scope = await scopeFor(["src/tools/leaf.ts"], edit("src/tools/leaf.ts"));
252
+ expect(scope.scope).toBe("changed");
253
+ expect(scope.base).toMatch(/^[0-9a-f]{40}$/);
254
+ },
255
+ CHILD_PROCESS_TEST_BUDGET_MS,
256
+ );
257
+
258
+ test.each([
259
+ "src/be/migrations/999_new.sql",
260
+ "templates/skills/x/content.md",
261
+ "src/tests/preload.ts",
262
+ "src/tests/hang-watchdog.ts",
263
+ "src/tests/hang-watchdog-worker.ts",
264
+ "bunfig.toml",
265
+ "tsconfig.json",
266
+ "bun.lock",
267
+ ".github/workflows/merge-gate.yml",
268
+ ])(
269
+ "%s runs the full suite on a pull request",
270
+ async (path) => {
271
+ expect((await scopeFor(["src/x.ts"], edit(path))).scope).toBe("full");
272
+ },
273
+ CHILD_PROCESS_TEST_BUDGET_MS,
274
+ );
275
+
276
+ test(
277
+ "every preload-only bootstrap file runs the full suite in CI and pre-push",
278
+ async () => {
279
+ const { local, external } = await preloadClosure();
280
+ // Positive control: the sweep sees the watchdog thread file only through `new URL`.
281
+ expect(local).toContain("src/tests/hang-watchdog-worker.ts");
282
+ const prePush = (await Bun.file(PRE_PUSH_PATH).text()).match(/^FULL_RUN_PATHS='(.+)'$/m)?.[1];
283
+ if (!prePush) throw new Error("FULL_RUN_PATHS not found in pre-push-tests.sh");
284
+ for (const path of local) {
285
+ expect({ path, scope: (await scopeFor(["src/x.ts"], edit(path))).scope }).toEqual({
286
+ path,
287
+ scope: "full",
288
+ });
289
+ expect({ path, prePush: new RegExp(prePush).test(path) }).toEqual({ path, prePush: true });
290
+ }
291
+ // A preload import outside src/tests/ is safe only while some test imports it too:
292
+ // `--changed` then selects that test, and it fails in the preload.
293
+ const tests = await Promise.all(
294
+ [...new Bun.Glob("src/**/*.test.ts").scanSync(REPO_ROOT)].map((f) =>
295
+ Bun.file(join(REPO_ROOT, f)).text(),
296
+ ),
297
+ );
298
+ for (const path of external) {
299
+ const spec = `/${path.replace(/^src\//, "").replace(/\.ts$/, "")}"`;
300
+ expect({ path, testImporter: tests.some((t) => t.includes(spec)) }).toEqual({
301
+ path,
302
+ testImporter: true,
303
+ });
304
+ }
305
+ },
306
+ CHILD_PROCESS_TEST_BUDGET_MS,
307
+ );
308
+
309
+ test(
310
+ "control: bun test --changed skips every test when only a preload-only import changes",
311
+ async () => {
312
+ const repo = await repoWith(
313
+ [
314
+ ["bunfig.toml", '[test]\npreload = ["./preload.ts"]\n'],
315
+ ["preload.ts", 'import "./dep";\n'],
316
+ ["dep.ts", "export {};\n"],
317
+ ["a.test.ts", 'import { test } from "bun:test";\ntest("a", () => {});\n'],
318
+ ],
319
+ edit("dep.ts", 'throw new Error("preload dependency regression");\n'),
320
+ );
321
+ const env = { ...GIT_ENV, HOME: process.env.HOME ?? tmpdir() };
322
+ const scoped = await runChild([process.execPath, "test", "--changed=base"], {
323
+ cwd: repo,
324
+ env,
325
+ });
326
+ const full = await runChild([process.execPath, "test"], { cwd: repo, env });
327
+ // Scoped: nothing selected, exit 0. Full: the preload throws.
328
+ expect(scoped.exitCode).toBe(0);
329
+ expect(`${scoped.stdout}${scoped.stderr}`).not.toContain("preload dependency regression");
330
+ expect(full.exitCode).not.toBe(0);
331
+ expect(`${full.stdout}${full.stderr}`).toContain("preload dependency regression");
332
+ },
333
+ CHILD_PROCESS_TEST_BUDGET_MS,
334
+ );
335
+
336
+ test(
337
+ "a package.json version bump alone stays scoped; a dependency change runs everything",
338
+ async () => {
339
+ const pkg = (version: string, dep: string) =>
340
+ `{\n "name": "x",\n "version": "${version}",\n "dependencies": { "a": "${dep}" }\n}\n`;
341
+ const base: Array<[string, string]> = [["package.json", pkg("1.0.0", "1.0.0")]];
342
+ const bump = await scopeFor(base, edit("package.json", pkg("1.0.1", "1.0.0")));
343
+ expect(bump.scope).toBe("changed");
344
+ const dep = await scopeFor(base, edit("package.json", pkg("1.0.0", "2.0.0")));
345
+ expect(dep.scope).toBe("full");
346
+ },
347
+ CHILD_PROCESS_TEST_BUDGET_MS,
348
+ );
349
+
350
+ test(
351
+ "the merge queue always runs the full suite",
352
+ async () => {
353
+ const scope = await scopeFor(["src/tools/leaf.ts"], edit("src/tools/leaf.ts"), "merge_group");
354
+ expect(scope.scope).toBe("full");
355
+ expect(scope.base).toBeUndefined();
356
+ },
357
+ CHILD_PROCESS_TEST_BUDGET_MS,
358
+ );
359
+ });
@@ -0,0 +1,196 @@
1
+ import { Database } from "bun:sqlite";
2
+ import { afterEach, beforeAll, expect, test } from "bun:test";
3
+ import { runMigrations } from "../be/migrations/runner";
4
+ import { backfillScriptRunSources } from "../be/migrations/script-run-sources";
5
+
6
+ let schema: string;
7
+ let migration: string;
8
+ let db: Database;
9
+
10
+ beforeAll(async () => {
11
+ const dir = `${import.meta.dir}/../be/migrations`;
12
+ schema = await Bun.file(`${dir}/083_script_workflows.sql`).text();
13
+ migration = await Bun.file(`${dir}/342_script_run_sources.sql`).text();
14
+ });
15
+
16
+ afterEach(() => {
17
+ db.close();
18
+ });
19
+
20
+ function legacyDatabase(): Database {
21
+ const database = new Database(":memory:");
22
+ database.exec("PRAGMA foreign_keys = ON; CREATE TABLE users (id TEXT PRIMARY KEY)");
23
+ database.exec(schema);
24
+ return database;
25
+ }
26
+
27
+ function insertRun(id: string, source: string): void {
28
+ db.run("INSERT INTO script_runs (id, agentId, source) VALUES (?, 'agent', ?)", [id, source]);
29
+ }
30
+
31
+ function hash(source: string): string {
32
+ return new Bun.CryptoHasher("sha256").update(source).digest("hex");
33
+ }
34
+
35
+ function count(sql: string): number {
36
+ return db.prepare<{ n: number }, []>(sql).get()?.n ?? 0;
37
+ }
38
+
39
+ test("fresh migrations install the source schema and resume backfill on later boots", () => {
40
+ db = new Database(":memory:");
41
+ runMigrations(db);
42
+ expect(db.prepare("PRAGMA table_info(script_run_sources)").all()).toMatchObject([
43
+ { name: "hash", pk: 1 },
44
+ { name: "source", notnull: 1 },
45
+ ]);
46
+ expect(db.prepare("PRAGMA foreign_key_list(script_runs)").all()).toContainEqual(
47
+ expect.objectContaining({ table: "script_run_sources", from: "sourceHash", to: "hash" }),
48
+ );
49
+ expect(db.prepare("PRAGMA index_list(script_runs)").all()).toContainEqual(
50
+ expect.objectContaining({ name: "idx_script_runs_sourceHash", partial: 0 }),
51
+ );
52
+
53
+ insertRun("legacy", "export default 1");
54
+ // The SQL migration is already recorded; boot must still finish the backfill.
55
+ runMigrations(db);
56
+ expect(
57
+ db.prepare("SELECT source, sourceHash FROM script_runs WHERE id = 'legacy'").get(),
58
+ ).toEqual({
59
+ source: "",
60
+ sourceHash: hash("export default 1"),
61
+ });
62
+ expect(count("SELECT count(*) AS n FROM _migrations WHERE version = 342")).toBe(1);
63
+ });
64
+
65
+ test("existing runs keep their table and journal while exact UTF-8 sources deduplicate", () => {
66
+ db = legacyDatabase();
67
+ const sources = ["same", "same", "", "你好 🌍\n", "é", "e\u0301", "same\n"];
68
+ sources.forEach((source, i) => {
69
+ insertRun(`run-${i}`, source);
70
+ });
71
+ db.run(
72
+ "INSERT INTO script_run_journal (id, runId, stepKey, stepType, status) VALUES ('journal', 'run-0', 'step', 'script', 'completed')",
73
+ );
74
+ const before = db.prepare("SELECT rootpage FROM sqlite_master WHERE name = 'script_runs'").get();
75
+ const rowids = db.prepare("SELECT rowid, id FROM script_runs ORDER BY rowid").all();
76
+
77
+ db.exec(migration);
78
+ backfillScriptRunSources(db);
79
+
80
+ expect(db.prepare("SELECT rootpage FROM sqlite_master WHERE name = 'script_runs'").get()).toEqual(
81
+ before,
82
+ );
83
+ expect(db.prepare("SELECT rowid, id FROM script_runs ORDER BY rowid").all()).toEqual(rowids);
84
+ expect(count("SELECT count(*) AS n FROM script_run_journal")).toBe(1);
85
+ expect(count("SELECT count(*) AS n FROM script_run_sources")).toBe(6);
86
+ sources.forEach((source, i) => {
87
+ expect(
88
+ db.prepare("SELECT source, sourceHash FROM script_runs WHERE id = ?").get(`run-${i}`),
89
+ ).toEqual({
90
+ source: "",
91
+ sourceHash: hash(source),
92
+ });
93
+ expect(
94
+ db.prepare("SELECT source FROM script_run_sources WHERE hash = ?").get(hash(source)),
95
+ ).toEqual({
96
+ source,
97
+ });
98
+ });
99
+ // Neither whitespace nor Unicode normalization may alter content identity.
100
+ expect(hash("é")).not.toBe(hash("e\u0301"));
101
+ });
102
+
103
+ test("backfill commits bounded batches and rolls an interrupted batch back before restart", () => {
104
+ db = new Database(":memory:");
105
+ runMigrations(db);
106
+ for (let i = 0; i < 60; i++) insertRun(`run-${i.toString().padStart(3, "0")}`, `source ${i}`);
107
+ db.exec(`CREATE TRIGGER interrupt_source_backfill BEFORE UPDATE OF sourceHash ON script_runs
108
+ WHEN NEW.id = 'run-026'
109
+ BEGIN SELECT RAISE(ABORT, 'interrupted backfill'); END`);
110
+
111
+ expect(() => runMigrations(db)).toThrow("interrupted backfill");
112
+ expect(count("SELECT count(*) AS n FROM script_runs WHERE sourceHash IS NOT NULL")).toBe(25);
113
+ expect(count("SELECT count(*) AS n FROM script_run_sources")).toBe(25);
114
+ expect(
115
+ db.prepare("SELECT source, sourceHash FROM script_runs WHERE id = 'run-025'").get(),
116
+ ).toEqual({
117
+ source: "source 25",
118
+ sourceHash: null,
119
+ });
120
+ expect(
121
+ db.prepare("SELECT source FROM script_run_sources WHERE hash = ?").get(hash("source 25")),
122
+ ).toBeNull();
123
+
124
+ // Reopen the committed database state, as after process termination.
125
+ const snapshot = db.serialize();
126
+ db.close();
127
+ db = Database.deserialize(snapshot);
128
+ db.exec("PRAGMA foreign_keys = ON; DROP TRIGGER interrupt_source_backfill");
129
+ runMigrations(db);
130
+ expect(count("SELECT count(*) AS n FROM script_runs WHERE sourceHash IS NOT NULL")).toBe(60);
131
+ expect(count("SELECT count(*) AS n FROM script_run_sources")).toBe(60);
132
+ expect(count("SELECT count(*) AS n FROM script_runs WHERE source <> ''")).toBe(0);
133
+
134
+ const changes = db.prepare("SELECT total_changes() AS n").get();
135
+ backfillScriptRunSources(db);
136
+ expect(db.prepare("SELECT total_changes() AS n").get()).toEqual(changes);
137
+ expect(db.prepare("PRAGMA foreign_key_check").all()).toEqual([]);
138
+ });
139
+
140
+ test("partial upgrades retain already-pinned sources and reuse their content", () => {
141
+ db = legacyDatabase();
142
+ insertRun("pinned", "same");
143
+ insertRun("pending", "same");
144
+ insertRun("unique", "another");
145
+ db.exec(migration);
146
+ db.run("INSERT INTO script_run_sources (hash, source) VALUES (?, 'same')", [hash("same")]);
147
+ db.run("UPDATE script_runs SET sourceHash = ?, source = '' WHERE id = 'pinned'", [hash("same")]);
148
+
149
+ backfillScriptRunSources(db);
150
+ expect(count("SELECT count(*) AS n FROM script_run_sources")).toBe(2);
151
+ expect(count("SELECT count(*) AS n FROM script_runs WHERE sourceHash IS NULL")).toBe(0);
152
+ expect(
153
+ db
154
+ .prepare<{ n: number }, [string]>(
155
+ "SELECT count(*) AS n FROM script_runs WHERE sourceHash = ?",
156
+ )
157
+ .get(hash("same"))?.n,
158
+ ).toBe(2);
159
+ });
160
+
161
+ test("foreign keys reject missing sources and retention drops only the final reference", () => {
162
+ db = legacyDatabase();
163
+ insertRun("shared-1", "same");
164
+ insertRun("shared-2", "same");
165
+ insertRun("unique", "unique");
166
+ db.exec(migration);
167
+ backfillScriptRunSources(db);
168
+ db.run(
169
+ "INSERT INTO script_run_journal (id, runId, stepKey, stepType, status) VALUES ('journal', 'shared-2', 'step', 'script', 'completed')",
170
+ );
171
+ expect(() =>
172
+ db.run(
173
+ "INSERT INTO script_runs (id, agentId, source, sourceHash) VALUES ('invalid', 'agent', '', 'missing')",
174
+ ),
175
+ ).toThrow("FOREIGN KEY constraint failed");
176
+ expect(() => db.run("UPDATE script_runs SET sourceHash = 'missing' WHERE id = 'unique'")).toThrow(
177
+ "FOREIGN KEY constraint failed",
178
+ );
179
+ expect(() => db.run("DELETE FROM script_run_sources WHERE hash = ?", [hash("same")])).toThrow(
180
+ "FOREIGN KEY constraint failed",
181
+ );
182
+
183
+ db.run("DELETE FROM script_runs WHERE id = 'shared-1'");
184
+ expect(
185
+ db.prepare("SELECT source FROM script_run_sources WHERE hash = ?").get(hash("same")),
186
+ ).toEqual({ source: "same" });
187
+ db.run("DELETE FROM script_runs WHERE id = 'shared-2'");
188
+ expect(
189
+ db.prepare("SELECT source FROM script_run_sources WHERE hash = ?").get(hash("same")),
190
+ ).toBeNull();
191
+ expect(count("SELECT count(*) AS n FROM script_run_journal")).toBe(0);
192
+ expect(count("SELECT count(*) AS n FROM script_run_sources")).toBe(1);
193
+ db.run("DELETE FROM script_runs");
194
+ expect(count("SELECT count(*) AS n FROM script_run_sources")).toBe(0);
195
+ expect(db.prepare("PRAGMA foreign_key_check").all()).toEqual([]);
196
+ });
@@ -1,6 +1,6 @@
1
1
  import { Database } from "bun:sqlite";
2
- import { afterAll, describe, expect, test } from "bun:test";
3
- import { mkdtempSync, rmSync } from "node:fs";
2
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
3
+ import { mkdirSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { join } from "node:path";
6
6
  import {
@@ -106,8 +106,28 @@ describe("assertNotEmptyDatabase", () => {
106
106
 
107
107
  describe("compiled binary — the exact failure mode this incident shipped in", () => {
108
108
  const workDir = mkdtempSync(join(tmpdir(), "migration-bunfs-"));
109
- const fixtureBinary = join(workDir, "compiled-migrations-boot");
109
+ const fixtureBinary = join(
110
+ workDir,
111
+ `compiled-migrations-boot${process.platform === "win32" ? ".exe" : ""}`,
112
+ );
110
113
  const fixtureSrc = join(import.meta.dir, "fixtures", "compiled-migrations-boot.ts");
114
+ const apiBinary = join(
115
+ workDir,
116
+ `compiled-source-schema-boot${process.platform === "win32" ? ".exe" : ""}`,
117
+ );
118
+ const apiFixtureSrc = join(import.meta.dir, "fixtures", "compiled-source-schema-boot.ts");
119
+ const legacyDir = join(workDir, "legacy-migrations");
120
+ const emptyDir = join(workDir, "empty-migrations");
121
+
122
+ beforeAll(async () => {
123
+ mkdirSync(legacyDir);
124
+ mkdirSync(emptyDir);
125
+ for (const file of readdirSync(REPO_MIGRATIONS_DIR)) {
126
+ if (file.endsWith(".sql") && Number.parseInt(file, 10) < 342) {
127
+ await Bun.write(join(legacyDir, file), Bun.file(join(REPO_MIGRATIONS_DIR, file)));
128
+ }
129
+ }
130
+ });
111
131
 
112
132
  afterAll(() => {
113
133
  rmSync(workDir, { recursive: true, force: true });
@@ -116,13 +136,28 @@ describe("compiled binary — the exact failure mode this incident shipped in",
116
136
  test(
117
137
  "builds",
118
138
  async () => {
119
- const result = await runChild(
120
- ["bun", "build", fixtureSrc, "--compile", "--outfile", fixtureBinary],
121
- { timeoutMs: CHILD_PROCESS_TEST_BUDGET_MS },
122
- );
123
- expectChildOk(result, "bun build --compile of the migrations fixture");
139
+ for (const [source, binary] of [
140
+ [fixtureSrc, fixtureBinary],
141
+ [apiFixtureSrc, apiBinary],
142
+ ]) {
143
+ const result = await runChild(
144
+ [
145
+ "bun",
146
+ "build",
147
+ source,
148
+ "--compile",
149
+ "--outfile",
150
+ binary,
151
+ // Exercise the Linux API image's virtual path on Windows too, where
152
+ // Bun otherwise uses B:\\~BUN\\root instead of /$bunfs/root.
153
+ ...(process.platform === "win32" ? ["--define", 'import.meta.dir="/$bunfs/root"'] : []),
154
+ ],
155
+ { timeoutMs: CHILD_PROCESS_TEST_BUDGET_MS },
156
+ );
157
+ expectChildOk(result, "bun build --compile of the migrations fixture");
158
+ }
124
159
  },
125
- CHILD_PROCESS_TEST_BUDGET_MS + 5_000,
160
+ CHILD_PROCESS_TEST_BUDGET_MS * 2 + 5_000,
126
161
  );
127
162
 
128
163
  test(
@@ -164,4 +199,89 @@ describe("compiled binary — the exact failure mode this incident shipped in",
164
199
  },
165
200
  CHILD_PROCESS_TEST_BUDGET_MS + 5_000,
166
201
  );
202
+
203
+ test.each(["omitted", "empty", "unset", "missing table", "missing hash column"])(
204
+ "refuses a legacy database before runtime reads when migration 342 is %s",
205
+ async (mode) => {
206
+ const dbPath = join(workDir, `legacy-${mode}.sqlite`);
207
+ // The standalone runner can prepare historical schemas. Actual API boot
208
+ // must reject them before handing a handle to its source readers.
209
+ expectChildOk(
210
+ await runChild([fixtureBinary, dbPath], {
211
+ env: { ...process.env, MIGRATIONS_DIR: legacyDir },
212
+ timeoutMs: CHILD_PROCESS_TEST_BUDGET_MS,
213
+ }),
214
+ "prepare pre-342 database",
215
+ );
216
+ if (mode === "missing table" || mode === "missing hash column") {
217
+ const legacy = new Database(dbPath);
218
+ try {
219
+ legacy.run(
220
+ mode === "missing table"
221
+ ? "ALTER TABLE script_runs ADD COLUMN sourceHash TEXT"
222
+ : "CREATE TABLE script_run_sources (hash TEXT PRIMARY KEY, source TEXT NOT NULL)",
223
+ );
224
+ } finally {
225
+ legacy.close(true);
226
+ }
227
+ }
228
+ const env = { ...process.env };
229
+ if (mode === "unset") delete env.MIGRATIONS_DIR;
230
+ else env.MIGRATIONS_DIR = mode === "empty" ? emptyDir : legacyDir;
231
+
232
+ const result = await runChild([apiBinary, dbPath], {
233
+ env,
234
+ timeoutMs: CHILD_PROCESS_TEST_BUDGET_MS,
235
+ });
236
+ expectChildOk(result, "compiled fixture with incomplete migrations");
237
+ const parsed = JSON.parse(result.stdout.trim());
238
+ expect(parsed.ok).toBe(false);
239
+ expect(parsed.error).toContain("342_script_run_sources.sql");
240
+ expect(parsed.error).toContain("MIGRATIONS_DIR");
241
+ },
242
+ CHILD_PROCESS_TEST_BUDGET_MS * 2 + 5_000,
243
+ );
244
+
245
+ test.each(["omitted", "empty", "unset"])(
246
+ "reuses and backfills an upgraded database when migration 342 is %s",
247
+ async (mode) => {
248
+ const dbPath = join(workDir, `upgraded-${mode}.sqlite`);
249
+ const seeded = await runChild([apiBinary, dbPath], {
250
+ env: { ...process.env, MIGRATIONS_DIR: REPO_MIGRATIONS_DIR },
251
+ timeoutMs: CHILD_PROCESS_TEST_BUDGET_MS,
252
+ });
253
+ expectChildOk(seeded, "prepare upgraded database");
254
+ expect(JSON.parse(seeded.stdout.trim()).ok).toBe(true);
255
+ const source = "export default () => '雪';\n";
256
+ const legacy = new Database(dbPath);
257
+ try {
258
+ legacy.run("INSERT INTO script_runs (id, agentId, source) VALUES ('legacy', 'agent', ?)", [
259
+ source,
260
+ ]);
261
+ } finally {
262
+ legacy.close(true);
263
+ }
264
+ const env = { ...process.env };
265
+ if (mode === "unset") delete env.MIGRATIONS_DIR;
266
+ else env.MIGRATIONS_DIR = mode === "empty" ? emptyDir : legacyDir;
267
+
268
+ const result = await runChild([apiBinary, dbPath], {
269
+ env,
270
+ timeoutMs: CHILD_PROCESS_TEST_BUDGET_MS,
271
+ });
272
+ expectChildOk(result, "compiled fixture reusing upgraded source schema");
273
+ expect(JSON.parse(result.stdout.trim()).ok).toBe(true);
274
+ const reopened = new Database(dbPath);
275
+ const storedSource = reopened.prepare(`SELECT r.source AS legacySource, s.source
276
+ FROM script_runs r LEFT JOIN script_run_sources s ON s.hash = r.sourceHash
277
+ WHERE r.id = 'legacy'`);
278
+ try {
279
+ expect(storedSource.get()).toEqual({ legacySource: "", source });
280
+ } finally {
281
+ storedSource.finalize();
282
+ reopened.close(true);
283
+ }
284
+ },
285
+ CHILD_PROCESS_TEST_BUDGET_MS * 2 + 5_000,
286
+ );
167
287
  });
@@ -1,7 +1,7 @@
1
1
  import { expect, test } from "bun:test";
2
2
  import { closeSync, openSync } from "node:fs";
3
3
  import { mkdtemp, rm } from "node:fs/promises";
4
- import { createServer } from "node:net";
4
+ import { createServer } from "node:http";
5
5
  import { tmpdir } from "node:os";
6
6
  import { join } from "node:path";
7
7
  import {
@@ -105,17 +105,23 @@ test("startOnFreePort retries only PortInUseError, up to its attempt bound", asy
105
105
  });
106
106
 
107
107
  test(
108
- "spawnSwarmServer starts again on a new port when its first port is taken",
108
+ "spawnSwarmServer retries when another HTTP server answers on its first port",
109
109
  async () => {
110
110
  const dir = await makeScratchDir();
111
- const holder = createServer();
111
+ const holder = createServer((_req, res) => {
112
+ res.writeHead(200, { "Content-Type": "application/json" });
113
+ res.end(JSON.stringify({ ok: true }));
114
+ });
112
115
  const heldPort = await listenOnFreePort(holder);
116
+ const logPath = join(dir, "server.log");
117
+ // A reused log can contain a previous boot on the same port.
118
+ await Bun.write(logPath, `MCP HTTP server running on http://localhost:${heldPort}/mcp\n`);
113
119
  let server: SwarmServer | undefined;
114
120
  try {
115
121
  const offered: number[] = [];
116
122
  server = await spawnSwarmServer({
117
123
  dbPath: join(dir, "test.sqlite"),
118
- logPath: join(dir, "server.log"),
124
+ logPath,
119
125
  getPort: async () => {
120
126
  const port = offered.length === 0 ? heldPort : await getFreePort();
121
127
  offered.push(port);